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