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>
65 #include <rx/rx_identity.h>
67 #include <afs/cellconfig.h>
71 #include "ptprototypes.h"
72 #include "afs/audit.h"
74 extern int restricted;
75 extern int restrict_anonymous;
76 extern struct ubik_dbase *dbase;
78 extern int prp_group_default;
79 extern int prp_user_default;
80 extern struct afsconf_dir *prdir;
82 static afs_int32 iNewEntry(struct rx_call *call, char aname[], afs_int32 aid,
83 afs_int32 oid, afs_int32 *cid);
84 static afs_int32 newEntry(struct rx_call *call, char aname[], afs_int32 flag,
85 afs_int32 oid, afs_int32 *aid, afs_int32 *cid);
86 static afs_int32 whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos,
88 static afs_int32 dumpEntry(struct rx_call *call, afs_int32 apos,
89 struct prdebugentry *aentry, afs_int32 *cid);
90 static afs_int32 addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid,
92 static afs_int32 nameToID(struct rx_call *call, namelist *aname, idlist *aid);
93 static afs_int32 idToName(struct rx_call *call, idlist *aid, namelist *aname, afs_int32 *cid);
94 static afs_int32 Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid);
95 static afs_int32 UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
96 struct PrUpdateEntry *uentry, afs_int32 *cid);
97 static afs_int32 removeFromGroup(struct rx_call *call, afs_int32 aid,
98 afs_int32 gid, afs_int32 *cid);
99 static afs_int32 getCPS(struct rx_call *call, afs_int32 aid, prlist *alist,
100 afs_int32 *over, afs_int32 *cid);
101 static afs_int32 getCPS2(struct rx_call *call, afs_int32 aid, afs_uint32 ahost,
102 prlist *alist, afs_int32 *over, afs_int32 *cid);
103 static afs_int32 getHostCPS(struct rx_call *call, afs_uint32 ahost,
104 prlist *alist, afs_int32 *over, afs_int32 *cid);
105 static afs_int32 listMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid, afs_int32 *cid);
106 static afs_int32 setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag,
108 static afs_int32 listEntry(struct rx_call *call, afs_int32 aid,
109 struct prcheckentry *aentry, afs_int32 *cid);
110 static afs_int32 listEntries(struct rx_call *call, afs_int32 flag,
111 afs_int32 startindex, prentries *bulkentries,
112 afs_int32 *nextstartindex, afs_int32 *cid);
113 static afs_int32 put_prentries(struct prentry *tentry, prentries *bulkentries);
114 static afs_int32 changeEntry(struct rx_call *call, afs_int32 aid, char *name,
115 afs_int32 oid, afs_int32 newid, afs_int32 *cid);
116 static afs_int32 setFieldsEntry(struct rx_call *call, afs_int32 id,
117 afs_int32 mask, afs_int32 flags,
118 afs_int32 ngroups, afs_int32 nusers,
119 afs_int32 spare1, afs_int32 spare2,
121 static afs_int32 listElements(struct rx_call *call, afs_int32 aid,
122 prlist *alist, afs_int32 *over, afs_int32 *cid);
123 #if defined(SUPERGROUPS)
124 static afs_int32 listSuperGroups(struct rx_call *call, afs_int32 aid,
125 prlist *alist, afs_int32 *over,
128 static afs_int32 listOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
129 afs_int32 *lastP, afs_int32 *cid);
130 static afs_int32 isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid,
131 afs_int32 *flag, afs_int32 *cid);
132 static afs_int32 addWildCards(struct ubik_trans *tt, prlist *alist,
134 static afs_int32 WhoIsThisWithName(struct rx_call *acall,
135 struct ubik_trans *at, afs_int32 *aid,
138 /* when we abort, the ubik cachedVersion will be reset, so we'll read in the
139 * header on the next call.
140 * Abort the transaction and return the code.
142 #define ABORT_WITH(tt,code) return(ubik_AbortTrans(tt),code)
145 CreateOK(struct ubik_trans *ut, afs_int32 cid, afs_int32 oid, afs_int32 flag,
148 if (restricted && !admin)
151 if (flag & PRFOREIGN) {
152 /* Foreign users are recognized by the '@' sign and
153 * not by the PRFOREIGN flag.
156 } else if (flag & PRGRP) {
157 /* Allow anonymous group creation only if owner specified
158 * and running noAuth.
160 if (cid == ANONYMOUSID) {
161 if ((oid == 0) || !pr_noAuth)
164 } else { /* creating a user */
165 if (oid == ANONYMOUSID)
167 if (!admin && !pr_noAuth)
174 WhoIsThis(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid)
176 int code = WhoIsThisWithName(acall, at, aid, NULL);
177 if (code == 2 && *aid == ANONYMOUSID)
183 WritePreamble(struct ubik_trans **tt)
191 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, tt);
195 code = ubik_SetLock(*tt, 1, 1, LOCKWRITE);
199 code = read_DbHeader(*tt);
203 ubik_AbortTrans(*tt);
209 ReadPreamble(struct ubik_trans **tt)
217 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, tt);
221 code = ubik_SetLock(*tt, 1, 1, LOCKREAD);
225 code = read_DbHeader(*tt);
229 ubik_AbortTrans(*tt);
235 SPR_INewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid)
238 afs_int32 cid = ANONYMOUSID;
240 code = iNewEntry(call, aname, aid, oid, &cid);
241 osi_auditU(call, PTS_INewEntEvent, code, AUD_ID, aid, AUD_STR, aname,
242 AUD_ID, oid, AUD_END);
243 ViceLog(5, ("PTS_INewEntry: code %d cid %d aid %d aname %s oid %d\n", code, cid, aid, aname, oid));
248 iNewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid,
251 /* used primarily for conversion - not intended to be used as usual means
252 * of entering people into the database. */
253 struct ubik_trans *tt;
260 code = WritePreamble(&tt);
264 code = WhoIsThis(call, tt, cid);
266 ABORT_WITH(tt, PRPERM);
267 admin = IsAMemberOf(tt, *cid, SYSADMINID);
269 /* first verify the id is good */
271 ABORT_WITH(tt, PRPERM);
274 /* only sysadmin can reuse a group id */
275 if (!admin && !pr_noAuth && (aid != ntohl(cheader.maxGroup) - 1))
276 ABORT_WITH(tt, PRPERM);
278 if (FindByID(tt, aid))
279 ABORT_WITH(tt, PRIDEXIST);
281 /* check a few other things */
282 if (!CreateOK(tt, *cid, oid, gflag, admin))
283 ABORT_WITH(tt, PRPERM);
285 code = CreateEntry(tt, aname, &aid, 1, gflag, oid, *cid);
286 if (code != PRSUCCESS)
287 ABORT_WITH(tt, code);
289 /* finally, commit transaction */
290 code = ubik_EndTrans(tt);
298 SPR_NewEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
302 afs_int32 cid = ANONYMOUSID;
304 code = newEntry(call, aname, flag, oid, aid, &cid);
305 osi_auditU(call, PTS_NewEntEvent, code, AUD_ID, *aid, AUD_STR, aname,
306 AUD_ID, oid, AUD_END);
307 ViceLog(5, ("PTS_NewEntry: code %d cid %d aid %d aname %s oid %d\n", code, cid, *aid, aname, oid));
312 newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
313 afs_int32 *aid, afs_int32 *cid)
316 struct ubik_trans *tt;
319 char cname[PR_MAXNAMELEN];
322 code = WritePreamble(&tt);
326 /* this is for cross-cell self registration. It is not added in the
327 * SPR_INewEntry because we want self-registration to only do
328 * automatic id assignment.
330 code = WhoIsThisWithName(call, tt, cid, cname);
331 if (code && code != 2)
332 ABORT_WITH(tt, PRPERM);
333 admin = IsAMemberOf(tt, *cid, SYSADMINID);
334 if (code == 2 /* foreign cell request */) {
337 if (!restricted && (strcmp(aname, cname) == 0)) {
338 /* can't autoregister while providing an owner id */
340 ABORT_WITH(tt, PRPERM);
346 if (!CreateOK(tt, *cid, oid, flag, admin))
347 ABORT_WITH(tt, PRPERM);
349 code = CreateEntry(tt, aname, aid, 0, flag, oid, *cid);
351 * If this was an autoregistration then be sure to audit log
352 * the proper id as the creator.
354 if (foreign && code == 0 && *aid > 0)
356 if (code != PRSUCCESS)
357 ABORT_WITH(tt, code);
359 code = ubik_EndTrans(tt);
368 SPR_WhereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos)
371 afs_int32 cid = ANONYMOUSID;
373 code = whereIsIt(call, aid, apos, &cid);
374 osi_auditU(call, PTS_WheIsItEvent, code, AUD_ID, aid, AUD_LONG, *apos,
376 ViceLog(125, ("PTS_WhereIsIt: code %d cid %d aid %d apos %d\n", code, cid, aid, *apos));
381 whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos, afs_int32 *cid)
384 struct ubik_trans *tt;
387 code = ReadPreamble(&tt);
391 code = WhoIsThis(call, tt, cid);
393 ABORT_WITH(tt, PRPERM);
394 if (!pr_noAuth && restrict_anonymous && *cid == ANONYMOUSID)
395 ABORT_WITH(tt, PRPERM);
397 temp = FindByID(tt, aid);
399 ABORT_WITH(tt, PRNOENT);
401 code = ubik_EndTrans(tt);
409 SPR_DumpEntry(struct rx_call *call, afs_int32 apos,
410 struct prdebugentry *aentry)
413 afs_int32 cid = ANONYMOUSID;
415 code = dumpEntry(call, apos, aentry, &cid);
416 osi_auditU(call, PTS_DmpEntEvent, code, AUD_LONG, apos, AUD_END);
417 ViceLog(125, ("PTS_DumpEntry: code %d cid %d apos %d\n", code, cid, apos));
422 dumpEntry(struct rx_call *call, afs_int32 apos, struct prdebugentry *aentry,
426 struct ubik_trans *tt;
428 code = ReadPreamble(&tt);
432 code = WhoIsThis(call, tt, cid);
434 ABORT_WITH(tt, PRPERM);
435 code = pr_ReadEntry(tt, 0, apos, (struct prentry *)aentry);
437 ABORT_WITH(tt, code);
439 if (!AccessOK(tt, *cid, 0, PRP_STATUS_MEM, 0))
440 ABORT_WITH(tt, PRPERM);
442 code = ubik_EndTrans(tt);
449 SPR_AddToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
452 afs_int32 cid = ANONYMOUSID;
454 code = addToGroup(call, aid, gid, &cid);
455 osi_auditU(call, PTS_AdToGrpEvent, code, AUD_ID, gid, AUD_ID, aid,
457 ViceLog(5, ("PTS_AddToGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid));
462 addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid, afs_int32 *cid)
465 struct ubik_trans *tt;
468 struct prentry tentry;
469 struct prentry uentry;
471 if (gid == ANYUSERID || gid == AUTHUSERID)
473 if (aid == ANONYMOUSID)
476 code = WritePreamble(&tt);
480 code = WhoIsThis(call, tt, cid);
482 ABORT_WITH(tt, PRPERM);
483 tempu = FindByID(tt, aid);
485 ABORT_WITH(tt, PRNOENT);
486 memset(&uentry, 0, sizeof(uentry));
487 code = pr_ReadEntry(tt, 0, tempu, &uentry);
489 ABORT_WITH(tt, code);
491 #if !defined(SUPERGROUPS)
492 /* we don't allow groups as members of groups at present */
493 if (uentry.flags & PRGRP)
494 ABORT_WITH(tt, PRNOTUSER);
497 tempg = FindByID(tt, gid);
499 ABORT_WITH(tt, PRNOENT);
500 code = pr_ReadEntry(tt, 0, tempg, &tentry);
502 ABORT_WITH(tt, code);
503 /* make sure that this is a group */
504 if (!(tentry.flags & PRGRP))
505 ABORT_WITH(tt, PRNOTGROUP);
506 if (!AccessOK(tt, *cid, &tentry, PRP_ADD_MEM, PRP_ADD_ANY))
507 ABORT_WITH(tt, PRPERM);
509 code = AddToEntry(tt, &tentry, tempg, aid);
510 if (code != PRSUCCESS)
511 ABORT_WITH(tt, code);
513 #if defined(SUPERGROUPS)
514 if (uentry.flags & PRGRP)
515 code = AddToSGEntry(tt, &uentry, tempu, gid); /* mod group to be in sg */
518 /* now, modify the user's entry as well */
519 code = AddToEntry(tt, &uentry, tempu, gid);
520 if (code != PRSUCCESS)
521 ABORT_WITH(tt, code);
522 code = ubik_EndTrans(tt);
529 SPR_NameToID(struct rx_call *call, namelist *aname, idlist *aid)
533 code = nameToID(call, aname, aid);
534 osi_auditU(call, PTS_NmToIdEvent, code, AUD_END);
535 ViceLog(125, ("PTS_NameToID: code %d\n", code));
540 nameToID(struct rx_call *call, namelist *aname, idlist *aid)
543 struct ubik_trans *tt;
548 /* Initialize return struct */
550 aid->idlist_val = NULL;
552 size = aname->namelist_len;
558 aid->idlist_val = malloc(size * sizeof(afs_int32));
559 if (!aid->idlist_val)
562 code = ReadPreamble(&tt);
566 for (i = 0; i < aname->namelist_len; i++) {
568 char *nameinst, *cell;
569 afs_int32 islocal = 1;
571 strncpy(vname, aname->namelist_val[i], sizeof(vname));
572 vname[sizeof(vname)-1] ='\0';
575 cell = strchr(vname, '@');
582 code = afsconf_IsLocalRealmMatch(prdir, &islocal, nameinst, NULL, cell);
584 ("PTS_NameToID: afsconf_IsLocalRealmMatch(); code=%d, nameinst=%s, cell=%s\n",
585 code, nameinst, cell));
588 code = NameToID(tt, nameinst, &aid->idlist_val[i]);
590 code = NameToID(tt, aname->namelist_val[i], &aid->idlist_val[i]);
592 if (code != PRSUCCESS)
593 aid->idlist_val[i] = ANONYMOUSID;
594 osi_audit(PTS_NmToIdEvent, code, AUD_STR,
595 aname->namelist_val[i], AUD_ID, aid->idlist_val[i],
597 ViceLog(125, ("PTS_NameToID: code %d aname %s aid %d\n", code,
598 aname->namelist_val[i], aid->idlist_val[i]));
600 #ifndef AFS_PTHREAD_ENV
606 aid->idlist_len = aname->namelist_len;
608 code = ubik_EndTrans(tt);
616 * Given an array of ids, find the name for each of them.
617 * The array of ids and names is unlimited.
620 SPR_IDToName(struct rx_call *call, idlist *aid, namelist *aname)
623 afs_int32 cid = ANONYMOUSID;
625 code = idToName(call, aid, aname, &cid);
626 osi_auditU(call, PTS_IdToNmEvent, code, AUD_END);
627 ViceLog(125, ("PTS_IDToName: code %d\n", code));
632 idToName(struct rx_call *call, idlist *aid, namelist *aname, afs_int32 *cid)
635 struct ubik_trans *tt;
640 /* leave this first for rpc stub */
641 size = aid->idlist_len;
644 if (size < 0 || size > INT_MAX / PR_MAXNAMELEN)
646 aname->namelist_val = calloc(size, PR_MAXNAMELEN);
647 aname->namelist_len = 0;
648 if (aname->namelist_val == 0)
650 if (aid->idlist_len == 0)
653 return PRTOOMANY; /* rxgen will probably handle this */
655 code = ReadPreamble(&tt);
659 code = WhoIsThis(call, tt, cid);
661 ABORT_WITH(tt, PRPERM);
662 if (!pr_noAuth && restrict_anonymous && *cid == ANONYMOUSID)
663 ABORT_WITH(tt, PRPERM);
665 for (i = 0; i < aid->idlist_len; i++) {
666 code = IDToName(tt, aid->idlist_val[i], aname->namelist_val[i]);
667 if (code != PRSUCCESS)
668 sprintf(aname->namelist_val[i], "%d", aid->idlist_val[i]);
669 osi_audit(PTS_IdToNmEvent, code, AUD_ID, aid->idlist_val[i],
670 AUD_STR, aname->namelist_val[i], AUD_END);
671 ViceLog(125, ("PTS_idToName: code %d aid %d aname %s\n", code,
672 aid->idlist_val[i], aname->namelist_val[i]));
674 #ifndef AFS_PTHREAD_ENV
680 aname->namelist_len = aid->idlist_len;
682 code = ubik_EndTrans(tt);
689 SPR_Delete(struct rx_call *call, afs_int32 aid)
692 afs_int32 cid = ANONYMOUSID;
694 code = Delete(call, aid, &cid);
695 osi_auditU(call, PTS_DelEvent, code, AUD_ID, aid, AUD_END);
696 ViceLog(5, ("PTS_Delete: code %d cid %d aid %d\n", code, cid, aid));
701 Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid)
704 struct ubik_trans *tt;
705 struct prentry tentry;
709 if (aid == SYSADMINID || aid == ANYUSERID || aid == AUTHUSERID
710 || aid == ANONYMOUSID)
713 code = WritePreamble(&tt);
717 code = WhoIsThis(call, tt, cid);
719 ABORT_WITH(tt, PRPERM);
721 /* Read in entry to be deleted */
722 loc = FindByID(tt, aid);
724 ABORT_WITH(tt, PRNOENT);
725 code = pr_ReadEntry(tt, 0, loc, &tentry);
727 ABORT_WITH(tt, PRDBFAIL);
729 /* Do some access checking */
730 if (tentry.owner != *cid && !IsAMemberOf(tt, *cid, SYSADMINID)
731 && !IsAMemberOf(tt, *cid, tentry.owner) && !pr_noAuth)
732 ABORT_WITH(tt, PRPERM);
734 if (restricted && !IsAMemberOf(tt, *cid, SYSADMINID)) {
735 ABORT_WITH(tt, PRPERM);
738 /* Delete each continuation block as a separate transaction so that no one
739 * transaction become to large to complete. */
742 struct contentry centry;
745 code = pr_ReadCoEntry(tt, 0, nptr, ¢ry);
747 ABORT_WITH(tt, PRDBFAIL);
748 for (i = 0; i < COSIZE; i++) {
749 if (centry.entries[i] == PRBADID)
751 if (centry.entries[i] == 0)
753 #if defined(SUPERGROUPS)
754 if (aid < 0 && centry.entries[i] < 0) /* Supergroup */
755 code = RemoveFromSGEntry(tt, aid, centry.entries[i]);
758 code = RemoveFromEntry(tt, aid, centry.entries[i]);
760 ABORT_WITH(tt, code);
761 tentry.count--; /* maintain count */
762 #ifndef AFS_PTHREAD_ENV
767 tentry.next = centry.next; /* thread out this block */
768 code = FreeBlock(tt, nptr); /* free continuation block */
770 ABORT_WITH(tt, code);
771 code = pr_WriteEntry(tt, 0, loc, &tentry); /* update main entry */
773 ABORT_WITH(tt, code);
775 /* end this trans and start a new one */
776 code = ubik_EndTrans(tt);
779 #ifndef AFS_PTHREAD_ENV
780 IOMGR_Poll(); /* just to keep the connection alive */
782 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
785 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
787 ABORT_WITH(tt, code);
789 /* re-read entry to get consistent uptodate info */
790 loc = FindByID(tt, aid);
792 ABORT_WITH(tt, PRNOENT);
793 code = pr_ReadEntry(tt, 0, loc, &tentry);
795 ABORT_WITH(tt, PRDBFAIL);
800 #if defined(SUPERGROUPS)
801 /* Delete each continuation block as a separate transaction
802 * so that no one transaction become too large to complete. */
804 struct prentryg *tentryg = (struct prentryg *)&tentry;
805 nptr = tentryg->nextsg;
807 struct contentry centry;
810 code = pr_ReadCoEntry(tt, 0, nptr, ¢ry);
812 ABORT_WITH(tt, PRDBFAIL);
813 for (i = 0; i < COSIZE; i++) {
814 if (centry.entries[i] == PRBADID)
816 if (centry.entries[i] == 0)
818 code = RemoveFromEntry(tt, aid, centry.entries[i]);
820 ABORT_WITH(tt, code);
821 tentryg->countsg--; /* maintain count */
822 #ifndef AFS_PTHREAD_ENV
827 tentryg->nextsg = centry.next; /* thread out this block */
828 code = FreeBlock(tt, nptr); /* free continuation block */
830 ABORT_WITH(tt, code);
831 code = pr_WriteEntry(tt, 0, loc, &tentry); /* update main entry */
833 ABORT_WITH(tt, code);
835 /* end this trans and start a new one */
836 code = ubik_EndTrans(tt);
839 #ifndef AFS_PTHREAD_ENV
840 IOMGR_Poll(); /* just to keep the connection alive */
843 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
846 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
848 ABORT_WITH(tt, code);
850 /* re-read entry to get consistent uptodate info */
851 loc = FindByID(tt, aid);
853 ABORT_WITH(tt, PRNOENT);
854 code = pr_ReadEntry(tt, 0, loc, &tentry);
856 ABORT_WITH(tt, PRDBFAIL);
858 nptr = tentryg->nextsg;
862 #endif /* SUPERGROUPS */
864 /* Then move the owned chain, except possibly ourself to the orphan list.
865 * Because this list can be very long and so exceed the size of a ubik
866 * transaction, we start a new transaction every 50 entries. */
870 struct prentry nentry;
872 code = pr_ReadEntry(tt, 0, nptr, &nentry);
874 ABORT_WITH(tt, PRDBFAIL);
875 nptr = tentry.owned = nentry.nextOwned; /* thread out */
877 if (nentry.id != tentry.id) { /* don't add us to orphan chain! */
878 code = AddToOrphan(tt, nentry.id);
880 ABORT_WITH(tt, code);
882 #ifndef AFS_PTHREAD_ENV
883 if ((count & 3) == 0)
889 code = pr_WriteEntry(tt, 0, loc, &tentry); /* update main entry */
891 ABORT_WITH(tt, code);
893 /* end this trans and start a new one */
894 code = ubik_EndTrans(tt);
897 #ifndef AFS_PTHREAD_ENV
898 IOMGR_Poll(); /* just to keep the connection alive */
900 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
903 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
905 ABORT_WITH(tt, code);
907 /* re-read entry to get consistent uptodate info */
908 loc = FindByID(tt, aid);
910 ABORT_WITH(tt, PRNOENT);
911 code = pr_ReadEntry(tt, 0, loc, &tentry);
913 ABORT_WITH(tt, PRDBFAIL);
918 /* now do what's left of the deletion stuff */
919 code = DeleteEntry(tt, &tentry, loc);
920 if (code != PRSUCCESS)
921 ABORT_WITH(tt, code);
923 code = ubik_EndTrans(tt);
930 SPR_UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
931 struct PrUpdateEntry *uentry)
934 afs_int32 cid = ANONYMOUSID;
936 code = UpdateEntry(call, aid, name, uentry, &cid);
937 osi_auditU(call, PTS_UpdEntEvent, code, AUD_ID, aid, AUD_STR, name, AUD_END);
938 ViceLog(5, ("PTS_UpdateEntry: code %d cid %d aid %d name %s\n", code, cid, aid, name));
943 UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
944 struct PrUpdateEntry *uentry, afs_int32 *cid)
947 struct ubik_trans *tt;
948 struct prentry tentry;
954 if (aid == SYSADMINID || aid == ANYUSERID || aid == AUTHUSERID
955 || aid == ANONYMOUSID)
959 code = WritePreamble(&tt);
963 code = WhoIsThis(call, tt, cid);
965 ABORT_WITH(tt, PRPERM);
966 code = IsAMemberOf(tt, *cid, SYSADMINID);
967 if (!code && !pr_noAuth)
968 ABORT_WITH(tt, PRPERM);
970 /* Read in entry to be deleted */
972 loc = FindByID(tt, aid);
974 loc = FindByName(tt, name, &tentry);
977 ABORT_WITH(tt, PRNOENT);
978 code = pr_ReadEntry(tt, 0, loc, &tentry);
980 ABORT_WITH(tt, PRDBFAIL);
982 if (uentry->Mask & PRUPDATE_NAMEHASH) {
984 code = RemoveFromNameHash(tt, tentry.name, &tloc);
985 if (code != PRSUCCESS)
986 ABORT_WITH(tt, PRDBFAIL);
987 code = AddToNameHash(tt, tentry.name, loc);
989 ABORT_WITH(tt, code);
992 if (uentry->Mask & PRUPDATE_IDHASH) {
996 code = RemoveFromIDHash(tt, id, &tloc);
997 if (code != PRSUCCESS)
998 ABORT_WITH(tt, PRDBFAIL);
999 code = AddToIDHash(tt, id, loc);
1001 ABORT_WITH(tt, code);
1004 code = ubik_EndTrans(tt);
1011 SPR_RemoveFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
1014 afs_int32 cid = ANONYMOUSID;
1016 code = removeFromGroup(call, aid, gid, &cid);
1017 osi_auditU(call, PTS_RmFmGrpEvent, code, AUD_ID, gid, AUD_ID, aid,
1019 ViceLog(5, ("PTS_RemoveFromGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid));
1024 removeFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid,
1028 struct ubik_trans *tt;
1031 struct prentry uentry;
1032 struct prentry gentry;
1034 code = WritePreamble(&tt);
1038 code = WhoIsThis(call, tt, cid);
1040 ABORT_WITH(tt, PRPERM);
1041 tempu = FindByID(tt, aid);
1043 ABORT_WITH(tt, PRNOENT);
1044 tempg = FindByID(tt, gid);
1046 ABORT_WITH(tt, PRNOENT);
1047 memset(&uentry, 0, sizeof(uentry));
1048 memset(&gentry, 0, sizeof(gentry));
1049 code = pr_ReadEntry(tt, 0, tempu, &uentry);
1051 ABORT_WITH(tt, code);
1052 code = pr_ReadEntry(tt, 0, tempg, &gentry);
1054 ABORT_WITH(tt, code);
1055 if (!(gentry.flags & PRGRP))
1056 ABORT_WITH(tt, PRNOTGROUP);
1057 #if !defined(SUPERGROUPS)
1058 if (uentry.flags & PRGRP)
1059 ABORT_WITH(tt, PRNOTUSER);
1061 if (!AccessOK(tt, *cid, &gentry, PRP_REMOVE_MEM, 0))
1062 ABORT_WITH(tt, PRPERM);
1063 code = RemoveFromEntry(tt, aid, gid);
1064 if (code != PRSUCCESS)
1065 ABORT_WITH(tt, code);
1066 #if defined(SUPERGROUPS)
1067 if (!(uentry.flags & PRGRP))
1069 code = RemoveFromEntry(tt, gid, aid);
1070 #if defined(SUPERGROUPS)
1072 code = RemoveFromSGEntry(tt, gid, aid);
1074 if (code != PRSUCCESS)
1075 ABORT_WITH(tt, code);
1077 code = ubik_EndTrans(tt);
1085 SPR_GetCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over)
1088 afs_int32 cid = ANONYMOUSID;
1090 code = getCPS(call, aid, alist, over, &cid);
1091 osi_auditU(call, PTS_GetCPSEvent, code, AUD_ID, aid, AUD_END);
1092 ViceLog(125, ("PTS_GetCPS: code %d cid %d aid %d\n", code, cid, aid));
1097 getCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over,
1101 struct ubik_trans *tt;
1103 struct prentry tentry;
1106 alist->prlist_len = 0;
1107 alist->prlist_val = NULL;
1109 code = ReadPreamble(&tt);
1113 code = WhoIsThis(call, tt, cid);
1115 ABORT_WITH(tt, PRPERM);
1116 if (!pr_noAuth && restrict_anonymous && *cid == ANONYMOUSID)
1117 ABORT_WITH(tt, PRPERM);
1119 temp = FindByID(tt, aid);
1121 ABORT_WITH(tt, PRNOENT);
1122 code = pr_ReadEntry(tt, 0, temp, &tentry);
1124 ABORT_WITH(tt, code);
1126 if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
1127 ABORT_WITH(tt, PRPERM);
1129 code = GetList(tt, &tentry, alist, 1);
1130 if (code != PRSUCCESS)
1131 ABORT_WITH(tt, code);
1133 code = ubik_EndTrans(tt);
1139 inCPS(prlist CPS, afs_int32 id)
1143 for (i = (CPS.prlist_len - 1); i >= 0; i--) {
1144 if (CPS.prlist_val[i] == id)
1152 SPR_GetCPS2(struct rx_call *call, afs_int32 aid, afs_int32 ahost,
1153 prlist *alist, afs_int32 *over)
1156 afs_int32 cid = ANONYMOUSID;
1158 code = getCPS2(call, aid, ahost, alist, over, &cid);
1159 osi_auditU(call, PTS_GetCPS2Event, code, AUD_ID, aid, AUD_HOST, htonl(ahost),
1161 ViceLog(125, ("PTS_GetCPS2: code %d cid %d aid %d ahost %d\n", code, cid, aid, ahost));
1166 getCPS2(struct rx_call *call, afs_int32 aid, afs_uint32 ahost, prlist *alist,
1167 afs_int32 *over, afs_int32 *cid)
1170 struct ubik_trans *tt;
1172 struct prentry tentry;
1173 struct prentry host_tentry;
1176 struct in_addr iaddr;
1180 iaddr.s_addr = ntohl(ahost);
1181 alist->prlist_len = 0;
1182 alist->prlist_val = NULL;
1184 code = ReadPreamble(&tt);
1188 if (aid != PRBADID) {
1189 temp = FindByID(tt, aid);
1191 ABORT_WITH(tt, PRNOENT);
1192 code = pr_ReadEntry(tt, 0, temp, &tentry);
1194 ABORT_WITH(tt, code);
1196 /* afs does authenticate now */
1197 code = WhoIsThis(call, tt, cid);
1199 || !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
1200 ABORT_WITH(tt, PRPERM);
1202 code = NameToID(tt, afs_inet_ntoa_r(iaddr.s_addr, hoststr), &hostid);
1203 if (code == PRSUCCESS && hostid != 0) {
1204 temp = FindByID(tt, hostid);
1206 code = pr_ReadEntry(tt, 0, temp, &host_tentry);
1207 if (code == PRSUCCESS)
1210 fprintf(stderr, "pr_ReadEntry returned %d\n", code);
1212 fprintf(stderr, "FindByID Failed -- Not found\n");
1215 code = GetList2(tt, &tentry, &host_tentry, alist, 1);
1217 code = GetList(tt, &tentry, alist, 1);
1219 code = addWildCards(tt, alist, ntohl(ahost));
1220 if (code != PRSUCCESS)
1221 ABORT_WITH(tt, code);
1223 code = ubik_EndTrans(tt);
1229 SPR_GetHostCPS(struct rx_call *call, afs_int32 ahost, prlist *alist,
1233 afs_int32 cid = ANONYMOUSID;
1235 code = getHostCPS(call, ahost, alist, over, &cid);
1236 osi_auditU(call, PTS_GetHCPSEvent, code, AUD_HOST, htonl(ahost), AUD_END);
1237 ViceLog(125, ("PTS_GetHostCPS: code %d ahost %u (0x%x)\n", code, ahost, ahost));
1242 getHostCPS(struct rx_call *call, afs_uint32 ahost, prlist *alist,
1243 afs_int32 *over, afs_int32 *cid)
1245 afs_int32 code, temp;
1246 struct ubik_trans *tt;
1247 struct prentry host_tentry;
1249 struct in_addr iaddr;
1253 iaddr.s_addr = ntohl(ahost);
1254 alist->prlist_len = 0;
1255 alist->prlist_val = NULL;
1257 code = ReadPreamble(&tt);
1261 code = WhoIsThis(call, tt, cid);
1263 ABORT_WITH(tt, PRPERM);
1264 if (!pr_noAuth && restrict_anonymous && *cid == ANONYMOUSID)
1265 ABORT_WITH(tt, PRPERM);
1267 code = NameToID(tt, afs_inet_ntoa_r(iaddr.s_addr, hoststr), &hostid);
1268 if (code == PRSUCCESS && hostid != 0) {
1269 temp = FindByID(tt, hostid);
1271 code = pr_ReadEntry(tt, 0, temp, &host_tentry);
1272 if (code == PRSUCCESS) {
1273 code = GetList(tt, &host_tentry, alist, 0);
1277 fprintf(stderr, "pr_ReadEntry returned %d\n", code);
1279 fprintf(stderr, "FindByID Failed -- Not found\n");
1281 code = addWildCards(tt, alist, ntohl(ahost));
1283 if (code != PRSUCCESS)
1284 ABORT_WITH(tt, code);
1286 code = ubik_EndTrans(tt);
1292 SPR_ListMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
1295 afs_int32 cid = ANONYMOUSID;
1297 code = listMax(call, uid, gid, &cid);
1298 osi_auditU(call, PTS_LstMaxEvent, code, AUD_END);
1299 ViceLog(125, ("PTS_ListMax: code %d\n", code));
1304 listMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid, afs_int32 *cid)
1307 struct ubik_trans *tt;
1309 code = ReadPreamble(&tt);
1313 code = WhoIsThis(call, tt, cid);
1315 ABORT_WITH(tt, PRPERM);
1316 if (!pr_noAuth && restrict_anonymous && *cid == ANONYMOUSID)
1317 ABORT_WITH(tt, PRPERM);
1319 code = GetMax(tt, uid, gid);
1320 if (code != PRSUCCESS)
1321 ABORT_WITH(tt, code);
1323 code = ubik_EndTrans(tt);
1330 SPR_SetMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag)
1333 afs_int32 cid = ANONYMOUSID;
1335 code = setMax(call, aid, gflag, &cid);
1336 osi_auditU(call, PTS_SetMaxEvent, code, AUD_ID, aid, AUD_LONG, gflag,
1338 ViceLog(125, ("PTS_SetMax: code %d cid %d aid %d gflag %d\n", code, cid, aid, gflag));
1343 setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag, afs_int32 *cid)
1346 struct ubik_trans *tt;
1348 code = WritePreamble(&tt);
1352 code = WhoIsThis(call, tt, cid);
1354 ABORT_WITH(tt, PRPERM);
1355 if (!AccessOK(tt, *cid, 0, 0, 0))
1356 ABORT_WITH(tt, PRPERM);
1357 if (((gflag & PRGRP) && (aid > 0)) || (!(gflag & PRGRP) && (aid < 0)))
1358 ABORT_WITH(tt, PRBADARG);
1360 code = SetMax(tt, aid, gflag);
1361 if (code != PRSUCCESS)
1362 ABORT_WITH(tt, code);
1364 code = ubik_EndTrans(tt);
1371 SPR_ListEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry)
1374 afs_int32 cid = ANONYMOUSID;
1376 code = listEntry(call, aid, aentry, &cid);
1377 osi_auditU(call, PTS_LstEntEvent, code, AUD_ID, aid, AUD_END);
1378 ViceLog(125, ("PTS_ListEntry: code %d cid %d aid %d\n", code, cid, aid));
1383 listEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry,
1387 struct ubik_trans *tt;
1389 struct prentry tentry;
1391 code = ReadPreamble(&tt);
1395 code = WhoIsThis(call, tt, cid);
1397 ABORT_WITH(tt, PRPERM);
1398 if (!pr_noAuth && restrict_anonymous && *cid == ANONYMOUSID)
1399 ABORT_WITH(tt, PRPERM);
1400 temp = FindByID(tt, aid);
1402 ABORT_WITH(tt, PRNOENT);
1403 code = pr_ReadEntry(tt, 0, temp, &tentry);
1405 ABORT_WITH(tt, code);
1406 if (!AccessOK(tt, *cid, &tentry, PRP_STATUS_MEM, PRP_STATUS_ANY))
1407 ABORT_WITH(tt, PRPERM);
1409 aentry->flags = tentry.flags >> PRIVATE_SHIFT;
1410 if (aentry->flags == 0) {
1411 if (tentry.flags & PRGRP)
1412 aentry->flags = prp_group_default >> PRIVATE_SHIFT;
1414 aentry->flags = prp_user_default >> PRIVATE_SHIFT;
1416 aentry->owner = tentry.owner;
1417 aentry->id = tentry.id;
1418 strncpy(aentry->name, tentry.name, PR_MAXNAMELEN);
1419 aentry->creator = tentry.creator;
1420 aentry->ngroups = tentry.ngroups;
1421 aentry->nusers = tentry.nusers;
1422 aentry->count = tentry.count;
1423 memset(aentry->reserved, 0, sizeof(aentry->reserved));
1424 code = ubik_EndTrans(tt);
1431 SPR_ListEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
1432 prentries *bulkentries, afs_int32 *nextstartindex)
1435 afs_int32 cid = ANONYMOUSID;
1437 code = listEntries(call, flag, startindex, bulkentries, nextstartindex, &cid);
1438 osi_auditU(call, PTS_LstEntsEvent, code, AUD_LONG, flag, AUD_END);
1439 ViceLog(125, ("PTS_ListEntries: code %d cid %d flag %d\n", code, cid, flag));
1444 listEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
1445 prentries *bulkentries, afs_int32 *nextstartindex, afs_int32 *cid)
1448 struct ubik_trans *tt;
1449 afs_int32 i, eof, pos, maxentries, f;
1450 struct prentry tentry;
1451 afs_int32 pollcount = 0;
1453 *nextstartindex = -1;
1454 bulkentries->prentries_val = 0;
1455 bulkentries->prentries_len = 0;
1457 code = ReadPreamble(&tt);
1461 /* Make sure we are an authenticated caller and that we are on the
1464 code = WhoIsThis(call, tt, cid);
1466 ABORT_WITH(tt, PRPERM);
1467 code = IsAMemberOf(tt, *cid, SYSADMINID);
1468 if (!code && !pr_noAuth)
1469 ABORT_WITH(tt, PRPERM);
1471 eof = ntohl(cheader.eofPtr) - sizeof(cheader);
1472 maxentries = eof / sizeof(struct prentry);
1473 for (i = startindex; i < maxentries; i++) {
1474 pos = i * sizeof(struct prentry) + sizeof(cheader);
1475 code = pr_ReadEntry(tt, 0, pos, &tentry);
1479 if (++pollcount > 50) {
1480 #ifndef AFS_PTHREAD_ENV
1486 f = (tentry.flags & PRTYPE);
1487 if (((flag & PRUSERS) && (f == 0)) || /* User entry */
1488 ((flag & PRGROUPS) && (f & PRGRP))) { /* Group entry */
1489 code = put_prentries(&tentry, bulkentries);
1491 break; /* Filled return array */
1498 *nextstartindex = i;
1502 if (bulkentries->prentries_val)
1503 free(bulkentries->prentries_val);
1504 bulkentries->prentries_val = 0;
1505 bulkentries->prentries_len = 0;
1506 ABORT_WITH(tt, code);
1508 code = ubik_EndTrans(tt);
1515 #define PR_MAXENTRIES 500
1517 put_prentries(struct prentry *tentry, prentries *bulkentries)
1519 struct prlistentries *entry;
1521 if (bulkentries->prentries_val == 0) {
1522 bulkentries->prentries_len = 0;
1523 bulkentries->prentries_val = malloc(PR_MAXENTRIES *
1524 sizeof(struct prlistentries));
1525 if (!bulkentries->prentries_val) {
1530 if (bulkentries->prentries_len >= PR_MAXENTRIES) {
1534 entry = bulkentries->prentries_val;
1535 entry += bulkentries->prentries_len;
1537 memset(entry, 0, sizeof(*entry));
1538 entry->flags = tentry->flags >> PRIVATE_SHIFT;
1539 if (entry->flags == 0) {
1542 flags & PRGRP) ? prp_group_default : prp_user_default) >>
1545 entry->owner = tentry->owner;
1546 entry->id = tentry->id;
1547 entry->creator = tentry->creator;
1548 entry->ngroups = tentry->ngroups;
1549 entry->nusers = tentry->nusers;
1550 entry->count = tentry->count;
1551 strncpy(entry->name, tentry->name, PR_MAXNAMELEN);
1552 bulkentries->prentries_len++;
1557 SPR_ChangeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid,
1561 afs_int32 cid = ANONYMOUSID;
1563 code = changeEntry(call, aid, name, oid, newid, &cid);
1564 osi_auditU(call, PTS_ChgEntEvent, code, AUD_ID, aid, AUD_STR, name,
1565 AUD_LONG, oid, AUD_LONG, newid, AUD_END);
1566 ViceLog(5, ("PTS_ChangeEntry: code %d cid %d aid %d name %s oid %d newid %d\n", code, cid, aid, name, oid, newid));
1571 changeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid,
1572 afs_int32 newid, afs_int32 *cid)
1575 struct ubik_trans *tt;
1582 if (aid == ANYUSERID || aid == AUTHUSERID || aid == ANONYMOUSID
1583 || aid == SYSADMINID)
1586 code = WritePreamble(&tt);
1590 code = WhoIsThis(call, tt, cid);
1592 ABORT_WITH(tt, PRPERM);
1593 pos = FindByID(tt, aid);
1595 ABORT_WITH(tt, PRNOENT);
1596 /* protection check in changeentry */
1597 code = ChangeEntry(tt, aid, *cid, name, oid, newid);
1598 if (code != PRSUCCESS)
1599 ABORT_WITH(tt, code);
1601 code = ubik_EndTrans(tt);
1606 SPR_SetFieldsEntry(struct rx_call *call,
1608 afs_int32 mask, /* specify which fields to update */
1609 afs_int32 flags, afs_int32 ngroups, afs_int32 nusers,
1610 afs_int32 spare1, afs_int32 spare2)
1613 afs_int32 cid = ANONYMOUSID;
1616 setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1,
1618 osi_auditU(call, PTS_SetFldEntEvent, code, AUD_ID, id, AUD_END);
1619 ViceLog(5, ("PTS_SetFieldsEntry: code %d cid %d id %d\n", code, cid, id));
1624 setFieldsEntry(struct rx_call *call,
1626 afs_int32 mask, /* specify which fields to update */
1627 afs_int32 flags, afs_int32 ngroups, afs_int32 nusers,
1628 afs_int32 spare1, afs_int32 spare2, afs_int32 *cid)
1631 struct ubik_trans *tt;
1633 struct prentry tentry;
1637 return 0; /* no-op */
1639 if (id == ANYUSERID || id == AUTHUSERID || id == ANONYMOUSID)
1642 code = WritePreamble(&tt);
1646 code = WhoIsThis(call, tt, cid);
1648 ABORT_WITH(tt, PRPERM);
1649 pos = FindByID(tt, id);
1651 ABORT_WITH(tt, PRNOENT);
1652 code = pr_ReadEntry(tt, 0, pos, &tentry);
1654 ABORT_WITH(tt, code);
1655 tflags = tentry.flags;
1657 if (mask & (PR_SF_NGROUPS | PR_SF_NUSERS)) {
1658 if (!AccessOK(tt, *cid, 0, 0, 0))
1659 ABORT_WITH(tt, PRPERM);
1660 if ((tflags & PRQUOTA) == 0) { /* default if only setting one */
1661 tentry.ngroups = tentry.nusers = 20;
1664 if (!AccessOK(tt, *cid, &tentry, 0, 0))
1665 ABORT_WITH(tt, PRPERM);
1668 if (mask & 0xffff) { /* if setting flag bits */
1669 afs_int32 flagsMask = mask & 0xffff;
1670 tflags &= ~(flagsMask << PRIVATE_SHIFT);
1671 tflags |= (flags & flagsMask) << PRIVATE_SHIFT;
1675 if (mask & PR_SF_NGROUPS) { /* setting group limit */
1677 ABORT_WITH(tt, PRBADARG);
1678 tentry.ngroups = ngroups;
1682 if (mask & PR_SF_NUSERS) { /* setting foreign user limit */
1684 ABORT_WITH(tt, PRBADARG);
1685 tentry.nusers = nusers;
1688 tentry.flags = tflags;
1690 code = pr_WriteEntry(tt, 0, pos, &tentry);
1692 ABORT_WITH(tt, code);
1694 code = ubik_EndTrans(tt);
1699 SPR_ListElements(struct rx_call *call, afs_int32 aid, prlist *alist,
1703 afs_int32 cid = ANONYMOUSID;
1705 code = listElements(call, aid, alist, over, &cid);
1706 osi_auditU(call, PTS_LstEleEvent, code, AUD_ID, aid, AUD_END);
1707 ViceLog(125, ("PTS_ListElements: code %d cid %d aid %d\n", code, cid, aid));
1712 listElements(struct rx_call *call, afs_int32 aid, prlist *alist,
1713 afs_int32 *over, afs_int32 *cid)
1716 struct ubik_trans *tt;
1718 struct prentry tentry;
1721 alist->prlist_len = 0;
1722 alist->prlist_val = NULL;
1724 code = ReadPreamble(&tt);
1728 code = WhoIsThis(call, tt, cid);
1730 ABORT_WITH(tt, PRPERM);
1732 temp = FindByID(tt, aid);
1734 ABORT_WITH(tt, PRNOENT);
1735 code = pr_ReadEntry(tt, 0, temp, &tentry);
1737 ABORT_WITH(tt, code);
1738 if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
1739 ABORT_WITH(tt, PRPERM);
1741 code = GetList(tt, &tentry, alist, 0);
1742 if (code != PRSUCCESS)
1743 ABORT_WITH(tt, code);
1745 code = ubik_EndTrans(tt);
1751 SPR_ListSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
1754 #if defined(SUPERGROUPS)
1756 afs_int32 cid = ANONYMOUSID;
1758 code = listSuperGroups(call, aid, alist, over, &cid);
1759 osi_auditU(call, PTS_LstSGrps, code, AUD_ID, aid, AUD_END);
1760 ViceLog(125, ("PTS_ListSuperGroups: code %d cid %d aid %d\n", code, cid, aid));
1763 return RXGEN_OPCODE;
1767 #if defined(SUPERGROUPS)
1769 listSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
1770 afs_int32 *over, afs_int32 *cid)
1773 struct ubik_trans *tt;
1775 struct prentry tentry;
1777 alist->prlist_len = 0;
1778 alist->prlist_val = (afs_int32 *) 0;
1780 code = ReadPreamble(&tt);
1784 code = WhoIsThis(call, tt, cid);
1786 ABORT_WITH(tt, PRPERM);
1787 if (!pr_noAuth && restrict_anonymous && *cid == ANONYMOUSID)
1788 ABORT_WITH(tt, PRPERM);
1790 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
1792 ABORT_WITH(tt, code);
1794 temp = FindByID(tt, aid);
1796 ABORT_WITH(tt, PRNOENT);
1797 code = pr_ReadEntry(tt, 0, temp, &tentry);
1799 ABORT_WITH(tt, code);
1800 if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
1801 ABORT_WITH(tt, PRPERM);
1803 code = GetSGList(tt, &tentry, alist);
1805 if (code == PRTOOMANY)
1807 else if (code != PRSUCCESS)
1808 ABORT_WITH(tt, code);
1810 code = ubik_EndTrans(tt);
1815 #endif /* SUPERGROUPS */
1819 * List the entries owned by this id. If the id is zero,
1820 * return the orphans list. This will return up to PR_MAXGROUPS
1821 * at a time with the lastP available to get the rest. The
1822 * maximum value is enforced in GetOwnedChain().
1825 SPR_ListOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
1829 afs_int32 cid = ANONYMOUSID;
1831 code = listOwned(call, aid, alist, lastP, &cid);
1832 osi_auditU(call, PTS_LstOwnEvent, code, AUD_ID, aid, AUD_END);
1833 ViceLog(125, ("PTS_ListOwned: code %d cid %d aid %d\n", code, cid, aid));
1838 listOwned(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *lastP,
1842 struct ubik_trans *tt;
1843 struct prentry tentry;
1847 alist->prlist_len = 0;
1848 alist->prlist_val = NULL;
1855 code = ReadPreamble(&tt);
1859 code = WhoIsThis(call, tt, cid);
1861 ABORT_WITH(tt, PRPERM);
1864 code = pr_ReadEntry(tt, 0, start, &tentry);
1865 if (!code && (tentry.owner == aid))
1866 head = start; /* pick up where we left off */
1871 afs_int32 loc = FindByID(tt, aid);
1873 ABORT_WITH(tt, PRNOENT);
1874 code = pr_ReadEntry(tt, 0, loc, &tentry);
1876 ABORT_WITH(tt, code);
1878 if (!AccessOK(tt, *cid, &tentry, -1, PRP_OWNED_ANY))
1879 ABORT_WITH(tt, PRPERM);
1880 head = tentry.owned;
1882 if (!AccessOK(tt, *cid, 0, 0, 0))
1883 ABORT_WITH(tt, PRPERM);
1884 head = ntohl(cheader.orphan);
1888 code = GetOwnedChain(tt, &head, alist);
1890 if (code == PRTOOMANY)
1893 ABORT_WITH(tt, code);
1896 code = ubik_EndTrans(tt);
1901 SPR_IsAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid,
1905 afs_int32 cid = ANONYMOUSID;
1907 code = isAMemberOf(call, uid, gid, flag, &cid);
1908 osi_auditU(call, PTS_IsMemOfEvent, code, AUD_LONG, uid, AUD_LONG, gid,
1910 ViceLog(125, ("PTS_IsAMemberOf: code %d cid %d uid %d gid %d\n", code, cid, uid, gid));
1915 isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid, afs_int32 *flag,
1919 struct ubik_trans *tt;
1921 code = ReadPreamble(&tt);
1926 afs_int32 uloc = FindByID(tt, uid);
1927 afs_int32 gloc = FindByID(tt, gid);
1928 struct prentry uentry, gentry;
1931 ABORT_WITH(tt, PRNOENT);
1932 code = WhoIsThis(call, tt, cid);
1934 ABORT_WITH(tt, PRPERM);
1935 code = pr_ReadEntry(tt, 0, uloc, &uentry);
1937 ABORT_WITH(tt, code);
1938 code = pr_ReadEntry(tt, 0, gloc, &gentry);
1940 ABORT_WITH(tt, code);
1941 #if !defined(SUPERGROUPS)
1942 if ((uentry.flags & PRGRP) || !(gentry.flags & PRGRP))
1943 ABORT_WITH(tt, PRBADARG);
1945 if (!(gentry.flags & PRGRP))
1946 ABORT_WITH(tt, PRBADARG);
1948 if (!AccessOK(tt, *cid, &uentry, 0, PRP_MEMBER_ANY)
1949 && !AccessOK(tt, *cid, &gentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
1950 ABORT_WITH(tt, PRPERM);
1953 *flag = IsAMemberOf(tt, uid, gid);
1954 code = ubik_EndTrans(tt);
1959 addWildCards(struct ubik_trans *tt, prlist *alist, afs_uint32 host)
1962 struct prentry tentry;
1964 unsigned wild = htonl(0xffffff00);
1965 struct in_addr iaddr;
1967 int size = 0, i, code;
1971 while ((host = (host & wild))) {
1972 wild = htonl(ntohl(wild) << 8);
1973 iaddr.s_addr = host;
1974 code = NameToID(tt, afs_inet_ntoa_r(iaddr.s_addr, hoststr), &hostid);
1975 if (code == PRSUCCESS && hostid != 0) {
1976 temp = FindByID(tt, hostid);
1978 code = pr_ReadEntry(tt, 0, temp, &tentry);
1979 if (code != PRSUCCESS)
1985 wlist.prlist_len = 0;
1986 wlist.prlist_val = NULL;
1988 code = GetList(tt, &tentry, &wlist, 0);
1991 added += wlist.prlist_len;
1992 for (i = 0; i < wlist.prlist_len; i++) {
1993 if (!inCPS(*alist, wlist.prlist_val[i]))
1994 if ((code = AddToPRList(alist, &size, wlist.prlist_val[i]))) {
1995 free(wlist.prlist_val);
1999 if (wlist.prlist_val)
2000 free(wlist.prlist_val);
2003 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
2008 WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid,
2011 afs_int32 islocal = 1;
2012 /* aid is set to the identity of the caller, if known, else ANONYMOUSID */
2013 /* returns -1 and sets aid to ANONYMOUSID on any failure */
2014 struct rx_connection *tconn;
2016 char tcell[MAXKTCREALMLEN];
2017 char name[MAXKTCNAMELEN];
2018 char inst[MAXKTCNAMELEN];
2023 tconn = rx_ConnectionOf(acall);
2024 code = rx_SecurityClassOf(tconn);
2025 if (code == RX_SECIDX_NULL)
2027 else if (code == RX_SECIDX_VAB) {
2028 goto done; /* no longer supported */
2029 } else if (code == RX_SECIDX_KAD) {
2030 if ((code = rxkad_GetServerInfo(rx_ConnectionOf(acall), NULL, NULL,
2031 name, inst, tcell, NULL)))
2035 code = afsconf_IsLocalRealmMatch(prdir, &islocal, name, inst, tcell);
2039 strncpy(vname, name, sizeof(vname));
2040 if ((ilen = strlen(inst))) {
2041 if (strlen(vname) + 1 + ilen >= sizeof(vname))
2044 strcat(vname, inst);
2047 if (strlen(vname) + strlen(tcell) + 1 >= sizeof(vname))
2050 strcat(vname, tcell);
2051 lcstring(vname, vname, sizeof(vname));
2052 NameToID(at, vname, aid);
2054 strcpy(aname, vname);
2058 if (strcmp(AUTH_SUPERUSER, vname) == 0)
2059 *aid = SYSADMINID; /* special case for the fileserver */
2061 lcstring(vname, vname, sizeof(vname));
2062 code = NameToID(at, vname, aid);
2066 /* If we reached here, we don't understand the security class of the
2067 * given call. But if the calling user is RX_ID_SUPERUSER, we can check
2068 * that without even needing to understand the security class. Remember
2069 * to only check for RX_ID_SUPERUSER specifically; we do not use
2070 * SYSADMINID for other admins. */
2072 struct rx_identity *id = NULL;
2073 is_super = afsconf_SuperIdentity(prdir, acall, &id);
2074 if (is_super && id->kind == RX_ID_SUPERUSER) {
2081 rx_identity_free(&id);
2085 if (code && !pr_noAuth)