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>
28 #include <sys/types.h>
33 #include <netinet/in.h>
39 #include <afs/com_err.h>
40 #include <afs/cellconfig.h>
43 #include "ptprototypes.h"
46 /* Foreign cells are represented by the group system:authuser@cell*/
47 #define AUTHUSER_GROUP "system:authuser"
49 extern int restricted;
50 extern struct ubik_dbase *dbase;
51 extern struct afsconf_dir *prdir;
54 static int inRange(struct prentry *cellEntry, afs_int32 aid);
55 static afs_int32 allocNextId(struct ubik_trans *, struct prentry *);
56 static int AddAuthGroup(struct prentry *tentry, prlist *alist, afs_int32 *size);
58 static char *whoami = "ptserver";
60 int prp_user_default = PRP_USER_DEFAULT;
61 int prp_group_default = PRP_GROUP_DEFAULT;
63 #if defined(SUPERGROUPS)
67 afs_int32 depthsg = 5; /* Maximum iterations used during IsAMemberOF */
68 afs_int32 GetListSG2(struct ubik_trans *at, afs_int32 gid, prlist * alist,
69 afs_int32 * sizeP, afs_int32 depth);
71 struct map *sg_flagged;
74 #define NIL_MAP ((struct map *) 0)
76 /* pt_mywrite hooks into the logic that writes ubik records to disk
77 * at a very low level. It invalidates mappings in sg_flagged/sg_found.
78 * By hoooking in at this level, we ensure that a ubik file reload
79 * invalidates our incore cache.
81 * We assert records, cheaders and everything else are 0 mod 64.
82 * So, we can always see the first 64 bytes of any record written.
83 * The stuff we're interested in (flags, id) are in the first 8 bytes.
84 * so we can always tell if we're writing a group record.
87 int (*pt_save_dbase_write)(struct ubik_dbase *, afs_int32, void *, afs_int32,
91 pt_mywrite(struct ubik_dbase *tdb, afs_int32 fno, void *bp, afs_int32 pos, afs_int32 count)
93 afs_uint32 headersize = ntohl(cheader.headerSize);
95 if (fno == 0 && pos + count > headersize) {
110 #define xPT(p,x) ((((struct prentry *)(p))->flags & htonl(PRTYPE)) == htonl(x))
113 fprintf(stderr, "Writing %d bytes of entry @ %#lx(+%d)\n", c,
115 else if (c == ENTRYSIZE)
117 "Writing %d bytes of entry @ %#lx (%d<%s>,%d)\n",
118 c, p, ntohl(((struct prentry *)cp)->flags),
119 xPT(cp,PRUSER) ? "user" : xPT(cp,PRFREE) ? "free" :
120 xPT(cp,PRGRP) ? "group" : xPT(cp,PRCONT) ? "cont" :
121 xPT(cp,PRCELL) ? "cell" : xPT(cp,PRFOREIGN) ? "foreign" :
122 xPT(cp,PRINST) ? "sub/super instance" : "?",
123 ntohl(((struct prentry *)cp)->id));
126 "Writing first %d bytes of entry @ %#lx (%d<%s>,%d)\n",
127 c, p, ntohl(((struct prentry *)cp)->flags),
128 xPT(cp,PRUSER) ? "user" : xPT(cp,PRFREE) ? "free" :
129 xPT(cp,PRGRP) ? "group" : xPT(cp,PRCONT) ? "cont" :
130 xPT(cp,PRCELL) ? "cell" : xPT(cp,PRFOREIGN) ? "foreign" :
131 xPT(cp,PRINST) ? "sub/super instance" : "?",
132 ntohl(((struct prentry *)cp)->id));
134 fprintf(stderr, "Writing %d bytes of entry @ %#lx\n", c, p);
136 if (!o && c >= 8 && xPT(cp,PRGRP)) {
138 if (in_map(sg_found, -ntohl(((struct prentry *)cp)->id)))
139 fprintf(stderr, "Unfound: Removing group %d\n",
140 ntohl(((struct prentry *)cp)->id));
141 if (in_map(sg_flagged, -ntohl(((struct prentry *)cp)->id)))
142 fprintf(stderr, "Unflag: Removing group %d\n",
143 ntohl(((struct prentry *)cp)->id));
147 add_map(NIL_MAP, -ntohl(((struct prentry *)cp)->id)));
150 add_map(NIL_MAP, -ntohl(((struct prentry *)cp)->id)));
158 return (*pt_save_dbase_write) (tdb, fno, bp, pos, count);
162 * this function attaches pt_mywrite. It's called once,
163 * just after ubik_ServerInit.
169 extern struct ubik_dbase *ubik_dbase;
170 if (ubik_dbase->write != pt_mywrite) {
171 pt_save_dbase_write = ubik_dbase->write;
172 ubik_dbase->write = pt_mywrite;
176 #endif /* SUPERGROUPS */
178 /* CorrectUserName - Check to make sure a user name is OK. It must not include
179 * either a colon (or it would look like a group) or a newline (which can
180 * confuse some ptdb code, depending on the format we're reading from).
181 * This is a predicate, so it return one if name is OK and zero if name is
185 CorrectUserName(char *name)
187 /* We accept foreign names, so we will deal with '@' later */
188 if (strchr(name, ':') || strchr(name, '\n'))
190 if (strlen(name) >= PR_MAXNAMELEN)
195 /* CorrectGroupName - Like the above but handles more complicated cases caused
196 * by including the ownership in the name. The interface works by calculating
197 * the correct name based on a given name and owner. This allows easy use by
198 * rename, which then compares the correct name with the requested new name. */
201 CorrectGroupName(struct ubik_trans *ut, char aname[PR_MAXNAMELEN], /* name for group */
202 afs_int32 cid, /* caller id */
203 afs_int32 oid, /* owner of group */
204 char cname[PR_MAXNAMELEN]) /* correct name for group */
208 char *prefix; /* ptr to group owner part */
209 char *suffix; /* ptr to group name part */
210 char name[PR_MAXNAMELEN]; /* correct name for group */
211 struct prentry tentry;
213 if (strlen(aname) >= PR_MAXNAMELEN)
215 admin = pr_noAuth || IsAMemberOf(ut, cid, SYSADMINID);
220 /* Determine the correct prefix for the name. */
221 if (oid == SYSADMINID)
224 afs_int32 loc = FindByID(ut, oid);
226 /* let admin create groups owned by non-existent ids (probably
227 * setting a group to own itself). Check that they look like
228 * groups (with a colon) or otherwise are good user names. */
230 strcpy(cname, aname);
235 code = pr_Read(ut, 0, loc, &tentry, sizeof(tentry));
238 if (ntohl(tentry.flags) & PRGRP) {
239 if ((tentry.count == 0) && !admin)
241 /* terminate prefix at colon if there is one */
242 if ((prefix = strchr(tentry.name, ':')))
245 prefix = tentry.name;
247 /* only sysadmin allow to use 'system:' prefix */
248 if ((strcmp(prefix, "system") == 0) && !admin)
251 strcpy(name, aname); /* in case aname & cname are same */
252 suffix = strchr(name, ':');
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));
342 if ((oid == 0) || (oid == ANONYMOUSID))
346 code = CorrectGroupName(at, aname, creator, oid, tentry.name);
349 if (strcmp(aname, tentry.name) != 0)
351 } else { /* non-group must not have colon */
352 if (!CorrectUserName(aname))
354 strcpy(tentry.name, aname);
357 if (FindByName(at, aname, &tent))
360 newEntry = AllocBlock(at);
363 #ifdef PR_REMEMBER_TIMES
364 tentry.createTime = time(0);
368 tentry.flags = PRGRP;
370 } else if (flag == 0) {
372 tentry.owner = SYSADMINID;
377 atsign = strchr(aname, '@');
379 /* A normal user or group. Pick an id for it */
383 code = AllocID(at, flag, &tentry.id);
384 if (code != PRSUCCESS)
387 } else if (flag & PRGRP) {
388 /* A foreign group. Its format must be AUTHUSER_GROUP@cellname
389 * Then pick an id for the group.
394 badFormat = strcmp(AUTHUSER_GROUP, aname);
402 code = AllocID(at, flag, &tentry.id);
403 if (code != PRSUCCESS)
407 /* A foreign user: <name>@<cell>. The foreign user is added to
408 * its representing group. It is
412 struct prentry centry;
414 /* To create the user <name>@<cell> the group AUTHUSER_GROUP@<cell>
418 (char *)malloc(strlen(AUTHUSER_GROUP) + strlen(atsign) + 1);
419 strcpy(cellGroup, AUTHUSER_GROUP);
420 strcat(cellGroup, atsign);
421 pos = FindByName(at, cellGroup, ¢ry);
425 code = pr_Read(at, 0, pos, ¢ry, sizeof(centry));
429 /* cellid is the id of the group representing the cell */
430 tentry.cellid = ntohl(centry.id);
433 /* Check if id is good */
434 if (!inRange(¢ry, *aid))
438 /* Allocate an ID special for this foreign user. It is based
439 * on the representing group's id and nusers count.
441 tentry.id = allocNextId(at, ¢ry);
446 /* The foreign user will be added to the representing foreign
447 * group. The group can hold up to 30 entries.
449 if (!(ntohl(centry.flags) & PRQUOTA)) {
450 centry.flags = htonl(ntohl(centry.flags) | PRQUOTA);
451 centry.ngroups = htonl(30);
453 n = ntohl(centry.ngroups);
454 if ((n <= 0) && !pr_noAuth)
456 centry.ngroups = htonl(n - 1);
458 /* write updated entry for group */
459 code = pr_Write(at, 0, pos, ¢ry, sizeof(centry));
461 /* Now add the new user entry to the database */
462 tentry.creator = creator;
464 code = pr_WriteEntry(at, 0, newEntry, &tentry);
467 code = AddToIDHash(at, *aid, newEntry);
468 if (code != PRSUCCESS)
470 code = AddToNameHash(at, aname, newEntry);
471 if (code != PRSUCCESS)
473 if (inc_header_word(at, foreigncount, 1))
476 /* Now add the entry to the authuser group for this cell.
477 * We will reread the entries for the user and the group
478 * instead of modifying them before writing them in the
479 * previous steps. Although not very efficient, much simpler
481 pos = FindByID(at, tentry.cellid);
484 code = pr_ReadEntry(at, 0, pos, ¢ry);
487 code = AddToEntry(at, ¢ry, pos, *aid);
490 /* and now the user entry */
491 pos = FindByID(at, *aid);
494 code = pr_ReadEntry(at, 0, pos, &tentry);
497 code = AddToEntry(at, &tentry, pos, tentry.cellid);
504 /* Remember the largest group id or largest user id */
506 /* group ids are negative */
507 if (tentry.id < (afs_int32) ntohl(cheader.maxGroup)) {
508 code = set_header_word(at, maxGroup, htonl(tentry.id));
513 if (tentry.id > (afs_int32) ntohl(cheader.maxID)) {
514 code = set_header_word(at, maxID, htonl(tentry.id));
520 /* Charge the creator for this group */
522 afs_int32 loc = FindByID(at, creator);
523 struct prentry centry;
526 if (loc) { /* this should only fail during initialization */
527 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
531 /* If quota is uninitialized, do it */
532 if (!(ntohl(centry.flags) & PRQUOTA)) {
533 centry.flags = htonl(ntohl(centry.flags) | PRQUOTA);
534 centry.ngroups = centry.nusers = htonl(20);
537 /* Admins don't get charged for creating a group.
538 * If in noAuth mode, you get changed for it but you
539 * are still allowed to create as many groups as you want.
541 admin = ((creator == SYSADMINID)
542 || IsAMemberOf(at, creator, SYSADMINID));
544 if (ntohl(centry.ngroups) <= 0) {
548 centry.ngroups = htonl(ntohl(centry.ngroups) - 1);
552 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
557 /* Initialize the quota for the user. Groups don't have their
560 tentry.flags |= PRQUOTA;
561 tentry.ngroups = tentry.nusers = 20;
564 tentry.creator = creator;
566 code = pr_WriteEntry(at, 0, newEntry, &tentry);
569 code = AddToIDHash(at, *aid, newEntry);
570 if (code != PRSUCCESS)
572 code = AddToNameHash(at, aname, newEntry);
573 if (code != PRSUCCESS)
575 if (tentry.flags & PRGRP) {
576 code = AddToOwnerChain(at, tentry.id, oid);
580 if (tentry.flags & PRGRP) {
581 if (inc_header_word(at, groupcount, 1))
583 } else if (tentry.flags & PRINST) {
584 if (inc_header_word(at, instcount, 1))
587 if (inc_header_word(at, usercount, 1))
594 /* RemoveFromEntry - remove aid from bid's entries list, freeing a continuation
595 * entry if appropriate */
598 RemoveFromEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 bid)
601 struct prentry tentry;
602 struct contentry centry;
603 struct contentry hentry;
610 return PRINCONSISTENT;
611 memset(&hentry, 0, sizeof(hentry));
612 temp = FindByID(at, bid);
615 code = pr_ReadEntry(at, 0, temp, &tentry);
618 #ifdef PR_REMEMBER_TIMES
619 tentry.removeTime = time(0);
621 for (i = 0; i < PRSIZE; i++) {
622 if (tentry.entries[i] == aid) {
623 tentry.entries[i] = PRBADID;
625 code = pr_WriteEntry(at, 0, temp, &tentry);
630 if (tentry.entries[i] == 0) /* found end of list */
636 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
639 if ((centry.id != bid) || !(centry.flags & PRCONT))
641 for (i = 0; i < COSIZE; i++) {
642 if (centry.entries[i] == aid) {
643 centry.entries[i] = PRBADID;
644 for (j = 0; j < COSIZE; j++)
645 if (centry.entries[j] != PRBADID
646 && centry.entries[j] != 0)
648 if (j == COSIZE) { /* can free this block */
650 tentry.next = centry.next;
652 hentry.next = centry.next;
653 code = pr_WriteCoEntry(at, 0, hloc, &hentry);
657 code = FreeBlock(at, nptr);
660 } else { /* can't free it yet */
661 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
666 code = pr_WriteEntry(at, 0, temp, &tentry);
671 if (centry.entries[i] == 0)
673 } /* for all coentry slots */
676 memcpy(&hentry, ¢ry, sizeof(centry));
677 } /* while there are coentries */
681 #if defined(SUPERGROUPS)
682 /* ChangeIDEntry - remove aid from bid's entries list, freeing a continuation
683 * entry if appropriate */
686 ChangeIDEntry(register struct ubik_trans *at, register afs_int32 aid, afs_int32 newid, register afs_int32 bid)
688 register afs_int32 code;
689 struct prentry tentry;
690 struct contentry centry;
696 return PRINCONSISTENT;
697 temp = FindByID(at, bid);
701 code = pr_ReadEntry(at, 0, temp, &tentry);
704 for (i = 0; i < PRSIZE; i++) {
705 if (tentry.entries[i] == aid) {
706 tentry.entries[i] = newid;
707 code = pr_WriteEntry(at, 0, temp, &tentry);
712 if (tentry.entries[i] == 0) { /* found end of list */
719 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
722 if ((centry.id != bid) || !(centry.flags & PRCONT)) {
724 "ChangeIDEntry: bad database bid=%d centry.id=%d .flags=%d\n",
725 bid, centry.id, centry.flags);
728 for (i = 0; i < COSIZE; i++) {
729 if (centry.entries[i] == aid) {
730 centry.entries[i] = newid;
731 for (j = 0; j < COSIZE; j++)
732 if (centry.entries[j] != PRBADID
733 && centry.entries[j] != 0)
735 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
740 if (centry.entries[i] == 0) {
743 } /* for all coentry slots */
745 } /* while there are coentries */
749 /* #ifdef SUPERGROUPS */
750 /* RemoveFromSGEntry - remove aid from bid's supergroups list, freeing a
751 * continuation entry if appropriate */
754 RemoveFromSGEntry(register struct ubik_trans *at, register afs_int32 aid, register afs_int32 bid)
756 register afs_int32 code;
757 struct prentry tentry;
758 struct prentryg *tentryg;
759 struct contentry centry;
760 struct contentry hentry;
767 return PRINCONSISTENT;
768 memset(&hentry, 0, sizeof(hentry));
769 temp = FindByID(at, bid);
773 code = pr_ReadEntry(at, 0, temp, &tentry);
776 #ifdef PR_REMEMBER_TIMES
777 tentry.removeTime = time(NULL);
779 tentryg = (struct prentryg *)&tentry;
780 for (i = 0; i < SGSIZE; i++) {
781 if (tentryg->supergroup[i] == aid) {
782 tentryg->supergroup[i] = PRBADID;
784 code = pr_WriteEntry(at, 0, temp, &tentry);
789 if (tentryg->supergroup[i] == 0) { /* found end of list */
794 nptr = tentryg->nextsg;
796 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
799 if ((centry.id != bid) || !(centry.flags & PRCONT)) {
801 "ChangeIDEntry: bad database bid=%d centry.id=%d .flags=%d\n",
802 bid, centry.id, centry.flags);
805 for (i = 0; i < COSIZE; i++) {
806 if (centry.entries[i] == aid) {
807 centry.entries[i] = PRBADID;
808 for (j = 0; j < COSIZE; j++)
809 if (centry.entries[j] != PRBADID
810 && centry.entries[j] != 0)
812 if (j == COSIZE) { /* can free this block */
814 tentryg->nextsg = centry.next;
816 hentry.next = centry.next;
817 code = pr_WriteCoEntry(at, 0, hloc, &hentry);
821 code = FreeBlock(at, nptr);
824 } else { /* can't free it yet */
825 code = pr_WriteCoEntry(at, 0, nptr, ¢ry);
830 code = pr_WriteEntry(at, 0, temp, &tentry);
835 if (centry.entries[i] == 0) {
838 } /* for all coentry slots */
841 memcpy((char *)¢ry, (char *)&hentry, sizeof(centry));
842 } /* while there are coentries */
846 #endif /* SUPERGROUPS */
848 /* DeleteEntry - delete the entry in tentry at loc, removing it from all
849 * groups, putting groups owned by it on orphan chain, and freeing the space */
852 DeleteEntry(struct ubik_trans *at, struct prentry *tentry, afs_int32 loc)
855 struct contentry centry;
859 if (strchr(tentry->name, '@')) {
860 if (tentry->flags & PRGRP) {
861 /* If there are still foreign user accounts from that cell
862 * don't delete the group */
868 afs_int32 loc = FindByID(at, tentry->cellid);
869 struct prentry centry;
871 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
874 if (ntohl(centry.flags) & PRQUOTA) {
875 centry.ngroups = htonl(ntohl(centry.ngroups) + 1);
877 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
883 /* First remove the entire membership list */
884 for (i = 0; i < PRSIZE; i++) {
885 if (tentry->entries[i] == PRBADID)
887 if (tentry->entries[i] == 0)
889 #if defined(SUPERGROUPS)
890 if ((tentry->flags & PRGRP) && tentry->entries[i] < 0) /* Supergroup */
891 code = RemoveFromSGEntry(at, tentry->id, tentry->entries[i]);
894 code = RemoveFromEntry(at, tentry->id, tentry->entries[i]);
898 #if defined(SUPERGROUPS)
900 struct prentryg *tentryg = (struct prentryg *)tentry;
902 /* Then remove the entire supergroup list */
903 for (i = 0; i < SGSIZE; i++) {
904 if (tentryg->supergroup[i] == PRBADID)
906 if (tentryg->supergroup[i] == 0)
908 code = RemoveFromEntry(at, tentry->id, tentryg->supergroup[i]);
913 #endif /* SUPERGROUPS */
916 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
919 for (i = 0; i < COSIZE; i++) {
920 if (centry.entries[i] == PRBADID)
922 if (centry.entries[i] == 0)
924 code = RemoveFromEntry(at, tentry->id, centry.entries[i]);
928 code = FreeBlock(at, nptr); /* free continuation block */
934 /* Remove us from other's owned chain. Note that this will zero our owned
935 * field (on disk) so this step must follow the above step in case we are
936 * on our own owned list. */
937 if (tentry->flags & PRGRP) {
939 code = RemoveFromOwnerChain(at, tentry->id, tentry->owner);
943 code = RemoveFromOrphan(at, tentry->id);
949 code = RemoveFromIDHash(at, tentry->id, &loc);
950 if (code != PRSUCCESS)
952 code = RemoveFromNameHash(at, tentry->name, &loc);
953 if (code != PRSUCCESS)
956 if (tentry->flags & PRGRP) {
957 afs_int32 loc = FindByID(at, tentry->creator);
958 struct prentry centry;
962 code = pr_Read(at, 0, loc, ¢ry, sizeof(centry));
965 admin = ((tentry->creator == SYSADMINID)
966 || IsAMemberOf(at, tentry->creator, SYSADMINID));
967 if (ntohl(centry.flags) & PRQUOTA) {
968 if (!(admin && (ntohl(centry.ngroups) >= 20))) {
969 centry.ngroups = htonl(ntohl(centry.ngroups) + 1);
972 code = pr_Write(at, 0, loc, ¢ry, sizeof(centry));
978 if (tentry->flags & PRGRP) {
979 if (inc_header_word(at, groupcount, -1))
981 } else if (tentry->flags & PRINST) {
982 if (inc_header_word(at, instcount, -1))
985 if (strchr(tentry->name, '@')) {
986 if (inc_header_word(at, foreigncount, -1))
989 if (inc_header_word(at, usercount, -1))
993 code = FreeBlock(at, loc);
997 /* AddToEntry - add aid to entry's entries list, alloc'ing a continuation block
1000 * Note the entry is written out by this routine. */
1003 AddToEntry(struct ubik_trans *tt, struct prentry *entry, afs_int32 loc, afs_int32 aid)
1007 struct contentry nentry;
1008 struct contentry aentry;
1010 afs_int32 last; /* addr of last cont. block */
1011 afs_int32 first = 0;
1013 afs_int32 slot = -1;
1015 if (entry->id == aid)
1016 return PRINCONSISTENT;
1017 #ifdef PR_REMEMBER_TIMES
1018 entry->addTime = time(0);
1020 for (i = 0; i < PRSIZE; i++) {
1021 if (entry->entries[i] == aid)
1023 if (entry->entries[i] == PRBADID) { /* remember this spot */
1026 } else if (entry->entries[i] == 0) { /* end of the line */
1037 code = pr_ReadCoEntry(tt, 0, nptr, &nentry);
1041 if (!(nentry.flags & PRCONT))
1043 for (i = 0; i < COSIZE; i++) {
1044 if (nentry.entries[i] == aid)
1046 if (nentry.entries[i] == PRBADID) {
1051 } else if (nentry.entries[i] == 0) {
1061 if (slot != -1) { /* we found a place */
1063 if (first) { /* place is in first block */
1064 entry->entries[slot] = aid;
1065 code = pr_WriteEntry(tt, 0, loc, entry);
1070 code = pr_WriteEntry(tt, 0, loc, entry);
1073 code = pr_ReadCoEntry(tt, 0, cloc, &aentry);
1076 aentry.entries[slot] = aid;
1077 code = pr_WriteCoEntry(tt, 0, cloc, &aentry);
1082 /* have to allocate a continuation block if we got here */
1083 nptr = AllocBlock(tt);
1085 /* then we should tack new block after last block in cont. chain */
1087 code = pr_WriteCoEntry(tt, 0, last, &nentry);
1093 memset(&aentry, 0, sizeof(aentry));
1094 aentry.flags |= PRCONT;
1095 aentry.id = entry->id;
1097 aentry.entries[0] = aid;
1098 code = pr_WriteCoEntry(tt, 0, nptr, &aentry);
1101 /* don't forget to update count, here! */
1103 code = pr_WriteEntry(tt, 0, loc, entry);
1108 #if defined(SUPERGROUPS)
1110 /* AddToSGEntry - add aid to entry's supergroup list, alloc'ing a
1111 * continuation block if needed.
1113 * Note the entry is written out by this routine. */
1116 AddToSGEntry(struct ubik_trans *tt, struct prentry *entry, afs_int32 loc, afs_int32 aid)
1118 register afs_int32 code;
1120 struct contentry nentry;
1121 struct contentry aentry;
1122 struct prentryg *entryg;
1124 afs_int32 last; /* addr of last cont. block */
1125 afs_int32 first = 0;
1127 afs_int32 slot = -1;
1129 if (entry->id == aid)
1130 return PRINCONSISTENT;
1131 #ifdef PR_REMEMBER_TIMES
1132 entry->addTime = time(NULL);
1134 entryg = (struct prentryg *)entry;
1135 for (i = 0; i < SGSIZE; i++) {
1136 if (entryg->supergroup[i] == aid)
1138 if (entryg->supergroup[i] == PRBADID) { /* remember this spot */
1141 } else if (entryg->supergroup[i] == 0) { /* end of the line */
1150 nptr = entryg->nextsg;
1152 code = pr_ReadCoEntry(tt, 0, nptr, &nentry);
1156 if (!(nentry.flags & PRCONT))
1158 for (i = 0; i < COSIZE; i++) {
1159 if (nentry.entries[i] == aid)
1161 if (nentry.entries[i] == PRBADID) {
1166 } else if (nentry.entries[i] == 0) {
1176 if (slot != -1) { /* we found a place */
1178 if (first) { /* place is in first block */
1179 entryg->supergroup[slot] = aid;
1180 code = pr_WriteEntry(tt, 0, loc, entry);
1185 code = pr_WriteEntry(tt, 0, loc, entry);
1188 code = pr_ReadCoEntry(tt, 0, cloc, &aentry);
1191 aentry.entries[slot] = aid;
1192 code = pr_WriteCoEntry(tt, 0, cloc, &aentry);
1197 /* have to allocate a continuation block if we got here */
1198 nptr = AllocBlock(tt);
1200 /* then we should tack new block after last block in cont. chain */
1202 code = pr_WriteCoEntry(tt, 0, last, &nentry);
1206 entryg->nextsg = nptr;
1208 memset(&aentry, 0, sizeof(aentry));
1209 aentry.flags |= PRCONT;
1210 aentry.id = entry->id;
1212 aentry.entries[0] = aid;
1213 code = pr_WriteCoEntry(tt, 0, nptr, &aentry);
1216 /* don't forget to update count, here! */
1218 code = pr_WriteEntry(tt, 0, loc, entry);
1222 #endif /* SUPERGROUPS */
1225 AddToPRList(prlist *alist, int *sizeP, afs_int32 id)
1230 if (alist->prlist_len >= *sizeP) {
1231 count = alist->prlist_len + 100;
1232 if (alist->prlist_val) {
1234 (char *)realloc(alist->prlist_val, count * sizeof(afs_int32));
1236 tmp = (char *)malloc(count * sizeof(afs_int32));
1240 alist->prlist_val = (afs_int32 *) tmp;
1243 alist->prlist_val[alist->prlist_len++] = id;
1248 GetList(struct ubik_trans *at, struct prentry *tentry, prlist *alist, afs_int32 add)
1252 struct contentry centry;
1258 alist->prlist_val = 0;
1259 alist->prlist_len = 0;
1261 for (i = 0; i < PRSIZE; i++) {
1262 if (tentry->entries[i] == PRBADID)
1264 if (tentry->entries[i] == 0)
1266 code = AddToPRList(alist, &size, tentry->entries[i]);
1269 #if defined(SUPERGROUPS)
1272 code = GetListSG2(at, tentry->entries[i], alist, &size, depthsg);
1278 for (nptr = tentry->next; nptr != 0; nptr = centry.next) {
1279 /* look through cont entries */
1280 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1283 for (i = 0; i < COSIZE; i++) {
1284 if (centry.entries[i] == PRBADID)
1286 if (centry.entries[i] == 0)
1288 code = AddToPRList(alist, &size, centry.entries[i]);
1291 #if defined(SUPERGROUPS)
1294 code = GetListSG2(at, centry.entries[i], alist, &size, depthsg);
1300 #ifndef AFS_PTHREAD_ENV
1307 if (add) { /* this is for a CPS, so tack on appropriate stuff */
1308 if (tentry->id != ANONYMOUSID && tentry->id != ANYUSERID) {
1309 if ((code = AddToPRList(alist, &size, ANYUSERID))
1310 || (code = AddAuthGroup(tentry, alist, &size))
1311 || (code = AddToPRList(alist, &size, tentry->id)))
1314 if ((code = AddToPRList(alist, &size, ANYUSERID))
1315 || (code = AddToPRList(alist, &size, tentry->id)))
1319 #ifndef AFS_PTHREAD_ENV
1320 if (alist->prlist_len > 100)
1323 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1329 GetList2(struct ubik_trans *at, struct prentry *tentry, struct prentry *tentry2, prlist *alist, afs_int32 add)
1333 struct contentry centry;
1339 alist->prlist_val = 0;
1340 alist->prlist_len = 0;
1341 for (i = 0; i < PRSIZE; i++) {
1342 if (tentry->entries[i] == PRBADID)
1344 if (tentry->entries[i] == 0)
1346 code = AddToPRList(alist, &size, tentry->entries[i]);
1349 #if defined(SUPERGROUPS)
1352 code = GetListSG2(at, tentry->entries[i], alist, &size, depthsg);
1358 nptr = tentry->next;
1360 /* look through cont entries */
1361 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1364 for (i = 0; i < COSIZE; i++) {
1365 if (centry.entries[i] == PRBADID)
1367 if (centry.entries[i] == 0)
1369 code = AddToPRList(alist, &size, centry.entries[i]);
1372 #if defined(SUPERGROUPS)
1375 code = GetListSG2(at, centry.entries[i], alist, &size, depthsg);
1382 #ifndef AFS_PTHREAD_ENV
1389 for (i = 0; i < PRSIZE; i++) {
1390 if (tentry2->entries[i] == PRBADID)
1392 if (tentry2->entries[i] == 0)
1394 code = AddToPRList(alist, &size, tentry2->entries[i]);
1400 nptr = tentry2->next;
1402 /* look through cont entries */
1403 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1406 for (i = 0; i < COSIZE; i++) {
1407 if (centry.entries[i] == PRBADID)
1409 if (centry.entries[i] == 0)
1411 code = AddToPRList(alist, &size, centry.entries[i]);
1417 #ifndef AFS_PTHREAD_ENV
1424 if (add) { /* this is for a CPS, so tack on appropriate stuff */
1425 if (tentry->id != ANONYMOUSID && tentry->id != ANYUSERID) {
1426 if ((code = AddToPRList(alist, &size, ANYUSERID))
1427 || (code = AddToPRList(alist, &size, AUTHUSERID))
1428 || (code = AddToPRList(alist, &size, tentry->id)))
1431 if ((code = AddToPRList(alist, &size, ANYUSERID))
1432 || (code = AddToPRList(alist, &size, tentry->id)))
1436 #ifndef AFS_PTHREAD_ENV
1437 if (alist->prlist_len > 100)
1440 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1444 #if defined(SUPERGROUPS)
1447 GetListSG2(struct ubik_trans *at, afs_int32 gid, prlist *alist, afs_int32 *sizeP, afs_int32 depth)
1449 register afs_int32 code;
1450 struct prentry tentry;
1451 struct prentryg *tentryg = (struct prentryg *)&tentry;
1453 struct contentry centry;
1459 int predictfound, predictflagged;
1464 if (!in_map(sg_flagged, -gid)) {
1466 fprintf(stderr, "GetListSG2: I have not yet searched for gid=%d\n",
1468 } else if (predictflagged = 1, in_map(sg_found, -gid)) {
1471 "GetListSG2: I have already searched for gid=%d, and predict success.\n",
1476 if (in_map(sg_flagged, -gid) && !in_map(sg_found, -gid)) {
1479 "GetListSG2: I have already searched for gid=%d, and predict failure.\n",
1488 temp = FindByID(at, gid);
1493 code = pr_ReadEntry(at, 0, temp, &tentry);
1497 fprintf(stderr, "GetListSG2: lookup for gid=%d [\n", gid);
1501 for (i = 0; i < SGSIZE; i++) {
1502 if (tentryg->supergroup[i] == PRBADID)
1504 if (tentryg->supergroup[i] == 0)
1508 fprintf(stderr, "via gid=%d, added %d\n", gid,
1509 e.tentryg.supergroup[i]);
1511 code = AddToPRList(alist, sizeP, tentryg->supergroup[i]);
1515 GetListSG2(at, tentryg->supergroup[i], alist, sizeP, depth - 1);
1520 nptr = tentryg->nextsg;
1523 /* look through cont entries */
1524 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1527 for (i = 0; i < COSIZE; i++) {
1528 if (centry.entries[i] == PRBADID)
1530 if (centry.entries[i] == 0)
1533 fprintf(stderr, "via gid=%d, added %d\n", gid,
1534 e.centry.entries[i]);
1536 code = AddToPRList(alist, sizeP, centry.entries[i]);
1539 code = GetListSG2(at, centry.entries[i], alist, sizeP, depth - 1);
1545 #ifndef AFS_PTHREAD_ENV
1552 fprintf(stderr, "] for gid %d, done [flag=%s]\n", gid,
1553 didsomething ? "TRUE" : "FALSE");
1554 if (predictflagged && didsomething != predictfound)
1555 fprintf(stderr, "**** for gid=%d, didsomething=%d predictfound=%d\n",
1556 didsomething, predictfound);
1559 sg_found = add_map(sg_found, -gid);
1561 sg_found = bic_map(sg_found, add_map(NIL_MAP, -gid));
1562 sg_flagged = add_map(sg_flagged, -gid);
1567 GetSGList(struct ubik_trans *at, struct prentry *tentry, prlist *alist)
1569 register afs_int32 code;
1571 struct contentry centry;
1572 struct prentryg *tentryg;
1578 alist->prlist_val = 0;
1579 alist->prlist_len = 0;
1581 tentryg = (struct prentryg *)tentry;
1582 for (i = 0; i < SGSIZE; i++) {
1583 if (tentryg->supergroup[i] == PRBADID)
1585 if (tentryg->supergroup[i] == 0)
1587 code = AddToPRList(alist, &size, tentryg->supergroup[i]);
1592 nptr = tentryg->nextsg;
1594 /* look through cont entries */
1595 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
1598 for (i = 0; i < COSIZE; i++) {
1599 if (centry.entries[i] == PRBADID)
1601 if (centry.entries[i] == 0)
1603 code = AddToPRList(alist, &size, centry.entries[i]);
1609 #ifndef AFS_PTHREAD_ENV
1616 #ifndef AFS_PTHREAD_ENV
1617 if (alist->prlist_len > 100)
1620 qsort((char *)alist->prlist_val, (int)alist->prlist_len,
1621 sizeof(afs_int32), IDCmp);
1624 #endif /* SUPERGROUPS */
1627 GetOwnedChain(struct ubik_trans *ut, afs_int32 *next, prlist *alist)
1630 struct prentry tentry;
1635 alist->prlist_val = 0;
1636 alist->prlist_len = 0;
1638 for (; *next; *next = ntohl(tentry.nextOwned)) {
1639 code = pr_Read(ut, 0, *next, &tentry, sizeof(tentry));
1642 code = AddToPRList(alist, &size, ntohl(tentry.id));
1643 if (alist->prlist_len >= PR_MAXGROUPS) {
1649 #ifndef AFS_PTHREAD_ENV
1655 #ifndef AFS_PTHREAD_ENV
1656 if (alist->prlist_len > 100)
1659 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
1664 GetMax(struct ubik_trans *at, afs_int32 *uid, afs_int32 *gid)
1666 *uid = ntohl(cheader.maxID);
1667 *gid = ntohl(cheader.maxGroup);
1672 SetMax(struct ubik_trans *at, afs_int32 id, afs_int32 flag)
1676 cheader.maxGroup = htonl(id);
1678 pr_Write(at, 0, 16, (char *)&cheader.maxGroup,
1679 sizeof(cheader.maxGroup));
1683 cheader.maxID = htonl(id);
1685 pr_Write(at, 0, 20, (char *)&cheader.maxID,
1686 sizeof(cheader.maxID));
1694 UpdateCache(struct ubik_trans *tt, void *rock)
1698 code = pr_Read(tt, 0, 0, (char *)&cheader, sizeof(cheader));
1700 afs_com_err(whoami, code, "Couldn't read header");
1706 read_DbHeader(struct ubik_trans *tt)
1708 return ubik_CheckCache(tt, UpdateCache, NULL);
1714 * reads in db cache from ubik.
1716 * @param[in] ut ubik transaction
1717 * @param[out] rock opaque pointer to an int*, which on success will be set
1718 * to 1 if we need to build the database, or 0 if we do not
1720 * @return operation status
1724 Initdb_check(struct ubik_trans *tt, void *rock)
1726 int *build_rock = rock;
1730 len = sizeof(cheader);
1731 code = pr_Read(tt, 0, 0, (char *)&cheader, len);
1733 afs_com_err(whoami, code, "couldn't read header");
1736 if ((ntohl(cheader.version) == PRDBVERSION)
1737 && ntohl(cheader.headerSize) == sizeof(cheader)
1738 && ntohl(cheader.eofPtr) != 0
1739 && FindByID(tt, ANONYMOUSID) != 0) {
1740 /* database exists, so we don't have to build it */
1745 /* else we need to build a database */
1753 struct ubik_trans *tt;
1757 /* init the database. We'll try reading it, but if we're starting
1758 * from scratch, we'll have to do a write transaction. */
1760 pr_noAuth = afsconf_GetNoAuthFlag(prdir);
1762 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
1765 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
1767 ubik_AbortTrans(tt);
1771 code = ubik_CheckCache(tt, Initdb_check, &build);
1773 ubik_AbortTrans(tt);
1778 /* Only rebuild database if the db was deleted (the header is zero) and we
1779 * are running noAuth. */
1780 char *bp = (char *)&cheader;
1782 for (i = 0; i < sizeof(cheader); i++) {
1785 afs_com_err(whoami, code,
1786 "Can't rebuild database because it is not empty");
1792 afs_com_err(whoami, code,
1793 "Can't rebuild database because not running NoAuth");
1800 code = ubik_EndTrans(tt);
1802 if (code || !build) {
1803 /* either we encountered an error, or we don't need to build the db */
1807 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
1811 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
1813 ubik_AbortTrans(tt);
1817 /* before doing a rebuild, check again that the dbase looks bad, because
1818 * the previous check was only under a ReadAny transaction, and there could
1819 * actually have been a good database out there. Now that we have a
1820 * real write transaction, make sure things are still bad.
1822 code = pr_Read(tt, 0, 0, (char *)&cheader, sizeof(cheader));
1824 afs_com_err(whoami, code, "couldn't read header");
1825 ubik_AbortTrans(tt);
1828 if ((ntohl(cheader.version) == PRDBVERSION)
1829 && ntohl(cheader.headerSize) == sizeof(cheader)
1830 && ntohl(cheader.eofPtr) != 0
1831 && FindByID(tt, ANONYMOUSID) != 0) {
1832 /* database exists, so we don't have to build it */
1833 code = ubik_EndTrans(tt);
1839 /* Initialize the database header */
1840 if ((code = set_header_word(tt, version, htonl(PRDBVERSION)))
1841 || (code = set_header_word(tt, headerSize, htonl(sizeof(cheader))))
1842 || (code = set_header_word(tt, eofPtr, cheader.headerSize))) {
1843 afs_com_err(whoami, code, "couldn't write header words");
1844 ubik_AbortTrans(tt);
1847 #define InitialGroup(id,name) do { \
1848 afs_int32 temp = (id); \
1849 afs_int32 flag = (id) < 0 ? PRGRP : 0; \
1850 code = CreateEntry \
1851 (tt, (name), &temp, /*idflag*/1, flag, SYSADMINID, SYSADMINID); \
1853 afs_com_err (whoami, code, "couldn't create %s with id %di.", \
1855 ubik_AbortTrans(tt); \
1860 InitialGroup(SYSADMINID, "system:administrators");
1861 InitialGroup(SYSBACKUPID, "system:backup");
1862 InitialGroup(ANYUSERID, "system:anyuser");
1863 InitialGroup(AUTHUSERID, "system:authuser");
1864 InitialGroup(SYSVIEWERID, "system:ptsviewers");
1865 InitialGroup(ANONYMOUSID, "anonymous");
1867 /* Well, we don't really want the max id set to anonymousid, so we'll set
1869 code = set_header_word(tt, maxID, 0); /* correct in any byte order */
1871 afs_com_err(whoami, code, "couldn't reset max id");
1872 ubik_AbortTrans(tt);
1876 code = ubik_EndTrans(tt);
1883 ChangeEntry(struct ubik_trans *at, afs_int32 aid, afs_int32 cid, char *name, afs_int32 oid, afs_int32 newid)
1887 #if defined(SUPERGROUPS)
1891 struct contentry centry;
1893 struct prentry tentry, tent;
1896 char holder[PR_MAXNAMELEN];
1897 char temp[PR_MAXNAMELEN];
1898 char oldname[PR_MAXNAMELEN];
1901 memset(holder, 0, PR_MAXNAMELEN);
1902 memset(temp, 0, PR_MAXNAMELEN);
1903 loc = FindByID(at, aid);
1906 code = pr_ReadEntry(at, 0, loc, &tentry);
1909 if (restricted && !IsAMemberOf(at, cid, SYSADMINID))
1911 if (tentry.owner != cid && !IsAMemberOf(at, cid, SYSADMINID)
1912 && !IsAMemberOf(at, cid, tentry.owner) && !pr_noAuth)
1914 #ifdef PR_REMEMBER_TIMES
1915 tentry.changeTime = time(0);
1918 /* we're actually trying to change the id */
1919 if (newid && (newid != aid)) {
1920 if (!IsAMemberOf(at, cid, SYSADMINID) && !pr_noAuth)
1923 pos = FindByID(at, newid);
1925 return PRIDEXIST; /* new id already in use! */
1926 if ((aid < 0 && newid > 0) || (aid > 0 && newid < 0))
1929 /* Should check that foreign users id to change to is good: inRange() */
1931 /* if new id is not in use, rehash things */
1932 code = RemoveFromIDHash(at, aid, &loc);
1933 if (code != PRSUCCESS)
1936 code = pr_WriteEntry(at, 0, loc, &tentry);
1939 code = AddToIDHash(at, tentry.id, loc);
1943 /* get current data */
1944 code = pr_ReadEntry(at, 0, loc, &tentry);
1948 #if defined(SUPERGROUPS)
1949 if (tentry.id > (afs_int32) ntohl(cheader.maxID))
1950 code = set_header_word(at, maxID, htonl(tentry.id));
1954 /* need to fix up: membership
1959 for (i = 0; i < PRSIZE; i++) {
1960 if (tentry.entries[i] == PRBADID)
1962 if (tentry.entries[i] == 0)
1964 if ((tentry.flags & PRGRP) && tentry.entries[i] < 0) { /* Supergroup */
1965 return 5; /* not yet, in short. */
1967 code = ChangeIDEntry(at, aid, newid, tentry.entries[i]);
1972 for (pos = ntohl(tentry.owned); pos; pos = nextpos) {
1973 code = pr_ReadEntry(at, 0, pos, &tent);
1977 nextpos = tent.nextOwned;
1978 code = pr_WriteEntry(at, 0, pos, &tent);
1984 #define centry (*(struct contentry*)&tent)
1985 code = pr_ReadCoEntry(at, 0, pos, ¢ry);
1986 if ((centry.id != aid)
1987 || !(centry.flags & PRCONT)) {
1989 "ChangeEntry: bad database aid=%d centry.id=%d .flags=%d\n",
1990 aid, centry.id, centry.flags);
1994 for (i = 0; i < COSIZE; i++) {
1995 if (centry.entries[i] == PRBADID)
1997 if (centry.entries[i] == 0)
1999 if ((centry.flags & PRGRP) && centry.entries[i] < 0) { /* Supergroup */
2000 return 5; /* not yet, in short. */
2002 code = ChangeIDEntry(at, aid, newid, centry.entries[i]);
2007 code = pr_WriteCoEntry(at, 0, pos, ¢ry);
2014 #else /* SUPERGROUPS */
2017 /* Also change the references from the membership list */
2018 for (i = 0; i < PRSIZE; i++) {
2019 if (tentry.entries[i] == PRBADID)
2021 if (tentry.entries[i] == 0)
2023 pos = FindByID(at, tentry.entries[i]);
2026 code = RemoveFromEntry(at, aid, tentry.entries[i]);
2029 code = pr_ReadEntry(at, 0, pos, &tent);
2032 code = AddToEntry(at, &tent, pos, newid);
2036 /* Look through cont entries too. This needs to be broken into
2037 * seperate transaction so that no one transaction becomes too
2038 * large to complete.
2040 for (nptr = tentry.next; nptr; nptr = centry.next) {
2041 code = pr_ReadCoEntry(at, 0, nptr, ¢ry);
2044 for (i = 0; i < COSIZE; i++) {
2045 if (centry.entries[i] == PRBADID)
2047 if (centry.entries[i] == 0)
2049 pos = FindByID(at, centry.entries[i]);
2052 code = RemoveFromEntry(at, aid, centry.entries[i]);
2055 code = pr_ReadEntry(at, 0, pos, &tent);
2058 code = AddToEntry(at, &tent, pos, newid);
2063 #endif /* SUPERGROUPS */
2066 atsign = strchr(tentry.name, '@'); /* check for foreign entry */
2068 /* Change the owner */
2069 if (oid && (oid != tentry.owner)) {
2070 /* only groups can have their owner's changed */
2071 if (!(tentry.flags & PRGRP))
2075 oldowner = tentry.owner;
2077 /* The entry must be written through first so Remove and Add routines
2078 * can operate on disk data */
2079 code = pr_WriteEntry(at, 0, loc, &tentry);
2083 /* switch owner chains */
2084 if (oldowner) /* if it has an owner */
2085 code = RemoveFromOwnerChain(at, tentry.id, oldowner);
2086 else /* must be an orphan */
2087 code = RemoveFromOrphan(at, tentry.id);
2090 code = AddToOwnerChain(at, tentry.id, tentry.owner);
2094 /* fix up the name */
2095 if (strlen(name) == 0)
2097 /* get current data */
2098 code = pr_ReadEntry(at, 0, loc, &tentry);
2103 /* Change the name, if name is a ptr to tentry.name then this name change
2104 * is due to a chown, otherwise caller has specified a new name */
2105 if ((name == tentry.name) || (*name && (strcmp(tentry.name, name) != 0))) {
2106 strncpy(oldname, tentry.name, PR_MAXNAMELEN);
2107 if (tentry.flags & PRGRP) {
2108 /* don't let foreign cell groups change name */
2111 code = CorrectGroupName(at, name, cid, tentry.owner, tentry.name);
2115 if (name == tentry.name) { /* owner fixup */
2116 if (strcmp(oldname, tentry.name) == 0)
2118 } else { /* new name, caller must be correct */
2119 if (strcmp(name, tentry.name) != 0)
2123 /* Allow a foreign name change only if the cellname part is
2128 newatsign = strchr(name, '@');
2129 if (newatsign != atsign) { /* if they are the same no problem */
2130 /*if the pointers are not equal the strings better be */
2131 if ((atsign == NULL) || (newatsign == NULL)
2132 || strcmp(atsign, newatsign))
2135 if (!CorrectUserName(name))
2139 pos = FindByName(at, name, &tent);
2142 code = RemoveFromNameHash(at, oldname, &loc);
2143 if (code != PRSUCCESS)
2145 strncpy(tentry.name, name, PR_MAXNAMELEN);
2146 code = pr_WriteEntry(at, 0, loc, &tentry);
2149 code = AddToNameHash(at, tentry.name, loc);
2150 if (code != PRSUCCESS)
2159 allocNextId(struct ubik_trans * at, struct prentry * cellEntry)
2161 /* Id's for foreign cell entries are constructed as follows:
2162 * The 16 low order bits are the group id of the cell and the
2163 * top 16 bits identify the particular users in that cell */
2166 afs_int32 cellid = ((ntohl(cellEntry->id)) & 0x0000ffff);
2168 id = (ntohl(cellEntry->nusers) + 1);
2169 while (FindByID(at, ((id << 16) | cellid))) {
2175 cellEntry->nusers = htonl(id);
2176 /* use the field nusers to keep
2177 * the next available id in that
2178 * foreign cell's group. Note :
2179 * It would seem more appropriate
2180 * to use ngroup for that and nusers
2181 * to enforce the quota, however pts
2182 * does not have an option to change
2183 * foreign users quota yet */
2185 id = (id << 16) | cellid;
2190 inRange(struct prentry *cellEntry, afs_int32 aid)
2192 afs_uint32 id, cellid, groupid;
2196 * The only thing that we want to make sure here is that
2197 * the id is in the legal range of this group. If it is
2198 * a duplicate we don't care since it will get caught
2199 * in a different check.
2202 cellid = aid & 0x0000ffff;
2203 groupid = (ntohl(cellEntry->id)) & 0x0000ffff;
2204 if (cellid != groupid)
2205 return 0; /* not in range */
2208 * if we got here we're ok but we need to update the nusers
2209 * field in order to get the id correct the next time that
2210 * we try to allocate it automatically
2214 if (id > ntohl(cellEntry->nusers))
2215 cellEntry->nusers = htonl(id);
2221 AddAuthGroup(struct prentry *tentry, prlist *alist, afs_int32 *size)
2223 if (!(strchr(tentry->name, '@')))
2224 return (AddToPRList(alist, size, AUTHUSERID));