Protect ubik cache accesses
[openafs.git] / src / ptserver / ptprocs.c
index 4cf7369..1cd803f 100644 (file)
@@ -50,8 +50,6 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
 
 #include <afs/stds.h>
 #include <ctype.h>
@@ -67,16 +65,12 @@ RCSID
 #include <winsock2.h>
 #else
 #include <netinet/in.h>
+#include <arpa/inet.h>
 #endif
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 #include "ptserver.h"
 #include "pterror.h"
+#include "ptprototypes.h"
 #include "afs/audit.h"
 
 #ifdef AFS_ATHENA_STDENV
@@ -86,36 +80,84 @@ RCSID
 
 #define        IP_WILDCARDS    1       /* XXX Should be defined outside of here XXX */
 
+extern int restricted;
 extern struct ubik_dbase *dbase;
-extern afs_int32 Initdb();
 extern int pr_noAuth;
-extern afs_int32 initd;
-afs_int32 iNewEntry(), newEntry(), whereIsIt(), dumpEntry(), addToGroup(),
-nameToID(), Delete(), removeFromGroup();
-afs_int32 getCPS(), getCPS2(), getHostCPS(), listMax(), setMax(), listEntry();
-afs_int32 listEntries(), changeEntry(), setFieldsEntry(), put_prentries();
-afs_int32 listElements(), listOwned(), isAMemberOf(), idToName();
-
+extern char *pr_realmName;
+extern int prp_group_default;
+extern int prp_user_default;
+
+static afs_int32 iNewEntry(struct rx_call *call, char aname[], afs_int32 aid, 
+                          afs_int32 oid, afs_int32 *cid);
+static afs_int32 newEntry(struct rx_call *call, char aname[], afs_int32 flag, 
+                         afs_int32 oid, afs_int32 *aid, afs_int32 *cid);       
+static afs_int32 whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos,
+                          afs_int32 *cid);
+static afs_int32 dumpEntry(struct rx_call *call, afs_int32 apos, 
+                          struct prdebugentry *aentry, afs_int32 *cid);
+static afs_int32 addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid, 
+                           afs_int32 *cid);
+static afs_int32 nameToID(struct rx_call *call, namelist *aname, idlist *aid);
+static afs_int32 idToName(struct rx_call *call, idlist *aid, namelist *aname);
+static afs_int32 Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid);
+static afs_int32 UpdateEntry(struct rx_call *call, afs_int32 aid, char *name, 
+                            struct PrUpdateEntry *uentry, afs_int32 *cid);
+static afs_int32 removeFromGroup(struct rx_call *call, afs_int32 aid, 
+                                afs_int32 gid, afs_int32 *cid);
+static afs_int32 getCPS(struct rx_call *call, afs_int32 aid, prlist *alist, 
+                       afs_int32 *over, afs_int32 *cid);
+static afs_int32 getCPS2(struct rx_call *call, afs_int32 aid, afs_int32 ahost,
+                        prlist *alist, afs_int32 *over, afs_int32 *cid);
+static afs_int32 getHostCPS(struct rx_call *call, afs_int32 ahost, 
+                           prlist *alist, afs_int32 *over);
+static afs_int32 listMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid);
+static afs_int32 setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag, 
+                       afs_int32 *cid);
+static afs_int32 listEntry(struct rx_call *call, afs_int32 aid, 
+                          struct prcheckentry *aentry, afs_int32 *cid);
+static afs_int32 listEntries(struct rx_call *call, afs_int32 flag, 
+                            afs_int32 startindex, prentries *bulkentries, 
+                            afs_int32 *nextstartindex, afs_int32 *cid);
+static afs_int32 put_prentries(struct prentry *tentry, prentries *bulkentries);
+static afs_int32 changeEntry(struct rx_call *call, afs_int32 aid, char *name, 
+                            afs_int32 oid, afs_int32 newid, afs_int32 *cid);
+static afs_int32 setFieldsEntry(struct rx_call *call, afs_int32 id, 
+                               afs_int32 mask, afs_int32 flags, 
+                               afs_int32 ngroups, afs_int32 nusers, 
+                               afs_int32 spare1, afs_int32 spare2, 
+                               afs_int32 *cid);
+static afs_int32 listElements(struct rx_call *call, afs_int32 aid,
+                             prlist *alist, afs_int32 *over, afs_int32 *cid);
 #if defined(SUPERGROUPS)
-afs_int32 listSuperGroups();
+static afs_int32 listSuperGroups(struct rx_call *call, afs_int32 aid, 
+                                prlist *alist, afs_int32 *over, 
+                                afs_int32 *cid);
 #endif
+static afs_int32 listOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
+                          afs_int32 *lastP, afs_int32 *cid);
+static afs_int32 isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid,
+                            afs_int32 *flag, afs_int32 *cid);
+#if IP_WILDCARDS
+static afs_int32 addWildCards(struct ubik_trans *tt, prlist *alist, 
+                             afs_int32 host);
+#endif
+static afs_int32 WhoIsThisWithName(struct rx_call *acall, 
+                                  struct ubik_trans *at, afs_int32 *aid, 
+                                  char *aname);
 
-static stolower();
-extern int IDCmp();
-
-/* When abort, reset initd so that the header is read in on next call.
+/* when we abort, the ubik cachedVersion will be reset, so we'll read in the
+ * header on the next call.
  * Abort the transaction and return the code.
  */
-#define ABORT_WITH(tt,code) return(initd=0,ubik_AbortTrans(tt),code)
+#define ABORT_WITH(tt,code) return(ubik_AbortTrans(tt),code)
 
 static int
