| plan 9 kernel history: overview | file list | diff list |
2001/0527/port/auth.c (diff list | history)
| port/auth.c on 1993/0330 | ||
| 1993/0330 | #include "u.h" #include "../port/lib.h" #include "mem.h" #include "dat.h" #include "fns.h" #include "../port/error.h" | |
| 2001/0527 | #include <auth.h> | |
| 1993/0330 | ||
| 2001/0527 | char *eve; | |
| 1993/0330 | char evekey[DESKEYLEN]; char hostdomain[DOMLEN]; /* * return true if current user is eve */ int iseve(void) { | |
| 1993/0501 | return strcmp(eve, up->user) == 0; | |
| 1993/0330 | } long | |
| 2001/0527 | sysfversion(ulong *arg) | |
| 1993/0330 | { | |
| 2001/0527 | Fcall f; /* two Fcalls should be big enough for reply */ uchar *msg; char *vers; uint arglen, n, m, msize; | |
| 1993/0330 | Chan *c; | |
| 2001/0527 | uvlong oo; | |
| 1993/0330 | ||
| 2001/0527 | msize = arg[1]; vers = (char*)arg[2]; arglen = arg[3]; validaddr(arg[2], arglen, 1); /* check there's a NUL in the version string */ if(memchr(vers, 0, arglen) == 0) error(Ebadarg); c = fdtochan(arg[0], ORDWR, 0, 1); | |
| 1993/0407 | if(waserror()){ | |
| 1997/0327 | cclose(c); | |
| 1993/0330 | nexterror(); } | |
| 1993/0407 | ||
| 2001/0527 | if((c->flag&CMSG) && c->version!=nil) /* BUG: insufficient; should check compatibility */ goto Return; f.type = Tversion; f.tag = NOTAG; if(msize == 0) msize = IOHDRSZ+8192; /* reasonable default */ f.msize = msize; if(vers[0] == '\0') vers = VERSION9P; f.version = vers; msg = smalloc(MAXMSG); if(waserror()){ free(msg); nexterror(); | |
| 1993/0731 | } | |
| 2001/0527 | n = convS2M(&f, msg, MAXMSG); if(n == 0) error("bad fversion conversion on send"); lock(c); oo = c->offset; c->offset += n; | |
| 1993/0731 | unlock(c); | |
| 1993/0407 | ||
| 2001/0527 | m = devtab[c->type]->write(c, msg, n, oo); | |
| 1993/0731 | ||
| 2001/0527 | if(m < n){ lock(c); c->offset -= n - m; unlock(c); error("short write in fversion"); | |
| 1993/0330 | } | |
| 2001/0527 | /* message sent; receive and decode reply */ m = devtab[c->type]->read(c, msg, MAXMSG, c->offset); if(m <= 0) error("EOF receiving fversion reply"); | |
| 1993/0330 | ||
| 2001/0527 | lock(c); c->offset += m; unlock(c); | |
| 1993/0330 | ||
| 2001/0527 | n = convM2S(msg, m, &f); if(n != m) error("bad fversion conversion on reply"); if(f.type != Rversion) error("unexpected reply type in fversion"); if(f.msize > msize) error("server tries to increase msize in fversion"); if(f.msize<256 || f.msize>1024*1024) error("nonsense value of msize in fversion"); kstrdup(&c->version, f.version); c->iounit = f.msize; free(msg); poperror(); Return: m = strlen(c->version); if(m > arglen) m = arglen; memmove((char*)arg[2], c->version, m); | |
| 1997/0327 | cclose(c); | |
| 1993/0407 | poperror(); | |
| 2001/0527 | return m; | |
| 1993/0330 | } long | |
| 2001/0527 | sysfsession(ulong *arg) | |
| 1993/0330 | { | |
| 2001/0527 | Fcall f; uchar *msg; uint authlen, n, m; | |
| 1993/0330 | Chan *c; | |
| 2001/0527 | uvlong oo; | |
| 1993/0330 | ||
| 2001/0527 | //BUG print("warning: stub fsession being used\n"); authlen = arg[2]; validaddr(arg[1], authlen, 1); c = fdtochan(arg[0], ORDWR, 0, 1); | |
| 1993/0330 | if(waserror()){ | |
| 1999/0331 | cclose(c); | |
| 1993/0330 | nexterror(); } | |
| 2001/0527 | if(c->flag & CMSG){ //BUG what to do? ((uchar*)arg[1])[0] = 0; poperror(); cclose(c); | |
| 1993/0330 | return 0; } | |
| 2001/0527 | f.type = Tsession; f.tag = NOTAG; f.nchal = 0; f.chal = (uchar*)""; msg = smalloc(MAXMSG); if(waserror()){ free(msg); nexterror(); | |
| 1993/0330 | } | |
| 2001/0527 | n = convS2M(&f, msg, MAXMSG); if(n == 0) error("bad fsession conversion on send"); | |
| 1993/0330 | ||
| 2001/0527 | lock(c); oo = c->offset; c->offset += n; unlock(c); | |
| 1993/0330 | ||
| 2001/0527 | m = devtab[c->type]->write(c, msg, n, oo); | |
| 1993/0731 | ||
| 2001/0527 | if(m < n){ lock(c); c->offset -= n - m; unlock(c); error("short write in fsession"); | |
| 1993/0330 | } | |
| 2001/0527 | /* message sent; receive and decode reply */ m = devtab[c->type]->read(c, msg, MAXMSG, c->offset); if(m <= 0) error("EOF receiving fsession reply"); | |
| 1993/0330 | ||
| 2001/0527 | lock(c); c->offset += m; unlock(c); | |
| 1993/0731 | ||
| 2001/0527 | n = convM2S(msg, m, &f); if(n != m) error("bad fsession conversion on reply"); if(f.type != Rsession) error("unexpected reply type in fsession"); m = f.nchal; if(m > authlen) error(Eshort); //BUG print("auth stuff ignored; noauth by default\n"); ((uchar*)arg[1])[0] = 0; | |
| 1993/0731 | ||
| 2001/0527 | free(msg); poperror(); poperror(); cclose(c); return m; | |
| 1993/0330 | } long | |
| 2001/0527 | sysfauth(ulong *) | |
| 1993/0330 | { | |
| 2001/0527 | error("sysfauth unimplemented"); return -1; | |
| 1993/0731 | } /* | |
| 1993/0330 | * called by devcons() for key device */ long keyread(char *a, int n, long offset) { if(n<DESKEYLEN || offset != 0) error(Ebadarg); | |
| 1995/0113 | if(!cpuserver || !iseve()) | |
| 1993/0330 | error(Eperm); memmove(a, evekey, DESKEYLEN); return DESKEYLEN; } long keywrite(char *a, int n) { if(n != DESKEYLEN) error(Ebadarg); if(!iseve()) error(Eperm); memmove(evekey, a, DESKEYLEN); return DESKEYLEN; } /* * called by devcons() for user device * * anyone can become none */ long userwrite(char *a, int n) { | |
| 2000/0710 | if(!iseve() || strcmp(a, "none") != 0) | |
| 1993/0330 | error(Eperm); | |
| 2001/0527 | kstrdup(&up->user, "none"); | |
| 1995/0110 | up->basepri = PriNormal; | |
| 1993/0330 | return n; } /* * called by devcons() for host owner/domain * * writing hostowner also sets user */ long hostownerwrite(char *a, int n) { | |
| 2001/0527 | char buf[128]; | |
| 1993/0330 | if(!iseve()) error(Eperm); | |
| 2001/0527 | if(n >= sizeof buf) | |
| 1993/0330 | error(Ebadarg); | |
| 2001/0527 | strncpy(buf, a, n+1); if(buf[0] == '\0') | |
| 1993/0330 | error(Ebadarg); | |
| 2001/0527 | ||
| 1994/1027 | renameuser(eve, buf); | |
| 2001/0527 | kstrdup(&eve, buf); kstrdup(&up->user, buf); | |
| 1995/0110 | up->basepri = PriNormal; | |
| 1993/0330 | return n; } long hostdomainwrite(char *a, int n) { char buf[DOMLEN]; if(!iseve()) error(Eperm); if(n >= DOMLEN) error(Ebadarg); memset(buf, 0, DOMLEN); strncpy(buf, a, n); if(buf[0] == 0) error(Ebadarg); memmove(hostdomain, buf, DOMLEN); return n; } | |