selftest: fix domain name of nt4_dc_smb1 environment
[Samba.git] / source3 / param / test_lp_load.c
blob493aa316d38e808a50e31ee26cbf73a175bab061
1 /*
2 * Unix SMB/CIFS implementation.
3 * Test for lp_load()
4 * Copyright (C) Michael Adam 2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "lib/cmdline/cmdline.h"
22 #include "lib/param/param.h"
24 int main(int argc, const char **argv)
26 const char *config_file = NULL;
27 int ret = 0;
28 poptContext pc;
29 char *count_str = NULL;
30 int i, count = 1;
31 int opt;
32 bool ok;
34 struct poptOption long_options[] = {
35 POPT_AUTOHELP
37 .longName = "count",
38 .shortName = 'c',
39 .argInfo = POPT_ARG_STRING,
40 .arg = &count_str,
41 .val = 1,
42 .descrip = "Load config <count> number of times"
44 POPT_COMMON_DEBUG_ONLY
45 POPT_COMMON_VERSION
46 POPT_TABLEEND
49 TALLOC_CTX *frame = talloc_stackframe();
50 struct loadparm_context *lp_ctx = NULL;
52 smb_init_locale();
54 ok = samba_cmdline_init(frame,
55 SAMBA_CMDLINE_CONFIG_NONE,
56 false /* require_smbconf */);
57 if (!ok) {
58 DBG_ERR("Failed to init cmdline parser!\n");
59 TALLOC_FREE(frame);
60 exit(ENOMEM);
62 lp_ctx = samba_cmdline_get_lp_ctx();
63 lpcfg_set_cmdline(lp_ctx, "log level", "0");
65 pc = samba_popt_get_context(getprogname(),
66 argc,
67 argv,
68 long_options,
69 0);
70 if (pc == NULL) {
71 DBG_ERR("Failed to setup popt context!\n");
72 TALLOC_FREE(frame);
73 exit(1);
75 poptSetOtherOptionHelp(pc, "[OPTION...] <config-file>");
77 while ((opt = poptGetNextOpt(pc)) != -1) {
78 switch (opt) {
79 case POPT_ERROR_BADOPT:
80 fprintf(stderr, "\nInvalid option %s: %s\n\n",
81 poptBadOption(pc, 0), poptStrerror(opt));
82 poptPrintUsage(pc, stderr, 0);
83 exit(1);
87 if (poptPeekArg(pc)) {
88 config_file = talloc_strdup(frame, poptGetArg(pc));
89 if (config_file == NULL) {
90 DBG_ERR("out of memory\n");
91 TALLOC_FREE(frame);
92 exit(1);
94 } else {
95 config_file = get_dyn_CONFIGFILE();
98 poptFreeContext(pc);
100 if (count_str != NULL) {
101 count = atoi(count_str);
104 for (i=0; i < count; i++) {
105 printf("call lp_load() #%d: ", i+1);
106 if (!lp_load_with_registry_shares(config_file)) {
107 printf("ERROR.\n");
108 ret = 1;
109 goto done;
111 printf("ok.\n");
115 done:
116 gfree_loadparm();
117 TALLOC_FREE(frame);
118 return ret;