netrestrict-netinfo-20081129
[openafs.git] / src / butc / tcmain.c
index a6ef344..935aea4 100644 (file)
@@ -40,7 +40,6 @@ RCSID
 #include <afs/afsutil.h>
 #include <rx/rx.h>
 #include <rx/rx_globals.h>
-#include <afs/auth.h>
 #include <rx/rxkad.h>
 #include <afs/cellconfig.h>
 #include <afs/keys.h>
@@ -55,7 +54,9 @@ RCSID
 #include "error_macros.h"
 #include <afs/budb_errs.h>
 #include "afs/butx.h"
+#define XBSA_TCMAIN
 #include "butc_xbsa.h"
+#include "butc_prototypes.h"
 
 #define N_SECURITY_OBJECTS 3
 #define ERRCODE_RANGE 8                /* from error_table.h */
@@ -66,7 +67,6 @@ RCSID
 
 struct ubik_client *cstruct;
 extern void TC_ExecuteRequest();
-extern int dbWatcher();
 FILE *logIO, *ErrorlogIO, *centralLogIO, *lastLogIO;
 char lFile[AFSDIR_PATH_MAX];
 char logFile[256];
@@ -92,20 +92,6 @@ char *closecallout;
 char *restoretofile;
 int forcemultiple;
 
-/* XBSA Global Parameters */
-afs_int32 xbsaType;
-#ifdef xbsa
-struct butx_transactionInfo butxInfo;
-
-#define rpc_c_protect_level_default 0
-afs_uint32 dumpRestAuthnLevel = rpc_c_protect_level_default;
-char *xbsaObjectOwner;
-char *appObjectOwner;
-char *adsmServerName;
-char *xbsaSecToken;
-char *xbsalGName;
-#endif
-
 int maxpass;
 #define PASSESMIN  1
 #define PASSESMAX  10
@@ -119,6 +105,10 @@ afs_int32 statusSize;
 afs_int32 BufferSize;          /* Size in B stored for data */
 char *centralLogFile;
 afs_int32 lastLog;             /* Log last pass info */
+int rxBind = 0;
+
+#define ADDRSPERSITE 16         /* Same global is in rx/rx_user.c */
+afs_uint32 SHostAddrs[ADDRSPERSITE];
 
 /* dummy routine for the audit work.  It should do nothing since audits */
 /* occur at the server level and bos is not a server. */
@@ -128,8 +118,7 @@ osi_audit()
 }
 
 static afs_int32
