ptserver: remove static local realms
[openafs.git] / src / ptserver / ptprocs.c
index 4c7b690..2aec8d3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
  *                             to groups. This is an error in normal AFS.
  *                          2. If adding a group to a group call AddToSGEntry
  *                             to add the id of the group it's a member of.
- *                      
+ *
  *                      (4) function Delete
  *
  *                          1. Print a messsage if an error is returned from
- *                             FindByID() and PTDEBUG is defined. 
- *                          2. If removing a group from a group call   
- *                             RemoveFromSGEntry to remove the id of the  
- *                             group it's a member of.            
+ *                             FindByID() and PTDEBUG is defined.
+ *                          2. If removing a group from a group call
+ *                             RemoveFromSGEntry to remove the id of the
+ *                             group it's a member of.
  *                          3. Remove supergroup continuation records.
  *
- *                      (5) function RemoveFromGroup 
- *               
+ *                      (5) function RemoveFromGroup
+ *
  *                          1. Eliminate the code that tests for adding groups
- *                             to groups. This is an error in normal AFS. 
- *                          2. If removing a group from a group call 
- *                             RemoveFromSGEntry to remove the id of the 
+ *                             to groups. This is an error in normal AFS.
+ *                          2. If removing a group from a group call
+ *                             RemoveFromSGEntry to remove the id of the
  *                             group it's a member of.
  *
- *                      (6) Add new functions PR_ListSuperGroups and 
+ *                      (6) Add new functions PR_ListSuperGroups and
  *                          listSuperGroups.
- *                      
+ *
  *                      (7) function isAMemberOf
- *                      
+ *
  *                          1. Allow groups to be members of groups.
  *
  *                      Transarc does not currently use opcodes past 520, but
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
+#include <afs/opr.h>
 
-#include <afs/stds.h>
 #include <ctype.h>
-#include <stdio.h>
+
 #include <lock.h>
 #include <afs/afsutil.h>
 #include <ubik.h>
@@ -63,105 +63,91 @@ RCSID
 #include <rx/rx.h>
 #include <rx/rxkad.h>
 #include <afs/auth.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#endif
-#include <string.h>
+#include <afs/cellconfig.h>
+
 #include "ptserver.h"
 #include "pterror.h"
 #include "ptprototypes.h"
 #include "afs/audit.h"
 
-#ifdef AFS_ATHENA_STDENV
-#include <krb.h>
-#endif
-
-
-#define        IP_WILDCARDS    1       /* XXX Should be defined outside of here XXX */
-
 extern int restricted;
 extern struct ubik_dbase *dbase;
 extern int pr_noAuth;
-extern afs_int32 initd;
-extern char *pr_realmName;
 extern int prp_group_default;
 extern int prp_user_default;
+extern struct afsconf_dir *prdir;
 
