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>
408 asprintf(&cellGroup, "%s%s", AUTHUSER_GROUP, atsign);
409 pos = FindByName(at, cellGroup, ¢ry);
413 code = pr_Read(at, 0, pos, ¢ry, sizeof(centry));
417 /* cellid is the id of the group representing the cell */
418 tentry.cellid = ntohl(centry.id);
421 /* Check if id is good */
422 if (!inRange(¢ry, *aid))
426 /* Allocate an ID special for this foreign user. It is based
427 * on the representing group's id and nusers count.
429 tentry.id = allocNextId(at, ¢ry);
434 /* The foreign user will be added to the representing foreign
435 * group. The group can hold up to 30 entries.
437 if (!(ntohl(centry.flags) & PRQUOTA)) {
438 centry.flags = htonl(ntohl(centry.flags) | PRQUOTA);
439 centry.ngroups = htonl(30);
441 n = ntohl(centry.ngroups);
442 if ((n <= 0) && !pr_noAuth)
444 centry.ngroups = htonl(n - 1);
446 /* write updated entry for group */
447 code = pr_Write(at, 0, pos, ¢ry, sizeof(centry));
451 /* Now add the new user entry to the database */
452 tentry.creator = creator;
454 code = pr_WriteEntry(at, 0, newEntry, &tentry);
457 code = AddToIDHash(at, *aid, newEntry);
458 if (code != PRSUCCESS)
460 code = AddToNameHash(at, aname, newEntry);
461 if (code != PRSUCCESS)
463 if (inc_header_word(at, foreigncount, 1))
466 /* Now add the entry to the authuser group for this cell.
467 * We will reread the entries for the user and the group
468 * instead of modifying them before writing them in the
469 * previous steps. Although not very efficient, much simpler
471 pos = FindByID(at, tentry.cellid);
474 code = pr_ReadEntry(at, 0, pos, ¢ry);
477 code = AddToEntry(at, ¢ry, pos, *aid);
480 /* and now the user entry */
481 pos = FindByID(at, *aid);
484 code = pr_ReadEntry(at, 0, pos, &tentry);
487 code = AddToEntry(at, &tentry, pos, tentry.cellid);
494 /* Remember the largest group id or largest user id */
496 /* group ids are negative */
497 if (tentry.id < (afs_int32) ntohl(cheader.maxGroup)) {
498 code = set_header_word(at, maxGroup, htonl(tentry.id));
503 if (tentry.id > (afs_int32) ntohl(cheader.maxID)) {
504 code = set_header_word(at, maxID, htonl(tentry.id));
510 /* Charge the creator for this group */
512 afs_int32 loc = FindByID(at, creator);
513 struct prentry centry;
516 if (loc) { /* this should only fail during initialization */
517 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
521 /* If quota is uninitialized, do it */
522 if (!(ntohl(centry.flags) & PRQUOTA)) {
523 centry.flags = htonl(ntohl(centry.flags) | PRQUOTA);
524 centry.ngroups = centry.nusers = htonl(20);
527 /* Admins don't get charged for creating a group.
528 * If in noAuth mode, you get changed for it but you
529 * are still allowed to create as many groups as you want.
531 admin = ((creator == SYSADMINID)
532 || IsAMemberOf(at, creator, SYSADMINID));
534 if (ntohl(centry.ngroups) <= 0) {
538 centry.ngroups = htonl(ntohl(centry.ngroups) - 1);
542 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
547 /* Initialize the quota for the user. Groups don't have their
550 tentry.flags |= PRQUOTA;
551 tentry.ngroups = tentry.nusers = 20;
554 tentry.creator = creator;
556 code = pr_WriteEntry(at, 0, newEntry, &tentry);
559 code = AddToIDHash(at, *aid, newEntry);
560 if (code != PRSUCCESS)
562 code = AddToNameHash(at, aname, newEntry);
563 if (code != PRSUCCESS)
565 if (tentry.flags & PRGRP) {
566 code = AddToOwnerChain(at, tentry.id, oid);
570 if (tentry.flags & PRGRP) {
571 if (inc_header_word(at, groupcount, 1))
573 } else if (tentry.flags & PRINST) {
574 if (inc_header_word(at, instcount, 1))
577 if (inc_header_word(at, usercount, 1))
584 /* RemoveFromEntry - remove aid from bid's entries list, freeing a continuation
585 * entry if appropriate */
588 RemoveFromEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 bid)
591 struct prentry tentry;
592 struct contentry centry;
593 struct contentry hentry;
600 return PRINCONSISTENT;
601 memset(&hentry, 0, sizeof(hentry));
602 temp = FindByID(at, bid);
605 code = pr_ReadEntry(at, 0, temp, &tentry);
608 tentry.removeTime = time(0);
609 for (i = 0; i < PRSIZE; i++) {
610 if (tentry.entries[i] == aid) {
611 tentry.entries[i] = PRBADID;
613 code = pr_WriteEntry(at, 0, temp, &tentry);
618 if (tentry.entries[i] == 0) /* found end of list */
624 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
627 if ((centry.id != bid) || !(centry.flags & PRCONT))
629 for (i = 0; i < COSIZE; i++) {
630 if (centry.entries[i] == aid) {
631 centry.entries[i] = PRBADID;
632 for (j = 0; j < COSIZE; j++)
633 if (centry.entries[j] != PRBADID
634 && centry.entries[j] != 0)
636 if (j == COSIZE) { /* can free this block */
638 tentry.next = centry.next;
640 hentry.next = centry.next;
641 code = pr_WriteCoEntry(at, 0, hloc, &hentry);
645 code = FreeBlock(at, nptr);
648 } else { /* can't free it yet */
649 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
654 code = pr_WriteEntry(at, 0, temp, &tentry);
659 if (centry.entries[i] == 0)
661 } /* for all coentry slots */
664 memcpy(&hentry, ¢ry, sizeof(centry));
665 } /* while there are coentries */
669 #if defined(SUPERGROUPS)
670 /* ChangeIDEntry - remove aid from bid's entries list, freeing a continuation
671 * entry if appropriate */
674 ChangeIDEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 newid, afs_int32 bid)
677 struct prentry tentry;
678 struct contentry centry;
684 return PRINCONSISTENT;
685 temp = FindByID(at, bid);
689 code = pr_ReadEntry(at, 0, temp, &tentry);
692 for (i = 0; i < PRSIZE; i++) {
693 if (tentry.entries[i] == aid) {
694 tentry.entries[i] = newid;
695 code = pr_WriteEntry(at, 0, temp, &tentry);
700 if (tentry.entries[i] == 0) { /* found end of list */
707 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
710 if ((centry.id != bid) || !(centry.flags & PRCONT)) {
712 "ChangeIDEntry: bad database bid=%d centry.id=%d .flags=%d\n",
713 bid, centry.id, centry.flags);
716 for (i = 0; i < COSIZE; i++) {
717 if (centry.entries[i] == aid) {
718 centry.entries[i] = newid;
719 for (j = 0; j < COSIZE; j++)
720 if (centry.entries[j] != PRBADID
721 && centry.entries[j] != 0)
723 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
728 if (centry.entries[i] == 0) {
731 } /* for all coentry slots */
733 } /* while there are coentries */
737 /* #ifdef SUPERGROUPS */
738 /* RemoveFromSGEntry - remove aid from bid's supergroups list, freeing a
739 * continuation entry if appropriate */
742 RemoveFromSGEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 bid)
745 struct prentry tentry;
746 struct prentryg *tentryg;
747 struct contentry centry;
748 struct contentry hentry;
755 return PRINCONSISTENT;
756 memset(&hentry, 0, sizeof(hentry));
757 temp = FindByID(at, bid);
761 code = pr_ReadEntry(at, 0, temp, &tentry);
764 tentry.removeTime = time(NULL);
765 tentryg = (struct prentryg *)&tentry;
766 for (i = 0; i < SGSIZE; i++) {
767 if (tentryg->supergroup[i] == aid) {
768 tentryg->supergroup[i] = PRBADID;
770 code = pr_WriteEntry(at, 0, temp, &tentry);
775 if (tentryg->supergroup[i] == 0) { /* found end of list */
780 nptr = tentryg->nextsg;
782 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
785 if ((centry.id != bid) || !(centry.flags & PRCONT)) {
787 "ChangeIDEntry: bad database bid=%d centry.id=%d .flags=%d\n",
788 bid, centry.id, centry.flags);
791 for (i = 0; i < COSIZE; i++) {
792 if (centry.entries[i] == aid) {
793 centry.entries[i] = PRBADID;
794 for (j = 0; j < COSIZE; j++)
795 if (centry.entries[j] != PRBADID
796 && centry.entries[j] != 0)
798 if (j == COSIZE) { /* can free this block */
800 tentryg->nextsg = centry.next;
802 hentry.next = centry.next;
803 code = pr_WriteCoEntry(at, 0, hloc, &hentry);
807 code = FreeBlock(at, nptr);
810 } else { /* can't free it yet */
811 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
816 code = pr_WriteEntry(at, 0, temp, &tentry);
821 if (centry.entries[i] == 0) {
824 } /* for all coentry slots */
827 memcpy((char *)¢ry, (char *)&hentry, sizeof(centry));
828 } /* while there are coentries */
832 #endif /* SUPERGROUPS */
834 /* DeleteEntry - delete the entry in tentry at loc, removing it from all
835 * groups, putting groups owned by it on orphan chain, and freeing the space */
838 DeleteEntry(struct ubik_trans *at, struct prentry *tentry, afs_int32 loc)
841 struct contentry centry;
845 if (strchr(tentry->name, '@')) {
846 if (tentry->flags & PRGRP) {
847 /* If there are still foreign user accounts from that cell
848 * don't delete the group */
854 afs_int32 loc = FindByID(at, tentry->cellid);
855 struct prentry centry;
857 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
860 if (ntohl(centry.flags) & PRQUOTA) {
861 centry.ngroups = htonl(ntohl(centry.ngroups) + 1);
863 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
869 /* First remove the entire membership list */
870 for (i = 0; i < PRSIZE; i++) {
871 if (tentry->entries[i] == PRBADID)
873 if (tentry->entries[i] == 0)
875 #if defined(SUPERGROUPS)
876 if ((tentry->flags & PRGRP) && tentry->entries[i] < 0) /* Supergroup */
877 code = RemoveFromSGEntry(at, tentry->id, tentry->entries[i]);
880 code = RemoveFromEntry(at, tentry->id, tentry->entries[i]);
884 #if defined(SUPERGROUPS)
886 struct prentryg *tentryg = (struct prentryg *)tentry;
888 /* Then remove the entire supergroup list */
889 for (i = 0; i < SGSIZE; i++) {
890 if (tentryg->supergroup[i] == PRBADID)
892 if (tentryg->supergroup[i] == 0)
894 code = RemoveFromEntry(at, tentry->id, tentryg->supergroup[i]);
899 #endif /* SUPERGROUPS */
902 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
905 for (i = 0; i < COSIZE; i++) {
906 if (centry.entries[i] == PRBADID)
908 if (centry.entries[i] == 0)
910 code = RemoveFromEntry(at, tentry->id, centry.entries[i]);
914 code = FreeBlock(at, nptr); /* free continuation block */
920 /* Remove us from other's owned chain. Note that this will zero our owned
921 * field (on disk) so this step must follow the above step in case we are
922 * on our own owned list. */
923 if (tentry->flags & PRGRP) {
925 code = RemoveFromOwnerChain(at, tentry->id, tentry->owner);
929 code = RemoveFromOrphan(at, tentry->id);
935 code = RemoveFromIDHash(at, tentry->id, &loc);
936 if (code != PRSUCCESS)
938 code = RemoveFromNameHash(at, tentry->name, &loc);
939 if (code != PRSUCCESS)
942 if (tentry->flags & PRGRP) {
943 afs_int32 loc = FindByID(at, tentry->creator);
944 struct prentry centry;
948 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
951 admin = ((tentry->creator == SYSADMINID)
952 || IsAMemberOf(at, tentry->creator, SYSADMINID));
953 if (ntohl(centry.flags) & PRQUOTA) {
954 if (!(admin && (ntohl(centry.ngroups) >= 20))) {
955 centry.ngroups = htonl(ntohl(centry.ngroups) + 1);
958 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
964 if (tentry->flags & PRGRP) {
965 if (inc_header_word(at, groupcount, -1))
967 } else if (tentry->flags & PRINST) {
968 if (inc_header_word(at, instcount, -1))
971 if (strchr(tentry->name, '@')) {
972 if (inc_header_word(at, foreigncount, -1))
975 if (inc_header_word(at, usercount, -1))
979 code = FreeBlock(at, loc);
983 /* AddToEntry - add aid to entry's entries list, alloc'ing a continuation block
986 * Note the entry is written out by this routine. */
989 AddToEntry(struct ubik_trans *tt, struct prentry *entry, afs_int32 loc, afs_int32 aid)
993 struct contentry nentry;
994 struct contentry aentry;
996 afs_int32 last; /* addr of last cont. block */
1001 if (entry->id == aid)
1002 return PRINCONSISTENT;
1003 entry->addTime = time(0);
1004 for (i = 0; i < PRSIZE; i++) {
1005 if (entry->entries[i] == aid)
1007 if (entry->entries[i] == PRBADID) { /* remember this spot */
1010 } else if (entry->entries[i] == 0) { /* end of the line */
1021 code = pr_ReadCoEntry(tt, 0, nptr, &nentry);
1025 if (!(nentry.flags & PRCONT))
1027 for (i = 0; i < COSIZE; i++) {
1028 if (nentry.entries[i] == aid)
1030 if (nentry.entries[i] == PRBADID) {
1035 } else if (nentry.entries[i] == 0) {
1045 if (slot != -1) { /* we found a place */
1047 if (first) { /* place is in first block */
1048 entry->entries[slot] = aid;
1049 code = pr_WriteEntry(tt, 0, loc, entry);
1054 code = pr_WriteEntry(tt, 0, loc, entry);
1057 code = pr_ReadCoEntry(tt, 0, cloc, &aentry);
1060 aentry.entries[slot] = aid;
1061 code = pr_WriteCoEntry(tt, 0, cloc, &aentry);
1066 /* have to allocate a continuation block if we got here */
1067 nptr = AllocBlock(tt);
1069 /* then we should tack new block after last block in cont. chain */
1071 code = pr_WriteCoEntry(tt, 0, last, &nentry);
1077 memset(&aentry, 0, sizeof(aentry));
1078 aentry.flags |= PRCONT;
1079 aentry.id = entry->id;
1081 aentry.entries[0] = aid;
1082 code = pr_WriteCoEntry(tt, 0, nptr, &aentry);
1085 /* don't forget to update count, here! */
1087 code = pr_WriteEntry(tt, 0, loc, entry);
1092 #if defined(SUPERGROUPS)
1094 /* AddToSGEntry - add aid to entry's supergroup list, alloc'ing a
1095 * continuation block if needed.
1097 * Note the entry is written out by this routine. */
1100 AddToSGEntry(struct ubik_trans *tt, struct prentry *entry, afs_int32 loc, afs_int32 aid)
1104 struct contentry nentry;
1105 struct contentry aentry;
1106 struct prentryg *entryg;
1108 afs_int32 last; /* addr of last cont. block */
1109 afs_int32 first = 0;
1111 afs_int32 slot = -1;
1113 if (entry->id == aid)
1114 return PRINCONSISTENT;
1115 entry->addTime = time(NULL);
1116 entryg = (struct prentryg *)entry;
1117 for (i = 0; i < SGSIZE; i++) {
1118 if (entryg->supergroup[i] == aid)
1120 if (entryg->supergroup[i] == PRBADID) { /* remember this spot */
1123 } else if (entryg->supergroup[i] == 0) { /* end of the line */
1132 nptr = entryg->nextsg;
1134 code = pr_ReadCoEntry(tt, 0, nptr, &nentry);
1138 if (!(nentry.flags & PRCONT))
1140 for (i = 0; i < COSIZE; i++) {
1141 if (nentry.entries[i] == aid)
1143 if (nentry.entries[i] == PRBADID) {
1148 } else if (nentry.entries[i] == 0) {
1158 if (slot != -1) { /* we found a place */
1160 if (first) { /* place is in first block */
1161 entryg->supergroup[slot] = aid;
1162 code = pr_WriteEntry(tt, 0, loc, entry);
1167 code = pr_WriteEntry(tt, 0, loc, entry);
1170 code = pr_ReadCoEntry(tt, 0, cloc, &aentry);
1173 aentry.entries[slot] = aid;
1174 code = pr_WriteCoEntry(tt, 0, cloc, &aentry);
1179 /* have to allocate a continuation block if we got here */
1180 nptr = AllocBlock(tt);
1182 /* then we should tack new block after last block in cont. chain */
1184 code = pr_WriteCoEntry(tt, 0, last, &nentry);
1188 entryg->nextsg = nptr;
1190 memset(&aentry, 0, sizeof(aentry));
1191 aentry.flags |= PRCONT;
1192 aentry.id = entry->id;
1194 aentry.entries[0] = aid;
1195 code = pr_WriteCoEntry(tt, 0, nptr, &aentry);
1198 /* don't forget to update count, here! */
1200 code = pr_WriteEntry(tt, 0, loc, entry);
1204 #endif /* SUPERGROUPS */
1207 AddToPRList(prlist *alist, int *sizeP, afs_int32 id)
1212 if (alist->prlist_len >= *sizeP) {
1213 count = alist->prlist_len + 100;
1214 if (alist->prlist_val) {
1215 tmp = realloc(alist->prlist_val, count * sizeof(afs_int32));
1217 tmp = malloc(count * sizeof(afs_int32));
1221 alist->prlist_val = tmp;
1224 alist->prlist_val[alist->prlist_len++] = id;
1229 GetList(struct ubik_trans *at, struct prentry *tentry, prlist *alist, afs_int32 add)
1233 struct contentry centry;
1239 alist->prlist_val = 0;
1240 alist->prlist_len = 0;
1242 for (i = 0; i < PRSIZE; i++) {
1243 if (tentry->entries[i] == PRBADID)
1245 if (tentry->entries[i] == 0)
1247 code = AddToPRList(alist, &size, tentry->entries[i]);
1250 #if defined(SUPERGROUPS)
1253 code = GetListSG2(at, tentry->entries[i], alist, &size, depthsg);
1259 for (nptr = tentry->next; nptr != 0; nptr = centry.next) {
1260 /* look through cont entries */
1261 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1264 for (i = 0; i < COSIZE; i++) {
1265 if (centry.entries[i] == PRBADID)
1267 if (centry.entries[i] == 0)
1269 code = AddToPRList(alist, &size, centry.entries[i]);
1272 #if defined(SUPERGROUPS)
1275 code = GetListSG2(at, centry.entries[i], alist, &size, depthsg);
1281 #ifndef AFS_PTHREAD_ENV
1288 if (add) { /* this is for a CPS, so tack on appropriate stuff */
1289 if (tentry->id != ANONYMOUSID && tentry->id != ANYUSERID) {
1290 if ((code = AddToPRList(alist, &size, ANYUSERID))
1291 || (code = AddAuthGroup(tentry, alist, &size))
1292 || (code = AddToPRList(alist, &size, tentry->id)))
1295 if ((code = AddToPRList(alist, &size, ANYUSERID))
1296 || (code = AddToPRList(alist, &size, tentry->id)))
1300 #ifndef AFS_PTHREAD_ENV
1301 if (alist->prlist_len > 100)
1304 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1310 GetList2(struct ubik_trans *at, struct prentry *tentry, struct prentry *tentry2, prlist *alist, afs_int32 add)
1314 struct contentry centry;
1320 alist->prlist_val = 0;
1321 alist->prlist_len = 0;
1322 for (i = 0; i < PRSIZE; i++) {
1323 if (tentry->entries[i] == PRBADID)
1325 if (tentry->entries[i] == 0)
1327 code = AddToPRList(alist, &size, tentry->entries[i]);
1330 #if defined(SUPERGROUPS)
1333 code = GetListSG2(at, tentry->entries[i], alist, &size, depthsg);
1339 nptr = tentry->next;
1341 /* look through cont entries */
1342 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1345 for (i = 0; i < COSIZE; i++) {
1346 if (centry.entries[i] == PRBADID)
1348 if (centry.entries[i] == 0)
1350 code = AddToPRList(alist, &size, centry.entries[i]);
1353 #if defined(SUPERGROUPS)
1356 code = GetListSG2(at, centry.entries[i], alist, &size, depthsg);
1363 #ifndef AFS_PTHREAD_ENV
1370 for (i = 0; i < PRSIZE; i++) {
1371 if (tentry2->entries[i] == PRBADID)
1373 if (tentry2->entries[i] == 0)
1375 code = AddToPRList(alist, &size, tentry2->entries[i]);
1381 nptr = tentry2->next;
1383 /* look through cont entries */
1384 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1387 for (i = 0; i < COSIZE; i++) {
1388 if (centry.entries[i] == PRBADID)
1390 if (centry.entries[i] == 0)
1392 code = AddToPRList(alist, &size, centry.entries[i]);
1398 #ifndef AFS_PTHREAD_ENV
1405 if (add) { /* this is for a CPS, so tack on appropriate stuff */
1406 if (tentry->id != ANONYMOUSID && tentry->id != ANYUSERID) {
1407 if ((code = AddToPRList(alist, &size, ANYUSERID))
1408 || (code = AddToPRList(alist, &size, AUTHUSERID))
1409 || (code = AddToPRList(alist, &size, tentry->id)))
1412 if ((code = AddToPRList(alist, &size, ANYUSERID))
1413 || (code = AddToPRList(alist, &size, tentry->id)))
1417 #ifndef AFS_PTHREAD_ENV
1418 if (alist->prlist_len > 100)
1421 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1425 #if defined(SUPERGROUPS)
1428 GetListSG2(struct ubik_trans *at, afs_int32 gid, prlist *alist, afs_int32 *sizeP, afs_int32 depth)
1431 struct prentry tentry;
1432 struct prentryg *tentryg = (struct prentryg *)&tentry;
1434 struct contentry centry;
1440 int predictfound, predictflagged;
1445 if (!in_map(sg_flagged, -gid)) {
1447 fprintf(stderr, "GetListSG2: I have not yet searched for gid=%d\n",
1449 } else if (predictflagged = 1, in_map(sg_found, -gid)) {
1452 "GetListSG2: I have already searched for gid=%d, and predict success.\n",
1457 if (in_map(sg_flagged, -gid) && !in_map(sg_found, -gid)) {
1460 "GetListSG2: I have already searched for gid=%d, and predict failure.\n",
1469 temp = FindByID(at, gid);
1474 code = pr_ReadEntry(at, 0, temp, &tentry);
1478 fprintf(stderr, "GetListSG2: lookup for gid=%d [\n", gid);
1482 for (i = 0; i < SGSIZE; i++) {
1483 if (tentryg->supergroup[i] == PRBADID)
1485 if (tentryg->supergroup[i] == 0)
1489 fprintf(stderr, "via gid=%d, added %d\n", gid,
1490 e.tentryg.supergroup[i]);
1492 code = AddToPRList(alist, sizeP, tentryg->supergroup[i]);
1496 GetListSG2(at, tentryg->supergroup[i], alist, sizeP, depth - 1);
1501 nptr = tentryg->nextsg;
1504 /* look through cont entries */
1505 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1508 for (i = 0; i < COSIZE; i++) {
1509 if (centry.entries[i] == PRBADID)
1511 if (centry.entries[i] == 0)
1514 fprintf(stderr, "via gid=%d, added %d\n", gid,
1515 e.centry.entries[i]);
1517 code = AddToPRList(alist, sizeP, centry.entries[i]);
1520 code = GetListSG2(at, centry.entries[i], alist, sizeP, depth - 1);
1526 #ifndef AFS_PTHREAD_ENV
1533 fprintf(stderr, "] for gid %d, done [flag=%s]\n", gid,
1534 didsomething ? "TRUE" : "FALSE");
1535 if (predictflagged && didsomething != predictfound)
1536 fprintf(stderr, "**** for gid=%d, didsomething=%d predictfound=%d\n",
1537 didsomething, predictfound);
1540 sg_found = add_map(sg_found, -gid);
1542 sg_found = bic_map(sg_found, add_map(NIL_MAP, -gid));
1543 sg_flagged = add_map(sg_flagged, -gid);
1548 GetSGList(struct ubik_trans *at, struct prentry *tentry, prlist *alist)
1552 struct contentry centry;
1553 struct prentryg *tentryg;
1559 alist->prlist_val = 0;
1560 alist->prlist_len = 0;
1562 tentryg = (struct prentryg *)tentry;
1563 for (i = 0; i < SGSIZE; i++) {
1564 if (tentryg->supergroup[i] == PRBADID)
1566 if (tentryg->supergroup[i] == 0)
1568 code = AddToPRList(alist, &size, tentryg->supergroup[i]);
1573 nptr = tentryg->nextsg;
1575 /* look through cont entries */
1576 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1579 for (i = 0; i < COSIZE; i++) {
1580 if (centry.entries[i] == PRBADID)
1582 if (centry.entries[i] == 0)
1584 code = AddToPRList(alist, &size, centry.entries[i]);
1590 #ifndef AFS_PTHREAD_ENV
1597 #ifndef AFS_PTHREAD_ENV
1598 if (alist->prlist_len > 100)
1601 qsort((char *)alist->prlist_val, (int)alist->prlist_len,
1602 sizeof(afs_int32), IDCmp);
1605 #endif /* SUPERGROUPS */
1608 GetOwnedChain(struct ubik_trans *ut, afs_int32 *next, prlist *alist)
1611 struct prentry tentry;
1616 alist->prlist_val = 0;
1617 alist->prlist_len = 0;
1619 for (; *next; *next = ntohl(tentry.nextOwned)) {
1620 code = pr_Read(ut, 0, *next, &tentry, sizeof(tentry));
1623 code = AddToPRList(alist, &size, ntohl(tentry.id));
1624 if (alist->prlist_len >= PR_MAXGROUPS) {
1630 #ifndef AFS_PTHREAD_ENV
1636 #ifndef AFS_PTHREAD_ENV
1637 if (alist->prlist_len > 100)
1640 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1645 GetMax(struct ubik_trans *at, afs_int32 *uid, afs_int32 *gid)
1647 *uid = ntohl(cheader.maxID);
1648 *gid = ntohl(cheader.maxGroup);
1653 SetMax(struct ubik_trans *at, afs_int32 id, afs_int32 flag)
1657 cheader.maxGroup = htonl(id);
1659 pr_Write(at, 0, 16, (char *)&cheader.maxGroup,
1660 sizeof(cheader.maxGroup));
1664 cheader.maxID = htonl(id);
1666 pr_Write(at, 0, 20, (char *)&cheader.maxID,
1667 sizeof(cheader.maxID));
1675 UpdateCache(struct ubik_trans *tt, void *rock)
1679 code = pr_Read(tt, 0, 0, (char *)&cheader, sizeof(cheader));
1681 afs_com_err(whoami, code, "Couldn't read header");
1687 read_DbHeader(struct ubik_trans *tt)
1689 return ubik_CheckCache(tt, UpdateCache, NULL);
1695 * reads in db cache from ubik.
1697 * @param[in] ut ubik transaction
1698 * @param[out] rock opaque pointer to an int*, which on success will be set
1699 * to 1 if we need to build the database, or 0 if we do not
1701 * @return operation status
1705 Initdb_check(struct ubik_trans *tt, void *rock)
1707 int *build_rock = rock;
1711 len = sizeof(cheader);
1712 code = pr_Read(tt, 0, 0, (char *)&cheader, len);
1714 afs_com_err(whoami, code, "couldn't read header");
1717 if ((ntohl(cheader.version) == PRDBVERSION)
1718 && ntohl(cheader.headerSize) == sizeof(cheader)
1719 && ntohl(cheader.eofPtr) != 0
1720 && FindByID(tt, ANONYMOUSID) != 0) {
1721 /* database exists, so we don't have to build it */
1726 /* else we need to build a database */
1734 struct ubik_trans *tt;
1738 /* init the database. We'll try reading it, but if we're starting
1739 * from scratch, we'll have to do a write transaction. */
1741 pr_noAuth = afsconf_GetNoAuthFlag(prdir);
1743 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
1746 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
1748 ubik_AbortTrans(tt);
1752 code = ubik_CheckCache(tt, Initdb_check, &build);
1754 ubik_AbortTrans(tt);
1759 /* Only rebuild database if the db was deleted (the header is zero) */
1760 char *bp = (char *)&cheader;
1762 for (i = 0; i < sizeof(cheader); i++) {
1765 afs_com_err(whoami, code,
1766 "Can't rebuild database because it is not empty");
1775 code = ubik_EndTrans(tt);
1777 if (code || !build) {
1778 /* either we encountered an error, or we don't need to build the db */
1782 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
1786 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
1788 ubik_AbortTrans(tt);
1792 /* before doing a rebuild, check again that the dbase looks bad, because
1793 * the previous check was only under a ReadAny transaction, and there could
1794 * actually have been a good database out there. Now that we have a
1795 * real write transaction, make sure things are still bad.
1797 code = pr_Read(tt, 0, 0, (char *)&cheader, sizeof(cheader));
1799 afs_com_err(whoami, code, "couldn't read header");
1800 ubik_AbortTrans(tt);
1803 if ((ntohl(cheader.version) == PRDBVERSION)
1804 && ntohl(cheader.headerSize) == sizeof(cheader)
1805 && ntohl(cheader.eofPtr) != 0
1806 && FindByID(tt, ANONYMOUSID) != 0) {
1807 /* database exists, so we don't have to build it */
1808 code = ubik_EndTrans(tt);
1814 /* Initialize the database header */
1815 if ((code = set_header_word(tt, version, htonl(PRDBVERSION)))
1816 || (code = set_header_word(tt, headerSize, htonl(sizeof(cheader))))
1817 || (code = set_header_word(tt, eofPtr, cheader.headerSize))) {
1818 afs_com_err(whoami, code, "couldn't write header words");
1819 ubik_AbortTrans(tt);
1822 #define InitialGroup(id,name) do { \
1823 afs_int32 temp = (id); \
1824 afs_int32 flag = (id) < 0 ? PRGRP : 0; \
1825 code = CreateEntry \
1826 (tt, (name), &temp, /*idflag*/1, flag, SYSADMINID, SYSADMINID); \
1828 afs_com_err (whoami, code, "couldn't create %s with id %di.", \
1830 ubik_AbortTrans(tt); \
1835 InitialGroup(SYSADMINID, "system:administrators");
1836 InitialGroup(SYSBACKUPID, "system:backup");
1837 InitialGroup(ANYUSERID, "system:anyuser");
1838 InitialGroup(AUTHUSERID, "system:authuser");
1839 InitialGroup(SYSVIEWERID, "system:ptsviewers");
1840 InitialGroup(ANONYMOUSID, "anonymous");
1842 /* Well, we don't really want the max id set to anonymousid, so we'll set
1844 code = set_header_word(tt, maxID, 0); /* correct in any byte order */
1846 afs_com_err(whoami, code, "couldn't reset max id");
1847 ubik_AbortTrans(tt);
1851 code = ubik_EndTrans(tt);
1858 ChangeEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 cid, char *name, afs_int32 oid, afs_int32 newid)
1862 #if defined(SUPERGROUPS)
1866 struct contentry centry;
1868 struct prentry tentry, tent;
1871 char holder[PR_MAXNAMELEN];
1872 char temp[PR_MAXNAMELEN];
1873 char oldname[PR_MAXNAMELEN];
1876 memset(holder, 0, PR_MAXNAMELEN);
1877 memset(temp, 0, PR_MAXNAMELEN);
1878 loc = FindByID(at, aid);
1881 code = pr_ReadEntry(at, 0, loc, &tentry);
1884 if (restricted && !IsAMemberOf(at, cid, SYSADMINID))
1886 if (tentry.owner != cid && !IsAMemberOf(at, cid, SYSADMINID)
1887 && !IsAMemberOf(at, cid, tentry.owner) && !pr_noAuth)
1889 tentry.changeTime = time(0);
1891 /* we're actually trying to change the id */
1892 if (newid && (newid != aid)) {
1893 if (!IsAMemberOf(at, cid, SYSADMINID) && !pr_noAuth)
1896 pos = FindByID(at, newid);
1898 return PRIDEXIST; /* new id already in use! */
1899 if ((aid < 0 && newid > 0) || (aid > 0 && newid < 0))
1902 /* Should check that foreign users id to change to is good: inRange() */
1904 /* if new id is not in use, rehash things */
1905 code = RemoveFromIDHash(at, aid, &loc);
1906 if (code != PRSUCCESS)
1909 code = pr_WriteEntry(at, 0, loc, &tentry);
1912 code = AddToIDHash(at, tentry.id, loc);
1916 /* get current data */
1917 code = pr_ReadEntry(at, 0, loc, &tentry);
1921 #if defined(SUPERGROUPS)
1922 if (tentry.id > (afs_int32) ntohl(cheader.maxID))
1923 code = set_header_word(at, maxID, htonl(tentry.id));
1927 /* need to fix up: membership
1932 for (i = 0; i < PRSIZE; i++) {
1933 if (tentry.entries[i] == PRBADID)
1935 if (tentry.entries[i] == 0)
1937 if ((tentry.flags & PRGRP) && tentry.entries[i] < 0) { /* Supergroup */
1938 return 5; /* not yet, in short. */
1940 code = ChangeIDEntry(at, aid, newid, tentry.entries[i]);
1945 for (pos = ntohl(tentry.owned); pos; pos = nextpos) {
1946 code = pr_ReadEntry(at, 0, pos, &tent);
1950 nextpos = tent.nextOwned;
1951 code = pr_WriteEntry(at, 0, pos, &tent);
1957 #define centry (*(struct contentry*)&tent)
1958 code = pr_ReadCoEntry(at, 0, pos, ¢ry);
1959 if ((centry.id != aid)
1960 || !(centry.flags & PRCONT)) {
1962 "ChangeEntry: bad database aid=%d centry.id=%d .flags=%d\n",
1963 aid, centry.id, centry.flags);
1967 for (i = 0; i < COSIZE; i++) {
1968 if (centry.entries[i] == PRBADID)
1970 if (centry.entries[i] == 0)
1972 if ((centry.flags & PRGRP) && centry.entries[i] < 0) { /* Supergroup */
1973 return 5; /* not yet, in short. */
1975 code = ChangeIDEntry(at, aid, newid, centry.entries[i]);
1980 code = pr_WriteCoEntry(at, 0, pos, ¢ry);
1987 #else /* SUPERGROUPS */
1990 /* Also change the references from the membership list */
1991 for (i = 0; i < PRSIZE; i++) {
1992 if (tentry.entries[i] == PRBADID)
1994 if (tentry.entries[i] == 0)
1996 pos = FindByID(at, tentry.entries[i]);
1999 code = RemoveFromEntry(at, aid, tentry.entries[i]);
2002 code = pr_ReadEntry(at, 0, pos, &tent);
2005 code = AddToEntry(at, &tent, pos, newid);
2009 /* Look through cont entries too. This needs to be broken into
2010 * seperate transaction so that no one transaction becomes too
2011 * large to complete.
2013 for (nptr = tentry.next; nptr; nptr = centry.next) {
2014 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
2017 for (i = 0; i < COSIZE; i++) {
2018 if (centry.entries[i] == PRBADID)
2020 if (centry.entries[i] == 0)
2022 pos = FindByID(at, centry.entries[i]);
2025 code = RemoveFromEntry(at, aid, centry.entries[i]);
2028 code = pr_ReadEntry(at, 0, pos, &tent);
2031 code = AddToEntry(at, &tent, pos, newid);
2036 #endif /* SUPERGROUPS */
2039 atsign = strchr(tentry.name, '@'); /* check for foreign entry */
2041 /* Change the owner */
2042 if (oid && (oid != tentry.owner)) {
2043 /* only groups can have their owner's changed */
2044 if (!(tentry.flags & PRGRP))
2048 oldowner = tentry.owner;
2050 /* The entry must be written through first so Remove and Add routines
2051 * can operate on disk data */
2052 code = pr_WriteEntry(at, 0, loc, &tentry);
2056 /* switch owner chains */
2057 if (oldowner) /* if it has an owner */
2058 code = RemoveFromOwnerChain(at, tentry.id, oldowner);
2059 else /* must be an orphan */
2060 code = RemoveFromOrphan(at, tentry.id);
2063 code = AddToOwnerChain(at, tentry.id, tentry.owner);
2067 /* fix up the name */
2068 if (strlen(name) == 0)
2070 /* get current data */
2071 code = pr_ReadEntry(at, 0, loc, &tentry);
2076 /* Change the name, if name is a ptr to tentry.name then this name change
2077 * is due to a chown, otherwise caller has specified a new name */
2078 if ((name == tentry.name) || (*name && (strcmp(tentry.name, name) != 0))) {
2079 strncpy(oldname, tentry.name, PR_MAXNAMELEN);
2080 if (tentry.flags & PRGRP) {
2081 /* don't let foreign cell groups change name */
2084 code = CorrectGroupName(at, name, cid, tentry.owner, tentry.name);
2088 if (name == tentry.name) { /* owner fixup */
2089 if (strcmp(oldname, tentry.name) == 0)
2091 } else { /* new name, caller must be correct */
2092 if (strcmp(name, tentry.name) != 0)
2096 /* Allow a foreign name change only if the cellname part is
2101 newatsign = strchr(name, '@');
2102 if (newatsign != atsign) { /* if they are the same no problem */
2103 /*if the pointers are not equal the strings better be */
2104 if ((atsign == NULL) || (newatsign == NULL)
2105 || strcmp(atsign, newatsign))
2108 if (!CorrectUserName(name))
2112 pos = FindByName(at, name, &tent);
2115 code = RemoveFromNameHash(at, oldname, &loc);
2116 if (code != PRSUCCESS)
2118 strncpy(tentry.name, name, PR_MAXNAMELEN);
2119 code = pr_WriteEntry(at, 0, loc, &tentry);
2122 code = AddToNameHash(at, tentry.name, loc);
2123 if (code != PRSUCCESS)
2132 allocNextId(struct ubik_trans * at, struct prentry * cellEntry)
2134 /* Id's for foreign cell entries are constructed as follows:
2135 * The 16 low order bits are the group id of the cell and the
2136 * top 16 bits identify the particular users in that cell */
2139 afs_int32 cellid = ((ntohl(cellEntry->id)) & 0x0000ffff);
2141 id = (ntohl(cellEntry->nusers) + 1);
2142 while (FindByID(at, ((id << 16) | cellid))) {
2148 cellEntry->nusers = htonl(id);
2149 /* use the field nusers to keep
2150 * the next available id in that
2151 * foreign cell's group. Note :
2152 * It would seem more appropriate
2153 * to use ngroup for that and nusers
2154 * to enforce the quota, however pts
2155 * does not have an option to change
2156 * foreign users quota yet */
2158 id = (id << 16) | cellid;
2163 inRange(struct prentry *cellEntry, afs_int32 aid)
2165 afs_uint32 id, cellid, groupid;
2169 * The only thing that we want to make sure here is that
2170 * the id is in the legal range of this group. If it is
2171 * a duplicate we don't care since it will get caught
2172 * in a different check.
2175 cellid = aid & 0x0000ffff;
2176 groupid = (ntohl(cellEntry->id)) & 0x0000ffff;
2177 if (cellid != groupid)
2178 return 0; /* not in range */
2181 * if we got here we're ok but we need to update the nusers
2182 * field in order to get the id correct the next time that
2183 * we try to allocate it automatically
2187 if (id > ntohl(cellEntry->nusers))
2188 cellEntry->nusers = htonl(id);
2194 AddAuthGroup(struct prentry *tentry, prlist *alist, afs_int32 *size)
2196 if (!(strchr(tentry->name, '@')))
2197 return (AddToPRList(alist, size, AUTHUSERID));