5 #include "authcmdlib.h"
8 main(int argc, char **argv)
28 s = strchr(user, '@');
35 fd = authdial(nil, s);
37 error("authdial: %r");
39 memset(&tr, 0, sizeof(tr));
40 strncpy(tr.uid, user, sizeof(tr.uid)-1);
44 * get a password from the user and try to decrypt the
45 * ticket. If it doesn't work we've got a bad password,
48 memset(&pr, 0, sizeof(pr));
49 getpass(&key, pr.old, 0, 0);
52 * negotiate PAK key. we need to retry in case the AS does
53 * not support the AuthPAK request or when the user has
54 * not yet setup a new key and the AS made one up.
57 authpak_hash(&key, tr.uid);
58 if(_asgetpakkey(fd, &tr, &key) < 0){
62 fd = authdial(nil, s);
64 error("authdial: %r");
66 /* send ticket request to AS */
67 if(_asrequest(fd, &tr) < 0)
69 if(_asgetresp(fd, &t, nil, &key) < 0)
71 if(t.num != AuthTp || strcmp(t.cuid, tr.uid) != 0){
74 error("bad password");
77 /* loop trying new passwords */
79 memset(pr.new, 0, sizeof(pr.new));
80 if(answer("change Plan 9 Password?"))
81 getpass(nil, pr.new, 0, 1);
82 pr.changesecret = answer("change Inferno/POP secret?");
84 if(answer("make it the same as your plan 9 password?")){
86 strcpy(pr.secret, pr.new);
88 strcpy(pr.secret, pr.old);
90 getpass(nil, pr.secret, 0, 1);
94 n = convPR2M(&pr, buf, sizeof(buf), &t);
95 if(write(fd, buf, n) != n)
96 error("AS protocol botch: %r");
97 if(_asrdresp(fd, buf, 0) == 0)
99 fprint(2, "passwd: refused: %r\n");