Add interface to select client security objects
[openafs.git] / src / venus / afsio.c
index 8d2cd8f..e795e6b 100644 (file)
@@ -73,6 +73,7 @@
 #include <afs/afsutil.h>
 #include <rx/rx.h>
 #include <rx/xdr.h>
+#include <afs/afs_consts.h>
 #include <afs/afscbint.h>
 #include <afs/vldbint.h>
 #include <afs/vlserver.h>
 #include <des_prototypes.h>
 #include <rx_prototypes.h>
 #include "../rxkad/md5.h"
-#define        MAXHOSTS 13
 #ifdef O_LARGEFILE
 #define afs_stat        stat64
 #define afs_fstat       fstat64
@@ -159,7 +159,7 @@ struct connectionLookup {
 struct cellLookup {
     struct cellLookup *next;
     struct afsconf_cell info;
-    struct rx_securityClass *sc[3];
+    struct rx_securityClass *sc;
     afs_int32 scIndex;
 };
 
@@ -274,7 +274,7 @@ main (int argc, char **argv)
 
 AFS_UNUSED
 afs_int32
-HandleLocalAuth(struct rx_securityClass **sc[3], afs_int32 *scIndex)
+HandleLocalAuth(struct rx_securityClass **sc, afs_int32 *scIndex)
 {
     static struct afsconf_dir *tdir = NULL;
     struct ktc_principal sname;
@@ -285,45 +285,20 @@ HandleLocalAuth(struct rx_securityClass **sc[3], afs_int32 *scIndex)
     char *cell;
     afs_int32 code;
 
+    *sc = NULL;
+    *scIndex = 0;
+
     tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
     if (!tdir) {
         fprintf(stderr,"Could not open configuration directory: %s.\n",
                AFSDIR_SERVER_ETC_DIRPATH);
         return -1;
     }
-    cell = tdir->cellName;
-    strcpy(sname.cell, cell);
-    sname.instance[0] = 0;
-    strcpy(sname.name, "afs");
-    code=afsconf_GetLatestKey(tdir, &kvno, &key);
+    code = afsconf_ClientAuth(tdir, sc, &scIndex);
     if (code) {
-        fprintf(stderr,"afsconf_GetLatestKey returned %d\n", code);
+        fprintf(stderr,"afsconf_ClientAuth returned %d\n", code);
         return -1;
     }
-    ttoken.kvno = kvno;
-    des_init_random_number_generator(ktc_to_cblock(&key));
-    code = des_random_key(ktc_to_cblock(&ttoken.sessionKey));
-    if (code) {
-        fprintf(stderr,"des_random_key returned %d\n", code);
-        return -1;
-    }
-    ttoken.ticketLen = MAXKTCTICKETLEN;
-    code = tkt_MakeTicket(ttoken.ticket, &ttoken.ticketLen, &key,
-                         AUTH_SUPERUSER, "", sname.cell,
-                         0, 0xffffffff,
-                         &ttoken.sessionKey, host,
-                         sname.name, sname.instance);
-    if (code)
-        *scIndex = 0;
-    else {
-       *scIndex = 2;
-        *sc[2] = (struct rx_securityClass *)
-           rxkad_NewClientSecurityObject(rxkad_clear,
-                                         &ttoken.sessionKey, ttoken.kvno,
-                                         ttoken.ticketLen, ttoken.ticket);
-    }
-    if (*scIndex == 0)
-       *sc[0] = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
     return 0;
 }
 
@@ -798,7 +773,7 @@ get_vnode_hosts(char *fname, char **cellp, afs_int32 *hosts, AFSFid *Fid,
             i++;
         }
     }
-    for (; i<MAXHOSTS; i++) *h++ = 0;
+    for (; i<AFS_MAXHOSTS; i++) *h++ = 0;
     return 0;
 }
 
