| @@ -13,7 +13,6 @@ · 12 unmodified lines |
| 13 | | 13 | |
| 14 | #define MaxStr 128 | 14 | #define MaxStr 128 |
| 15 | | 15 | |
| 16 | static void fatal(int, char*, ...); | | |
| 17 | static void usage(void); | 16 | static void usage(void); |
| 18 | static void writestr(int, char*, char*, int); | 17 | static void writestr(int, char*, char*, int); |
| 19 | static int readstr(int, char*, int); | 18 | static int readstr(int, char*, int); |
| @@ -37,10 +36,10 @@ static int p9authtls(int); · 17 unmodified lines |
| 37 | char *authserver; | 36 | char *authserver; |
| 38 | char *secstore; | 37 | char *secstore; |
| 39 | | 38 | |
| 40 | void | 39 | static void |
| 41 | exits(char *s) | 40 | ending(void) |
| 42 | { | 41 | { |
| 43 | exit(1); | 42 | panic("ending"); |
| 44 | } | 43 | } |
| 45 | | 44 | |
| 46 | void | 45 | void |
| @@ -98,7 +97,7 @@ startaan(char *host, int fd) · 51 unmodified lines |
| 98 | int n; | 97 | int n; |
| 99 | | 98 | |
| 100 | if(fprint(fd, "%7ld\n%s", strlen(script), script) < 0) | 99 | if(fprint(fd, "%7ld\n%s", strlen(script), script) < 0) |
| 101 | fatal(1, "sending aan script"); | 100 | sysfatal("sending aan script: %r"); |
| 102 | n = read(fd, buf, sizeof(buf)-1); | 101 | n = read(fd, buf, sizeof(buf)-1); |
| 103 | close(fd); | 102 | close(fd); |
| 104 | | 103 | |
| @@ -139,17 +138,17 @@ rcpu(char *host) · 34 unmodified lines |
| 139 | if(aanfilter){ | 138 | if(aanfilter){ |
| 140 | fd = startaan(host, fd); | 139 | fd = startaan(host, fd); |
| 141 | if(fd < 0) | 140 | if(fd < 0) |
| 142 | fatal(1, "startaan"); | 141 | sysfatal("startaan: %r"); |
| 143 | fd = p9authtls(fd); | 142 | fd = p9authtls(fd); |
| 144 | } | 143 | } |
| 145 | memset(secstorebuf, 0, sizeof(secstorebuf)); /* forget secstore secrets */ | 144 | memset(secstorebuf, 0, sizeof(secstorebuf)); /* forget secstore secrets */ |
| 146 | | 145 | |
| 147 | if(fprint(fd, "%7ld\n%s", strlen(script), script) < 0) | 146 | if(fprint(fd, "%7ld\n%s", strlen(script), script) < 0) |
| 148 | fatal(1, "sending script"); | 147 | sysfatal("sending script: %r"); |
| 149 | | 148 | |
| 150 | /* Begin serving the namespace */ | 149 | /* Begin serving the namespace */ |
| 151 | exportfs(fd); | 150 | exportfs(fd); |
| 152 | fatal(1, "starting exportfs"); | 151 | sysfatal("starting exportfs: %r"); |
| 153 | } | 152 | } |
| 154 | | 153 | |
| 155 | void | 154 | void |
| @@ -169,9 +168,9 @@ ncpu(char *host) · 13 unmodified lines |
| 169 | } | 168 | } |
| 170 | writestr(fd, buf, "negotiating authentication method", 0); | 169 | writestr(fd, buf, "negotiating authentication method", 0); |
| 171 | if(readstr(fd, buf, sizeof buf) < 0) | 170 | if(readstr(fd, buf, sizeof buf) < 0) |
| 172 | fatal(1, "can't negotiate authentication method: %r"); | 171 | sysfatal("can't negotiate authentication method: %r"); |
| 173 | if(*buf) | 172 | if(*buf) |
| 174 | fatal(1, "%s", buf); | 173 | sysfatal("%s", buf); |
| 175 | | 174 | |
| 176 | /* authenticate and encrypt the channel */ | 175 | /* authenticate and encrypt the channel */ |
| 177 | fd = p9authssl(fd); | 176 | fd = p9authssl(fd); |
| @@ -187,14 +186,14 @@ ncpu(char *host) · 9 unmodified lines |
| 187 | * of /mnt/term | 186 | * of /mnt/term |
| 188 | */ | 187 | */ |
| 189 | if(readstr(fd, buf, sizeof(buf)) < 0) | 188 | if(readstr(fd, buf, sizeof(buf)) < 0) |
| 190 | fatal(1, "waiting for FS: %r"); | 189 | sysfatal("waiting for FS: %r"); |
| 191 | if(strncmp("FS", buf, 2) != 0) { | 190 | if(strncmp("FS", buf, 2) != 0) { |
| 192 | print("remote cpu: %s", buf); | 191 | print("remote cpu: %s", buf); |
| 193 | exits(buf); | 192 | exits(buf); |
| 194 | } | 193 | } |
| 195 | | 194 | |
| 196 | if(readstr(fd, buf, sizeof(buf)) < 0) | 195 | if(readstr(fd, buf, sizeof(buf)) < 0) |
| 197 | fatal(1, "waiting for remote export: %r"); | 196 | sysfatal("waiting for remote export: %r"); |
| 198 | if(strcmp(buf, "/") != 0){ | 197 | if(strcmp(buf, "/") != 0){ |
| 199 | print("remote cpu: %s", buf); | 198 | print("remote cpu: %s", buf); |
| 200 | exits(buf); | 199 | exits(buf); |
| @@ -203,7 +202,7 @@ ncpu(char *host) · 2 unmodified lines |
| 203 | | 202 | |
| 204 | /* Begin serving the gnot namespace */ | 203 | /* Begin serving the gnot namespace */ |
| 205 | exportfs(fd); | 204 | exportfs(fd); |
| 206 | fatal(1, "starting exportfs"); | 205 | sysfatal("starting exportfs: %r"); |
| 207 | } | 206 | } |
| 208 | | 207 | |
| 209 | void | 208 | void |
| @@ -267,19 +266,23 @@ cpumain(int argc, char **argv) · 57 unmodified lines |
| 267 | panic("bind #i: %r"); | 266 | panic("bind #i: %r"); |
| 268 | if(bind("#m", "/dev", MBEFORE) < 0) | 267 | if(bind("#m", "/dev", MBEFORE) < 0) |
| 269 | panic("bind #m: %r"); | 268 | panic("bind #m: %r"); |
| | 269 | atexit(ending); |
| 270 | } | 270 | } |
| 271 | | 271 | |
| 272 | if(bind("/root", "/", MAFTER) < 0) | 272 | if(bind("/root", "/", MAFTER) < 0) |
| 273 | panic("bind /root: %r"); | 273 | panic("bind /root: %r"); |
| 274 | | 274 | |
| 275 | if(host == nil) | 275 | if(host == nil) |
| 276 | host = readcons("cpu", "cpu", 0); | 276 | if((host = readcons("cpu", "cpu", 0)) == nil) |
| 277 | | 277 | sysfatal("user terminated input"); |
| 278 | if(user == nil) | | |
| 279 | user = readcons("user", "glenda", 0); | | |
| 280 | | 278 | |
| 281 | if(authserver == nil) | 279 | if(authserver == nil) |
| 282 | authserver = readcons("auth", host, 0); | 280 | if((authserver = readcons("auth", host, 0)) == nil) |
| | 281 | sysfatal("user terminated input"); |
| | 282 | |
| | 283 | if(user == nil) |
| | 284 | if((user = readcons("user", "glenda", 0)) == nil) |
| | 285 | sysfatal("user terminated input"); |
| 283 | | 286 | |
| 284 | if(mountfactotum() < 0){ | 287 | if(mountfactotum() < 0){ |
| 285 | if(secstore == nil) | 288 | if(secstore == nil) |
| @@ -299,27 +302,7 @@ cpumain(int argc, char **argv) · 13 unmodified lines |
| 299 | | 302 | |
| 300 | ncpu(host); | 303 | ncpu(host); |
| 301 | | 304 | |
| 302 | fatal(1, "can't dial %s: %r", host); | 305 | sysfatal("can't dial %s: %r", host); |
| 303 | } | | |
| 304 | | | |
| 305 | void | | |
| 306 | fatal(int syserr, char *fmt, ...) | | |
| 307 | { | | |
| 308 | Fmt f; | | |
| 309 | char *str; | | |
| 310 | va_list arg; | | |
| 311 | | | |
| 312 | fmtstrinit(&f); | | |
| 313 | fmtprint(&f, "cpu: "); | | |
| 314 | va_start(arg, fmt); | | |
| 315 | fmtvprint(&f, fmt, arg); | | |
| 316 | va_end(arg); | | |
| 317 | if(syserr) | | |
| 318 | fmtprint(&f, ": %r"); | | |
| 319 | fmtprint(&f, "\n"); | | |
| 320 | str = fmtstrflush(&f); | | |
| 321 | write(2, str, strlen(str)); | | |
| 322 | exits(str); | | |
| 323 | } | 306 | } |
| 324 | | 307 | |
| 325 | void | 308 | void |
| @@ -330,7 +313,7 @@ writestr(int fd, char *str, char *thing, int ignore) · 4 unmodified lines |
| 330 | l = strlen(str); | 313 | l = strlen(str); |
| 331 | n = write(fd, str, l+1); | 314 | n = write(fd, str, l+1); |
| 332 | if(!ignore && n < 0) | 315 | if(!ignore && n < 0) |
| 333 | fatal(1, "writing network: %s", thing); | 316 | sysfatal("writing network: %s: %r", thing); |
| 334 | } | 317 | } |
| 335 | | 318 | |
| 336 | int | 319 | int |
| @@ -372,13 +355,13 @@ p9authssl(int fd) · 35 unmodified lines |
| 372 | ai = p9any(fd); | 355 | ai = p9any(fd); |
| 373 | memset(secstorebuf, 0, sizeof(secstorebuf)); /* forget secstore secrets */ | 356 | memset(secstorebuf, 0, sizeof(secstorebuf)); /* forget secstore secrets */ |
| 374 | if(ai == nil) | 357 | if(ai == nil) |
| 375 | fatal(1, "can't authenticate"); | 358 | sysfatal("can't authenticate: %r"); |
| 376 | | 359 | |
| 377 | if(ealgs == nil) | 360 | if(ealgs == nil) |
| 378 | return fd; | 361 | return fd; |
| 379 | | 362 | |
| 380 | if(ai->nsecret < 8){ | 363 | if(ai->nsecret < 8){ |
| 381 | fatal(1, "p9authssl: secret too small"); | 364 | sysfatal("p9authssl: secret too small"); |
| 382 | return -1; | 365 | return -1; |
| 383 | } | 366 | } |
| 384 | memmove(key+4, ai->secret, 8); | 367 | memmove(key+4, ai->secret, 8); |
| @@ -386,11 +369,11 @@ p9authssl(int fd) · 1 unmodified line |
| 386 | /* exchange random numbers */ | 369 | /* exchange random numbers */ |
| 387 | genrandom(key, 4); | 370 | genrandom(key, 4); |
| 388 | if(write(fd, key, 4) != 4){ | 371 | if(write(fd, key, 4) != 4){ |
| 389 | fatal(1, "p9authssl: write random: %r"); | 372 | sysfatal("p9authssl: write random: %r"); |
| 390 | return -1; | 373 | return -1; |
| 391 | } | 374 | } |
| 392 | if(readn(fd, key+12, 4) != 4){ | 375 | if(readn(fd, key+12, 4) != 4){ |
| 393 | fatal(1, "p9authssl: read random: %r"); | 376 | sysfatal("p9authssl: read random: %r"); |
| 394 | return -1; | 377 | return -1; |
| 395 | } | 378 | } |
| 396 | | 379 | |
| @@ -402,7 +385,7 @@ p9authssl(int fd) · 5 unmodified lines |
| 402 | /* set up encryption */ | 385 | /* set up encryption */ |
| 403 | fd = pushssl(fd, ealgs, fromclientsecret, fromserversecret, nil); | 386 | fd = pushssl(fd, ealgs, fromclientsecret, fromserversecret, nil); |
| 404 | if(fd < 0) | 387 | if(fd < 0) |
| 405 | fatal(1, "p9authssl: pushssl: %r"); | 388 | sysfatal("p9authssl: pushssl: %r"); |
| 406 | | 389 | |
| 407 | return fd; | 390 | return fd; |
| 408 | } | 391 | } |
| @@ -418,7 +401,7 @@ p9authtls(int fd) · 9 unmodified lines |
| 418 | | 401 | |
| 419 | ai = p9any(fd); | 402 | ai = p9any(fd); |
| 420 | if(ai == nil) | 403 | if(ai == nil) |
| 421 | fatal(1, "can't authenticate"); | 404 | sysfatal("can't authenticate: %r"); |
| 422 | | 405 | |
| 423 | conn = mallocz(sizeof(TLSconn), 1); | 406 | conn = mallocz(sizeof(TLSconn), 1); |
| 424 | conn->pskID = "p9secret"; | 407 | conn->pskID = "p9secret"; |
| @@ -427,7 +410,7 @@ p9authtls(int fd) · 2 unmodified lines |
| 427 | | 410 | |
| 428 | fd = tlsClient(fd, conn); | 411 | fd = tlsClient(fd, conn); |
| 429 | if(fd < 0) | 412 | if(fd < 0) |
| 430 | fatal(1, "tlsClient"); | 413 | sysfatal("tlsClient: %r"); |
| 431 | | 414 | |
| 432 | auth_freeAI(ai); | 415 | auth_freeAI(ai); |
| 433 | free(conn->sessionID); | 416 | free(conn->sessionID); |
| @@ -627,7 +610,7 @@ p9any(int fd) · 193 unmodified lines |
| 627 | werrstr(""); | 610 | werrstr(""); |
| 628 | | 611 | |
| 629 | if(readstr(fd, buf, sizeof buf) < 0) | 612 | if(readstr(fd, buf, sizeof buf) < 0) |
| 630 | fatal(1, "cannot read p9any negotiation"); | 613 | sysfatal("cannot read p9any negotiation: %r"); |
| 631 | bbuf = buf; | 614 | bbuf = buf; |
| 632 | v2 = 0; | 615 | v2 = 0; |
| 633 | if(strncmp(buf, "v.2 ", 4) == 0){ | 616 | if(strncmp(buf, "v.2 ", 4) == 0){ |
| @@ -640,7 +623,7 @@ p9any(int fd) · 6 unmodified lines |
| 640 | if((p = strchr(bbuf, ' '))) | 623 | if((p = strchr(bbuf, ' '))) |
| 641 | *p++ = 0; | 624 | *p++ = 0; |
| 642 | if((dom = strchr(bbuf, '@')) == nil) | 625 | if((dom = strchr(bbuf, '@')) == nil) |
| 643 | fatal(1, "bad p9any domain"); | 626 | sysfatal("bad p9any domain"); |
| 644 | *dom++ = 0; | 627 | *dom++ = 0; |
| 645 | if(strcmp(bbuf, "p9sk1") == 0 || strcmp(bbuf, "dp9ik") == 0){ | 628 | if(strcmp(bbuf, "p9sk1") == 0 || strcmp(bbuf, "dp9ik") == 0){ |
| 646 | proto = bbuf; | 629 | proto = bbuf; |
| @@ -652,32 +635,32 @@ p9any(int fd) · 5 unmodified lines |
| 652 | bbuf = p; | 635 | bbuf = p; |
| 653 | } | 636 | } |
| 654 | if(proto == nil) | 637 | if(proto == nil) |
| 655 | fatal(1, "server did not offer p9sk1 or dp9ik"); | 638 | sysfatal("server did not offer p9sk1 or dp9ik"); |
| 656 | proto = estrdup(proto); | 639 | proto = estrdup(proto); |
| 657 | sprint(buf2, "%s %s", proto, dom); | 640 | sprint(buf2, "%s %s", proto, dom); |
| 658 | if(write(fd, buf2, strlen(buf2)+1) != strlen(buf2)+1) | 641 | if(write(fd, buf2, strlen(buf2)+1) != strlen(buf2)+1) |
| 659 | fatal(1, "cannot write user/domain choice in p9any"); | 642 | sysfatal("cannot write user/domain choice in p9any"); |
| 660 | if(v2){ | 643 | if(v2){ |
| 661 | if(readstr(fd, buf, sizeof buf) < 0) | 644 | if(readstr(fd, buf, sizeof buf) < 0) |
| 662 | fatal(1, "cannot read OK in p9any"); | 645 | sysfatal("cannot read OK in p9any: %r"); |
| 663 | if(memcmp(buf, "OK\0", 3) != 0) | 646 | if(memcmp(buf, "OK\0", 3) != 0) |
| 664 | fatal(1, "did not get OK in p9any: got %s", buf); | 647 | sysfatal("did not get OK in p9any: got %s", buf); |
| 665 | } | 648 | } |
| 666 | genrandom(crand, 2*NONCELEN); | 649 | genrandom(crand, 2*NONCELEN); |
| 667 | genrandom(cchal, CHALLEN); | 650 | genrandom(cchal, CHALLEN); |
| 668 | if(write(fd, cchal, CHALLEN) != CHALLEN) | 651 | if(write(fd, cchal, CHALLEN) != CHALLEN) |
| 669 | fatal(1, "cannot write p9sk1 challenge"); | 652 | sysfatal("cannot write p9sk1 challenge: %r"); |
| 670 | | 653 | |
| 671 | n = TICKREQLEN; | 654 | n = TICKREQLEN; |
| 672 | if(dp9ik) | 655 | if(dp9ik) |
| 673 | n += PAKYLEN; | 656 | n += PAKYLEN; |
| 674 | | 657 | |
| 675 | if(readn(fd, trbuf, n) != n || convM2TR(trbuf, TICKREQLEN, &tr) <= 0) | 658 | if(readn(fd, trbuf, n) != n || convM2TR(trbuf, TICKREQLEN, &tr) <= 0) |
| 676 | fatal(1, "cannot read ticket request in p9sk1"); | 659 | sysfatal("cannot read ticket request in p9sk1: %r"); |
| 677 | | 660 | |
| 678 | if(!findkey(&authkey, user, tr.authdom, proto)){ | 661 | if(!findkey(&authkey, user, tr.authdom, proto)){ |
| 679 | again: if(!getkey(&authkey, user, tr.authdom, proto)) | 662 | again: if(!getkey(&authkey, user, tr.authdom, proto)) |
| 680 | fatal(1, "no password"); | 663 | sysfatal("no password"); |
| 681 | } | 664 | } |
| 682 | | 665 | |
| 683 | strecpy(tr.hostid, tr.hostid+sizeof tr.hostid, user); | 666 | strecpy(tr.hostid, tr.hostid+sizeof tr.hostid, user); |
| @@ -690,7 +673,7 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 6 unmodified lines |
| 690 | n = gettickets(&authkey, &tr, nil, tbuf, sizeof(tbuf)); | 673 | n = gettickets(&authkey, &tr, nil, tbuf, sizeof(tbuf)); |
| 691 | } | 674 | } |
| 692 | if(n <= 0) | 675 | if(n <= 0) |
| 693 | fatal(1, "cannot get auth tickets in p9sk1"); | 676 | sysfatal("cannot get auth tickets in p9sk1: %r"); |
| 694 | | 677 | |
| 695 | m = convM2T(tbuf, n, &t, &authkey); | 678 | m = convM2T(tbuf, n, &t, &authkey); |
| 696 | if(m <= 0 || t.num != AuthTc){ | 679 | if(m <= 0 || t.num != AuthTc){ |
| @@ -701,7 +684,7 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 4 unmodified lines |
| 701 | memmove(tbuf, tbuf+m, n); | 684 | memmove(tbuf, tbuf+m, n); |
| 702 | | 685 | |
| 703 | if(dp9ik && write(fd, y, PAKYLEN) != PAKYLEN) | 686 | if(dp9ik && write(fd, y, PAKYLEN) != PAKYLEN) |
| 704 | fatal(1, "cannot send authpak public key back"); | 687 | sysfatal("cannot send authpak public key back: %r"); |
| 705 | | 688 | |
| 706 | auth.num = AuthAc; | 689 | auth.num = AuthAc; |
| 707 | memmove(auth.rand, crand, NONCELEN); | 690 | memmove(auth.rand, crand, NONCELEN); |
| @@ -710,11 +693,11 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 2 unmodified lines |
| 710 | n += m; | 693 | n += m; |
| 711 | | 694 | |
| 712 | if(write(fd, tbuf, n) != n) | 695 | if(write(fd, tbuf, n) != n) |
| 713 | fatal(1, "cannot send ticket and authenticator back"); | 696 | sysfatal("cannot send ticket and authenticator back: %r"); |
| 714 | | 697 | |
| 715 | if((n=readn(fd, tbuf, m)) != m || memcmp(tbuf, "cpu:", 4) == 0){ | 698 | if((n=readn(fd, tbuf, m)) != m || memcmp(tbuf, "cpu:", 4) == 0){ |
| 716 | if(n <= 4) | 699 | if(n <= 4) |
| 717 | fatal(1, "cannot read authenticator"); | 700 | sysfatal("cannot read authenticator"); |
| 718 | | 701 | |
| 719 | /* | 702 | /* |
| 720 | * didn't send back authenticator: | 703 | * didn't send back authenticator: |
| @@ -725,15 +708,14 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 4 unmodified lines |
| 725 | if(i > 0) | 708 | if(i > 0) |
| 726 | n += i; | 709 | n += i; |
| 727 | buf[n] = 0; | 710 | buf[n] = 0; |
| 728 | werrstr(""); | 711 | sysfatal("server says: %s", buf); |
| 729 | fatal(0, "server says: %s", buf); | | |
| 730 | } | 712 | } |
| 731 | | 713 | |
| 732 | if(convM2A(tbuf, n, &auth, &t) <= 0 | 714 | if(convM2A(tbuf, n, &auth, &t) <= 0 |
| 733 | || auth.num != AuthAs || tsmemcmp(auth.chal, cchal, CHALLEN) != 0){ | 715 | || auth.num != AuthAs || tsmemcmp(auth.chal, cchal, CHALLEN) != 0){ |
| 734 | print("?you and auth server agree about password.\n"); | 716 | print("?you and auth server agree about password.\n"); |
| 735 | print("?server is confused.\n"); | 717 | print("?server is confused.\n"); |
| 736 | fatal(0, "server lies got %llux want %llux", *(vlong*)auth.chal, *(vlong*)cchal); | 718 | sysfatal("server lies"); |
| 737 | } | 719 | } |
| 738 | memmove(crand+NONCELEN, auth.rand, NONCELEN); | 720 | memmove(crand+NONCELEN, auth.rand, NONCELEN); |
| 739 | | 721 | |