Don't cast the return from calloc()
[openafs.git] / src / libadmin / adminutil / afs_utilAdmin.c
index c29e3d4..7cfdd40 100644 (file)
@@ -9,17 +9,18 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
+
+#include <rx/rx.h>
+#include <rx/rxstat.h>
+
+#ifdef AFS_NT40_ENV
+# include <afs/krb5_nt.h>
+#endif
 
-#include <afs/stds.h>
-#include <afs/afs_Admin.h>
-#include <stdio.h>
-#include <string.h>
 #include <afs/afs_Admin.h>
-#include "afs_AdminInternal.h"
-#include "afs_utilAdmin.h"
 #include <afs/pthread_glock.h>
 #include <afs/cellconfig.h>
 #include <afs/dirpath.h>
@@ -30,18 +31,10 @@ RCSID
 #include <afs/pterror.h>
 #include <afs/bnode.h>
 #include <afs/volser.h>
-#include <afs/afsint.h>
-#include <rx/rx.h>
-#include <rx/rxstat.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#endif
+#include <afs/afscbint.h>
+
+#include "afs_AdminInternal.h"
+#include "afs_utilAdmin.h"
 
 /*
  * AIX 4.2 has PTHREAD_CREATE_UNDETACHED and not PTHREAD_CREATE_JOINABLE
@@ -81,9 +74,15 @@ init_once(void)
     initialize_AU_error_table();
     initialize_AV_error_table();
     initialize_VOLS_error_table();
+#ifdef AFS_KRB5_ERROR_ENV
+    initialize_krb5();
+#endif
     error_init_done = 1;
 }
 
+/*
+ * (*errorTextP) will not be freed by the caller.
+ */
 int ADMINAPI
 util_AdminErrorCodeTranslate(afs_status_t errorCode, int langId,
                             const char **errorTextP, afs_status_p st)