@@ -807,7 +782,7 @@ get_vnode_hosts(char *fname, char **cellp, afs_int32 *hosts, AFSFid *Fid,
  *     offer it, and the FID.
  */
 afs_int32
-get_file_cell(char *fn, char **cellp, afs_int32 hosts[MAXHOSTS], AFSFid *Fid,
+get_file_cell(char *fn, char **cellp, afs_int32 hosts[AFS_MAXHOSTS], AFSFid *Fid,
              struct AFSFetchStatus *Status, afs_int32 create)
 {
     afs_int32 code;
@@ -865,7 +840,7 @@ get_file_cell(char *fn, char **cellp, afs_int32 hosts[MAXHOSTS], AFSFid *Fid,
                afs_com_err(pnp, code, (char *) 0);
        } else {
            Tmpafs_int32 = (afs_int32 *)buf;
-           for (j=0;j<MAXHOSTS;++j) {
+           for (j=0;j<AFS_MAXHOSTS;++j) {
                hosts[j] = Tmpafs_int32[j];
                if (!Tmpafs_int32[j])
                    break;
@@ -926,7 +901,7 @@ readFile(struct cmd_syndesc *as, void *unused)
     char *fname;
     char *cell = 0;
     afs_int32 code;
-    afs_int32 hosts[MAXHOSTS];
+    afs_int32 hosts[AFS_MAXHOSTS];
     AFSFid Fid;
     int i, j;
     struct rx_connection *RXConn;
@@ -977,7 +952,7 @@ readFile(struct cmd_syndesc *as, void *unused)
        return ENOENT;
     }
     cl = FindCell(cell);
-    for (j=0;j<MAXHOSTS;++j) {
+    for (j=0;j<AFS_MAXHOSTS;++j) {
        int useHost;
 
         if (first && as->parms[6].items) {
@@ -993,7 +968,7 @@ readFile(struct cmd_syndesc *as, void *unused)
        }
        first = 0;
         RXConn = FindRXConnection(useHost, htons(AFSCONF_FILEPORT), 1,
-                                 cl->sc[cl->scIndex], cl->scIndex);
+                                 cl->sc, cl->scIndex);
         if (!RXConn) {
             fprintf(stderr,"rx_NewConnection failed to server 0x%X\n",
                     useHost);
@@ -1130,7 +1105,7 @@ writeFile(struct cmd_syndesc *as, void *unused)
     char *fname = NULL;
     char *cell = 0;
     afs_int32 code, localcode = 0;
-    afs_int32 hosts[MAXHOSTS];
+    afs_int32 hosts[AFS_MAXHOSTS];
     afs_uint32 useHost;
     AFSFid Fid;
     int i;
@@ -1205,7 +1180,7 @@ writeFile(struct cmd_syndesc *as, void *unused)
     gettimeofday (&starttime, &Timezone);
     useHost = hosts[0];
     RXConn = FindRXConnection(useHost, htons(AFSCONF_FILEPORT), 1,
-                             cl->sc[cl->scIndex], cl->scIndex);
+                             cl->sc, cl->scIndex);
     if (!RXConn) {
         fprintf(stderr,"rx_NewConnection failed to server 0x%X\n",
                hosts[0]);
@@ -1452,29 +1427,11 @@ FindCell(char *cellName)
        if (code = VLDBInit(1, &p->info))
             fprintf(stderr,"VLDBInit failed for cell %s\n", p->info.name);
 #endif
-        strcpy((char *)&sname.cell, (char *)&p->info.name);
-        sname.instance[0] = 0;
-        strcpy(sname.name, "afs");
-        code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
-        if (code)
-            p->scIndex = 0;
-        else {
-            if ((ttoken.kvno >= 0) && (ttoken.kvno <= 255))
-               /* this is a kerberos ticket, set scIndex accordingly */
-               p->scIndex = 2;
-           else {
-               fprintf(stderr,"funny kvno (%d) in ticket, proceeding\n",
-                       ttoken.kvno);
-               p->scIndex = 2;
-           }
-           p->sc[2] = (struct rx_securityClass *)
-               rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
-                                             ttoken.kvno, ttoken.ticketLen,
-                                             ttoken.ticket);
-        }
-        if (p->scIndex == 0)
-            p->sc[0] = (struct rx_securityClass *)
-               rxnull_NewClientSecurityObject();
+       code = afsconf_ClientAuthToken(&p->info, 0, &p->sc, &p->scIndex);
+       if (code) {
+           p->scIndex = 0;
+            p->sc = rxnull_NewClientSecurityObject();
+       }
     }
 
     if (p)