bos_util: Fix buffer overflow
[openafs.git] / src / bozo / bos_util.c
index e11dfb9..62293a2 100644 (file)
@@ -1,12 +1,12 @@
-/* 
+/*
  *  Copyright (C) 1989 by the Massachusetts Institute of Technology
- * 
+ *
  *    Export of software employing encryption from the United States of
  *    America is assumed to require a specific license from the United
  *    States Government.  It is the responsibility of any person or
  *    organization contemplating export to obtain such a license before
  *    exporting.
- * 
+ *
  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
  * distribute this software and its documentation for any purpose and
  * without fee is hereby granted, provided that the above copyright
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <string.h>
-#include <stdio.h>
+#include <hcrypto/ui.h>
+#include <hcrypto/des.h>
 
 #include <afs/stds.h>
 #include <afs/afsutil.h>
-#include <rx/rxkad.h>
 #include <afs/keys.h>
 #include <afs/cellconfig.h>
 #include <afs/kautils.h>
-#include <des.h>
-#include <des_prototypes.h>
 
 int
 main(int argc, char **argv)
 {
     struct afsconf_dir *tdir;
-    register afs_int32 code;
+    afs_int32 code;
 
     if (argc == 1) {
        printf("bos_util: usage is 'bos_util <opcode> options, e.g.\n");
@@ -76,12 +71,12 @@ main(int argc, char **argv)
        memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
 
        /* prompt for key */
-       code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
+       code = UI_UTIL_read_pw_string(buf, sizeof(buf), "input key: ", 0);
        if (code || strlen(buf) == 0) {
            printf("Bad key: \n");
            exit(1);
        }
-       code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
+       code = UI_UTIL_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
        if (code || strlen(ver) == 0) {
            printf("Bad key: \n");
            exit(1);
@@ -91,15 +86,15 @@ main(int argc, char **argv)
            exit(1);
        }
        ka_StringToKey(buf, tcell, &tkey);
-       code = afsconf_AddKey(tdir, kvno, ktc_to_charptr(&tkey), 0);
+       code = afsconf_AddKey(tdir, kvno, (char *)&tkey, 0);
        if (code) {
            printf("bos_util: failed to set key, code %d.\n", code);
            exit(1);
        }
     } else if (strcmp(argv[1], "adddes") == 0) {
-       struct ktc_encryptionKey tkey;
+       DES_cblock tkey;
        int kvno;
-       register afs_int32 code;
+       afs_int32 code;
        char buf[BUFSIZ], ver[BUFSIZ];
 
        if (argc != 3) {
@@ -110,12 +105,12 @@ main(int argc, char **argv)
        memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
 
        /* prompt for key */
-       code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
+       code = UI_UTIL_read_pw_string(buf, sizeof(buf), "input key: ", 0);
        if (code || strlen(buf) == 0) {
            printf("Bad key: \n");
            exit(1);
        }
-       code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
+       code = UI_UTIL_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
        if (code || strlen(ver) == 0) {
            printf("Bad key: \n");
            exit(1);
@@ -124,8 +119,8 @@ main(int argc, char **argv)
            printf("\nInput key mismatch\n");
            exit(1);
        }
-       des_string_to_key(buf, ktc_to_cblockptr(&tkey));
-       code = afsconf_AddKey(tdir, kvno, ktc_to_charptr(&tkey), 0);
+       DES_string_to_key(buf, &tkey);
+       code = afsconf_AddKey(tdir, kvno, (char *) &tkey, 0);
        if (code) {
            printf("bos_util: failed to set key, code %d.\n", code);
            exit(1);
@@ -174,7 +169,7 @@ main(int argc, char **argv)
        }
     } else if (strcmp(argv[1], "list") == 0) {
        struct afsconf_keys tkeys;
-       register int i;
+       int i;
        unsigned char tbuffer[9];
 
        code = afsconf_GetKeys(tdir, &tkeys);
@@ -185,13 +180,11 @@ main(int argc, char **argv)
        for (i = 0; i < tkeys.nkeys; i++) {
            if (tkeys.key[i].kvno != -1) {
                int count;
-               unsigned char x[8];
                memcpy(tbuffer, tkeys.key[i].key, 8);
                tbuffer[8] = 0;
                printf("kvno %4d: key is '%s' '", tkeys.key[i].kvno, tbuffer);
-               strcpy((char *)x, (char *)tbuffer);
                for (count = 0; count < 8; count++)
-                   printf("\\%03o", x[count]);
+                   printf("\\%03o", tbuffer[count]);
                printf("'\n");
            }
        }