afsconf: Rework security flags
[openafs.git] / src / update / server.c
index 3bb4b0e..b62dc87 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
@@ -10,8 +10,8 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <afs/procmgmt.h>
+#include <roken.h>
 
 #include <afs/stds.h>
 #ifdef AFS_AIX32_ENV
@@ -23,21 +23,14 @@ RCSID
 #include <WINNT/afsevent.h>
 #include <fcntl.h>
 #include <io.h>
-#include <afs/dirent.h>
 #include <afs/procmgmt.h>
 #else
 #include <netdb.h>
 #include <netinet/in.h>
 #include <sys/file.h>
-#include <dirent.h>
 #endif
-#ifdef HAVE_STRING_H
+#include <dirent.h>
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -50,12 +43,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 +62,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 +132,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 +167,7 @@ AuthOkay(call, name)
 }
 
 int
-osi_audit()
+osi_audit(void)
 {
 /* this sucks but it works for now.
 */
@@ -179,12 +179,12 @@ osi_audit()
 #endif
 
 int
-main(argc, argv)
-     int argc;
-     char *argv[];
+main(int argc, char *argv[])
 {
-    struct rx_securityClass *securityObjects[3];
+    struct rx_securityClass **securityClasses;
+    afs_int32 numClasses;
     struct rx_service *service;
+    afs_uint32 host = htonl(INADDR_ANY);
 
     int a = 0;
     rxkad_level level;
@@ -192,8 +192,8 @@ main(argc, argv)
 
 #ifdef AFS_AIX32_ENV
     /*
-     * The following signal action for AIX is necessary so that in case of a 
-     * crash (i.e. core is generated) we can include the user's data section 
+     * The following signal action for AIX is necessary so that in case of a
+     * crash (i.e. core is generated) we can include the user's data section
      * in the core dump. Unfortunately, by default, only a partial core is
      * generated which, in many cases, isn't too useful.
      */
@@ -236,15 +236,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,34 +277,39 @@ 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,
-     * for unauthenticated connections, which will be used to control security
-     * on connections made to this server. */
-
-    /* WHAT A JOKE!  Let's use rxkad at least so we know who we're talking to,
-     * then sometimes require full encryption. */
-
-    /* rxnull and rxvab are no longer supported */
-    securityObjects[0] = rxnull_NewServerSecurityObject();
-
-    securityObjects[1] = (struct rx_securityClass *)0;
+    afsconf_BuildServerSecurityObjects(cdir, &securityClasses, &numClasses);
 
-    securityObjects[2] =
-       rxkad_NewServerSecurityObject(rxkad_clear, cdir, afsconf_GetKey, 0);
-    if (securityObjects[2] == (struct rx_securityClass *)0)
+    if (securityClasses[2] == NULL)
        Quit("rxkad_NewServerSecurityObject");
 
     /* Instantiate a single UPDATE service.  The rxgen-generated procedure
      * 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", securityClasses,
+                         numClasses, UPDATE_ExecuteRequest);
     if (service == (struct rx_service *)0)
        Quit("rx_NewService");
     rx_SetMaxProcs(service, 2);
@@ -315,9 +325,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 +334,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,9 +358,7 @@ 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 error = 0;
     struct stat status;
@@ -360,7 +366,7 @@ UPDATE_FetchInfo(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;
     }
 
@@ -385,27 +391,19 @@ UPDATE_FetchInfo(call, name)
 }
 
 static int
-Quit(msg, a, b)
-     char *msg;
+Quit(char *msg)
 {
-    fprintf(stderr, msg, a, b);
+    fprintf(stderr, "%s", msg);
     exit(1);
 }
 
 int
-update_SendFile(fd, call, status)
-     register int fd;
-     register struct rx_call *call;
-     register struct stat *status;
+update_SendFile(int fd, struct rx_call *call, 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
 
@@ -425,16 +423,10 @@ 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);
+       int nbytes = (length > blockSize ? blockSize : length);
        nbytes = read(fd, buffer, nbytes);
        if (nbytes <= 0) {
            fprintf(stderr, "File system read failed\n");
@@ -451,20 +443,19 @@ update_SendFile(fd, call, status)
     return error;
 }
 
-/* Enumerate dir (name) and write dir entry info into temp file. 
+/* 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 */
+     struct rx_call *call,     /* rx call */
+     struct stat *status,      /* stat struct for dir */
+     char *origDir)            /* orig name of dir before being localized */
 {
     DIR *dirp;
     struct dirent *dp;
     FILE *stream;
     struct stat tstatus;
-    char filename[MAXSIZE], dirInfoFile[MAXSIZE];
+    char filename[MAXFNSIZE], dirInfoFile[MAXFNSIZE];
     int fd, tfd, errcode, error, err;
 
     error = 0;
@@ -486,7 +477,7 @@ update_SendDirInfo(name, call, status, origDir)
                goto fail;
            }
            if ((tstatus.st_mode & S_IFMT) != S_IFDIR) {        /* not a directory */
-               char dirEntry[MAXSIZE];
+               char dirEntry[MAXFNSIZE];
 
                strcpy(dirEntry, origDir);
                strcat(dirEntry, "/");
@@ -536,9 +527,9 @@ update_SendDirInfo(name, call, status, origDir)
 /* AddObject() - Adds the object to the list of exported objects after
  *     converting to a local path.
  *
- * expPath : points to allocated storage in which the exportable path is 
+ * expPath : points to allocated storage in which the exportable path is
  *           passed back.
- * dir     : dir name passed in for export 
+ * dir     : dir name passed in for export
  *
  */
 static int
@@ -549,14 +540,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 */