-CreateOK(ut, cid, oid, flag, admin)
-     struct ubik_trans *ut;
-     afs_int32 cid;            /* id of caller */
-     afs_int32 oid;            /* id of owner */
-     afs_int32 flag;           /* indicates type of entry */
-     int admin;                        /* sysadmin membership */
+CreateOK(struct ubik_trans *ut, afs_int32 cid, afs_int32 oid, afs_int32 flag, 
+        int admin)
 {
+    if (restricted && !admin) 
+       return 0;
+
     if (flag & PRFOREIGN) {
        /* Foreign users are recognized by the '@' sign and 
         * not by the PRFOREIGN flag.
@@ -137,10 +179,7 @@ CreateOK(ut, cid, oid, flag, admin)
 }
 
 afs_int32
-WhoIsThis(acall, at, aid)
-     struct rx_call *acall;
-     struct ubik_trans *at;
-     afs_int32 *aid;
+WhoIsThis(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid)
 {
     int foreign = 0;
     /* aid is set to the identity of the caller, if known, else ANONYMOUSID */
@@ -170,24 +209,11 @@ WhoIsThis(acall, at, aid)
        if (exp < FT_ApproxTime())
            goto done;
 #endif
-       if (strlen(tcell)) {
-           extern char *pr_realmName;
-#if    defined(AFS_ATHENA_STDENV) || defined(AFS_KERBREALM_ENV)
-           static char local_realm[AFS_REALM_SZ] = "";
-           if (!local_realm[0]) {
-               if (afs_krb_get_lrealm(local_realm, 0) != 0 /*KSUCCESS*/)
-                   strncpy(local_realm, pr_realmName, AFS_REALM_SZ);
-           }
-#endif
-           if (
-#if    defined(AFS_ATHENA_STDENV) || defined(AFS_KERBREALM_ENV)
-                  strcasecmp(local_realm, tcell) &&
-#endif
-                  strcasecmp(pr_realmName, tcell))
-               foreign = 1;
-       }
+       if (tcell[0])
+           foreign = afs_is_foreign_ticket_name(name,inst,tcell,pr_realmName);
+
        strncpy(vname, name, sizeof(vname));
-       if (ilen = strlen(inst)) {
+       if ((ilen = strlen(inst))) {
            if (strlen(vname) + 1 + ilen >= sizeof(vname))
                goto done;
            strcat(vname, ".");
@@ -213,33 +239,27 @@ WhoIsThis(acall, at, aid)
 }
 
 afs_int32
-SPR_INewEntry(call, aname, aid, oid)
-     struct rx_call *call;
-     char aname[PR_MAXNAMELEN];
-     afs_int32 aid;
-     afs_int32 oid;
+SPR_INewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = iNewEntry(call, aname, aid, oid);
-    osi_auditU(call, PTS_INewEntEvent, code, AUD_LONG, aid, AUD_STR, aname,
-              AUD_LONG, oid, AUD_END);
+    code = iNewEntry(call, aname, aid, oid, &cid);
+    osi_auditU(call, PTS_INewEntEvent, code, AUD_ID, aid, AUD_STR, aname,
+              AUD_ID, oid, AUD_END);
+    ViceLog(5, ("PTS_INewEntry: code %d cid %d aid %d aname %s oid %d\n", code, cid, aid, aname, oid));
     return code;
 }
 
-afs_int32
-iNewEntry(call, aname, aid, oid)
-     struct rx_call *call;
-     char aname[PR_MAXNAMELEN];
-     afs_int32 aid;
-     afs_int32 oid;
+static afs_int32
+iNewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid, 
+         afs_int32 *cid)
 {
     /* used primarily for conversion - not intended to be used as usual means
      * of entering people into the database. */
     struct ubik_trans *tt;
     register afs_int32 code;
     afs_int32 gflag = 0;
-    afs_int32 cid;
     int admin;
 
     stolower(aname);
@@ -256,10 +276,10 @@ iNewEntry(call, aname, aid, oid)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
-    admin = IsAMemberOf(tt, cid, SYSADMINID);
+    admin = IsAMemberOf(tt, *cid, SYSADMINID);
 
     /* first verify the id is good */
     if (aid == 0)
@@ -274,10 +294,10 @@ iNewEntry(call, aname, aid, oid)
        ABORT_WITH(tt, PRIDEXIST);
 
     /* check a few other things */
-    if (!CreateOK(tt, cid, oid, gflag, admin))
+    if (!CreateOK(tt, *cid, oid, gflag, admin))
        ABORT_WITH(tt, PRPERM);
 
-    code = CreateEntry(tt, aname, &aid, 1, gflag, oid, cid);
+    code = CreateEntry(tt, aname, &aid, 1, gflag, oid, *cid);
     if (code != PRSUCCESS)
        ABORT_WITH(tt, code);
 
@@ -290,34 +310,26 @@ iNewEntry(call, aname, aid, oid)
 
 
 afs_int32
-SPR_NewEntry(call, aname, flag, oid, aid)
-     struct rx_call *call;
-     char aname[PR_MAXNAMELEN];
-     afs_int32 flag;
-     afs_int32 oid;
-     afs_int32 *aid;
+SPR_NewEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid, 
+            afs_int32 *aid)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = newEntry(call, aname, flag, oid, aid);
-    osi_auditU(call, PTS_NewEntEvent, code, AUD_LONG, *aid, AUD_STR, aname,
-              AUD_LONG, oid, AUD_END);
+    code = newEntry(call, aname, flag, oid, aid, &cid);
+    osi_auditU(call, PTS_NewEntEvent, code, AUD_ID, *aid, AUD_STR, aname,
+              AUD_ID, oid, AUD_END);
+    ViceLog(5, ("PTS_NewEntry: code %d cid %d aid %d aname %s oid %d\n", code, cid, *aid, aname, oid));
     return code;
 }
 
-afs_int32
-newEntry(call, aname, flag, oid, aid)
-     struct rx_call *call;
-     char aname[PR_MAXNAMELEN];
-     afs_int32 flag;
-     afs_int32 oid;
-     afs_int32 *aid;
+static afs_int32
+newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid, 
+        afs_int32 *aid, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
-    afs_int32 cid;
     int admin;
-    extern afs_int32 WhoIsThisWithName();
     char cname[PR_MAXNAMELEN];
     stolower(aname);
     code = Initdb();
@@ -337,19 +349,19 @@ newEntry(call, aname, flag, oid, aid)
      * SPR_INewEntry because we want self-registration to only do 
      * automatic id assignment.
      */
-    code = WhoIsThisWithName(call, tt, &cid, cname);
+    code = WhoIsThisWithName(call, tt, cid, cname);
     if (code != 2) {           /* 2 specifies that this is a foreign cell request */
        if (code)
            ABORT_WITH(tt, PRPERM);
-       admin = IsAMemberOf(tt, cid, SYSADMINID);
+       admin = IsAMemberOf(tt, *cid, SYSADMINID);
     } else {
-       admin = (!strcmp(aname, cname)) || IsAMemberOf(tt, cid, SYSADMINID);
-       oid = cid = SYSADMINID;
+       admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
+       oid = *cid = SYSADMINID;
     }
-    if (!CreateOK(tt, cid, oid, flag, admin))
+    if (!CreateOK(tt, *cid, oid, flag, admin))
        ABORT_WITH(tt, PRPERM);
 
-    code = CreateEntry(tt, aname, aid, 0, flag, oid, cid);
+    code = CreateEntry(tt, aname, aid, 0, flag, oid, *cid);
     if (code != PRSUCCESS)
        ABORT_WITH(tt, code);
 
@@ -362,24 +374,20 @@ newEntry(call, aname, flag, oid, aid)
 
 
 afs_int32
-SPR_WhereIsIt(call, aid, apos)
-     struct rx_call *call;
-     afs_int32 aid;
-     afs_int32 *apos;
+SPR_WhereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = whereIsIt(call, aid, apos);
-    osi_auditU(call, PTS_WheIsItEvent, code, AUD_LONG, aid, AUD_LONG, *apos,
+    code = whereIsIt(call, aid, apos, &cid);
+    osi_auditU(call, PTS_WheIsItEvent, code, AUD_ID, aid, AUD_LONG, *apos,
               AUD_END);
+    ViceLog(125, ("PTS_WhereIsIt: code %d cid %d aid %d apos %d\n", code, cid, aid, *apos));
     return code;
 }
 
-afs_int32
-whereIsIt(call, aid, apos)
-     struct rx_call *call;
-     afs_int32 aid;
-     afs_int32 *apos;
+static afs_int32
+whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
@@ -398,6 +406,10 @@ whereIsIt(call, aid, apos)
     if (code)
        ABORT_WITH(tt, code);
 
+    code = WhoIsThis(call, tt, cid);
+    if (code)
+       ABORT_WITH(tt, PRPERM);
+
     temp = FindByID(tt, aid);
     if (!temp)
        ABORT_WITH(tt, PRNOENT);
@@ -410,26 +422,23 @@ whereIsIt(call, aid, apos)
 
 
 afs_int32