@@ -104,7 +103,14 @@ util_AdminErrorCodeTranslate(afs_status_t errorCode, int langId,
     if (!error_init_done)
        pthread_once(&error_init_once, init_once);
     code = (afs_int32) errorCode;
-    *errorTextP = error_message(code);
+    *errorTextP = afs_error_message(code);
+#ifdef AFS_KRB5_ERROR_ENV
+    if (strncmp(*errorTextP, "unknown", strlen("unknown")) == 0) {
+        const char *msg = fetch_krb5_error_message(code);
+        if (msg)
+            *errorTextP = msg;
+    }
+#endif
     rc = 1;
 
   fail_util_AdminErrorCodeTranslate:
@@ -222,8 +228,7 @@ util_DatabaseServerGetBegin(const char *cellName, void **iterationIdP,
     afs_status_t tst = 0;
     afs_admin_iterator_p iter =
        (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
-    database_server_get_p serv =
-       (database_server_get_p) calloc(1, sizeof(database_server_get_t));
+    database_server_get_p serv = calloc(1, sizeof(database_server_get_t));
     char copyCell[MAXCELLCHARS];
 
     /*
@@ -446,17 +451,19 @@ util_AdminServerAddressGetFromName(const char *serverName, int *serverAddress,
     if (num_converted == 4) {
        *serverAddress = (part1 << 24) | (part2 << 16) | (part3 << 8) | part4;
     } else {
-       LOCK_GLOBAL_MUTEX server = gethostbyname(serverName);
+       LOCK_GLOBAL_MUTEX;
+       server = gethostbyname(serverName);
        if (server != NULL) {
            memcpy((void *)serverAddress, (const void *)server->h_addr,
-                  sizeof(serverAddress));
+                  sizeof(int));
            *serverAddress = ntohl(*serverAddress);
        } else {
            tst = ADMUTILCANTGETSERVERNAME;
            UNLOCK_GLOBAL_MUTEX;
            goto fail_util_AdminServerAddressGetFromName;
        }
-    UNLOCK_GLOBAL_MUTEX}
+       UNLOCK_GLOBAL_MUTEX;
+    }
     rc = 1;
 
   fail_util_AdminServerAddressGetFromName:
@@ -1197,13 +1204,13 @@ UnmarshallRPCStats(afs_uint32 serverVersion, afs_uint32 ** ptrP,
     s->stats_v1.func_index = *(ptr++);
     hi = *(ptr++);
     lo = *(ptr++);
-    hset64(s->stats_v1.invocations, hi, lo);
+    s->stats_v1.invocations = ((afs_uint64) hi << 32) + lo;
     hi = *(ptr++);
     lo = *(ptr++);
-    hset64(s->stats_v1.bytes_sent, hi, lo);
+    s->stats_v1.bytes_sent = ((afs_uint64) hi << 32) + lo;
     hi = *(ptr++);
     lo = *(ptr++);
-    hset64(s->stats_v1.bytes_rcvd, hi, lo);
+    s->stats_v1.bytes_rcvd = ((afs_uint64) hi << 32) + lo;
     s->stats_v1.queue_time_sum.sec = *(ptr++);
     s->stats_v1.queue_time_sum.usec = *(ptr++);
     s->stats_v1.queue_time_sum_sqr.sec = *(ptr++);
@@ -1319,7 +1326,11 @@ DestroyRPCStats(void *rpc_specific, afs_status_p st)
  */
 
 int ADMINAPI
-util_RPCStatsGetBegin(struct rx_connection *conn, int (*rpc) (),
+util_RPCStatsGetBegin(struct rx_connection *conn, 
+                     int (*rpc) (struct rx_connection *,
+                                 afs_uint32, afs_uint32 *,
+                                 afs_uint32 *, afs_uint32 *,
+                                 afs_uint32 *, struct rpcStats *),
                      void **iterationIdP, afs_status_p st)
 {
     int rc = 0;
@@ -1513,7 +1524,9 @@ util_RPCStatsGetDone(const void *iterationId, afs_status_p st)
  */
 
 int ADMINAPI
-util_RPCStatsStateGet(struct rx_connection *conn, int (*rpc) (),
+util_RPCStatsStateGet(struct rx_connection *conn, 
+                     int (*rpc) (struct rx_connection *,
+                                 afs_RPCStatsState_p),
                      afs_RPCStatsState_p state, afs_status_p st)
 {
     int rc = 0;
@@ -1569,7 +1582,8 @@ util_RPCStatsStateGet(struct rx_connection *conn, int (*rpc) (),
  */
 
 int ADMINAPI
-util_RPCStatsStateEnable(struct rx_connection *conn, int (*rpc) (),
+util_RPCStatsStateEnable(struct rx_connection *conn, 
+                        int (*rpc) (struct rx_connection *),
                         afs_status_p st)
 {
     int rc = 0;
@@ -1620,7 +1634,8 @@ util_RPCStatsStateEnable(struct rx_connection *conn, int (*rpc) (),
  */
 
 int ADMINAPI
-util_RPCStatsStateDisable(struct rx_connection *conn, int (*rpc) (),
+util_RPCStatsStateDisable(struct rx_connection *conn, 
+                         int (*rpc) (struct rx_connection *),
                          afs_status_p st)
 {
     int rc = 0;
@@ -1674,7 +1689,9 @@ util_RPCStatsStateDisable(struct rx_connection *conn, int (*rpc) (),
  */
 
 int ADMINAPI
-util_RPCStatsClear(struct rx_connection *conn, int (*rpc) (),
+util_RPCStatsClear(struct rx_connection *conn, 
+                  int (*rpc) (struct rx_connection *,
+                              afs_RPCStatsClearFlag_t),
                   afs_RPCStatsClearFlag_t flag, afs_status_p st)
 {
     int rc = 0;
@@ -1988,18 +2005,28 @@ ListCellsRPC(void *rpc_specific, int slot, int *last_item,
     afs_status_t tst = 0;
     cm_list_cell_get_p t = (cm_list_cell_get_p) rpc_specific;
     char *name;
+    serverList sl;
+    unsigned int n;
 
     /*
      * Get the next entry in the CellServDB.
      */
     name = t->cell[slot].cellname;
+    sl.serverList_len = 0;
+    sl.serverList_val = NULL;
+    memset(t->cell[slot].serverAddr, 0, sizeof(afs_int32)*UTIL_MAX_CELL_HOSTS);
     tst =
-       RXAFSCB_GetCellServDB(t->conn, t->index, &name,
-                             t->cell[slot].serverAddr);
+       RXAFSCB_GetCellServDB(t->conn, t->index, &name, &sl);
     if (tst) {
        goto fail_ListCellsRPC;
     }
     strcpy(t->cell[slot].cellname, name);
+    if (sl.serverList_val) {
+        for (n=0; n<sl.serverList_len && n<UTIL_MAX_CELL_HOSTS; n++) {
+            t->cell[slot].serverAddr[n] = sl.serverList_val[n];
+        }
+        xdr_free((xdrproc_t) xdr_serverList, &sl);
+    }
 
     /*
      * See if we've processed all the entries
@@ -2280,7 +2307,7 @@ util_CMClientConfig(struct rx_connection *conn, afs_ClientConfig_p config,
 {
     int rc = 0;
     afs_status_t tst = 0;
-    afs_int32 allocbytes;
+    afs_uint32 allocbytes;
     struct cacheConfig tconfig;
 
     if (conn == NULL) {
@@ -2506,7 +2533,7 @@ util_RXDebugBasicStats(rxdebugHandle_p handle, struct rx_debugStats *stats,
  */
 
 int ADMINAPI
-util_RXDebugRxStats(rxdebugHandle_p handle, struct rx_stats *stats,
+util_RXDebugRxStats(rxdebugHandle_p handle, struct rx_statistics *stats,
                    afs_uint32 * supportedValues, afs_status_p st)
 {
     int rc = 0;