5 authRead(Fid* afid, void* data, int count)
10 if((rpc = afid->rpc) == nil){
11 werrstr("not an auth fid");
15 switch(auth_rpc(rpc, "read", nil, 0)){
17 werrstr("fossil authRead: auth protocol not finished");
20 if((ai = auth_getinfo(rpc)) == nil){
24 if(ai->cuid == nil || *ai->cuid == '\0'){
25 werrstr("auth with no cuid");
29 assert(afid->cuname == nil);
30 afid->cuname = vtstrdup(ai->cuid);
33 fprint(2, "authRead cuname %s\n", afid->cuname);
34 assert(afid->uid == nil);
35 if((afid->uid = uidByUname(afid->cuname)) == nil){
36 werrstr("unknown user %#q", afid->cuname);
41 if(count < rpc->narg){
42 werrstr("not enough data in auth read");
45 memmove(data, rpc->arg, rpc->narg);
55 authWrite(Fid* afid, void* data, int count)
57 assert(afid->rpc != nil);
58 if(auth_rpc(afid->rpc, "write", data, count) != ARok)
64 authCheck(Fcall* t, Fid* fid, Fsys* fsys)
71 * Can't lookup with FidWlock here as there may be
72 * protocol to do. Use a separate lock to protect altering
73 * the auth information inside afid.
78 * If no authentication is asked for, allow
79 * "none" provided the connection has already
80 * been authenticatated.
82 * The console is allowed to attach without
88 }else if((con->flags&ConNoneAllow) || con->aok){
92 consPrint("attach %s as %s: allowing as none\n",
93 fsysGetName(fsys), fid->uname);
95 fid->uname = vtstrdup(unamenone);
98 consPrint("attach %s as %s: connection not authenticated, not console\n",
99 fsysGetName(fsys), fid->uname);
100 werrstr("cannot attach as none before authentication");
103 runlock(&con->alock);
105 if((fid->uid = uidByUname(fid->uname)) == nil){
106 consPrint("attach %s as %s: unknown uname\n",
107 fsysGetName(fsys), fid->uname);
108 werrstr("unknown user");
114 if((afid = fidGet(con, t->afid, 0)) == nil){
115 consPrint("attach %s as %s: bad afid\n",
116 fsysGetName(fsys), fid->uname);
117 werrstr("bad authentication fid");
123 * check uname and aname match.
125 if(!(afid->qid.type & QTAUTH)){
126 consPrint("attach %s as %s: afid not an auth file\n",
127 fsysGetName(fsys), fid->uname);
129 werrstr("bad authentication fid");
132 if(strcmp(afid->uname, fid->uname) != 0 || afid->fsys != fsys){
133 consPrint("attach %s as %s: afid is for %s as %s\n",
134 fsysGetName(fsys), fid->uname,
135 fsysGetName(afid->fsys), afid->uname);
137 werrstr("attach/auth mismatch");
142 if(afid->cuname == nil){
143 if(authRead(afid, buf, 0) != 0 || afid->cuname == nil){
144 qunlock(&afid->alock);
145 consPrint("attach %s as %s: %r\n",
146 fsysGetName(fsys), fid->uname);
148 werrstr("fossil authCheck: auth protocol not finished");
152 qunlock(&afid->alock);
154 assert(fid->uid == nil);
155 if((fid->uid = uidByUname(afid->cuname)) == nil){
156 consPrint("attach %s as %s: unknown cuname %s\n",
157 fsysGetName(fsys), fid->uname, afid->cuname);
159 werrstr("unknown user");
164 fid->uname = vtstrdup(afid->cuname);
168 * Allow "none" once the connection has been authenticated.
172 wunlock(&con->alock);