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 * (5) Add functions to process supergroups:
12 * ChangeIDEntry(), RemoveFromSGEntry(),
13 * AddToSGEntry(), GetListSG2().
14 * (6) Add code to existing functions to process
16 * 2/1/98 jjm Add mdw's changes for bit mapping for supergroups
18 * 09/26/02 kwc Move depthsg definition here from ptserver.c since
19 * pt_util needs it defined also, and this file is
20 * common between the two programs.
23 #include <afsconfig.h>
24 #include <afs/param.h>
32 #include <afs/com_err.h>
33 #include <afs/cellconfig.h>
37 #include "ptprototypes.h"
39 /* Foreign cells are represented by the group system:authuser@cell*/
40 #define AUTHUSER_GROUP "system:authuser"
42 extern int restricted;
43 extern struct ubik_dbase *dbase;
44 extern struct afsconf_dir *prdir;
47 static int inRange(struct prentry *cellEntry, afs_int32 aid);
48 static afs_int32 allocNextId(struct ubik_trans *, struct prentry *);
49 static int AddAuthGroup(struct prentry *tentry, prlist *alist, afs_int32 *size);
51 static char *whoami = "ptserver";
53 int prp_user_default = PRP_USER_DEFAULT;
54 int prp_group_default = PRP_GROUP_DEFAULT;
56 #if defined(SUPERGROUPS)
60 afs_int32 depthsg = 5; /* Maximum iterations used during IsAMemberOF */
61 afs_int32 GetListSG2(struct ubik_trans *at, afs_int32 gid, prlist * alist,
62 afs_int32 * sizeP, afs_int32 depth);
64 struct map *sg_flagged;
67 #define NIL_MAP ((struct map *) 0)
69 /* pt_mywrite hooks into the logic that writes ubik records to disk
70 * at a very low level. It invalidates mappings in sg_flagged/sg_found.
71 * By hoooking in at this level, we ensure that a ubik file reload
72 * invalidates our incore cache.
74 * We assert records, cheaders and everything else are 0 mod 64.
75 * So, we can always see the first 64 bytes of any record written.
76 * The stuff we're interested in (flags, id) are in the first 8 bytes.
77 * so we can always tell if we're writing a group record.
80 int (*pt_save_dbase_write)(struct ubik_dbase *, afs_int32, void *, afs_int32,
84 pt_mywrite(struct ubik_dbase *tdb, afs_int32 fno, void *bp, afs_int32 pos, afs_int32 count)
86 afs_uint32 headersize = ntohl(cheader.headerSize);
88 if (fno == 0 && pos + count > headersize) {
103 #define xPT(p,x) ((((struct prentry *)(p))->flags & htonl(PRTYPE)) == htonl(x))
106 fprintf(stderr, "Writing %d bytes of entry @ %#lx(+%d)\n", c,
108 else if (c == ENTRYSIZE)
110 "Writing %d bytes of entry @ %#lx (%d<%s>,%d)\n",
111 c, p, ntohl(((struct prentry *)cp)->flags),
112 xPT(cp,PRUSER) ? "user" : xPT(cp,PRFREE) ? "free" :
113 xPT(cp,PRGRP) ? "group" : xPT(cp,PRCONT) ? "cont" :
114 xPT(cp,PRCELL) ? "cell" : xPT(cp,PRFOREIGN) ? "foreign" :
115 xPT(cp,PRINST) ? "sub/super instance" : "?",
116 ntohl(((struct prentry *)cp)->id));
119 "Writing first %d bytes of entry @ %#lx (%d<%s>,%d)\n",
120 c, p, ntohl(((struct prentry *)cp)->flags),
121 xPT(cp,PRUSER) ? "user" : xPT(cp,PRFREE) ? "free" :
122 xPT(cp,PRGRP) ? "group" : xPT(cp,PRCONT) ? "cont" :
123 xPT(cp,PRCELL) ? "cell" : xPT(cp,PRFOREIGN) ? "foreign" :
124 xPT(cp,PRINST) ? "sub/super instance" : "?",
125 ntohl(((struct prentry *)cp)->id));
127 fprintf(stderr, "Writing %d bytes of entry @ %#lx\n", c, p);
129 if (!o && c >= 8 && xPT(cp,PRGRP)) {
131 if (in_map(sg_found, -ntohl(((struct prentry *)cp)->id)))
132 fprintf(stderr, "Unfound: Removing group %d\n",
133 ntohl(((struct prentry *)cp)->id));
134 if (in_map(sg_flagged, -ntohl(((struct prentry *)cp)->id)))
135 fprintf(stderr, "Unflag: Removing group %d\n",
136 ntohl(((struct prentry *)cp)->id));
140 add_map(NIL_MAP, -ntohl(((struct prentry *)cp)->id)));
143 add_map(NIL_MAP, -ntohl(((struct prentry *)cp)->id)));
151 return (*pt_save_dbase_write) (tdb, fno, bp, pos, count);
155 * this function attaches pt_mywrite. It's called once,
156 * just after ubik_ServerInit.
162 extern struct ubik_dbase *ubik_dbase;
163 if (ubik_dbase->write != pt_mywrite) {
164 pt_save_dbase_write = ubik_dbase->write;
165 ubik_dbase->write = pt_mywrite;
169 #endif /* SUPERGROUPS */
171 /* CorrectUserName - Check to make sure a user name is OK. It must not include
172 * either a colon (or it would look like a group) or a newline (which can
173 * confuse some ptdb code, depending on the format we're reading from).
174 * This is a predicate, so it return one if name is OK and zero if name is
178 CorrectUserName(char *name)
180 /* We accept foreign names, so we will deal with '@' later */
181 if (strchr(name, ':') || strchr(name, '\n'))
183 if (strlen(name) >= PR_MAXNAMELEN)
188 /* CorrectGroupName - Like the above but handles more complicated cases caused
189 * by including the ownership in the name. The interface works by calculating
190 * the correct name based on a given name and owner. This allows easy use by
191 * rename, which then compares the correct name with the requested new name. */
194 CorrectGroupName(struct ubik_trans *ut, char aname[PR_MAXNAMELEN], /* name for group */
195 afs_int32 cid, /* caller id */
196 afs_int32 oid, /* owner of group */
197 char cname[PR_MAXNAMELEN]) /* correct name for group */
201 char *prefix; /* ptr to group owner part */
202 char *suffix; /* ptr to group name part */
203 char name[PR_MAXNAMELEN]; /* correct name for group */
204 struct prentry tentry;
206 if (strlen(aname) >= PR_MAXNAMELEN)
208 admin = pr_noAuth || IsAMemberOf(ut, cid, SYSADMINID);
213 /* Determine the correct prefix for the name. */
214 if (oid == SYSADMINID)
217 afs_int32 loc = FindByID(ut, oid);
219 /* let admin create groups owned by non-existent ids (probably
220 * setting a group to own itself). Check that they look like
221 * groups (with a colon) or otherwise are good user names. */
223 strcpy(cname, aname);
228 code = pr_Read(ut, 0, loc, &tentry, sizeof(tentry));
231 if (ntohl(tentry.flags) & PRGRP) {
232 if ((tentry.count == 0) && !admin)
234 /* terminate prefix at colon if there is one */
235 if ((prefix = strchr(tentry.name, ':')))
238 prefix = tentry.name;
240 /* only sysadmin allow to use 'system:' prefix */
241 if ((strcmp(prefix, "system") == 0) && !admin)
244 strcpy(name, aname); /* in case aname & cname are same */
245 suffix = strchr(name, ':');
247 /* sysadmin can make groups w/o ':', but they must still look like
248 * legal user names. */
253 if (strlen(prefix) + strlen(suffix) >= PR_MAXNAMELEN)
255 strcpy(cname, prefix);
256 strcat(cname, suffix);
259 /* check for legal name with either group rules or user rules */
260 if ((suffix = strchr(cname, ':'))) {
261 /* check for confusing characters */
262 if (strchr(cname, '\n') || /* restrict so recreate can work */
263 strchr(suffix + 1, ':')) /* avoid multiple colons */
266 if (!CorrectUserName(cname))
273 AccessOK(struct ubik_trans *ut, afs_int32 cid, /* caller id */
274 struct prentry *tentry, /* object being accessed */
275 int mem, /* check membership in aid, if group */
276 int any) /* if set return true */
284 if (cid == SYSADMINID)
285 return 1; /* special case fileserver */
286 if (restricted && ((mem == PRP_ADD_MEM) || (mem == PRP_REMOVE_MEM)) && (any == 0))
289 flags = tentry->flags;
293 flags = oid = aid = 0;
295 if (!(flags & PRACCESS)) { /* provide default access */
297 flags |= prp_group_default;
299 flags |= prp_user_default;
305 if ((cid == oid) || IsAMemberOf(ut, cid, oid))
308 if (aid > 0) { /* checking on a user */
311 } else if (aid < 0) { /* checking on group */
312 if ((flags & mem) && IsAMemberOf(ut, cid, aid))
315 /* Allow members of SYSVIEWERID to get membership and status only */
316 if (((mem == PRP_STATUS_MEM) || (mem == PRP_MEMBER_MEM)
317 || (any == PRP_OWNED_ANY)) && (IsAMemberOf(ut, cid, SYSVIEWERID)))
319 if (IsAMemberOf(ut, cid, SYSADMINID))
321 return 0; /* no access */
325 CreateEntry(struct ubik_trans *at, char aname[PR_MAXNAMELEN], afs_int32 *aid, afs_int32 idflag, afs_int32 flag, afs_int32 oid, afs_int32 creator)
327 /* get and init a new entry */
330 struct prentry tentry, tent;
333 memset(&tentry, 0, sizeof(tentry));
335 if ((oid == 0) || (oid == ANONYMOUSID))
339 code = CorrectGroupName(at, aname, creator, oid, tentry.name);
342 if (strcmp(aname, tentry.name) != 0)
344 } else { /* non-group must not have colon */
345 if (!CorrectUserName(aname))
347 strcpy(tentry.name, aname);
350 if (FindByName(at, aname, &tent))
353 newEntry = AllocBlock(at);
356 tentry.createTime = time(0);
359 tentry.flags = PRGRP;
361 } else if (flag == 0) {
363 tentry.owner = SYSADMINID;
368 atsign = strchr(aname, '@');
370 /* A normal user or group. Pick an id for it */
374 code = AllocID(at, flag, &tentry.id);
375 if (code != PRSUCCESS)
378 } else if (flag & PRGRP) {
379 /* A foreign group. Its format must be AUTHUSER_GROUP@cellname
380 * Then pick an id for the group.
385 badFormat = strcmp(AUTHUSER_GROUP, aname);
393 code = AllocID(at, flag, &tentry.id);
394 if (code != PRSUCCESS)
398 /* A foreign user: <name>@<cell>. The foreign user is added to
399 * its representing group. It is
403 struct prentry centry;
405 /* To create the user <name>@<cell> the group AUTHUSER_GROUP@<cell>
409 (char *)malloc(strlen(AUTHUSER_GROUP) + strlen(atsign) + 1);
410 strcpy(cellGroup, AUTHUSER_GROUP);
411 strcat(cellGroup, atsign);
412 pos = FindByName(at, cellGroup, ¢ry);
416 code = pr_Read(at, 0, pos, ¢ry, sizeof(centry));
420 /* cellid is the id of the group representing the cell */
421 tentry.cellid = ntohl(centry.id);
424 /* Check if id is good */
425 if (!inRange(¢ry, *aid))
429 /* Allocate an ID special for this foreign user. It is based
430 * on the representing group's id and nusers count.
432 tentry.id = allocNextId(at, ¢ry);
437 /* The foreign user will be added to the representing foreign
438 * group. The group can hold up to 30 entries.
440 if (!(ntohl(centry.flags) & PRQUOTA)) {
441 centry.flags = htonl(ntohl(centry.flags) | PRQUOTA);
442 centry.ngroups = htonl(30);
444 n = ntohl(centry.ngroups);
445 if ((n <= 0) && !pr_noAuth)
447 centry.ngroups = htonl(n - 1);
449 /* write updated entry for group */
450 code = pr_Write(at, 0, pos, ¢ry, sizeof(centry));
452 /* Now add the new user entry to the database */
453 tentry.creator = creator;
455 code = pr_WriteEntry(at, 0, newEntry, &tentry);
458 code = AddToIDHash(at, *aid, newEntry);
459 if (code != PRSUCCESS)
461 code = AddToNameHash(at, aname, newEntry);
462 if (code != PRSUCCESS)
464 if (inc_header_word(at, foreigncount, 1))
467 /* Now add the entry to the authuser group for this cell.
468 * We will reread the entries for the user and the group
469 * instead of modifying them before writing them in the
470 * previous steps. Although not very efficient, much simpler
472 pos = FindByID(at, tentry.cellid);
475 code = pr_ReadEntry(at, 0, pos, ¢ry);
478 code = AddToEntry(at, ¢ry, pos, *aid);
481 /* and now the user entry */
482 pos = FindByID(at, *aid);
485 code = pr_ReadEntry(at, 0, pos, &tentry);
488 code = AddToEntry(at, &tentry, pos, tentry.cellid);
495 /* Remember the largest group id or largest user id */
497 /* group ids are negative */
498 if (tentry.id < (afs_int32) ntohl(cheader.maxGroup)) {
499 code = set_header_word(at, maxGroup, htonl(tentry.id));
504 if (tentry.id > (afs_int32) ntohl(cheader.maxID)) {
505 code = set_header_word(at, maxID, htonl(tentry.id));
511 /* Charge the creator for this group */
513 afs_int32 loc = FindByID(at, creator);
514 struct prentry centry;
517 if (loc) { /* this should only fail during initialization */
518 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
522 /* If quota is uninitialized, do it */
523 if (!(ntohl(centry.flags) & PRQUOTA)) {
524 centry.flags = htonl(ntohl(centry.flags) | PRQUOTA);
525 centry.ngroups = centry.nusers = htonl(20);
528 /* Admins don't get charged for creating a group.
529 * If in noAuth mode, you get changed for it but you
530 * are still allowed to create as many groups as you want.
532 admin = ((creator == SYSADMINID)
533 || IsAMemberOf(at, creator, SYSADMINID));
535 if (ntohl(centry.ngroups) <= 0) {
539 centry.ngroups = htonl(ntohl(centry.ngroups) - 1);
543 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
548 /* Initialize the quota for the user. Groups don't have their
551 tentry.flags |= PRQUOTA;
552 tentry.ngroups = tentry.nusers = 20;
555 tentry.creator = creator;
557 code = pr_WriteEntry(at, 0, newEntry, &tentry);
560 code = AddToIDHash(at, *aid, newEntry);
561 if (code != PRSUCCESS)
563 code = AddToNameHash(at, aname, newEntry);
564 if (code != PRSUCCESS)
566 if (tentry.flags & PRGRP) {
567 code = AddToOwnerChain(at, tentry.id, oid);
571 if (tentry.flags & PRGRP) {
572 if (inc_header_word(at, groupcount, 1))
574 } else if (tentry.flags & PRINST) {
575 if (inc_header_word(at, instcount, 1))
578 if (inc_header_word(at, usercount, 1))
585 /* RemoveFromEntry - remove aid from bid's entries list, freeing a continuation
586 * entry if appropriate */
589 RemoveFromEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 bid)
592 struct prentry tentry;
593 struct contentry centry;
594 struct contentry hentry;
601 return PRINCONSISTENT;
602 memset(&hentry, 0, sizeof(hentry));
603 temp = FindByID(at, bid);
606 code = pr_ReadEntry(at, 0, temp, &tentry);
609 tentry.removeTime = time(0);
610 for (i = 0; i < PRSIZE; i++) {
611 if (tentry.entries[i] == aid) {
612 tentry.entries[i] = PRBADID;
614 code = pr_WriteEntry(at, 0, temp, &tentry);
619 if (tentry.entries[i] == 0) /* found end of list */
625 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
628 if ((centry.id != bid) || !(centry.flags & PRCONT))
630 for (i = 0; i < COSIZE; i++) {
631 if (centry.entries[i] == aid) {
632 centry.entries[i] = PRBADID;
633 for (j = 0; j < COSIZE; j++)
634 if (centry.entries[j] != PRBADID
635 && centry.entries[j] != 0)
637 if (j == COSIZE) { /* can free this block */
639 tentry.next = centry.next;
641 hentry.next = centry.next;
642 code = pr_WriteCoEntry(at, 0, hloc, &hentry);
646 code = FreeBlock(at, nptr);
649 } else { /* can't free it yet */
650 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
655 code = pr_WriteEntry(at, 0, temp, &tentry);
660 if (centry.entries[i] == 0)
662 } /* for all coentry slots */
665 memcpy(&hentry, ¢ry, sizeof(centry));
666 } /* while there are coentries */
670 #if defined(SUPERGROUPS)
671 /* ChangeIDEntry - remove aid from bid's entries list, freeing a continuation
672 * entry if appropriate */
675 ChangeIDEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 newid, afs_int32 bid)
678 struct prentry tentry;
679 struct contentry centry;
685 return PRINCONSISTENT;
686 temp = FindByID(at, bid);
690 code = pr_ReadEntry(at, 0, temp, &tentry);
693 for (i = 0; i < PRSIZE; i++) {
694 if (tentry.entries[i] == aid) {
695 tentry.entries[i] = newid;
696 code = pr_WriteEntry(at, 0, temp, &tentry);
701 if (tentry.entries[i] == 0) { /* found end of list */
708 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
711 if ((centry.id != bid) || !(centry.flags & PRCONT)) {
713 "ChangeIDEntry: bad database bid=%d centry.id=%d .flags=%d\n",
714 bid, centry.id, centry.flags);
717 for (i = 0; i < COSIZE; i++) {
718 if (centry.entries[i] == aid) {
719 centry.entries[i] = newid;
720 for (j = 0; j < COSIZE; j++)
721 if (centry.entries[j] != PRBADID
722 && centry.entries[j] != 0)
724 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
729 if (centry.entries[i] == 0) {
732 } /* for all coentry slots */
734 } /* while there are coentries */
738 /* #ifdef SUPERGROUPS */
739 /* RemoveFromSGEntry - remove aid from bid's supergroups list, freeing a
740 * continuation entry if appropriate */
743 RemoveFromSGEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 bid)
746 struct prentry tentry;
747 struct prentryg *tentryg;
748 struct contentry centry;
749 struct contentry hentry;
756 return PRINCONSISTENT;
757 memset(&hentry, 0, sizeof(hentry));
758 temp = FindByID(at, bid);
762 code = pr_ReadEntry(at, 0, temp, &tentry);
765 tentry.removeTime = time(NULL);
766 tentryg = (struct prentryg *)&tentry;
767 for (i = 0; i < SGSIZE; i++) {
768 if (tentryg->supergroup[i] == aid) {
769 tentryg->supergroup[i] = PRBADID;
771 code = pr_WriteEntry(at, 0, temp, &tentry);
776 if (tentryg->supergroup[i] == 0) { /* found end of list */
781 nptr = tentryg->nextsg;
783 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
786 if ((centry.id != bid) || !(centry.flags & PRCONT)) {
788 "ChangeIDEntry: bad database bid=%d centry.id=%d .flags=%d\n",
789 bid, centry.id, centry.flags);
792 for (i = 0; i < COSIZE; i++) {
793 if (centry.entries[i] == aid) {
794 centry.entries[i] = PRBADID;
795 for (j = 0; j < COSIZE; j++)
796 if (centry.entries[j] != PRBADID
797 && centry.entries[j] != 0)
799 if (j == COSIZE) { /* can free this block */
801 tentryg->nextsg = centry.next;
803 hentry.next = centry.next;
804 code = pr_WriteCoEntry(at, 0, hloc, &hentry);
808 code = FreeBlock(at, nptr);
811 } else { /* can't free it yet */
812 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
817 code = pr_WriteEntry(at, 0, temp, &tentry);
822 if (centry.entries[i] == 0) {
825 } /* for all coentry slots */
828 memcpy((char *)¢ry, (char *)&hentry, sizeof(centry));
829 } /* while there are coentries */
833 #endif /* SUPERGROUPS */
835 /* DeleteEntry - delete the entry in tentry at loc, removing it from all
836 * groups, putting groups owned by it on orphan chain, and freeing the space */
839 DeleteEntry(struct ubik_trans *at, struct prentry *tentry, afs_int32 loc)
842 struct contentry centry;
846 if (strchr(tentry->name, '@')) {
847 if (tentry->flags & PRGRP) {
848 /* If there are still foreign user accounts from that cell
849 * don't delete the group */
855 afs_int32 loc = FindByID(at, tentry->cellid);
856 struct prentry centry;
858 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
861 if (ntohl(centry.flags) & PRQUOTA) {
862 centry.ngroups = htonl(ntohl(centry.ngroups) + 1);
864 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
870 /* First remove the entire membership list */
871 for (i = 0; i < PRSIZE; i++) {
872 if (tentry->entries[i] == PRBADID)
874 if (tentry->entries[i] == 0)
876 #if defined(SUPERGROUPS)
877 if ((tentry->flags & PRGRP) && tentry->entries[i] < 0) /* Supergroup */
878 code = RemoveFromSGEntry(at, tentry->id, tentry->entries[i]);
881 code = RemoveFromEntry(at, tentry->id, tentry->entries[i]);
885 #if defined(SUPERGROUPS)
887 struct prentryg *tentryg = (struct prentryg *)tentry;
889 /* Then remove the entire supergroup list */
890 for (i = 0; i < SGSIZE; i++) {
891 if (tentryg->supergroup[i] == PRBADID)
893 if (tentryg->supergroup[i] == 0)
895 code = RemoveFromEntry(at, tentry->id, tentryg->supergroup[i]);
900 #endif /* SUPERGROUPS */
903 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
906 for (i = 0; i < COSIZE; i++) {
907 if (centry.entries[i] == PRBADID)
909 if (centry.entries[i] == 0)
911 code = RemoveFromEntry(at, tentry->id, centry.entries[i]);
915 code = FreeBlock(at, nptr); /* free continuation block */
921 /* Remove us from other's owned chain. Note that this will zero our owned
922 * field (on disk) so this step must follow the above step in case we are
923 * on our own owned list. */
924 if (tentry->flags & PRGRP) {
926 code = RemoveFromOwnerChain(at, tentry->id, tentry->owner);
930 code = RemoveFromOrphan(at, tentry->id);
936 code = RemoveFromIDHash(at, tentry->id, &loc);
937 if (code != PRSUCCESS)
939 code = RemoveFromNameHash(at, tentry->name, &loc);
940 if (code != PRSUCCESS)
943 if (tentry->flags & PRGRP) {
944 afs_int32 loc = FindByID(at, tentry->creator);
945 struct prentry centry;
949 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
952 admin = ((tentry->creator == SYSADMINID)
953 || IsAMemberOf(at, tentry->creator, SYSADMINID));
954 if (ntohl(centry.flags) & PRQUOTA) {
955 if (!(admin && (ntohl(centry.ngroups) >= 20))) {
956 centry.ngroups = htonl(ntohl(centry.ngroups) + 1);
959 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
965 if (tentry->flags & PRGRP) {
966 if (inc_header_word(at, groupcount, -1))
968 } else if (tentry->flags & PRINST) {
969 if (inc_header_word(at, instcount, -1))
972 if (strchr(tentry->name, '@')) {
973 if (inc_header_word(at, foreigncount, -1))
976 if (inc_header_word(at, usercount, -1))
980 code = FreeBlock(at, loc);
984 /* AddToEntry - add aid to entry's entries list, alloc'ing a continuation block
987 * Note the entry is written out by this routine. */
990 AddToEntry(struct ubik_trans *tt, struct prentry *entry, afs_int32 loc, afs_int32 aid)
994 struct contentry nentry;
995 struct contentry aentry;
997 afs_int32 last; /* addr of last cont. block */
1000 afs_int32 slot = -1;
1002 if (entry->id == aid)
1003 return PRINCONSISTENT;
1004 entry->addTime = time(0);
1005 for (i = 0; i < PRSIZE; i++) {
1006 if (entry->entries[i] == aid)
1008 if (entry->entries[i] == PRBADID) { /* remember this spot */
1011 } else if (entry->entries[i] == 0) { /* end of the line */
1022 code = pr_ReadCoEntry(tt, 0, nptr, &nentry);
1026 if (!(nentry.flags & PRCONT))
1028 for (i = 0; i < COSIZE; i++) {
1029 if (nentry.entries[i] == aid)
1031 if (nentry.entries[i] == PRBADID) {
1036 } else if (nentry.entries[i] == 0) {
1046 if (slot != -1) { /* we found a place */
1048 if (first) { /* place is in first block */
1049 entry->entries[slot] = aid;
1050 code = pr_WriteEntry(tt, 0, loc, entry);
1055 code = pr_WriteEntry(tt, 0, loc, entry);
1058 code = pr_ReadCoEntry(tt, 0, cloc, &aentry);
1061 aentry.entries[slot] = aid;
1062 code = pr_WriteCoEntry(tt, 0, cloc, &aentry);
1067 /* have to allocate a continuation block if we got here */
1068 nptr = AllocBlock(tt);
1070 /* then we should tack new block after last block in cont. chain */
1072 code = pr_WriteCoEntry(tt, 0, last, &nentry);
1078 memset(&aentry, 0, sizeof(aentry));
1079 aentry.flags |= PRCONT;
1080 aentry.id = entry->id;
1082 aentry.entries[0] = aid;
1083 code = pr_WriteCoEntry(tt, 0, nptr, &aentry);
1086 /* don't forget to update count, here! */
1088 code = pr_WriteEntry(tt, 0, loc, entry);
1093 #if defined(SUPERGROUPS)
1095 /* AddToSGEntry - add aid to entry's supergroup list, alloc'ing a
1096 * continuation block if needed.
1098 * Note the entry is written out by this routine. */
1101 AddToSGEntry(struct ubik_trans *tt, struct prentry *entry, afs_int32 loc, afs_int32 aid)
1105 struct contentry nentry;
1106 struct contentry aentry;
1107 struct prentryg *entryg;
1109 afs_int32 last; /* addr of last cont. block */
1110 afs_int32 first = 0;
1112 afs_int32 slot = -1;
1114 if (entry->id == aid)
1115 return PRINCONSISTENT;
1116 entry->addTime = time(NULL);
1117 entryg = (struct prentryg *)entry;
1118 for (i = 0; i < SGSIZE; i++) {
1119 if (entryg->supergroup[i] == aid)
1121 if (entryg->supergroup[i] == PRBADID) { /* remember this spot */
1124 } else if (entryg->supergroup[i] == 0) { /* end of the line */
1133 nptr = entryg->nextsg;
1135 code = pr_ReadCoEntry(tt, 0, nptr, &nentry);
1139 if (!(nentry.flags & PRCONT))
1141 for (i = 0; i < COSIZE; i++) {
1142 if (nentry.entries[i] == aid)
1144 if (nentry.entries[i] == PRBADID) {
1149 } else if (nentry.entries[i] == 0) {
1159 if (slot != -1) { /* we found a place */
1161 if (first) { /* place is in first block */
1162 entryg->supergroup[slot] = aid;
1163 code = pr_WriteEntry(tt, 0, loc, entry);
1168 code = pr_WriteEntry(tt, 0, loc, entry);
1171 code = pr_ReadCoEntry(tt, 0, cloc, &aentry);
1174 aentry.entries[slot] = aid;
1175 code = pr_WriteCoEntry(tt, 0, cloc, &aentry);
1180 /* have to allocate a continuation block if we got here */
1181 nptr = AllocBlock(tt);
1183 /* then we should tack new block after last block in cont. chain */
1185 code = pr_WriteCoEntry(tt, 0, last, &nentry);
1189 entryg->nextsg = nptr;
1191 memset(&aentry, 0, sizeof(aentry));
1192 aentry.flags |= PRCONT;
1193 aentry.id = entry->id;
1195 aentry.entries[0] = aid;
1196 code = pr_WriteCoEntry(tt, 0, nptr, &aentry);
1199 /* don't forget to update count, here! */
1201 code = pr_WriteEntry(tt, 0, loc, entry);
1205 #endif /* SUPERGROUPS */
1208 AddToPRList(prlist *alist, int *sizeP, afs_int32 id)
1213 if (alist->prlist_len >= *sizeP) {
1214 count = alist->prlist_len + 100;
1215 if (alist->prlist_val) {
1217 (char *)realloc(alist->prlist_val, count * sizeof(afs_int32));
1219 tmp = (char *)malloc(count * sizeof(afs_int32));
1223 alist->prlist_val = (afs_int32 *) tmp;
1226 alist->prlist_val[alist->prlist_len++] = id;
1231 GetList(struct ubik_trans *at, struct prentry *tentry, prlist *alist, afs_int32 add)
1235 struct contentry centry;
1241 alist->prlist_val = 0;
1242 alist->prlist_len = 0;
1244 for (i = 0; i < PRSIZE; i++) {
1245 if (tentry->entries[i] == PRBADID)
1247 if (tentry->entries[i] == 0)
1249 code = AddToPRList(alist, &size, tentry->entries[i]);
1252 #if defined(SUPERGROUPS)
1255 code = GetListSG2(at, tentry->entries[i], alist, &size, depthsg);
1261 for (nptr = tentry->next; nptr != 0; nptr = centry.next) {
1262 /* look through cont entries */
1263 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1266 for (i = 0; i < COSIZE; i++) {
1267 if (centry.entries[i] == PRBADID)
1269 if (centry.entries[i] == 0)
1271 code = AddToPRList(alist, &size, centry.entries[i]);
1274 #if defined(SUPERGROUPS)
1277 code = GetListSG2(at, centry.entries[i], alist, &size, depthsg);
1283 #ifndef AFS_PTHREAD_ENV
1290 if (add) { /* this is for a CPS, so tack on appropriate stuff */
1291 if (tentry->id != ANONYMOUSID && tentry->id != ANYUSERID) {
1292 if ((code = AddToPRList(alist, &size, ANYUSERID))
1293 || (code = AddAuthGroup(tentry, alist, &size))
1294 || (code = AddToPRList(alist, &size, tentry->id)))
1297 if ((code = AddToPRList(alist, &size, ANYUSERID))
1298 || (code = AddToPRList(alist, &size, tentry->id)))
1302 #ifndef AFS_PTHREAD_ENV
1303 if (alist->prlist_len > 100)
1306 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1312 GetList2(struct ubik_trans *at, struct prentry *tentry, struct prentry *tentry2, prlist *alist, afs_int32 add)
1316 struct contentry centry;
1322 alist->prlist_val = 0;
1323 alist->prlist_len = 0;
1324 for (i = 0; i < PRSIZE; i++) {
1325 if (tentry->entries[i] == PRBADID)
1327 if (tentry->entries[i] == 0)
1329 code = AddToPRList(alist, &size, tentry->entries[i]);
1332 #if defined(SUPERGROUPS)
1335 code = GetListSG2(at, tentry->entries[i], alist, &size, depthsg);
1341 nptr = tentry->next;
1343 /* look through cont entries */
1344 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1347 for (i = 0; i < COSIZE; i++) {
1348 if (centry.entries[i] == PRBADID)
1350 if (centry.entries[i] == 0)
1352 code = AddToPRList(alist, &size, centry.entries[i]);
1355 #if defined(SUPERGROUPS)
1358 code = GetListSG2(at, centry.entries[i], alist, &size, depthsg);
1365 #ifndef AFS_PTHREAD_ENV
1372 for (i = 0; i < PRSIZE; i++) {
1373 if (tentry2->entries[i] == PRBADID)
1375 if (tentry2->entries[i] == 0)
1377 code = AddToPRList(alist, &size, tentry2->entries[i]);
1383 nptr = tentry2->next;
1385 /* look through cont entries */
1386 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1389 for (i = 0; i < COSIZE; i++) {
1390 if (centry.entries[i] == PRBADID)
1392 if (centry.entries[i] == 0)
1394 code = AddToPRList(alist, &size, centry.entries[i]);
1400 #ifndef AFS_PTHREAD_ENV
1407 if (add) { /* this is for a CPS, so tack on appropriate stuff */
1408 if (tentry->id != ANONYMOUSID && tentry->id != ANYUSERID) {
1409 if ((code = AddToPRList(alist, &size, ANYUSERID))
1410 || (code = AddToPRList(alist, &size, AUTHUSERID))
1411 || (code = AddToPRList(alist, &size, tentry->id)))
1414 if ((code = AddToPRList(alist, &size, ANYUSERID))
1415 || (code = AddToPRList(alist, &size, tentry->id)))
1419 #ifndef AFS_PTHREAD_ENV
1420 if (alist->prlist_len > 100)
1423 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1427 #if defined(SUPERGROUPS)
1430 GetListSG2(struct ubik_trans *at, afs_int32 gid, prlist *alist, afs_int32 *sizeP, afs_int32 depth)
1433 struct prentry tentry;
1434 struct prentryg *tentryg = (struct prentryg *)&tentry;
1436 struct contentry centry;
1442 int predictfound, predictflagged;
1447 if (!in_map(sg_flagged, -gid)) {
1449 fprintf(stderr, "GetListSG2: I have not yet searched for gid=%d\n",
1451 } else if (predictflagged = 1, in_map(sg_found, -gid)) {
1454 "GetListSG2: I have already searched for gid=%d, and predict success.\n",
1459 if (in_map(sg_flagged, -gid) && !in_map(sg_found, -gid)) {
1462 "GetListSG2: I have already searched for gid=%d, and predict failure.\n",
1471 temp = FindByID(at, gid);
1476 code = pr_ReadEntry(at, 0, temp, &tentry);
1480 fprintf(stderr, "GetListSG2: lookup for gid=%d [\n", gid);
1484 for (i = 0; i < SGSIZE; i++) {
1485 if (tentryg->supergroup[i] == PRBADID)
1487 if (tentryg->supergroup[i] == 0)
1491 fprintf(stderr, "via gid=%d, added %d\n", gid,
1492 e.tentryg.supergroup[i]);
1494 code = AddToPRList(alist, sizeP, tentryg->supergroup[i]);
1498 GetListSG2(at, tentryg->supergroup[i], alist, sizeP, depth - 1);
1503 nptr = tentryg->nextsg;
1506 /* look through cont entries */
1507 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1510 for (i = 0; i < COSIZE; i++) {
1511 if (centry.entries[i] == PRBADID)
1513 if (centry.entries[i] == 0)
1516 fprintf(stderr, "via gid=%d, added %d\n", gid,
1517 e.centry.entries[i]);
1519 code = AddToPRList(alist, sizeP, centry.entries[i]);
1522 code = GetListSG2(at, centry.entries[i], alist, sizeP, depth - 1);
1528 #ifndef AFS_PTHREAD_ENV
1535 fprintf(stderr, "] for gid %d, done [flag=%s]\n", gid,
1536 didsomething ? "TRUE" : "FALSE");
1537 if (predictflagged && didsomething != predictfound)
1538 fprintf(stderr, "**** for gid=%d, didsomething=%d predictfound=%d\n",
1539 didsomething, predictfound);
1542 sg_found = add_map(sg_found, -gid);
1544 sg_found = bic_map(sg_found, add_map(NIL_MAP, -gid));
1545 sg_flagged = add_map(sg_flagged, -gid);
1550 GetSGList(struct ubik_trans *at, struct prentry *tentry, prlist *alist)
1554 struct contentry centry;
1555 struct prentryg *tentryg;
1561 alist->prlist_val = 0;
1562 alist->prlist_len = 0;
1564 tentryg = (struct prentryg *)tentry;
1565 for (i = 0; i < SGSIZE; i++) {
1566 if (tentryg->supergroup[i] == PRBADID)
1568 if (tentryg->supergroup[i] == 0)
1570 code = AddToPRList(alist, &size, tentryg->supergroup[i]);
1575 nptr = tentryg->nextsg;
1577 /* look through cont entries */
1578 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1581 for (i = 0; i < COSIZE; i++) {
1582 if (centry.entries[i] == PRBADID)
1584 if (centry.entries[i] == 0)
1586 code = AddToPRList(alist, &size, centry.entries[i]);
1592 #ifndef AFS_PTHREAD_ENV
1599 #ifndef AFS_PTHREAD_ENV
1600 if (alist->prlist_len > 100)
1603 qsort((char *)alist->prlist_val, (int)alist->prlist_len,
1604 sizeof(afs_int32), IDCmp);
1607 #endif /* SUPERGROUPS */
1610 GetOwnedChain(struct ubik_trans *ut, afs_int32 *next, prlist *alist)
1613 struct prentry tentry;
1618 alist->prlist_val = 0;
1619 alist->prlist_len = 0;
1621 for (; *next; *next = ntohl(tentry.nextOwned)) {
1622 code = pr_Read(ut, 0, *next, &tentry, sizeof(tentry));
1625 code = AddToPRList(alist, &size, ntohl(tentry.id));
1626 if (alist->prlist_len >= PR_MAXGROUPS) {
1632 #ifndef AFS_PTHREAD_ENV
1638 #ifndef AFS_PTHREAD_ENV
1639 if (alist->prlist_len > 100)
1642 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1647 GetMax(struct ubik_trans *at, afs_int32 *uid, afs_int32 *gid)
1649 *uid = ntohl(cheader.maxID);
1650 *gid = ntohl(cheader.maxGroup);
1655 SetMax(struct ubik_trans *at, afs_int32 id, afs_int32 flag)
1659 cheader.maxGroup = htonl(id);
1661 pr_Write(at, 0, 16, (char *)&cheader.maxGroup,
1662 sizeof(cheader.maxGroup));
1666 cheader.maxID = htonl(id);
1668 pr_Write(at, 0, 20, (char *)&cheader.maxID,
1669 sizeof(cheader.maxID));
1677 UpdateCache(struct ubik_trans *tt, void *rock)
1681 code = pr_Read(tt, 0, 0, (char *)&cheader, sizeof(cheader));
1683 afs_com_err(whoami, code, "Couldn't read header");
1689 read_DbHeader(struct ubik_trans *tt)
1691 return ubik_CheckCache(tt, UpdateCache, NULL);
1697 * reads in db cache from ubik.
1699 * @param[in] ut ubik transaction
1700 * @param[out] rock opaque pointer to an int*, which on success will be set
1701 * to 1 if we need to build the database, or 0 if we do not
1703 * @return operation status
1707 Initdb_check(struct ubik_trans *tt, void *rock)
1709 int *build_rock = rock;
1713 len = sizeof(cheader);
1714 code = pr_Read(tt, 0, 0, (char *)&cheader, len);
1716 afs_com_err(whoami, code, "couldn't read header");
1719 if ((ntohl(cheader.version) == PRDBVERSION)
1720 && ntohl(cheader.headerSize) == sizeof(cheader)
1721 && ntohl(cheader.eofPtr) != 0
1722 && FindByID(tt, ANONYMOUSID) != 0) {
1723 /* database exists, so we don't have to build it */
1728 /* else we need to build a database */
1736 struct ubik_trans *tt;
1740 /* init the database. We'll try reading it, but if we're starting
1741 * from scratch, we'll have to do a write transaction. */
1743 pr_noAuth = afsconf_GetNoAuthFlag(prdir);
1745 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
1748 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
1750 ubik_AbortTrans(tt);
1754 code = ubik_CheckCache(tt, Initdb_check, &build);
1756 ubik_AbortTrans(tt);
1761 /* Only rebuild database if the db was deleted (the header is zero) */
1762 char *bp = (char *)&cheader;
1764 for (i = 0; i < sizeof(cheader); i++) {
1767 afs_com_err(whoami, code,
1768 "Can't rebuild database because it is not empty");
1777 code = ubik_EndTrans(tt);
1779 if (code || !build) {
1780 /* either we encountered an error, or we don't need to build the db */
1784 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
1788 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
1790 ubik_AbortTrans(tt);
1794 /* before doing a rebuild, check again that the dbase looks bad, because
1795 * the previous check was only under a ReadAny transaction, and there could
1796 * actually have been a good database out there. Now that we have a
1797 * real write transaction, make sure things are still bad.
1799 code = pr_Read(tt, 0, 0, (char *)&cheader, sizeof(cheader));
1801 afs_com_err(whoami, code, "couldn't read header");
1802 ubik_AbortTrans(tt);
1805 if ((ntohl(cheader.version) == PRDBVERSION)
1806 && ntohl(cheader.headerSize) == sizeof(cheader)
1807 && ntohl(cheader.eofPtr) != 0
1808 && FindByID(tt, ANONYMOUSID) != 0) {
1809 /* database exists, so we don't have to build it */
1810 code = ubik_EndTrans(tt);
1816 /* Initialize the database header */
1817 if ((code = set_header_word(tt, version, htonl(PRDBVERSION)))
1818 || (code = set_header_word(tt, headerSize, htonl(sizeof(cheader))))
1819 || (code = set_header_word(tt, eofPtr, cheader.headerSize))) {
1820 afs_com_err(whoami, code, "couldn't write header words");
1821 ubik_AbortTrans(tt);
1824 #define InitialGroup(id,name) do { \
1825 afs_int32 temp = (id); \
1826 afs_int32 flag = (id) < 0 ? PRGRP : 0; \
1827 code = CreateEntry \
1828 (tt, (name), &temp, /*idflag*/1, flag, SYSADMINID, SYSADMINID); \
1830 afs_com_err (whoami, code, "couldn't create %s with id %di.", \
1832 ubik_AbortTrans(tt); \
1837 InitialGroup(SYSADMINID, "system:administrators");
1838 InitialGroup(SYSBACKUPID, "system:backup");
1839 InitialGroup(ANYUSERID, "system:anyuser");
1840 InitialGroup(AUTHUSERID, "system:authuser");
1841 InitialGroup(SYSVIEWERID, "system:ptsviewers");
1842 InitialGroup(ANONYMOUSID, "anonymous");
1844 /* Well, we don't really want the max id set to anonymousid, so we'll set
1846 code = set_header_word(tt, maxID, 0); /* correct in any byte order */
1848 afs_com_err(whoami, code, "couldn't reset max id");
1849 ubik_AbortTrans(tt);
1853 code = ubik_EndTrans(tt);
1860 ChangeEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 cid, char *name, afs_int32 oid, afs_int32 newid)
1864 #if defined(SUPERGROUPS)
1868 struct contentry centry;
1870 struct prentry tentry, tent;
1873 char holder[PR_MAXNAMELEN];
1874 char temp[PR_MAXNAMELEN];
1875 char oldname[PR_MAXNAMELEN];
1878 memset(holder, 0, PR_MAXNAMELEN);
1879 memset(temp, 0, PR_MAXNAMELEN);
1880 loc = FindByID(at, aid);
1883 code = pr_ReadEntry(at, 0, loc, &tentry);
1886 if (restricted && !IsAMemberOf(at, cid, SYSADMINID))
1888 if (tentry.owner != cid && !IsAMemberOf(at, cid, SYSADMINID)
1889 && !IsAMemberOf(at, cid, tentry.owner) && !pr_noAuth)
1891 tentry.changeTime = time(0);
1893 /* we're actually trying to change the id */
1894 if (newid && (newid != aid)) {
1895 if (!IsAMemberOf(at, cid, SYSADMINID) && !pr_noAuth)
1898 pos = FindByID(at, newid);
1900 return PRIDEXIST; /* new id already in use! */
1901 if ((aid < 0 && newid > 0) || (aid > 0 && newid < 0))
1904 /* Should check that foreign users id to change to is good: inRange() */
1906 /* if new id is not in use, rehash things */
1907 code = RemoveFromIDHash(at, aid, &loc);
1908 if (code != PRSUCCESS)
1911 code = pr_WriteEntry(at, 0, loc, &tentry);
1914 code = AddToIDHash(at, tentry.id, loc);
1918 /* get current data */
1919 code = pr_ReadEntry(at, 0, loc, &tentry);
1923 #if defined(SUPERGROUPS)
1924 if (tentry.id > (afs_int32) ntohl(cheader.maxID))
1925 code = set_header_word(at, maxID, htonl(tentry.id));
1929 /* need to fix up: membership
1934 for (i = 0; i < PRSIZE; i++) {
1935 if (tentry.entries[i] == PRBADID)
1937 if (tentry.entries[i] == 0)
1939 if ((tentry.flags & PRGRP) && tentry.entries[i] < 0) { /* Supergroup */
1940 return 5; /* not yet, in short. */
1942 code = ChangeIDEntry(at, aid, newid, tentry.entries[i]);
1947 for (pos = ntohl(tentry.owned); pos; pos = nextpos) {
1948 code = pr_ReadEntry(at, 0, pos, &tent);
1952 nextpos = tent.nextOwned;
1953 code = pr_WriteEntry(at, 0, pos, &tent);
1959 #define centry (*(struct contentry*)&tent)
1960 code = pr_ReadCoEntry(at, 0, pos, ¢ry);
1961 if ((centry.id != aid)
1962 || !(centry.flags & PRCONT)) {
1964 "ChangeEntry: bad database aid=%d centry.id=%d .flags=%d\n",
1965 aid, centry.id, centry.flags);
1969 for (i = 0; i < COSIZE; i++) {
1970 if (centry.entries[i] == PRBADID)
1972 if (centry.entries[i] == 0)
1974 if ((centry.flags & PRGRP) && centry.entries[i] < 0) { /* Supergroup */
1975 return 5; /* not yet, in short. */
1977 code = ChangeIDEntry(at, aid, newid, centry.entries[i]);
1982 code = pr_WriteCoEntry(at, 0, pos, ¢ry);
1989 #else /* SUPERGROUPS */
1992 /* Also change the references from the membership list */
1993 for (i = 0; i < PRSIZE; i++) {
1994 if (tentry.entries[i] == PRBADID)
1996 if (tentry.entries[i] == 0)
1998 pos = FindByID(at, tentry.entries[i]);
2001 code = RemoveFromEntry(at, aid, tentry.entries[i]);
2004 code = pr_ReadEntry(at, 0, pos, &tent);
2007 code = AddToEntry(at, &tent, pos, newid);
2011 /* Look through cont entries too. This needs to be broken into
2012 * seperate transaction so that no one transaction becomes too
2013 * large to complete.
2015 for (nptr = tentry.next; nptr; nptr = centry.next) {
2016 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
2019 for (i = 0; i < COSIZE; i++) {
2020 if (centry.entries[i] == PRBADID)
2022 if (centry.entries[i] == 0)
2024 pos = FindByID(at, centry.entries[i]);
2027 code = RemoveFromEntry(at, aid, centry.entries[i]);
2030 code = pr_ReadEntry(at, 0, pos, &tent);
2033 code = AddToEntry(at, &tent, pos, newid);
2038 #endif /* SUPERGROUPS */
2041 atsign = strchr(tentry.name, '@'); /* check for foreign entry */
2043 /* Change the owner */
2044 if (oid && (oid != tentry.owner)) {
2045 /* only groups can have their owner's changed */
2046 if (!(tentry.flags & PRGRP))
2050 oldowner = tentry.owner;
2052 /* The entry must be written through first so Remove and Add routines
2053 * can operate on disk data */
2054 code = pr_WriteEntry(at, 0, loc, &tentry);
2058 /* switch owner chains */
2059 if (oldowner) /* if it has an owner */
2060 code = RemoveFromOwnerChain(at, tentry.id, oldowner);
2061 else /* must be an orphan */
2062 code = RemoveFromOrphan(at, tentry.id);
2065 code = AddToOwnerChain(at, tentry.id, tentry.owner);
2069 /* fix up the name */
2070 if (strlen(name) == 0)
2072 /* get current data */
2073 code = pr_ReadEntry(at, 0, loc, &tentry);
2078 /* Change the name, if name is a ptr to tentry.name then this name change
2079 * is due to a chown, otherwise caller has specified a new name */
2080 if ((name == tentry.name) || (*name && (strcmp(tentry.name, name) != 0))) {
2081 strncpy(oldname, tentry.name, PR_MAXNAMELEN);
2082 if (tentry.flags & PRGRP) {
2083 /* don't let foreign cell groups change name */
2086 code = CorrectGroupName(at, name, cid, tentry.owner, tentry.name);
2090 if (name == tentry.name) { /* owner fixup */
2091 if (strcmp(oldname, tentry.name) == 0)
2093 } else { /* new name, caller must be correct */
2094 if (strcmp(name, tentry.name) != 0)
2098 /* Allow a foreign name change only if the cellname part is
2103 newatsign = strchr(name, '@');
2104 if (newatsign != atsign) { /* if they are the same no problem */
2105 /*if the pointers are not equal the strings better be */
2106 if ((atsign == NULL) || (newatsign == NULL)
2107 || strcmp(atsign, newatsign))
2110 if (!CorrectUserName(name))
2114 pos = FindByName(at, name, &tent);
2117 code = RemoveFromNameHash(at, oldname, &loc);
2118 if (code != PRSUCCESS)
2120 strncpy(tentry.name, name, PR_MAXNAMELEN);
2121 code = pr_WriteEntry(at, 0, loc, &tentry);
2124 code = AddToNameHash(at, tentry.name, loc);
2125 if (code != PRSUCCESS)
2134 allocNextId(struct ubik_trans * at, struct prentry * cellEntry)
2136 /* Id's for foreign cell entries are constructed as follows:
2137 * The 16 low order bits are the group id of the cell and the
2138 * top 16 bits identify the particular users in that cell */
2141 afs_int32 cellid = ((ntohl(cellEntry->id)) & 0x0000ffff);
2143 id = (ntohl(cellEntry->nusers) + 1);
2144 while (FindByID(at, ((id << 16) | cellid))) {
2150 cellEntry->nusers = htonl(id);
2151 /* use the field nusers to keep
2152 * the next available id in that
2153 * foreign cell's group. Note :
2154 * It would seem more appropriate
2155 * to use ngroup for that and nusers
2156 * to enforce the quota, however pts
2157 * does not have an option to change
2158 * foreign users quota yet */
2160 id = (id << 16) | cellid;
2165 inRange(struct prentry *cellEntry, afs_int32 aid)
2167 afs_uint32 id, cellid, groupid;
2171 * The only thing that we want to make sure here is that
2172 * the id is in the legal range of this group. If it is
2173 * a duplicate we don't care since it will get caught
2174 * in a different check.
2177 cellid = aid & 0x0000ffff;
2178 groupid = (ntohl(cellEntry->id)) & 0x0000ffff;
2179 if (cellid != groupid)
2180 return 0; /* not in range */
2183 * if we got here we're ok but we need to update the nusers
2184 * field in order to get the id correct the next time that
2185 * we try to allocate it automatically
2189 if (id > ntohl(cellEntry->nusers))
2190 cellEntry->nusers = htonl(id);
2196 AddAuthGroup(struct prentry *tentry, prlist *alist, afs_int32 *size)
2198 if (!(strchr(tentry->name, '@')))
2199 return (AddToPRList(alist, size, AUTHUSERID));