s3: util: Do not take over stderr when there is no log file
[samba.git] / lib / util / debug.c
index d30b1a9fae504b2e7d28c248a6861a2204ee12b8..d41e0f99c7703e0498a5929749c7f16f49462459 100644 (file)
@@ -480,8 +480,8 @@ static void debug_set_backends(const char *param)
 static void debug_backends_log(const char *msg, int msg_level)
 {
        char msg_no_nl[FORMAT_BUFR_SIZE];
-       unsigned i;
-       int len;
+       size_t i;
+       size_t len;
 
        /*
         * Some backends already add an extra newline, so also provide
@@ -540,6 +540,17 @@ static const char *default_classname_table[] = {
        [DBGC_AUTH_AUDIT] =     "auth_audit",
        [DBGC_AUTH_AUDIT_JSON] = "auth_json_audit",
        [DBGC_KERBEROS] =       "kerberos",
+       [DBGC_DRS_REPL] =       "drs_repl",
+       [DBGC_SMB2] =           "smb2",
+       [DBGC_SMB2_CREDITS] =   "smb2_credits",
+       [DBGC_DSDB_AUDIT]  =    "dsdb_audit",
+       [DBGC_DSDB_AUDIT_JSON] = "dsdb_json_audit",
+       [DBGC_DSDB_PWD_AUDIT]  =        "dsdb_password_audit",
+       [DBGC_DSDB_PWD_AUDIT_JSON] = "dsdb_password_json_audit",
+       [DBGC_DSDB_TXN_AUDIT]  =        "dsdb_transaction_audit",
+       [DBGC_DSDB_TXN_AUDIT_JSON] = "dsdb_transaction_json_audit",
+       [DBGC_DSDB_GROUP_AUDIT] =       "dsdb_group_audit",
+       [DBGC_DSDB_GROUP_AUDIT_JSON] = "dsdb_group_json_audit",
 };
 
 /*
@@ -548,7 +559,7 @@ static const char *default_classname_table[] = {
  */
 static const int debug_class_list_initial[ARRAY_SIZE(default_classname_table)];
 
-static int debug_num_classes = 0;
+static size_t debug_num_classes = 0;
 int     *DEBUGLEVEL_CLASS = discard_const_p(int, debug_class_list_initial);
 
 
@@ -627,7 +638,7 @@ utility lists registered debug class names's
 char *debug_list_class_names_and_levels(void)
 {
        char *buf = NULL;
-       unsigned int i;
+       size_t i;
        /* prepare strings */
        for (i = 0; i < debug_num_classes; i++) {
                buf = talloc_asprintf_append(buf,
@@ -648,7 +659,7 @@ char *debug_list_class_names_and_levels(void)
 
 static int debug_lookup_classname_int(const char* classname)
 {
-       int i;
+       size_t i;
 
        if (!classname) return -1;
 
@@ -738,7 +749,7 @@ static int debug_lookup_classname(const char *classname)
 
 static void debug_dump_status(int level)
 {
-       int q;
+       size_t q;
 
        DEBUG(level, ("INFO: Current debug levels:\n"));
        for (q = 0; q < debug_num_classes; q++) {
@@ -787,7 +798,7 @@ bool debug_parse_levels(const char *params_str)
        size_t str_len = strlen(params_str);
        char str[str_len+1];
        char *tok, *saveptr;
-       int i;
+       size_t i;
 
        /* Just in case */
        debug_init();
@@ -1066,8 +1077,11 @@ bool reopen_logs_internal(void)
        force_check_log_size();
        (void)umask(oldumask);
 
-       /* Take over stderr to catch output into logs */
-       if (state.fd > 0) {
+       /*
+        * If log file was opened or created successfully, take over stderr to
+        * catch output into logs.
+        */
+       if (new_fd != -1) {
                if (dup2(state.fd, 2) == -1) {
                        /* Close stderr too, if dup2 can't point it -
                           at the logfile.  There really isn't much