butc: fix int to float conversion warning
[openafs.git] / src / butc / tcmain.c
index c539939..8402963 100644 (file)
 #define TL_PREFIX  "TL"
 #define CFG_PREFIX "CFG"
 
-struct ubik_client *cstruct;
+extern struct ubik_client *cstruct;
 FILE *logIO, *ErrorlogIO, *centralLogIO, *lastLogIO;
 char lFile[AFSDIR_PATH_MAX];
-char logFile[256];
-char ErrorlogFile[256];
-char lastLogFile[256];
+char logFile[AFSDIR_PATH_MAX + 256];
+char ErrorlogFile[AFSDIR_PATH_MAX + 256];
+char lastLogFile[AFSDIR_PATH_MAX + 256];
 char eFile[AFSDIR_PATH_MAX];
 char tapeConfigFile[AFSDIR_PATH_MAX];
 char pFile[AFSDIR_PATH_MAX];
@@ -237,31 +237,14 @@ atocl(char *numstring, char crunit, afs_int32 *number)
        total *= 1024.0;
 
     total += 0.5;              /* Round up */
-    if ((total > 0x7fffffff) || (total < 0))   /* Don't go over 2G */
-       total = 0x7fffffff;
+    if ((total >= 2147483648.0) || (total < 0))        /* Don't go over 2G */
+       *number = 2147483647;
+    else
+       *number = total;
 
-    *number = total;
     return (0);
 }
 
-/* replace last two ocurrences of / by _ */
-#if 0
-static int
-stringReplace(char *name)
-{
-    char *pos;
-    char buffer[256];
-
-    pos = strrchr(name, '/');
-    *pos = '_';
-    strcpy(buffer, pos);
-    pos = strrchr(name, '/');
-    *pos = '\0';
-    strcat(name, buffer);
-    return 0;
-}
-#endif
-
 static int
 stringNowReplace(char *logFile, char *deviceName)
 {
@@ -403,7 +386,7 @@ GetDeviceConfig(char *filename, struct tapeConfig *config, afs_int32 portOffset)
 static afs_int32
 GetConfigParams(char *filename, afs_int32 port)
 {
-    char paramFile[256];
+    char paramFile[AFSDIR_PATH_MAX + 257];
     FILE *devFile = 0;
     char line[LINESIZE], cmd[LINESIZE], value[LINESIZE];
     afs_int32 code = 0;
@@ -437,13 +420,13 @@ GetConfigParams(char *filename, afs_int32 port)
     groupId = 0;               /* Group id for multiple dumps */
 
     /* Try opening the CFG_<port> file */
-    sprintf(paramFile, "%s_%d", filename, port);
+    snprintf(paramFile, sizeof(paramFile), "%s_%d", filename, port);
     devFile = fopen(paramFile, "r");
     if (devFile) {
        /* Set log names to TL_<port>, TL_<port>.lp and TE_<port> */
-       sprintf(logFile, "%s_%d", lFile, port);
-       sprintf(lastLogFile, "%s_%d.lp", lFile, port);
-       sprintf(ErrorlogFile, "%s_%d", eFile, port);
+       snprintf(logFile, sizeof(logFile), "%s_%d", lFile, port);
+       snprintf(lastLogFile, sizeof(lastLogFile), "%s_%d.lp", lFile, port);
+       snprintf(ErrorlogFile, sizeof(ErrorlogFile), "%s_%d", eFile, port);
     } else if (CONF_XBSA) {
        /* If configured as XBSA, a configuration file CFG_<port> must exist */
        printf("Cannot open configuration file %s", paramFile);
@@ -583,7 +566,7 @@ GetConfigParams(char *filename, afs_int32 port)
 
        else if (!strcmp(cmd, "BUFFERSIZE")) {
            afs_int32 size;
-           afs_int32 tapeblocks;
+           afs_int32 numTapeblocks;
 
            if (!CONF_XBSA) {
                if (atocl(value, 'K', &size)) {
@@ -594,11 +577,11 @@ GetConfigParams(char *filename, afs_int32 port)
                /* A tapeblock is 16KB. Determine # of tapeblocks. Then
                 * determine BufferSize needed for that many tapeblocks.
                 */
-               tapeblocks = size / 16;
-               if (tapeblocks <= 0)
-                   tapeblocks = 1;
-               printf("BUFFERSIZE is %u KBytes\n", (tapeblocks * 16));
-               BufferSize = tapeblocks * BUTM_BLOCKSIZE;
+               numTapeblocks = size / 16;
+               if (numTapeblocks <= 0)
+                   numTapeblocks = 1;
+               printf("BUFFERSIZE is %u KBytes\n", (numTapeblocks * 16));
+               BufferSize = numTapeblocks * BUTM_BLOCKSIZE;
            } else {
 #ifdef xbsa
                if (atocl(value, 'B', &size)) {
@@ -835,8 +818,8 @@ tc_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
 
     code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
     if (code) {
-       TLog(0, ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
-                code, name, inst, cell));
+       TLog(0, "Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
+                code, name, inst, cell);
     }
     return islocal;
 }
@@ -859,6 +842,7 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
 #else
     PROCESS dbWatcherPid;
 #endif
+    char hoststr[16];
     afs_uint32 host = htonl(INADDR_ANY);
     char *auditFileName = NULL;
     char *auditInterface = NULL;
@@ -1014,6 +998,12 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
        exit(1);
     }
 
+    if (afsconf_CountKeys(butc_confdir) == 0) {
+       TLog(0, "WARNING: No encryption keys found! "
+               "All authenticated accesses will fail. "
+               "Run akeyconvert or asetkey to import encryption keys.\n");
+    }
+
     /* Start auditing */
     osi_audit_init();
     if (as->parms[9].items) {
@@ -1096,6 +1086,8 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
             host = SHostAddrs[0];
     }
 
+    TLog(0, "butc binding rx to %s:%d\n",
+         afs_inet_ntoa_r(host, hoststr), 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",