6 memrandom(void *p, int n)
10 for(cp = (uchar*)p; n > 0; n--)
16 * create a change uid capability
21 mkcap(char *from, char *to)
32 /* create the capability */
35 cap = emalloc(nfrom+1+nto+1+sizeof(rand)*3+1);
36 sprint(cap, "%s@%s", from, to);
37 memrandom(rand, sizeof(rand));
38 key = cap+nfrom+1+nto+1;
39 enc64(key, sizeof(rand)*3, rand, sizeof(rand));
41 /* hash the capability */
42 hmac_sha1((uchar*)cap, strlen(cap), (uchar*)key, strlen(key), hash, nil);
44 /* give the kernel the hash */
46 if(write(caphashfd, hash, SHA1dlen) < 0){
55 addcap(Attr *a, char *from, Ticket *t)
59 cap = mkcap(from, t->suid);
60 return addattr(a, "cuid=%q suid=%q cap=%q", t->cuid, t->suid, cap);
63 /* bind in the default network and cs */
69 if(access("/net/tcp", AEXIST) < 0)
70 bind("#I", "/net", MBEFORE);
72 if(access("/net/cs", AEXIST) < 0){
73 if((srvfd = open("#s/cs", ORDWR)) >= 0){
74 /* mount closes srvfd on success */
75 if(mount(srvfd, -1, "/net", MBEFORE, "") >= 0)
85 _authdial(char *net, char *authdom)
89 vanilla = net==nil || strcmp(net, "/net")==0;
91 if(!vanilla || bindnetcs()>=0)
92 return authdial(net, authdom);
94 /* use the auth sever passed to us as an arg */
97 return dial(netmkaddr(authaddr, "tcp", "567"), 0, 0, 0);
101 plan9authkey(Attr *a)
107 * The only important part of a is dom.
108 * We don't care, for example, about user name.
110 dom = strfindattr(a, "dom");
112 k = keylookup("proto=p9sk1 role=server user? dom=%q", dom);
114 k = keylookup("proto=p9sk1 role=server user? dom?");
116 werrstr("could not find plan 9 auth key dom %q", dom);
121 * prompt for a string with a possible default response
124 readcons(char *prompt, char *def, int raw)
126 int fdin, fdout, ctl, n;
130 fdin = open("/dev/cons", OREAD);
133 fdout = open("/dev/cons", OWRITE);
137 fprint(fdout, "%s[%s]: ", prompt, def);
139 fprint(fdout, "%s: ", prompt);
141 ctl = open("/dev/consctl", OWRITE);
143 write(ctl, "rawon", 5);
148 n = read(fdin, line, 1);
162 if(n == 0 || line[0] == '\n' || line[0] == '\r'){
164 write(ctl, "rawoff", 6);
165 write(fdout, "\n", 1);
170 if(*s == 0 && def != nil)
171 s = estrappend(s, "%s", def);
177 } else if(line[0] == 0x15) { /* ^U: line kill */
179 fprint(fdout, "\n%s[%s]: ", prompt, def);
181 fprint(fdout, "\n%s: ", prompt);
185 s = estrappend(s, "%c", line[0]);
188 return nil; /* not reached */