static int pc1auth(int n, Rpccall *cmd, Rpccall *reply) { uchar *argptr = cmd->args; uchar *dataptr = reply->results; String id, pw; Unixidmap *m; int uid; chat("host=%I, port=%ld: pcauth...", cmd->host, cmd->port); if(n <= 8) return garbage(reply, "count too small"); argptr += string2S(argptr, &id); argptr += string2S(argptr, &pw); if(argptr != &((uchar*)cmd->args)[n]) return garbage(reply, "bad count"); scramble(&id); scramble(&pw); m = pair2idmap("pcnfsd", cmd->host); uid = -1; if(m) uid = name2id(&m->u.ids, id.s); if(uid < 0) uid = 1; chat("\"%.*s\",\"%.*s\" uid=%d\n", utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, uid); PLONG(0); /* status */ PLONG(uid); /* uid */ PLONG(uid); /* gid */ return dataptr - (uchar*)reply->results; }
void mapinit(char *file, char *client) { if(file){ print("reading %s...\n", file); if(readunixidmaps(file) < 0) exits("readunixidmaps"); if(!client) client = "nslocum.research.bell-labs.com"; } print("client = %s...\n", client); mp = pair2idmap("bootes", client, 0); if(mp == 0){ fprint(2, "%s: pair2idmap failed\n", argv0); exits("pair2idmap"); } pids = &mp->u.ids; print("[users...]\n"); }
static int pcauth(int n, Rpccall *cmd, Rpccall *reply) { uchar *argptr = cmd->args; uchar *dataptr = reply->results; String sys, id, pw, cm; Unixidmap *m; int uid; chat("host=%I, port=%ld: pcauth...", cmd->host, cmd->port); if(n <= 16) return garbage(reply, "count too small"); argptr += string2S(argptr, &sys); argptr += string2S(argptr, &id); argptr += string2S(argptr, &pw); argptr += string2S(argptr, &cm); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); scramble(&id); scramble(&pw); m = pair2idmap("pcnfsd", cmd->host); uid = -1; if(m) uid = name2id(&m->u.ids, id.s); if(uid < 0) uid = 1; chat("\"%.*s\",\"%.*s\",\"%.*s\",\"%.*s\"\n", utfnlen(sys.s, sys.n), sys.s, utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, utfnlen(cm.s, cm.n), cm.s); PLONG(0); /* status - OK */ PLONG(uid); PLONG(uid); /* gid */ PLONG(0); /* ngids */ PLONG(sizeof(pc_home)-1); PPTR(pc_home, sizeof(pc_home)-1); PLONG(0); /* umask */ PLONG(sizeof(no_comment)-1); PPTR(no_comment, sizeof(no_comment)-1); return dataptr - (uchar *)reply->results; }
Xfid * rpc2xfid(Rpccall *cmd, Dir *dp) { char *argptr = cmd->args; Xfile *xp; Xfid *xf; Session *s; char *service; Authunix au; Qid qid; char client[256], *user; Unixidmap *m; int i; uvlong x1, x2; chat("rpc2xfid %.8lux %.8lux %p %p\n", *((ulong*)argptr), *((ulong*)argptr+1), buf, argptr); if(argptr[0] == 0 && argptr[1] == 0){ /* root */ chat("root..."); xp = xfroot(&argptr[2], 0); s = xp ? xp->s : 0; }else{ ulong ul; chat("noroot %.8lux...", *((ulong*)argptr)); if((ul=GLONG()) != starttime){ chat("bad tag %lux %lux...", ul, starttime); return 0; } s = (Session *)GLONG(); x1 = GLONG(); x2 = GLONG(); qid.path = x1 | (x2<<32); qid.vers = 0; qid.type = GBYTE(); xp = xfile(&qid, s, 0); } if(xp == 0){ chat("no xfile..."); return 0; } if(auth2unix(&cmd->cred, &au) != 0){ chat("auth flavor=%ld, count=%ld\n", cmd->cred.flavor, cmd->cred.count); for(i=0; i<cmd->cred.count; i++) chat(" %.2ux", ((uchar *)cmd->cred.data)[i]); chat("..."); return 0; }else{ /* chat("auth: %d %.*s u=%d g=%d", * au.stamp, utfnlen(au.mach.s, au.mach.n), au.mach.s, au.uid, au.gid); * for(i=0; i<au.gidlen; i++) * chat(", %d", au.gids[i]); * chat("..."); */ char *p = memchr(au.mach.s, '.', au.mach.n); chat("%ld@%.*s...", au.uid, utfnlen(au.mach.s, (p ? p-au.mach.s : au.mach.n)), au.mach.s); } if(au.mach.n >= sizeof client){ chat("client name too long..."); return 0; } memcpy(client, au.mach.s, au.mach.n); client[au.mach.n] = 0; service = xp->parent->s->service; cmd->up = m = pair2idmap(service, cmd->host); if(m == 0){ chat("no map for pair (%s,%s)...", service, client); /*chat("getdom %d.%d.%d.%d", cmd->host&0xFF, (cmd->host>>8)&0xFF, (cmd->host>>16)&0xFF, (cmd->host>>24)&0xFF);/**/ /*if(getdom(cmd->host, client, sizeof(client))<0) return 0;/**/ return 0; } /*chat("map=(%s,%s)...", m->server, m->client);/**/ cmd->user = user = id2name(&m->u.ids, au.uid); if(user == 0){ chat("no user for id %ld...", au.uid); return 0; } chat("user=%s...", user);/**/ xf = 0; if(s == xp->parent->s){ if(!s->noauth) xf = setuser(xp, user); if(xf == 0) xf = setuser(xp, "none"); if(xf == 0) chat("can't set user none..."); }else xf = xp->users; if(xf) chat("uid=%s...", xf->uid); if(xf && dp && xfstat(xf, dp) < 0){ chat("can't stat %s...", xp->name); return 0; } return xf; }