6 * P_R_P_Q_# (C) COPYRIGHT IBM CORPORATION 1988
7 * LICENSED MATERIALS - PROPERTY OF IBM
8 * REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
13 Information Technology Center
29 extern struct ubik_dbase *dbase;
30 extern struct afsconf_dir *prdir;
33 PR_INewEntry(call,aname,aid,oid)
35 char aname[PR_MAXNAMELEN];
39 /* used primarily for conversion - not intended to be used as usual means of entering people into the database. */
40 struct ubik_trans *tt;
48 char oname[PR_MAXNAMELEN];
52 if (code != PRSUCCESS) return code;
53 noAuth =afsconf_GetNoAuthFlag(prdir);
54 code = ubik_BeginTrans(dbase,UBIK_WRITETRANS, &tt);
55 if (code) return code;
56 code = ubik_SetLock(tt, 1,1,LOCKWRITE);
61 code = WhoIsThis(call,tt,&cid);
62 if (code && !noAuth) {
70 if (aid < 0) gflag |= PRGRP;
74 if (oid != cid && !IsAMemberOf(tt,cid,SYSADMINID)) {
80 if (!IsAMemberOf(tt,cid,SYSADMINID)) {
87 /* is this guy already in the database? */
88 temp = FindByID(tt,aid);
94 if (cid == ANONYMOUSID) {
98 if ((check = index(aname,':')) == 0) {
99 /* groups should have owner's name prepended */
104 if (!IsAMemberOf(tt,cid,SYSADMINID) && !IsOwnerOf(tt,cid,oid)) {
105 /* must be a sysadmin to specify another owner, unless other owner is group owned by you */
111 bzero(oname,PR_MAXNAMELEN);
112 /* check prepended part */
113 strncpy(oname,aname,check-aname);
114 if (!strcmp(oname,"system")) {
115 /* groups with system: at beginning are owned by SYSADMIN */
119 code = NameToID(tt,oname,&tid);
120 if (code || tid == ANONYMOUSID) {
121 /* owner doesn't exist */
127 /* owner's name should be prepended */
134 /* if owner is a group, group owner's name should be prepended. */
135 if (tid != OwnerOf(tt,oid)) {
141 temp = FindByName(tt,aname);
146 code = CreateEntry(tt,aname,&aid,1,gflag,oid,cid);
147 if (code != PRSUCCESS) {
151 /* finally, commit transaction */
152 code = ubik_EndTrans(tt);
153 if (code) return code;
158 PR_NewEntry(call,aname,flag,oid,aid)
159 struct rx_call *call;
160 char aname[PR_MAXNAMELEN];
166 struct ubik_trans *tt;
169 char oname[PR_MAXNAMELEN];
176 noAuth = afsconf_GetNoAuthFlag(prdir);
177 if (code != PRSUCCESS) return code;
178 code = ubik_BeginTrans(dbase,UBIK_WRITETRANS,&tt);
179 if (code) return code;
180 code = ubik_SetLock(tt,1,1,LOCKWRITE);
185 code = WhoIsThis(call,tt,&cid);
186 if (code && !noAuth) {
191 if (cid == ANONYMOUSID) {
195 if ((check = index(aname,':')) == 0) {
196 /* groups should have owner's name prepended */
201 if (!IsAMemberOf(tt,cid,SYSADMINID) && !IsOwnerOf(tt,cid,oid)) {
202 /* must be a sysadmin to specify another owner, unless other owner is group owned by you */
208 bzero(oname,PR_MAXNAMELEN);
209 /* check prepended part */
210 strncpy(oname,aname,check-aname);
211 if (!strcmp(oname,"system")) {
212 /* groups with system: at beginning are owned by SYSADMIN */
216 code = NameToID(tt,oname,&tid);
217 if (code || tid == ANONYMOUSID) {
218 /* owner doesn't exist */
224 /* owner's name should be prepended */
231 /* if owner is a group, prepend group owner's name. */
232 if (tid != OwnerOf(tt,oid)) {
237 temp = FindByName(tt,aname);
242 code = CreateEntry(tt,aname,aid,0,flag,oid,cid);
243 if (code != PRSUCCESS) {
249 if (!(flag & PRFOREIGN)) {
250 if (!IsAMemberOf(tt,cid,SYSADMINID) && !noAuth) {
254 if (oid != SYSADMINID) oid = SYSADMINID;
256 temp = FindByName(tt,aname);
261 code = CreateEntry(tt,aname,aid,0,flag,oid,cid);
262 if (code != PRSUCCESS) {
267 code = ubik_EndTrans(tt);
268 if (code) return code;
274 PR_WhereIsIt(call,aid,apos)
275 struct rx_call *call;
280 struct ubik_trans *tt;
284 if (code != PRSUCCESS) return code;
285 code = ubik_BeginTrans(dbase,UBIK_READTRANS,&tt);
286 if (code) return code;
287 code = ubik_SetLock(tt,1,1,LOCKREAD);
292 temp = FindByID(tt,aid);
298 code = ubik_EndTrans(tt);
299 if (code) return code;
304 PR_DumpEntry(call,apos, aentry)
305 struct rx_call *call;
307 struct prdebugentry *aentry;
310 struct ubik_trans *tt;
313 if (code != PRSUCCESS) return code;
314 code = ubik_BeginTrans(dbase,UBIK_READTRANS,&tt);
315 if (code) return code;
316 code = ubik_SetLock(tt,1,1,LOCKREAD);
321 code = pr_ReadEntry(tt, 0, apos, aentry);
326 code = ubik_EndTrans(tt);
327 if (code) return code;
331 PR_AddToGroup(call,aid,gid)
332 struct rx_call *call;
337 struct ubik_trans *tt;
340 struct prentry tentry;
341 struct prentry uentry;
347 if (code != PRSUCCESS) return code;
348 if (gid == ANYUSERID || gid == AUTHUSERID) return PRPERM;
349 if (aid == ANONYMOUSID) return PRPERM;
350 noAuth = afsconf_GetNoAuthFlag(prdir);
351 code = ubik_BeginTrans(dbase,UBIK_WRITETRANS,&tt);
352 if (code) return code;
353 code = ubik_SetLock(tt,1,1,LOCKWRITE);
358 code = WhoIsThis(call, tt, &cid);
359 if (code && !noAuth) {
363 tempu = FindByID(tt,aid);
368 bzero(&uentry,sizeof(uentry));
369 code = pr_ReadEntry(tt,0,tempu,&uentry);
374 /* we don't allow groups as members of groups at present */
375 if (uentry.flags & PRGRP) {
379 tempg = FindByID(tt,gid);
384 code = pr_ReadEntry(tt,0,tempg,&tentry);
389 /* make sure that this is a group */
390 if (!(tentry.flags & PRGRP)) {
394 if (tentry.owner != cid && !IsAMemberOf(tt,cid,SYSADMINID) && !IsAMemberOf(tt,cid,tentry.owner) && !noAuth) {
400 code = AddToEntry(tt,tentry,tempg,aid);
401 if (code != PRSUCCESS) {
405 /* now, modify the user's entry as well */
406 code = AddToEntry(tt,uentry,tempu,gid);
407 if (code != PRSUCCESS) {
411 code = ubik_EndTrans(tt);
412 if (code) return code;
416 PR_NameToID(call,aname,aid)
417 struct rx_call *call;
422 struct ubik_trans *tt;
425 /* must do this first for RPC stub to work */
426 aid->idlist_val = (long *)malloc(PR_MAXLIST*sizeof(long));
430 if (code != PRSUCCESS) return code;
431 code = ubik_BeginTrans(dbase,UBIK_READTRANS,&tt);
432 if (code) return code;
433 code = ubik_SetLock(tt,1,1,LOCKREAD);
438 for (i=0;i<aname->namelist_len;i++) {
439 code = NameToID(tt,aname->namelist_val[i],&aid->idlist_val[i]);
440 if (code != PRSUCCESS) aid->idlist_val[i] = ANONYMOUSID;
443 code = ubik_EndTrans(tt);
444 if (code)return code;
448 PR_IDToName(call,aid,aname)
449 struct rx_call *call;
454 struct ubik_trans *tt;
457 /* leave this first for rpc stub */
458 aname->namelist_len = 0;
459 aname->namelist_val = (prname *)malloc(PR_MAXLIST*PR_MAXNAMELEN);
462 if (code != PRSUCCESS) return code;
463 code = ubik_BeginTrans(dbase,UBIK_READTRANS,&tt);
464 if (code) return code;
465 code = ubik_SetLock(tt,1,1,LOCKREAD);
470 for (i=0;i<aid->idlist_len;i++) {
471 /* interface won't allow more than PR_MAXLIST to be sent in */
472 code = IDToName(tt,aid->idlist_val[i],aname->namelist_val[i]);
473 if (code != PRSUCCESS)
474 sprintf(aname->namelist_val[i],"%d",aid->idlist_val[i]);
475 aname->namelist_len++;
477 code = ubik_EndTrans(tt);
478 if (code) return code;
483 struct rx_call *call;
487 struct ubik_trans *tt;
492 noAuth = afsconf_GetNoAuthFlag(prdir);
493 if (code != PRSUCCESS) return code;
494 if (aid == SYSADMINID || aid == ANYUSERID || aid == AUTHUSERID || aid == ANONYMOUSID) return PRPERM;
495 code = ubik_BeginTrans(dbase,UBIK_WRITETRANS,&tt);
496 if (code) return code;
497 code = ubik_SetLock(tt,1,1,LOCKWRITE);
502 code = WhoIsThis(call,tt,&cid);
503 if (code && !noAuth) {
507 /*protection check will occur in DeleteEntry - sigh. */
508 code = DeleteEntry(tt,aid,cid);
509 if (code != PRSUCCESS) {
513 code = ubik_EndTrans(tt);
514 if (code) return code;
518 PR_RemoveFromGroup(call,aid,gid)
519 struct rx_call *call;
524 struct ubik_trans *tt;
527 struct prentry uentry;
528 struct prentry gentry;
533 if (code != PRSUCCESS) return code;
534 noAuth = afsconf_GetNoAuthFlag(prdir);
535 code = ubik_BeginTrans(dbase,UBIK_WRITETRANS,&tt);
536 if (code) return code;
537 code = ubik_SetLock(tt,1,1,LOCKWRITE);
542 code = WhoIsThis(call,tt,&cid);
543 if (code && !noAuth) {
547 tempu = FindByID(tt,aid);
552 tempg = FindByID(tt,gid);
557 bzero(&uentry,sizeof(uentry));
558 bzero(&gentry,sizeof(gentry));
559 code = pr_ReadEntry(tt,0,tempu,&uentry);
564 code = pr_ReadEntry(tt,0,tempg,&gentry);
569 if (!(gentry.flags & PRGRP)) {
573 if (uentry.flags & PRGRP) {
577 if (gentry.owner != cid && !IsAMemberOf(tt,cid,SYSADMINID) && !IsAMemberOf(tt,cid,gentry.owner) && !noAuth) {
581 code = RemoveFromEntry(tt,aid,gid);
582 if (code != PRSUCCESS) {
586 code = RemoveFromEntry(tt,gid,aid);
587 if (code != PRSUCCESS) {
591 code = ubik_EndTrans(tt);
592 if (code) return code;
596 PR_GetCPS(call,aid,alist,over)
597 struct rx_call *call;
603 struct ubik_trans *tt;
605 alist->prlist_len = 0;
606 alist->prlist_val = (long *) 0;
608 if (code != PRSUCCESS) goto done;
609 code = ubik_BeginTrans(dbase,UBIK_READTRANS,&tt);
611 code = ubik_SetLock(tt,1,1,LOCKREAD);
617 code = GetList(tt,aid,alist,1);
618 if (code != PRSUCCESS) {
622 if (alist->prlist_len > PR_MAXGROUPS) *over = alist->prlist_len - PR_MAXGROUPS;
623 code = ubik_EndTrans(tt);
626 /* return code, making sure that prlist_val points to malloc'd memory */
627 if (!alist->prlist_val)
628 alist->prlist_val = (long *) malloc(0); /* make xdr stub happy */
632 PR_ListMax(call,uid,gid)
633 struct rx_call *call;
638 struct ubik_trans *tt;
641 if (code != PRSUCCESS) return code;
642 code = ubik_BeginTrans(dbase,UBIK_READTRANS,&tt);
643 if (code) return code;
644 code = ubik_SetLock(tt,1,1,LOCKREAD);
649 code = GetMax(tt,uid,gid);
650 if (code != PRSUCCESS) {
654 code = ubik_EndTrans(tt);
655 if (code) return code;
659 PR_SetMax(call,aid,gflag)
660 struct rx_call *call;
665 struct ubik_trans *tt;
670 if (code != PRSUCCESS) return code;
671 noAuth = afsconf_GetNoAuthFlag(prdir);
672 code = ubik_BeginTrans(dbase,UBIK_WRITETRANS,&tt);
673 if (code) return code;
674 code = ubik_SetLock(tt,1,1,LOCKWRITE);
679 code = WhoIsThis(call,tt,&cid);
680 if (code && !noAuth) {
684 if (!IsAMemberOf(tt, cid,SYSADMINID) && !noAuth) {
688 code = SetMax(tt,aid,gflag);
689 if (code != PRSUCCESS) {
693 code = ubik_EndTrans(tt);
694 if (code) return code;
698 PR_ListEntry(call,aid,aentry)
699 struct rx_call *call;
701 struct prcheckentry *aentry;
704 struct ubik_trans *tt;
706 struct prentry tentry;
709 if (code != PRSUCCESS) return code;
710 code = ubik_BeginTrans(dbase,UBIK_READTRANS,&tt);
711 if (code) return code;
712 code = ubik_SetLock(tt,1,1,LOCKREAD);
717 temp = FindByID(tt,aid);
722 code = pr_ReadEntry(tt, 0, temp, &tentry);
727 aentry->owner = tentry.owner;
728 aentry->id = tentry.id;
729 strncpy(aentry->name,tentry.name,PR_MAXNAMELEN);
730 aentry->creator = tentry.creator;
731 aentry->ngroups = tentry.ngroups;
732 aentry->nusers = tentry.nusers;
733 aentry->count = aentry->count;
734 code = ubik_EndTrans(tt);
735 if (code) return code;
739 PR_ChangeEntry(call,aid,name,oid,newid)
740 struct rx_call *call;
747 struct ubik_trans *tt;
754 if (aid == ANYUSERID || aid == AUTHUSERID || aid == ANONYMOUSID || aid == SYSADMINID) return PRPERM;
755 noAuth = afsconf_GetNoAuthFlag(prdir);
756 if (code != PRSUCCESS) return code;
757 code = ubik_BeginTrans(dbase,UBIK_WRITETRANS,&tt);
758 if (code) return code;
759 code = ubik_SetLock(tt,1,1,LOCKWRITE);
764 code = WhoIsThis(call,tt,&cid);
765 if (code && !noAuth) {
769 pos = FindByID(tt,aid);
774 /* protection check in changeentry */
775 code = ChangeEntry(tt,aid,cid,name,oid,newid);
776 if (code != PRSUCCESS) {
780 code = ubik_EndTrans(tt);
784 PR_ListElements(call,aid,alist,over)
785 struct rx_call *call;
791 struct ubik_trans *tt;
793 alist->prlist_len = 0;
794 alist->prlist_val = (long *) 0;
797 if (code != PRSUCCESS) goto done;
798 code = ubik_BeginTrans(dbase,UBIK_READTRANS,&tt);
800 code = ubik_SetLock(tt,1,1,LOCKREAD);
805 code = GetList(tt,aid,alist,0);
806 if (code != PRSUCCESS) {
810 if (alist->prlist_len > PR_MAXGROUPS) *over = alist->prlist_len - PR_MAXGROUPS;
811 code = ubik_EndTrans(tt);
814 if (!alist->prlist_val)
815 alist->prlist_val = (long *) malloc(0); /* make calling stub happy */
824 if (isupper(tc)) *s = tolower(tc);