make bozo honor -rxbind correctly
[openafs.git] / src / bozo / bosserver.c
index 811dc31..b7a6bb7 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
@@ -9,56 +9,44 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
+
+#include <afs/procmgmt.h>
+#include <roken.h>
 
 #ifdef IGNORE_SOME_GCC_WARNINGS
 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
 #endif
 
-#include <afs/stds.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
 #ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
 #endif
+
 #ifdef AFS_NT40_ENV
-#include <winsock2.h>
 #include <direct.h>
-#include <io.h>
 #include <WINNT/afsevent.h>
-#else
-#include <unistd.h>
-#include <netinet/in.h>
-#include <syslog.h>
 #endif /* AFS_NT40_ENV */
-#include <afs/cellconfig.h>
+
 #include <rx/rx.h>
 #include <rx/xdr.h>
 #include <rx/rx_globals.h>
-#include "bosint.h"
-#include "bnode.h"
-#include "bosprototypes.h"
 #include <rx/rxkad.h>
 #include <rx/rxstat.h>
 #include <afs/keys.h>
 #include <afs/ktime.h>
 #include <afs/afsutil.h>
 #include <afs/fileutil.h>
-#include <afs/procmgmt.h>      /* signal(), kill(), wait(), etc. */
 #include <afs/audit.h>
 #include <afs/cellconfig.h>
+
 #if defined(AFS_SGI_ENV)
 #include <afs/afs_args.h>
 #endif
 
+#include "bosint.h"
+#include "bnode.h"
+#include "bosprototypes.h"
+
 #define BOZO_LWP_STACKSIZE     16000
 extern struct bnode_ops fsbnode_ops, dafsbnode_ops, ezbnode_ops, cronbnode_ops;
 
@@ -605,7 +593,7 @@ tweak_config(void)
  * fundamental errors occur.
  *
  * This routine requires
- * 
+ *
  * #include <sys/types.h>
  * #include <sys/stat.h>
  * #include <fcntl.h>
@@ -627,7 +615,7 @@ tweak_config(void)
 static void
 background(void)
 {
-    /* 
+    /*
      * A process is a process group leader if its process ID
      * (getpid()) and its process group ID (getpgrp()) are the same.
      */
@@ -744,14 +732,14 @@ main(int argc, char **argv, char **envp)
     struct sigaction nsa;
 
     /* for some reason, this permits user-mode RX to run a lot faster.
-     * we do it here in the bosserver, so we don't have to do it 
+     * we do it here in the bosserver, so we don't have to do it
      * individually in each server.
      */
     tweak_config();
 
     /*
-     * 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.
      */
@@ -840,14 +828,14 @@ main(int argc, char **argv, char **envp)
        }
        else if (!strcmp(argv[code], "-rxmaxmtu")) {
            if ((code + 1) >= argc) {
-               fprintf(stderr, "missing argument for -rxmaxmtu\n"); 
-               exit(1); 
+               fprintf(stderr, "missing argument for -rxmaxmtu\n");
+               exit(1);
            }
            rxMaxMTU = atoi(argv[++code]);
-           if ((rxMaxMTU < RX_MIN_PACKET_SIZE) || 
+           if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
                (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
                printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n",
-                       rxMaxMTU, RX_MIN_PACKET_SIZE, 
+                       rxMaxMTU, RX_MIN_PACKET_SIZE,
                        RX_MAX_PACKET_DATA_SIZE);
                exit(1);
            }
@@ -926,7 +914,7 @@ main(int argc, char **argv, char **envp)
     fflush(stdout);
 #endif
 
-    /* go into the background and remove our controlling tty, close open 
+    /* go into the background and remove our controlling tty, close open
        file desriptors
      */
 
@@ -937,7 +925,7 @@ main(int argc, char **argv, char **envp)
 
     if ((!DoSyslog)
 #ifndef AFS_NT40_ENV
-       && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) && 
+       && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
        !(S_ISFIFO(sb.st_mode)))
 #endif
        ) {
@@ -975,8 +963,28 @@ main(int argc, char **argv, char **envp)
     /* Write current state of directory permissions to log file */
     DirAccessOK();
 
+    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];
+    }
+
     for (i = 0; i < 10; i++) {
-       code = rx_Init(htons(AFSCONF_NANNYPORT));
+       if (rxBind) {
+           code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
+       } else {
+           code = rx_Init(htons(AFSCONF_NANNYPORT));
+       }
        if (code) {
            bozo_Log("can't initialize rx: code=%d\n", code);
            sleep(3);
@@ -1042,7 +1050,7 @@ main(int argc, char **argv, char **envp)
     rx_SetRxStatUserOk(bozo_rxstat_userok);
 
     afsconf_SetNoAuthFlag(tdir, noAuth);
-    afsconf_BuildServerSecurityObjects(tdir, 0, &securityClasses, &numClasses);
+    afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
 
     /* Disable jumbograms */
     rx_SetNoJumbo();
@@ -1051,23 +1059,6 @@ main(int argc, char **argv, char **envp)
        rx_SetMaxMTU(rxMaxMTU);
     }
 
-    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];
-    }
-
     tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
                                 "bozo", securityClasses, numClasses,
                                 BOZO_ExecuteRequest);