Use asprintf for string construction
[openafs.git] / src / bozo / bosserver.c
index 169685b..77c86f5 100644 (file)
@@ -99,6 +99,24 @@ bozo_rxstat_userok(struct rx_call *call)
     return afsconf_SuperUser(bozo_confdir, call, NULL);
 }
 
+/**
+ * Return true if this name is a member of the local realm.
+ */
+int
+bozo_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
+{
+    struct afsconf_dir *dir = (struct afsconf_dir *)rock;
+    afs_int32 islocal = 0;     /* default to no */
+    int code;
+
+    code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
+    if (code) {
+       bozo_Log("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
+                code, name, inst, cell);
+    }
+    return islocal;
+}
+
 /* restart bozo process */
 int
 bozo_ReBozo(void)
@@ -668,28 +686,18 @@ static char *
 make_pid_filename(char *ainst, char *aname)
 {
     char *buffer = NULL;
-    int length;
 
-    length = strlen(DoPidFiles) + strlen(ainst) + 6;
     if (aname && *aname) {
-       length += strlen(aname) + 1;
-    }
-    buffer = malloc(length * sizeof(char));
-    if (!buffer) {
-       if (aname) {
+       asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname);
+       if (buffer == NULL)
            bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
                     ainst, aname);
-       } else {
-           bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
-       }
     } else {
-       if (aname && *aname) {
-           snprintf(buffer, length, "%s/%s.%s.pid", DoPidFiles, ainst,
-                    aname);
-       } else {
-           snprintf(buffer, length, "%s/%s.pid", DoPidFiles, ainst);
-       }
+       asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst);
+       if (buffer == NULL)
+           bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
     }
+
     return buffer;
 }
 
@@ -1082,6 +1090,16 @@ main(int argc, char **argv, char **envp)
        exit(code);
     }
 
+    /* Disable jumbograms */
+    rx_SetNoJumbo();
+
+    if (rxMaxMTU != -1) {
+       if (rx_SetMaxMTU(rxMaxMTU) != 0) {
+           bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
+           exit(1);
+       }
+    }
+
     code = LWP_CreateProcess(BozoDaemon, BOZO_LWP_STACKSIZE, /* priority */ 1,
                             /* param */ NULL , "bozo-the-clown",
                             &bozo_pid);
@@ -1121,6 +1139,9 @@ main(int argc, char **argv, char **envp)
        }
     }
 
+    /* initialize audit user check */
+    osi_audit_set_user_check(tdir, bozo_IsLocalRealmMatch);
+
     /* read init file, starting up programs */
     if ((code = ReadBozoFile(0))) {
        bozo_Log
@@ -1144,16 +1165,6 @@ main(int argc, char **argv, char **envp)
        bozo_CreatePidFile("bosserver", NULL, getpid());
     }
 
-    /* Disable jumbograms */
-    rx_SetNoJumbo();
-
-    if (rxMaxMTU != -1) {
-       if (rx_SetMaxMTU(rxMaxMTU) != 0) {
-           bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU);
-           exit(1);
-       }
-    }
-
     tservice = rx_NewServiceHost(host, 0, /* service id */ 1,
                                 "bozo", securityClasses, numClasses,
                                 BOZO_ExecuteRequest);