2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * (3) function addToGroup
13 * 1. Eliminate the code that tests for adding groups
14 * to groups. This is an error in normal AFS.
15 * 2. If adding a group to a group call AddToSGEntry
16 * to add the id of the group it's a member of.
20 * 1. Print a messsage if an error is returned from
21 * FindByID() and PTDEBUG is defined.
22 * 2. If removing a group from a group call
23 * RemoveFromSGEntry to remove the id of the
24 * group it's a member of.
25 * 3. Remove supergroup continuation records.
27 * (5) function RemoveFromGroup
29 * 1. Eliminate the code that tests for adding groups
30 * to groups. This is an error in normal AFS.
31 * 2. If removing a group from a group call
32 * RemoveFromSGEntry to remove the id of the
33 * group it's a member of.
35 * (6) Add new functions PR_ListSuperGroups and
38 * (7) function isAMemberOf
40 * 1. Allow groups to be members of groups.
42 * Transarc does not currently use opcodes past 520, but
43 * they *could* decide at any time to use more opcodes.
44 * If they did, then one part of our local mods,
45 * ListSupergroups, would break. I've therefore
46 * renumbered it to 530, and put logic in to enable the
47 * old opcode to work (for now).
50 #include <afsconfig.h>
51 #include <afs/param.h>
60 #include <afs/afsutil.h>
66 #include <afs/cellconfig.h>
70 #include "ptprototypes.h"
71 #include "afs/audit.h"
73 extern int restricted;
74 extern struct ubik_dbase *dbase;
76 extern int prp_group_default;
77 extern int prp_user_default;
78 extern struct afsconf_dir *prdir;
80 static afs_int32 iNewEntry(struct rx_call *call, char aname[], afs_int32 aid,
81 afs_int32 oid, afs_int32 *cid);
82 static afs_int32 newEntry(struct rx_call *call, char aname[], afs_int32 flag,
83 afs_int32 oid, afs_int32 *aid, afs_int32 *cid);
84 static afs_int32 whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos,
86 static afs_int32 dumpEntry(struct rx_call *call, afs_int32 apos,
87 struct prdebugentry *aentry, afs_int32 *cid);
88 static afs_int32 addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid,
90 static afs_int32 nameToID(struct rx_call *call, namelist *aname, idlist *aid);
91 static afs_int32 idToName(struct rx_call *call, idlist *aid, namelist *aname);
92 static afs_int32 Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid);
93 static afs_int32 UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
94 struct PrUpdateEntry *uentry, afs_int32 *cid);
95 static afs_int32 removeFromGroup(struct rx_call *call, afs_int32 aid,
96 afs_int32 gid, afs_int32 *cid);
97 static afs_int32 getCPS(struct rx_call *call, afs_int32 aid, prlist *alist,
98 afs_int32 *over, afs_int32 *cid);
99 static afs_int32 getCPS2(struct rx_call *call, afs_int32 aid, afs_uint32 ahost,
100 prlist *alist, afs_int32 *over, afs_int32 *cid);
101 static afs_int32 getHostCPS(struct rx_call *call, afs_uint32 ahost,
102 prlist *alist, afs_int32 *over);
103 static afs_int32 listMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid);
104 static afs_int32 setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag,
106 static afs_int32 listEntry(struct rx_call *call, afs_int32 aid,
107 struct prcheckentry *aentry, afs_int32 *cid);
108 static afs_int32 listEntries(struct rx_call *call, afs_int32 flag,
109 afs_int32 startindex, prentries *bulkentries,
110 afs_int32 *nextstartindex, afs_int32 *cid);
111 static afs_int32 put_prentries(struct prentry *tentry, prentries *bulkentries);
112 static afs_int32 changeEntry(struct rx_call *call, afs_int32 aid, char *name,
113 afs_int32 oid, afs_int32 newid, afs_int32 *cid);
114 static afs_int32 setFieldsEntry(struct rx_call *call, afs_int32 id,
115 afs_int32 mask, afs_int32 flags,
116 afs_int32 ngroups, afs_int32 nusers,
117 afs_int32 spare1, afs_int32 spare2,
119 static afs_int32 listElements(struct rx_call *call, afs_int32 aid,
120 prlist *alist, afs_int32 *over, afs_int32 *cid);
121 #if defined(SUPERGROUPS)
122 static afs_int32 listSuperGroups(struct rx_call *call, afs_int32 aid,
123 prlist *alist, afs_int32 *over,
126 static afs_int32 listOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
127 afs_int32 *lastP, afs_int32 *cid);
128 static afs_int32 isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid,
129 afs_int32 *flag, afs_int32 *cid);
130 static afs_int32 addWildCards(struct ubik_trans *tt, prlist *alist,
132 static afs_int32 WhoIsThisWithName(struct rx_call *acall,
133 struct ubik_trans *at, afs_int32 *aid,
136 /* when we abort, the ubik cachedVersion will be reset, so we'll read in the
137 * header on the next call.
138 * Abort the transaction and return the code.
140 #define ABORT_WITH(tt,code) return(ubik_AbortTrans(tt),code)
143 CreateOK(struct ubik_trans *ut, afs_int32 cid, afs_int32 oid, afs_int32 flag,
146 if (restricted && !admin)
149 if (flag & PRFOREIGN) {
150 /* Foreign users are recognized by the '@' sign and
151 * not by the PRFOREIGN flag.
154 } else if (flag & PRGRP) {
155 /* Allow anonymous group creation only if owner specified
156 * and running noAuth.
158 if (cid == ANONYMOUSID) {
159 if ((oid == 0) || !pr_noAuth)
162 } else { /* creating a user */
163 if (!admin && !pr_noAuth)
170 WhoIsThis(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid)
172 int code = WhoIsThisWithName(acall, at, aid, NULL);
173 if (code == 2 && *aid == ANONYMOUSID)
179 WritePreamble(struct ubik_trans **tt)
187 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, tt);
191 code = ubik_SetLock(*tt, 1, 1, LOCKWRITE);
195 code = read_DbHeader(*tt);
199 ubik_AbortTrans(*tt);
205 ReadPreamble(struct ubik_trans **tt)
213 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, tt);
217 code = ubik_SetLock(*tt, 1, 1, LOCKREAD);
221 code = read_DbHeader(*tt);
225 ubik_AbortTrans(*tt);
231 SPR_INewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid)
234 afs_int32 cid = ANONYMOUSID;
236 code = iNewEntry(call, aname, aid, oid, &cid);
237 osi_auditU(call, PTS_INewEntEvent, code, AUD_ID, aid, AUD_STR, aname,
238 AUD_ID, oid, AUD_END);
239 ViceLog(5, ("PTS_INewEntry: code %d cid %d aid %d aname %s oid %d\n", code, cid, aid, aname, oid));
244 iNewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid,
247 /* used primarily for conversion - not intended to be used as usual means
248 * of entering people into the database. */
249 struct ubik_trans *tt;
256 code = WritePreamble(&tt);
260 code = WhoIsThis(call, tt, cid);
262 ABORT_WITH(tt, PRPERM);
263 admin = IsAMemberOf(tt, *cid, SYSADMINID);
265 /* first verify the id is good */
267 ABORT_WITH(tt, PRPERM);
270 /* only sysadmin can reuse a group id */
271 if (!admin && !pr_noAuth && (aid != ntohl(cheader.maxGroup) - 1))
272 ABORT_WITH(tt, PRPERM);
274 if (FindByID(tt, aid))
275 ABORT_WITH(tt, PRIDEXIST);
277 /* check a few other things */
278 if (!CreateOK(tt, *cid, oid, gflag, admin))
279 ABORT_WITH(tt, PRPERM);
281 code = CreateEntry(tt, aname, &aid, 1, gflag, oid, *cid);
282 if (code != PRSUCCESS)
283 ABORT_WITH(tt, code);
285 /* finally, commit transaction */
286 code = ubik_EndTrans(tt);
294 SPR_NewEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
298 afs_int32 cid = ANONYMOUSID;
300 code = newEntry(call, aname, flag, oid, aid, &cid);
301 osi_auditU(call, PTS_NewEntEvent, code, AUD_ID, *aid, AUD_STR, aname,
302 AUD_ID, oid, AUD_END);
303 ViceLog(5, ("PTS_NewEntry: code %d cid %d aid %d aname %s oid %d\n", code, cid, *aid, aname, oid));
308 newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
309 afs_int32 *aid, afs_int32 *cid)
312 struct ubik_trans *tt;
314 char cname[PR_MAXNAMELEN];
317 code = WritePreamble(&tt);
321 /* this is for cross-cell self registration. It is not added in the
322 * SPR_INewEntry because we want self-registration to only do
323 * automatic id assignment.
325 code = WhoIsThisWithName(call, tt, cid, cname);
326 if (code != 2) { /* 2 specifies that this is a foreign cell request */
328 ABORT_WITH(tt, PRPERM);
329 admin = IsAMemberOf(tt, *cid, SYSADMINID);
331 admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
332 oid = *cid = SYSADMINID;
334 if (!CreateOK(tt, *cid, oid, flag, admin))
335 ABORT_WITH(tt, PRPERM);
337 code = CreateEntry(tt, aname, aid, 0, flag, oid, *cid);
338 if (code != PRSUCCESS)
339 ABORT_WITH(tt, code);
341 code = ubik_EndTrans(tt);
350 SPR_WhereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos)
353 afs_int32 cid = ANONYMOUSID;
355 code = whereIsIt(call, aid, apos, &cid);
356 osi_auditU(call, PTS_WheIsItEvent, code, AUD_ID, aid, AUD_LONG, *apos,
358 ViceLog(125, ("PTS_WhereIsIt: code %d cid %d aid %d apos %d\n", code, cid, aid, *apos));
363 whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos, afs_int32 *cid)
366 struct ubik_trans *tt;
369 code = ReadPreamble(&tt);
373 code = WhoIsThis(call, tt, cid);
375 ABORT_WITH(tt, PRPERM);
377 temp = FindByID(tt, aid);
379 ABORT_WITH(tt, PRNOENT);
381 code = ubik_EndTrans(tt);
389 SPR_DumpEntry(struct rx_call *call, afs_int32 apos,
390 struct prdebugentry *aentry)
393 afs_int32 cid = ANONYMOUSID;
395 code = dumpEntry(call, apos, aentry, &cid);
396 osi_auditU(call, PTS_DmpEntEvent, code, AUD_LONG, apos, AUD_END);
397 ViceLog(125, ("PTS_DumpEntry: code %d cid %d apos %d\n", code, cid, apos));
402 dumpEntry(struct rx_call *call, afs_int32 apos, struct prdebugentry *aentry,
406 struct ubik_trans *tt;
408 code = ReadPreamble(&tt);
412 code = WhoIsThis(call, tt, cid);
414 ABORT_WITH(tt, PRPERM);
415 code = pr_ReadEntry(tt, 0, apos, (struct prentry *)aentry);
417 ABORT_WITH(tt, code);
419 if (!AccessOK(tt, *cid, 0, PRP_STATUS_MEM, 0))
420 ABORT_WITH(tt, PRPERM);
422 /* Since prdebugentry is in the form of a prentry not a coentry, we will
423 * return the coentry slots in network order where the string is. */
425 if (aentry->flags & PRCONT) { /* wrong type, get coentry instead */
426 code = pr_ReadCoEntry(tt, 0, apos, aentry);
428 ABORT_WITH(tt, code);
431 code = ubik_EndTrans(tt);
438 SPR_AddToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
441 afs_int32 cid = ANONYMOUSID;
443 code = addToGroup(call, aid, gid, &cid);
444 osi_auditU(call, PTS_AdToGrpEvent, code, AUD_ID, gid, AUD_ID, aid,
446 ViceLog(5, ("PTS_AddToGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid));
451 addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid, afs_int32 *cid)
454 struct ubik_trans *tt;
457 struct prentry tentry;
458 struct prentry uentry;
460 if (gid == ANYUSERID || gid == AUTHUSERID)
462 if (aid == ANONYMOUSID)
465 code = WritePreamble(&tt);
469 code = WhoIsThis(call, tt, cid);
471 ABORT_WITH(tt, PRPERM);
472 tempu = FindByID(tt, aid);
474 ABORT_WITH(tt, PRNOENT);
475 memset(&uentry, 0, sizeof(uentry));
476 code = pr_ReadEntry(tt, 0, tempu, &uentry);
478 ABORT_WITH(tt, code);
480 #if !defined(SUPERGROUPS)
481 /* we don't allow groups as members of groups at present */
482 if (uentry.flags & PRGRP)
483 ABORT_WITH(tt, PRNOTUSER);
486 tempg = FindByID(tt, gid);
488 ABORT_WITH(tt, PRNOENT);
489 code = pr_ReadEntry(tt, 0, tempg, &tentry);
491 ABORT_WITH(tt, code);
492 /* make sure that this is a group */
493 if (!(tentry.flags & PRGRP))
494 ABORT_WITH(tt, PRNOTGROUP);
495 if (!AccessOK(tt, *cid, &tentry, PRP_ADD_MEM, PRP_ADD_ANY))
496 ABORT_WITH(tt, PRPERM);
498 code = AddToEntry(tt, &tentry, tempg, aid);
499 if (code != PRSUCCESS)
500 ABORT_WITH(tt, code);
502 #if defined(SUPERGROUPS)
503 if (uentry.flags & PRGRP)
504 code = AddToSGEntry(tt, &uentry, tempu, gid); /* mod group to be in sg */
507 /* now, modify the user's entry as well */
508 code = AddToEntry(tt, &uentry, tempu, gid);
509 if (code != PRSUCCESS)
510 ABORT_WITH(tt, code);
511 code = ubik_EndTrans(tt);
518 SPR_NameToID(struct rx_call *call, namelist *aname, idlist *aid)
522 code = nameToID(call, aname, aid);
523 osi_auditU(call, PTS_NmToIdEvent, code, AUD_END);
524 ViceLog(125, ("PTS_NameToID: code %d\n", code));
529 nameToID(struct rx_call *call, namelist *aname, idlist *aid)
532 struct ubik_trans *tt;
537 /* Initialize return struct */
539 aid->idlist_val = NULL;
541 size = aname->namelist_len;
547 aid->idlist_val = malloc(size * sizeof(afs_int32));
548 if (!aid->idlist_val)
551 code = ReadPreamble(&tt);
555 for (i = 0; i < aname->namelist_len; i++) {
557 char *nameinst, *cell;
558 afs_int32 islocal = 1;
560 strncpy(vname, aname->namelist_val[i], sizeof(vname));
561 vname[sizeof(vname)-1] ='\0';
564 cell = strchr(vname, '@');
571 code = afsconf_IsLocalRealmMatch(prdir, &islocal, nameinst, NULL, cell);
573 ("PTS_NameToID: afsconf_IsLocalRealmMatch(); code=%d, nameinst=%s, cell=%s\n",
574 code, nameinst, cell));
577 code = NameToID(tt, nameinst, &aid->idlist_val[i]);
579 code = NameToID(tt, aname->namelist_val[i], &aid->idlist_val[i]);
581 if (code != PRSUCCESS)
582 aid->idlist_val[i] = ANONYMOUSID;
583 osi_audit(PTS_NmToIdEvent, code, AUD_STR,
584 aname->namelist_val[i], AUD_ID, aid->idlist_val[i],
586 ViceLog(125, ("PTS_NameToID: code %d aname %s aid %d\n", code,
587 aname->namelist_val[i], aid->idlist_val[i]));
589 #ifndef AFS_PTHREAD_ENV
595 aid->idlist_len = aname->namelist_len;
597 code = ubik_EndTrans(tt);
605 * Given an array of ids, find the name for each of them.
606 * The array of ids and names is unlimited.
609 SPR_IDToName(struct rx_call *call, idlist *aid, namelist *aname)
613 code = idToName(call, aid, aname);
614 osi_auditU(call, PTS_IdToNmEvent, code, AUD_END);
615 ViceLog(125, ("PTS_IDToName: code %d\n", code));
620 idToName(struct rx_call *call, idlist *aid, namelist *aname)
623 struct ubik_trans *tt;
628 /* leave this first for rpc stub */
629 size = aid->idlist_len;
634 aname->namelist_val = malloc(size * PR_MAXNAMELEN);
635 aname->namelist_len = 0;
636 if (aname->namelist_val == 0)
638 if (aid->idlist_len == 0)
641 return PRTOOMANY; /* rxgen will probably handle this */
643 code = ReadPreamble(&tt);
647 for (i = 0; i < aid->idlist_len; i++) {
648 code = IDToName(tt, aid->idlist_val[i], aname->namelist_val[i]);
649 if (code != PRSUCCESS)
650 sprintf(aname->namelist_val[i], "%d", aid->idlist_val[i]);
651 osi_audit(PTS_IdToNmEvent, code, AUD_ID, aid->idlist_val[i],
652 AUD_STR, aname->namelist_val[i], AUD_END);
653 ViceLog(125, ("PTS_idToName: code %d aid %d aname %s\n", code,
654 aid->idlist_val[i], aname->namelist_val[i]));
656 #ifndef AFS_PTHREAD_ENV
662 aname->namelist_len = aid->idlist_len;
664 code = ubik_EndTrans(tt);
671 SPR_Delete(struct rx_call *call, afs_int32 aid)
674 afs_int32 cid = ANONYMOUSID;
676 code = Delete(call, aid, &cid);
677 osi_auditU(call, PTS_DelEvent, code, AUD_ID, aid, AUD_END);
678 ViceLog(5, ("PTS_Delete: code %d cid %d aid %d\n", code, cid, aid));
683 Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid)
686 struct ubik_trans *tt;
687 struct prentry tentry;
691 if (aid == SYSADMINID || aid == ANYUSERID || aid == AUTHUSERID
692 || aid == ANONYMOUSID)
695 code = WritePreamble(&tt);
699 code = WhoIsThis(call, tt, cid);
701 ABORT_WITH(tt, PRPERM);
703 /* Read in entry to be deleted */
704 loc = FindByID(tt, aid);
706 ABORT_WITH(tt, PRNOENT);
707 code = pr_ReadEntry(tt, 0, loc, &tentry);
709 ABORT_WITH(tt, PRDBFAIL);
711 /* Do some access checking */
712 if (tentry.owner != *cid && !IsAMemberOf(tt, *cid, SYSADMINID)
713 && !IsAMemberOf(tt, *cid, tentry.owner) && !pr_noAuth)
714 ABORT_WITH(tt, PRPERM);
716 /* Delete each continuation block as a separate transaction so that no one
717 * transaction become to large to complete. */
720 struct contentry centry;
723 code = pr_ReadCoEntry(tt, 0, nptr, ¢ry);
725 ABORT_WITH(tt, PRDBFAIL);
726 for (i = 0; i < COSIZE; i++) {
727 if (centry.entries[i] == PRBADID)
729 if (centry.entries[i] == 0)
731 #if defined(SUPERGROUPS)
732 if (aid < 0 && centry.entries[i] < 0) /* Supergroup */
733 code = RemoveFromSGEntry(tt, aid, centry.entries[i]);
736 code = RemoveFromEntry(tt, aid, centry.entries[i]);
738 ABORT_WITH(tt, code);
739 tentry.count--; /* maintain count */
740 #ifndef AFS_PTHREAD_ENV
745 tentry.next = centry.next; /* thread out this block */
746 code = FreeBlock(tt, nptr); /* free continuation block */
748 ABORT_WITH(tt, code);
749 code = pr_WriteEntry(tt, 0, loc, &tentry); /* update main entry */
751 ABORT_WITH(tt, code);
753 /* end this trans and start a new one */
754 code = ubik_EndTrans(tt);
757 #ifndef AFS_PTHREAD_ENV
758 IOMGR_Poll(); /* just to keep the connection alive */
760 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
763 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
765 ABORT_WITH(tt, code);
767 /* re-read entry to get consistent uptodate info */
768 loc = FindByID(tt, aid);
770 ABORT_WITH(tt, PRNOENT);
771 code = pr_ReadEntry(tt, 0, loc, &tentry);
773 ABORT_WITH(tt, PRDBFAIL);
778 #if defined(SUPERGROUPS)
779 /* Delete each continuation block as a separate transaction
780 * so that no one transaction become too large to complete. */
782 struct prentryg *tentryg = (struct prentryg *)&tentry;
783 nptr = tentryg->nextsg;
785 struct contentry centry;
788 code = pr_ReadCoEntry(tt, 0, nptr, ¢ry);
790 ABORT_WITH(tt, PRDBFAIL);
791 for (i = 0; i < COSIZE; i++) {
792 if (centry.entries[i] == PRBADID)
794 if (centry.entries[i] == 0)
796 code = RemoveFromEntry(tt, aid, centry.entries[i]);
798 ABORT_WITH(tt, code);
799 tentryg->countsg--; /* maintain count */
800 #ifndef AFS_PTHREAD_ENV
805 tentryg->nextsg = centry.next; /* thread out this block */
806 code = FreeBlock(tt, nptr); /* free continuation block */
808 ABORT_WITH(tt, code);
809 code = pr_WriteEntry(tt, 0, loc, &tentry); /* update main entry */
811 ABORT_WITH(tt, code);
813 /* end this trans and start a new one */
814 code = ubik_EndTrans(tt);
817 #ifndef AFS_PTHREAD_ENV
818 IOMGR_Poll(); /* just to keep the connection alive */
821 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
824 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
826 ABORT_WITH(tt, code);
828 /* re-read entry to get consistent uptodate info */
829 loc = FindByID(tt, aid);
831 ABORT_WITH(tt, PRNOENT);
832 code = pr_ReadEntry(tt, 0, loc, &tentry);
834 ABORT_WITH(tt, PRDBFAIL);
836 nptr = tentryg->nextsg;
840 #endif /* SUPERGROUPS */
842 /* Then move the owned chain, except possibly ourself to the orphan list.
843 * Because this list can be very long and so exceed the size of a ubik
844 * transaction, we start a new transaction every 50 entries. */
848 struct prentry nentry;
850 code = pr_ReadEntry(tt, 0, nptr, &nentry);
852 ABORT_WITH(tt, PRDBFAIL);
853 nptr = tentry.owned = nentry.nextOwned; /* thread out */
855 if (nentry.id != tentry.id) { /* don't add us to orphan chain! */
856 code = AddToOrphan(tt, nentry.id);
858 ABORT_WITH(tt, code);
860 #ifndef AFS_PTHREAD_ENV
861 if ((count & 3) == 0)
867 code = pr_WriteEntry(tt, 0, loc, &tentry); /* update main entry */
869 ABORT_WITH(tt, code);
871 /* end this trans and start a new one */
872 code = ubik_EndTrans(tt);
875 #ifndef AFS_PTHREAD_ENV
876 IOMGR_Poll(); /* just to keep the connection alive */
878 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
881 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
883 ABORT_WITH(tt, code);
885 /* re-read entry to get consistent uptodate info */
886 loc = FindByID(tt, aid);
888 ABORT_WITH(tt, PRNOENT);
889 code = pr_ReadEntry(tt, 0, loc, &tentry);
891 ABORT_WITH(tt, PRDBFAIL);
896 /* now do what's left of the deletion stuff */
897 code = DeleteEntry(tt, &tentry, loc);
898 if (code != PRSUCCESS)
899 ABORT_WITH(tt, code);
901 code = ubik_EndTrans(tt);
908 SPR_UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
909 struct PrUpdateEntry *uentry)
912 afs_int32 cid = ANONYMOUSID;
914 code = UpdateEntry(call, aid, name, uentry, &cid);
915 osi_auditU(call, PTS_UpdEntEvent, code, AUD_ID, aid, AUD_STR, name, AUD_END);
916 ViceLog(5, ("PTS_UpdateEntry: code %d cid %d aid %d name %s\n", code, cid, aid, name));
921 UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
922 struct PrUpdateEntry *uentry, afs_int32 *cid)
925 struct ubik_trans *tt;
926 struct prentry tentry;
932 if (aid == SYSADMINID || aid == ANYUSERID || aid == AUTHUSERID
933 || aid == ANONYMOUSID)
937 code = WritePreamble(&tt);
941 code = WhoIsThis(call, tt, cid);
943 ABORT_WITH(tt, PRPERM);
944 code = IsAMemberOf(tt, *cid, SYSADMINID);
945 if (!code && !pr_noAuth)
946 ABORT_WITH(tt, PRPERM);
948 /* Read in entry to be deleted */
950 loc = FindByID(tt, aid);
952 loc = FindByName(tt, name, &tentry);
955 ABORT_WITH(tt, PRNOENT);
956 code = pr_ReadEntry(tt, 0, loc, &tentry);
958 ABORT_WITH(tt, PRDBFAIL);
960 if (uentry->Mask & PRUPDATE_NAMEHASH) {
962 code = RemoveFromNameHash(tt, tentry.name, &tloc);
963 if (code != PRSUCCESS)
964 ABORT_WITH(tt, PRDBFAIL);
965 code = AddToNameHash(tt, tentry.name, loc);
967 ABORT_WITH(tt, code);
970 if (uentry->Mask & PRUPDATE_IDHASH) {
974 code = RemoveFromIDHash(tt, id, &tloc);
975 if (code != PRSUCCESS)
976 ABORT_WITH(tt, PRDBFAIL);
977 code = AddToIDHash(tt, id, loc);
979 ABORT_WITH(tt, code);
982 code = ubik_EndTrans(tt);
989 SPR_RemoveFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
992 afs_int32 cid = ANONYMOUSID;
994 code = removeFromGroup(call, aid, gid, &cid);
995 osi_auditU(call, PTS_RmFmGrpEvent, code, AUD_ID, gid, AUD_ID, aid,
997 ViceLog(5, ("PTS_RemoveFromGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid));
1002 removeFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid,
1006 struct ubik_trans *tt;
1009 struct prentry uentry;
1010 struct prentry gentry;
1012 code = WritePreamble(&tt);
1016 code = WhoIsThis(call, tt, cid);
1018 ABORT_WITH(tt, PRPERM);
1019 tempu = FindByID(tt, aid);
1021 ABORT_WITH(tt, PRNOENT);
1022 tempg = FindByID(tt, gid);
1024 ABORT_WITH(tt, PRNOENT);
1025 memset(&uentry, 0, sizeof(uentry));
1026 memset(&gentry, 0, sizeof(gentry));
1027 code = pr_ReadEntry(tt, 0, tempu, &uentry);
1029 ABORT_WITH(tt, code);
1030 code = pr_ReadEntry(tt, 0, tempg, &gentry);
1032 ABORT_WITH(tt, code);
1033 if (!(gentry.flags & PRGRP))
1034 ABORT_WITH(tt, PRNOTGROUP);
1035 #if !defined(SUPERGROUPS)
1036 if (uentry.flags & PRGRP)
1037 ABORT_WITH(tt, PRNOTUSER);
1039 if (!AccessOK(tt, *cid, &gentry, PRP_REMOVE_MEM, 0))
1040 ABORT_WITH(tt, PRPERM);
1041 code = RemoveFromEntry(tt, aid, gid);
1042 if (code != PRSUCCESS)
1043 ABORT_WITH(tt, code);
1044 #if defined(SUPERGROUPS)
1045 if (!(uentry.flags & PRGRP))
1047 code = RemoveFromEntry(tt, gid, aid);
1048 #if defined(SUPERGROUPS)
1050 code = RemoveFromSGEntry(tt, gid, aid);
1052 if (code != PRSUCCESS)
1053 ABORT_WITH(tt, code);
1055 code = ubik_EndTrans(tt);
1063 SPR_GetCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over)
1066 afs_int32 cid = ANONYMOUSID;
1068 code = getCPS(call, aid, alist, over, &cid);
1069 osi_auditU(call, PTS_GetCPSEvent, code, AUD_ID, aid, AUD_END);
1070 ViceLog(125, ("PTS_GetCPS: code %d cid %d aid %d\n", code, cid, aid));
1075 getCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over,
1079 struct ubik_trans *tt;
1081 struct prentry tentry;
1084 alist->prlist_len = 0;
1085 alist->prlist_val = NULL;
1087 code = ReadPreamble(&tt);
1091 temp = FindByID(tt, aid);
1093 ABORT_WITH(tt, PRNOENT);
1094 code = pr_ReadEntry(tt, 0, temp, &tentry);
1096 ABORT_WITH(tt, code);
1098 /* afs does authenticate now */
1099 code = WhoIsThis(call, tt, cid);
1100 if (code || !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
1101 ABORT_WITH(tt, PRPERM);
1103 code = GetList(tt, &tentry, alist, 1);
1104 if (code != PRSUCCESS)
1105 ABORT_WITH(tt, code);
1107 code = ubik_EndTrans(tt);
1113 inCPS(prlist CPS, afs_int32 id)
1117 for (i = (CPS.prlist_len - 1); i >= 0; i--) {
1118 if (CPS.prlist_val[i] == id)
1126 SPR_GetCPS2(struct rx_call *call, afs_int32 aid, afs_int32 ahost,
1127 prlist *alist, afs_int32 *over)
1130 afs_int32 cid = ANONYMOUSID;
1132 code = getCPS2(call, aid, ahost, alist, over, &cid);
1133 osi_auditU(call, PTS_GetCPS2Event, code, AUD_ID, aid, AUD_HOST, htonl(ahost),
1135 ViceLog(125, ("PTS_GetCPS2: code %d cid %d aid %d ahost %d\n", code, cid, aid, ahost));
1140 getCPS2(struct rx_call *call, afs_int32 aid, afs_uint32 ahost, prlist *alist,
1141 afs_int32 *over, afs_int32 *cid)
1144 struct ubik_trans *tt;
1146 struct prentry tentry;
1147 struct prentry host_tentry;
1150 struct in_addr iaddr;
1153 iaddr.s_addr = ntohl(ahost);
1154 alist->prlist_len = 0;
1155 alist->prlist_val = NULL;
1157 code = ReadPreamble(&tt);
1161 if (aid != PRBADID) {
1162 temp = FindByID(tt, aid);
1164 ABORT_WITH(tt, PRNOENT);
1165 code = pr_ReadEntry(tt, 0, temp, &tentry);
1167 ABORT_WITH(tt, code);
1169 /* afs does authenticate now */
1170 code = WhoIsThis(call, tt, cid);
1172 || !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
1173 ABORT_WITH(tt, PRPERM);
1175 code = NameToID(tt, inet_ntoa(iaddr), &hostid);
1176 if (code == PRSUCCESS && hostid != 0) {
1177 temp = FindByID(tt, hostid);
1179 code = pr_ReadEntry(tt, 0, temp, &host_tentry);
1180 if (code == PRSUCCESS)
1183 fprintf(stderr, "pr_ReadEntry returned %d\n", code);
1185 fprintf(stderr, "FindByID Failed -- Not found\n");
1188 code = GetList2(tt, &tentry, &host_tentry, alist, 1);
1190 code = GetList(tt, &tentry, alist, 1);
1192 code = addWildCards(tt, alist, ntohl(ahost));
1193 if (code != PRSUCCESS)
1194 ABORT_WITH(tt, code);
1196 code = ubik_EndTrans(tt);
1202 SPR_GetHostCPS(struct rx_call *call, afs_int32 ahost, prlist *alist,
1207 code = getHostCPS(call, ahost, alist, over);
1208 osi_auditU(call, PTS_GetHCPSEvent, code, AUD_HOST, htonl(ahost), AUD_END);
1209 ViceLog(125, ("PTS_GetHostCPS: code %d ahost %d\n", code, ahost));
1214 getHostCPS(struct rx_call *call, afs_uint32 ahost, prlist *alist,
1217 afs_int32 code, temp;
1218 struct ubik_trans *tt;
1219 struct prentry host_tentry;
1221 struct in_addr iaddr;
1224 iaddr.s_addr = ntohl(ahost);
1225 alist->prlist_len = 0;
1226 alist->prlist_val = NULL;
1228 code = ReadPreamble(&tt);
1232 code = NameToID(tt, inet_ntoa(iaddr), &hostid);
1233 if (code == PRSUCCESS && hostid != 0) {
1234 temp = FindByID(tt, hostid);
1236 code = pr_ReadEntry(tt, 0, temp, &host_tentry);
1237 if (code == PRSUCCESS) {
1238 code = GetList(tt, &host_tentry, alist, 0);
1242 fprintf(stderr, "pr_ReadEntry returned %d\n", code);
1244 fprintf(stderr, "FindByID Failed -- Not found\n");
1246 code = addWildCards(tt, alist, ntohl(ahost));
1248 if (code != PRSUCCESS)
1249 ABORT_WITH(tt, code);
1251 code = ubik_EndTrans(tt);
1257 SPR_ListMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
1261 code = listMax(call, uid, gid);
1262 osi_auditU(call, PTS_LstMaxEvent, code, AUD_END);
1263 ViceLog(125, ("PTS_ListMax: code %d\n", code));
1268 listMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
1271 struct ubik_trans *tt;
1273 code = ReadPreamble(&tt);
1277 code = GetMax(tt, uid, gid);
1278 if (code != PRSUCCESS)
1279 ABORT_WITH(tt, code);
1281 code = ubik_EndTrans(tt);
1288 SPR_SetMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag)
1291 afs_int32 cid = ANONYMOUSID;
1293 code = setMax(call, aid, gflag, &cid);
1294 osi_auditU(call, PTS_SetMaxEvent, code, AUD_ID, aid, AUD_LONG, gflag,
1296 ViceLog(125, ("PTS_SetMax: code %d cid %d aid %d gflag %d\n", code, cid, aid, gflag));
1301 setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag, afs_int32 *cid)
1304 struct ubik_trans *tt;
1306 code = WritePreamble(&tt);
1310 code = WhoIsThis(call, tt, cid);
1312 ABORT_WITH(tt, PRPERM);
1313 if (!AccessOK(tt, *cid, 0, 0, 0))
1314 ABORT_WITH(tt, PRPERM);
1315 if (((gflag & PRGRP) && (aid > 0)) || (!(gflag & PRGRP) && (aid < 0)))
1316 ABORT_WITH(tt, PRBADARG);
1318 code = SetMax(tt, aid, gflag);
1319 if (code != PRSUCCESS)
1320 ABORT_WITH(tt, code);
1322 code = ubik_EndTrans(tt);
1329 SPR_ListEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry)
1332 afs_int32 cid = ANONYMOUSID;
1334 code = listEntry(call, aid, aentry, &cid);
1335 osi_auditU(call, PTS_LstEntEvent, code, AUD_ID, aid, AUD_END);
1336 ViceLog(125, ("PTS_ListEntry: code %d cid %d aid %d\n", code, cid, aid));
1341 listEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry,
1345 struct ubik_trans *tt;
1347 struct prentry tentry;
1349 code = ReadPreamble(&tt);
1353 code = WhoIsThis(call, tt, cid);
1355 ABORT_WITH(tt, PRPERM);
1356 temp = FindByID(tt, aid);
1358 ABORT_WITH(tt, PRNOENT);
1359 code = pr_ReadEntry(tt, 0, temp, &tentry);
1361 ABORT_WITH(tt, code);
1362 if (!AccessOK(tt, *cid, &tentry, PRP_STATUS_MEM, PRP_STATUS_ANY))
1363 ABORT_WITH(tt, PRPERM);
1365 aentry->flags = tentry.flags >> PRIVATE_SHIFT;
1366 if (aentry->flags == 0) {
1367 if (tentry.flags & PRGRP)
1368 aentry->flags = prp_group_default >> PRIVATE_SHIFT;
1370 aentry->flags = prp_user_default >> PRIVATE_SHIFT;
1372 aentry->owner = tentry.owner;
1373 aentry->id = tentry.id;
1374 strncpy(aentry->name, tentry.name, PR_MAXNAMELEN);
1375 aentry->creator = tentry.creator;
1376 aentry->ngroups = tentry.ngroups;
1377 aentry->nusers = tentry.nusers;
1378 aentry->count = tentry.count;
1379 memset(aentry->reserved, 0, sizeof(aentry->reserved));
1380 code = ubik_EndTrans(tt);
1387 SPR_ListEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
1388 prentries *bulkentries, afs_int32 *nextstartindex)
1391 afs_int32 cid = ANONYMOUSID;
1393 code = listEntries(call, flag, startindex, bulkentries, nextstartindex, &cid);
1394 osi_auditU(call, PTS_LstEntsEvent, code, AUD_LONG, flag, AUD_END);
1395 ViceLog(125, ("PTS_ListEntries: code %d cid %d flag %d\n", code, cid, flag));
1400 listEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
1401 prentries *bulkentries, afs_int32 *nextstartindex, afs_int32 *cid)
1404 struct ubik_trans *tt;
1405 afs_int32 i, eof, pos, maxentries, f;
1406 struct prentry tentry;
1407 afs_int32 pollcount = 0;
1409 *nextstartindex = -1;
1410 bulkentries->prentries_val = 0;
1411 bulkentries->prentries_len = 0;
1413 code = ReadPreamble(&tt);
1417 /* Make sure we are an authenticated caller and that we are on the
1420 code = WhoIsThis(call, tt, cid);
1422 ABORT_WITH(tt, PRPERM);
1423 code = IsAMemberOf(tt, *cid, SYSADMINID);
1424 if (!code && !pr_noAuth)
1425 ABORT_WITH(tt, PRPERM);
1427 eof = ntohl(cheader.eofPtr) - sizeof(cheader);
1428 maxentries = eof / sizeof(struct prentry);
1429 for (i = startindex; i < maxentries; i++) {
1430 pos = i * sizeof(struct prentry) + sizeof(cheader);
1431 code = pr_ReadEntry(tt, 0, pos, &tentry);
1435 if (++pollcount > 50) {
1436 #ifndef AFS_PTHREAD_ENV
1442 f = (tentry.flags & PRTYPE);
1443 if (((flag & PRUSERS) && (f == 0)) || /* User entry */
1444 ((flag & PRGROUPS) && (f & PRGRP))) { /* Group entry */
1445 code = put_prentries(&tentry, bulkentries);
1447 break; /* Filled return array */
1454 *nextstartindex = i;
1458 if (bulkentries->prentries_val)
1459 free(bulkentries->prentries_val);
1460 bulkentries->prentries_val = 0;
1461 bulkentries->prentries_len = 0;
1462 ABORT_WITH(tt, code);
1464 code = ubik_EndTrans(tt);
1471 #define PR_MAXENTRIES 500
1473 put_prentries(struct prentry *tentry, prentries *bulkentries)
1475 struct prlistentries *entry;
1477 if (bulkentries->prentries_val == 0) {
1478 bulkentries->prentries_len = 0;
1479 bulkentries->prentries_val = malloc(PR_MAXENTRIES *
1480 sizeof(struct prentry));
1481 if (!bulkentries->prentries_val) {
1486 if (bulkentries->prentries_len >= PR_MAXENTRIES) {
1490 entry = (struct prlistentries *)bulkentries->prentries_val;
1491 entry += bulkentries->prentries_len;
1493 entry->flags = tentry->flags >> PRIVATE_SHIFT;
1494 if (entry->flags == 0) {
1497 flags & PRGRP) ? prp_group_default : prp_user_default) >>
1500 entry->owner = tentry->owner;
1501 entry->id = tentry->id;
1502 entry->creator = tentry->creator;
1503 entry->ngroups = tentry->ngroups;
1504 entry->nusers = tentry->nusers;
1505 entry->count = tentry->count;
1506 strncpy(entry->name, tentry->name, PR_MAXNAMELEN);
1507 memset(entry->reserved, 0, sizeof(entry->reserved));
1508 bulkentries->prentries_len++;
1513 SPR_ChangeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid,
1517 afs_int32 cid = ANONYMOUSID;
1519 code = changeEntry(call, aid, name, oid, newid, &cid);
1520 osi_auditU(call, PTS_ChgEntEvent, code, AUD_ID, aid, AUD_STR, name,
1521 AUD_LONG, oid, AUD_LONG, newid, AUD_END);
1522 ViceLog(5, ("PTS_ChangeEntry: code %d cid %d aid %d name %s oid %d newid %d\n", code, cid, aid, name, oid, newid));
1527 changeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid,
1528 afs_int32 newid, afs_int32 *cid)
1531 struct ubik_trans *tt;
1538 if (aid == ANYUSERID || aid == AUTHUSERID || aid == ANONYMOUSID
1539 || aid == SYSADMINID)
1542 code = WritePreamble(&tt);
1546 code = WhoIsThis(call, tt, cid);
1548 ABORT_WITH(tt, PRPERM);
1549 pos = FindByID(tt, aid);
1551 ABORT_WITH(tt, PRNOENT);
1552 /* protection check in changeentry */
1553 code = ChangeEntry(tt, aid, *cid, name, oid, newid);
1554 if (code != PRSUCCESS)
1555 ABORT_WITH(tt, code);
1557 code = ubik_EndTrans(tt);
1562 SPR_SetFieldsEntry(struct rx_call *call,
1564 afs_int32 mask, /* specify which fields to update */
1565 afs_int32 flags, afs_int32 ngroups, afs_int32 nusers,
1566 afs_int32 spare1, afs_int32 spare2)
1569 afs_int32 cid = ANONYMOUSID;
1572 setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1,
1574 osi_auditU(call, PTS_SetFldEntEvent, code, AUD_ID, id, AUD_END);
1575 ViceLog(5, ("PTS_SetFieldsEntry: code %d cid %d id %d\n", code, cid, id));
1580 setFieldsEntry(struct rx_call *call,
1582 afs_int32 mask, /* specify which fields to update */
1583 afs_int32 flags, afs_int32 ngroups, afs_int32 nusers,
1584 afs_int32 spare1, afs_int32 spare2, afs_int32 *cid)
1587 struct ubik_trans *tt;
1589 struct prentry tentry;
1593 return 0; /* no-op */
1595 if (id == ANYUSERID || id == AUTHUSERID || id == ANONYMOUSID)
1598 code = WritePreamble(&tt);
1602 code = WhoIsThis(call, tt, cid);
1604 ABORT_WITH(tt, PRPERM);
1605 pos = FindByID(tt, id);
1607 ABORT_WITH(tt, PRNOENT);
1608 code = pr_ReadEntry(tt, 0, pos, &tentry);
1610 ABORT_WITH(tt, code);
1611 tflags = tentry.flags;
1613 if (mask & (PR_SF_NGROUPS | PR_SF_NUSERS)) {
1614 if (!AccessOK(tt, *cid, 0, 0, 0))
1615 ABORT_WITH(tt, PRPERM);
1616 if ((tflags & PRQUOTA) == 0) { /* default if only setting one */
1617 tentry.ngroups = tentry.nusers = 20;
1620 if (!AccessOK(tt, *cid, &tentry, 0, 0))
1621 ABORT_WITH(tt, PRPERM);
1624 if (mask & 0xffff) { /* if setting flag bits */
1625 afs_int32 flagsMask = mask & 0xffff;
1626 tflags &= ~(flagsMask << PRIVATE_SHIFT);
1627 tflags |= (flags & flagsMask) << PRIVATE_SHIFT;
1631 if (mask & PR_SF_NGROUPS) { /* setting group limit */
1633 ABORT_WITH(tt, PRBADARG);
1634 tentry.ngroups = ngroups;
1638 if (mask & PR_SF_NUSERS) { /* setting foreign user limit */
1640 ABORT_WITH(tt, PRBADARG);
1641 tentry.nusers = nusers;
1644 tentry.flags = tflags;
1646 code = pr_WriteEntry(tt, 0, pos, &tentry);
1648 ABORT_WITH(tt, code);
1650 code = ubik_EndTrans(tt);
1655 SPR_ListElements(struct rx_call *call, afs_int32 aid, prlist *alist,
1659 afs_int32 cid = ANONYMOUSID;
1661 code = listElements(call, aid, alist, over, &cid);
1662 osi_auditU(call, PTS_LstEleEvent, code, AUD_ID, aid, AUD_END);
1663 ViceLog(125, ("PTS_ListElements: code %d cid %d aid %d\n", code, cid, aid));
1668 listElements(struct rx_call *call, afs_int32 aid, prlist *alist,
1669 afs_int32 *over, afs_int32 *cid)
1672 struct ubik_trans *tt;
1674 struct prentry tentry;
1677 alist->prlist_len = 0;
1678 alist->prlist_val = NULL;
1680 code = ReadPreamble(&tt);
1684 code = WhoIsThis(call, tt, cid);
1686 ABORT_WITH(tt, PRPERM);
1688 temp = FindByID(tt, aid);
1690 ABORT_WITH(tt, PRNOENT);
1691 code = pr_ReadEntry(tt, 0, temp, &tentry);
1693 ABORT_WITH(tt, code);
1694 if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
1695 ABORT_WITH(tt, PRPERM);
1697 code = GetList(tt, &tentry, alist, 0);
1698 if (code != PRSUCCESS)
1699 ABORT_WITH(tt, code);
1701 code = ubik_EndTrans(tt);
1707 SPR_ListSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
1710 #if defined(SUPERGROUPS)
1712 afs_int32 cid = ANONYMOUSID;
1714 code = listSuperGroups(call, aid, alist, over, &cid);
1715 osi_auditU(call, PTS_LstSGrps, code, AUD_ID, aid, AUD_END);
1716 ViceLog(125, ("PTS_ListSuperGroups: code %d cid %d aid %d\n", code, cid, aid));
1719 return RXGEN_OPCODE;
1723 #if defined(SUPERGROUPS)
1725 listSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
1726 afs_int32 *over, afs_int32 *cid)
1729 struct ubik_trans *tt;
1731 struct prentry tentry;
1733 alist->prlist_len = 0;
1734 alist->prlist_val = (afs_int32 *) 0;
1736 code = ReadPreamble(&tt);
1740 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
1742 ABORT_WITH(tt, code);
1743 code = WhoIsThis(call, tt, cid);
1745 ABORT_WITH(tt, PRPERM);
1747 temp = FindByID(tt, aid);
1749 ABORT_WITH(tt, PRNOENT);
1750 code = pr_ReadEntry(tt, 0, temp, &tentry);
1752 ABORT_WITH(tt, code);
1753 if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
1754 ABORT_WITH(tt, PRPERM);
1756 code = GetSGList(tt, &tentry, alist);
1758 if (code == PRTOOMANY)
1760 else if (code != PRSUCCESS)
1761 ABORT_WITH(tt, code);
1763 code = ubik_EndTrans(tt);
1768 #endif /* SUPERGROUPS */
1772 * List the entries owned by this id. If the id is zero,
1773 * return the orphans list. This will return up to PR_MAXGROUPS
1774 * at a time with the lastP available to get the rest. The
1775 * maximum value is enforced in GetOwnedChain().
1778 SPR_ListOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
1782 afs_int32 cid = ANONYMOUSID;
1784 code = listOwned(call, aid, alist, lastP, &cid);
1785 osi_auditU(call, PTS_LstOwnEvent, code, AUD_ID, aid, AUD_END);
1786 ViceLog(125, ("PTS_ListOwned: code %d cid %d aid %d\n", code, cid, aid));
1791 listOwned(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *lastP,
1795 struct ubik_trans *tt;
1796 struct prentry tentry;
1800 alist->prlist_len = 0;
1801 alist->prlist_val = NULL;
1808 code = ReadPreamble(&tt);
1812 code = WhoIsThis(call, tt, cid);
1814 ABORT_WITH(tt, PRPERM);
1817 code = pr_ReadEntry(tt, 0, start, &tentry);
1818 if (!code && (tentry.owner == aid))
1819 head = start; /* pick up where we left off */
1824 afs_int32 loc = FindByID(tt, aid);
1826 ABORT_WITH(tt, PRNOENT);
1827 code = pr_ReadEntry(tt, 0, loc, &tentry);
1829 ABORT_WITH(tt, code);
1831 if (!AccessOK(tt, *cid, &tentry, -1, PRP_OWNED_ANY))
1832 ABORT_WITH(tt, PRPERM);
1833 head = tentry.owned;
1835 if (!AccessOK(tt, *cid, 0, 0, 0))
1836 ABORT_WITH(tt, PRPERM);
1837 head = ntohl(cheader.orphan);
1841 code = GetOwnedChain(tt, &head, alist);
1843 if (code == PRTOOMANY)
1846 ABORT_WITH(tt, code);
1849 code = ubik_EndTrans(tt);
1854 SPR_IsAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid,
1858 afs_int32 cid = ANONYMOUSID;
1860 code = isAMemberOf(call, uid, gid, flag, &cid);
1861 osi_auditU(call, PTS_IsMemOfEvent, code, AUD_LONG, uid, AUD_LONG, gid,
1863 ViceLog(125, ("PTS_IsAMemberOf: code %d cid %d uid %d gid %d\n", code, cid, uid, gid));
1868 isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid, afs_int32 *flag,
1872 struct ubik_trans *tt;
1874 code = ReadPreamble(&tt);
1879 afs_int32 uloc = FindByID(tt, uid);
1880 afs_int32 gloc = FindByID(tt, gid);
1881 struct prentry uentry, gentry;
1884 ABORT_WITH(tt, PRNOENT);
1885 code = WhoIsThis(call, tt, cid);
1887 ABORT_WITH(tt, PRPERM);
1888 code = pr_ReadEntry(tt, 0, uloc, &uentry);
1890 ABORT_WITH(tt, code);
1891 code = pr_ReadEntry(tt, 0, gloc, &gentry);
1893 ABORT_WITH(tt, code);
1894 #if !defined(SUPERGROUPS)
1895 if ((uentry.flags & PRGRP) || !(gentry.flags & PRGRP))
1896 ABORT_WITH(tt, PRBADARG);
1898 if (!(gentry.flags & PRGRP))
1899 ABORT_WITH(tt, PRBADARG);
1901 if (!AccessOK(tt, *cid, &uentry, 0, PRP_MEMBER_ANY)
1902 && !AccessOK(tt, *cid, &gentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
1903 ABORT_WITH(tt, PRPERM);
1906 *flag = IsAMemberOf(tt, uid, gid);
1907 code = ubik_EndTrans(tt);
1912 addWildCards(struct ubik_trans *tt, prlist *alist, afs_uint32 host)
1915 struct prentry tentry;
1917 unsigned wild = htonl(0xffffff00);
1918 struct in_addr iaddr;
1920 int size = 0, i, code;
1923 while ((host = (host & wild))) {
1924 wild = htonl(ntohl(wild) << 8);
1925 iaddr.s_addr = host;
1926 code = NameToID(tt, inet_ntoa(iaddr), &hostid);
1927 if (code == PRSUCCESS && hostid != 0) {
1928 temp = FindByID(tt, hostid);
1930 code = pr_ReadEntry(tt, 0, temp, &tentry);
1931 if (code != PRSUCCESS)
1937 wlist.prlist_len = 0;
1938 wlist.prlist_val = NULL;
1940 code = GetList(tt, &tentry, &wlist, 0);
1943 added += wlist.prlist_len;
1944 for (i = 0; i < wlist.prlist_len; i++) {
1945 if (!inCPS(*alist, wlist.prlist_val[i]))
1946 if ((code = AddToPRList(alist, &size, wlist.prlist_val[i]))) {
1947 free(wlist.prlist_val);
1951 if (wlist.prlist_val)
1952 free(wlist.prlist_val);
1955 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1960 WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid,
1963 afs_int32 islocal = 1;
1964 /* aid is set to the identity of the caller, if known, else ANONYMOUSID */
1965 /* returns -1 and sets aid to ANONYMOUSID on any failure */
1966 struct rx_connection *tconn;
1968 char tcell[MAXKTCREALMLEN];
1969 char name[MAXKTCNAMELEN];
1970 char inst[MAXKTCNAMELEN];
1975 tconn = rx_ConnectionOf(acall);
1976 code = rx_SecurityClassOf(tconn);
1979 else if (code == 1) { /* vab class */
1980 goto done; /* no longer supported */
1981 } else if (code == 2) { /* kad class */
1982 if ((code = rxkad_GetServerInfo(rx_ConnectionOf(acall), NULL, NULL,
1983 name, inst, tcell, NULL)))
1987 code = afsconf_IsLocalRealmMatch(prdir, &islocal, name, inst, tcell);
1991 strncpy(vname, name, sizeof(vname));
1992 if ((ilen = strlen(inst))) {
1993 if (strlen(vname) + 1 + ilen >= sizeof(vname))
1996 strcat(vname, inst);
1999 if (strlen(vname) + strlen(tcell) + 1 >= sizeof(vname))
2002 strcat(vname, tcell);
2003 lcstring(vname, vname, sizeof(vname));
2004 code = NameToID(at, vname, aid);
2006 strcpy(aname, vname);
2010 if (strcmp(AUTH_SUPERUSER, vname) == 0)
2011 *aid = SYSADMINID; /* special case for the fileserver */
2013 lcstring(vname, vname, sizeof(vname));
2014 code = NameToID(at, vname, aid);
2018 if (code && !pr_noAuth)