Unified · Split
| @@ -6,7 +6,6 @@ OFILES=\ · 5 unmodified lines | ||
| 6 | 6 | main.$O\ |
| 7 | 7 | cpu.$O\ |
| 8 | 8 | aan.$O\ |
| 9 | − readcons.$O\ | |
| 10 | 9 | secstore.$O\ |
| 11 | 10 | latin1.$O\ |
| 12 | 11 | $(OS)-factotum.$O\ |
| @@ -36,6 +36,15 @@ static int p9authtls(int); · 35 unmodified lines | ||
| 36 | 36 | char *authserver; |
| 37 | 37 | char *secstore; |
| 38 | 38 | |
| 39 | +char* | |
| 40 | +estrdup(char *s) | |
| 41 | +{ | |
| 42 | + s = strdup(s); | |
| 43 | + if(s == nil) | |
| 44 | + sysfatal("out of memory"); | |
| 45 | + return s; | |
| 46 | +} | |
| 47 | + | |
| 39 | 48 | static void |
| 40 | 49 | ending(void) |
| 41 | 50 | { |
| @@ -3,7 +3,6 @@ extern char *secstore; · 2 unmodified lines | ||
| 3 | 3 | extern char secstorebuf[65536]; |
| 4 | 4 | extern char *secstorefetch(char *addr, char *owner, char *passwd); |
| 5 | 5 | extern char *authserver; |
| 6 | −extern char *readcons(char *prompt, char *def, int secret); | |
| 7 | 6 | extern int exportfs(int); |
| 8 | 7 | extern char *user; |
| 9 | 8 | extern int dialfactotum(void); |
| @@ -23,6 +23,7 @@ enum · 22 unmodified lines | ||
| 23 | 23 | NETCHLEN= 16, /* max network challenge length (used in AS protocol) */ |
| 24 | 24 | CONFIGLEN= 14, |
| 25 | 25 | SECRETLEN= 32, /* secret max size */ |
| 26 | + PASSWDLEN= 28, /* password max size */ | |
| 26 | 27 | |
| 27 | 28 | NONCELEN= 32, |
| 28 | 29 | |
| @@ -99,8 +100,8 @@ struct Authenticator · 70 unmodified lines | ||
| 99 | 100 | struct Passwordreq |
| 100 | 101 | { |
| 101 | 102 | char num; |
| 102 | − char old[ANAMELEN]; | |
| 103 | − char new[ANAMELEN]; | |
| 103 | + char old[PASSWDLEN]; | |
| 104 | + char new[PASSWDLEN]; | |
| 104 | 105 | char changesecret; |
| 105 | 106 | char secret[SECRETLEN]; /* new secret */ |
| 106 | 107 | }; |
| @@ -184,6 +185,7 @@ struct Nvrsafe · 77 unmodified lines | ||
| 184 | 185 | |
| 185 | 186 | extern uchar nvcsum(void*, int); |
| 186 | 187 | extern int readnvram(Nvrsafe*, int); |
| 188 | +extern char* readcons(char*, char*, int); | |
| 187 | 189 | |
| 188 | 190 | /* |
| 189 | 191 | * call up auth server |
| @@ -487,7 +487,7 @@ consclose(Chan *c) · 486 unmodified lines | ||
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | static int |
| 490 | −readcons(Queue *q, char *buf, int n) | |
| 490 | +qreadcons(Queue *q, char *buf, int n) | |
| 491 | 491 | { |
| 492 | 492 | if(screenputs==0 && !qcanread(q)) |
| 493 | 493 | return read(0, buf, n); |
| @@ -521,7 +521,7 @@ consread(Chan *c, void *buf, long n, vlong off) · 27 unmodified lines | ||
| 521 | 521 | else { |
| 522 | 522 | /* read as much as possible */ |
| 523 | 523 | do { |
| 524 | − i = readcons(kbdq, cbuf, n); | |
| 524 | + i = qreadcons(kbdq, cbuf, n); | |
| 525 | 525 | cbuf += i; |
| 526 | 526 | n -= i; |
| 527 | 527 | } while (n>0 && qcanread(kbdq)); |
| @@ -530,7 +530,7 @@ consread(Chan *c, void *buf, long n, vlong off) · 2 unmodified lines | ||
| 530 | 530 | } else { |
| 531 | 531 | while(!qcanread(lineq)) { |
| 532 | 532 | eol = 1; |
| 533 | − if(readcons(kbdq, &kbd.line[kbd.x], 1) == 1){ | |
| 533 | + if(qreadcons(kbdq, &kbd.line[kbd.x], 1) == 1){ | |
| 534 | 534 | eol = 0; |
| 535 | 535 | ch = kbd.line[kbd.x]; |
| 536 | 536 | switch(ch){ |
| @@ -15,6 +15,7 @@ OFILES=\ · 14 unmodified lines | ||
| 15 | 15 | convTR2M.$O\ |
| 16 | 16 | nvcsum.$O\ |
| 17 | 17 | passtokey.$O\ |
| 18 | + readcons.$O\ | |
| 18 | 19 | _asgetpakkey.$O\ |
| 19 | 20 | _asgetresp.$O\ |
| 20 | 21 | _asrequest.$O\ |
| @@ -13,7 +13,7 @@ authdial(char *netroot, char *dom) · 12 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | if(dom == nil) |
| 15 | 15 | /* look for one relative to my machine */ |
| 16 | − return dial(netmkaddr("$auth", netroot, "ticket"), 0, 0, 0); | |
| 16 | + return dial(netmkaddr("$auth", nil, "ticket"), nil, nil, nil); | |
| 17 | 17 | |
| 18 | 18 | /* look up an auth server in an authentication domain */ |
| 19 | 19 | p = csgetvalue(netroot, "authdom", dom, "auth", &t); |
| @@ -39,8 +39,7 @@ authdial(char *netroot, char *dom) · 19 unmodified lines | ||
| 39 | 39 | rv = -1; |
| 40 | 40 | for(nt = t; nt != nil; nt = nt->entry) { |
| 41 | 41 | if(strcmp(nt->attr, "auth") == 0) { |
| 42 | − p = netmkaddr(nt->val, netroot, "ticket"); | |
| 43 | − rv = dial(p, 0, 0, 0); | |
| 42 | + rv = dial(netmkaddr(nt->val, nil, "ticket"), nil, nil, nil); | |
| 44 | 43 | if(rv >= 0) |
| 45 | 44 | break; |
| 46 | 45 | } |
| @@ -0,0 +1,82 @@ | ||
| 1 | +#include <u.h> | |
| 2 | +#include <libc.h> | |
| 3 | + | |
| 4 | +/* | |
| 5 | + * prompt for a string with a possible default response | |
| 6 | + */ | |
| 7 | +char* | |
| 8 | +readcons(char *prompt, char *def, int raw) | |
| 9 | +{ | |
| 10 | + int fdin, fdout, ctl, n; | |
| 11 | + char *s, *p; | |
| 12 | + | |
| 13 | + s = p = nil; | |
| 14 | + fdout = ctl = -1; | |
| 15 | + | |
| 16 | + if((fdin = open("/dev/cons", OREAD)) < 0) | |
| 17 | + goto Out; | |
| 18 | + if((fdout = open("/dev/cons", OWRITE)) < 0) | |
| 19 | + goto Out; | |
| 20 | + | |
| 21 | + if(raw){ | |
| 22 | + if((ctl = open("/dev/consctl", OWRITE)) < 0) | |
| 23 | + goto Out; | |
| 24 | + write(ctl, "rawon", 5); | |
| 25 | + } | |
| 26 | + | |
| 27 | + if(def != nil) | |
| 28 | + fprint(fdout, "%s[%s]: ", prompt, def); | |
| 29 | + else | |
| 30 | + fprint(fdout, "%s: ", prompt); | |
| 31 | + | |
| 32 | + for(;;){ | |
| 33 | + n = p - s; | |
| 34 | + if((n % 32) == 0){ | |
| 35 | + if((p = realloc(s, n+32)) == nil) | |
| 36 | + break; | |
| 37 | + s = p, p += n; | |
| 38 | + } | |
| 39 | + | |
| 40 | + if(read(fdin, p, 1) <= 0 || *p == 0x7f) | |
| 41 | + break; | |
| 42 | + | |
| 43 | + if(*p == '\n' || *p == '\r'){ | |
| 44 | + if(p == s && def != nil){ | |
| 45 | + free(s); | |
| 46 | + s = strdup(def); | |
| 47 | + } else | |
| 48 | + *p = 0; | |
| 49 | + if(raw) | |
| 50 | + write(fdout, "\n", 1); | |
| 51 | + goto Out; | |
| 52 | + } else if(*p == '\b') { | |
| 53 | + while(p > s && (p[-1] & 0xc0) == 0x80) | |
| 54 | + *p-- = 0; | |
| 55 | + if(p > s) | |
| 56 | + *p-- = 0; | |
| 57 | + } else if(*p == 0x15) { /* ^U: line kill */ | |
| 58 | + if(def != nil) | |
| 59 | + fprint(fdout, "\n%s[%s]: ", prompt, def); | |
| 60 | + else | |
| 61 | + fprint(fdout, "\n%s: ", prompt); | |
| 62 | + while(p > s) | |
| 63 | + *p-- = 0; | |
| 64 | + } else if(*p >= ' ') | |
| 65 | + p++; | |
| 66 | + } | |
| 67 | + free(s); | |
| 68 | + s = nil; | |
| 69 | + if(raw) | |
| 70 | + write(fdout, "\n", 1); | |
| 71 | +Out: | |
| 72 | + if(ctl >= 0){ | |
| 73 | + write(ctl, "rawoff", 6); | |
| 74 | + close(ctl); | |
| 75 | + } | |
| 76 | + if(fdin >= 0) | |
| 77 | + close(fdin); | |
| 78 | + if(fdout >= 0) | |
| 79 | + close(fdout); | |
| 80 | + | |
| 81 | + return s; | |
| 82 | +} | |
| @@ -53,78 +53,6 @@ static struct { · 52 unmodified lines | ||
| 53 | 53 | "debug", "/tmp/nvram", 0, sizeof(Nvrsafe), |
| 54 | 54 | }; |
| 55 | 55 | |
| 56 | −static char* | |
| 57 | −readcons(char *prompt, char *def, int raw, char *buf, int nbuf) | |
| 58 | −{ | |
| 59 | − int fdin, fdout, ctl, n, m; | |
| 60 | − char line[10]; | |
| 61 | − | |
| 62 | − fdin = open("/dev/cons", OREAD); | |
| 63 | − if(fdin < 0) | |
| 64 | − fdin = 0; | |
| 65 | − fdout = open("/dev/cons", OWRITE); | |
| 66 | − if(fdout < 0) | |
| 67 | − fdout = 1; | |
| 68 | − if(def != nil) | |
| 69 | − fprint(fdout, "%s[%s]: ", prompt, def); | |
| 70 | − else | |
| 71 | − fprint(fdout, "%s: ", prompt); | |
| 72 | − if(raw){ | |
| 73 | − ctl = open("/dev/consctl", OWRITE); | |
| 74 | − if(ctl >= 0) | |
| 75 | − write(ctl, "rawon", 5); | |
| 76 | − } else | |
| 77 | − ctl = -1; | |
| 78 | − | |
| 79 | − m = 0; | |
| 80 | − for(;;){ | |
| 81 | − n = read(fdin, line, 1); | |
| 82 | − if(n == 0){ | |
| 83 | − close(ctl); | |
| 84 | − werrstr("readcons: EOF"); | |
| 85 | − return nil; | |
| 86 | − } | |
| 87 | − if(n < 0){ | |
| 88 | − close(ctl); | |
| 89 | − werrstr("can't read cons"); | |
| 90 | − return nil; | |
| 91 | − } | |
| 92 | − if(line[0] == 0x7f) | |
| 93 | − exits(0); | |
| 94 | − if(n == 0 || line[0] == '\n' || line[0] == '\r'){ | |
| 95 | − if(raw){ | |
| 96 | − write(ctl, "rawoff", 6); | |
| 97 | − write(fdout, "\n", 1); | |
| 98 | − close(ctl); | |
| 99 | − } | |
| 100 | − buf[m] = '\0'; | |
| 101 | − if(buf[0]=='\0' && def) | |
| 102 | − strcpy(buf, def); | |
| 103 | − return buf; | |
| 104 | − } | |
| 105 | − if(line[0] == '\b'){ | |
| 106 | − if(m > 0) | |
| 107 | − m--; | |
| 108 | − }else if(line[0] == 0x15){ /* ^U: line kill */ | |
| 109 | − m = 0; | |
| 110 | − if(def != nil) | |
| 111 | − fprint(fdout, "%s[%s]: ", prompt, def); | |
| 112 | − else | |
| 113 | − fprint(fdout, "%s: ", prompt); | |
| 114 | − }else{ | |
| 115 | − if(m >= nbuf-1){ | |
| 116 | − fprint(fdout, "line too long\n"); | |
| 117 | − m = 0; | |
| 118 | − if(def != nil) | |
| 119 | − fprint(fdout, "%s[%s]: ", prompt, def); | |
| 120 | − else | |
| 121 | − fprint(fdout, "%s: ", prompt); | |
| 122 | − }else | |
| 123 | − buf[m++] = line[0]; | |
| 124 | − } | |
| 125 | − } | |
| 126 | −} | |
| 127 | − | |
| 128 | 56 | typedef struct { |
| 129 | 57 | int fd; |
| 130 | 58 | int safelen; |
| @@ -211,6 +139,29 @@ findnvram(Nvrwhere *locp) · 80 unmodified lines | ||
| 211 | 139 | locp->safeoff = safeoff; |
| 212 | 140 | } |
| 213 | 141 | |
| 142 | +static int | |
| 143 | +ask(char *prompt, char *buf, int len, int raw) | |
| 144 | +{ | |
| 145 | + char *s; | |
| 146 | + int n; | |
| 147 | + | |
| 148 | + memset(buf, 0, len); | |
| 149 | + for(;;){ | |
| 150 | + if((s = readcons(prompt, nil, raw)) == nil) | |
| 151 | + return -1; | |
| 152 | + if((n = strlen(s)) >= len) | |
| 153 | + fprint(2, "%s longer than %d characters; try again\n", prompt, len-1); | |
| 154 | + else { | |
| 155 | + memmove(buf, s, n); | |
| 156 | + memset(s, 0, n); | |
| 157 | + free(s); | |
| 158 | + return 0; | |
| 159 | + } | |
| 160 | + memset(s, 0, n); | |
| 161 | + free(s); | |
| 162 | + } | |
| 163 | +} | |
| 164 | + | |
| 214 | 165 | /* |
| 215 | 166 | * get key info out of nvram. since there isn't room in the PC's nvram use |
| 216 | 167 | * a disk partition there. |
| @@ -219,7 +170,7 @@ int · 2 unmodified lines | ||
| 219 | 170 | readnvram(Nvrsafe *safep, int flag) |
| 220 | 171 | { |
| 221 | 172 | int err; |
| 222 | − char buf[512], in[128]; /* 512 for floppy i/o */ | |
| 173 | + char buf[512]; /* 512 for floppy i/o */ | |
| 223 | 174 | Nvrsafe *safe; |
| 224 | 175 | Nvrwhere loc; |
| 225 | 176 | |
| @@ -294,22 +245,22 @@ readnvram(Nvrsafe *safep, int flag) · 68 unmodified lines | ||
| 294 | 245 | |
| 295 | 246 | if((flag&(NVwrite|NVwritemem)) || (err && (flag&NVwriteonerr))){ |
| 296 | 247 | if (!(flag&NVwritemem)) { |
| 297 | − readcons("authid", nil, 0, safe->authid, | |
| 298 | − sizeof safe->authid); | |
| 299 | − readcons("authdom", nil, 0, safe->authdom, | |
| 300 | − sizeof safe->authdom); | |
| 301 | − readcons("secstore key", nil, 1, safe->config, | |
| 302 | − sizeof safe->config); | |
| 303 | − for(;;){ | |
| 304 | − Authkey k; | |
| 248 | + char pass[PASSWDLEN]; | |
| 249 | + Authkey k; | |
| 305 | 250 | |
| 306 | − if(readcons("password", nil, 1, in, sizeof in) == nil) | |
| 307 | − goto Out; | |
| 308 | − passtokey(&k, in); | |
| 309 | − memmove(safe->machkey, k.des, DESKEYLEN); | |
| 310 | − memmove(safe->aesmachkey, k.aes, AESKEYLEN); | |
| 311 | − break; | |
| 312 | − } | |
| 251 | + if(ask("authid", safe->authid, sizeof safe->authid, 0)) | |
| 252 | + goto Out; | |
| 253 | + if(ask("authdom", safe->authdom, sizeof safe->authdom, 0)) | |
| 254 | + goto Out; | |
| 255 | + if(ask("secstore key", safe->config, sizeof safe->config, 1)) | |
| 256 | + goto Out; | |
| 257 | + if(ask("password", pass, sizeof pass, 1)) | |
| 258 | + goto Out; | |
| 259 | + passtokey(&k, pass); | |
| 260 | + memset(pass, 0, sizeof pass); | |
| 261 | + memmove(safe->machkey, k.des, DESKEYLEN); | |
| 262 | + memmove(safe->aesmachkey, k.aes, AESKEYLEN); | |
| 263 | + memset(&k, 0, sizeof k); | |
| 313 | 264 | } |
| 314 | 265 | |
| 315 | 266 | safe->machsum = nvcsum(safe->machkey, DESKEYLEN); |
| @@ -1,110 +0,0 @@ | ||
| 1 | −#include <u.h> | |
| 2 | −#include <libc.h> | |
| 3 | −#include "drawterm.h" | |
| 4 | − | |
| 5 | −void* | |
| 6 | −erealloc(void *v, ulong n) | |
| 7 | −{ | |
| 8 | − v = realloc(v, n); | |
| 9 | − if(v == nil && n != 0) | |
| 10 | − sysfatal("out of memory"); | |
| 11 | − return v; | |
| 12 | −} | |
| 13 | − | |
| 14 | −char* | |
| 15 | −estrdup(char *s) | |
| 16 | −{ | |
| 17 | − s = strdup(s); | |
| 18 | − if(s == nil) | |
| 19 | − sysfatal("out of memory"); | |
| 20 | − return s; | |
| 21 | −} | |
| 22 | − | |
| 23 | −char* | |
| 24 | −estrappend(char *s, char *fmt, ...) | |
| 25 | −{ | |
| 26 | − char *t; | |
| 27 | − va_list arg; | |
| 28 | − | |
| 29 | − va_start(arg, fmt); | |
| 30 | − t = vsmprint(fmt, arg); | |
| 31 | − if(t == nil) | |
| 32 | − sysfatal("out of memory"); | |
| 33 | − va_end(arg); | |
| 34 | − s = erealloc(s, strlen(s)+strlen(t)+1); | |
| 35 | − strcat(s, t); | |
| 36 | − free(t); | |
| 37 | − return s; | |
| 38 | −} | |
| 39 | − | |
| 40 | −/* | |
| 41 | − * prompt for a string with a possible default response | |
| 42 | − */ | |
| 43 | −char* | |
| 44 | −readcons(char *prompt, char *def, int raw) | |
| 45 | −{ | |
| 46 | − int fdin, fdout, ctl, n; | |
| 47 | − char line[10]; | |
| 48 | − char *s; | |
| 49 | − | |
| 50 | − fdin = open("/dev/cons", OREAD); | |
| 51 | − if(fdin < 0) | |
| 52 | − fdin = 0; | |
| 53 | − fdout = open("/dev/cons", OWRITE); | |
| 54 | − if(fdout < 0) | |
| 55 | − fdout = 1; | |
| 56 | − if(def != nil) | |
| 57 | − fprint(fdout, "%s[%s]: ", prompt, def); | |
| 58 | − else | |
| 59 | − fprint(fdout, "%s: ", prompt); | |
| 60 | − if(raw){ | |
| 61 | − ctl = open("/dev/consctl", OWRITE); | |
| 62 | − if(ctl >= 0) | |
| 63 | − write(ctl, "rawon", 5); | |
| 64 | − } else | |
| 65 | − ctl = -1; | |
| 66 | − s = estrdup(""); | |
| 67 | − for(;;){ | |
| 68 | − n = read(fdin, line, 1); | |
| 69 | − if(n == 0){ | |
| 70 | − Error: | |
| 71 | − close(fdin); | |
| 72 | − close(fdout); | |
| 73 | − if(ctl >= 0) | |
| 74 | − close(ctl); | |
| 75 | − free(s); | |
| 76 | − return nil; | |
| 77 | − } | |
| 78 | − if(n < 0) | |
| 79 | − goto Error; | |
| 80 | − if(line[0] == 0x7f) | |
| 81 | − goto Error; | |
| 82 | − if(n == 0 || line[0] == '\n' || line[0] == '\r'){ | |
| 83 | − if(raw){ | |
| 84 | − write(ctl, "rawoff", 6); | |
| 85 | − write(fdout, "\n", 1); | |
| 86 | − } | |
| 87 | − close(ctl); | |
| 88 | − close(fdin); | |
| 89 | − close(fdout); | |
| 90 | − if(*s == 0 && def != nil) | |
| 91 | − s = estrappend(s, "%s", def); | |
| 92 | − return s; | |
| 93 | − } | |
| 94 | − if(line[0] == '\b'){ | |
| 95 | − if(strlen(s) > 0) | |
| 96 | − s[strlen(s)-1] = 0; | |
| 97 | − } else if(line[0] == 0x15) { /* ^U: line kill */ | |
| 98 | − if(def != nil) | |
| 99 | − fprint(fdout, "\n%s[%s]: ", prompt, def); | |
| 100 | − else | |
| 101 | − fprint(fdout, "\n%s: ", prompt); | |
| 102 | − | |
| 103 | − s[0] = 0; | |
| 104 | − } else { | |
| 105 | − s = estrappend(s, "%c", line[0]); | |
| 106 | − } | |
| 107 | − } | |
| 108 | − return nil; /* not reached */ | |
| 109 | −} | |
| 110 | − | |
| @@ -7,6 +7,7 @@ · 6 unmodified lines | ||
| 7 | 7 | #include <libc.h> |
| 8 | 8 | #include <mp.h> |
| 9 | 9 | #include <libsec.h> |
| 10 | +#include <authsrv.h> | |
| 10 | 11 | #include "drawterm.h" |
| 11 | 12 | |
| 12 | 13 | static void* |
| @@ -185,7 +186,7 @@ verify(uchar secret[SHA1dlen], uchar *data, int len, int seqno, uchar d[SHA1dlen · 172 unmodified lines | ||
| 185 | 186 | sha1(secret, SHA1dlen, nil, &sha); |
| 186 | 187 | sha1(data, len, nil, &sha); |
| 187 | 188 | sha1(seq, 4, digest, &sha); |
| 188 | − return memcmp(d, digest, SHA1dlen); | |
| 189 | + return tsmemcmp(d, digest, SHA1dlen); | |
| 189 | 190 | } |
| 190 | 191 | |
| 191 | 192 | static int |