cmd: Convert to using libtool
[openafs.git] / tests / auth / superuser-t.c
index 3d3bda0..095abf1 100644 (file)
@@ -41,7 +41,8 @@
 #include <rx/rxkad.h>
 #include <rx/rx_identity.h>
 
-#include <tap/basic.h>
+#include <hcrypto/des.h>
+#include <tests/tap/basic.h>
 
 #include "test.h"
 #include "common.h"
@@ -71,43 +72,6 @@ testNewIterator(struct afsconf_dir *dir, int num, struct rx_identity *id) {
     rx_identity_free(&fileId);
 }
 
-struct rx_securityClass *
-fakeRXKADClass(struct afsconf_dir *dir,
-              char *name, char *instance, char *realm,
-              afs_uint32 startTime, afs_uint32 endTime)
-{
-    int code;
-    char buffer[256];
-    struct ktc_encryptionKey key, session;
-    afs_int32 kvno;
-    afs_int32 ticketLen;
-    struct rx_securityClass *class = NULL;
-
-    code = afsconf_GetLatestKey(dir, &kvno, &key);
-    if (code)
-       goto out;
-
-    DES_init_random_number_generator((DES_cblock *) &key);
-    code = DES_new_random_key((DES_cblock *) &session);
-    if (code)
-       goto out;
-
-    ticketLen = sizeof(buffer);
-    memset(buffer, 0, sizeof(buffer));
-    startTime = time(NULL);
-    endTime = startTime + 60 * 60;
-
-    code = tkt_MakeTicket(buffer, &ticketLen, &key, name, instance, realm,
-                         startTime, endTime, &session, 0, "afs", "");
-    if (code)
-       goto out;
-
-    class = rxkad_NewClientSecurityObject(rxkad_clear, &session, kvno,
-                                         ticketLen, buffer);
-out:
-    return class;
-}
-
 
 void
 startClient(char *configPath)
@@ -123,7 +87,7 @@ startClient(char *configPath)
     struct hostent *he;
     afs_uint32 addr;
     afs_int32 result;
-    char *string;
+    char *string = NULL;
 
     plan(63);
 
@@ -255,6 +219,8 @@ startClient(char *configPath)
     is_int(0, code, "Can get identity back");
     is_string("<LocalAuth>", string, "Forged token is super user");
 
+    xdr_free((xdrproc_t)xdr_string, &string);
+
     /* Throw away this connection and security class */
     rx_DestroyConnection(conn);
     rxs_Release(class);
@@ -263,7 +229,8 @@ startClient(char *configPath)
      * here, sadly */
 
     startTime = time(NULL);
-    class = fakeRXKADClass(dir, "rpctest", "", "", startTime, startTime + 60* 60);
+    class = afstest_FakeRxkadClass(dir, "rpctest", "", "", startTime,
+                                  startTime + 60* 60);
 
     conn = rx_NewConnection(addr, htons(TEST_PORT), TEST_SERVICE_ID, class,
                            RX_SECIDX_KAD);
@@ -275,9 +242,11 @@ startClient(char *configPath)
     is_int(EPERM, code,
           "Running new interface RPC as non-super user fails as expected");
     code = TEST_WhoAmI(conn, &string);
+    xdr_free((xdrproc_t)xdr_string, &string);
     is_int(EPERM, code,
           "Running RPC returning string fails as expected");
     code = TEST_NewWhoAmI(conn, &string);
