*query_host = 0;
*base_directory = 0;
- setup_logging(argv[0],DEBUG_STDOUT);
mem_ctx = talloc_init("client.c/main");
if (!mem_ctx) {
d_printf("\nclient.c: Not enough memory\n");
exit(1);
}
- if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
- fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
- argv[0], dyn_CONFIGFILE);
- }
-
pc = poptGetContext("smbclient", argc, (const char **) argv, long_options, 0);
poptSetOtherOptionHelp(pc, "[OPTIONS] service <password>");
case 'I':
dest_ip = poptGetOptArg(pc);
break;
- case 'E':
- setup_logging("client", DEBUG_STDERR);
- break;
-
case 'L':
remember_query_host(poptGetOptArg(pc), query_host);
break;
}
}
- load_interfaces();
-
smbclient_init_subsystems;
if(poptPeekArg(pc)) {
#define DEBUGADDC(class, level, body) DEBUG(level, body)
#define DEBUGTAB(n) do_debug_tab(n)
-enum debug_logtype {DEBUG_FILE, DEBUG_STDOUT, DEBUG_STDERR};
+enum debug_logtype {DEBUG_STDOUT = 0, DEBUG_FILE = 1, DEBUG_STDERR = 2};
/* keep some debug class defines for now to avoid changing old code too much */
#define DBGC_AUTH 0
* -i,--scope
*/
-enum {OPT_OPTION=1,OPT_LEAK_REPORT,OPT_LEAK_REPORT_FULL};
+enum {OPT_OPTION=1,OPT_LEAK_REPORT,OPT_LEAK_REPORT_FULL, OPT_DEBUG_STDERR};
struct cli_credentials *cmdline_credentials = NULL;
{
const char *pname;
+ if (reason == POPT_CALLBACK_REASON_POST) {
+ /* Hook any 'every Samba program must do this, after
+ * the smb.conf is setup' functions here */
+ lp_load(dyn_CONFIGFILE,True,False,False);
+ load_interfaces();
+ return;
+ }
+
/* Find out basename of current program */
pname = strrchr_m(poptGetInvocationName(con),'/');
pname++;
if (reason == POPT_CALLBACK_REASON_PRE) {
- char *logfile = talloc_asprintf(NULL, "%s/log.%s", dyn_LOGFILEBASE, pname);
- lp_set_cmdline("log file", logfile);
- talloc_free(logfile);
+ setup_logging(pname, DEBUG_STDOUT);
return;
}
lp_set_cmdline("log level", arg);
break;
+ case OPT_DEBUG_STDERR:
+ setup_logging(pname, DEBUG_STDERR);
+ break;
+
case 'V':
printf( "Version %s\n", SAMBA_VERSION_STRING );
exit(0);
case OPT_LEAK_REPORT_FULL:
talloc_enable_leak_report_full();
break;
+
}
}
};
struct poptOption popt_common_samba[] = {
- { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback },
+ { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, popt_common_callback },
{ "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" },
+ { "debug-stderr", 0, POPT_ARG_NONE, NULL, OPT_DEBUG_STDERR, "Send debug output to STDERR", NULL },
{ "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file", "CONFIGFILE" },
{ "option", 0, POPT_ARG_STRING, NULL, OPT_OPTION, "Set smb.conf option from command line", "name=value" },
{ "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files", "LOGFILEBASE" },
char *fname = NULL;
int old_fd = state.fd;
- state.fd = 0;
-
switch (state.logtype) {
case DEBUG_STDOUT:
state.fd = 1;
if ((*logfile) == '/') {
fname = strdup(logfile);
} else {
- asprintf(&fname, "%s/%s.log", dyn_LOGFILEBASE, logfile);
+ asprintf(&fname, "%s/%s.log", dyn_LOGFILEBASE, state.prog_name);
}
if (fname) {
- state.fd = open(fname, O_CREAT|O_APPEND|O_WRONLY, 0644);
+ int newfd = open(fname, O_CREAT|O_APPEND|O_WRONLY, 0600);
+ if (newfd == -1) {
+ DEBUG(1, ("Failed to open new logfile: %s\n", fname));
+ } else {
+ state.fd = newfd;
+ }
free(fname);
+ } else {
+ DEBUG(1, ("Failed to find name for file-based logfile!\n"));
}
+
break;
}
*/
void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
{
- state.logtype = new_logtype;
- state.prog_name = prog_name;
+ if (state.logtype < new_logtype) {
+ state.logtype = new_logtype;
+ }
+ if (prog_name) {
+ state.prog_name = prog_name;
+ }
reopen_logs();
}
WERROR error, error2;
struct poptOption long_options[] = {
POPT_AUTOHELP
- POPT_COMMON_CREDENTIALS
{"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL },
{"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL", NULL },
{"remote", 'R', POPT_ARG_STRING, NULL, 0, "Connect to remote server" , NULL },
{"local", 'L', POPT_ARG_NONE, NULL, 0, "Open local registry", NULL },
+ POPT_COMMON_SAMBA
+ POPT_COMMON_CREDENTIALS
+ POPT_COMMON_VERSION
POPT_TABLEEND
};
regdiff_init_subsystems;
- if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
- fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
- }
-
-
pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
while((opt = poptGetNextOpt(pc)) != -1) {
return 1;
}
}
- setup_logging(argv[0], DEBUG_STDOUT);
poptFreeContext(pc);
WERROR error;
struct poptOption long_options[] = {
POPT_AUTOHELP
- POPT_COMMON_CREDENTIALS
{"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL},
+ POPT_COMMON_SAMBA
+ POPT_COMMON_CREDENTIALS
POPT_TABLEEND
};
regpatch_init_subsystems;
- if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
- fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
- }
-
-
pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
while((opt = poptGetNextOpt(pc)) != -1) {
}
- setup_logging(argv[0], DEBUG_STDOUT);
-
if (remote) {
error = reg_open_remote (&h, cmdline_credentials, remote);
} else {
struct registry_context *h = NULL;
struct poptOption long_options[] = {
POPT_AUTOHELP
- POPT_COMMON_CREDENTIALS
{"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
{"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL},
+ POPT_COMMON_SAMBA
+ POPT_COMMON_CREDENTIALS
+ POPT_COMMON_VERSION
POPT_TABLEEND
};
regshell_init_subsystems;
- if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
- fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
- }
-
-
pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
while((opt = poptGetNextOpt(pc)) != -1) {
}
- setup_logging("regtree", DEBUG_STDOUT);
-
if (remote) {
error = reg_open_remote (&h, cmdline_credentials, remote);
} else if (backend) {
int fullpath = 0, no_values = 0;
struct poptOption long_options[] = {
POPT_AUTOHELP
- POPT_COMMON_CREDENTIALS
{"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
{"fullpath", 'f', POPT_ARG_NONE, &fullpath, 0, "show full paths", NULL},
{"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL },
{"no-values", 'V', POPT_ARG_NONE, &no_values, 0, "don't show values", NULL},
+ POPT_COMMON_SAMBA
+ POPT_COMMON_CREDENTIALS
POPT_TABLEEND
};
regtree_init_subsystems;
- if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
- fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
- }
-
-
pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
while((opt = poptGetNextOpt(pc)) != -1) {
}
- setup_logging("regtree", DEBUG_STDOUT);
-
if (remote) {
error = reg_open_remote(&h, cmdline_credentials, remote);
} else if (backend) {
int max_runtime = 0;
struct poptOption long_options[] = {
POPT_AUTOHELP
- POPT_COMMON_SAMBA
{"interactive", 'i', POPT_ARG_VAL, &interactive, True,
"Run interactive (not a daemon)", NULL},
{"model", 'M', POPT_ARG_STRING, &model, True,
"Select process model", "MODEL"},
{"maximum-runtime", 0, POPT_ARG_INT, &max_runtime, True,
"set maximum time for smbd to live", "seconds"},
+ POPT_COMMON_SAMBA
POPT_COMMON_VERSION
POPT_TABLEEND
};
poptFreeContext(pc);
- setup_logging(argv[0], interactive?DEBUG_STDOUT:DEBUG_FILE);
+ setup_logging(NULL, interactive?DEBUG_STDOUT:DEBUG_FILE);
setup_signals();
/* we want total control over the permissions on created files,
so set our umask to 0 */
umask(0);
- reopen_logs();
-
DEBUG(0,("smbd version %s started.\n", SAMBA_VERSION_STRING));
DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2005\n"));
exit(1);
}
- lp_load(dyn_CONFIGFILE, False, False, True);
-
- reopen_logs();
- load_interfaces();
-
if (!interactive) {
DEBUG(3,("Becoming a daemon.\n"));
become_daemon(True);
while(poptGetNextOpt(pc) != -1);
- /* the following functions are part of the Samba debugging
- facilities. See lib/debug.c */
- setup_logging("smbiconv", DEBUG_STDOUT);
-
if (preload_modules[0]) smb_load_modules(preload_modules);
if(output) {
POPT_TABLEEND
};
- setup_logging("smbtorture", DEBUG_STDOUT);
-
#ifdef HAVE_SETBUFFER
setbuffer(stdout, NULL, 0);
#endif
alarm(max_runtime);
}
- lp_load(dyn_CONFIGFILE,True,False,False);
- load_interfaces();
-
smbtorture_init_subsystems;
POPT_TABLEEND
};
- setup_logging("ndrdump", DEBUG_STDOUT);
-
ndrdump_init_subsystems;
pc = poptGetContext("ndrdump", argc, argv, long_options, 0);
POPT_TABLEEND
};
- setup_logging("net", DEBUG_STDOUT);
-
#ifdef HAVE_SETBUFFER
setbuffer(stdout, NULL, 0);
#endif
pc = poptGetContext("net", argc, (const char **) argv, long_options,
- POPT_CONTEXT_KEEP_FIRST);
+ POPT_CONTEXT_KEEP_FIRST);
while((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
}
}
- lp_load(dyn_CONFIGFILE,True,False,False);
- load_interfaces();
-
argv_new = (const char **)poptGetArgs(pc);
argc_new = argc;
{ 0, 0, 0, 0 }
};
- setup_logging(argv[0], DEBUG_STDOUT);
-
pc = poptGetContext("nmblookup", argc, (const char **)argv, long_options,
POPT_CONTEXT_KEEP_FIRST);
exit(1);
}
- lp_load(dyn_CONFIGFILE,True,False,False);
- load_interfaces();
-
while (poptPeekArg(pc)) {
const char *name = poptGetArg(pc);
/* Samba client initialisation */
- setup_logging("ntlm_auth", DEBUG_STDERR);
-
- if (!lp_load(dyn_CONFIGFILE, True, False, False)) {
- d_fprintf(stderr, "wbinfo: error opening config file %s. Error was %s\n",
- dyn_CONFIGFILE, strerror(errno));
- exit(1);
- }
+ setup_logging(NULL, DEBUG_STDERR);
/* Parse options */