Remove warnings in the update client and server
[openafs.git] / src / update / server.c
index 1de5292..0650af9 100644 (file)
@@ -10,8 +10,6 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
 
 #include <afs/stds.h>
 #ifdef AFS_AIX32_ENV
@@ -31,13 +29,7 @@ RCSID
 #include <sys/file.h>
 #include <dirent.h>
 #endif
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -50,12 +42,18 @@ RCSID
 #include <afs/cellconfig.h>
 #include <afs/afsutil.h>
 #include <afs/fileutil.h>
+#include <afs/com_err.h>
+#ifdef AFS_AIX_ENV
+#include <sys/statfs.h>
+#endif
 #include "update.h"
 #include "global.h"
 
-extern int UPDATE_ExecuteRequest();
 static int AddObject(char **expPath, char *dir);
 static int PathInDirectory(char *dir, char *path);
+int update_SendFile(int, struct rx_call *, struct stat *);
+int update_SendDirInfo(char *, struct rx_call *, struct stat *,
+                      char *origDir);
 
 struct afsconf_dir *cdir;
 int nDirs;
@@ -63,12 +61,16 @@ char *dirName[MAXENTRIES];
 int dirLevel[MAXENTRIES];
 char *whoami;
 
-static int Quit();
+static int Quit(char *);
+
+int rxBind = 0;
+
+#define ADDRSPERSITE 16         /* Same global is in rx/rx_user.c */
+afs_uint32 SHostAddrs[ADDRSPERSITE];
 
 /* check whether caller is authorized to manage RX statistics */
 int
-update_rxstat_userok(call)
-     struct rx_call *call;
+update_rxstat_userok(struct rx_call *call)
 {
     return afsconf_SuperUser(cdir, call, NULL);
 }
@@ -129,11 +131,8 @@ PathInDirectory(char *dir, char *path)
     return inDir;
 }
 
-
 int
-AuthOkay(call, name)
-     struct rx_call *call;
-     char *name;
+AuthOkay(struct rx_call *call, char *name)
 {
     int i;
     rxkad_level level;
@@ -167,7 +166,7 @@ AuthOkay(call, name)
 }
 
 int