-SPR_DumpEntry(call, apos, aentry)
-     struct rx_call *call;
-     afs_int32 apos;
-     struct prdebugentry *aentry;
+SPR_DumpEntry(struct rx_call *call, afs_int32 apos, 
+             struct prdebugentry *aentry)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = dumpEntry(call, apos, aentry);
+    code = dumpEntry(call, apos, aentry, &cid);
     osi_auditU(call, PTS_DmpEntEvent, code, AUD_LONG, apos, AUD_END);
+    ViceLog(125, ("PTS_DumpEntry: code %d cid %d apos %d\n", code, cid, apos));
     return code;
 }
 
-afs_int32
-dumpEntry(call, apos, aentry)
-     struct rx_call *call;
-     afs_int32 apos;
-     struct prdebugentry *aentry;
+static afs_int32
+dumpEntry(struct rx_call *call, afs_int32 apos, struct prdebugentry *aentry, 
+         afs_int32 *cid)
 {
     register afs_int32 code;
-    afs_int32 cid;
     struct ubik_trans *tt;
 
     code = Initdb();
@@ -445,14 +454,14 @@ dumpEntry(call, apos, aentry)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
-    code = pr_ReadEntry(tt, 0, apos, aentry);
+    code = pr_ReadEntry(tt, 0, apos, (struct prentry *)aentry);
     if (code)
        ABORT_WITH(tt, code);
 
-    if (!AccessOK(tt, cid, 0, PRP_STATUS_MEM, 0))
+    if (!AccessOK(tt, *cid, 0, PRP_STATUS_MEM, 0))
        ABORT_WITH(tt, PRPERM);
 
     /* Since prdebugentry is in the form of a prentry not a coentry, we will
@@ -471,24 +480,20 @@ dumpEntry(call, apos, aentry)
 }
 
 afs_int32
-SPR_AddToGroup(call, aid, gid)
-     struct rx_call *call;
-     afs_int32 aid;
-     afs_int32 gid;
+SPR_AddToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = addToGroup(call, aid, gid);
-    osi_auditU(call, PTS_AdToGrpEvent, code, AUD_LONG, gid, AUD_LONG, aid,
+    code = addToGroup(call, aid, gid, &cid);
+    osi_auditU(call, PTS_AdToGrpEvent, code, AUD_ID, gid, AUD_ID, aid,
               AUD_END);
+    ViceLog(5, ("PTS_AddToGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid));
     return code;
 }
 
-afs_int32
-addToGroup(call, aid, gid)
-     struct rx_call *call;
-     afs_int32 aid;
-     afs_int32 gid;
+static afs_int32
+addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
@@ -496,7 +501,6 @@ addToGroup(call, aid, gid)
     afs_int32 tempg;
     struct prentry tentry;
     struct prentry uentry;
-    afs_int32 cid;
 
     code = Initdb();
     if (code != PRSUCCESS)
@@ -515,7 +519,7 @@ addToGroup(call, aid, gid)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
     tempu = FindByID(tt, aid);
@@ -541,7 +545,7 @@ addToGroup(call, aid, gid)
     /* make sure that this is a group */
     if (!(tentry.flags & PRGRP))
        ABORT_WITH(tt, PRNOTGROUP);
-    if (!AccessOK(tt, cid, &tentry, PRP_ADD_MEM, PRP_ADD_ANY))
+    if (!AccessOK(tt, *cid, &tentry, PRP_ADD_MEM, PRP_ADD_ANY))
        ABORT_WITH(tt, PRPERM);
 
     code = AddToEntry(tt, &tentry, tempg, aid);
@@ -564,23 +568,18 @@ addToGroup(call, aid, gid)
 }
 
 afs_int32
-SPR_NameToID(call, aname, aid)
-     struct rx_call *call;
-     namelist *aname;
-     idlist *aid;
+SPR_NameToID(struct rx_call *call, namelist *aname, idlist *aid)
 {
     afs_int32 code;
 
     code = nameToID(call, aname, aid);
     osi_auditU(call, PTS_NmToIdEvent, code, AUD_END);
+    ViceLog(125, ("PTS_NameToID: code %d\n", code));
     return code;
 }
 
-afs_int32
-nameToID(call, aname, aid)
-     struct rx_call *call;
-     namelist *aname;
-     idlist *aid;
+static afs_int32
+nameToID(struct rx_call *call, namelist *aname, idlist *aid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
@@ -616,11 +615,37 @@ nameToID(call, aname, aid)
        ABORT_WITH(tt, code);
 
     for (i = 0; i < aname->namelist_len; i++) {
-       code = NameToID(tt, aname->namelist_val[i], &aid->idlist_val[i]);
+       char vname[256];
+       char *nameinst, *cell;
+
+       strncpy(vname, aname->namelist_val[i], sizeof(vname));
+       vname[sizeof(vname)-1] ='\0';
+
+       nameinst = vname;
+       cell = strchr(vname, '@');
+       if (cell) {
+           *cell = '\0';
+           cell++;
+       }
+
+       if (cell && afs_is_foreign_ticket_name(nameinst,NULL,cell,pr_realmName))
+           code = NameToID(tt, aname->namelist_val[i], &aid->idlist_val[i]);
+       else 
+           code = NameToID(tt, nameinst, &aid->idlist_val[i]);
+
        if (code != PRSUCCESS)
            aid->idlist_val[i] = ANONYMOUSID;
-       if (count++ > 50)
-           IOMGR_Poll(), count = 0;
+        osi_audit(PTS_NmToIdEvent, code, AUD_STR,
+                  aname->namelist_val[i], AUD_ID, aid->idlist_val[i], 
+                  AUD_END);
+       ViceLog(125, ("PTS_NameToID: code %d aname %s aid %d\n", code,
+                     aname->namelist_val[i], aid->idlist_val[i]));
+       if (count++ > 50) {
+#ifndef AFS_PTHREAD_ENV
+           IOMGR_Poll();
+#endif
+           count = 0;
+       }
     }
     aid->idlist_len = aname->namelist_len;
 
@@ -636,23 +661,18 @@ nameToID(call, aname, aid)
  * The array of ids and names is unlimited.
  */
 afs_int32
-SPR_IDToName(call, aid, aname)
-     struct rx_call *call;
-     idlist *aid;
-     namelist *aname;
+SPR_IDToName(struct rx_call *call, idlist *aid, namelist *aname)
 {
     afs_int32 code;
 
     code = idToName(call, aid, aname);
-    osi_auditU(call, PTS_IdToNmEvent, code, AUD_LONG, aid, AUD_END);
+    osi_auditU(call, PTS_IdToNmEvent, code, AUD_END);
+    ViceLog(125, ("PTS_IDToName: code %d\n", code));
     return code;
 }
 
-afs_int32
-idToName(call, aid, aname)
-     struct rx_call *call;
-     idlist *aid;
-     namelist *aname;
+static afs_int32
+idToName(struct rx_call *call, idlist *aid, namelist *aname)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
@@ -692,8 +712,16 @@ idToName(call, aid, aname)
        code = IDToName(tt, aid->idlist_val[i], aname->namelist_val[i]);
        if (code != PRSUCCESS)
            sprintf(aname->namelist_val[i], "%d", aid->idlist_val[i]);
-       if (count++ > 50)
-           IOMGR_Poll(), count = 0;
+        osi_audit(PTS_IdToNmEvent, code, AUD_ID, aid->idlist_val[i],
+                 AUD_STR, aname->namelist_val[i], AUD_END);
+       ViceLog(125, ("PTS_idToName: code %d aid %d aname %s\n", code,
+                     aid->idlist_val[i], aname->namelist_val[i]));
+       if (count++ > 50) {
+#ifndef AFS_PTHREAD_ENV
+           IOMGR_Poll();
+#endif
+           count = 0;
+       }
     }
     aname->namelist_len = aid->idlist_len;
 
