Don't cast the return from realloc()
[openafs.git] / src / kauth / kadatabase.c
index f80f1c6..5d59ba2 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>
 
+#include <roken.h>
 
-#include <sys/types.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
-#endif
-#include <string.h>
 #include <ubik.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <afs/afsutil.h>
+
 #include "kauth.h"
 #include "kautils.h"
 #include "kaserver.h"
 
+#if !defined(offsetof)
+#include <stddef.h>             /* for definition of offsetof() */
+#endif
+
 extern Date cheaderReadTime;   /* time cheader last read in */
 
-#define set_header_word(tt,field,value) kawrite ((tt), ((char *)&(cheader.field) - (char *)&cheader), ((cheader.field = (value)), (char *)&(cheader.field)), sizeof(afs_int32))
+#define set_header_word(tt,field,value) kawrite ((tt), (offsetof(struct kaheader, field)), ((cheader.field = (value)), (char *)&(cheader.field)), sizeof(afs_int32))
 
-#define inc_header_word(tt,field) kawrite ((tt), ((char *)&(cheader.field) - (char *)&cheader), ((cheader.field = (htonl(ntohl(cheader.field)+1))), (char *)&(cheader.field)), sizeof(afs_int32))
+#define inc_header_word(tt,field) kawrite ((tt), (offsetof(struct kaheader, field)), ((cheader.field = (htonl(ntohl(cheader.field)+1))), (char *)&(cheader.field)), sizeof(afs_int32))
 
 static int index_OK(afs_int32);
 
@@ -265,7 +264,7 @@ FreeBlock(struct ubik_trans *at, afs_int32 index)
    returned. */
 
 afs_int32
-FindBlock(struct ubik_trans *at, char *aname, char *ainstance, afs_int32 *toP, 
+FindBlock(struct ubik_trans *at, char *aname, char *ainstance, afs_int32 *toP,
          struct kaentry *tentry)
 {
     afs_int32 i, code;
@@ -295,7 +294,7 @@ FindBlock(struct ubik_trans *at, char *aname, char *ainstance, afs_int32 *toP,
    returns zero if there were no errors. */
 
 afs_int32
-ThreadBlock(struct ubik_trans *at, afs_int32 index, 
+ThreadBlock(struct ubik_trans *at, afs_int32 index,
            struct kaentry *tentry)
 {
     int code;
@@ -364,7 +363,7 @@ UnthreadBlock(struct ubik_trans *at, struct kaentry *aentry)
    remaining count is negative.  */
 
 afs_int32
-NextBlock(struct ubik_trans *at, afs_int32 index, struct kaentry *tentry, 
+NextBlock(struct ubik_trans *at, afs_int32 index, struct kaentry *tentry,
          afs_int32 *remaining)
 {
     int code;
@@ -401,7 +400,7 @@ NextBlock(struct ubik_trans *at, afs_int32 index, struct kaentry *tentry,
    and pointer to the user entry. */
 
 afs_int32
-ka_NewKey(struct ubik_trans *tt, afs_int32 tentryaddr, 
+ka_NewKey(struct ubik_trans *tt, afs_int32 tentryaddr,
          struct kaentry *tentry, struct ktc_encryptionKey *key)
 {
     struct kaOldKeys okeys;    /* old keys block */
@@ -411,7 +410,10 @@ ka_NewKey(struct ubik_trans *tt, afs_int32 tentryaddr,
     Date now = time(0);
     afs_int32 newkeyver;       /* new key version number */
     afs_int32 newtotalkeyentries = 0, oldtotalkeyentries = 0, keyentries;
-    int foundcurrentkey = 0, addednewkey = 0, modified;
+    int addednewkey = 0, modified;
+#ifdef AUTH_DBM_LOG
+    int foundcurrentkey = 0;
+#endif
 
     es_Report("Newkey for %s.%s\n", tentry->userID.name,
              tentry->userID.instance);
@@ -460,8 +462,8 @@ ka_NewKey(struct ubik_trans *tt, afs_int32 tentryaddr,
                            ("Warning: Entry %s.%s contains more than one valid key: fixing\n",
                             tentry->userID.name, tentry->userID.instance));
                }
-#endif
                foundcurrentkey = 1;
+#endif
            }
 
            /* If we find an oldkey of the same version or
@@ -575,7 +577,7 @@ ka_NewKey(struct ubik_trans *tt, afs_int32 tentryaddr,
 }
 
 afs_int32
-ka_DelKey(struct ubik_trans *tt, afs_int32 tentryaddr, 
+ka_DelKey(struct ubik_trans *tt, afs_int32 tentryaddr,
          struct kaentry *tentry)
 {
     int code;
@@ -678,7 +680,7 @@ ka_debugKeyCache(struct ka_debugInfo *info)
 /* Add a key to the key cache, expanding it if necessary. */
 
 void
-ka_Encache(char *name, char *inst, afs_int32 kvno, 
+ka_Encache(char *name, char *inst, afs_int32 kvno,
           struct ktc_encryptionKey *key, Date superseded)
 {
     int i;
@@ -704,10 +706,8 @@ ka_Encache(char *name, char *inst, afs_int32 kvno,
            return;
        }
     /* i == maxCachedKeys */
-    keyCache =
-       (struct cachedKey *)realloc(keyCache,
-                                   (maxCachedKeys *=
-                                    2) * sizeof(struct cachedKey));
+    keyCache = realloc(keyCache, (maxCachedKeys *=2)
+                                 * sizeof(struct cachedKey));
     if (keyCache == 0) {
        es_Report("Can't realloc keyCache! out of memory?");
        exit(123);
@@ -727,7 +727,7 @@ ka_Encache(char *name, char *inst, afs_int32 kvno,
    with tt==0, since Rx can't call Ubik. */
 
 afs_int32
-ka_LookupKvno(struct ubik_trans *tt, char *name, char *inst, afs_int32 kvno, 
+ka_LookupKvno(struct ubik_trans *tt, char *name, char *inst, afs_int32 kvno,
              struct ktc_encryptionKey *key)
 {
     int i;
@@ -792,9 +792,9 @@ ka_LookupKvno(struct ubik_trans *tt, char *name, char *inst, afs_int32 kvno,
 /* Look up the primary key and key version for a principal. */
 
 afs_int32
-ka_LookupKey(struct ubik_trans *tt, 
-            char *name, 
-            char *inst, 
+ka_LookupKey(struct ubik_trans *tt,
+            char *name,
+            char *inst,
             afs_int32 *kvno,                   /* returned */
             struct ktc_encryptionKey *key)     /* copied out */
 {