-SafeATOL(anum)
-     register char *anum;
+SafeATOL(register char *anum)
 {
     register afs_int32 total;
     register int tc;
@@ -164,10 +153,8 @@ SafeATOL(anum)
  *     should deal with signed numbers. Should signal error if no digits
  *     seen.
  */
-atocl(numstring, crunit, number)
-     char *numstring;
-     char crunit;              /* Units to report number in */
-     afs_int32 *number;
+int
+atocl(char *numstring, char crunit, afs_int32 *number)
 {
     float total;
     afs_int32 runits;
@@ -210,7 +197,7 @@ atocl(numstring, crunit, number)
     }
 
     count =
-       sscanf(numstring, "%f%c%s", (unsigned char *)&total, &cunit, rest);
+       sscanf(numstring, "%f%c%s", &total, &cunit, rest);
     if ((count > 2) || (count <= 0))
        return -1;
     if (count == 1)
@@ -264,11 +251,9 @@ atocl(numstring, crunit, number)
 
 /* replace last two ocurrences of / by _ */
 static
-stringReplace(name)
-     char *name;
+stringReplace(char *name)
 {
     char *pos;
-    int i;
     char buffer[256];
 
     pos = strrchr(name, '/');
@@ -281,9 +266,7 @@ stringReplace(name)
 }
 
 static
-stringNowReplace(logFile, deviceName)
-     char *logFile, *deviceName;
-
+stringNowReplace(char *logFile, char *deviceName)
 {
     char *pos = 0;
     char storeDevice[256];
@@ -333,10 +316,7 @@ stringNowReplace(logFile, deviceName)
 
 #define        LINESIZE        256
 static afs_int32
-GetDeviceConfig(filename, config, portOffset)
-     char *filename;
-     struct tapeConfig *config;
-     afs_int32 portOffset;
+GetDeviceConfig(char *filename, struct tapeConfig *config, afs_int32 portOffset)
 {
     FILE *devFile = 0;
     char line[LINESIZE];
@@ -425,9 +405,7 @@ GetDeviceConfig(filename, config, portOffset)
 /* GetConfigParams
  */
 static afs_int32
-GetConfigParams(filename, port)
-     char *filename;
-     afs_int32 port;
+GetConfigParams(char *filename, afs_int32 port)
 {
     char paramFile[256];
     FILE *devFile = 0;
@@ -642,7 +620,6 @@ GetConfigParams(filename, port)
 #endif
            }
        }
-
 #ifndef xbsa
        /* All the xbsa spacific parameters */
        else if (!strcmp(cmd, "TYPE") || !strcmp(cmd, "NODE")
@@ -851,12 +828,9 @@ GetConfigParams(filename, port)
     return (code);
 }
 
-static
-WorkerBee(as, arock)
-     struct cmd_syndesc *as;
-     char *arock;
+static int
+WorkerBee(struct cmd_syndesc *as, void *arock)
 {
-    char *pid;
     register afs_int32 code;
     struct rx_securityClass *(securityObjects[3]);
     struct rx_service *service;
@@ -865,7 +839,6 @@ WorkerBee(as, arock)
     int localauth;
     /*process arguments */
     afs_int32 portOffset = 0;
-    afs_int32 logIOName;
 #ifdef AFS_PTHREAD_ENV
     pthread_t dbWatcherPid;
     pthread_attr_t tattr;
@@ -873,6 +846,8 @@ WorkerBee(as, arock)
 #else
     PROCESS dbWatcherPid;
 #endif
+    time_t t;
+    afs_uint32 host = htonl(INADDR_ANY);
 
     debugLevel = 0;
 
@@ -979,7 +954,9 @@ WorkerBee(as, arock)
     if (centralLogFile) {
        struct stat sbuf;
        afs_int32 statcode;
+#ifndef AFS_NT40_ENV
        char path[AFSDIR_PATH_MAX];
+#endif
 
        statcode = stat(centralLogFile, &sbuf);
        centralLogIO = fopen(centralLogFile, "a");
@@ -1053,8 +1030,26 @@ WorkerBee(as, arock)
        autoQuery = 0;
 
     localauth = (as->parms[5].items ? 1 : 0);
+    rxBind = (as->parms[8].items ? 1 : 0);
+
+    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];
+    }
 
-    code = rx_Init(htons(BC_TAPEPORT + portOffset));
+    code = rx_InitHost(host, htons(BC_TAPEPORT + portOffset));
     if (code) {
        TapeLog(0, 0, code, 0, "rx init failed on port %u\n",
                BC_TAPEPORT + portOffset);
@@ -1094,7 +1089,7 @@ WorkerBee(as, arock)
     }
 
     service =
-       rx_NewService(0, 1, "BUTC", securityObjects, 3, TC_ExecuteRequest);
+       rx_NewServiceHost(host, 0, 1, "BUTC", securityObjects, 3, TC_ExecuteRequest);
     if (!service) {
        TLog(0, "rx_NewService");
        exit(1);
@@ -1146,7 +1141,8 @@ WorkerBee(as, arock)
 
     TLog(0, "Starting Tape Coordinator: Port offset %u   Debug level %u\n",
         portOffset, debugLevel);
-    TLog(0, "Token expires: %s\n", cTIME(&ttoken.endTime));
+    t = ttoken.endTime;
+    TLog(0, "Token expires: %s\n", cTIME(&t));
 
     rx_StartServer(1);         /* Donate this process to the server process pool */
     TLog(0, "Error: StartServer returned");
@@ -1157,9 +1153,8 @@ WorkerBee(as, arock)
 #include "AFS_component_version_number.c"
 #endif
 
-main(argc, argv)
-     int argc;
-     char **argv;
+int
+main(int argc, char **argv)
 {
     register struct cmd_syndesc *ts;
     register struct cmd_item *ti;
@@ -1196,6 +1191,8 @@ main(argc, argv)
                "file to restore to");
     cmd_AddParm(ts, "-xbsaforcemultiple", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE),
                "Force multiple XBSA server support");
+    cmd_AddParm(ts, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
+               "bind Rx socket");
 
     /* Initialize dirpaths */
     if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {