s4:torture: Initialize struct cldap_netlogon
[Samba.git] / lib / util / tests / test_logging.c
blob9b13b052f25435914ea769e7db5d1da08b095c22
1 /*
2 Unix SMB/CIFS implementation.
4 A test server that only does logging.
6 Copyright (C) Andrew Tridgell 1992-2005
7 Copyright (C) Martin Pool 2002
8 Copyright (C) Jelmer Vernooij 2002
9 Copyright (C) James J Myers 2003 <myersjj@samba.org>
10 Copyright (C) Douglas Bagnall 2022
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "includes.h"
27 #include "lib/cmdline/cmdline.h"
29 #ifdef USING_CMDLINE_S3
30 #include "lib/util/debug_s3.h"
31 #endif
33 #define BINARY_NAME "test_s4_logging"
35 static int log_level = 1;
38 #include "lib/util/debug-classes/debug-classname-table.c"
40 static int log_all_classes(int level)
42 size_t i;
43 const char *name = NULL;
44 for (i = 0; i < ARRAY_SIZE(default_classname_table); i++) {
45 name = default_classname_table[i];
46 DEBUGC(i, level,
47 ("logging for '%s' [%zu], at level %d\n",
48 name, i, level));
51 * That's it for the tests *here*. The invoker of this
52 * process will have set up an smb.conf that directs the
53 * output in particular ways, and will be looking to see that
54 * happens correctly.
57 return 0;
61 static int init_daemon(TALLOC_CTX *mem_ctx,
62 int argc,
63 const char *argv[],
64 const char **error)
66 poptContext pc;
67 int opt;
68 bool ok;
69 struct poptOption long_options[] = {
70 POPT_AUTOHELP
72 .longName = "level",
73 .shortName = 'L',
74 .argInfo = POPT_ARG_INT,
75 .arg = &log_level,
76 .descrip = "log at this level",
77 .argDescrip = "LEVEL",
79 POPT_COMMON_SAMBA
80 POPT_COMMON_DAEMON
81 POPT_COMMON_VERSION
82 POPT_TABLEEND
85 setproctitle(BINARY_NAME);
87 ok = samba_cmdline_init(mem_ctx,
88 SAMBA_CMDLINE_CONFIG_SERVER,
89 true /* require_smbconf */);
90 if (!ok) {
91 *error = "Failed to init cmdline parser!\n";
92 return EINVAL;
95 pc = samba_popt_get_context(BINARY_NAME,
96 argc,
97 argv,
98 long_options,
99 0);
100 if (pc == NULL) {
101 *error = "Failed to setup popt context!\n";
102 return ENOTRECOVERABLE;
105 while((opt = poptGetNextOpt(pc)) != -1) {
106 fprintf(stderr, "\nInvalid option %s: %s\n\n",
107 poptBadOption(pc, 0), poptStrerror(opt));
108 poptPrintUsage(pc, stderr, 0);
109 return 1;
112 poptFreeContext(pc);
114 #ifdef USING_CMDLINE_S3
115 reopen_logs();
116 #endif
117 return 0;
121 int main(int argc, const char *argv[])
123 int rc;
124 const char *error = NULL;
125 TALLOC_CTX *mem_ctx = talloc_stackframe();
126 if (mem_ctx == NULL) {
127 exit(ENOMEM);
130 setproctitle_init(argc, discard_const(argv), environ);
132 rc = init_daemon(mem_ctx, argc, argv, &error);
133 if (rc != 0) {
134 fprintf(stderr, "error [%d]: %s\n", rc, error);
135 exit_daemon(error, rc);
138 rc = log_all_classes(log_level);
139 if (rc != 0) {
140 fprintf(stderr, "error in log_all_classes [%d]\n", rc);
141 exit_daemon("logging error", rc);
144 TALLOC_FREE(mem_ctx);
145 return rc;