bozo-log-fix-20060119
[openafs.git] / src / bozo / bos_util.c
index 17152aa..b6e992f 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID("$Header$");
+RCSID
+    ("$Header$");
 
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <netdb.h>
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+
 #include <afs/stds.h>
 #include <afs/afsutil.h>
 #include <rx/rxkad.h>
 #include <afs/keys.h>
 #include <afs/cellconfig.h>
 
-int 
+int
 main(int argc, char **argv)
 {
     struct afsconf_dir *tdir;
@@ -54,14 +63,15 @@ main(int argc, char **argv)
 
     tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIR);
     if (!tdir) {
-       printf("bos_util: can't initialize conf dir '%s'\n", AFSDIR_SERVER_ETC_DIR);
+       printf("bos_util: can't initialize conf dir '%s'\n",
+              AFSDIR_SERVER_ETC_DIR);
        exit(1);
     }
-    if (strcmp(argv[1], "add")==0) {
+    if (strcmp(argv[1], "add") == 0) {
        struct ktc_encryptionKey tkey;
        int kvno;
        char buf[BUFSIZ], ver[BUFSIZ];
-       char *tcell = (char *) 0;
+       char *tcell = NULL;
 
        if (argc != 3) {
            printf("bos_util add: usage is 'bos_util add <kvno>\n");
@@ -71,33 +81,32 @@ 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);
-       if(code || strlen(buf)==0) {
+       code = des_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);
-       if(code || strlen(ver)==0) {
+       code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
+       if (code || strlen(ver) == 0) {
            printf("Bad key: \n");
            exit(1);
        }
-       if (strcmp (ver, buf) != 0) {
-           printf ("\nInput key mismatch\n");
+       if (strcmp(ver, buf) != 0) {
+           printf("\nInput key mismatch\n");
            exit(1);
        }
-       ka_StringToKey(buf,tcell,&tkey);
-       code = afsconf_AddKey(tdir, kvno, &tkey);
+       ka_StringToKey(buf, tcell, &tkey);
+       code = afsconf_AddKey(tdir, kvno, &tkey, 0);
        if (code) {
            printf("bos_util: failed to set key, code %d.\n", code);
            exit(1);
        }
-    }
-    else if (strcmp(argv[1], "adddes")==0) {
+    } else if (strcmp(argv[1], "adddes") == 0) {
        struct ktc_encryptionKey tkey;
        int kvno;
        register afs_int32 code;
        char buf[BUFSIZ], ver[BUFSIZ];
-       char *tcell = (char *) 0;
+       char *tcell = NULL;
 
        if (argc != 3) {
            printf("bos_util adddes: usage is 'bos_util adddes <kvno>\n");
@@ -107,55 +116,56 @@ 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);
-       if(code || strlen(buf)==0) {
+       code = des_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);
-       if(code || strlen(ver)==0) {
+       code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
+       if (code || strlen(ver) == 0) {
            printf("Bad key: \n");
            exit(1);
        }
-       if (strcmp (ver, buf) != 0) {
-           printf ("\nInput key mismatch\n");
+       if (strcmp(ver, buf) != 0) {
+           printf("\nInput key mismatch\n");
            exit(1);
        }
-       des_string_to_key(buf,&tkey);
-       code = afsconf_AddKey(tdir, kvno, &tkey);
+       des_string_to_key(buf, &tkey);
+       code = afsconf_AddKey(tdir, kvno, &tkey, 0);
        if (code) {
            printf("bos_util: failed to set key, code %d.\n", code);
            exit(1);
        }
     }
 #ifdef KERBEROS
-    else if (strcmp(argv[1], "srvtab2keyfile")==0) {
+    else if (strcmp(argv[1], "srvtab2keyfile") == 0) {
        char tkey[8], name[255], inst[255], realm[255];
        int kvno;
        if (argc != 5) {
-           printf("bos_util add: usage is 'bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
+           printf
+               ("bos_util add: usage is 'bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
            exit(1);
        }
        kvno = atoi(argv[2]);
        bzero(tkey, sizeof(tkey));
        code = kname_parse(name, inst, realm, argv[4]);
        if (code != 0) {
-               printf("Invalid kerberos name\n");
-               exit(1);
+           printf("Invalid kerberos name\n");
+           exit(1);
        }
        code = read_service_key(name, inst, realm, kvno, argv[3], tkey);
        if (code != 0) {
-               printf("Can't find key in %s\n", argv[3]);
-               exit(1);
+           printf("Can't find key in %s\n", argv[3]);
+           exit(1);
        }
-       code = afsconf_AddKey(tdir, kvno, tkey);
+       code = afsconf_AddKey(tdir, kvno, tkey, 0);
        if (code) {
            printf("bos_util: failed to set key, code %d.\n", code);
            exit(1);
        }
     }
 #endif
-    else if (strcmp(argv[1], "delete")==0) {
+    else if (strcmp(argv[1], "delete") == 0) {
        long kvno;
        if (argc != 3) {
            printf("bos_util delete: usage is 'bos_util delete <kvno>\n");
@@ -164,37 +174,38 @@ main(int argc, char **argv)
        kvno = atoi(argv[2]);
        code = afsconf_DeleteKey(tdir, kvno);
        if (code) {
-           printf("bos_util: failed to delete key %d, (code %d)\n", kvno, code);
+           printf("bos_util: failed to delete key %d, (code %d)\n", kvno,
+                  code);
            exit(1);
        }
-    }
-    else if (strcmp(argv[1], "list") == 0) {
+    } else if (strcmp(argv[1], "list") == 0) {
        struct afsconf_keys tkeys;
        register int i;
        unsigned char tbuffer[9];
-       
+
        code = afsconf_GetKeys(tdir, &tkeys);
        if (code) {
            printf("bos_util: failed to get keys, code %d\n", code);
            exit(1);
        }
-       for(i=0;i<tkeys.nkeys;i++) {
+       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(x,(char *)tbuffer);
-               for(count=0;count<8;count++)
-                   printf("\\%03o",(unsigned char *)x[count]);
+               strcpy(x, (char *)tbuffer);
+               for (count = 0; count < 8; count++)
+                   printf("\\%03o", x[count]);
                printf("'\n");
            }
        }
        printf("All done.\n");
-    }
-    else {
-       printf("bos_util: unknown operation '%s', type 'bos_util' for assistance\n");
+    } else {
+       printf
+           ("bos_util: unknown operation '%s', type 'bos_util' for assistance\n",
+            argv[1]);
        exit(1);
     }
     exit(0);