Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Samba utility functions
4 : Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
5 :
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.
10 :
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.
15 :
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/>.
18 : */
19 :
20 : #include "includes.h"
21 : #include "param/share.h"
22 : #include "param/param.h"
23 : #include "torture/torture.h"
24 : #include "torture/local/proto.h"
25 : #include "libds/common/roles.h"
26 :
27 1 : static bool test_create(struct torture_context *tctx)
28 : {
29 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
30 1 : torture_assert(tctx, lp_ctx != NULL, "lp_ctx");
31 0 : return true;
32 : }
33 :
34 1 : static bool test_set_option(struct torture_context *tctx)
35 : {
36 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
37 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "workgroup=werkgroep"), "lpcfg_set_option failed");
38 1 : torture_assert_str_equal(tctx, "WERKGROEP", lpcfg_workgroup(lp_ctx), "workgroup");
39 0 : return true;
40 : }
41 :
42 1 : static bool test_set_cmdline(struct torture_context *tctx)
43 : {
44 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
45 1 : torture_assert(tctx, lpcfg_set_cmdline(lp_ctx, "workgroup", "werkgroep"), "lpcfg_set_cmdline failed");
46 1 : torture_assert(tctx, lpcfg_do_global_parameter(lp_ctx, "workgroup", "barbla"), "lpcfg_set_option failed");
47 1 : torture_assert_str_equal(tctx, "WERKGROEP", lpcfg_workgroup(lp_ctx), "workgroup");
48 0 : return true;
49 : }
50 :
51 1 : static bool test_do_global_parameter(struct torture_context *tctx)
52 : {
53 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
54 1 : torture_assert(tctx, lpcfg_do_global_parameter(lp_ctx, "workgroup", "werkgroep42"),
55 : "lpcfg_set_cmdline failed");
56 1 : torture_assert_str_equal(tctx, lpcfg_workgroup(lp_ctx), "WERKGROEP42", "workgroup");
57 0 : return true;
58 : }
59 :
60 :
61 1 : static bool test_do_global_parameter_var(struct torture_context *tctx)
62 : {
63 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
64 1 : torture_assert(tctx, lpcfg_do_global_parameter_var(lp_ctx, "workgroup", "werk%s%d", "groep", 42),
65 : "lpcfg_set_cmdline failed");
66 1 : torture_assert_str_equal(tctx, lpcfg_workgroup(lp_ctx), "WERKGROEP42", "workgroup");
67 0 : return true;
68 : }
69 :
70 :
71 1 : static bool test_set_option_invalid(struct torture_context *tctx)
72 : {
73 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
74 1 : torture_assert(tctx, !lpcfg_set_option(lp_ctx, "workgroup"), "lpcfg_set_option succeeded");
75 0 : return true;
76 : }
77 :
78 1 : static bool test_set_option_parametric(struct torture_context *tctx)
79 : {
80 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
81 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "some:thing=blaat"), "lpcfg_set_option failed");
82 1 : torture_assert_str_equal(tctx, lpcfg_parm_string(lp_ctx, NULL, "some", "thing"), "blaat",
83 : "invalid parametric option");
84 0 : return true;
85 : }
86 :
87 1 : static bool test_lp_parm_double(struct torture_context *tctx)
88 : {
89 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
90 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "some:thing=3.4"), "lpcfg_set_option failed");
91 1 : torture_assert(tctx, lpcfg_parm_double(lp_ctx, NULL, "some", "thing", 2.0) == 3.4,
92 : "invalid parametric option");
93 1 : torture_assert(tctx, lpcfg_parm_double(lp_ctx, NULL, "some", "bla", 2.0) == 2.0,
94 : "invalid parametric option");
95 0 : return true;
96 : }
97 :
98 1 : static bool test_lp_parm_bool(struct torture_context *tctx)
99 : {
100 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
101 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "some:thing=true"), "lpcfg_set_option failed");
102 1 : torture_assert(tctx, lpcfg_parm_bool(lp_ctx, NULL, "some", "thing", false) == true,
103 : "invalid parametric option");
104 1 : torture_assert(tctx, lpcfg_parm_bool(lp_ctx, NULL, "some", "bla", true) == true,
105 : "invalid parametric option");
106 0 : return true;
107 : }
108 :
109 1 : static bool test_lp_parm_int(struct torture_context *tctx)
110 : {
111 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
112 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "some:thing=34"), "lpcfg_set_option failed");
113 1 : torture_assert_int_equal(tctx, lpcfg_parm_int(lp_ctx, NULL, "some", "thing", 20), 34,
114 : "invalid parametric option");
115 1 : torture_assert_int_equal(tctx, lpcfg_parm_int(lp_ctx, NULL, "some", "bla", 42), 42,
116 : "invalid parametric option");
117 0 : return true;
118 : }
119 :
120 1 : static bool test_lp_parm_bytes(struct torture_context *tctx)
121 : {
122 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
123 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "some:thing=16K"), "lpcfg_set_option failed");
124 1 : torture_assert_int_equal(tctx, lpcfg_parm_bytes(lp_ctx, NULL, "some", "thing", 20), 16 * 1024,
125 : "invalid parametric option");
126 1 : torture_assert_int_equal(tctx, lpcfg_parm_bytes(lp_ctx, NULL, "some", "bla", 42), 42,
127 : "invalid parametric option");
128 0 : return true;
129 : }
130 :
131 1 : static bool test_lp_do_service_parameter(struct torture_context *tctx)
132 : {
133 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
134 1 : struct loadparm_service *service = lpcfg_add_service(lp_ctx, lpcfg_default_service(lp_ctx), "foo");
135 1 : torture_assert(tctx, lpcfg_do_service_parameter(lp_ctx, service,
136 : "some:thing", "foo"), "lpcfg_set_option failed");
137 1 : torture_assert_str_equal(tctx, lpcfg_parm_string(lp_ctx, service, "some", "thing"), "foo",
138 : "invalid parametric option");
139 0 : return true;
140 : }
141 :
142 1 : static bool test_lp_service(struct torture_context *tctx)
143 : {
144 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
145 1 : struct loadparm_service *service = lpcfg_add_service(lp_ctx, lpcfg_default_service(lp_ctx), "foo");
146 1 : torture_assert(tctx, service == lpcfg_service(lp_ctx, "foo"), "invalid service");
147 0 : return true;
148 : }
149 :
150 1 : static bool test_server_role_default(struct torture_context *tctx)
151 : {
152 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
153 1 : torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_STANDALONE, "ROLE should be standalone by default");
154 1 : torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_USER, "security should be user");
155 0 : return true;
156 : }
157 :
158 1 : static bool test_server_role_dc_specified(struct torture_context *tctx)
159 : {
160 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
161 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "server role=domain controller"), "lpcfg_set_option failed");
162 1 : torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_ACTIVE_DIRECTORY_DC, "ROLE should be DC");
163 1 : torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_USER, "security should be USER");
164 0 : return true;
165 : }
166 :
167 1 : static bool test_server_role_member_specified(struct torture_context *tctx)
168 : {
169 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
170 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "server role=member"), "lpcfg_set_option failed");
171 1 : torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_MEMBER, "ROLE should be member");
172 1 : torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_ADS, "security should be ADS");
173 0 : return true;
174 : }
175 :
176 1 : static bool test_server_role_member_specified2(struct torture_context *tctx)
177 : {
178 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
179 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "server role=member"), "lpcfg_set_option failed");
180 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "security=domain"), "lpcfg_set_option failed");
181 1 : torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_MEMBER, "ROLE should be member");
182 1 : torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_DOMAIN, "security should be domain");
183 0 : return true;
184 : }
185 :
186 1 : static bool test_server_role_member_specified3(struct torture_context *tctx)
187 : {
188 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
189 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "server role=member"), "lpcfg_set_option failed");
190 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "security=ads"), "lpcfg_set_option failed");
191 1 : torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_MEMBER, "ROLE should be member");
192 1 : torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_ADS, "security should be ads");
193 0 : return true;
194 : }
195 :
196 1 : static bool test_server_role_standalone_specified(struct torture_context *tctx)
197 : {
198 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
199 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "server role=standalone"), "lpcfg_set_option failed");
200 1 : torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_STANDALONE, "ROLE should be standalone");
201 1 : torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_USER, "security should be USER");
202 0 : return true;
203 : }
204 :
205 1 : static bool test_server_role_dc_domain_logons(struct torture_context *tctx)
206 : {
207 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
208 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "domain logons=true"), "lpcfg_set_option failed");
209 1 : torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_PDC, "ROLE should be PDC");
210 1 : torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_USER, "security should be user");
211 0 : return true;
212 : }
213 :
214 1 : static bool test_server_role_dc_domain_logons_and_not_master(struct torture_context *tctx)
215 : {
216 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
217 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "domain logons=true"), "lpcfg_set_option failed");
218 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "domain master=false"), "lpcfg_set_option failed");
219 1 : torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_BDC, "ROLE should be BDC");
220 1 : torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_USER, "security should be user");
221 0 : return true;
222 : }
223 :
224 1 : static bool test_server_role_security_ads(struct torture_context *tctx)
225 : {
226 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
227 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "security=ads"), "lpcfg_set_option failed");
228 1 : torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_MEMBER, "ROLE should be MEMBER");
229 1 : torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_ADS, "security should be ads");
230 0 : return true;
231 : }
232 :
233 1 : static bool test_server_role_security_domain(struct torture_context *tctx)
234 : {
235 1 : struct loadparm_context *lp_ctx = loadparm_init(tctx);
236 1 : torture_assert(tctx, lpcfg_set_option(lp_ctx, "security=domain"), "lpcfg_set_option failed");
237 1 : torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_MEMBER, "ROLE should be MEMBER");
238 1 : torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_DOMAIN, "security should be domain");
239 0 : return true;
240 : }
241 :
242 2354 : struct torture_suite *torture_local_loadparm(TALLOC_CTX *mem_ctx)
243 : {
244 2354 : struct torture_suite *suite = torture_suite_create(mem_ctx, "loadparm");
245 :
246 2354 : torture_suite_add_simple_test(suite, "create", test_create);
247 2354 : torture_suite_add_simple_test(suite, "set_option", test_set_option);
248 2354 : torture_suite_add_simple_test(suite, "set_cmdline", test_set_cmdline);
249 2354 : torture_suite_add_simple_test(suite, "set_option_invalid", test_set_option_invalid);
250 2354 : torture_suite_add_simple_test(suite, "set_option_parametric", test_set_option_parametric);
251 2354 : torture_suite_add_simple_test(suite, "set_lp_parm_double", test_lp_parm_double);
252 2354 : torture_suite_add_simple_test(suite, "set_lp_parm_bool", test_lp_parm_bool);
253 2354 : torture_suite_add_simple_test(suite, "set_lp_parm_int", test_lp_parm_int);
254 2354 : torture_suite_add_simple_test(suite, "set_lp_parm_bytes", test_lp_parm_bytes);
255 2354 : torture_suite_add_simple_test(suite, "service_parameter", test_lp_do_service_parameter);
256 2354 : torture_suite_add_simple_test(suite, "lpcfg_service", test_lp_service);
257 2354 : torture_suite_add_simple_test(suite, "do_global_parameter_var", test_do_global_parameter_var);
258 2354 : torture_suite_add_simple_test(suite, "do_global_parameter", test_do_global_parameter);
259 2354 : torture_suite_add_simple_test(suite, "test_server_role_default", test_server_role_default);
260 2354 : torture_suite_add_simple_test(suite, "test_server_role_dc_specified", test_server_role_dc_specified);
261 2354 : torture_suite_add_simple_test(suite, "test_server_role_member_specified", test_server_role_member_specified);
262 2354 : torture_suite_add_simple_test(suite, "test_server_role_member_specified2", test_server_role_member_specified2);
263 2354 : torture_suite_add_simple_test(suite, "test_server_role_member_specified3", test_server_role_member_specified3);
264 2354 : torture_suite_add_simple_test(suite, "test_server_role_standalone_specified", test_server_role_standalone_specified);
265 2354 : torture_suite_add_simple_test(suite, "test_server_role_dc_domain_logons", test_server_role_dc_domain_logons);
266 2354 : torture_suite_add_simple_test(suite, "test_server_role_dc_domain_logons_and_not_master", test_server_role_dc_domain_logons_and_not_master);
267 2354 : torture_suite_add_simple_test(suite, "test_server_role_security_ads", test_server_role_security_ads);
268 2354 : torture_suite_add_simple_test(suite, "test_server_role_security_domain", test_server_role_security_domain);
269 :
270 2354 : return suite;
271 : }
|