Add rx security index enum
[openafs.git] / src / viced / host.c
index 01ebee9..8796bdd 100644 (file)
@@ -266,9 +266,8 @@ hpr_Initialize(struct ubik_client **uclient)
 {
     afs_int32 code;
     struct rx_connection *serverconns[MAXSERVERS];
-    struct rx_securityClass *sc[3];
+    struct rx_securityClass *sc;
     struct afsconf_dir *tdir;
-    struct ktc_token ttoken;
     afs_int32 scIndex;
     struct afsconf_cell info;
     afs_int32 i;
@@ -289,7 +288,8 @@ hpr_Initialize(struct ubik_client **uclient)
     
     code = afsconf_GetCellInfo(tdir, cellstr, "afsprot", &info);
     if (code) {
-       ViceLog(0, ("hpr_Initialize: Could not locate cell %s in %s/%s", cellstr, confDir, AFSDIR_CELLSERVDB_FILE));
+       ViceLog(0, ("hpr_Initialize: Could not locate cell %s in %s/%s",
+                   cellstr, confDir->name, AFSDIR_CELLSERVDB_FILE));
        afsconf_Close(tdir);
        return code;
     }
@@ -301,55 +301,29 @@ hpr_Initialize(struct ubik_client **uclient)
         return code;
     }
     
-    scIndex = 2;
-    sc[0] = 0;
-    sc[1] = 0;
-    sc[2] = 0;
     /* Most callers use secLevel==1, however, the fileserver uses secLevel==2
      * to force use of the KeyFile.  secLevel == 0 implies -noauth was
      * specified. */
     if ((afsconf_GetLatestKey(tdir, 0, 0) == 0)) {
-        code = afsconf_ClientAuthSecure(tdir, &sc[2], &scIndex);
+        code = afsconf_ClientAuthSecure(tdir, &sc, &scIndex);
         if (code)
            ViceLog(0, ("hpr_Initialize: clientauthsecure returns %d %s (so trying noauth)", code, afs_error_message(code)));
         if (code)
-            scIndex = 0;        /* use noauth */
-        if (scIndex != 2)
-            /* if there was a problem, an unauthenticated conn is returned */
-            sc[scIndex] = sc[2];
+            scIndex = RX_SECIDX_NULL;
     } else {
-        struct ktc_principal sname;
-        strcpy(sname.cell, info.name);
-        sname.instance[0] = 0;
-        strcpy(sname.name, "afs");
-        code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
-        if (code)
-            scIndex = 0;
-        else {
-            if (ttoken.kvno >= 0 && ttoken.kvno <= 256)
-                /* this is a kerberos ticket, set scIndex accordingly */
-                scIndex = 2;
-            else {
-                ViceLog(0, ("hpr_Initialize: funny kvno (%d) in ticket, proceeding", ttoken.kvno));
-                scIndex = 2;
-            }
-            sc[2] =
-                rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
-                                              ttoken.kvno, ttoken.ticketLen,
-                                              ttoken.ticket);
-        }
+       afsconf_ClientAuthToken(&info, 0, &sc, &scIndex, NULL);
     }
-    if ((scIndex == 0) && (sc[0] == 0))
-        sc[0] = rxnull_NewClientSecurityObject();
-    if ((scIndex == 0))
+    if ((scIndex == RX_SECIDX_NULL) && (sc == NULL))
+        sc = rxnull_NewClientSecurityObject();
+    if (scIndex == RX_SECIDX_NULL)
        ViceLog(0, ("hpr_Initialize: Could not get afs tokens, running unauthenticated. [%d]", code));
     
     memset(serverconns, 0, sizeof(serverconns));        /* terminate list!!! */
     for (i = 0; i < info.numServers; i++) {
         serverconns[i] =
             rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
-                             info.hostAddr[i].sin_port, PRSRV, sc[scIndex],
-                             scIndex);
+                             info.hostAddr[i].sin_port, PRSRV,
+                            sc, scIndex);
     }
 
     code = ubik_ClientInit(serverconns, uclient);
@@ -357,7 +331,7 @@ hpr_Initialize(struct ubik_client **uclient)
        ViceLog(0, ("hpr_Initialize: ubik client init failed. [%d]", code));
     }
     afsconf_Close(tdir);
-    code = rxs_Release(sc[scIndex]);
+    code = rxs_Release(sc);
     return code;
 }
 
