|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 1794 (0x702) Types: TextFile Notes: UNIX file Names: »enroll.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code └─⟦f4b8d8c84⟧ UNIX Filesystem └─⟦this⟧ »cmd/knapsack/enroll.c«
/* * Enroll users in the knapsack system. */ #include <stdio.h> #include <signal.h> #include "knapsack.h" static struct knapsack k; static mint key[K]; static mint t; static char s1[PPSIZ], s2[PPSIZ]; /* passphrase buffers */ char *getlogin(); main(ac, av) int ac; char *av[]; { register int i; register char *pname; register FILE *f; switch (ac) { case 1: if ((pname = getlogin()) == NULL) byebye(1, "Who are you?"); break; case 2: pname = av[1]; break; default: fputs("Usage: enroll [user]\n", stderr); break; } pname = pubkeyfile(pname); /* * Is the user already enrolled? If so verify that he knows the * passphrase that generates the public key stored in pathname. */ if ((f = fopen(pname, "r")) != NULL) { gpph("Current Passphrase: ", s1); knapsack(&k, s1); public(key, &k); for (i = 0; i < K; ++i) { pkin(&t, f); if (mcmp(&t, &key[i]) != 0) byebye(2, "Passphrase does not fit public key."); } fclose(f); } /* * Get new passphrase, get a second copy and check for typos. * If passphrase is empty remove the public key file. */ gpph("New Passphrase: ", s1); gpph("Repeat, please: ", s2); if (strcmp(s1, s2) != 0) byebye(2, "Passphrase not changed."); if (s1[0] == '\0') { unlink(pname); exit(0); } /* * Catch signals while we are rewriting the public key file. */ signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGTERM, SIG_IGN); /* * Create a new public key file. */ if ((f = fopen(pname, "w")) == NULL) byebye(3, "Cannot open public key file for writing."); knapsack(&k, s1); public(key, &k); for (i = 0; i < K; ++i) pkout(&key[i], f); return (0); } static byebye(n, s) int n; char *s; { fputs(s, stderr); putc('\n', stderr); exit(n); }