6 static char *pbmsg = "AS protocol botch";
9 asrdresp(int fd, char *buf, int len)
13 if(read(fd, buf, 1) != 1){
20 if(readn(fd, buf, len) < 0){
26 if(readn(fd, error, AERRLEN) < 0){
41 readln(char *prompt, char *buf, int nbuf, int secret)
45 p = readcons(prompt, nil, secret);
47 sysfatal("user terminated input");
51 memset(p, 0, strlen(p));
56 main(int argc, char **argv)
75 s = strchr(user, '@');
82 fd = authdial(nil, s);
84 sysfatal("protocol botch: %r");
86 /* send ticket request to AS */
87 memset(&tr, 0, sizeof(tr));
91 if(write(fd, buf, TICKREQLEN) != TICKREQLEN)
92 sysfatal("protocol botch: %r");
93 if(asrdresp(fd, buf, TICKETLEN) < 0)
95 memmove(tbuf, buf, TICKETLEN);
98 * get a password from the user and try to decrypt the
99 * ticket. If it doesn't work we've got a bad password,
102 readln("Plan 9 Password", pr.old, sizeof pr.old, 1);
103 passtokey(key, pr.old);
104 convM2T(tbuf, &t, key);
105 if(t.num != AuthTp || strcmp(t.cuid, tr.uid))
106 sysfatal("bad password");
108 /* loop trying new passwords */
112 readln("change Plan 9 Password? (y/n)", buf, sizeof buf, 0);
113 if(*buf == 'y' || *buf == 'Y'){
114 readln("Password(8 to 31 characters)", pr.new,
116 readln("Confirm", buf, sizeof buf, 1);
117 if(strcmp(pr.new, buf)){
118 print("!mismatch\n");
122 readln("change Inferno/POP password? (y/n)", buf, sizeof buf, 0);
123 if(*buf == 'y' || *buf == 'Y'){
125 readln("make it the same as your plan 9 password? (y/n)",
127 if(*buf == 'y' || *buf == 'Y'){
129 strcpy(pr.secret, pr.old);
131 strcpy(pr.secret, pr.new);
133 readln("Secret(0 to 256 characters)", pr.secret,
134 sizeof pr.secret, 1);
135 readln("Confirm", buf, sizeof buf, 1);
136 if(strcmp(pr.secret, buf)){
137 print("!mismatch\n");
143 convPR2M(&pr, buf, t.key);
144 if(write(fd, buf, PASSREQLEN) != PASSREQLEN)
145 sysfatal("AS protocol botch: %r");
146 if(asrdresp(fd, buf, 0) == 0)
148 fprint(2, "refused: %r\n");