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);
210 if (((*oid == 0) || (*oid == ANONYMOUSID)) && !admin)
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, ':');
246 /* let e.g. pt_util create groups with "wrong" names (like
247 * an orphan whose parent ID was reused). Check that they look like
248 * groups (with a colon) or otherwise are good user names. */
250 strcpy(cname, aname);
254 /* sysadmin can make groups w/o ':', but they must still look like
255 * legal user names. */
260 if (strlen(prefix) + strlen(suffix) >= PR_MAXNAMELEN)
262 strcpy(cname, prefix);
263 strcat(cname, suffix);
266 /* check for legal name with either group rules or user rules */
267 if ((suffix = strchr(cname, ':'))) {
268 /* check for confusing characters */
269 if (strchr(cname, '\n') || /* restrict so recreate can work */
270 strchr(suffix + 1, ':')) /* avoid multiple colons */
273 if (!CorrectUserName(cname))
280 AccessOK(struct ubik_trans *ut, afs_int32 cid, /* caller id */
281 struct prentry *tentry, /* object being accessed */
282 int mem, /* check membership in aid, if group */
283 int any) /* if set return true */
291 if (cid == SYSADMINID)
292 return 1; /* special case fileserver */
293 if (restricted && ((mem == PRP_ADD_MEM) || (mem == PRP_REMOVE_MEM)) && (any == 0))
296 flags = tentry->flags;
300 flags = oid = aid = 0;
302 if (!(flags & PRACCESS)) { /* provide default access */
304 flags |= prp_group_default;
306 flags |= prp_user_default;
312 if ((cid == oid) || IsAMemberOf(ut, cid, oid))
315 if (aid > 0) { /* checking on a user */
318 } else if (aid < 0) { /* checking on group */
319 if ((flags & mem) && IsAMemberOf(ut, cid, aid))
322 /* Allow members of SYSVIEWERID to get membership and status only */
323 if (((mem == PRP_STATUS_MEM) || (mem == PRP_MEMBER_MEM)
324 || (any == PRP_OWNED_ANY)) && (IsAMemberOf(ut, cid, SYSVIEWERID)))
326 if (IsAMemberOf(ut, cid, SYSADMINID))
328 return 0; /* no access */
332 CreateEntry(struct ubik_trans *at, char aname[PR_MAXNAMELEN], afs_int32 *aid, afs_int32 idflag, afs_int32 flag, afs_int32 oid, afs_int32 creator)
334 /* get and init a new entry */
337 struct prentry tentry, tent;
340 memset(&tentry, 0, sizeof(tentry));
343 code = CorrectGroupName(at, aname, creator, &oid, tentry.name);
346 if (strcmp(aname, tentry.name) != 0)
348 } else { /* non-group must not have colon */
349 if (!CorrectUserName(aname))
351 strcpy(tentry.name, aname);
354 if (FindByName(at, aname, &tent))
357 newEntry = AllocBlock(at);
360 tentry.createTime = time(0);
363 tentry.flags = PRGRP;
365 } else if (flag == 0) {
367 tentry.owner = SYSADMINID;
372 atsign = strchr(aname, '@');
374 /* A normal user or group. Pick an id for it */
378 code = AllocID(at, flag, &tentry.id);
379 if (code != PRSUCCESS)
382 } else if (flag & PRGRP) {
383 /* A foreign group. Its format must be AUTHUSER_GROUP@cellname
384 * Then pick an id for the group.
389 badFormat = strcmp(AUTHUSER_GROUP, aname);
397 code = AllocID(at, flag, &tentry.id);
398 if (code != PRSUCCESS)
402 /* A foreign user: <name>@<cell>. The foreign user is added to
403 * its representing group. It is
407 struct prentry centry;
409 /* To create the user <name>@<cell> the group AUTHUSER_GROUP@<cell>
412 if (asprintf(&cellGroup, "%s%s", AUTHUSER_GROUP, atsign) < 0)
414 pos = FindByName(at, cellGroup, ¢ry);
418 code = pr_Read(at, 0, pos, ¢ry, sizeof(centry));
422 /* cellid is the id of the group representing the cell */
423 tentry.cellid = ntohl(centry.id);
426 /* Check if id is good */
427 if (!inRange(¢ry, *aid))
431 /* Allocate an ID special for this foreign user. It is based
432 * on the representing group's id and nusers count.
434 tentry.id = allocNextId(at, ¢ry);
439 /* The foreign user will be added to the representing foreign
440 * group. The group can hold up to 30 entries.
442 if (!(ntohl(centry.flags) & PRQUOTA)) {
443 centry.flags = htonl(ntohl(centry.flags) | PRQUOTA);
444 centry.ngroups = htonl(30);
446 n = ntohl(centry.ngroups);
447 if ((n <= 0) && !pr_noAuth)
449 centry.ngroups = htonl(n - 1);
451 /* write updated entry for group */
452 code = pr_Write(at, 0, pos, ¢ry, sizeof(centry));
456 /* Now add the new user entry to the database */
457 tentry.creator = creator;
459 code = pr_WriteEntry(at, 0, newEntry, &tentry);
462 code = AddToIDHash(at, *aid, newEntry);
463 if (code != PRSUCCESS)
465 code = AddToNameHash(at, aname, newEntry);
466 if (code != PRSUCCESS)
468 if (inc_header_word(at, foreigncount, 1))
471 /* Now add the entry to the authuser group for this cell.
472 * We will reread the entries for the user and the group
473 * instead of modifying them before writing them in the
474 * previous steps. Although not very efficient, much simpler
476 pos = FindByID(at, tentry.cellid);
479 code = pr_ReadEntry(at, 0, pos, ¢ry);
482 code = AddToEntry(at, ¢ry, pos, *aid);
485 /* and now the user entry */
486 pos = FindByID(at, *aid);
489 code = pr_ReadEntry(at, 0, pos, &tentry);
492 code = AddToEntry(at, &tentry, pos, tentry.cellid);
499 /* Remember the largest group id or largest user id */
501 /* group ids are negative */
502 if (tentry.id < (afs_int32) ntohl(cheader.maxGroup)) {
503 code = set_header_word(at, maxGroup, htonl(tentry.id));
508 if (tentry.id > (afs_int32) ntohl(cheader.maxID)) {
509 code = set_header_word(at, maxID, htonl(tentry.id));
515 /* Charge the creator for this group */
517 afs_int32 loc = FindByID(at, creator);
518 struct prentry centry;
521 if (loc) { /* this should only fail during initialization */
522 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
526 /* If quota is uninitialized, do it */
527 if (!(ntohl(centry.flags) & PRQUOTA)) {
528 centry.flags = htonl(ntohl(centry.flags) | PRQUOTA);
529 centry.ngroups = centry.nusers = htonl(20);
532 /* Admins don't get charged for creating a group.
533 * If in noAuth mode, you get changed for it but you
534 * are still allowed to create as many groups as you want.
536 admin = ((creator == SYSADMINID)
537 || IsAMemberOf(at, creator, SYSADMINID));
539 if (ntohl(centry.ngroups) <= 0) {
543 centry.ngroups = htonl(ntohl(centry.ngroups) - 1);
547 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
552 /* Initialize the quota for the user. Groups don't have their
555 tentry.flags |= PRQUOTA;
556 tentry.ngroups = tentry.nusers = 20;
559 tentry.creator = creator;
561 code = pr_WriteEntry(at, 0, newEntry, &tentry);
564 code = AddToIDHash(at, *aid, newEntry);
565 if (code != PRSUCCESS)
567 code = AddToNameHash(at, aname, newEntry);
568 if (code != PRSUCCESS)
570 if (tentry.flags & PRGRP) {
571 code = AddToOwnerChain(at, tentry.id, oid);
575 if (tentry.flags & PRGRP) {
576 if (inc_header_word(at, groupcount, 1))
578 } else if (tentry.flags & PRINST) {
579 if (inc_header_word(at, instcount, 1))
582 if (inc_header_word(at, usercount, 1))
589 /* RemoveFromEntry - remove aid from bid's entries list, freeing a continuation
590 * entry if appropriate */
593 RemoveFromEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 bid)
596 struct prentry tentry;
597 struct contentry centry;
598 struct contentry hentry;
605 return PRINCONSISTENT;
606 memset(&hentry, 0, sizeof(hentry));
607 temp = FindByID(at, bid);
610 code = pr_ReadEntry(at, 0, temp, &tentry);
613 tentry.removeTime = time(0);
614 for (i = 0; i < PRSIZE; i++) {
615 if (tentry.entries[i] == aid) {
616 tentry.entries[i] = PRBADID;
618 code = pr_WriteEntry(at, 0, temp, &tentry);
623 if (tentry.entries[i] == 0) /* found end of list */
629 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
632 if ((centry.id != bid) || !(centry.flags & PRCONT))
634 for (i = 0; i < COSIZE; i++) {
635 if (centry.entries[i] == aid) {
636 centry.entries[i] = PRBADID;
637 for (j = 0; j < COSIZE; j++)
638 if (centry.entries[j] != PRBADID
639 && centry.entries[j] != 0)
641 if (j == COSIZE) { /* can free this block */
643 tentry.next = centry.next;
645 hentry.next = centry.next;
646 code = pr_WriteCoEntry(at, 0, hloc, &hentry);
650 code = FreeBlock(at, nptr);
653 } else { /* can't free it yet */
654 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
659 code = pr_WriteEntry(at, 0, temp, &tentry);
664 if (centry.entries[i] == 0)
666 } /* for all coentry slots */
669 memcpy(&hentry, ¢ry, sizeof(centry));
670 } /* while there are coentries */
674 #if defined(SUPERGROUPS)
675 /* ChangeIDEntry - remove aid from bid's entries list, freeing a continuation
676 * entry if appropriate */
679 ChangeIDEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 newid, afs_int32 bid)
682 struct prentry tentry;
683 struct contentry centry;
689 return PRINCONSISTENT;
690 temp = FindByID(at, bid);
694 code = pr_ReadEntry(at, 0, temp, &tentry);
697 for (i = 0; i < PRSIZE; i++) {
698 if (tentry.entries[i] == aid) {
699 tentry.entries[i] = newid;
700 code = pr_WriteEntry(at, 0, temp, &tentry);
705 if (tentry.entries[i] == 0) { /* found end of list */
712 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
715 if ((centry.id != bid) || !(centry.flags & PRCONT)) {
717 "ChangeIDEntry: bad database bid=%d centry.id=%d .flags=%d\n",
718 bid, centry.id, centry.flags);
721 for (i = 0; i < COSIZE; i++) {
722 if (centry.entries[i] == aid) {
723 centry.entries[i] = newid;
724 for (j = 0; j < COSIZE; j++)
725 if (centry.entries[j] != PRBADID
726 && centry.entries[j] != 0)
728 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
733 if (centry.entries[i] == 0) {
736 } /* for all coentry slots */
738 } /* while there are coentries */
742 /* #ifdef SUPERGROUPS */
743 /* RemoveFromSGEntry - remove aid from bid's supergroups list, freeing a
744 * continuation entry if appropriate */
747 RemoveFromSGEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 bid)
750 struct prentry tentry;
751 struct prentryg *tentryg;
752 struct contentry centry;
753 struct contentry hentry;
760 return PRINCONSISTENT;
761 memset(&hentry, 0, sizeof(hentry));
762 temp = FindByID(at, bid);
766 code = pr_ReadEntry(at, 0, temp, &tentry);
769 tentry.removeTime = time(NULL);
770 tentryg = (struct prentryg *)&tentry;
771 for (i = 0; i < SGSIZE; i++) {
772 if (tentryg->supergroup[i] == aid) {
773 tentryg->supergroup[i] = PRBADID;
775 code = pr_WriteEntry(at, 0, temp, &tentry);
780 if (tentryg->supergroup[i] == 0) { /* found end of list */
785 nptr = tentryg->nextsg;
787 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
790 if ((centry.id != bid) || !(centry.flags & PRCONT)) {
792 "ChangeIDEntry: bad database bid=%d centry.id=%d .flags=%d\n",
793 bid, centry.id, centry.flags);
796 for (i = 0; i < COSIZE; i++) {
797 if (centry.entries[i] == aid) {
798 centry.entries[i] = PRBADID;
799 for (j = 0; j < COSIZE; j++)
800 if (centry.entries[j] != PRBADID
801 && centry.entries[j] != 0)
803 if (j == COSIZE) { /* can free this block */
805 tentryg->nextsg = centry.next;
807 hentry.next = centry.next;
808 code = pr_WriteCoEntry(at, 0, hloc, &hentry);
812 code = FreeBlock(at, nptr);
815 } else { /* can't free it yet */
816 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
821 code = pr_WriteEntry(at, 0, temp, &tentry);
826 if (centry.entries[i] == 0) {
829 } /* for all coentry slots */
832 memcpy(&hentry, ¢ry, sizeof(centry));
833 } /* while there are coentries */
837 #endif /* SUPERGROUPS */
839 /* DeleteEntry - delete the entry in tentry at loc, removing it from all
840 * groups, putting groups owned by it on orphan chain, and freeing the space */
843 DeleteEntry(struct ubik_trans *at, struct prentry *tentry, afs_int32 loc)
846 struct contentry centry;
850 if (strchr(tentry->name, '@')) {
851 if (tentry->flags & PRGRP) {
852 /* If there are still foreign user accounts from that cell
853 * don't delete the group */
859 afs_int32 loc = FindByID(at, tentry->cellid);
860 struct prentry centry;
862 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
865 if (ntohl(centry.flags) & PRQUOTA) {
866 centry.ngroups = htonl(ntohl(centry.ngroups) + 1);
868 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
874 /* First remove the entire membership list */
875 for (i = 0; i < PRSIZE; i++) {
876 if (tentry->entries[i] == PRBADID)
878 if (tentry->entries[i] == 0)
880 #if defined(SUPERGROUPS)
881 if ((tentry->flags & PRGRP) && tentry->entries[i] < 0) /* Supergroup */
882 code = RemoveFromSGEntry(at, tentry->id, tentry->entries[i]);
885 code = RemoveFromEntry(at, tentry->id, tentry->entries[i]);
889 #if defined(SUPERGROUPS)
891 struct prentryg *tentryg = (struct prentryg *)tentry;
893 /* Then remove the entire supergroup list */
894 for (i = 0; i < SGSIZE; i++) {
895 if (tentryg->supergroup[i] == PRBADID)
897 if (tentryg->supergroup[i] == 0)
899 code = RemoveFromEntry(at, tentry->id, tentryg->supergroup[i]);
904 #endif /* SUPERGROUPS */
907 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
910 for (i = 0; i < COSIZE; i++) {
911 if (centry.entries[i] == PRBADID)
913 if (centry.entries[i] == 0)
915 code = RemoveFromEntry(at, tentry->id, centry.entries[i]);
919 code = FreeBlock(at, nptr); /* free continuation block */
925 /* Remove us from other's owned chain. Note that this will zero our owned
926 * field (on disk) so this step must follow the above step in case we are
927 * on our own owned list. */
928 if (tentry->flags & PRGRP) {
930 code = RemoveFromOwnerChain(at, tentry->id, tentry->owner);
934 code = RemoveFromOrphan(at, tentry->id);
940 code = RemoveFromIDHash(at, tentry->id, &loc);
941 if (code != PRSUCCESS)
943 code = RemoveFromNameHash(at, tentry->name, &loc);
944 if (code != PRSUCCESS)
947 if (tentry->flags & PRGRP) {
948 afs_int32 loc = FindByID(at, tentry->creator);
949 struct prentry centry;
953 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
956 admin = ((tentry->creator == SYSADMINID)
957 || IsAMemberOf(at, tentry->creator, SYSADMINID));
958 if (ntohl(centry.flags) & PRQUOTA) {
959 if (!(admin && (ntohl(centry.ngroups) >= 20))) {
960 centry.ngroups = htonl(ntohl(centry.ngroups) + 1);
963 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
969 if (tentry->flags & PRGRP) {
970 if (inc_header_word(at, groupcount, -1))
972 } else if (tentry->flags & PRINST) {
973 if (inc_header_word(at, instcount, -1))
976 if (strchr(tentry->name, '@')) {
977 if (inc_header_word(at, foreigncount, -1))
980 if (inc_header_word(at, usercount, -1))
984 code = FreeBlock(at, loc);
988 /* AddToEntry - add aid to entry's entries list, alloc'ing a continuation block
991 * Note the entry is written out by this routine. */
994 AddToEntry(struct ubik_trans *tt, struct prentry *entry, afs_int32 loc, afs_int32 aid)
998 struct contentry nentry;
999 struct contentry aentry;
1001 afs_int32 last; /* addr of last cont. block */
1002 afs_int32 first = 0;
1004 afs_int32 slot = -1;
1006 if (entry->id == aid)
1007 return PRINCONSISTENT;
1008 entry->addTime = time(0);
1009 for (i = 0; i < PRSIZE; i++) {
1010 if (entry->entries[i] == aid)
1012 if (entry->entries[i] == PRBADID) { /* remember this spot */
1015 } else if (entry->entries[i] == 0) { /* end of the line */
1026 code = pr_ReadCoEntry(tt, 0, nptr, &nentry);
1030 if (!(nentry.flags & PRCONT))
1032 for (i = 0; i < COSIZE; i++) {
1033 if (nentry.entries[i] == aid)
1035 if (nentry.entries[i] == PRBADID) {
1040 } else if (nentry.entries[i] == 0) {
1050 if (slot != -1) { /* we found a place */
1052 if (first) { /* place is in first block */
1053 entry->entries[slot] = aid;
1054 code = pr_WriteEntry(tt, 0, loc, entry);
1059 code = pr_WriteEntry(tt, 0, loc, entry);
1062 code = pr_ReadCoEntry(tt, 0, cloc, &aentry);
1065 aentry.entries[slot] = aid;
1066 code = pr_WriteCoEntry(tt, 0, cloc, &aentry);
1071 /* have to allocate a continuation block if we got here */
1072 nptr = AllocBlock(tt);
1074 /* then we should tack new block after last block in cont. chain */
1076 code = pr_WriteCoEntry(tt, 0, last, &nentry);
1082 memset(&aentry, 0, sizeof(aentry));
1083 aentry.flags |= PRCONT;
1084 aentry.id = entry->id;
1086 aentry.entries[0] = aid;
1087 code = pr_WriteCoEntry(tt, 0, nptr, &aentry);
1090 /* don't forget to update count, here! */
1092 code = pr_WriteEntry(tt, 0, loc, entry);
1097 #if defined(SUPERGROUPS)
1099 /* AddToSGEntry - add aid to entry's supergroup list, alloc'ing a
1100 * continuation block if needed.
1102 * Note the entry is written out by this routine. */
1105 AddToSGEntry(struct ubik_trans *tt, struct prentry *entry, afs_int32 loc, afs_int32 aid)
1109 struct contentry nentry;
1110 struct contentry aentry;
1111 struct prentryg *entryg;
1113 afs_int32 last; /* addr of last cont. block */
1114 afs_int32 first = 0;
1116 afs_int32 slot = -1;
1118 if (entry->id == aid)
1119 return PRINCONSISTENT;
1120 entry->addTime = time(NULL);
1121 entryg = (struct prentryg *)entry;
1122 for (i = 0; i < SGSIZE; i++) {
1123 if (entryg->supergroup[i] == aid)
1125 if (entryg->supergroup[i] == PRBADID) { /* remember this spot */
1128 } else if (entryg->supergroup[i] == 0) { /* end of the line */
1137 nptr = entryg->nextsg;
1139 code = pr_ReadCoEntry(tt, 0, nptr, &nentry);
1143 if (!(nentry.flags & PRCONT))
1145 for (i = 0; i < COSIZE; i++) {
1146 if (nentry.entries[i] == aid)
1148 if (nentry.entries[i] == PRBADID) {
1153 } else if (nentry.entries[i] == 0) {
1163 if (slot != -1) { /* we found a place */
1165 if (first) { /* place is in first block */
1166 entryg->supergroup[slot] = aid;
1167 code = pr_WriteEntry(tt, 0, loc, entry);
1172 code = pr_WriteEntry(tt, 0, loc, entry);
1175 code = pr_ReadCoEntry(tt, 0, cloc, &aentry);
1178 aentry.entries[slot] = aid;
1179 code = pr_WriteCoEntry(tt, 0, cloc, &aentry);
1184 /* have to allocate a continuation block if we got here */
1185 nptr = AllocBlock(tt);
1187 /* then we should tack new block after last block in cont. chain */
1189 code = pr_WriteCoEntry(tt, 0, last, &nentry);
1193 entryg->nextsg = nptr;
1195 memset(&aentry, 0, sizeof(aentry));
1196 aentry.flags |= PRCONT;
1197 aentry.id = entry->id;
1199 aentry.entries[0] = aid;
1200 code = pr_WriteCoEntry(tt, 0, nptr, &aentry);
1203 /* don't forget to update count, here! */
1205 code = pr_WriteEntry(tt, 0, loc, entry);
1209 #endif /* SUPERGROUPS */
1212 AddToPRList(prlist *alist, int *sizeP, afs_int32 id)
1217 if (alist->prlist_len >= *sizeP) {
1218 count = alist->prlist_len + 100;
1219 if (alist->prlist_val) {
1220 tmp = realloc(alist->prlist_val, count * sizeof(afs_int32));
1222 tmp = malloc(count * sizeof(afs_int32));
1226 alist->prlist_val = tmp;
1229 alist->prlist_val[alist->prlist_len++] = id;
1234 GetList(struct ubik_trans *at, struct prentry *tentry, prlist *alist, afs_int32 add)
1238 struct contentry centry;
1244 alist->prlist_val = 0;
1245 alist->prlist_len = 0;
1247 for (i = 0; i < PRSIZE; i++) {
1248 if (tentry->entries[i] == PRBADID)
1250 if (tentry->entries[i] == 0)
1252 code = AddToPRList(alist, &size, tentry->entries[i]);
1255 #if defined(SUPERGROUPS)
1258 code = GetListSG2(at, tentry->entries[i], alist, &size, depthsg);
1264 for (nptr = tentry->next; nptr != 0; nptr = centry.next) {
1265 /* look through cont entries */
1266 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1269 for (i = 0; i < COSIZE; i++) {
1270 if (centry.entries[i] == PRBADID)
1272 if (centry.entries[i] == 0)
1274 code = AddToPRList(alist, &size, centry.entries[i]);
1277 #if defined(SUPERGROUPS)
1280 code = GetListSG2(at, centry.entries[i], alist, &size, depthsg);
1286 #ifndef AFS_PTHREAD_ENV
1293 if (add) { /* this is for a CPS, so tack on appropriate stuff */
1294 if (tentry->id != ANONYMOUSID && tentry->id != ANYUSERID) {
1295 if ((code = AddToPRList(alist, &size, ANYUSERID))
1296 || (code = AddAuthGroup(tentry, alist, &size))
1297 || (code = AddToPRList(alist, &size, tentry->id)))
1300 if ((code = AddToPRList(alist, &size, ANYUSERID))
1301 || (code = AddToPRList(alist, &size, tentry->id)))
1305 #ifndef AFS_PTHREAD_ENV
1306 if (alist->prlist_len > 100)
1309 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1315 GetList2(struct ubik_trans *at, struct prentry *tentry, struct prentry *tentry2, prlist *alist, afs_int32 add)
1319 struct contentry centry;
1325 alist->prlist_val = 0;
1326 alist->prlist_len = 0;
1327 for (i = 0; i < PRSIZE; i++) {
1328 if (tentry->entries[i] == PRBADID)
1330 if (tentry->entries[i] == 0)
1332 code = AddToPRList(alist, &size, tentry->entries[i]);
1335 #if defined(SUPERGROUPS)
1338 code = GetListSG2(at, tentry->entries[i], alist, &size, depthsg);
1344 nptr = tentry->next;
1346 /* look through cont entries */
1347 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1350 for (i = 0; i < COSIZE; i++) {
1351 if (centry.entries[i] == PRBADID)
1353 if (centry.entries[i] == 0)
1355 code = AddToPRList(alist, &size, centry.entries[i]);
1358 #if defined(SUPERGROUPS)
1361 code = GetListSG2(at, centry.entries[i], alist, &size, depthsg);
1368 #ifndef AFS_PTHREAD_ENV
1375 for (i = 0; i < PRSIZE; i++) {
1376 if (tentry2->entries[i] == PRBADID)
1378 if (tentry2->entries[i] == 0)
1380 code = AddToPRList(alist, &size, tentry2->entries[i]);
1386 nptr = tentry2->next;
1388 /* look through cont entries */
1389 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1392 for (i = 0; i < COSIZE; i++) {
1393 if (centry.entries[i] == PRBADID)
1395 if (centry.entries[i] == 0)
1397 code = AddToPRList(alist, &size, centry.entries[i]);
1403 #ifndef AFS_PTHREAD_ENV
1410 if (add) { /* this is for a CPS, so tack on appropriate stuff */
1411 if (tentry->id != ANONYMOUSID && tentry->id != ANYUSERID) {
1412 if ((code = AddToPRList(alist, &size, ANYUSERID))
1413 || (code = AddToPRList(alist, &size, AUTHUSERID))
1414 || (code = AddToPRList(alist, &size, tentry->id)))
1417 if ((code = AddToPRList(alist, &size, ANYUSERID))
1418 || (code = AddToPRList(alist, &size, tentry->id)))
1422 #ifndef AFS_PTHREAD_ENV
1423 if (alist->prlist_len > 100)
1426 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1430 #if defined(SUPERGROUPS)
1433 GetListSG2(struct ubik_trans *at, afs_int32 gid, prlist *alist, afs_int32 *sizeP, afs_int32 depth)
1436 struct prentry tentry;
1437 struct prentryg *tentryg = (struct prentryg *)&tentry;
1439 struct contentry centry;
1445 int predictfound, predictflagged;
1450 if (!in_map(sg_flagged, -gid)) {
1452 fprintf(stderr, "GetListSG2: I have not yet searched for gid=%d\n",
1454 } else if (predictflagged = 1, in_map(sg_found, -gid)) {
1457 "GetListSG2: I have already searched for gid=%d, and predict success.\n",
1462 if (in_map(sg_flagged, -gid) && !in_map(sg_found, -gid)) {
1465 "GetListSG2: I have already searched for gid=%d, and predict failure.\n",
1474 temp = FindByID(at, gid);
1479 code = pr_ReadEntry(at, 0, temp, &tentry);
1483 fprintf(stderr, "GetListSG2: lookup for gid=%d [\n", gid);
1487 for (i = 0; i < SGSIZE; i++) {
1488 if (tentryg->supergroup[i] == PRBADID)
1490 if (tentryg->supergroup[i] == 0)
1494 fprintf(stderr, "via gid=%d, added %d\n", gid,
1495 e.tentryg.supergroup[i]);
1497 code = AddToPRList(alist, sizeP, tentryg->supergroup[i]);
1501 GetListSG2(at, tentryg->supergroup[i], alist, sizeP, depth - 1);
1506 nptr = tentryg->nextsg;
1509 /* look through cont entries */
1510 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1513 for (i = 0; i < COSIZE; i++) {
1514 if (centry.entries[i] == PRBADID)
1516 if (centry.entries[i] == 0)
1519 fprintf(stderr, "via gid=%d, added %d\n", gid,
1520 e.centry.entries[i]);
1522 code = AddToPRList(alist, sizeP, centry.entries[i]);
1525 code = GetListSG2(at, centry.entries[i], alist, sizeP, depth - 1);
1531 #ifndef AFS_PTHREAD_ENV
1538 fprintf(stderr, "] for gid %d, done [flag=%s]\n", gid,
1539 didsomething ? "TRUE" : "FALSE");
1540 if (predictflagged && didsomething != predictfound)
1541 fprintf(stderr, "**** for gid=%d, didsomething=%d predictfound=%d\n",
1542 didsomething, predictfound);
1545 sg_found = add_map(sg_found, -gid);
1547 sg_found = bic_map(sg_found, add_map(NIL_MAP, -gid));
1548 sg_flagged = add_map(sg_flagged, -gid);
1553 GetSGList(struct ubik_trans *at, struct prentry *tentry, prlist *alist)
1557 struct contentry centry;
1558 struct prentryg *tentryg;
1564 alist->prlist_val = 0;
1565 alist->prlist_len = 0;
1567 tentryg = (struct prentryg *)tentry;
1568 for (i = 0; i < SGSIZE; i++) {
1569 if (tentryg->supergroup[i] == PRBADID)
1571 if (tentryg->supergroup[i] == 0)
1573 code = AddToPRList(alist, &size, tentryg->supergroup[i]);
1578 nptr = tentryg->nextsg;
1580 /* look through cont entries */
1581 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1584 for (i = 0; i < COSIZE; i++) {
1585 if (centry.entries[i] == PRBADID)
1587 if (centry.entries[i] == 0)
1589 code = AddToPRList(alist, &size, centry.entries[i]);
1595 #ifndef AFS_PTHREAD_ENV
1602 #ifndef AFS_PTHREAD_ENV
1603 if (alist->prlist_len > 100)
1606 qsort((char *)alist->prlist_val, (int)alist->prlist_len,
1607 sizeof(afs_int32), IDCmp);
1610 #endif /* SUPERGROUPS */
1613 GetOwnedChain(struct ubik_trans *ut, afs_int32 *next, prlist *alist)
1616 struct prentry tentry;
1621 alist->prlist_val = 0;
1622 alist->prlist_len = 0;
1624 for (; *next; *next = ntohl(tentry.nextOwned)) {
1625 code = pr_Read(ut, 0, *next, &tentry, sizeof(tentry));
1628 code = AddToPRList(alist, &size, ntohl(tentry.id));
1629 if (alist->prlist_len >= PR_MAXGROUPS) {
1635 #ifndef AFS_PTHREAD_ENV
1641 #ifndef AFS_PTHREAD_ENV
1642 if (alist->prlist_len > 100)
1645 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1650 GetMax(struct ubik_trans *at, afs_int32 *uid, afs_int32 *gid)
1652 *uid = ntohl(cheader.maxID);
1653 *gid = ntohl(cheader.maxGroup);
1658 SetMax(struct ubik_trans *at, afs_int32 id, afs_int32 flag)
1662 cheader.maxGroup = htonl(id);
1664 pr_Write(at, 0, 16, (char *)&cheader.maxGroup,
1665 sizeof(cheader.maxGroup));
1669 cheader.maxID = htonl(id);
1671 pr_Write(at, 0, 20, (char *)&cheader.maxID,
1672 sizeof(cheader.maxID));
1680 UpdateCache(struct ubik_trans *tt, void *rock)
1684 code = pr_Read(tt, 0, 0, (char *)&cheader, sizeof(cheader));
1686 afs_com_err(whoami, code, "Couldn't read header");
1692 read_DbHeader(struct ubik_trans *tt)
1694 return ubik_CheckCache(tt, UpdateCache, NULL);
1700 * reads in db cache from ubik.
1702 * @param[in] ut ubik transaction
1703 * @param[out] rock opaque pointer to an int*, which on success will be set
1704 * to 1 if we need to build the database, or 0 if we do not
1706 * @return operation status
1710 Initdb_check(struct ubik_trans *tt, void *rock)
1712 int *build_rock = rock;
1716 len = sizeof(cheader);
1717 code = pr_Read(tt, 0, 0, (char *)&cheader, len);
1719 afs_com_err(whoami, code, "couldn't read header");
1722 if ((ntohl(cheader.version) == PRDBVERSION)
1723 && ntohl(cheader.headerSize) == sizeof(cheader)
1724 && ntohl(cheader.eofPtr) != 0
1725 && FindByID(tt, ANONYMOUSID) != 0) {
1726 /* database exists, so we don't have to build it */
1731 /* else we need to build a database */
1739 struct ubik_trans *tt;
1743 /* init the database. We'll try reading it, but if we're starting
1744 * from scratch, we'll have to do a write transaction. */
1746 pr_noAuth = afsconf_GetNoAuthFlag(prdir);
1748 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
1751 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
1753 ubik_AbortTrans(tt);
1757 code = ubik_CheckCache(tt, Initdb_check, &build);
1759 ubik_AbortTrans(tt);
1764 /* Only rebuild database if the db was deleted (the header is zero) */
1765 char *bp = (char *)&cheader;
1767 for (i = 0; i < sizeof(cheader); i++) {
1770 afs_com_err(whoami, code,
1771 "Can't rebuild database because it is not empty");
1780 code = ubik_EndTrans(tt);
1782 if (code || !build) {
1783 /* either we encountered an error, or we don't need to build the db */
1787 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
1791 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
1793 ubik_AbortTrans(tt);
1797 /* before doing a rebuild, check again that the dbase looks bad, because
1798 * the previous check was only under a ReadAny transaction, and there could
1799 * actually have been a good database out there. Now that we have a
1800 * real write transaction, make sure things are still bad.
1802 code = pr_Read(tt, 0, 0, (char *)&cheader, sizeof(cheader));
1804 afs_com_err(whoami, code, "couldn't read header");
1805 ubik_AbortTrans(tt);
1808 if ((ntohl(cheader.version) == PRDBVERSION)
1809 && ntohl(cheader.headerSize) == sizeof(cheader)
1810 && ntohl(cheader.eofPtr) != 0
1811 && FindByID(tt, ANONYMOUSID) != 0) {
1812 /* database exists, so we don't have to build it */
1813 code = ubik_EndTrans(tt);
1819 /* Initialize the database header */
1820 if ((code = set_header_word(tt, version, htonl(PRDBVERSION)))
1821 || (code = set_header_word(tt, headerSize, htonl(sizeof(cheader))))
1822 || (code = set_header_word(tt, eofPtr, cheader.headerSize))) {
1823 afs_com_err(whoami, code, "couldn't write header words");
1824 ubik_AbortTrans(tt);
1827 #define InitialGroup(id,name) do { \
1828 afs_int32 temp = (id); \
1829 afs_int32 flag = (id) < 0 ? PRGRP : 0; \
1830 code = CreateEntry \
1831 (tt, (name), &temp, /*idflag*/1, flag, SYSADMINID, SYSADMINID); \
1833 afs_com_err (whoami, code, "couldn't create %s with id %di.", \
1835 ubik_AbortTrans(tt); \
1840 InitialGroup(SYSADMINID, "system:administrators");
1841 InitialGroup(SYSBACKUPID, "system:backup");
1842 InitialGroup(ANYUSERID, "system:anyuser");
1843 InitialGroup(AUTHUSERID, "system:authuser");
1844 InitialGroup(SYSVIEWERID, "system:ptsviewers");
1845 InitialGroup(ANONYMOUSID, "anonymous");
1847 /* Well, we don't really want the max id set to anonymousid, so we'll set
1849 code = set_header_word(tt, maxID, 0); /* correct in any byte order */
1851 afs_com_err(whoami, code, "couldn't reset max id");
1852 ubik_AbortTrans(tt);
1856 code = ubik_EndTrans(tt);
1863 ChangeEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 cid, char *name, afs_int32 oid, afs_int32 newid)
1867 #if defined(SUPERGROUPS)
1871 struct contentry centry;
1873 struct prentry tentry, tent;
1876 char holder[PR_MAXNAMELEN];
1877 char temp[PR_MAXNAMELEN];
1878 char oldname[PR_MAXNAMELEN];
1881 memset(holder, 0, PR_MAXNAMELEN);
1882 memset(temp, 0, PR_MAXNAMELEN);
1883 loc = FindByID(at, aid);
1886 code = pr_ReadEntry(at, 0, loc, &tentry);
1889 if (restricted && !IsAMemberOf(at, cid, SYSADMINID))
1891 if (tentry.owner != cid && !IsAMemberOf(at, cid, SYSADMINID)
1892 && !IsAMemberOf(at, cid, tentry.owner) && !pr_noAuth)
1894 tentry.changeTime = time(0);
1896 /* we're actually trying to change the id */
1897 if (newid && (newid != aid)) {
1898 if (!IsAMemberOf(at, cid, SYSADMINID) && !pr_noAuth)
1901 pos = FindByID(at, newid);
1903 return PRIDEXIST; /* new id already in use! */
1904 if ((aid < 0 && newid > 0) || (aid > 0 && newid < 0))
1907 /* Should check that foreign users id to change to is good: inRange() */
1909 /* if new id is not in use, rehash things */
1910 code = RemoveFromIDHash(at, aid, &loc);
1911 if (code != PRSUCCESS)
1914 code = pr_WriteEntry(at, 0, loc, &tentry);
1917 code = AddToIDHash(at, tentry.id, loc);
1921 /* get current data */
1922 code = pr_ReadEntry(at, 0, loc, &tentry);
1926 #if defined(SUPERGROUPS)
1927 if (tentry.id > (afs_int32) ntohl(cheader.maxID))
1928 code = set_header_word(at, maxID, htonl(tentry.id));
1932 /* need to fix up: membership
1937 for (i = 0; i < PRSIZE; i++) {
1938 if (tentry.entries[i] == PRBADID)
1940 if (tentry.entries[i] == 0)
1942 if ((tentry.flags & PRGRP) && tentry.entries[i] < 0) { /* Supergroup */
1943 return 5; /* not yet, in short. */
1945 code = ChangeIDEntry(at, aid, newid, tentry.entries[i]);
1950 for (pos = ntohl(tentry.owned); pos; pos = nextpos) {
1951 code = pr_ReadEntry(at, 0, pos, &tent);
1955 nextpos = tent.nextOwned;
1956 code = pr_WriteEntry(at, 0, pos, &tent);
1962 #define centry (*(struct contentry*)&tent)
1963 code = pr_ReadCoEntry(at, 0, pos, ¢ry);
1964 if ((centry.id != aid)
1965 || !(centry.flags & PRCONT)) {
1967 "ChangeEntry: bad database aid=%d centry.id=%d .flags=%d\n",
1968 aid, centry.id, centry.flags);
1972 for (i = 0; i < COSIZE; i++) {
1973 if (centry.entries[i] == PRBADID)
1975 if (centry.entries[i] == 0)
1977 if ((centry.flags & PRGRP) && centry.entries[i] < 0) { /* Supergroup */
1978 return 5; /* not yet, in short. */
1980 code = ChangeIDEntry(at, aid, newid, centry.entries[i]);
1985 code = pr_WriteCoEntry(at, 0, pos, ¢ry);
1992 #else /* SUPERGROUPS */
1995 /* Also change the references from the membership list */
1996 for (i = 0; i < PRSIZE; i++) {
1997 if (tentry.entries[i] == PRBADID)
1999 if (tentry.entries[i] == 0)
2001 pos = FindByID(at, tentry.entries[i]);
2004 code = RemoveFromEntry(at, aid, tentry.entries[i]);
2007 code = pr_ReadEntry(at, 0, pos, &tent);
2010 code = AddToEntry(at, &tent, pos, newid);
2014 /* Look through cont entries too. This needs to be broken into
2015 * seperate transaction so that no one transaction becomes too
2016 * large to complete.
2018 for (nptr = tentry.next; nptr; nptr = centry.next) {
2019 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
2022 for (i = 0; i < COSIZE; i++) {
2023 if (centry.entries[i] == PRBADID)
2025 if (centry.entries[i] == 0)
2027 pos = FindByID(at, centry.entries[i]);
2030 code = RemoveFromEntry(at, aid, centry.entries[i]);
2033 code = pr_ReadEntry(at, 0, pos, &tent);
2036 code = AddToEntry(at, &tent, pos, newid);
2041 #endif /* SUPERGROUPS */
2044 atsign = strchr(tentry.name, '@'); /* check for foreign entry */
2046 /* Change the owner */
2047 if (oid && (oid != tentry.owner)) {
2048 /* only groups can have their owner's changed */
2049 if (!(tentry.flags & PRGRP))
2053 oldowner = tentry.owner;
2055 /* The entry must be written through first so Remove and Add routines
2056 * can operate on disk data */
2057 code = pr_WriteEntry(at, 0, loc, &tentry);
2061 /* switch owner chains */
2062 if (oldowner) /* if it has an owner */
2063 code = RemoveFromOwnerChain(at, tentry.id, oldowner);
2064 else /* must be an orphan */
2065 code = RemoveFromOrphan(at, tentry.id);
2068 code = AddToOwnerChain(at, tentry.id, tentry.owner);
2072 /* fix up the name */
2073 if (strlen(name) == 0)
2075 /* get current data */
2076 code = pr_ReadEntry(at, 0, loc, &tentry);
2081 /* Change the name, if name is a ptr to tentry.name then this name change
2082 * is due to a chown, otherwise caller has specified a new name */
2083 if ((name == tentry.name) || (*name && (strcmp(tentry.name, name) != 0))) {
2084 strncpy(oldname, tentry.name, PR_MAXNAMELEN);
2085 if (tentry.flags & PRGRP) {
2086 /* don't let foreign cell groups change name */
2089 code = CorrectGroupName(at, name, cid, &tentry.owner, tentry.name);
2093 if (name == tentry.name) { /* owner fixup */
2094 if (strcmp(oldname, tentry.name) == 0)
2096 } else { /* new name, caller must be correct */
2097 if (strcmp(name, tentry.name) != 0)
2101 /* Allow a foreign name change only if the cellname part is
2106 newatsign = strchr(name, '@');
2107 if (newatsign != atsign) { /* if they are the same no problem */
2108 /*if the pointers are not equal the strings better be */
2109 if ((atsign == NULL) || (newatsign == NULL)
2110 || strcmp(atsign, newatsign))
2113 if (!CorrectUserName(name))
2117 pos = FindByName(at, name, &tent);
2120 code = RemoveFromNameHash(at, oldname, &loc);
2121 if (code != PRSUCCESS)
2123 strncpy(tentry.name, name, PR_MAXNAMELEN);
2124 code = pr_WriteEntry(at, 0, loc, &tentry);
2127 code = AddToNameHash(at, tentry.name, loc);
2128 if (code != PRSUCCESS)
2137 allocNextId(struct ubik_trans * at, struct prentry * cellEntry)
2139 /* Id's for foreign cell entries are constructed as follows:
2140 * The 16 low order bits are the group id of the cell and the
2141 * top 16 bits identify the particular users in that cell */
2144 afs_int32 cellid = ((ntohl(cellEntry->id)) & 0x0000ffff);
2146 id = (ntohl(cellEntry->nusers) + 1);
2147 while (FindByID(at, ((id << 16) | cellid))) {
2153 cellEntry->nusers = htonl(id);
2154 /* use the field nusers to keep
2155 * the next available id in that
2156 * foreign cell's group. Note :
2157 * It would seem more appropriate
2158 * to use ngroup for that and nusers
2159 * to enforce the quota, however pts
2160 * does not have an option to change
2161 * foreign users quota yet */
2163 id = (id << 16) | cellid;
2168 inRange(struct prentry *cellEntry, afs_int32 aid)
2170 afs_uint32 id, cellid, groupid;
2174 * The only thing that we want to make sure here is that
2175 * the id is in the legal range of this group. If it is
2176 * a duplicate we don't care since it will get caught
2177 * in a different check.
2180 cellid = aid & 0x0000ffff;
2181 groupid = (ntohl(cellEntry->id)) & 0x0000ffff;
2182 if (cellid != groupid)
2183 return 0; /* not in range */
2186 * if we got here we're ok but we need to update the nusers
2187 * field in order to get the id correct the next time that
2188 * we try to allocate it automatically
2192 if (id > ntohl(cellEntry->nusers))
2193 cellEntry->nusers = htonl(id);
2199 AddAuthGroup(struct prentry *tentry, prlist *alist, afs_int32 *size)
2201 if (!(strchr(tentry->name, '@')))
2202 return (AddToPRList(alist, size, AUTHUSERID));