-static afs_int32 iNewEntry(struct rx_call *call, char aname[], afs_int32 aid, 
+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 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, 
+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, 
+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, 
+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, 
+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, 
+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,
+static afs_int32 getCPS2(struct rx_call *call, afs_int32 aid, afs_uint32 ahost,
                         prlist *alist, afs_int32 *over, afs_int32 *cid);
-static afs_int32 getHostCPS(struct rx_call *call, afs_int32 ahost, 
+static afs_int32 getHostCPS(struct rx_call *call, afs_uint32 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, 
+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, 
+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, 
+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, 
+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, 
+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)
-static afs_int32 listSuperGroups(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);
 #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, 
+static afs_int32 addWildCards(struct ubik_trans *tt, prlist *alist,
+                             afs_uint32 host);
+static afs_int32 WhoIsThisWithName(struct rx_call *acall,
+                                  struct ubik_trans *at, afs_int32 *aid,
                                   char *aname);
 
-/* 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(struct ubik_trans *ut, afs_int32 cid, afs_int32 oid, afs_int32 flag, 
+CreateOK(struct ubik_trans *ut, afs_int32 cid, afs_int32 oid, afs_int32 flag,
         int admin)
 {
-    if (restricted && !admin) 
+    if (restricted && !admin)
        return 0;
 
     if (flag & PRFOREIGN) {
-       /* Foreign users are recognized by the '@' sign and 
+       /* Foreign users are recognized by the '@' sign and
         * not by the PRFOREIGN flag.
         */
        return 0;
@@ -183,61 +169,10 @@ CreateOK(struct ubik_trans *ut, afs_int32 cid, afs_int32 oid, afs_int32 flag,
 afs_int32
 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 */
-    /* returns -1 and sets aid to ANONYMOUSID on any failure */
-    register struct rx_connection *tconn;
-    register afs_int32 code;
-    char tcell[MAXKTCREALMLEN];
-    char name[MAXKTCNAMELEN];
-    char inst[MAXKTCNAMELEN];
-    int ilen;
-    char vname[256];
-
-    *aid = ANONYMOUSID;
-    tconn = rx_ConnectionOf(acall);
-    code = rx_SecurityClassOf(tconn);
-    if (code == 0)
-       return 0;
-    else if (code == 1) {      /* vab class */
-       goto done;              /* no longer supported */
-    } else if (code == 2) {    /* kad class */
-       if ((code = rxkad_GetServerInfo(acall->conn, NULL, 0 /*was &exp */ ,
-                                       name, inst, tcell, NULL)))
-           goto done;
-#if 0
-       /* This test is unnecessary, since rxkad_GetServerInfo already check.
-        * In addition, this is wrong since exp must be unsigned. */
-       if (exp < FT_ApproxTime())
-           goto done;
-#endif
-       if (tcell[0])
-           foreign = afs_is_foreign_ticket_name(name,inst,tcell,pr_realmName);
-
-       strncpy(vname, name, sizeof(vname));
-       if ((ilen = strlen(inst))) {
-           if (strlen(vname) + 1 + ilen >= sizeof(vname))
-               goto done;
-           strcat(vname, ".");
-           strcat(vname, inst);
-       }
-       if (foreign) {
-           if (strlen(vname) + strlen(tcell) + 1 >= sizeof(vname))
-               goto done;
-           strcat(vname, "@");
-           strcat(vname, tcell);
-       }
-       if (strcmp(AUTH_SUPERUSER, vname) == 0)
-           *aid = SYSADMINID;  /* special case for the fileserver */
-       else {
-           lcstring(vname, vname, sizeof(vname));
-           code = NameToID(at, vname, aid);
-       }
-    }
-  done:
-    if (code && !pr_noAuth)
-       return -1;
-    return 0;
+    int code = WhoIsThisWithName(acall, at, aid, NULL);
+    if (code == 2 && *aid == ANONYMOUSID)
+       return PRNOENT;
+    return code;
 }
 
 afs_int32
@@ -249,18 +184,18 @@ SPR_INewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid)
     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(25, ("PTS_INewEntry: code %d cid %d aid %d aname %s oid %d", code, cid, aid, aname, oid));
+    ViceLog(5, ("PTS_INewEntry: code %d cid %d aid %d aname %s oid %d\n", code, cid, aid, aname, oid));
     return code;
 }
 
 static afs_int32
-iNewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid, 
+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 code;
     afs_int32 gflag = 0;
     int admin;
 
@@ -312,7 +247,7 @@ iNewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid,
 
 
 afs_int32
-SPR_NewEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid, 
+SPR_NewEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
             afs_int32 *aid)
 {
     afs_int32 code;
@@ -321,15 +256,15 @@ SPR_NewEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
     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(25, ("PTS_NewEntry: code %d cid %d aid %d aname %s oid %d", code, cid, *aid, aname, oid));
+    ViceLog(5, ("PTS_NewEntry: code %d cid %d aid %d aname %s oid %d\n", code, cid, *aid, aname, oid));
     return code;
 }
 
 static afs_int32
-newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid, 
+newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
         afs_int32 *aid, afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     int admin;
     char cname[PR_MAXNAMELEN];
@@ -348,7 +283,7 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
        ABORT_WITH(tt, code);
 
     /* this is for cross-cell self registration. It is not added in the
-     * SPR_INewEntry because we want self-registration to only do 
+     * SPR_INewEntry because we want self-registration to only do
      * automatic id assignment.
      */
     code = WhoIsThisWithName(call, tt, cid, cname);
@@ -384,14 +319,14 @@ SPR_WhereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *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", code, cid, aid, *apos));
+    ViceLog(125, ("PTS_WhereIsIt: code %d cid %d aid %d apos %d\n", code, cid, aid, *apos));
     return code;
 }
 
 static afs_int32
 whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos, afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 temp;
 
@@ -424,7 +359,7 @@ whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos, afs_int32 *cid)
 
 
 afs_int32
-SPR_DumpEntry(struct rx_call *call, afs_int32 apos, 
+SPR_DumpEntry(struct rx_call *call, afs_int32 apos,
              struct prdebugentry *aentry)
 {
     afs_int32 code;
@@ -432,15 +367,15 @@ SPR_DumpEntry(struct rx_call *call, afs_int32 apos,
 
     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", code, cid, apos));
+    ViceLog(125, ("PTS_DumpEntry: code %d cid %d apos %d\n", code, cid, apos));
     return code;
 }
 
 static afs_int32
-dumpEntry(struct rx_call *call, afs_int32 apos, struct prdebugentry *aentry, 
+dumpEntry(struct rx_call *call, afs_int32 apos, struct prdebugentry *aentry,
          afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
 
     code = Initdb();
@@ -490,14 +425,14 @@ SPR_AddToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
     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", code, cid, gid, aid));
+    ViceLog(5, ("PTS_AddToGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid));
     return code;
 }
 
 static afs_int32
 addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid, afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 tempu;
     afs_int32 tempg;
@@ -576,14 +511,14 @@ SPR_NameToID(struct rx_call *call, namelist *aname, idlist *aid)
 
     code = nameToID(call, aname, aid);
     osi_auditU(call, PTS_NmToIdEvent, code, AUD_END);
-    ViceLog(125, ("PTS_NameToID: code %d", code));
+    ViceLog(125, ("PTS_NameToID: code %d\n", code));
     return code;
 }
 
 static afs_int32
 nameToID(struct rx_call *call, namelist *aname, idlist *aid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 i;
     int size;
@@ -619,6 +554,7 @@ nameToID(struct rx_call *call, namelist *aname, idlist *aid)
     for (i = 0; i < aname->namelist_len; i++) {
        char vname[256];
        char *nameinst, *cell;
+       afs_int32 islocal = 1;
 
        strncpy(vname, aname->namelist_val[i], sizeof(vname));
        vname[sizeof(vname)-1] ='\0';
@@ -630,17 +566,23 @@ nameToID(struct rx_call *call, namelist *aname, idlist *aid)
            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 
+       if (cell && *cell) {
+           code = afsconf_IsLocalRealmMatch(prdir, &islocal, nameinst, NULL, cell);
+           ViceLog(0,
+                   ("PTS_NameToID: afsconf_IsLocalRealmMatch(); code=%d, nameinst=%s, cell=%s\n",
+                    code, nameinst, cell));
+       }
+       if (islocal)
            code = NameToID(tt, nameinst, &aid->idlist_val[i]);
+       else
+           code = NameToID(tt, aname->namelist_val[i], &aid->idlist_val[i]);
 
        if (code != PRSUCCESS)
            aid->idlist_val[i] = ANONYMOUSID;
         osi_audit(PTS_NmToIdEvent, code, AUD_STR,
-                  aname->namelist_val[i], AUD_ID, aid->idlist_val[i], 
+                  aname->namelist_val[i], AUD_ID, aid->idlist_val[i],
                   AUD_END);
-       ViceLog(125, ("PTS_NameToID: code %d aname %s aid %d", code,
+       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
@@ -669,14 +611,14 @@ SPR_IDToName(struct rx_call *call, idlist *aid, namelist *aname)
 
     code = idToName(call, aid, aname);
     osi_auditU(call, PTS_IdToNmEvent, code, AUD_END);
-    ViceLog(125, ("PTS_IDToName: code %d", code));
+    ViceLog(125, ("PTS_IDToName: code %d\n", code));
     return code;
 }
 
 static afs_int32
 idToName(struct rx_call *call, idlist *aid, namelist *aname)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 i;
     int size;
@@ -716,7 +658,7 @@ idToName(struct rx_call *call, idlist *aid, namelist *aname)
            sprintf(aname->namelist_val[i], "%d", aid->idlist_val[i]);
         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", code,
+       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
@@ -741,14 +683,14 @@ SPR_Delete(struct rx_call *call, afs_int32 aid)
 
     code = Delete(call, aid, &cid);
     osi_auditU(call, PTS_DelEvent, code, AUD_ID, aid, AUD_END);
-    ViceLog(25, ("PTS_Delete: code %d cid %d aid %d", code, cid, aid));
+    ViceLog(5, ("PTS_Delete: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 }
 
 static afs_int32
 Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     struct prentry tentry;
     afs_int32 loc, nptr;
@@ -792,7 +734,7 @@ Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid)
     /* 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;
 
@@ -857,7 +799,7 @@ Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid)
     {
        struct prentryg *tentryg = (struct prentryg *)&tentry;
        nptr = tentryg->nextsg;
-       while (nptr != NULL) {
+       while (nptr != 0) {
            struct contentry centry;
            int i;
 
@@ -920,7 +862,7 @@ Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid)
      * 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);
@@ -981,7 +923,7 @@ Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid)
 }
 
 afs_int32
-SPR_UpdateEntry(struct rx_call *call, afs_int32 aid, char *name, 
+SPR_UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
                struct PrUpdateEntry *uentry)
 {
     afs_int32 code;
@@ -989,15 +931,15 @@ SPR_UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
 
     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", code, cid, aid, name));
+    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, 
+UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
            struct PrUpdateEntry *uentry, afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     struct prentry tentry;
     afs_int32 loc;
@@ -1080,15 +1022,15 @@ SPR_RemoveFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
     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", code, cid, gid, aid));
+    ViceLog(5, ("PTS_RemoveFromGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid));
     return code;
 }
 
 static afs_int32
-removeFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid, 
+removeFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid,
                afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 tempu;
     afs_int32 tempg;
@@ -1162,15 +1104,15 @@ SPR_GetCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over)
 
     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", code, cid, aid));
+    ViceLog(125, ("PTS_GetCPS: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 }
 
 static afs_int32
-getCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over, 
+getCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over,
        afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 temp;
     struct prentry tentry;
@@ -1212,7 +1154,6 @@ getCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over,
 }
 
 
-#ifdef IP_WILDCARDS
 int
 inCPS(prlist CPS, afs_int32 id)
 {
@@ -1224,28 +1165,27 @@ inCPS(prlist CPS, afs_int32 id)
     }
     return (0);
 }
-#endif /* IP_WILDCARDS */
 
 
 afs_int32
-SPR_GetCPS2(struct rx_call *call, afs_int32 aid, afs_int32 ahost, 
+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, &cid);
-    osi_auditU(call, PTS_GetCPS2Event, code, AUD_ID, aid, AUD_HOST, ahost,
+    osi_auditU(call, PTS_GetCPS2Event, code, AUD_ID, aid, AUD_HOST, htonl(ahost),
               AUD_END);
-    ViceLog(125, ("PTS_GetCPS2: code %d cid %d aid %d ahost %d", code, cid, aid, ahost));
+    ViceLog(125, ("PTS_GetCPS2: code %d cid %d aid %d ahost %d\n", code, cid, aid, ahost));
     return code;
 }
 
 static afs_int32
-getCPS2(struct rx_call *call, afs_int32 aid, afs_int32 ahost, prlist *alist, 
+getCPS2(struct rx_call *call, afs_int32 aid, afs_uint32 ahost, prlist *alist,
        afs_int32 *over, afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 temp;
     struct prentry tentry;
@@ -1301,10 +1241,8 @@ getCPS2(struct rx_call *call, afs_int32 aid, afs_int32 ahost, prlist *alist,
        code = GetList2(tt, &tentry, &host_tentry, alist, 1);
     else
        code = GetList(tt, &tentry, alist, 1);
-#if IP_WILDCARDS
     if (!code)
        code = addWildCards(tt, alist, ntohl(ahost));
-#endif /* IP_WILDCARDS */
     if (code != PRSUCCESS)
        ABORT_WITH(tt, code);
 
@@ -1314,22 +1252,22 @@ getCPS2(struct rx_call *call, afs_int32 aid, afs_int32 ahost, prlist *alist,
 
 
 afs_int32
-SPR_GetHostCPS(struct rx_call *call, afs_int32 ahost, prlist *alist, 
+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", code, ahost));
+    osi_auditU(call, PTS_GetHCPSEvent, code, AUD_HOST, htonl(ahost), AUD_END);
+    ViceLog(125, ("PTS_GetHostCPS: code %d ahost %d\n", code, ahost));
     return code;
 }
 
 afs_int32
-getHostCPS(struct rx_call *call, afs_int32 ahost, prlist *alist, 
+getHostCPS(struct rx_call *call, afs_uint32 ahost, prlist *alist,
           afs_int32 *over)
 {
-    register afs_int32 code, temp;
+    afs_int32 code, temp;
     struct ubik_trans *tt;
     struct prentry host_tentry;
     afs_int32 hostid;
@@ -1366,9 +1304,7 @@ getHostCPS(struct rx_call *call, afs_int32 ahost, prlist *alist,
        } else
            fprintf(stderr, "FindByID Failed -- Not found\n");
     }
-#if IP_WILDCARDS
     code = addWildCards(tt, alist, ntohl(ahost));
-#endif /* IP_WILDCARDS */
   bad:
     if (code != PRSUCCESS)
        ABORT_WITH(tt, code);
@@ -1385,14 +1321,14 @@ SPR_ListMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
 
     code = listMax(call, uid, gid);
     osi_auditU(call, PTS_LstMaxEvent, code, AUD_END);
-    ViceLog(125, ("PTS_ListMax: code %d", code));
+    ViceLog(125, ("PTS_ListMax: code %d\n", code));
     return code;
 }
 
 afs_int32
 listMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
 
     code = Initdb();
@@ -1427,14 +1363,14 @@ SPR_SetMax(struct rx_call *call, afs_int32 aid, afs_int32 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", code, cid, aid, gflag));
+    ViceLog(125, ("PTS_SetMax: code %d cid %d aid %d gflag %d\n", code, cid, aid, gflag));
     return code;
 }
 
 static afs_int32
 setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag, afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
 
     code = Initdb();
@@ -1476,15 +1412,15 @@ SPR_ListEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry)
 
     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", code, cid, aid));
+    ViceLog(125, ("PTS_ListEntry: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 }
 
 static afs_int32
-listEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry, 
+listEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry,
          afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 temp;
     struct prentry tentry;
@@ -1536,7 +1472,7 @@ listEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry,
 }
 
 afs_int32
-SPR_ListEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex, 
+SPR_ListEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
                prentries *bulkentries, afs_int32 *nextstartindex)
 {
     afs_int32 code;
@@ -1544,12 +1480,12 @@ SPR_ListEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
 
     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", code, cid, flag));
+    ViceLog(125, ("PTS_ListEntries: code %d cid %d flag %d\n", code, cid, flag));
     return code;
 }
 
 static afs_int32
-listEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex, 
+listEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
            prentries *bulkentries, afs_int32 *nextstartindex, afs_int32 *cid)
 {
     afs_int32 code;
@@ -1672,7 +1608,7 @@ put_prentries(struct prentry *tentry, prentries *bulkentries)
 }
 
 afs_int32
-SPR_ChangeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid, 
+SPR_ChangeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid,
                afs_int32 newid)
 {
     afs_int32 code;
@@ -1681,15 +1617,15 @@ SPR_ChangeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid,
     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", code, cid, aid, name, oid, newid));
+    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;
 }
 
 static afs_int32
-changeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid, 
+changeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid,
            afs_int32 newid, afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 pos;
 
@@ -1731,10 +1667,10 @@ changeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid,
 }
 
 afs_int32
-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, 
+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;
@@ -1744,18 +1680,18 @@ SPR_SetFieldsEntry(struct rx_call *call,
        setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1,
                       spare2, &cid);
     osi_auditU(call, PTS_SetFldEntEvent, code, AUD_ID, id, AUD_END);
-    ViceLog(5, ("PTS_SetFieldsEntry: code %d cid %d id %d", code, cid, id));
+    ViceLog(5, ("PTS_SetFieldsEntry: code %d cid %d id %d\n", code, cid, id));
     return code;
 }
 
 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, 
+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;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 pos;
     struct prentry tentry;
@@ -1833,7 +1769,7 @@ setFieldsEntry(struct rx_call *call,
 }
 
 afs_int32
-SPR_ListElements(struct rx_call *call, afs_int32 aid, prlist *alist, 
+SPR_ListElements(struct rx_call *call, afs_int32 aid, prlist *alist,
                 afs_int32 *over)
 {
     afs_int32 code;
@@ -1841,15 +1777,15 @@ SPR_ListElements(struct rx_call *call, afs_int32 aid, prlist *alist,
 
     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", code, cid, aid));
+    ViceLog(125, ("PTS_ListElements: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 }
 
 static afs_int32
-listElements(struct rx_call *call, afs_int32 aid, prlist *alist, 
+listElements(struct rx_call *call, afs_int32 aid, prlist *alist,
             afs_int32 *over, afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 temp;
     struct prentry tentry;
@@ -1894,7 +1830,7 @@ listElements(struct rx_call *call, afs_int32 aid, prlist *alist,
 
 
 afs_int32
-SPR_ListSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist, 
+SPR_ListSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
                    afs_int32 *over)
 {
 #if defined(SUPERGROUPS)
@@ -1903,7 +1839,7 @@ SPR_ListSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
 
     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", code, cid, aid));
+    ViceLog(125, ("PTS_ListSuperGroups: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 #else
     return RXGEN_OPCODE;
@@ -1912,10 +1848,10 @@ SPR_ListSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
 
 #if defined(SUPERGROUPS)
 static afs_int32
-listSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist, 
+listSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
                afs_int32 *over, afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
     afs_int32 temp;
     struct prentry tentry;
@@ -1960,7 +1896,7 @@ listSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
 
 #endif /* SUPERGROUPS */
 
-/* 
+/*
  * SPR_ListOwned
  * List the entries owned by this id.  If the id is zero,
  * return the orphans list. This will return up to PR_MAXGROUPS
@@ -1968,7 +1904,7 @@ listSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
  * maximum value is enforced in GetOwnedChain().
  */
 afs_int32
-SPR_ListOwned(struct rx_call *call, afs_int32 aid, prlist *alist, 
+SPR_ListOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
              afs_int32 *lastP)
 {
     afs_int32 code;
@@ -1976,15 +1912,15 @@ SPR_ListOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
 
     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", code, cid, aid));
+    ViceLog(125, ("PTS_ListOwned: code %d cid %d aid %d\n", code, cid, aid));
     return code;
 }
 
 afs_int32
-listOwned(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;
+    afs_int32 code;
     struct ubik_trans *tt;
     struct prentry tentry;
     afs_int32 head = 0;
@@ -2053,7 +1989,7 @@ listOwned(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *lastP,
 }
 
 afs_int32
-SPR_IsAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid, 
+SPR_IsAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid,
                afs_int32 *flag)
 {
     afs_int32 code;
@@ -2062,7 +1998,7 @@ SPR_IsAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid,
     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", code, cid, uid, gid));
+    ViceLog(125, ("PTS_IsAMemberOf: code %d cid %d uid %d gid %d\n", code, cid, uid, gid));
     return code;
 }
 
@@ -2070,7 +2006,7 @@ static afs_int32
 isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid, afs_int32 *flag,
            afs_int32 *cid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct ubik_trans *tt;
 
     code = Initdb();
@@ -2119,9 +2055,8 @@ isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid, afs_int32 *flag,
     return code;
 }
 
-#if IP_WILDCARDS
 static afs_int32
-addWildCards(struct ubik_trans *tt, prlist *alist, afs_int32 host)
+addWildCards(struct ubik_trans *tt, prlist *alist, afs_uint32 host)
 {
     afs_int32 temp;
     struct prentry tentry;
@@ -2167,16 +2102,16 @@ addWildCards(struct ubik_trans *tt, prlist *alist, afs_int32 host)
        qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
     return 0;
 }
-#endif /* IP_WILDCARDS */
 
 static afs_int32
-WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid, 
+WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid,
                  char *aname)
 {
+    afs_int32 islocal = 1;
     /* aid is set to the identity of the caller, if known, else ANONYMOUSID */
     /* returns -1 and sets aid to ANONYMOUSID on any failure */
-    register struct rx_connection *tconn;
-    register afs_int32 code;
+    struct rx_connection *tconn;
+    afs_int32 code;
     char tcell[MAXKTCREALMLEN];
     char name[MAXKTCNAMELEN];
     char inst[MAXKTCNAMELEN];
@@ -2191,14 +2126,15 @@ WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid,
     else if (code == 1) {      /* vab class */
        goto done;              /* no longer supported */
     } else if (code == 2) {    /* kad class */
-
-       int clen;
-
-       if ((code = rxkad_GetServerInfo(acall->conn, NULL, 0 /*was &exp */ ,
+       if ((code = rxkad_GetServerInfo(rx_ConnectionOf(acall), NULL, NULL,
                                        name, inst, tcell, NULL)))
            goto done;
 
-
+       if (tcell[0]) {
+           code = afsconf_IsLocalRealmMatch(prdir, &islocal, name, inst, tcell);
+           if (code)
+               goto done;
+       }
        strncpy(vname, name, sizeof(vname));
        if ((ilen = strlen(inst))) {
            if (strlen(vname) + 1 + ilen >= sizeof(vname))
@@ -2206,19 +2142,16 @@ WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid,
            strcat(vname, ".");
            strcat(vname, inst);
        }
-       if ((clen = strlen(tcell))) {
-           int foreign = afs_is_foreign_ticket_name(name,inst,tcell,pr_realmName);
-
-           if (foreign) {
-               if (strlen(vname) + 1 + clen >= sizeof(vname))
-                   goto done;
-               strcat(vname, "@");
-               strcat(vname, tcell);
-               lcstring(vname, vname, sizeof(vname));
-               code = NameToID(at, vname, aid);
+       if (!islocal) {
+            if (strlen(vname) + strlen(tcell) + 1  >= sizeof(vname))
+               goto done;
+            strcat(vname, "@");
+            strcat(vname, tcell);
+            lcstring(vname, vname, sizeof(vname));
+            code = NameToID(at, vname, aid);
+            if (aname)
                strcpy(aname, vname);
-               return 2;
-           }
+            return 2;
        }
 
        if (strcmp(AUTH_SUPERUSER, vname) == 0)