-osi_audit()
+osi_audit(void)
 {
 /* this sucks but it works for now.
 */
@@ -179,12 +178,11 @@ osi_audit()
 #endif
 
 int
-main(argc, argv)
-     int argc;
-     char *argv[];
+main(int argc, char *argv[])
 {
     struct rx_securityClass *securityObjects[3];
     struct rx_service *service;
+    afs_uint32 host = htonl(INADDR_ANY);
 
     int a = 0;
     rxkad_level level;
@@ -236,15 +234,20 @@ main(argc, argv)
 
     for (a = 1; a < argc; a++) {
        if (argv[a][0] == '-') {        /* parse options */
-           char arg[256];
-           lcstring(arg, argv[a], sizeof(arg));
-           newLevel = StringToLevel(&argv[a][1]);
-           if (newLevel != -1) {
-               level = newLevel;       /* set new level */
+           if (strcmp(argv[a], "-rxbind") == 0) {
+               rxBind = 1;
                continue;
+           } else {
+               char arg[256];
+               lcstring(arg, argv[a], sizeof(arg));
+               newLevel = rxkad_StringToLevel(&argv[a][1]);
+               if (newLevel != -1) {
+                   level = newLevel;   /* set new level */
+                   continue;
+               }
            }
          usage:
-           Quit("Usage: upserver [<directory>+] [-crypt <directory>+] [-clear <directory>+] [-auth <directory>+] [-help]\n");
+           Quit("Usage: upserver [<directory>+] [-crypt <directory>+] [-clear <directory>+] [-auth <directory>+] [-rxbind] [-help]\n");
        } else {
            int dirlen;
            if (nDirs >= sizeof(dirName) / sizeof(dirName[0]))
@@ -272,9 +275,26 @@ main(argc, argv)
        exit(1);
     }
 
+    if (rxBind) {
+       afs_int32 ccode;
+        if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || 
+            AFSDIR_SERVER_NETINFO_FILEPATH) {
+            char reason[1024];
+            ccode = parseNetFiles(SHostAddrs, NULL, NULL,
+                                           ADDRSPERSITE, reason,
+                                           AFSDIR_SERVER_NETINFO_FILEPATH,
+                                           AFSDIR_SERVER_NETRESTRICT_FILEPATH);
+        } else 
+       {
+            ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
+        }
+        if (ccode == 1) 
+            host = SHostAddrs[0];
+    }
+
     /* Initialize Rx, telling it port number this server will use for its
      * single service */
-    if (rx_Init(htons(AFSCONF_UPDATEPORT)) < 0)
+    if (rx_InitHost(host, htons(AFSCONF_UPDATEPORT)) < 0)
        Quit("rx_init");
 
     /* Create a single security object, in this case the null security object,
@@ -298,8 +318,8 @@ main(argc, argv)
      * which is called to decode requests is passed in here
      * (UPDATE_ExecuteRequest). */
     service =
-       rx_NewService(0, UPDATE_SERVICEID, "UPDATE", securityObjects, 3,
-                     UPDATE_ExecuteRequest);
+       rx_NewServiceHost(host, 0, UPDATE_SERVICEID, "UPDATE", securityObjects,
+                         3, UPDATE_ExecuteRequest);
     if (service == (struct rx_service *)0)
        Quit("rx_NewService");
     rx_SetMaxProcs(service, 2);
@@ -315,9 +335,7 @@ main(argc, argv)
 /* fetch the file name and send it to the remote requester specified by call */
 
 int
-UPDATE_FetchFile(call, name)
-     struct rx_call *call;
-     char *name;
+UPDATE_FetchFile(struct rx_call *call, char *name)
 {
     int fd = -1;
     int error = 0;
@@ -326,7 +344,7 @@ UPDATE_FetchFile(call, name)
 
     /* construct a local path from a canonical (wire-format) path */
     if ((error = ConstructLocalPath(name, "/", &reqObject))) {
-       com_err(whoami, error, "Unable to construct local path");
+       afs_com_err(whoami, error, "Unable to construct local path");
        return UPDATE_ERROR;
     }
 
@@ -350,18 +368,15 @@ UPDATE_FetchFile(call, name)
 /* fetch dir info about directory name and send it to remote host associated
   with call. */
 int
-UPDATE_FetchInfo(call, name)
-     struct rx_call *call;
-     char *name;
+UPDATE_FetchInfo(struct rx_call *call, char *name)
 {
-    int fd = -1;
     int error = 0;
     struct stat status;
     char *reqObject;
 
     /* construct a local path from a canonical (wire-format) path */
     if ((error = ConstructLocalPath(name, "/", &reqObject))) {
-       com_err(whoami, error, "Unable to construct local path");
+       afs_com_err(whoami, error, "Unable to construct local path");
        return UPDATE_ERROR;
     }
 
@@ -375,13 +390,9 @@ UPDATE_FetchInfo(call, name)
        }
        if ((status.st_mode & S_IFMT) != S_IFDIR) {
            printf(" file %s is not a directory \n", reqObject);
-           if (fd >= 0)
-               close(fd);
            error = -1;
        }
 
-       if (fd >= 0)
-           close(fd);
        if (!error)
            error = update_SendDirInfo(reqObject, call, &status, name);
     }
@@ -390,27 +401,19 @@ UPDATE_FetchInfo(call, name)
 }
 
 static int
-Quit(msg, a, b)
-     char *msg;
+Quit(char *msg)
 {
-    fprintf(stderr, msg, a, b);
+    fprintf(stderr, msg);
     exit(1);
 }
 
 int
-update_SendFile(fd, call, status)
-     register int fd;
-     register struct rx_call *call;
-     register struct stat *status;
+update_SendFile(register int fd, register struct rx_call *call, register struct stat *status)
 {
     char *buffer = (char *)0;
     int blockSize;
     afs_int32 length, tlen;
-#ifdef notdef
-    XDR xdr;
-#endif
 #ifdef AFS_AIX_ENV
-#include <sys/statfs.h>
     struct statfs tstatfs;
 #endif
 
@@ -430,14 +433,8 @@ update_SendFile(fd, call, status)
        printf("malloc failed\n");
        return UPDATE_ERROR;
     }
-#ifdef notdef
-    xdrrx_create(&xdr, call, XDR_ENCODE);
-    if (!xdr_afs_int32(&xdr, &length))
-       error = UPDATE_ERROR;
-#else
     tlen = htonl(length);
-    rx_Write(call, &tlen, sizeof(afs_int32));  /* send length on fetch */
-#endif
+    rx_Write(call, (char *)&tlen, sizeof(afs_int32));  /* send length on fetch */
     while (!error && length) {
        register int nbytes = (length > blockSize ? blockSize : length);
        nbytes = read(fd, buffer, nbytes);
@@ -459,11 +456,10 @@ update_SendFile(fd, call, status)
 /* Enumerate dir (name) and write dir entry info into temp file. 
  */
 int
-update_SendDirInfo(name, call, status, origDir)
-     char *name;               /* Name of dir to enumerate */
-     register struct rx_call *call;    /* rx call */
-     register struct stat *status;     /* stat struct for dir */
-     char *origDir;            /* orig name of dir before being localized */
+update_SendDirInfo(char *name,         /* Name of dir to enumerate */
+     register struct rx_call *call,    /* rx call */
+     register struct stat *status,     /* stat struct for dir */
+     char *origDir)            /* orig name of dir before being localized */
 {
     DIR *dirp;
     struct dirent *dp;
@@ -524,7 +520,7 @@ update_SendDirInfo(name, call, status, origDir)
     }
     if (error == 0) {
        fd = open(dirInfoFile, O_RDONLY, 0);
-       if (fd) {
+       if (fd >= 0) {
            fstat(fd, &tstatus);
            errcode = update_SendFile(fd, call, &tstatus);
            if (errcode)
@@ -554,14 +550,14 @@ AddObject(char **expPath, char *dir)
 
     /* construct a local path from a canonical (wire-format) path */
     if ((error = ConstructLocalPath(dir, "/", expPath))) {
-       com_err(whoami, error, "Unable to construct local path");
+       afs_com_err(whoami, error, "Unable to construct local path");
        return error;
     }
 
     /* stat the object */
     error = stat(*expPath, &statbuf);
     if (error) {
-       com_err(whoami, error, ";Can't stat object.");
+       afs_com_err(whoami, error, ";Can't stat object.");
        return error;
     }
     /* now check if the object has an exportable (file/dir)  type */