kdb: don't dereference a null pointer on corrupt database
[openafs.git] / src / kauth / kdb.c
index 7b1edeb..0703cdd 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
-#include <fcntl.h>
-#include <sys/types.h>
-#include <time.h>
-#include <stdio.h>
-#ifndef AFS_NT40_ENV
-#include <strings.h>
-#endif
 #include <afs/cmd.h>
+#include <afs/afsutil.h>
+
 #include "kauth.h"
 #include "kalog.h"
-#include <afs/afsutil.h>
 
 #ifdef AUTH_DBM_LOG
 
-char *dbmfile;
+const char *dbmfile;
 
 static int
-cmdproc(register struct cmd_syndesc *as, void * arock)
+cmdproc(struct cmd_syndesc *as, void * arock)
 {
     DBM *kdb;
     datum key, data;
     kalog_elt rdata;
-    register afs_int32 code = 0, cnt = 0;
-    register struct cmd_item *ti;
+    afs_int32 cnt = 0;
+    struct cmd_item *ti;
 
     if (as->parms[0].items) {
        dbmfile = as->parms[0].items->data;
@@ -53,27 +46,31 @@ cmdproc(register struct cmd_syndesc *as, void * arock)
             if (as->parms[2].items) {
                data = dbm_fetch(kdb, key);
                if (!data.dptr) {
-                   fprintf(stderr, "%s: no entry exists\n", ti->data);
+                   fprintf(stderr, "%s: no entry exists\n", (char *)key.dptr);
                    continue;
                }
                if (data.dsize != sizeof(kalog_elt)) {
-                   fprintf(stderr, "%s: data came out corrupt\n", ti->data);
+                   fprintf(stderr, "%s: data came out corrupt\n", 
+                       (char *)key.dptr);
                    continue;
                }
                memcpy(&rdata, data.dptr, sizeof(kalog_elt));
                if (! as->parms[3].items) {
                    char *hostName;
                    hostName = hostutil_GetNameByINet(rdata.host);
-                   printf("%s: last operation from host %s at %s", key.dptr, 
-                          hostName, ctime(&rdata.last_use));
+                   printf("%s: last operation from host %s at %s",
+                          (char *)key.dptr, hostName,
+                          ctime(&rdata.last_use));
                } else {
                    char *hostIP;
-                   hostIP = afs_inet_ntoa(rdata.host);
-                   printf("%s: last operation from host %s at %s", key.dptr, 
-                          hostIP, ctime(&rdata.last_use));
+                   char hoststr[16];
+                   hostIP = afs_inet_ntoa_r(rdata.host, hoststr);
+                   printf("%s: last operation from host %s at %s",
+                          (char *)key.dptr, hostIP,
+                          ctime(&rdata.last_use));
                }
             } else {
-               printf("\t%s\n", key.dptr);
+               printf("\t%s\n", (char *)key.dptr);
             }
        }
        printf("%d entries were found\n", cnt);
@@ -105,8 +102,8 @@ cmdproc(register struct cmd_syndesc *as, void * arock)
 int
 main(int argc, char **argv)
 {
-    register struct cmd_syndesc *ts;
-    register afs_int32 code;
+    struct cmd_syndesc *ts;
+    afs_int32 code;
     char dbmfile_help[AFSDIR_PATH_MAX];
 
     sprintf(dbmfile_help, "dbmfile to use (default %s)",
@@ -129,5 +126,6 @@ int
 main(void)
 {
     printf("kdb not supported\n");
+    return 1;
 }
 #endif