@@ -704,25 +732,22 @@ idToName(call, aid, aname)
 }
 
 afs_int32
-SPR_Delete(call, aid)
-     struct rx_call *call;
-     afs_int32 aid;
+SPR_Delete(struct rx_call *call, afs_int32 aid)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = Delete(call, aid);
-    osi_auditU(call, PTS_DelEvent, code, AUD_LONG, aid, AUD_END);
+    code = Delete(call, aid, &cid);
+    osi_auditU(call, PTS_DelEvent, code, AUD_ID, aid, AUD_END);
+    ViceLog(5, ("PTS_Delete: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 }
 
-afs_int32
-Delete(call, aid)
-     struct rx_call *call;
-     afs_int32 aid;
+static afs_int32
+Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
-    afs_int32 cid;
     struct prentry tentry;
     afs_int32 loc, nptr;
     int count;
@@ -745,7 +770,7 @@ Delete(call, aid)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
 
@@ -758,14 +783,14 @@ Delete(call, aid)
        ABORT_WITH(tt, PRDBFAIL);
 
     /* Do some access checking */
-    if (tentry.owner != cid && !IsAMemberOf(tt, cid, SYSADMINID)
-       && !IsAMemberOf(tt, cid, tentry.owner) && !pr_noAuth)
+    if (tentry.owner != *cid && !IsAMemberOf(tt, *cid, SYSADMINID)
+       && !IsAMemberOf(tt, *cid, tentry.owner) && !pr_noAuth)
        ABORT_WITH(tt, PRPERM);
 
     /* Delete each continuation block as a separate transaction so that no one
      * transaction become to large to complete. */
     nptr = tentry.next;
-    while (nptr != (afs_int32) NULL) {
+    while (nptr != 0) {
        struct contentry centry;
        int i;
 
@@ -786,8 +811,10 @@ Delete(call, aid)
            if (code)
                ABORT_WITH(tt, code);
            tentry.count--;     /* maintain count */
+#ifndef AFS_PTHREAD_ENV
            if ((i & 3) == 0)
                IOMGR_Poll();
+#endif
        }
        tentry.next = centry.next;      /* thread out this block */
        code = FreeBlock(tt, nptr);     /* free continuation block */
@@ -801,7 +828,9 @@ Delete(call, aid)
        code = ubik_EndTrans(tt);
        if (code)
            return code;
+#ifndef AFS_PTHREAD_ENV
        IOMGR_Poll();           /* just to keep the connection alive */
+#endif
        code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
        if (code)
            return code;
@@ -826,7 +855,7 @@ Delete(call, aid)
     {
        struct prentryg *tentryg = (struct prentryg *)&tentry;
        nptr = tentryg->nextsg;
-       while (nptr != NULL) {
+       while (nptr != 0) {
            struct contentry centry;
            int i;
 
@@ -842,8 +871,10 @@ Delete(call, aid)
                if (code)
                    ABORT_WITH(tt, code);
                tentryg->countsg--;     /* maintain count */
+#ifndef AFS_PTHREAD_ENV
                if ((i & 3) == 0)
                    IOMGR_Poll();
+#endif
            }
            tentryg->nextsg = centry.next;      /* thread out this block */
            code = FreeBlock(tt, nptr); /* free continuation block */
@@ -857,7 +888,9 @@ Delete(call, aid)
            code = ubik_EndTrans(tt);
            if (code)
                return code;
+#ifndef AFS_PTHREAD_ENV
            IOMGR_Poll();       /* just to keep the connection alive */
+#endif
 
            code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
            if (code)
@@ -885,7 +918,7 @@ Delete(call, aid)
      * transaction, we start a new transaction every 50 entries. */
     count = 0;
     nptr = tentry.owned;
-    while (nptr != (afs_int32) NULL) {
+    while (nptr != 0) {
        struct prentry nentry;
 
        code = pr_ReadEntry(tt, 0, nptr, &nentry);
@@ -898,8 +931,10 @@ Delete(call, aid)
            if (code)
                ABORT_WITH(tt, code);
            count++;
+#ifndef AFS_PTHREAD_ENV
            if ((count & 3) == 0)
                IOMGR_Poll();
+#endif
        }
        if (count < 50)
            continue;
@@ -911,7 +946,9 @@ Delete(call, aid)
        code = ubik_EndTrans(tt);
        if (code)
            return code;
+#ifndef AFS_PTHREAD_ENV
        IOMGR_Poll();           /* just to keep the connection alive */
+#endif
        code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
        if (code)
            return code;
@@ -942,15 +979,24 @@ Delete(call, aid)
 }
 
 afs_int32
-SPR_UpdateEntry(call, aid, name, uentry)
-     struct rx_call *call;
-     afs_int32 aid;
-     char *name;
-     struct PrUpdateEntry *uentry;
+SPR_UpdateEntry(struct rx_call *call, afs_int32 aid, char *name, 
+               struct PrUpdateEntry *uentry)
+{
+    afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
+
+    code = UpdateEntry(call, aid, name, uentry, &cid);
+    osi_auditU(call, PTS_UpdEntEvent, code, AUD_ID, aid, AUD_STR, name, AUD_END);
+    ViceLog(5, ("PTS_UpdateEntry: code %d cid %d aid %d name %s\n", code, cid, aid, name));
+    return code;
+}
+
+afs_int32
+UpdateEntry(struct rx_call *call, afs_int32 aid, char *name, 
+           struct PrUpdateEntry *uentry, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
-    afs_int32 cid;
     struct prentry tentry;
     afs_int32 loc;
     int id = 0;
@@ -976,10 +1022,10 @@ SPR_UpdateEntry(call, aid, name, uentry)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
-    code = IsAMemberOf(tt, cid, SYSADMINID);
+    code = IsAMemberOf(tt, *cid, SYSADMINID);
     if (!code && !pr_noAuth)
        ABORT_WITH(tt, PRPERM);
 
@@ -1024,24 +1070,21 @@ SPR_UpdateEntry(call, aid, name, uentry)
 }
 
 afs_int32
-SPR_RemoveFromGroup(call, aid, gid)
-     struct rx_call *call;
-     afs_int32 aid;
-     afs_int32 gid;
+SPR_RemoveFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = removeFromGroup(call, aid, gid);
-    osi_auditU(call, PTS_RmFmGrpEvent, code, AUD_LONG, gid, AUD_LONG, aid,
+    code = removeFromGroup(call, aid, gid, &cid);
+    osi_auditU(call, PTS_RmFmGrpEvent, code, AUD_ID, gid, AUD_ID, aid,
               AUD_END);
+    ViceLog(5, ("PTS_RemoveFromGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid));
     return code;
 }
 
-afs_int32
-removeFromGroup(call, aid, gid)
-     struct rx_call *call;
-     afs_int32 aid;
-     afs_int32 gid;
+static afs_int32
+removeFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid, 
+               afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
@@ -1049,7 +1092,6 @@ removeFromGroup(call, aid, gid)
     afs_int32 tempg;
     struct prentry uentry;
     struct prentry gentry;
-    afs_int32 cid;
 
     code = Initdb();
     if (code != PRSUCCESS)
@@ -1064,7 +1106,7 @@ removeFromGroup(call, aid, gid)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
     tempu = FindByID(tt, aid);
@@ -1087,7 +1129,7 @@ removeFromGroup(call, aid, gid)
     if (uentry.flags & PRGRP)
        ABORT_WITH(tt, PRNOTUSER);
 #endif
-    if (!AccessOK(tt, cid, &gentry, PRP_REMOVE_MEM, 0))
+    if (!AccessOK(tt, *cid, &gentry, PRP_REMOVE_MEM, 0))
        ABORT_WITH(tt, PRPERM);
     code = RemoveFromEntry(tt, aid, gid);
     if (code != PRSUCCESS)
@@ -1111,30 +1153,24 @@ removeFromGroup(call, aid, gid)
 
 
 afs_int32
-SPR_GetCPS(call, aid, alist, over)
-     struct rx_call *call;
-     afs_int32 aid;
-     prlist *alist;
-     afs_int32 *over;
+SPR_GetCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = getCPS(call, aid, alist, over);
-    osi_auditU(call, PTS_GetCPSEvent, code, AUD_LONG, aid, AUD_END);
+    code = getCPS(call, aid, alist, over, &cid);
+    osi_auditU(call, PTS_GetCPSEvent, code, AUD_ID, aid, AUD_END);
+    ViceLog(125, ("PTS_GetCPS: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 }
 
-afs_int32
-getCPS(call, aid, alist, over)
-     struct rx_call *call;
-     afs_int32 aid;
-     prlist *alist;
-     afs_int32 *over;
+static afs_int32
+getCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over, 
+       afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 temp;
-    afs_int32 cid;
     struct prentry tentry;
 
     *over = 0;
@@ -1161,8 +1197,8 @@ getCPS(call, aid, alist, over)
        ABORT_WITH(tt, code);
 
     /* afs does authenticate now */
-    code = WhoIsThis(call, tt, &cid);
-    if (code || !AccessOK(tt, cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
+    code = WhoIsThis(call, tt, cid);
+    if (code || !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
        ABORT_WITH(tt, PRPERM);
 
     code = GetList(tt, &tentry, alist, 1);
@@ -1176,9 +1212,7 @@ getCPS(call, aid, alist, over)
 
 #ifdef IP_WILDCARDS
 int
-inCPS(CPS, id)
-     prlist CPS;
-     afs_int32 id;
+inCPS(prlist CPS, afs_int32 id)
 {
     int i;
 
@@ -1192,41 +1226,31 @@ inCPS(CPS, id)
 
 
 afs_int32
-SPR_GetCPS2(call, aid, ahost, alist, over)
-     struct rx_call *call;
-     afs_int32 aid;
-     afs_int32 ahost;
-     prlist *alist;
-     afs_int32 *over;
+SPR_GetCPS2(struct rx_call *call, afs_int32 aid, afs_int32 ahost, 
+           prlist *alist, afs_int32 *over)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = getCPS2(call, aid, ahost, alist, over);
-    osi_auditU(call, PTS_GetCPS2Event, code, AUD_LONG, aid, AUD_HOST, ahost,
+    code = getCPS2(call, aid, ahost, alist, over, &cid);
+    osi_auditU(call, PTS_GetCPS2Event, code, AUD_ID, aid, AUD_HOST, ahost,
               AUD_END);
+    ViceLog(125, ("PTS_GetCPS2: code %d cid %d aid %d ahost %d\n", code, cid, aid, ahost));
     return code;
 }
 
-afs_int32
-getCPS2(call, aid, ahost, alist, over)
-     struct rx_call *call;
-     afs_int32 aid;
-     afs_int32 ahost;
-     prlist *alist;
-     afs_int32 *over;
+static afs_int32
+getCPS2(struct rx_call *call, afs_int32 aid, afs_int32 ahost, prlist *alist, 
+       afs_int32 *over, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 temp;
-    afs_int32 cid;
     struct prentry tentry;
     struct prentry host_tentry;
     afs_int32 hostid;
     int host_list = 0;
     struct in_addr iaddr;
-#if IP_WILDCARDS
-    extern afs_int32 addWildCards();
-#endif /* IP_WILDCARDS */
 
     *over = 0;
     iaddr.s_addr = ntohl(ahost);
@@ -1254,9 +1278,9 @@ getCPS2(call, aid, ahost, alist, over)
            ABORT_WITH(tt, code);
 
        /* afs does authenticate now */
-       code = WhoIsThis(call, tt, &cid);
+       code = WhoIsThis(call, tt, cid);
        if (code
-           || !AccessOK(tt, cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
+           || !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
            ABORT_WITH(tt, PRPERM);
     }
     code = NameToID(tt, inet_ntoa(iaddr), &hostid);
@@ -1288,34 +1312,26 @@ getCPS2(call, aid, ahost, alist, over)
 
 
 afs_int32
-SPR_GetHostCPS(call, ahost, alist, over)
-     struct rx_call *call;
-     afs_int32 ahost;
-     prlist *alist;
-     afs_int32 *over;
+SPR_GetHostCPS(struct rx_call *call, afs_int32 ahost, prlist *alist, 
+              afs_int32 *over)
 {
     afs_int32 code;
 
     code = getHostCPS(call, ahost, alist, over);
     osi_auditU(call, PTS_GetHCPSEvent, code, AUD_HOST, ahost, AUD_END);
+    ViceLog(125, ("PTS_GetHostCPS: code %d ahost %d\n", code, ahost));
     return code;
 }
 
 afs_int32
-getHostCPS(call, ahost, alist, over)
-     struct rx_call *call;
-     afs_int32 ahost;
-     prlist *alist;
-     afs_int32 *over;
+getHostCPS(struct rx_call *call, afs_int32 ahost, prlist *alist, 
+          afs_int32 *over)
 {
     register afs_int32 code, temp;
     struct ubik_trans *tt;
     struct prentry host_tentry;
     afs_int32 hostid;
     struct in_addr iaddr;
-#if IP_WILDCARDS
-    extern afs_int32 addWildCards();
-#endif /* IP_WILDCARDS */
 
     *over = 0;
     iaddr.s_addr = ntohl(ahost);
@@ -1361,23 +1377,18 @@ getHostCPS(call, ahost, alist, over)
 
 
 afs_int32
-SPR_ListMax(call, uid, gid)
-     struct rx_call *call;
-     afs_int32 *uid;
-     afs_int32 *gid;
+SPR_ListMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
 {
     afs_int32 code;
 
     code = listMax(call, uid, gid);
     osi_auditU(call, PTS_LstMaxEvent, code, AUD_END);
+    ViceLog(125, ("PTS_ListMax: code %d\n", code));
     return code;
 }
 
 afs_int32
-listMax(call, uid, gid)
-     struct rx_call *call;
-     afs_int32 *uid;
-     afs_int32 *gid;
+listMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
@@ -1406,28 +1417,23 @@ listMax(call, uid, gid)
 }
 
 afs_int32
-SPR_SetMax(call, aid, gflag)
-     struct rx_call *call;
-     afs_int32 aid;
-     afs_int32 gflag;
+SPR_SetMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = setMax(call, aid, gflag);
-    osi_auditU(call, PTS_SetMaxEvent, code, AUD_LONG, aid, AUD_LONG, gflag,
+    code = setMax(call, aid, gflag, &cid);
+    osi_auditU(call, PTS_SetMaxEvent, code, AUD_ID, aid, AUD_LONG, gflag,
               AUD_END);
+    ViceLog(125, ("PTS_SetMax: code %d cid %d aid %d gflag %d\n", code, cid, aid, gflag));
     return code;
 }
 
-afs_int32
-setMax(call, aid, gflag)
-     struct rx_call *call;
-     afs_int32 aid;
-     afs_int32 gflag;
+static afs_int32
+setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
-    afs_int32 cid;
 
     code = Initdb();
     if (code != PRSUCCESS)
@@ -1442,10 +1448,10 @@ setMax(call, aid, gflag)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
-    if (!AccessOK(tt, cid, 0, 0, 0))
+    if (!AccessOK(tt, *cid, 0, 0, 0))
        ABORT_WITH(tt, PRPERM);
     if (((gflag & PRGRP) && (aid > 0)) || (!(gflag & PRGRP) && (aid < 0)))
        ABORT_WITH(tt, PRBADARG);
@@ -1461,27 +1467,23 @@ setMax(call, aid, gflag)
 }
 
 afs_int32
-SPR_ListEntry(call, aid, aentry)
-     struct rx_call *call;
-     afs_int32 aid;
-     struct prcheckentry *aentry;
+SPR_ListEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = listEntry(call, aid, aentry);
-    osi_auditU(call, PTS_LstEntEvent, code, AUD_LONG, aid, AUD_END);
+    code = listEntry(call, aid, aentry, &cid);
+    osi_auditU(call, PTS_LstEntEvent, code, AUD_ID, aid, AUD_END);
+    ViceLog(125, ("PTS_ListEntry: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 }
 
-afs_int32
-listEntry(call, aid, aentry)
-     struct rx_call *call;
-     afs_int32 aid;
-     struct prcheckentry *aentry;
+static afs_int32
+listEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry, 
+         afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
-    afs_int32 cid;
     afs_int32 temp;
     struct prentry tentry;
 
@@ -1498,7 +1500,7 @@ listEntry(call, aid, aentry)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
     temp = FindByID(tt, aid);
@@ -1507,15 +1509,15 @@ listEntry(call, aid, aentry)
     code = pr_ReadEntry(tt, 0, temp, &tentry);
     if (code != 0)
        ABORT_WITH(tt, code);
-    if (!AccessOK(tt, cid, &tentry, PRP_STATUS_MEM, PRP_STATUS_ANY))
+    if (!AccessOK(tt, *cid, &tentry, PRP_STATUS_MEM, PRP_STATUS_ANY))
        ABORT_WITH(tt, PRPERM);
 
     aentry->flags = tentry.flags >> PRIVATE_SHIFT;
     if (aentry->flags == 0) {
        if (tentry.flags & PRGRP)
-           aentry->flags = PRP_GROUP_DEFAULT >> PRIVATE_SHIFT;
+           aentry->flags = prp_group_default >> PRIVATE_SHIFT;
        else
-           aentry->flags = PRP_USER_DEFAULT >> PRIVATE_SHIFT;
+           aentry->flags = prp_user_default >> PRIVATE_SHIFT;
     }
     aentry->owner = tentry.owner;
     aentry->id = tentry.id;
@@ -1532,31 +1534,24 @@ listEntry(call, aid, aentry)
 }
 
 afs_int32
-SPR_ListEntries(call, flag, startindex, bulkentries, nextstartindex)
-     struct rx_call *call;
-     afs_int32 flag;
-     afs_int32 startindex;
-     prentries *bulkentries;
-     afs_int32 *nextstartindex;
+SPR_ListEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex, 
+               prentries *bulkentries, afs_int32 *nextstartindex)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = listEntries(call, flag, startindex, bulkentries, nextstartindex);
+    code = listEntries(call, flag, startindex, bulkentries, nextstartindex, &cid);
     osi_auditU(call, PTS_LstEntsEvent, code, AUD_LONG, flag, AUD_END);
+    ViceLog(125, ("PTS_ListEntries: code %d cid %d flag %d\n", code, cid, flag));
     return code;
 }
 
-afs_int32
-listEntries(call, flag, startindex, bulkentries, nextstartindex)
-     struct rx_call *call;
-     afs_int32 flag;
-     afs_int32 startindex;
-     prentries *bulkentries;
-     afs_int32 *nextstartindex;
+static afs_int32
+listEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex, 
+           prentries *bulkentries, afs_int32 *nextstartindex, afs_int32 *cid)
 {
     afs_int32 code;
     struct ubik_trans *tt;
-    afs_int32 cid;
     afs_int32 i, eof, pos, maxentries, f;
     struct prentry tentry;
     afs_int32 pollcount = 0;
@@ -1581,10 +1576,10 @@ listEntries(call, flag, startindex, bulkentries, nextstartindex)
     /* Make sure we are an authenticated caller and that we are on the
      * SYSADMIN list.
      */
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
-    code = IsAMemberOf(tt, cid, SYSADMINID);
+    code = IsAMemberOf(tt, *cid, SYSADMINID);
     if (!code && !pr_noAuth)
        ABORT_WITH(tt, PRPERM);
 
@@ -1597,7 +1592,9 @@ listEntries(call, flag, startindex, bulkentries, nextstartindex)
            goto done;
 
        if (++pollcount > 50) {
+#ifndef AFS_PTHREAD_ENV
            IOMGR_Poll();
+#endif
            pollcount = 0;
        }
 
@@ -1631,10 +1628,8 @@ listEntries(call, flag, startindex, bulkentries, nextstartindex)
 }
 
 #define PR_MAXENTRIES 500
-afs_int32
-put_prentries(tentry, bulkentries)
-     struct prentry *tentry;
-     prentries *bulkentries;
+static afs_int32
+put_prentries(struct prentry *tentry, prentries *bulkentries)
 {
     struct prlistentries *entry;
 
@@ -1659,7 +1654,7 @@ put_prentries(tentry, bulkentries)
     if (entry->flags == 0) {
        entry->flags =
            ((tentry->
-             flags & PRGRP) ? PRP_GROUP_DEFAULT : PRP_USER_DEFAULT) >>
+             flags & PRGRP) ? prp_group_default : prp_user_default) >>
            PRIVATE_SHIFT;
     }
     entry->owner = tentry->owner;
@@ -1675,33 +1670,26 @@ put_prentries(tentry, bulkentries)
 }
 
 afs_int32
-SPR_ChangeEntry(call, aid, name, oid, newid)
-     struct rx_call *call;
-     afs_int32 aid;
-     char *name;
-     afs_int32 oid;
-     afs_int32 newid;
+SPR_ChangeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid, 
+               afs_int32 newid)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = changeEntry(call, aid, name, oid, newid);
-    osi_auditU(call, PTS_ChgEntEvent, code, AUD_LONG, aid, AUD_STR, name,
+    code = changeEntry(call, aid, name, oid, newid, &cid);
+    osi_auditU(call, PTS_ChgEntEvent, code, AUD_ID, aid, AUD_STR, name,
               AUD_LONG, oid, AUD_LONG, newid, AUD_END);
+    ViceLog(5, ("PTS_ChangeEntry: code %d cid %d aid %d name %s oid %d newid %d\n", code, cid, aid, name, oid, newid));
     return code;
 }
 
-afs_int32
-changeEntry(call, aid, name, oid, newid)
-     struct rx_call *call;
-     afs_int32 aid;
-     char *name;
-     afs_int32 oid;
-     afs_int32 newid;
+static afs_int32
+changeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid, 
+           afs_int32 newid, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 pos;
-    afs_int32 cid;
 
     if (!name)
        return PRPERM;
@@ -1725,14 +1713,14 @@ changeEntry(call, aid, name, oid, newid)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
     pos = FindByID(tt, aid);
     if (!pos)
        ABORT_WITH(tt, PRNOENT);
     /* protection check in changeentry */
-    code = ChangeEntry(tt, aid, cid, name, oid, newid);
+    code = ChangeEntry(tt, aid, *cid, name, oid, newid);
     if (code != PRSUCCESS)
        ABORT_WITH(tt, code);
 
@@ -1741,34 +1729,33 @@ changeEntry(call, aid, name, oid, newid)
 }
 
 afs_int32
-SPR_SetFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1, spare2)
-     struct rx_call *call;
-     afs_int32 id;
-     afs_int32 mask;           /* specify which fields to update */
-     afs_int32 flags, ngroups, nusers;
-     afs_int32 spare1, spare2;
+SPR_SetFieldsEntry(struct rx_call *call, 
+                  afs_int32 id, 
+                  afs_int32 mask, /* specify which fields to update */ 
+                  afs_int32 flags, afs_int32 ngroups, afs_int32 nusers, 
+                  afs_int32 spare1, afs_int32 spare2)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
     code =
        setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1,
-                      spare2);
-    osi_auditU(call, PTS_SetFldEntEvent, code, AUD_LONG, id, AUD_END);
+                      spare2, &cid);
+    osi_auditU(call, PTS_SetFldEntEvent, code, AUD_ID, id, AUD_END);
+    ViceLog(5, ("PTS_SetFieldsEntry: code %d cid %d id %d\n", code, cid, id));
     return code;
 }
 
-afs_int32
-setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1, spare2)
-     struct rx_call *call;
-     afs_int32 id;
-     afs_int32 mask;           /* specify which fields to update */
-     afs_int32 flags, ngroups, nusers;
-     afs_int32 spare1, spare2;
+static afs_int32
+setFieldsEntry(struct rx_call *call, 
+              afs_int32 id, 
+              afs_int32 mask, /* specify which fields to update */ 
+              afs_int32 flags, afs_int32 ngroups, afs_int32 nusers, 
+              afs_int32 spare1, afs_int32 spare2, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 pos;
-    afs_int32 cid;
     struct prentry tentry;
     afs_int32 tflags;
 
@@ -1791,7 +1778,7 @@ setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1, spare2)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
     pos = FindByID(tt, id);
@@ -1803,13 +1790,13 @@ setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1, spare2)
     tflags = tentry.flags;
 
     if (mask & (PR_SF_NGROUPS | PR_SF_NUSERS)) {
-       if (!AccessOK(tt, cid, 0, 0, 0))
+       if (!AccessOK(tt, *cid, 0, 0, 0))
            ABORT_WITH(tt, PRPERM);
        if ((tflags & PRQUOTA) == 0) {  /* default if only setting one */
            tentry.ngroups = tentry.nusers = 20;
        }
     } else {
-       if (!AccessOK(tt, cid, &tentry, 0, 0))
+       if (!AccessOK(tt, *cid, &tentry, 0, 0))
            ABORT_WITH(tt, PRPERM);
     }
 
@@ -1844,29 +1831,24 @@ setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1, spare2)
 }
 
 afs_int32
