3 static void uxfree(Unixid*);
7 Unixidmap *idhead, *idtail;
11 #define UNUSED 0x7FFFFFFF
14 * Sadly we have to use the IP address, since some systems (FreeBSD in particular)
15 * do not believe it to be safe to depend on the hostname and so refuse to send it.
16 * I dislike making this IP-centric, but so be it.
17 * We keep a cache of host names in getdom.
20 pair2idmap(char *server, ulong clientip)
27 for(mp=0,m=scmap; m; mp=m,m=m->next){
28 if(m->server[0] != server[0])
30 if(strcmp(m->server, server))
32 if(m->clientip != clientip)
40 if(r->u.timestamp != 0 && r->g.timestamp != 0)
47 fprint(2, "looking for %lux\n", clientip);
48 if(getdom(clientip, dom, sizeof dom)<0){
49 clog("auth: unknown ip address");
53 fprint(2, "dom is %s\n", dom);
54 for(r=idhead; r; r=r->next){
55 if(r->u.timestamp == 0 || r->g.timestamp == 0)
57 match.sp = match.ep = 0;
58 if(regexec(r->sexp, server, &match, 1) == 0)
60 if(match.sp != server || match.ep <= match.sp || *match.ep)
62 match.sp = match.ep = 0;
63 if(regexec(r->cexp, dom, &match, 1) == 0)
65 if(match.sp != dom || match.ep <= match.sp || *match.ep)
67 m = malloc(sizeof(Unixscmap));
70 m->server = strstore(server);
71 m->clientip = clientip;
79 readunixidmaps(char *file)
84 int i, arc; char *arv[16], buf[256];
88 // savalarm = alarm(0);
89 in = Bopen(file, OREAD);
91 clog("readunixidmaps can't open %s: %r\n", file);
95 for(m=idhead; m; m=m->next)
97 while(l = Brdline(in, '\n')){ /* assign = */
98 l[Blinelen(in)-1] = 0;
99 arc = strparse(l, nelem(arv), arv);
100 if(arc > 0 && arv[0][0] == '!'){
102 snprint(buf, sizeof buf, "/bin/%s", arv[0]);
109 w = system(buf, arv);
112 else if(w->msg && w->msg[0])
113 chat("status: %s\n", w->msg);
121 for(m=idhead; m; m=m->next)
122 if(strcmp(arv[0], m->server) == 0 &&
123 strcmp(arv[1], m->client) == 0)
126 m = malloc(sizeof(Unixidmap));
133 m->server = strstore(arv[0]);
134 m->client = strstore(arv[1]);
135 m->sexp = regcomp(m->server);
136 m->cexp = regcomp(m->client);
137 m->u.file = strstore(arv[2]);
141 m->g.file = strstore(arv[3]);
146 if(!m->u.file || strcmp(m->u.file, arv[2]) != 0){
147 m->u.file = strstore(arv[2]);
150 if(!m->g.file || strcmp(m->g.file, arv[3]) != 0){
151 m->g.file = strstore(arv[3]);
160 for(m=idhead; m; m=m->next)
189 if(tail->id == UNUSED)
199 checkunixmap(Unixmap *u)
203 dir = dirstat(u->file);
205 clog("checkunixmap can't stat %s: %r\n", u->file);
208 if(u->timestamp > dir->mtime){
213 u->ids = readunixids(u->file, u->style);
214 u->timestamp = time(0);
220 name2id(Unixid **list, char *name)
224 for(xp=0,x=*list; x; xp=x,x=x->next){
225 if(x->name[0] == name[0] && strcmp(x->name, name) == 0){
238 id2name(Unixid **list, int id)
242 for(xp=0,x=*list; x; xp=x,x=x->next){
256 idprint(int fd, Unixid *xp)
259 fprint(fd, "%d\t%s\n", xp->id, xp->name);
265 * style '9': 3:tom:tom:
266 * style 'u': sysadm:*:0:0:System-Administrator:/usr/admin:/bin/sh
270 readunixids(char *file, int style)
277 in = Bopen(file, OREAD);
279 clog("readunixids can't open %s: %r\n", file);
282 while(l = Brdline(in, '\n')){ /* assign = */
283 l[Blinelen(in)-1] = 0;
286 id = strtol(l, &l, 10);
305 id = strtol(l+1, 0, 10);
308 panic("unknown unixid style %d\n", style);
311 id = -1; /* any value will do */
312 if(!(x = xfree)) /* assign = */
313 x = listalloc(1024/sizeof(Unixid), sizeof(Unixid));
316 x->name = strstore(name);