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));
449 /* Now add the new user entry to the database */
450 tentry.creator = creator;
452 code = pr_WriteEntry(at, 0, newEntry, &tentry);
455 code = AddToIDHash(at, *aid, newEntry);
456 if (code != PRSUCCESS)
458 code = AddToNameHash(at, aname, newEntry);
459 if (code != PRSUCCESS)
461 if (inc_header_word(at, foreigncount, 1))
464 /* Now add the entry to the authuser group for this cell.
465 * We will reread the entries for the user and the group
466 * instead of modifying them before writing them in the
467 * previous steps. Although not very efficient, much simpler
469 pos = FindByID(at, tentry.cellid);
472 code = pr_ReadEntry(at, 0, pos, ¢ry);
475 code = AddToEntry(at, ¢ry, pos, *aid);
478 /* and now the user entry */
479 pos = FindByID(at, *aid);
482 code = pr_ReadEntry(at, 0, pos, &tentry);
485 code = AddToEntry(at, &tentry, pos, tentry.cellid);
492 /* Remember the largest group id or largest user id */
494 /* group ids are negative */
495 if (tentry.id < (afs_int32) ntohl(cheader.maxGroup)) {
496 code = set_header_word(at, maxGroup, htonl(tentry.id));
501 if (tentry.id > (afs_int32) ntohl(cheader.maxID)) {
502 code = set_header_word(at, maxID, htonl(tentry.id));
508 /* Charge the creator for this group */
510 afs_int32 loc = FindByID(at, creator);
511 struct prentry centry;
514 if (loc) { /* this should only fail during initialization */
515 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
519 /* If quota is uninitialized, do it */
520 if (!(ntohl(centry.flags) & PRQUOTA)) {
521 centry.flags = htonl(ntohl(centry.flags) | PRQUOTA);
522 centry.ngroups = centry.nusers = htonl(20);
525 /* Admins don't get charged for creating a group.
526 * If in noAuth mode, you get changed for it but you
527 * are still allowed to create as many groups as you want.
529 admin = ((creator == SYSADMINID)
530 || IsAMemberOf(at, creator, SYSADMINID));
532 if (ntohl(centry.ngroups) <= 0) {
536 centry.ngroups = htonl(ntohl(centry.ngroups) - 1);
540 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
545 /* Initialize the quota for the user. Groups don't have their
548 tentry.flags |= PRQUOTA;
549 tentry.ngroups = tentry.nusers = 20;
552 tentry.creator = creator;
554 code = pr_WriteEntry(at, 0, newEntry, &tentry);
557 code = AddToIDHash(at, *aid, newEntry);
558 if (code != PRSUCCESS)
560 code = AddToNameHash(at, aname, newEntry);
561 if (code != PRSUCCESS)
563 if (tentry.flags & PRGRP) {
564 code = AddToOwnerChain(at, tentry.id, oid);
568 if (tentry.flags & PRGRP) {
569 if (inc_header_word(at, groupcount, 1))
571 } else if (tentry.flags & PRINST) {
572 if (inc_header_word(at, instcount, 1))
575 if (inc_header_word(at, usercount, 1))
582 /* RemoveFromEntry - remove aid from bid's entries list, freeing a continuation
583 * entry if appropriate */
586 RemoveFromEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 bid)
589 struct prentry tentry;
590 struct contentry centry;
591 struct contentry hentry;
598 return PRINCONSISTENT;
599 memset(&hentry, 0, sizeof(hentry));
600 temp = FindByID(at, bid);
603 code = pr_ReadEntry(at, 0, temp, &tentry);
606 tentry.removeTime = time(0);
607 for (i = 0; i < PRSIZE; i++) {
608 if (tentry.entries[i] == aid) {
609 tentry.entries[i] = PRBADID;
611 code = pr_WriteEntry(at, 0, temp, &tentry);
616 if (tentry.entries[i] == 0) /* found end of list */
622 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
625 if ((centry.id != bid) || !(centry.flags & PRCONT))
627 for (i = 0; i < COSIZE; i++) {
628 if (centry.entries[i] == aid) {
629 centry.entries[i] = PRBADID;
630 for (j = 0; j < COSIZE; j++)
631 if (centry.entries[j] != PRBADID
632 && centry.entries[j] != 0)
634 if (j == COSIZE) { /* can free this block */
636 tentry.next = centry.next;
638 hentry.next = centry.next;
639 code = pr_WriteCoEntry(at, 0, hloc, &hentry);
643 code = FreeBlock(at, nptr);
646 } else { /* can't free it yet */
647 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
652 code = pr_WriteEntry(at, 0, temp, &tentry);
657 if (centry.entries[i] == 0)
659 } /* for all coentry slots */
662 memcpy(&hentry, ¢ry, sizeof(centry));
663 } /* while there are coentries */
667 #if defined(SUPERGROUPS)
668 /* ChangeIDEntry - remove aid from bid's entries list, freeing a continuation
669 * entry if appropriate */
672 ChangeIDEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 newid, afs_int32 bid)
675 struct prentry tentry;
676 struct contentry centry;
682 return PRINCONSISTENT;
683 temp = FindByID(at, bid);
687 code = pr_ReadEntry(at, 0, temp, &tentry);
690 for (i = 0; i < PRSIZE; i++) {
691 if (tentry.entries[i] == aid) {
692 tentry.entries[i] = newid;
693 code = pr_WriteEntry(at, 0, temp, &tentry);
698 if (tentry.entries[i] == 0) { /* found end of list */
705 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
708 if ((centry.id != bid) || !(centry.flags & PRCONT)) {
710 "ChangeIDEntry: bad database bid=%d centry.id=%d .flags=%d\n",
711 bid, centry.id, centry.flags);
714 for (i = 0; i < COSIZE; i++) {
715 if (centry.entries[i] == aid) {
716 centry.entries[i] = newid;
717 for (j = 0; j < COSIZE; j++)
718 if (centry.entries[j] != PRBADID
719 && centry.entries[j] != 0)
721 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
726 if (centry.entries[i] == 0) {
729 } /* for all coentry slots */
731 } /* while there are coentries */
735 /* #ifdef SUPERGROUPS */
736 /* RemoveFromSGEntry - remove aid from bid's supergroups list, freeing a
737 * continuation entry if appropriate */
740 RemoveFromSGEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 bid)
743 struct prentry tentry;
744 struct prentryg *tentryg;
745 struct contentry centry;
746 struct contentry hentry;
753 return PRINCONSISTENT;
754 memset(&hentry, 0, sizeof(hentry));
755 temp = FindByID(at, bid);
759 code = pr_ReadEntry(at, 0, temp, &tentry);
762 tentry.removeTime = time(NULL);
763 tentryg = (struct prentryg *)&tentry;
764 for (i = 0; i < SGSIZE; i++) {
765 if (tentryg->supergroup[i] == aid) {
766 tentryg->supergroup[i] = PRBADID;
768 code = pr_WriteEntry(at, 0, temp, &tentry);
773 if (tentryg->supergroup[i] == 0) { /* found end of list */
778 nptr = tentryg->nextsg;
780 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
783 if ((centry.id != bid) || !(centry.flags & PRCONT)) {
785 "ChangeIDEntry: bad database bid=%d centry.id=%d .flags=%d\n",
786 bid, centry.id, centry.flags);
789 for (i = 0; i < COSIZE; i++) {
790 if (centry.entries[i] == aid) {
791 centry.entries[i] = PRBADID;
792 for (j = 0; j < COSIZE; j++)
793 if (centry.entries[j] != PRBADID
794 && centry.entries[j] != 0)
796 if (j == COSIZE) { /* can free this block */
798 tentryg->nextsg = centry.next;
800 hentry.next = centry.next;
801 code = pr_WriteCoEntry(at, 0, hloc, &hentry);
805 code = FreeBlock(at, nptr);
808 } else { /* can't free it yet */
809 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
814 code = pr_WriteEntry(at, 0, temp, &tentry);
819 if (centry.entries[i] == 0) {
822 } /* for all coentry slots */
825 memcpy((char *)¢ry, (char *)&hentry, sizeof(centry));
826 } /* while there are coentries */
830 #endif /* SUPERGROUPS */
832 /* DeleteEntry - delete the entry in tentry at loc, removing it from all
833 * groups, putting groups owned by it on orphan chain, and freeing the space */
836 DeleteEntry(struct ubik_trans *at, struct prentry *tentry, afs_int32 loc)
839 struct contentry centry;
843 if (strchr(tentry->name, '@')) {
844 if (tentry->flags & PRGRP) {
845 /* If there are still foreign user accounts from that cell
846 * don't delete the group */
852 afs_int32 loc = FindByID(at, tentry->cellid);
853 struct prentry centry;
855 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
858 if (ntohl(centry.flags) & PRQUOTA) {
859 centry.ngroups = htonl(ntohl(centry.ngroups) + 1);
861 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
867 /* First remove the entire membership list */
868 for (i = 0; i < PRSIZE; i++) {
869 if (tentry->entries[i] == PRBADID)
871 if (tentry->entries[i] == 0)
873 #if defined(SUPERGROUPS)
874 if ((tentry->flags & PRGRP) && tentry->entries[i] < 0) /* Supergroup */
875 code = RemoveFromSGEntry(at, tentry->id, tentry->entries[i]);
878 code = RemoveFromEntry(at, tentry->id, tentry->entries[i]);
882 #if defined(SUPERGROUPS)
884 struct prentryg *tentryg = (struct prentryg *)tentry;
886 /* Then remove the entire supergroup list */
887 for (i = 0; i < SGSIZE; i++) {
888 if (tentryg->supergroup[i] == PRBADID)
890 if (tentryg->supergroup[i] == 0)
892 code = RemoveFromEntry(at, tentry->id, tentryg->supergroup[i]);
897 #endif /* SUPERGROUPS */
900 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
903 for (i = 0; i < COSIZE; i++) {
904 if (centry.entries[i] == PRBADID)
906 if (centry.entries[i] == 0)
908 code = RemoveFromEntry(at, tentry->id, centry.entries[i]);
912 code = FreeBlock(at, nptr); /* free continuation block */
918 /* Remove us from other's owned chain. Note that this will zero our owned
919 * field (on disk) so this step must follow the above step in case we are
920 * on our own owned list. */
921 if (tentry->flags & PRGRP) {
923 code = RemoveFromOwnerChain(at, tentry->id, tentry->owner);
927 code = RemoveFromOrphan(at, tentry->id);
933 code = RemoveFromIDHash(at, tentry->id, &loc);
934 if (code != PRSUCCESS)
936 code = RemoveFromNameHash(at, tentry->name, &loc);
937 if (code != PRSUCCESS)
940 if (tentry->flags & PRGRP) {
941 afs_int32 loc = FindByID(at, tentry->creator);
942 struct prentry centry;
946 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
949 admin = ((tentry->creator == SYSADMINID)
950 || IsAMemberOf(at, tentry->creator, SYSADMINID));
951 if (ntohl(centry.flags) & PRQUOTA) {
952 if (!(admin && (ntohl(centry.ngroups) >= 20))) {
953 centry.ngroups = htonl(ntohl(centry.ngroups) + 1);
956 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
962 if (tentry->flags & PRGRP) {
963 if (inc_header_word(at, groupcount, -1))
965 } else if (tentry->flags & PRINST) {
966 if (inc_header_word(at, instcount, -1))
969 if (strchr(tentry->name, '@')) {
970 if (inc_header_word(at, foreigncount, -1))
973 if (inc_header_word(at, usercount, -1))
977 code = FreeBlock(at, loc);
981 /* AddToEntry - add aid to entry's entries list, alloc'ing a continuation block
984 * Note the entry is written out by this routine. */
987 AddToEntry(struct ubik_trans *tt, struct prentry *entry, afs_int32 loc, afs_int32 aid)
991 struct contentry nentry;
992 struct contentry aentry;
994 afs_int32 last; /* addr of last cont. block */
999 if (entry->id == aid)
1000 return PRINCONSISTENT;
1001 entry->addTime = time(0);
1002 for (i = 0; i < PRSIZE; i++) {
1003 if (entry->entries[i] == aid)
1005 if (entry->entries[i] == PRBADID) { /* remember this spot */
1008 } else if (entry->entries[i] == 0) { /* end of the line */
1019 code = pr_ReadCoEntry(tt, 0, nptr, &nentry);
1023 if (!(nentry.flags & PRCONT))
1025 for (i = 0; i < COSIZE; i++) {
1026 if (nentry.entries[i] == aid)
1028 if (nentry.entries[i] == PRBADID) {
1033 } else if (nentry.entries[i] == 0) {
1043 if (slot != -1) { /* we found a place */
1045 if (first) { /* place is in first block */
1046 entry->entries[slot] = aid;
1047 code = pr_WriteEntry(tt, 0, loc, entry);
1052 code = pr_WriteEntry(tt, 0, loc, entry);
1055 code = pr_ReadCoEntry(tt, 0, cloc, &aentry);
1058 aentry.entries[slot] = aid;
1059 code = pr_WriteCoEntry(tt, 0, cloc, &aentry);
1064 /* have to allocate a continuation block if we got here */
1065 nptr = AllocBlock(tt);
1067 /* then we should tack new block after last block in cont. chain */
1069 code = pr_WriteCoEntry(tt, 0, last, &nentry);
1075 memset(&aentry, 0, sizeof(aentry));
1076 aentry.flags |= PRCONT;
1077 aentry.id = entry->id;
1079 aentry.entries[0] = aid;
1080 code = pr_WriteCoEntry(tt, 0, nptr, &aentry);
1083 /* don't forget to update count, here! */
1085 code = pr_WriteEntry(tt, 0, loc, entry);
1090 #if defined(SUPERGROUPS)
1092 /* AddToSGEntry - add aid to entry's supergroup list, alloc'ing a
1093 * continuation block if needed.
1095 * Note the entry is written out by this routine. */
1098 AddToSGEntry(struct ubik_trans *tt, struct prentry *entry, afs_int32 loc, afs_int32 aid)
1102 struct contentry nentry;
1103 struct contentry aentry;
1104 struct prentryg *entryg;
1106 afs_int32 last; /* addr of last cont. block */
1107 afs_int32 first = 0;
1109 afs_int32 slot = -1;
1111 if (entry->id == aid)
1112 return PRINCONSISTENT;
1113 entry->addTime = time(NULL);
1114 entryg = (struct prentryg *)entry;
1115 for (i = 0; i < SGSIZE; i++) {
1116 if (entryg->supergroup[i] == aid)
1118 if (entryg->supergroup[i] == PRBADID) { /* remember this spot */
1121 } else if (entryg->supergroup[i] == 0) { /* end of the line */
1130 nptr = entryg->nextsg;
1132 code = pr_ReadCoEntry(tt, 0, nptr, &nentry);
1136 if (!(nentry.flags & PRCONT))
1138 for (i = 0; i < COSIZE; i++) {
1139 if (nentry.entries[i] == aid)
1141 if (nentry.entries[i] == PRBADID) {
1146 } else if (nentry.entries[i] == 0) {
1156 if (slot != -1) { /* we found a place */
1158 if (first) { /* place is in first block */
1159 entryg->supergroup[slot] = aid;
1160 code = pr_WriteEntry(tt, 0, loc, entry);
1165 code = pr_WriteEntry(tt, 0, loc, entry);
1168 code = pr_ReadCoEntry(tt, 0, cloc, &aentry);
1171 aentry.entries[slot] = aid;
1172 code = pr_WriteCoEntry(tt, 0, cloc, &aentry);
1177 /* have to allocate a continuation block if we got here */
1178 nptr = AllocBlock(tt);
1180 /* then we should tack new block after last block in cont. chain */
1182 code = pr_WriteCoEntry(tt, 0, last, &nentry);
1186 entryg->nextsg = nptr;
1188 memset(&aentry, 0, sizeof(aentry));
1189 aentry.flags |= PRCONT;
1190 aentry.id = entry->id;
1192 aentry.entries[0] = aid;
1193 code = pr_WriteCoEntry(tt, 0, nptr, &aentry);
1196 /* don't forget to update count, here! */
1198 code = pr_WriteEntry(tt, 0, loc, entry);
1202 #endif /* SUPERGROUPS */
1205 AddToPRList(prlist *alist, int *sizeP, afs_int32 id)
1210 if (alist->prlist_len >= *sizeP) {
1211 count = alist->prlist_len + 100;
1212 if (alist->prlist_val) {
1213 tmp = realloc(alist->prlist_val, count * sizeof(afs_int32));
1215 tmp = malloc(count * sizeof(afs_int32));
1219 alist->prlist_val = tmp;
1222 alist->prlist_val[alist->prlist_len++] = id;
1227 GetList(struct ubik_trans *at, struct prentry *tentry, prlist *alist, afs_int32 add)
1231 struct contentry centry;
1237 alist->prlist_val = 0;
1238 alist->prlist_len = 0;
1240 for (i = 0; i < PRSIZE; i++) {
1241 if (tentry->entries[i] == PRBADID)
1243 if (tentry->entries[i] == 0)
1245 code = AddToPRList(alist, &size, tentry->entries[i]);
1248 #if defined(SUPERGROUPS)
1251 code = GetListSG2(at, tentry->entries[i], alist, &size, depthsg);
1257 for (nptr = tentry->next; nptr != 0; nptr = centry.next) {
1258 /* look through cont entries */
1259 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1262 for (i = 0; i < COSIZE; i++) {
1263 if (centry.entries[i] == PRBADID)
1265 if (centry.entries[i] == 0)
1267 code = AddToPRList(alist, &size, centry.entries[i]);
1270 #if defined(SUPERGROUPS)
1273 code = GetListSG2(at, centry.entries[i], alist, &size, depthsg);
1279 #ifndef AFS_PTHREAD_ENV
1286 if (add) { /* this is for a CPS, so tack on appropriate stuff */
1287 if (tentry->id != ANONYMOUSID && tentry->id != ANYUSERID) {
1288 if ((code = AddToPRList(alist, &size, ANYUSERID))
1289 || (code = AddAuthGroup(tentry, alist, &size))
1290 || (code = AddToPRList(alist, &size, tentry->id)))
1293 if ((code = AddToPRList(alist, &size, ANYUSERID))
1294 || (code = AddToPRList(alist, &size, tentry->id)))
1298 #ifndef AFS_PTHREAD_ENV
1299 if (alist->prlist_len > 100)
1302 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1308 GetList2(struct ubik_trans *at, struct prentry *tentry, struct prentry *tentry2, prlist *alist, afs_int32 add)
1312 struct contentry centry;
1318 alist->prlist_val = 0;
1319 alist->prlist_len = 0;
1320 for (i = 0; i < PRSIZE; i++) {
1321 if (tentry->entries[i] == PRBADID)
1323 if (tentry->entries[i] == 0)
1325 code = AddToPRList(alist, &size, tentry->entries[i]);
1328 #if defined(SUPERGROUPS)
1331 code = GetListSG2(at, tentry->entries[i], alist, &size, depthsg);
1337 nptr = tentry->next;
1339 /* look through cont entries */
1340 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1343 for (i = 0; i < COSIZE; i++) {
1344 if (centry.entries[i] == PRBADID)
1346 if (centry.entries[i] == 0)
1348 code = AddToPRList(alist, &size, centry.entries[i]);
1351 #if defined(SUPERGROUPS)
1354 code = GetListSG2(at, centry.entries[i], alist, &size, depthsg);
1361 #ifndef AFS_PTHREAD_ENV
1368 for (i = 0; i < PRSIZE; i++) {
1369 if (tentry2->entries[i] == PRBADID)
1371 if (tentry2->entries[i] == 0)
1373 code = AddToPRList(alist, &size, tentry2->entries[i]);
1379 nptr = tentry2->next;
1381 /* look through cont entries */
1382 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1385 for (i = 0; i < COSIZE; i++) {
1386 if (centry.entries[i] == PRBADID)
1388 if (centry.entries[i] == 0)
1390 code = AddToPRList(alist, &size, centry.entries[i]);
1396 #ifndef AFS_PTHREAD_ENV
1403 if (add) { /* this is for a CPS, so tack on appropriate stuff */
1404 if (tentry->id != ANONYMOUSID && tentry->id != ANYUSERID) {
1405 if ((code = AddToPRList(alist, &size, ANYUSERID))
1406 || (code = AddToPRList(alist, &size, AUTHUSERID))
1407 || (code = AddToPRList(alist, &size, tentry->id)))
1410 if ((code = AddToPRList(alist, &size, ANYUSERID))
1411 || (code = AddToPRList(alist, &size, tentry->id)))
1415 #ifndef AFS_PTHREAD_ENV
1416 if (alist->prlist_len > 100)
1419 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1423 #if defined(SUPERGROUPS)
1426 GetListSG2(struct ubik_trans *at, afs_int32 gid, prlist *alist, afs_int32 *sizeP, afs_int32 depth)
1429 struct prentry tentry;
1430 struct prentryg *tentryg = (struct prentryg *)&tentry;
1432 struct contentry centry;
1438 int predictfound, predictflagged;
1443 if (!in_map(sg_flagged, -gid)) {
1445 fprintf(stderr, "GetListSG2: I have not yet searched for gid=%d\n",
1447 } else if (predictflagged = 1, in_map(sg_found, -gid)) {
1450 "GetListSG2: I have already searched for gid=%d, and predict success.\n",
1455 if (in_map(sg_flagged, -gid) && !in_map(sg_found, -gid)) {
1458 "GetListSG2: I have already searched for gid=%d, and predict failure.\n",
1467 temp = FindByID(at, gid);
1472 code = pr_ReadEntry(at, 0, temp, &tentry);
1476 fprintf(stderr, "GetListSG2: lookup for gid=%d [\n", gid);
1480 for (i = 0; i < SGSIZE; i++) {
1481 if (tentryg->supergroup[i] == PRBADID)
1483 if (tentryg->supergroup[i] == 0)
1487 fprintf(stderr, "via gid=%d, added %d\n", gid,
1488 e.tentryg.supergroup[i]);
1490 code = AddToPRList(alist, sizeP, tentryg->supergroup[i]);
1494 GetListSG2(at, tentryg->supergroup[i], alist, sizeP, depth - 1);
1499 nptr = tentryg->nextsg;
1502 /* look through cont entries */
1503 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1506 for (i = 0; i < COSIZE; i++) {
1507 if (centry.entries[i] == PRBADID)
1509 if (centry.entries[i] == 0)
1512 fprintf(stderr, "via gid=%d, added %d\n", gid,
1513 e.centry.entries[i]);
1515 code = AddToPRList(alist, sizeP, centry.entries[i]);
1518 code = GetListSG2(at, centry.entries[i], alist, sizeP, depth - 1);
1524 #ifndef AFS_PTHREAD_ENV
1531 fprintf(stderr, "] for gid %d, done [flag=%s]\n", gid,
1532 didsomething ? "TRUE" : "FALSE");
1533 if (predictflagged && didsomething != predictfound)
1534 fprintf(stderr, "**** for gid=%d, didsomething=%d predictfound=%d\n",
1535 didsomething, predictfound);
1538 sg_found = add_map(sg_found, -gid);
1540 sg_found = bic_map(sg_found, add_map(NIL_MAP, -gid));
1541 sg_flagged = add_map(sg_flagged, -gid);
1546 GetSGList(struct ubik_trans *at, struct prentry *tentry, prlist *alist)
1550 struct contentry centry;
1551 struct prentryg *tentryg;
1557 alist->prlist_val = 0;
1558 alist->prlist_len = 0;
1560 tentryg = (struct prentryg *)tentry;
1561 for (i = 0; i < SGSIZE; i++) {
1562 if (tentryg->supergroup[i] == PRBADID)
1564 if (tentryg->supergroup[i] == 0)
1566 code = AddToPRList(alist, &size, tentryg->supergroup[i]);
1571 nptr = tentryg->nextsg;
1573 /* look through cont entries */
1574 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1577 for (i = 0; i < COSIZE; i++) {
1578 if (centry.entries[i] == PRBADID)
1580 if (centry.entries[i] == 0)
1582 code = AddToPRList(alist, &size, centry.entries[i]);
1588 #ifndef AFS_PTHREAD_ENV
1595 #ifndef AFS_PTHREAD_ENV
1596 if (alist->prlist_len > 100)
1599 qsort((char *)alist->prlist_val, (int)alist->prlist_len,
1600 sizeof(afs_int32), IDCmp);
1603 #endif /* SUPERGROUPS */
1606 GetOwnedChain(struct ubik_trans *ut, afs_int32 *next, prlist *alist)
1609 struct prentry tentry;
1614 alist->prlist_val = 0;
1615 alist->prlist_len = 0;
1617 for (; *next; *next = ntohl(tentry.nextOwned)) {
1618 code = pr_Read(ut, 0, *next, &tentry, sizeof(tentry));
1621 code = AddToPRList(alist, &size, ntohl(tentry.id));
1622 if (alist->prlist_len >= PR_MAXGROUPS) {
1628 #ifndef AFS_PTHREAD_ENV
1634 #ifndef AFS_PTHREAD_ENV
1635 if (alist->prlist_len > 100)
1638 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1643 GetMax(struct ubik_trans *at, afs_int32 *uid, afs_int32 *gid)
1645 *uid = ntohl(cheader.maxID);
1646 *gid = ntohl(cheader.maxGroup);
1651 SetMax(struct ubik_trans *at, afs_int32 id, afs_int32 flag)
1655 cheader.maxGroup = htonl(id);
1657 pr_Write(at, 0, 16, (char *)&cheader.maxGroup,
1658 sizeof(cheader.maxGroup));
1662 cheader.maxID = htonl(id);
1664 pr_Write(at, 0, 20, (char *)&cheader.maxID,
1665 sizeof(cheader.maxID));
1673 UpdateCache(struct ubik_trans *tt, void *rock)
1677 code = pr_Read(tt, 0, 0, (char *)&cheader, sizeof(cheader));
1679 afs_com_err(whoami, code, "Couldn't read header");
1685 read_DbHeader(struct ubik_trans *tt)
1687 return ubik_CheckCache(tt, UpdateCache, NULL);
1693 * reads in db cache from ubik.
1695 * @param[in] ut ubik transaction
1696 * @param[out] rock opaque pointer to an int*, which on success will be set
1697 * to 1 if we need to build the database, or 0 if we do not
1699 * @return operation status
1703 Initdb_check(struct ubik_trans *tt, void *rock)
1705 int *build_rock = rock;
1709 len = sizeof(cheader);
1710 code = pr_Read(tt, 0, 0, (char *)&cheader, len);
1712 afs_com_err(whoami, code, "couldn't read header");
1715 if ((ntohl(cheader.version) == PRDBVERSION)
1716 && ntohl(cheader.headerSize) == sizeof(cheader)
1717 && ntohl(cheader.eofPtr) != 0
1718 && FindByID(tt, ANONYMOUSID) != 0) {
1719 /* database exists, so we don't have to build it */
1724 /* else we need to build a database */
1732 struct ubik_trans *tt;
1736 /* init the database. We'll try reading it, but if we're starting
1737 * from scratch, we'll have to do a write transaction. */
1739 pr_noAuth = afsconf_GetNoAuthFlag(prdir);
1741 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
1744 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
1746 ubik_AbortTrans(tt);
1750 code = ubik_CheckCache(tt, Initdb_check, &build);
1752 ubik_AbortTrans(tt);
1757 /* Only rebuild database if the db was deleted (the header is zero) */
1758 char *bp = (char *)&cheader;
1760 for (i = 0; i < sizeof(cheader); i++) {
1763 afs_com_err(whoami, code,
1764 "Can't rebuild database because it is not empty");
1773 code = ubik_EndTrans(tt);
1775 if (code || !build) {
1776 /* either we encountered an error, or we don't need to build the db */
1780 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
1784 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
1786 ubik_AbortTrans(tt);
1790 /* before doing a rebuild, check again that the dbase looks bad, because
1791 * the previous check was only under a ReadAny transaction, and there could
1792 * actually have been a good database out there. Now that we have a
1793 * real write transaction, make sure things are still bad.
1795 code = pr_Read(tt, 0, 0, (char *)&cheader, sizeof(cheader));
1797 afs_com_err(whoami, code, "couldn't read header");
1798 ubik_AbortTrans(tt);
1801 if ((ntohl(cheader.version) == PRDBVERSION)
1802 && ntohl(cheader.headerSize) == sizeof(cheader)
1803 && ntohl(cheader.eofPtr) != 0
1804 && FindByID(tt, ANONYMOUSID) != 0) {
1805 /* database exists, so we don't have to build it */
1806 code = ubik_EndTrans(tt);
1812 /* Initialize the database header */
1813 if ((code = set_header_word(tt, version, htonl(PRDBVERSION)))
1814 || (code = set_header_word(tt, headerSize, htonl(sizeof(cheader))))
1815 || (code = set_header_word(tt, eofPtr, cheader.headerSize))) {
1816 afs_com_err(whoami, code, "couldn't write header words");
1817 ubik_AbortTrans(tt);
1820 #define InitialGroup(id,name) do { \
1821 afs_int32 temp = (id); \
1822 afs_int32 flag = (id) < 0 ? PRGRP : 0; \
1823 code = CreateEntry \
1824 (tt, (name), &temp, /*idflag*/1, flag, SYSADMINID, SYSADMINID); \
1826 afs_com_err (whoami, code, "couldn't create %s with id %di.", \
1828 ubik_AbortTrans(tt); \
1833 InitialGroup(SYSADMINID, "system:administrators");
1834 InitialGroup(SYSBACKUPID, "system:backup");
1835 InitialGroup(ANYUSERID, "system:anyuser");
1836 InitialGroup(AUTHUSERID, "system:authuser");
1837 InitialGroup(SYSVIEWERID, "system:ptsviewers");
1838 InitialGroup(ANONYMOUSID, "anonymous");
1840 /* Well, we don't really want the max id set to anonymousid, so we'll set
1842 code = set_header_word(tt, maxID, 0); /* correct in any byte order */
1844 afs_com_err(whoami, code, "couldn't reset max id");
1845 ubik_AbortTrans(tt);
1849 code = ubik_EndTrans(tt);
1856 ChangeEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 cid, char *name, afs_int32 oid, afs_int32 newid)
1860 #if defined(SUPERGROUPS)
1864 struct contentry centry;
1866 struct prentry tentry, tent;
1869 char holder[PR_MAXNAMELEN];
1870 char temp[PR_MAXNAMELEN];
1871 char oldname[PR_MAXNAMELEN];
1874 memset(holder, 0, PR_MAXNAMELEN);
1875 memset(temp, 0, PR_MAXNAMELEN);
1876 loc = FindByID(at, aid);
1879 code = pr_ReadEntry(at, 0, loc, &tentry);
1882 if (restricted && !IsAMemberOf(at, cid, SYSADMINID))
1884 if (tentry.owner != cid && !IsAMemberOf(at, cid, SYSADMINID)
1885 && !IsAMemberOf(at, cid, tentry.owner) && !pr_noAuth)
1887 tentry.changeTime = time(0);
1889 /* we're actually trying to change the id */
1890 if (newid && (newid != aid)) {
1891 if (!IsAMemberOf(at, cid, SYSADMINID) && !pr_noAuth)
1894 pos = FindByID(at, newid);
1896 return PRIDEXIST; /* new id already in use! */
1897 if ((aid < 0 && newid > 0) || (aid > 0 && newid < 0))
1900 /* Should check that foreign users id to change to is good: inRange() */
1902 /* if new id is not in use, rehash things */
1903 code = RemoveFromIDHash(at, aid, &loc);
1904 if (code != PRSUCCESS)
1907 code = pr_WriteEntry(at, 0, loc, &tentry);
1910 code = AddToIDHash(at, tentry.id, loc);
1914 /* get current data */
1915 code = pr_ReadEntry(at, 0, loc, &tentry);
1919 #if defined(SUPERGROUPS)
1920 if (tentry.id > (afs_int32) ntohl(cheader.maxID))
1921 code = set_header_word(at, maxID, htonl(tentry.id));
1925 /* need to fix up: membership
1930 for (i = 0; i < PRSIZE; i++) {
1931 if (tentry.entries[i] == PRBADID)
1933 if (tentry.entries[i] == 0)
1935 if ((tentry.flags & PRGRP) && tentry.entries[i] < 0) { /* Supergroup */
1936 return 5; /* not yet, in short. */
1938 code = ChangeIDEntry(at, aid, newid, tentry.entries[i]);
1943 for (pos = ntohl(tentry.owned); pos; pos = nextpos) {
1944 code = pr_ReadEntry(at, 0, pos, &tent);
1948 nextpos = tent.nextOwned;
1949 code = pr_WriteEntry(at, 0, pos, &tent);
1955 #define centry (*(struct contentry*)&tent)
1956 code = pr_ReadCoEntry(at, 0, pos, ¢ry);
1957 if ((centry.id != aid)
1958 || !(centry.flags & PRCONT)) {
1960 "ChangeEntry: bad database aid=%d centry.id=%d .flags=%d\n",
1961 aid, centry.id, centry.flags);
1965 for (i = 0; i < COSIZE; i++) {
1966 if (centry.entries[i] == PRBADID)
1968 if (centry.entries[i] == 0)
1970 if ((centry.flags & PRGRP) && centry.entries[i] < 0) { /* Supergroup */
1971 return 5; /* not yet, in short. */
1973 code = ChangeIDEntry(at, aid, newid, centry.entries[i]);
1978 code = pr_WriteCoEntry(at, 0, pos, ¢ry);
1985 #else /* SUPERGROUPS */
1988 /* Also change the references from the membership list */
1989 for (i = 0; i < PRSIZE; i++) {
1990 if (tentry.entries[i] == PRBADID)
1992 if (tentry.entries[i] == 0)
1994 pos = FindByID(at, tentry.entries[i]);
1997 code = RemoveFromEntry(at, aid, tentry.entries[i]);
2000 code = pr_ReadEntry(at, 0, pos, &tent);
2003 code = AddToEntry(at, &tent, pos, newid);
2007 /* Look through cont entries too. This needs to be broken into
2008 * seperate transaction so that no one transaction becomes too
2009 * large to complete.
2011 for (nptr = tentry.next; nptr; nptr = centry.next) {
2012 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
2015 for (i = 0; i < COSIZE; i++) {
2016 if (centry.entries[i] == PRBADID)
2018 if (centry.entries[i] == 0)
2020 pos = FindByID(at, centry.entries[i]);
2023 code = RemoveFromEntry(at, aid, centry.entries[i]);
2026 code = pr_ReadEntry(at, 0, pos, &tent);
2029 code = AddToEntry(at, &tent, pos, newid);
2034 #endif /* SUPERGROUPS */
2037 atsign = strchr(tentry.name, '@'); /* check for foreign entry */
2039 /* Change the owner */
2040 if (oid && (oid != tentry.owner)) {
2041 /* only groups can have their owner's changed */
2042 if (!(tentry.flags & PRGRP))
2046 oldowner = tentry.owner;
2048 /* The entry must be written through first so Remove and Add routines
2049 * can operate on disk data */
2050 code = pr_WriteEntry(at, 0, loc, &tentry);
2054 /* switch owner chains */
2055 if (oldowner) /* if it has an owner */
2056 code = RemoveFromOwnerChain(at, tentry.id, oldowner);
2057 else /* must be an orphan */
2058 code = RemoveFromOrphan(at, tentry.id);
2061 code = AddToOwnerChain(at, tentry.id, tentry.owner);
2065 /* fix up the name */
2066 if (strlen(name) == 0)
2068 /* get current data */
2069 code = pr_ReadEntry(at, 0, loc, &tentry);
2074 /* Change the name, if name is a ptr to tentry.name then this name change
2075 * is due to a chown, otherwise caller has specified a new name */
2076 if ((name == tentry.name) || (*name && (strcmp(tentry.name, name) != 0))) {
2077 strncpy(oldname, tentry.name, PR_MAXNAMELEN);
2078 if (tentry.flags & PRGRP) {
2079 /* don't let foreign cell groups change name */
2082 code = CorrectGroupName(at, name, cid, tentry.owner, tentry.name);
2086 if (name == tentry.name) { /* owner fixup */
2087 if (strcmp(oldname, tentry.name) == 0)
2089 } else { /* new name, caller must be correct */
2090 if (strcmp(name, tentry.name) != 0)
2094 /* Allow a foreign name change only if the cellname part is
2099 newatsign = strchr(name, '@');
2100 if (newatsign != atsign) { /* if they are the same no problem */
2101 /*if the pointers are not equal the strings better be */
2102 if ((atsign == NULL) || (newatsign == NULL)
2103 || strcmp(atsign, newatsign))
2106 if (!CorrectUserName(name))
2110 pos = FindByName(at, name, &tent);
2113 code = RemoveFromNameHash(at, oldname, &loc);
2114 if (code != PRSUCCESS)
2116 strncpy(tentry.name, name, PR_MAXNAMELEN);
2117 code = pr_WriteEntry(at, 0, loc, &tentry);
2120 code = AddToNameHash(at, tentry.name, loc);
2121 if (code != PRSUCCESS)
2130 allocNextId(struct ubik_trans * at, struct prentry * cellEntry)
2132 /* Id's for foreign cell entries are constructed as follows:
2133 * The 16 low order bits are the group id of the cell and the
2134 * top 16 bits identify the particular users in that cell */
2137 afs_int32 cellid = ((ntohl(cellEntry->id)) & 0x0000ffff);
2139 id = (ntohl(cellEntry->nusers) + 1);
2140 while (FindByID(at, ((id << 16) | cellid))) {
2146 cellEntry->nusers = htonl(id);
2147 /* use the field nusers to keep
2148 * the next available id in that
2149 * foreign cell's group. Note :
2150 * It would seem more appropriate
2151 * to use ngroup for that and nusers
2152 * to enforce the quota, however pts
2153 * does not have an option to change
2154 * foreign users quota yet */
2156 id = (id << 16) | cellid;
2161 inRange(struct prentry *cellEntry, afs_int32 aid)
2163 afs_uint32 id, cellid, groupid;
2167 * The only thing that we want to make sure here is that
2168 * the id is in the legal range of this group. If it is
2169 * a duplicate we don't care since it will get caught
2170 * in a different check.
2173 cellid = aid & 0x0000ffff;
2174 groupid = (ntohl(cellEntry->id)) & 0x0000ffff;
2175 if (cellid != groupid)
2176 return 0; /* not in range */
2179 * if we got here we're ok but we need to update the nusers
2180 * field in order to get the id correct the next time that
2181 * we try to allocate it automatically
2185 if (id > ntohl(cellEntry->nusers))
2186 cellEntry->nusers = htonl(id);
2192 AddAuthGroup(struct prentry *tentry, prlist *alist, afs_int32 *size)
2194 if (!(strchr(tentry->name, '@')))
2195 return (AddToPRList(alist, size, AUTHUSERID));