+    xdr_free((xdrproc_t)xdr_string, &string);
     is_int(EPERM, code,
           "Running new interface RPC returning string fails as expected");
     ok(afsconf_AddUser(dir, "rpctest") == 0,
@@ -289,16 +258,18 @@ startClient(char *configPath)
     code = TEST_WhoAmI(conn, &string);
     is_int(0, code, "Running RPC returning string as %s works", "rpctest");
     is_string("rpctest", string, "Returned user string matches");
+    xdr_free((xdrproc_t)xdr_string, &string);
     code = TEST_NewWhoAmI(conn, &string);
     is_int(0, code, "Running new RPC returning string as %s works", "rpctest");
     is_string("rpctest", string, "Returned user string for new interface matches");
+    xdr_free((xdrproc_t)xdr_string, &string);
     rx_DestroyConnection(conn);
     rxs_Release(class);
 
     /* Now try with an admin principal */
     startTime = time(NULL);
-    class = fakeRXKADClass(dir, "rpctest", "admin", "", startTime,
-                     startTime + 60* 60);
+    class = afstest_FakeRxkadClass(dir, "rpctest", "admin", "", startTime,
+                                  startTime + 60* 60);
 
     conn = rx_NewConnection(addr, htons(TEST_PORT), TEST_SERVICE_ID, class,
                            RX_SECIDX_KAD);
@@ -310,9 +281,11 @@ startClient(char *configPath)
     is_int(EPERM, code,
           "Running new interface RPC as non-super user fails as expected");
     code = TEST_WhoAmI(conn, &string);
+    xdr_free((xdrproc_t)xdr_string, &string);
     is_int(EPERM, code,
           "Running RPC returning string fails as expected");
     code = TEST_NewWhoAmI(conn, &string);
+    xdr_free((xdrproc_t)xdr_string, &string);
     is_int(EPERM, code,
           "Running new interface RPC returning string fails as expected");
 
@@ -326,11 +299,13 @@ startClient(char *configPath)
     code = TEST_WhoAmI(conn, &string);
     is_int(0, code, "Running RPC returning string as %s works", "rpctest/admin");
     is_string("rpctest.admin", string, "Returned user string matches");
+    xdr_free((xdrproc_t)xdr_string, &string);
     code = TEST_NewWhoAmI(conn, &string);
     is_int(0, code, "Running new interface RPC returning string as %s works",
           "rpctest/admin");
     is_string("rpctest.admin", string,
              "Returned user string from new interface matches");
+    xdr_free((xdrproc_t)xdr_string, &string);
 
     rx_DestroyConnection(conn);
     rxs_Release(class);
@@ -390,50 +365,20 @@ STEST_NewWhoAmI(struct rx_call *call, char **result)
    return 0;
 }
 
-void
-startServer(char *configPath)
-{
-    struct rx_securityClass **classes;
-    afs_int32 numClasses;
-    int code;
-    struct rx_service *service;
-
-    globalDir = afsconf_Open(configPath);
-    if (globalDir == NULL) {
-       fprintf(stderr, "Server: Unable to open config directory\n");
-       exit(1);
-    }
-
-    code = rx_Init(htons(TEST_PORT));
-    if (code != 0) {
-       fprintf(stderr, "Server: Unable to initialise RX\n");
-        exit(1);
-    }
-
-    afsconf_BuildServerSecurityObjects(globalDir, &classes, &numClasses);
-    service = rx_NewService(0, TEST_SERVICE_ID, "test", classes, numClasses,
-                           TEST_ExecuteRequest);
-    if (service == NULL) {
-       fprintf(stderr, "Server: Unable to start to test service\n");
-       exit(1);
-    }
-
-    rx_StartServer(1);
-}
-
 int main(int argc, char **argv)
 {
     struct afsconf_dir *dir;
     char *dirname;
     int serverPid, clientPid, waited, stat;
-    char keymaterial[]="\x19\x17\xff\xe6\xbb\x77\x2e\xfc";
     int code;
 
     /* Start the client and the server if requested */
 
     if (argc == 3 ) {
         if (strcmp(argv[1], "-server") == 0) {
-            startServer(argv[2]);
+           globalDir = afsconf_Open(argv[2]);
+           afstest_StartTestRPCService(argv[2], TEST_PORT, TEST_SERVICE_ID,
+                                       TEST_ExecuteRequest);
             exit(0);
         } else if (strcmp(argv[1], "-client") == 0) {
             startClient(argv[2]);
@@ -447,7 +392,7 @@ int main(int argc, char **argv)
     /* Otherwise, do the basic configuration, then start the client and
      * server */
 
-    dirname = buildTestConfig();
+    dirname = afstest_BuildTestConfig();
 
     dir = afsconf_Open(dirname);
     if (dir == NULL) {
@@ -455,10 +400,7 @@ int main(int argc, char **argv)
        exit(1);
     }
 
-    DES_set_odd_parity((DES_cblock *)keymaterial);
-
-    /* Add a key to it so we can use it for connection tests */
-    code = afsconf_AddKey(dir, 1, keymaterial, 1);
+    code = afstest_AddDESKeyFile(dir);
     if (code) {
        afs_com_err("superuser-t", code, "while adding new key\n");
        exit(1);