-SPR_ListElements(call, aid, alist, over)
-     struct rx_call *call;
-     afs_int32 aid;
-     prlist *alist;
-     afs_int32 *over;
+SPR_ListElements(struct rx_call *call, afs_int32 aid, prlist *alist, 
+                afs_int32 *over)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = listElements(call, aid, alist, over);
-    osi_auditU(call, PTS_LstEleEvent, code, AUD_LONG, aid, AUD_END);
+    code = listElements(call, aid, alist, over, &cid);
+    osi_auditU(call, PTS_LstEleEvent, code, AUD_ID, aid, AUD_END);
+    ViceLog(125, ("PTS_ListElements: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 }
 
-afs_int32
-listElements(call, aid, alist, over)
-     struct rx_call *call;
-     afs_int32 aid;
-     prlist *alist;
-     afs_int32 *over;
+static afs_int32
+listElements(struct rx_call *call, afs_int32 aid, prlist *alist, 
+            afs_int32 *over, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
-    afs_int32 cid;
     afs_int32 temp;
     struct prentry tentry;
 
@@ -1887,7 +1869,7 @@ listElements(call, aid, alist, over)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
 
@@ -1897,7 +1879,7 @@ listElements(call, aid, alist, over)
     code = pr_ReadEntry(tt, 0, temp, &tentry);
     if (code)
        ABORT_WITH(tt, code);
-    if (!AccessOK(tt, cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
+    if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
        ABORT_WITH(tt, PRPERM);
 
     code = GetList(tt, &tentry, alist, 0);
@@ -1910,17 +1892,16 @@ listElements(call, aid, alist, over)
 
 
 afs_int32
-SPR_ListSuperGroups(call, aid, alist, over)
-     struct rx_call *call;
-     afs_int32 aid;
-     prlist *alist;
-     afs_int32 *over;
+SPR_ListSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist, 
+                   afs_int32 *over)
 {
 #if defined(SUPERGROUPS)
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = listSuperGroups(call, aid, alist, over);
-    osi_auditU(call, "PTS_LstSGrps", code, AUD_LONG, aid, AUD_END);
+    code = listSuperGroups(call, aid, alist, over, &cid);
+    osi_auditU(call, PTS_LstSGrps, code, AUD_ID, aid, AUD_END);
+    ViceLog(125, ("PTS_ListSuperGroups: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 #else
     return RXGEN_OPCODE;
@@ -1928,16 +1909,12 @@ SPR_ListSuperGroups(call, aid, alist, over)
 }
 
 #if defined(SUPERGROUPS)
-afs_int32
-listSuperGroups(call, aid, alist, over)
-     struct rx_call *call;
-     afs_int32 aid;
-     prlist *alist;
-     afs_int32 *over;
+static afs_int32
+listSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist, 
+               afs_int32 *over, afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
-    afs_int32 cid;
     afs_int32 temp;
     struct prentry tentry;
 
@@ -1953,7 +1930,7 @@ listSuperGroups(call, aid, alist, over)
     code = ubik_SetLock(tt, 1, 1, LOCKREAD);
     if (code)
        ABORT_WITH(tt, code);
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
 
@@ -1963,7 +1940,7 @@ listSuperGroups(call, aid, alist, over)
     code = pr_ReadEntry(tt, 0, temp, &tentry);
     if (code)
        ABORT_WITH(tt, code);
-    if (!AccessOK(tt, cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
+    if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
        ABORT_WITH(tt, PRPERM);
 
     code = GetSGList(tt, &tentry, alist);
@@ -1989,29 +1966,24 @@ listSuperGroups(call, aid, alist, over)
  * maximum value is enforced in GetOwnedChain().
  */
 afs_int32
-SPR_ListOwned(call, aid, alist, lastP)
-     struct rx_call *call;
-     afs_int32 aid;
-     prlist *alist;
-     afs_int32 *lastP;
+SPR_ListOwned(struct rx_call *call, afs_int32 aid, prlist *alist, 
+             afs_int32 *lastP)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = listOwned(call, aid, alist, lastP);
-    osi_auditU(call, PTS_LstOwnEvent, code, AUD_LONG, aid, AUD_END);
+    code = listOwned(call, aid, alist, lastP, &cid);
+    osi_auditU(call, PTS_LstOwnEvent, code, AUD_ID, aid, AUD_END);
+    ViceLog(125, ("PTS_ListOwned: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 }
 
 afs_int32
-listOwned(call, aid, alist, lastP)
-     struct rx_call *call;
-     afs_int32 aid;
-     prlist *alist;
-     afs_int32 *lastP;
+listOwned(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *lastP, 
+         afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
-    afs_int32 cid;
     struct prentry tentry;
     afs_int32 head = 0;
     afs_int32 start;
@@ -2037,7 +2009,7 @@ listOwned(call, aid, alist, lastP)
     if (code)
        ABORT_WITH(tt, code);
 
-    code = WhoIsThis(call, tt, &cid);
+    code = WhoIsThis(call, tt, cid);
     if (code)
        ABORT_WITH(tt, PRPERM);
 
@@ -2056,11 +2028,11 @@ listOwned(call, aid, alist, lastP)
            if (code)
                ABORT_WITH(tt, code);
 
-           if (!AccessOK(tt, cid, &tentry, -1, PRP_OWNED_ANY))
+           if (!AccessOK(tt, *cid, &tentry, -1, PRP_OWNED_ANY))
                ABORT_WITH(tt, PRPERM);
            head = tentry.owned;
        } else {
-           if (!AccessOK(tt, cid, 0, 0, 0))
+           if (!AccessOK(tt, *cid, 0, 0, 0))
                ABORT_WITH(tt, PRPERM);
            head = ntohl(cheader.orphan);
        }
@@ -2079,26 +2051,22 @@ listOwned(call, aid, alist, lastP)
 }
 
 afs_int32
-SPR_IsAMemberOf(call, uid, gid, flag)
-     struct rx_call *call;
-     afs_int32 uid;
-     afs_int32 gid;
-     afs_int32 *flag;
+SPR_IsAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid, 
+               afs_int32 *flag)
 {
     afs_int32 code;
+    afs_int32 cid = ANONYMOUSID;
 
-    code = isAMemberOf(call, uid, gid, flag);
+    code = isAMemberOf(call, uid, gid, flag, &cid);
     osi_auditU(call, PTS_IsMemOfEvent, code, AUD_LONG, uid, AUD_LONG, gid,
               AUD_END);
+    ViceLog(125, ("PTS_IsAMemberOf: code %d cid %d uid %d gid %d\n", code, cid, uid, gid));
     return code;
 }
 
-afs_int32
-isAMemberOf(call, uid, gid, flag)
-     struct rx_call *call;
-     afs_int32 uid;
-     afs_int32 gid;
-     afs_int32 *flag;
+static afs_int32
+isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid, afs_int32 *flag,
+           afs_int32 *cid)
 {
     register afs_int32 code;
     struct ubik_trans *tt;
@@ -2117,14 +2085,13 @@ isAMemberOf(call, uid, gid, flag)
        ABORT_WITH(tt, code);
 
     {
-       afs_int32 cid;
        afs_int32 uloc = FindByID(tt, uid);
        afs_int32 gloc = FindByID(tt, gid);
        struct prentry uentry, gentry;
 
        if (!uloc || !gloc)
            ABORT_WITH(tt, PRNOENT);
-       code = WhoIsThis(call, tt, &cid);
+       code = WhoIsThis(call, tt, cid);
        if (code)
            ABORT_WITH(tt, PRPERM);
        code = pr_ReadEntry(tt, 0, uloc, &uentry);
@@ -2140,8 +2107,8 @@ isAMemberOf(call, uid, gid, flag)
        if (!(gentry.flags & PRGRP))
            ABORT_WITH(tt, PRBADARG);
 #endif
-       if (!AccessOK(tt, cid, &uentry, 0, PRP_MEMBER_ANY)
-           && !AccessOK(tt, cid, &gentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
+       if (!AccessOK(tt, *cid, &uentry, 0, PRP_MEMBER_ANY)
+           && !AccessOK(tt, *cid, &gentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
            ABORT_WITH(tt, PRPERM);
     }
 
@@ -2150,25 +2117,9 @@ isAMemberOf(call, uid, gid, flag)
     return code;
 }
 
-
-static
-stolower(s)
-     register char *s;
-{
-    register int tc;
-    while ((tc = *s)) {
-       if (isupper(tc))
-           *s = tolower(tc);
-       s++;
-    }
-}
-
 #if IP_WILDCARDS
-afs_int32
-addWildCards(tt, alist, host)
-     struct ubik_trans *tt;
-     prlist *alist;
-     afs_int32 host;
+static afs_int32
+addWildCards(struct ubik_trans *tt, prlist *alist, afs_int32 host)
 {
     afs_int32 temp;
     struct prentry tentry;
@@ -2216,13 +2167,9 @@ addWildCards(tt, alist, host)
 }
 #endif /* IP_WILDCARDS */
 
-
-afs_int32
-WhoIsThisWithName(acall, at, aid, aname)
-     struct rx_call *acall;
-     struct ubik_trans *at;
-     afs_int32 *aid;
-     char *aname;
+static afs_int32
+WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid, 
+                 char *aname)
 {
     /* aid is set to the identity of the caller, if known, else ANONYMOUSID */
     /* returns -1 and sets aid to ANONYMOUSID on any failure */
@@ -2244,11 +2191,12 @@ WhoIsThisWithName(acall, at, aid, aname)
     } else if (code == 2) {    /* kad class */
 
        int clen;
-       extern char *pr_realmName;
 
        if ((code = rxkad_GetServerInfo(acall->conn, NULL, 0 /*was &exp */ ,
                                        name, inst, tcell, NULL)))
            goto done;
+
+
        strncpy(vname, name, sizeof(vname));
        if ((ilen = strlen(inst))) {
            if (strlen(vname) + 1 + ilen >= sizeof(vname))
@@ -2257,19 +2205,9 @@ WhoIsThisWithName(acall, at, aid, aname)
            strcat(vname, inst);
        }
        if ((clen = strlen(tcell))) {
+           int foreign = afs_is_foreign_ticket_name(name,inst,tcell,pr_realmName);
 
-#if    defined(AFS_ATHENA_STDENV) || defined(AFS_KERBREALM_ENV)
-           static char local_realm[AFS_REALM_SZ] = "";
-           if (!local_realm[0]) {
-               if (afs_krb_get_lrealm(local_realm, 0) != 0 /*KSUCCESS*/)
-                   strncpy(local_realm, pr_realmName, AFS_REALM_SZ);
-           }
-#endif
-           if (
-#if    defined(AFS_ATHENA_STDENV) || defined(AFS_KERBREALM_ENV)
-                  strcasecmp(local_realm, tcell) &&
-#endif
-                  strcasecmp(pr_realmName, tcell)) {
+           if (foreign) {
                if (strlen(vname) + 1 + clen >= sizeof(vname))
                    goto done;
                strcat(vname, "@");