8 static int gotnvr; /* flag: nvr contains nvram; it could be bad */
17 * we shouldn't be writing nvram any more.
18 * the secstore/config field is now just secstore key.
19 * we still use authid, authdom and machkey for authentication.
27 if (readnvram(&nvr, NVread) < 0) {
28 print("nvrcheck: can't read nvram\n");
34 csum = nvcsum(nvr.machkey, sizeof nvr.machkey);
35 if(csum != nvr.machsum) {
36 print("\n\n ** NVR key checksum is incorrect **\n");
37 print(" ** set password to allow attaches **\n\n");
38 memset(nvr.machkey, 0, sizeof nvr.machkey);
46 nvrsetconfig(char* word)
48 /* config block is on device `word' */
57 char nkey1[DESKEYLEN];
58 static char zeroes[DESKEYLEN];
60 if(memcmp(nvr.machkey, zeroes, DESKEYLEN) == 0) {
61 print("no password set\n");
66 print("%s password:", service);
67 /* could turn off echo here */
69 if ((ln = Brdline(&bin, '\n')) == nil)
71 ln[Blinelen(&bin)-1] = '\0';
73 /* could turn on echo here */
74 memset(nkey1, 0, DESKEYLEN);
76 if(memcmp(nkey1, nvr.machkey, DESKEYLEN) == 0) {
81 print("Bad password\n");
87 /* authentication structure */
91 char uname[NAMELEN]; /* requestor's remote user name */
92 char aname[NAMELEN]; /* requested aname */
93 Userid uid; /* uid decided on */
103 auths = malloc(conf.nauth * sizeof(*auths));
107 failure(Auth *s, char *why)
111 if(why && *why)print("authentication failed: %s: %r\n", why);
121 authnew(char *uname, char *aname)
130 if(i < 0 || i >= conf.nauth){
141 strncpy(s->uname, uname, NAMELEN-1);
142 strncpy(s->aname, aname, NAMELEN-1);
150 if((afd = open("/mnt/factotum/rpc", ORDWR)) < 0){
151 failure(s, "open /mnt/factotum/rpc");
154 if((s->rpc = auth_allocrpc(afd)) == 0){
155 failure(s, "auth_allocrpc");
159 if(auth_rpc(s->rpc, "start", "proto=p9any role=server", 23) != ARok)
160 failure(s, "auth_rpc: start");
174 authread(File* file, uchar* data, int n)
184 switch(auth_rpc(s->rpc, "read", nil, 0)){
186 failure(s, "auth_rpc: read");
189 if((ai = auth_getinfo(s->rpc)) == nil){
190 failure(s, "auth_getinfo failed");
193 if(ai->cuid == nil || *ai->cuid == '\0'){
194 failure(s, "auth with no cuid");
199 s->uid = strtouid(ai->cuid);
205 memmove(data, s->rpc->arg, s->rpc->narg);
212 authwrite(File* file, uchar *data, int n)
221 if(auth_rpc(s->rpc, "write", data, n) != ARok){
222 failure(s, "auth_rpc: write");