@@ -659,12 +633,12 @@ h_gethostcps_r(register struct host *host, register afs_int32 now)
             */
            host->hcpsfailed = 1;
            ViceLog(0,
-                   ("Warning:  GetHostCPS failed (%d) for %x (%s:%d); will retry\n",
+                   ("Warning:  GetHostCPS failed (%d) for %p (%s:%d); will retry\n",
                     code, host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
        } else {
            host->hcpsfailed = 0;
            ViceLog(1,
-                   ("gethost:  GetHostCPS failed (%d) for %x (%s:%d); ignored\n",
+                   ("gethost:  GetHostCPS failed (%d) for %p (%s:%d); ignored\n",
                     code, host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
        }
        if (host->hcps.prlist_val)
@@ -892,7 +866,8 @@ h_TossStuff_r(register struct host *host)
            if (code < 0) {
                char hoststr[16];
                ViceLog(0,
-                       ("Warning: h_TossStuff_r failed: Host %" AFS_PTR_FMT " (%s:%d) client %x was locked.\n",
+                       ("Warning: h_TossStuff_r failed: Host %p (%s:%d) "
+                        "client %p was locked.\n",
                         host, afs_inet_ntoa_r(host->host, hoststr),
                         ntohs(host->port), client));
                return;
@@ -901,7 +876,8 @@ h_TossStuff_r(register struct host *host)
            if (client->refCount) {
                char hoststr[16];
                ViceLog(0,
-                       ("Warning: h_TossStuff_r failed: Host %" AFS_PTR_FMT " (%s:%d) client %x refcount %d.\n",
+                       ("Warning: h_TossStuff_r failed: Host %p (%s:%d) "
+                        "client %p refcount %d.\n",
                         host, afs_inet_ntoa_r(host->host, hoststr),
                         ntohs(host->port), client, client->refCount));
                /* This is the same thing we do if the host is locked */
@@ -1117,9 +1093,9 @@ h_AddHostToUuidHashTable_r(struct afsUUID *uuid, struct host *host)
               return;
      afsUUID_to_string(uuid, uuid2, 127);
      ViceLog(125, 
-            ("h_AddHostToUuidHashTable_r: host %" AFS_PTR_FMT " (%s:%d) added as uuid %s\n",
+            ("h_AddHostToUuidHashTable_r: host %p (%s:%d) added as uuid %s\n",
              host, afs_inet_ntoa_r(chain->hostPtr->host, hoststr), 
-             ntohs(chain->hostPtr->port), uuid));
+             ntohs(chain->hostPtr->port), uuid2));
 }
 
 /* deletes a HashChain structure corresponding to this host */
@@ -1164,27 +1140,29 @@ h_AddHostToAddrHashTable_r(afs_uint32 addr, afs_uint16 port, struct host *host)
 {
     int index;
     struct h_AddrHashChain *chain;
-    char hoststr[16], hoststr2[16];
+    char hoststr[16];
 
     /* hash into proper bucket */
     index = h_HashIndex(addr);
 
-    /* don't add the same entry multiple times */
+    /* don't add the same address:port pair entry multiple times */
     for (chain = hostAddrHashTable[index]; chain; chain = chain->next) {
-       if (chain->hostPtr == host) {
-           if (chain->addr != addr || chain->port != port) {
-               ViceLog(0, 
-                       ("h_AddHostToAddrHashTable_r: host %" AFS_PTR_FMT " exists as %s:%d when adding %s:%d\n",
-                        host, afs_inet_ntoa_r(chain->addr, hoststr), 
-                        ntohs(chain->port), afs_inet_ntoa_r(addr, hoststr2), 
-                        ntohs(port)));
-           } else
-               ViceLog(125, 
-                       ("h_AddHostToAddrHashTable_r: host %" AFS_PTR_FMT " (%s:%d) already hashed\n",
-                        host, afs_inet_ntoa_r(chain->addr, hoststr), 
-                        ntohs(chain->port)));
-           
-           return;
+       if (chain->addr == addr && chain->port == port) {
+           if (chain->hostPtr == host) {
+               ViceLog(125,
+                       ("h_AddHostToAddrHashTable_r: host %" AFS_PTR_FMT " (%s:%d) already hashed\n",
+                         host, afs_inet_ntoa_r(chain->addr, hoststr),
+                         ntohs(chain->port)));
+               return;
+           }
+           if (!(chain->hostPtr->hostFlags & HOSTDELETED)) {
+               ViceLog(0,
+                       ("h_AddHostToAddrHashTable_r: refusing to hash host %" AFS_PTR_FMT ", %"
+                        AFS_PTR_FMT " (%s:%d) already hashed\n",
+                        host, chain->hostPtr, afs_inet_ntoa_r(chain->addr, hoststr),
+                         ntohs(chain->port)));
+               return;
+           }
        }
     }
 
@@ -1761,7 +1739,8 @@ h_GetHost_r(struct rx_connection *tcon)
            if (host->interface)
                afsUUID_to_string(&host->interface->uuid, uuid2, 127);
            ViceLog(0,
-                   ("CB: new identity for host %" AFS_PTR_FMT " (%s:%d), deleting(%x %x %s %s)\n",
+                   ("CB: new identity for host %p (%s:%d), "
+                    "deleting(%x %p %s %s)\n",
                     host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port),
                     identP->valid, host->interface,
                     identP->valid ? uuid1 : "no_uuid",
@@ -2104,13 +2083,13 @@ MapName_r(char *aname, char *acell, afs_int32 * aval)
            if (*aval == AnonymousID) {
                ViceLog(2,
                        ("MapName: NameToId on %s returns anonymousID\n",
-                        lnames.namelist_val));
+                        lnames.namelist_val[0]));
            }
            free(lids.idlist_val);      /* return parms are not malloced in stub if server proc aborts */
        } else {
            ViceLog(0,
                    ("MapName: NameToId on '%s' is unknown\n",
-                    lnames.namelist_val));
+                    lnames.namelist_val[0]));
            code = -1;
        }
     }
@@ -2369,7 +2348,8 @@ h_FindClient_r(struct rx_connection *tcon)
        if (!oldClient->deleted) {
            /* if we didn't create it, it's not ours to put back */
            if (created) {
-               ViceLog(0, ("FindClient: stillborn client %x(%x); conn %x (host %s:%d) had client %x(%x)\n", 
+               ViceLog(0, ("FindClient: stillborn client %p(%x); "
+                           "conn %p (host %s:%d) had client %p(%x)\n",
                            client, client->sid, tcon, 
                            afs_inet_ntoa_r(rxr_HostOf(tcon), hoststr),
                            ntohs(rxr_PortOf(tcon)),
@@ -2392,7 +2372,8 @@ h_FindClient_r(struct rx_connection *tcon)
            H_LOCK;
            client = oldClient;
        } else {
-           ViceLog(0, ("FindClient: deleted client %x(%x) already had conn %x (host %s:%d), stolen by client %x(%x)\n", 
+           ViceLog(0, ("FindClient: deleted client %p(%x) already had "
+                       "conn %p (host %s:%d), stolen by client %p(%x)\n",
                        oldClient, oldClient->sid, tcon, 
                        afs_inet_ntoa_r(rxr_HostOf(tcon), hoststr),
                        ntohs(rxr_PortOf(tcon)),
@@ -2461,7 +2442,7 @@ GetClient(struct rx_connection *tcon, struct client **cp)
     client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
     if (client == NULL) {
        ViceLog(0,
-               ("GetClient: no client in conn %x (host %s:%d), VBUSYING\n",
+               ("GetClient: no client in conn %p (host %s:%d), VBUSYING\n",
                 tcon, afs_inet_ntoa_r(rxr_HostOf(tcon), hoststr),
                  ntohs(rxr_PortOf(tcon))));
        H_UNLOCK;
@@ -2469,7 +2450,7 @@ GetClient(struct rx_connection *tcon, struct client **cp)
     }
     if (rxr_CidOf(tcon) != client->sid || rxr_GetEpoch(tcon) != client->VenusEpoch) {
        ViceLog(0,
-               ("GetClient: tcon %x tcon sid %d client sid %d\n",
+               ("GetClient: tcon %p tcon sid %d client sid %d\n",
                 tcon, rxr_CidOf(tcon), client->sid));
        H_UNLOCK;
        return VBUSY;
@@ -2667,7 +2648,7 @@ h_DumpHost(register struct host *host, int flags, void *rock)
                     ntohs(host->interface->interface[i].port));
            (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
        }
-    sprintf(tmpStr, "] refCount: %d\n", host->refCount);
+    sprintf(tmpStr, "] refCount:%d hostFlags:%hu\n", host->refCount, host->hostFlags);
     (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
 
     H_UNLOCK;