]> andersk Git - moira.git/blob - afssync/utils.c
7f7a9dba9405b6b121429c2787a582658b5b2061
[moira.git] / afssync / utils.c
1 /* $Header$ */
2 /* $Source$ */
3
4
5 /*
6  * P_R_P_Q_# (C) COPYRIGHT IBM CORPORATION 1988
7  * LICENSED MATERIALS - PROPERTY OF IBM
8  * REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
9  */
10
11 /*      
12        Sherri Nichols
13        Information Technology Center
14        November, 1988
15
16        Modified May, 1989 by Jeff Schiller to keep disk file in
17        network byte order
18
19 */
20
21
22 #include <sys/types.h>
23 #include <lock.h>
24 #include <ubik.h>
25 #include <stdio.h>
26 #include <netinet/in.h>
27 #include <netdb.h>
28 #include <rx/xdr.h>
29 #include <rx/rx.h>
30 #include <rx/rx_vab.h>
31 #include <rx/rxkad.h>
32 #include "print.h"
33 #include "prserver.h"
34 #include "prerror.h"
35
36 extern struct prheader cheader;
37 extern struct ubik_dbase *dbase;
38
39 long IDHash(x)
40 long x;
41 {
42     /* returns hash bucket for x */
43     return ((abs(x)) % HASHSIZE);
44 }
45
46 long NameHash(aname)
47 register unsigned char *aname;
48 {
49     /* returns hash bucket for aname */
50     register unsigned int hash=0;
51     register int i;
52 /* stolen directly from the HashString function in the vol package */
53     for (i=strlen(aname),aname += i-1;i--;aname--)
54         hash = (hash*31) + (*aname-31);
55     return(hash % HASHSIZE);
56 }
57
58
59 long pr_Write(tt,afd,pos,buff,len)
60 struct ubik_trans *tt;
61 long afd;
62 long pos;
63 char *buff;
64 long len;
65 {
66     /* package up seek and write into one procedure for ease of use */
67     long code;
68     code = ubik_Seek(tt,afd,pos);
69     if (code) return code;
70     code = ubik_Write(tt,buff,len);
71     return code;
72 }
73
74 long pr_Read(tt,afd,pos,buff,len)
75 struct ubik_trans *tt;
76 long afd;
77 long pos;
78 char *buff;
79 long len;
80 {
81     /* same thing for read */
82     long code;
83     code = ubik_Seek(tt,afd,pos);
84     if (code) return code;
85     code = ubik_Read(tt,buff,len);
86     return code;
87 }
88
89 pr_WriteEntry(tt, afd, pos, tentry)
90 struct ubik_trans *tt;
91 long afd;
92 long pos;
93 struct prentry *tentry;
94 {
95     long code;
96     register long i;
97     struct prentry nentry;
98     if (ntohl(1) != 1) {        /* Need to swap bytes. */
99       nentry.flags = htonl(tentry->flags);
100       nentry.id = htonl(tentry->id);
101       nentry.cellid = htonl(tentry->cellid);
102       nentry.next = htonl(tentry->next);
103       nentry.nextID = htonl(tentry->nextID);
104       nentry.nextName = htonl(tentry->nextName);
105       nentry.owner = htonl(tentry->owner);
106       nentry.creator = htonl(tentry->creator);
107       nentry.ngroups = htonl(tentry->ngroups);
108       nentry.nusers = htonl(tentry->nusers);
109       nentry.count = htonl(tentry->count);
110       nentry.instance = htonl(tentry->instance);
111       nentry.owned = htonl(tentry->owned);
112       nentry.nextOwned = htonl(tentry->nextOwned);
113       nentry.parent = htonl(tentry->parent);
114       nentry.sibling = htonl(tentry->sibling);
115       nentry.child = htonl(tentry->child);
116       strncpy(nentry.name, tentry->name, PR_MAXNAMELEN);
117       for (i = 0; i < PRSIZE; i++)
118         nentry.entries[i] = htonl(tentry->entries[i]);
119       code = ubik_Seek(tt, afd, pos);
120       if (code) return (code);
121       code = ubik_Write(tt, (char *) &nentry, sizeof(struct prentry));
122       return(code);
123     } else {
124       code = ubik_Seek(tt, afd, pos);
125       if (code) return (code);
126       code = ubik_Write(tt, (char *) tentry, sizeof(struct prentry));
127       return(code);
128     }
129 }
130
131 pr_ReadEntry(tt, afd, pos, tentry)
132 struct ubik_trans *tt;
133 long afd;
134 long pos;
135 struct prentry *tentry;
136 {
137     long code;
138     register long i;
139     struct prentry nentry;
140     code = ubik_Seek(tt, afd, pos);
141     if (code) return (code);
142     if (ntohl(1) == 1) {        /* no swapping needed */
143       code = ubik_Read(tt, (char *) tentry, sizeof(struct prentry));
144       return(code);
145     }
146     code = ubik_Read(tt, (char *) &nentry, sizeof(struct prentry));
147     if (code) return (code);
148     tentry->flags = ntohl(nentry.flags);
149     tentry->id = ntohl(nentry.id);
150     tentry->cellid = ntohl(nentry.cellid);
151     tentry->next = ntohl(nentry.next);
152     tentry->nextID = ntohl(nentry.nextID);
153     tentry->nextName = ntohl(nentry.nextName);
154     tentry->owner = ntohl(nentry.owner);
155     tentry->creator = ntohl(nentry.creator);
156     tentry->ngroups = ntohl(nentry.ngroups);
157     tentry->nusers = ntohl(nentry.nusers);
158     tentry->count = ntohl(nentry.count);
159     tentry->instance = ntohl(nentry.instance);
160     tentry->owned = ntohl(nentry.owned);
161     tentry->nextOwned = ntohl(nentry.nextOwned);
162     tentry->parent = ntohl(nentry.parent);
163     tentry->sibling = ntohl(nentry.sibling);
164     tentry->child = ntohl(nentry.child);
165     strncpy(tentry->name, nentry.name, PR_MAXNAMELEN);
166     for (i = 0; i < PRSIZE; i++)
167       tentry->entries[i] = ntohl(nentry.entries[i]);
168     return(code);
169 }
170
171 pr_WriteCoEntry(tt, afd, pos, tentry)
172 struct ubik_trans *tt;
173 long afd;
174 long pos;
175 struct contentry *tentry;
176 {
177     long code;
178     register long i;
179     struct contentry nentry;
180     if (ntohl(1) == 1) {        /* No need to swap */
181       code = ubik_Seek(tt, afd, pos);
182       if (code) return(code);
183       code = ubik_Write(tt, (char *) tentry, sizeof(struct contentry));
184       return(code);
185     }
186     nentry.flags = htonl(tentry->flags);
187     nentry.id = htonl(tentry->id);
188     nentry.cellid = htonl(tentry->cellid);
189     nentry.next = htonl(tentry->next);
190     for (i = 0; i < COSIZE; i++)
191       nentry.entries[i] = htonl(tentry->entries[i]);
192     code = ubik_Seek(tt, afd, pos);
193     if (code) return (code);
194     code = ubik_Write(tt, (char *) &nentry, sizeof(struct contentry));
195     return(code);
196 }
197
198 pr_ReadCoEntry(tt, afd, pos, tentry)
199 struct ubik_trans *tt;
200 long afd;
201 long pos;
202 struct contentry *tentry;
203 {
204     long code;
205     register long i;
206     struct contentry nentry;
207     code = ubik_Seek(tt, afd, pos);
208     if (code) return (code);
209     if (ntohl(1) == 1) {        /* No swapping needed. */
210       code = ubik_Read(tt, (char *) tentry, sizeof(struct contentry));
211       return(code);
212     }
213     code = ubik_Read(tt, (char *) &nentry, sizeof(struct contentry));
214     if (code) return (code);
215     tentry->flags = ntohl(nentry.flags);
216     tentry->id = ntohl(nentry.id);
217     tentry->cellid = ntohl(nentry.cellid);
218     tentry->next = ntohl(nentry.next);
219     for (i = 0; i < COSIZE; i++)
220       tentry->entries[i] = ntohl(nentry.entries[i]);
221     return(code);
222 }
223
224 long AllocBlock(at)
225 register struct ubik_trans *at;
226 {
227     /* allocate a free block of storage for entry, returning address of new entry  */
228     register long code;
229     long temp;
230     struct prentry tentry;
231
232     if (cheader.freePtr) {
233         /* allocate this dude */
234         temp = ntohl(cheader.freePtr);      
235         code = pr_ReadEntry(at, 0, temp, &tentry);
236         if (code) return 0;
237         cheader.freePtr = htonl(tentry.next);
238         code = pr_Write(at, 0, 8, (char *)&cheader.freePtr, sizeof(cheader.freePtr));
239         if (code != 0) return 0;
240         return temp;
241     }
242     else {
243         /* hosed, nothing on free list, grow file */
244         temp = ntohl(cheader.eofPtr);   /* remember this guy */
245         cheader.eofPtr = htonl(temp + ENTRYSIZE);
246         code = pr_Write(at, 0, 12,(char *) &cheader.eofPtr, sizeof(cheader.eofPtr));
247         if (code != 0) return 0;
248         return temp;
249     }
250 }
251
252 long FreeBlock(at, pos)
253 register struct ubik_trans *at;
254 long pos;
255 {
256     /* add a block of storage to the free list */
257     register long code;
258     struct prentry tentry;
259
260     bzero(&tentry,sizeof(tentry));
261     tentry.next = ntohl(cheader.freePtr);
262     tentry.flags |= PRFREE;
263     cheader.freePtr = htonl(pos);
264     code = pr_Write(at,0,8, (char *) &cheader.freePtr,sizeof(cheader.freePtr));
265     if (code != 0) return code;
266     code = pr_WriteEntry(at,0,pos,&tentry);
267     if (code != 0) return code;
268     return PRSUCCESS;
269 }
270
271 long FindByID(at,aid)
272 register struct ubik_trans *at;
273 long aid;
274 {
275     /* returns address of entry if found, 0 otherwise */
276     register long code;
277     long i;
278     struct prentry tentry;
279     long entry;
280
281     i = IDHash(aid);
282     entry = ntohl(cheader.idHash[i]);
283     if (entry == 0) return entry;
284     bzero(&tentry,sizeof(tentry));
285     code = pr_ReadEntry(at, 0, entry, &tentry);
286     if (code != 0) return 0;
287     if (aid == tentry.id) return entry;
288     entry = tentry.nextID;
289     while (entry != NULL) {
290         bzero(&tentry,sizeof(tentry));
291         code = pr_ReadEntry(at,0,entry,&tentry);
292         if (code != 0) return 0;
293         if (aid == tentry.id) return entry;
294         entry = tentry.nextID;
295     }
296     return 0;
297 }
298  
299
300
301 long FindByName(at,aname)    
302 register struct ubik_trans *at;
303 char aname[PR_MAXNAMELEN];
304 {
305     /* ditto */
306     register long code;
307     long i;
308     struct prentry tentry;
309     long entry;
310
311     i = NameHash(aname);
312     entry = ntohl(cheader.nameHash[i]);
313     if (entry == 0) return entry;
314     bzero(&tentry,sizeof(tentry));
315     code = pr_ReadEntry(at, 0, entry,&tentry);
316     if (code != 0) return 0;
317     if ((strncmp(aname,tentry.name,PR_MAXNAMELEN)) == 0) return entry;
318     entry = tentry.nextName;
319     while (entry != NULL) {
320         bzero(&tentry,sizeof(tentry));
321         code = pr_ReadEntry(at,0,entry,&tentry);
322         if (code != 0) return 0;
323         if ((strncmp(aname,tentry.name,PR_MAXNAMELEN)) == 0) return entry;
324         entry = tentry.nextName;
325     }
326     return 0;
327 }
328
329 long AllocID(at,flag,aid)
330 register struct ubik_trans *at;
331 long flag;
332 long *aid;
333 {
334     /* allocs an id from the proper area of address space, based on flag */
335     register long code = 1;
336     register long i = 0;
337     register maxcount = 50;  /* to prevent infinite loops */
338     
339     if (flag & PRGRP) {
340         *aid = ntohl(cheader.maxGroup);
341         while (code && i<maxcount) {
342             --(*aid);
343             code = FindByID(at,*aid);
344             i++;
345         }
346         if (code) return PRNOIDS;
347         cheader.maxGroup = htonl(*aid);
348         code = pr_Write(at,0,16,(char *)&cheader.maxGroup,sizeof(cheader.maxGroup));
349         if (code) return PRDBFAIL;
350         return PRSUCCESS;
351     }
352     else if (flag & PRFOREIGN) {
353         *aid = ntohl(cheader.maxForeign);
354         while (code && i<maxcount) {
355             ++(*aid);
356             code = FindByID(at,*aid);
357             i++;
358         }
359         if (code) return PRNOIDS;
360         cheader.maxForeign = htonl(*aid);
361         code = pr_Write(at,0,24,(char *)&cheader.maxForeign,sizeof(cheader.maxForeign));
362         if (code) return PRDBFAIL;
363         return PRSUCCESS;
364     }
365     else {
366         *aid = ntohl(cheader.maxID);
367         while (code && i<maxcount) {
368             ++(*aid);
369             code = FindByID(at,*aid);
370             i++;
371         }
372         if (code) return PRNOIDS;
373         cheader.maxID = htonl(*aid);
374         code = pr_Write(at,0,20,(char *)&cheader.maxID,sizeof(cheader.maxID));
375         if (code) return PRDBFAIL;
376         return PRSUCCESS;
377     }
378 }
379
380 long IDCmp(a,b)
381 long *a;
382 long *b;
383 {
384     /* used to sort CPS's so that comparison with acl's is easier */
385     if (*a > *b) return 1;
386     if (*a == *b) return 0;
387     if (*a < *b) return -1;
388 }
389
390 long RemoveFromIDHash(tt,aid,loc)
391 struct ubik_trans *tt;
392 long aid;
393 long *loc;
394 {
395     /* remove entry designated by aid from id hash table */
396     register long code;
397     long current, trail, i;
398     struct prentry tentry;
399     struct prentry bentry;
400
401     i = IDHash(aid);
402     current = ntohl(cheader.idHash[i]);
403     bzero(&tentry,sizeof(tentry));
404     bzero(&bentry,sizeof(bentry));
405     trail = 0;
406     if (current == NULL) return PRNOENT;
407     code = pr_ReadEntry(tt,0,current,&tentry);
408     if (code) return PRDBFAIL;
409     while (aid != tentry.id) {
410         trail = current;
411         current = tentry.nextID;
412         if (current == NULL) break;
413         code = pr_ReadEntry(tt,0,current,&tentry);
414         if (code) return PRDBFAIL;
415     }
416     if (current == NULL) return PRNOENT;  /* we didn't find him */
417     if (trail == NULL) {
418         /* it's the first entry! */
419         cheader.idHash[i] = htonl(tentry.nextID);
420         code = pr_Write(tt,0,72+HASHSIZE*4+i*4,(char *)&cheader.idHash[i],sizeof(cheader.idHash[i]));
421         if (code) return PRDBFAIL;
422     }
423     else {
424         code = pr_ReadEntry(tt,0,trail, &bentry);
425         if (code) return PRDBFAIL;
426         bentry.nextID = tentry.nextID;
427         code = pr_WriteEntry(tt,0,trail,&bentry);
428     }
429     *loc = current;
430     return PRSUCCESS;
431 }
432
433 long AddToIDHash(tt, aid, loc)
434 struct ubik_trans *tt;
435 long aid;
436 long loc;
437 {
438     /* add entry at loc designated by aid to id hash table */
439     register long code;
440     long i;
441     struct prentry tentry;
442
443     i = IDHash(aid);
444     bzero(&tentry,sizeof(tentry));
445     code = pr_ReadEntry(tt,0,loc,&tentry);
446     if (code) return PRDBFAIL;
447     tentry.nextID = ntohl(cheader.idHash[i]);
448     cheader.idHash[i] = htonl(loc);
449     code = pr_WriteEntry(tt,0,loc,&tentry);
450     if (code) return PRDBFAIL;
451     code = pr_Write(tt,0,72+HASHSIZE*4+i*4,(char *)&cheader.idHash[i],sizeof(cheader.idHash[i]));
452     if (code) return PRDBFAIL;
453     return PRSUCCESS;
454 }
455
456 long RemoveFromNameHash(tt,aname,loc)
457 struct ubik_trans *tt;
458 char *aname;
459 long *loc;
460 {
461     /* remove from name hash */
462     register long code;
463     long current, trail, i;
464     struct prentry tentry;
465     struct prentry bentry;
466
467     i = NameHash(aname);
468     current = ntohl(cheader.nameHash[i]);
469     bzero(&tentry,sizeof(tentry));
470     bzero(&bentry,sizeof(bentry));
471     trail = 0;
472     if (current == NULL) return PRNOENT;
473     code = pr_ReadEntry(tt,0,current,&tentry);
474     if (code) return PRDBFAIL;
475     while (strcmp(aname,tentry.name)) {
476         trail = current;
477         current = tentry.nextName;
478         if (current == NULL) break;
479         code = pr_ReadEntry(tt,0,current,&tentry);
480         if (code) return PRDBFAIL;
481     }
482     if (current == NULL) return PRNOENT;  /* we dnamen't find him */
483     if (trail == NULL) {
484         /* it's the first entry! */
485         cheader.nameHash[i] = htonl(tentry.nextName);
486         code = pr_Write(tt,0,72+i*4,(char *)&cheader.nameHash[i],sizeof(cheader.nameHash[i]));
487         if (code) return PRDBFAIL;
488     }
489     else {
490         code = pr_ReadEntry(tt,0,trail, &bentry);
491         if (code) return PRDBFAIL;
492         bentry.nextName = tentry.nextName;
493         code = pr_WriteEntry(tt,0,trail,&bentry);
494     }
495     *loc = current;
496     return PRSUCCESS;
497 }
498
499 long AddToNameHash(tt, aname, loc)
500 struct ubik_trans *tt;
501 char *aname;
502 long loc;
503 {
504     /* add to name hash */
505     register long code;
506     long i;
507     struct prentry tentry;
508
509     i = NameHash(aname);
510     bzero(&tentry,sizeof(tentry));
511     code = pr_ReadEntry(tt,0,loc,&tentry);
512     if (code) return PRDBFAIL;
513     tentry.nextName = ntohl(cheader.nameHash[i]);
514     cheader.nameHash[i] = htonl(loc);
515     code = pr_WriteEntry(tt,0,loc,&tentry);
516     if (code) return PRDBFAIL;
517     code = pr_Write(tt,0,72+i*4,(char *)&cheader.nameHash[i],sizeof(cheader.nameHash[i]));
518     if (code) return PRDBFAIL;
519     return PRSUCCESS;
520 }
521
522 long AddToOwnerChain(at,gid,oid)
523 struct ubik_trans *at;
524 long gid;
525 long oid;
526 {
527     /* add entry designated by gid to owner chain of entry designated by oid */
528     register long code;
529     long loc;
530     long gloc;
531     struct prentry tentry;
532     struct prentry gentry;
533
534     loc = FindByID(at,oid);
535     if (!loc) return PRNOENT;
536     code = pr_ReadEntry(at,0,loc,&tentry);
537     if (code != 0) return PRDBFAIL;
538     gloc = FindByID(at,gid);
539     code = pr_ReadEntry(at,0,gloc,&gentry);
540     if (code != 0) return PRDBFAIL;
541     gentry.nextOwned = tentry.owned;
542     tentry.owned = gloc;
543     code = pr_WriteEntry(at,0,loc,&tentry);
544     if (code != 0) return PRDBFAIL;
545     code = pr_WriteEntry(at,0,gloc,&gentry);
546     if (code != 0) return PRDBFAIL;
547     return PRSUCCESS;
548 }
549
550 long RemoveFromOwnerChain(at,gid,oid)
551 struct ubik_trans *at;
552 long gid;
553 long oid;
554 {
555     /* remove gid from owner chain for oid */
556     register long code;
557     long nptr;
558     struct prentry tentry;
559     struct prentry bentry;
560     long loc;
561
562     loc = FindByID(at,oid);
563     if (!loc) return PRNOENT;
564     code = pr_ReadEntry(at,0,loc,&tentry);
565     if (code != 0) return PRDBFAIL;
566     if (!tentry.owned) return PRNOENT;
567     nptr = tentry.owned;
568     bcopy(&tentry,&bentry,sizeof(tentry));
569     while (nptr != NULL) {
570         code = pr_ReadEntry(at,0,nptr,&tentry);
571         if (code != 0) return PRDBFAIL;
572         if (tentry.id == gid) {
573             /* found it */
574             if (nptr == bentry.owned) /* modifying first of chain */
575                 bentry.owned = tentry.nextOwned;
576             else bentry.nextOwned = tentry.nextOwned;
577             tentry.nextOwned = 0;
578             code = pr_WriteEntry(at,0,loc,&bentry);
579             if (code != 0) return PRDBFAIL;
580             code = pr_WriteEntry(at,0,nptr,&tentry);
581             if (code != 0) return PRDBFAIL;
582             return PRSUCCESS;
583         }
584         loc = nptr;
585         nptr = tentry.nextOwned;
586         bcopy(&tentry,&bentry,sizeof(tentry));
587     }
588     return PRNOENT;
589 }
590
591 long AddToOrphan(at,gid)
592 struct ubik_trans *at;
593 long gid;
594 {
595     /* add gid to orphan list, as it's owner has died */
596     register long code;
597     long loc;
598     struct prentry tentry;
599
600     loc = FindByID(at,gid);
601     if (!loc) return PRNOENT;
602     code = pr_ReadEntry(at,0,loc,&tentry);
603     if (code != 0) return PRDBFAIL;
604     tentry.nextOwned = ntohl(cheader.orphan);
605     cheader.orphan = htonl(loc);
606     code = pr_WriteEntry(at,0,loc,&tentry);
607     if (code != 0) return PRDBFAIL;
608     code = pr_Write(at,0,32,(char *)&cheader.orphan,sizeof(cheader.orphan));
609     if (code != 0) return PRDBFAIL;
610     return PRSUCCESS;
611 }
612
613 long RemoveFromOrphan(at,gid)
614 struct ubik_trans *at;
615 long gid;
616 {
617     /* remove gid from the orphan list */
618     register long code;
619     long loc;
620     long nptr;
621     struct prentry tentry;
622     struct prentry bentry;
623
624     loc = FindByID(at,gid);
625     if (!loc) return PRNOENT;
626     code = pr_ReadEntry(at,0,loc,&tentry);
627     if (code != 0) return PRDBFAIL;
628     if (cheader.orphan == htonl(loc)) {
629         cheader.orphan = htonl(tentry.nextOwned);
630         tentry.nextOwned = 0;
631         code = pr_Write(at,0,32,(char *)&cheader.orphan,sizeof(cheader.orphan));
632         if (code != 0) return PRDBFAIL;
633         code = pr_WriteEntry(at,0,loc,&tentry);
634         if (code != 0) return PRDBFAIL;
635         return PRSUCCESS;
636     }
637     nptr = ntohl(cheader.orphan);
638     bzero(&bentry,sizeof(bentry));
639     loc = 0;
640     while (nptr != NULL) {
641         code = pr_ReadEntry(at,0,nptr,&tentry);
642         if (code != 0) return PRDBFAIL;
643         if (gid == tentry.id) {
644             /* found it */
645             bentry.nextOwned = tentry.nextOwned;
646             tentry.nextOwned = 0;
647             code = pr_WriteEntry(at,0,loc,&bentry);
648             if (code != 0) return PRDBFAIL;
649             code = pr_WriteEntry(at,0,nptr,&tentry);
650             if (code != 0) return PRDBFAIL;
651             return PRSUCCESS;
652         }
653         loc = nptr;
654         nptr = tentry.nextOwned;
655         bcopy(&tentry,&bentry,sizeof(tentry));
656     }
657     return PRNOENT;
658 }
659
660 long IsOwnerOf(at,aid,gid)
661 struct ubik_trans *at;
662 long aid;
663 long gid;
664 {
665     /* returns 1 if aid is the owner of gid, 0 otherwise */
666     register long code;
667     struct prentry tentry;
668     long loc;
669
670     loc = FindByID(at,gid);
671     if (!loc) return 0;
672     code = pr_ReadEntry(at,0,loc,&tentry);
673     if (code != 0) return 0;
674     if (tentry.owner == aid) return 1;
675     return 0;
676 }
677
678 long OwnerOf(at,gid)
679 struct ubik_trans *at;
680 long gid;
681 {
682     /* returns the owner of gid */
683     register long code;
684     long loc;
685     struct prentry tentry;
686
687     loc = FindByID(at,gid);
688     if (!loc) return 0;
689     code = pr_ReadEntry(at,0,loc,&tentry);
690     if (code != 0) return 0;
691     return tentry.owner;
692 }
693     
694
695 long WhoIsThis(acall, at, aid)
696 struct rx_call *acall;
697 struct ubik_trans *at;
698 long *aid;
699 {
700     /* aid is set to the identity of the caller, if known, ANONYMOUSID otherwise */
701     /* returns -1 and sets aid to ANONYMOUSID on any failure */
702     register struct rx_connection *tconn;
703     struct rxvab_conn *tc;
704     register long code;
705     char tcell[64];
706     long exp;
707     char vname[256];
708
709     tconn = rx_ConnectionOf(acall);
710     code = rx_SecurityClassOf(tconn);
711     if (code == 0) 
712         *aid = ANONYMOUSID;
713     else if (code == 1) {
714         /* vab class */
715         tc = (struct rxvab_conn *) tconn->securityData;
716         if (!tc) {
717             *aid = ANONYMOUSID; /* set it to something harmless */
718             return -1;
719         }
720         *aid = ntohl(tc->viceID);
721     }
722     else if (code == 2) {
723         /* kad class */
724         code = rxkad_GetServerInfo(acall->conn,(long *) 0, &exp, vname, (char *) 0, tcell, (long *) 0);
725         if (code) {
726             *aid = ANONYMOUSID;
727             return -1;
728         }
729         if (exp < FT_ApproxTime()) return -1;
730         code = NameToID(at,vname,aid);
731         if (code) {
732             *aid = ANONYMOUSID;
733             return -1;
734         }
735         return 0;
736     }
737     else {
738         *aid = ANONYMOUSID;
739         return -1;
740     }
741     return 0;
742 }
743
744 long IsAMemberOf(at,aid,gid)
745 struct ubik_trans *at;
746 long aid;
747 long gid;
748 {
749     /* returns true if aid is a member of gid */
750     struct prentry tentry;
751     struct contentry centry;
752     register long code;
753     long i;
754     long loc;
755
756     loc = FindByID(at,gid);
757     if (!loc) return 0;
758     bzero(&tentry,sizeof(tentry));
759     code = pr_ReadEntry(at, 0, loc,&tentry);
760     if (code) return 0;
761     if (!(tentry.flags & PRGRP)) return 0;
762     for (i= 0;i<PRSIZE;i++) {
763         if (tentry.entries[i] == aid) return 1;
764         if (tentry.entries[i] == 0) return 0;
765     }
766     if (tentry.next) {
767         loc = tentry.next;
768         while (loc) {
769             bzero(&centry,sizeof(centry));
770             code = pr_ReadCoEntry(at,0,loc,&centry);
771             if (code) return 0;
772             for (i=0;i<COSIZE;i++) {
773                 if (centry.entries[i] == aid) return 1;
774                 if (centry.entries[i] == 0) return 0;
775             }
776             loc = centry.next;
777         }
778     }
779     return 0;  /* actually, should never get here */
780 }
This page took 0.345399 seconds and 3 git commands to generate.