1 #include <check.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "test.h"
5 #include "builders/build_file.h"
6 #include "../src/alloc.h"
7 #include "../src/conf.h"
8 #include "../src/conffile.h"
9 #include "../src/fsops.h"
10 #include "../src/pathcmp.h"
11
12 #define BASE "utest_conffile"
13 #define CONFFILE BASE "/burp.conf"
14
setup_conf(void)15 static struct conf **setup_conf(void)
16 {
17 struct conf **confs=NULL;
18 fail_unless((confs=confs_alloc())!=NULL);
19 fail_unless(!confs_init(confs));
20 return confs;
21 }
22
setup(struct conf *** globalcs,struct conf *** cconfs)23 static void setup(struct conf ***globalcs, struct conf ***cconfs)
24 {
25 fail_unless(recursive_delete(BASE)==0);
26 alloc_counters_reset();
27 if(globalcs) *globalcs=setup_conf();
28 if(cconfs) *cconfs=setup_conf();
29 }
30
tear_down(struct conf *** globalcs,struct conf *** confs)31 static void tear_down(struct conf ***globalcs, struct conf ***confs)
32 {
33 fail_unless(recursive_delete(BASE)==0);
34 confs_free(confs);
35 confs_free(globalcs);
36 alloc_check();
37 }
38
39 struct data
40 {
41 const char *str;
42 const char *field;
43 const char *value;
44 int reset;
45 };
46
47 static struct data d[] = {
48 { "a=b", "a", "b", 0 },
49 { "a=b\n", "a", "b", 0 },
50 { "a = b", "a", "b", 0 },
51 { " a = b ", "a", "b", 0 },
52 { " a = b \n", "a", "b", 0 },
53 { "#a=b", NULL, NULL, 0 },
54 { " #a=b", NULL, NULL, 0 },
55 { "a='b'", "a", "b", 0 },
56 { "a='b", "a", "b", 0 },
57 { "a=b'", "a", "b'", 0 },
58 { "a=\"b\"", "a", "b", 0 },
59 { "a=b\"", "a", "b\"", 0 },
60 { "a=\"b", "a", "b", 0 },
61 { "a=b # comment", "a", "b # comment", 0 }, // Maybe fix this.
62 { "field=longvalue with spaces", "field", "longvalue with spaces", 0 },
63 { "test:=reset", "test", "reset", 1 },
64 };
65
START_TEST(test_conf_get_pair)66 START_TEST(test_conf_get_pair)
67 {
68 FOREACH(d)
69 {
70 char *field=NULL;
71 char *value=NULL;
72 char *str=strdup(d[i].str);
73 int reset=0;
74 conf_get_pair(str, &field, &value, &reset);
75 if(!field || !d[i].field)
76 fail_unless(field==d[i].field);
77 else
78 fail_unless(!strcmp(field, d[i].field));
79 if(!value || !d[i].value)
80 fail_unless(value==d[i].value);
81 else
82 fail_unless(!strcmp(value, d[i].value));
83 fail_unless(d[i].reset==reset);
84 free(str);
85 }
86 }
87 END_TEST
88
assert_strlist(struct strlist ** s,const char * path,int flag)89 static void assert_strlist(struct strlist **s, const char *path, int flag)
90 {
91 if(!path)
92 {
93 fail_unless(*s==NULL);
94 return;
95 }
96 ck_assert_str_eq((*s)->path, path);
97 fail_unless((*s)->flag==flag);
98 *s=(*s)->next;
99 }
100
check_listen(struct conf ** confs,const char * listen,int max_children,const char * listen_status,int max_status_children)101 static void check_listen(struct conf **confs,
102 const char *listen, int max_children,
103 const char *listen_status, int max_status_children)
104 {
105 struct strlist *s;
106 s=get_strlist(confs[OPT_LISTEN]);
107 assert_strlist(&s, listen, max_children);
108 s=get_strlist(confs[OPT_LISTEN_STATUS]);
109 assert_strlist(&s, listen_status, max_status_children);
110 }
111
check_ports(struct conf ** confs,const char * port,int max_children,const char * status_port,int max_status_children)112 static void check_ports(struct conf **confs,
113 const char *port, int max_children,
114 const char *status_port, int max_status_children)
115 {
116 struct strlist *s;
117 s=get_strlist(confs[OPT_PORT]);
118 assert_strlist(&s, port, max_children);
119 s=get_strlist(confs[OPT_STATUS_PORT]);
120 assert_strlist(&s, status_port, max_status_children);
121 }
122
START_TEST(test_client_conf)123 START_TEST(test_client_conf)
124 {
125 struct conf **confs=NULL;
126 setup(&confs, NULL);
127 build_file(CONFFILE, MIN_CLIENT_CONF);
128 fail_unless(!conf_load_global_only(CONFFILE, confs));
129 fail_unless(get_e_burp_mode(confs[OPT_BURP_MODE])==BURP_MODE_CLIENT);
130 ck_assert_str_eq(get_string(confs[OPT_SERVER]), "4.5.6.7");
131 check_ports(confs, "1234", 0, "12345", 0);
132 ck_assert_str_eq(get_string(confs[OPT_LOCKFILE]), "/lockfile/path");
133 ck_assert_str_eq(get_string(confs[OPT_SSL_CERT]), "/ssl/cert/path");
134 ck_assert_str_eq(get_string(confs[OPT_SSL_CERT_CA]), "/cert_ca/path");
135 ck_assert_str_eq(get_string(confs[OPT_SSL_PEER_CN]), "my_cn");
136 ck_assert_str_eq(get_string(confs[OPT_SSL_KEY]), "/ssl/key/path");
137 ck_assert_str_eq(get_string(confs[OPT_CA_CSR_DIR]), "/csr/dir");
138 tear_down(NULL, &confs);
139 }
140 END_TEST
141
check_client_ports(struct conf ** confs,int p_backup,int p_restore,int p_verify,int p_list,int p_delete)142 static void check_client_ports(struct conf **confs,
143 int p_backup, int p_restore, int p_verify, int p_list, int p_delete)
144 {
145 fail_unless(get_int(confs[OPT_PORT_BACKUP])==p_backup);
146 fail_unless(get_int(confs[OPT_PORT_RESTORE])==p_restore);
147 fail_unless(get_int(confs[OPT_PORT_VERIFY])==p_verify);
148 fail_unless(get_int(confs[OPT_PORT_LIST])==p_list);
149 fail_unless(get_int(confs[OPT_PORT_DELETE])==p_delete);
150 }
151
START_TEST(test_client_conf_monitor_exe)152 START_TEST(test_client_conf_monitor_exe)
153 {
154 struct conf **confs=NULL;
155 setup(&confs, NULL);
156 build_file(CONFFILE, MIN_CLIENT_CONF
157 "monitor_exe=/some/path"
158 );
159 fail_unless(!conf_load_global_only(CONFFILE, confs));
160 ck_assert_str_eq(get_string(confs[OPT_MONITOR_EXE]), "/some/path");
161 tear_down(NULL, &confs);
162 }
163 END_TEST
164
START_TEST(test_client_conf_ports_opt_port_only)165 START_TEST(test_client_conf_ports_opt_port_only)
166 {
167 struct conf **confs=NULL;
168 setup(&confs, NULL);
169 build_file(CONFFILE, MIN_CLIENT_CONF);
170 fail_unless(!conf_load_global_only(CONFFILE, confs));
171 check_client_ports(confs, 1234, 1234, 1234, 1234, 1234);
172 tear_down(NULL, &confs);
173 }
174 END_TEST
175
START_TEST(test_client_conf_ports_opt_port_and_restore)176 START_TEST(test_client_conf_ports_opt_port_and_restore)
177 {
178 struct conf **confs=NULL;
179 setup(&confs, NULL);
180 build_file(CONFFILE, MIN_CLIENT_CONF_NO_PORTS
181 "port=1234\n"
182 "port_restore=5555\n"
183 );
184 fail_unless(!conf_load_global_only(CONFFILE, confs));
185 check_client_ports(confs, 1234, 5555, 5555, 1234, 1234);
186 tear_down(NULL, &confs);
187 }
188 END_TEST
189
START_TEST(test_client_conf_ports_opt_port_and_all)190 START_TEST(test_client_conf_ports_opt_port_and_all)
191 {
192 struct conf **confs=NULL;
193 setup(&confs, NULL);
194 build_file(CONFFILE, MIN_CLIENT_CONF_NO_PORTS
195 "port=1234\n"
196 "port_backup=2345\n"
197 "port_restore=3456\n"
198 "port_verify=4567\n"
199 "port_list=5678\n"
200 "port_delete=6789\n"
201 );
202 fail_unless(!conf_load_global_only(CONFFILE, confs));
203 check_client_ports(confs, 2345, 3456, 4567, 5678, 6789);
204 tear_down(NULL, &confs);
205 }
206 END_TEST
207
START_TEST(test_client_conf_ports_no_opt_port_and_all)208 START_TEST(test_client_conf_ports_no_opt_port_and_all)
209 {
210 struct conf **confs=NULL;
211 setup(&confs, NULL);
212 build_file(CONFFILE, MIN_CLIENT_CONF_NO_PORTS
213 "port_backup=2345\n"
214 "port_restore=3456\n"
215 "port_verify=4567\n"
216 "port_list=5678\n"
217 "port_delete=6789\n"
218 );
219 fail_unless(!conf_load_global_only(CONFFILE, confs));
220 check_client_ports(confs, 2345, 3456, 4567, 5678, 6789);
221 tear_down(NULL, &confs);
222 }
223 END_TEST
224
START_TEST(test_client_conf_ca_conf_problems)225 START_TEST(test_client_conf_ca_conf_problems)
226 {
227 const char *buf="mode=client\n"
228 "server=4.5.6.7\n"
229 "port=1234\n"
230 "status_port=12345\n"
231 "lockfile=/lockfile/path\n"
232 "ca_burp_ca=blah\n"
233 ;
234 struct conf **confs=NULL;
235 setup(&confs, NULL);
236 build_file(CONFFILE, buf);
237 fail_unless(conf_load_global_only(CONFFILE, confs)==-1);
238 tear_down(NULL, &confs);
239 }
240 END_TEST
241
assert_include(struct strlist ** s,const char * path)242 static void assert_include(struct strlist **s, const char *path)
243 {
244 assert_strlist(s, path, 1);
245 }
246
assert_exclude(struct strlist ** s,const char * path)247 static void assert_exclude(struct strlist **s, const char *path)
248 {
249 assert_strlist(s, path, 0);
250 }
251
START_TEST(test_client_includes_excludes)252 START_TEST(test_client_includes_excludes)
253 {
254 const char *buf=MIN_CLIENT_CONF
255 "exclude=/z\n"
256 "exclude=/a/b\n"
257 "include=/a/b/c\n"
258 "include=/x/y/z\n"
259 "include=/r/s/t\n"
260 "include=/a\n"
261 "include=/a/b/c/d\n"
262 "cross_filesystem=/mnt/x\n"
263 "cross_filesystem=/mnt/y/\n"
264 ;
265 struct strlist *s;
266 struct conf **confs=NULL;
267 setup(&confs, NULL);
268 build_file(CONFFILE, buf);
269 fail_unless(!conf_load_global_only(CONFFILE, confs));
270 s=get_strlist(confs[OPT_INCLUDE]);
271 assert_include(&s, "/a");
272 assert_include(&s, "/a/b/c");
273 assert_include(&s, "/a/b/c/d");
274 assert_include(&s, "/r/s/t");
275 assert_include(&s, "/x/y/z");
276 assert_include(&s, NULL);
277 s=get_strlist(confs[OPT_EXCLUDE]);
278 assert_exclude(&s, "/a/b");
279 assert_exclude(&s, "/z");
280 assert_exclude(&s, NULL);
281 s=get_strlist(confs[OPT_STARTDIR]);
282 assert_include(&s, "/a");
283 assert_include(&s, "/r/s/t");
284 assert_include(&s, "/x/y/z");
285 assert_include(&s, NULL);
286 s=get_strlist(confs[OPT_INCEXCDIR]);
287 assert_include(&s, "/a");
288 assert_exclude(&s, "/a/b");
289 assert_include(&s, "/a/b/c");
290 assert_include(&s, "/a/b/c/d");
291 assert_include(&s, "/r/s/t");
292 assert_include(&s, "/x/y/z");
293 assert_exclude(&s, "/z");
294 assert_include(&s, NULL);
295 s=get_strlist(confs[OPT_FSCHGDIR]);
296 assert_strlist(&s, "/a/b/c", 0);
297 assert_strlist(&s, "/a/b/c/d", 0);
298 assert_strlist(&s, "/mnt/x", 0);
299 assert_strlist(&s, "/mnt/y", 0);
300 assert_strlist(&s, NULL, 0);
301 tear_down(NULL, &confs);
302 }
303 END_TEST
304
305 static const char *include_failures[] = {
306 MIN_CLIENT_CONF "include=not_absolute\n",
307 MIN_CLIENT_CONF "include=/\n"
308 "include=/boot\n"
309 "include=/boot/test\n"
310 "exclude=/boot\n",
311 };
312
START_TEST(test_client_include_failures)313 START_TEST(test_client_include_failures)
314 {
315 struct conf **confs=NULL;
316 FOREACH(include_failures)
317 {
318 setup(&confs, NULL);
319 build_file(CONFFILE, include_failures[i]);
320 fail_unless(conf_load_global_only(CONFFILE, confs)==-1);
321 tear_down(NULL, &confs);
322 }
323 }
324 END_TEST
325
START_TEST(test_client_include_glob)326 START_TEST(test_client_include_glob)
327 {
328 char cwd[1024];
329 char buf[4096];
330 char path1[2048];
331 char path2[2048];
332 struct strlist *s;
333 struct conf **confs=NULL;
334 fail_unless(getcwd(cwd, sizeof(cwd))!=NULL);
335 snprintf(buf, sizeof(buf),
336 "%s"
337 "include_glob=%s/%s/*.glob\n"
338 "include=/1\n",
339 MIN_CLIENT_CONF, cwd, BASE);
340 snprintf(path1, sizeof(path1), "%s/%s/a.glob", cwd, BASE);
341 snprintf(path2, sizeof(path2), "%s/%s/b.glob", cwd, BASE);
342 setup(&confs, NULL);
343 build_file(CONFFILE, buf);
344
345 fail_unless(!conf_load_global_only(CONFFILE, confs));
346 s=get_strlist(confs[OPT_INCLUDE]);
347 assert_include(&s, "/1");
348 assert_include(&s, NULL);
349
350 build_file(path1, "a");
351 fail_unless(!reeval_glob(confs));
352 s=get_strlist(confs[OPT_INCLUDE]);
353 assert_include(&s, "/1");
354 assert_include(&s, path1);
355 assert_include(&s, NULL);
356
357 build_file(path2, "b");
358 fail_unless(!reeval_glob(confs));
359 s=get_strlist(confs[OPT_INCLUDE]);
360 assert_include(&s, "/1");
361 assert_include(&s, path1);
362 assert_include(&s, path2);
363 assert_include(&s, NULL);
364
365 tear_down(NULL, &confs);
366 }
367 END_TEST
368
START_TEST(test_server_conf)369 START_TEST(test_server_conf)
370 {
371 struct strlist *s;
372 struct conf **confs=NULL;
373 setup(&confs, NULL);
374 build_file(CONFFILE, MIN_SERVER_CONF);
375 fail_unless(!conf_load_global_only(CONFFILE, confs));
376 fail_unless(get_e_burp_mode(confs[OPT_BURP_MODE])==BURP_MODE_SERVER);
377 check_listen(confs, "0.0.0.0:1234", 5, "0.0.0.0:12345", 5);
378 ck_assert_str_eq(get_string(confs[OPT_LOCKFILE]), "/lockfile/path");
379 ck_assert_str_eq(get_string(confs[OPT_SSL_CERT]), "/ssl/cert/path");
380 ck_assert_str_eq(get_string(confs[OPT_SSL_CERT_CA]), "/cert_ca/path");
381 ck_assert_str_eq(get_string(confs[OPT_DIRECTORY]), "/a/directory");
382 ck_assert_str_eq(get_string(confs[OPT_DEDUP_GROUP]), "a_group");
383 ck_assert_str_eq(get_string(confs[OPT_CLIENTCONFDIR]), "clientconfdir");
384 ck_assert_str_eq(get_string(confs[OPT_SSL_DHFILE]), "/a/dhfile");
385 s=get_strlist(confs[OPT_KEEP]);
386 assert_strlist(&s, "10", 10);
387 assert_include(&s, NULL);
388 tear_down(NULL, &confs);
389 }
390 END_TEST
391
START_TEST(test_server_port_conf_one_max_child)392 START_TEST(test_server_port_conf_one_max_child)
393 {
394 struct conf **confs=NULL;
395 setup(&confs, NULL);
396 build_file(CONFFILE, MIN_SERVER_CONF_NO_LISTEN
397 "listen=0.0.0.0:1234\n"
398 "listen_status=0.0.0.0:12345\n"
399 "max_children=12\n"
400 "max_status_children=21\n");
401 fail_unless(!conf_load_global_only(CONFFILE, confs));
402 check_listen(confs, "0.0.0.0:1234", 12, "0.0.0.0:12345", 21);
403 tear_down(NULL, &confs);
404 }
405 END_TEST
406
START_TEST(test_server_port_conf_too_many_max_child)407 START_TEST(test_server_port_conf_too_many_max_child)
408 {
409 struct conf **confs=NULL;
410 setup(&confs, NULL);
411 build_file(CONFFILE, MIN_SERVER_CONF_NO_LISTEN
412 "port=1234\n"
413 "max_children=12\n"
414 "max_children=21\n");
415 fail_unless(conf_load_global_only(CONFFILE, confs)==-1);
416 fail_unless(get_strlist(confs[OPT_STATUS_PORT])==NULL);
417 tear_down(NULL, &confs);
418 }
419 END_TEST
420
START_TEST(test_server_port_conf_few_max_child)421 START_TEST(test_server_port_conf_few_max_child)
422 {
423 struct strlist *s;
424 struct conf **confs=NULL;
425 setup(&confs, NULL);
426 build_file(CONFFILE, MIN_SERVER_CONF_NO_LISTEN
427 "listen=0.0.0.0:1234\n"
428 "listen=1.1.1.1:2345\n"
429 "listen=9.8.7.6:3456\n"
430 "max_children=12\n"
431 "max_children=21\n");
432 fail_unless(!conf_load_global_only(CONFFILE, confs));
433
434 s=get_strlist(confs[OPT_LISTEN]);
435 assert_strlist(&s, "0.0.0.0:1234", 12);
436 assert_strlist(&s, "1.1.1.1:2345", 21);
437 assert_strlist(&s, "9.8.7.6:3456", 21); // takes the previous as default
438 fail_unless(get_strlist(confs[OPT_LISTEN_STATUS])==NULL);
439 tear_down(NULL, &confs);
440 }
441 END_TEST
442
START_TEST(test_server_port_conf_complex)443 START_TEST(test_server_port_conf_complex)
444 {
445 struct strlist *s;
446 struct conf **confs=NULL;
447 setup(&confs, NULL);
448 build_file(CONFFILE, MIN_SERVER_CONF_NO_LISTEN
449 "listen=0.0.0.0:1234\n"
450 "listen=1.1.1.1:2345\n"
451 "listen=9.8.7.6:3456\n"
452 "max_children=12\n"
453 "max_children=21\n"
454 "max_children=37\n"
455 "listen_status=::1:987\n"
456 "listen_status=127.0.0.1:654\n"
457 "listen_status=1abc:2323::9999:321\n"
458 "max_status_children=4\n"
459 "max_status_children=5\n"
460 "max_status_children=6\n");
461 fail_unless(!conf_load_global_only(CONFFILE, confs));
462
463 s=get_strlist(confs[OPT_LISTEN]);
464 assert_strlist(&s, "0.0.0.0:1234", 12);
465 assert_strlist(&s, "1.1.1.1:2345", 21);
466 assert_strlist(&s, "9.8.7.6:3456", 37);
467 s=get_strlist(confs[OPT_LISTEN_STATUS]);
468 assert_strlist(&s, "::1:987", 4);
469 assert_strlist(&s, "127.0.0.1:654", 5);
470 assert_strlist(&s, "1abc:2323::9999:321", 6);
471 tear_down(NULL, &confs);
472 }
473 END_TEST
474
pre_post_assertions(struct conf ** confs,const char * pre_path,const char * post_path,const char * pre_arg1,const char * pre_arg2,const char * post_arg1,const char * post_arg2,enum conf_opt o_script_pre,enum conf_opt o_script_post,enum conf_opt o_script_pre_arg,enum conf_opt o_script_post_arg,enum conf_opt o_script_pre_notify,enum conf_opt o_script_post_notify,enum conf_opt o_script_post_run_on_fail)475 static void pre_post_assertions(struct conf **confs, const char *pre_path,
476 const char *post_path, const char *pre_arg1, const char *pre_arg2,
477 const char *post_arg1, const char *post_arg2,
478 enum conf_opt o_script_pre, enum conf_opt o_script_post,
479 enum conf_opt o_script_pre_arg, enum conf_opt o_script_post_arg,
480 enum conf_opt o_script_pre_notify, enum conf_opt o_script_post_notify,
481 enum conf_opt o_script_post_run_on_fail)
482 {
483 struct strlist *s;
484 ck_assert_str_eq(get_string(confs[o_script_pre]), pre_path);
485 ck_assert_str_eq(get_string(confs[o_script_post]), post_path);
486 s=get_strlist(confs[o_script_pre_arg]);
487 assert_strlist(&s, pre_arg1, 0);
488 assert_strlist(&s, pre_arg2, 0);
489 assert_strlist(&s, NULL, 0);
490 if(o_script_pre_notify!=OPT_MAX)
491 fail_unless(get_int(confs[o_script_pre_notify])==1);
492 s=get_strlist(confs[o_script_post_arg]);
493 assert_strlist(&s, post_arg1, 0);
494 assert_strlist(&s, post_arg2, 0);
495 assert_strlist(&s, NULL, 0);
496 if(o_script_post_notify!=OPT_MAX)
497 fail_unless(get_int(confs[o_script_post_notify])==1);
498 fail_unless(get_int(confs[o_script_post_run_on_fail])==1);
499 }
500
pre_post_checks(const char * buf,const char * pre_path,const char * post_path,const char * pre_arg1,const char * pre_arg2,const char * post_arg1,const char * post_arg2,enum conf_opt o_script_pre,enum conf_opt o_script_post,enum conf_opt o_script_pre_arg,enum conf_opt o_script_post_arg,enum conf_opt o_script_pre_notify,enum conf_opt o_script_post_notify,enum conf_opt o_script_post_run_on_fail)501 static void pre_post_checks(const char *buf, const char *pre_path,
502 const char *post_path, const char *pre_arg1, const char *pre_arg2,
503 const char *post_arg1, const char *post_arg2,
504 enum conf_opt o_script_pre, enum conf_opt o_script_post,
505 enum conf_opt o_script_pre_arg, enum conf_opt o_script_post_arg,
506 enum conf_opt o_script_pre_notify, enum conf_opt o_script_post_notify,
507 enum conf_opt o_script_post_run_on_fail)
508 {
509 struct conf **confs=NULL;
510 setup(&confs, NULL);
511 build_file(CONFFILE, buf);
512 fail_unless(!conf_load_global_only(CONFFILE, confs));
513 pre_post_assertions(confs, pre_path, post_path, pre_arg1, pre_arg2,
514 post_arg1, post_arg2,
515 o_script_pre, o_script_post,
516 o_script_pre_arg, o_script_post_arg,
517 o_script_pre_notify, o_script_post_notify,
518 o_script_post_run_on_fail);
519 tear_down(NULL, &confs);
520 }
521
server_pre_post_checks(const char * buf,const char * pre_path,const char * post_path,const char * pre_arg1,const char * pre_arg2,const char * post_arg1,const char * post_arg2)522 static void server_pre_post_checks(const char *buf, const char *pre_path,
523 const char *post_path, const char *pre_arg1, const char *pre_arg2,
524 const char *post_arg1, const char *post_arg2)
525 {
526 pre_post_checks(buf, pre_path, post_path, pre_arg1, pre_arg2,
527 post_arg1, post_arg2,
528 OPT_S_SCRIPT_PRE, OPT_S_SCRIPT_POST,
529 OPT_S_SCRIPT_PRE_ARG, OPT_S_SCRIPT_POST_ARG,
530 OPT_S_SCRIPT_PRE_NOTIFY, OPT_S_SCRIPT_POST_NOTIFY,
531 OPT_S_SCRIPT_POST_RUN_ON_FAIL);
532 }
533
534 #define SERVER_SCRIPT_PRE_POST \
535 "server_script_pre=pre_path\n" \
536 "server_script_pre_arg=pre_arg1\n" \
537 "server_script_pre_arg=pre_arg2\n" \
538 "server_script_pre_notify=1\n" \
539 "server_script_post=post_path\n" \
540 "server_script_post_arg=post_arg1\n" \
541 "server_script_post_arg=post_arg2\n" \
542 "server_script_post_notify=1\n" \
543 "server_script_post_run_on_fail=1\n" \
544
START_TEST(test_server_script_pre_post)545 START_TEST(test_server_script_pre_post)
546 {
547 const char *buf=MIN_SERVER_CONF SERVER_SCRIPT_PRE_POST;
548 server_pre_post_checks(buf, "pre_path", "post_path", "pre_arg1",
549 "pre_arg2", "post_arg1", "post_arg2");
550 }
551 END_TEST
552
553 #define SERVER_SCRIPT_CONF \
554 "server_script=path\n" \
555 "server_script_arg=arg1\n" \
556 "server_script_arg=arg2\n" \
557 "server_script_notify=1\n" \
558 "server_script_notify=1\n" \
559 "server_script_run_on_fail=1\n" \
560 "server_script_post_run_on_fail=1\n" \
561
562 // Same as test_server_script_pre_post, but use server_script to set both pre
563 // and post at the same time.
START_TEST(test_server_script)564 START_TEST(test_server_script)
565 {
566 const char *buf=MIN_SERVER_CONF SERVER_SCRIPT_CONF;
567 server_pre_post_checks(buf, "path", "path", "arg1",
568 "arg2", "arg1", "arg2");
569 }
570 END_TEST
571
backup_script_pre_post_checks(const char * buf,const char * pre_path,const char * post_path,const char * pre_arg1,const char * pre_arg2,const char * post_arg1,const char * post_arg2)572 static void backup_script_pre_post_checks(const char *buf, const char *pre_path,
573 const char *post_path, const char *pre_arg1, const char *pre_arg2,
574 const char *post_arg1, const char *post_arg2)
575 {
576 pre_post_checks(buf, pre_path, post_path, pre_arg1, pre_arg2,
577 post_arg1, post_arg2,
578 OPT_B_SCRIPT_PRE, OPT_B_SCRIPT_POST,
579 OPT_B_SCRIPT_PRE_ARG, OPT_B_SCRIPT_POST_ARG,
580 OPT_MAX, OPT_MAX, OPT_B_SCRIPT_POST_RUN_ON_FAIL);
581 }
582
START_TEST(test_backup_script_pre_post)583 START_TEST(test_backup_script_pre_post)
584 {
585 const char *buf=MIN_CLIENT_CONF
586 "backup_script_pre=pre_path\n"
587 "backup_script_pre_arg=pre_arg1\n"
588 "backup_script_pre_arg=pre_arg2\n"
589 "backup_script_post=post_path\n"
590 "backup_script_post_arg=post_arg1\n"
591 "backup_script_post_arg=post_arg2\n"
592 "backup_script_post_run_on_fail=1\n"
593 ;
594 backup_script_pre_post_checks(buf, "pre_path", "post_path", "pre_arg1",
595 "pre_arg2", "post_arg1", "post_arg2");
596 }
597 END_TEST
598
599 // Same as test_backup_script_pre_post, but use backup_script to set both pre
600 // and post at the same time.
START_TEST(test_backup_script)601 START_TEST(test_backup_script)
602 {
603 const char *buf=MIN_CLIENT_CONF
604 "backup_script=path\n"
605 "backup_script_arg=arg1\n"
606 "backup_script_arg=arg2\n"
607 "backup_script_run_on_fail=1\n"
608 "backup_script_post_run_on_fail=1\n"
609 ;
610 backup_script_pre_post_checks(buf, "path", "path", "arg1",
611 "arg2", "arg1", "arg2");
612 }
613 END_TEST
614
restore_script_pre_post_checks(const char * buf,const char * pre_path,const char * post_path,const char * pre_arg1,const char * pre_arg2,const char * post_arg1,const char * post_arg2)615 static void restore_script_pre_post_checks(const char *buf,
616 const char *pre_path, const char *post_path,
617 const char *pre_arg1, const char *pre_arg2,
618 const char *post_arg1, const char *post_arg2)
619 {
620 pre_post_checks(buf, pre_path, post_path, pre_arg1, pre_arg2,
621 post_arg1, post_arg2,
622 OPT_R_SCRIPT_PRE, OPT_R_SCRIPT_POST,
623 OPT_R_SCRIPT_PRE_ARG, OPT_R_SCRIPT_POST_ARG,
624 OPT_MAX, OPT_MAX, OPT_R_SCRIPT_POST_RUN_ON_FAIL);
625 }
626
START_TEST(test_restore_script_pre_post)627 START_TEST(test_restore_script_pre_post)
628 {
629 const char *buf=MIN_CLIENT_CONF
630 "restore_script_pre=pre_path\n"
631 "restore_script_pre_arg=pre_arg1\n"
632 "restore_script_pre_arg=pre_arg2\n"
633 "restore_script_post=post_path\n"
634 "restore_script_post_arg=post_arg1\n"
635 "restore_script_post_arg=post_arg2\n"
636 "restore_script_post_run_on_fail=1\n"
637 ;
638 restore_script_pre_post_checks(buf, "pre_path", "post_path", "pre_arg1",
639 "pre_arg2", "post_arg1", "post_arg2");
640 }
641 END_TEST
642
643 // Same as test_restore_script_pre_post, but use restore_script to set both pre
644 // and post at the same time.
START_TEST(test_restore_script)645 START_TEST(test_restore_script)
646 {
647 const char *buf=MIN_CLIENT_CONF
648 "restore_script=path\n"
649 "restore_script_arg=arg1\n"
650 "restore_script_arg=arg2\n"
651 "restore_script_run_on_fail=1\n"
652 "restore_script_post_run_on_fail=1\n"
653 ;
654 restore_script_pre_post_checks(buf, "path", "path", "arg1",
655 "arg2", "arg1", "arg2");
656 }
657 END_TEST
658
clientconfdir_setup(struct conf *** globalcs,struct conf *** cconfs,const char * gbuf,const char * buf)659 static void clientconfdir_setup(struct conf ***globalcs, struct conf ***cconfs,
660 const char *gbuf, const char *buf)
661 {
662 const char *global_path=BASE "/burp-server.conf";
663 setup(globalcs, cconfs);
664 build_file(CONFFILE, gbuf);
665 fail_unless(!conf_load_global_only(CONFFILE, *globalcs));
666 set_string((*cconfs)[OPT_CNAME], "utestclient");
667 build_file(global_path, buf);
668 fail_unless(!conf_load_overrides(*globalcs, *cconfs, global_path));
669 ck_assert_str_eq(get_string((*cconfs)[OPT_CNAME]), "utestclient");
670 }
671
672 #define NOTIFY_CONF \
673 "notify_success_script=/success_path\n" \
674 "notify_success_arg=/success/arg1\n" \
675 "notify_success_arg=/success/arg2\n" \
676 "notify_success_warnings_only=1\n" \
677 "notify_success_changes_only=1\n" \
678 "notify_failure_script=/failure_path\n" \
679 "notify_failure_arg=/failure/arg1\n" \
680 "notify_failure_arg=/failure/arg2\n" \
681
notify_assertions(struct conf ** cconfs)682 static void notify_assertions(struct conf **cconfs)
683 {
684 struct strlist *s;
685 ck_assert_str_eq(get_string(cconfs[OPT_N_SUCCESS_SCRIPT]),
686 "/success_path");
687 s=get_strlist(cconfs[OPT_N_SUCCESS_ARG]);
688 assert_strlist(&s, "/success/arg1", 0);
689 assert_strlist(&s, "/success/arg2", 0);
690 assert_include(&s, NULL);
691 ck_assert_str_eq(get_string(cconfs[OPT_N_FAILURE_SCRIPT]),
692 "/failure_path");
693 fail_unless(get_int(cconfs[OPT_N_SUCCESS_WARNINGS_ONLY])==1);
694 fail_unless(get_int(cconfs[OPT_N_SUCCESS_CHANGES_ONLY])==1);
695 s=get_strlist(cconfs[OPT_N_FAILURE_ARG]);
696 assert_strlist(&s, "/failure/arg1", 0);
697 assert_strlist(&s, "/failure/arg2", 0);
698 assert_include(&s, NULL);
699 }
700
701 #define MIN_CLIENTCONFDIR_BUF "# comment\n"
702
START_TEST(test_clientconfdir_conf)703 START_TEST(test_clientconfdir_conf)
704 {
705 struct strlist *s;
706 struct conf **globalcs=NULL;
707 struct conf **cconfs=NULL;
708 const char *gbuf=MIN_SERVER_CONF
709 "restore_client=abc\n"
710 "restore_client=xyz\n"
711 "super_client=sss\n"
712 "super_client=ttt\n"
713 "timer_script=/timer/script\n"
714 "timer_arg=/timer/arg1\n"
715 "timer_arg=/timer/arg2\n"
716 "label=qwe\n"
717 "client_lockdir=/tmp/blah\n"
718 NOTIFY_CONF
719 ;
720 const char *buf=MIN_CLIENTCONFDIR_BUF
721 "protocol=1\n"
722 "directory=/another/dir\n"
723 "directory_tree=0\n"
724 "timestamp_format=%H %M %S\n"
725 "password_check=0\n"
726 "keep=4\n"
727 "keep=7\n"
728 "working_dir_recovery_method=resume\n"
729 "max_resume_attempts=5\n"
730 "librsync=0\n"
731 "librsync_max_size=10Mb\n"
732 "version_warn=0\n"
733 "path_length_warn=0\n"
734 "syslog=1\n"
735 "client_can_delete=0\n"
736 "client_can_force_backup=0\n"
737 "client_can_list=0\n"
738 "client_can_monitor=0\n"
739 "client_can_restore=0\n"
740 "client_can_verify=0\n"
741 "restore_client=123\n"
742 "restore_client=456\n"
743 "super_client=ppp\n"
744 "super_client=qqq\n"
745 "dedup_group=dd_group\n"
746 "label=rty\n"
747 "label=xyz\n"
748 "timer_repeat_interval=5\n"
749 ;
750
751 clientconfdir_setup(&globalcs, &cconfs, gbuf, buf);
752
753 fail_unless(get_e_protocol(cconfs[OPT_PROTOCOL])==PROTO_1);
754 ck_assert_str_eq(get_string(cconfs[OPT_DIRECTORY]), "/another/dir");
755 fail_unless(get_int(cconfs[OPT_DIRECTORY_TREE])==0);
756 ck_assert_str_eq(get_string(cconfs[OPT_TIMESTAMP_FORMAT]),
757 "%H %M %S");
758 fail_unless(get_int(cconfs[OPT_PASSWORD_CHECK])==0);
759 s=get_strlist(cconfs[OPT_KEEP]);
760 assert_strlist(&s, "4", 4);
761 assert_strlist(&s, "7", 8); // The last one gets 1 added to it.
762 assert_include(&s, NULL);
763 s=get_strlist(cconfs[OPT_RESTORE_CLIENTS]);
764 assert_strlist(&s, "123", 0);
765 assert_strlist(&s, "456", 0);
766 assert_strlist(&s, "abc", 0);
767 assert_strlist(&s, "xyz", 0);
768 assert_include(&s, NULL);
769 s=get_strlist(cconfs[OPT_SUPER_CLIENTS]);
770 assert_strlist(&s, "ppp", 0);
771 assert_strlist(&s, "qqq", 0);
772 assert_strlist(&s, "sss", 0);
773 assert_strlist(&s, "ttt", 0);
774 assert_include(&s, NULL);
775 fail_unless(get_e_recovery_method(
776 cconfs[OPT_WORKING_DIR_RECOVERY_METHOD])==RECOVERY_METHOD_RESUME);
777 fail_unless(get_int(cconfs[OPT_MAX_RESUME_ATTEMPTS])==5);
778 fail_unless(get_int(cconfs[OPT_LIBRSYNC])==0);
779 fail_unless(get_uint64_t(cconfs[OPT_LIBRSYNC_MAX_SIZE])==10485760);
780 fail_unless(get_int(cconfs[OPT_VERSION_WARN])==0);
781 fail_unless(get_int(cconfs[OPT_PATH_LENGTH_WARN])==0);
782 fail_unless(get_int(cconfs[OPT_SYSLOG])==1);
783 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_DELETE])==0);
784 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_FORCE_BACKUP])==0);
785 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_LIST])==0);
786 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_RESTORE])==0);
787 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_VERIFY])==0);
788 s=get_strlist(cconfs[OPT_TIMER_ARG]);
789 assert_strlist(&s, "/timer/arg1", 0);
790 assert_strlist(&s, "/timer/arg2", 0);
791 assert_include(&s, NULL);
792 fail_unless(get_int(cconfs[OPT_TIMER_REPEAT_INTERVAL])==5);
793 ck_assert_str_eq(get_string(cconfs[OPT_DEDUP_GROUP]), "dd_group");
794 s=get_strlist(cconfs[OPT_LABEL]);
795 assert_strlist(&s, "rty", 0);
796 assert_strlist(&s, "xyz", 0);
797 notify_assertions(cconfs);
798 ck_assert_str_eq(get_string(globalcs[OPT_CLIENT_LOCKDIR]), "/tmp/blah");
799 ck_assert_str_eq(get_string(cconfs[OPT_CLIENT_LOCKDIR]), "/tmp/blah");
800 tear_down(&globalcs, &cconfs);
801 }
802 END_TEST
803
START_TEST(test_clientconfdir_extra)804 START_TEST(test_clientconfdir_extra)
805 {
806 struct strlist *s;
807 struct conf **globalcs=NULL;
808 struct conf **cconfs=NULL;
809 const char *gbuf=MIN_SERVER_CONF
810 "restore_client=abc\n"
811 "include = /ignored/include\n"
812 "timer_script = /ignored/timer\n"
813 "timer_arg = /ignored/timer/arg1\n"
814 "timer_arg = /ignored/timer/arg2\n"
815 "notify_success_script = /ignored/success\n"
816 "notify_success_arg = /ignored/success/arg\n"
817 "notify_failure_script = /ignored/failure\n"
818 "notify_failure_arg = /ignored/failure/arg\n"
819 SERVER_SCRIPT_CONF
820 ;
821 const char *buf=MIN_CLIENTCONFDIR_BUF
822 "include = /testdir\n"
823 "timer_script = /timer/script\n"
824 "timer_arg = /timer/arg1\n"
825 "timer_arg = /timer/arg2\n"
826 SERVER_SCRIPT_PRE_POST
827 NOTIFY_CONF
828 ;
829 clientconfdir_setup(&globalcs, &cconfs, gbuf, buf);
830 s=get_strlist(cconfs[OPT_RESTORE_CLIENTS]);
831 assert_strlist(&s, "abc", 0);
832 assert_include(&s, NULL);
833 s=get_strlist(cconfs[OPT_INCLUDE]);
834 assert_strlist(&s, "/testdir", 1);
835 assert_include(&s, NULL);
836 ck_assert_str_eq(get_string(cconfs[OPT_TIMER_SCRIPT]), "/timer/script");
837 s=get_strlist(cconfs[OPT_TIMER_ARG]);
838 assert_strlist(&s, "/timer/arg1", 0);
839 assert_strlist(&s, "/timer/arg2", 0);
840 assert_include(&s, NULL);
841 pre_post_assertions(cconfs, "pre_path", "post_path",
842 "pre_arg1", "pre_arg2",
843 "post_arg1", "post_arg2",
844 OPT_S_SCRIPT_PRE, OPT_S_SCRIPT_POST,
845 OPT_S_SCRIPT_PRE_ARG, OPT_S_SCRIPT_POST_ARG,
846 OPT_S_SCRIPT_PRE_NOTIFY, OPT_S_SCRIPT_POST_NOTIFY,
847 OPT_S_SCRIPT_POST_RUN_ON_FAIL);
848 notify_assertions(cconfs);
849 tear_down(&globalcs, &cconfs);
850 }
851 END_TEST
852
START_TEST(test_strlist_reset)853 START_TEST(test_strlist_reset)
854 {
855 struct strlist *s;
856 struct conf **confs=NULL;
857 setup(&confs, NULL);
858 build_file(CONFFILE, MIN_SERVER_CONF
859 "timer_arg = /ignored/timer/arg1\n"
860 "timer_arg = /ignored/timer/arg2\n"
861 "timer_arg := /timer/arg3\n"
862 "timer_arg = /timer/arg4\n");
863 fail_unless(!conf_load_global_only(CONFFILE, confs));
864
865 s=get_strlist(confs[OPT_TIMER_ARG]);
866 assert_strlist(&s, "/timer/arg3", 0);
867 assert_strlist(&s, "/timer/arg4", 0);
868 assert_include(&s, NULL);
869 tear_down(NULL, &confs);
870 }
871 END_TEST
872
START_TEST(test_clientconfdir_server_script)873 START_TEST(test_clientconfdir_server_script)
874 {
875 struct conf **globalcs=NULL;
876 struct conf **cconfs=NULL;
877 const char *gbuf=MIN_SERVER_CONF SERVER_SCRIPT_PRE_POST;
878 const char *buf=MIN_CLIENTCONFDIR_BUF SERVER_SCRIPT_CONF;
879
880 clientconfdir_setup(&globalcs, &cconfs, gbuf, buf);
881 pre_post_assertions(cconfs, "path", "path",
882 "arg1", "arg2",
883 "arg1", "arg2",
884 OPT_S_SCRIPT_PRE, OPT_S_SCRIPT_POST,
885 OPT_S_SCRIPT_PRE_ARG, OPT_S_SCRIPT_POST_ARG,
886 OPT_S_SCRIPT_PRE_NOTIFY, OPT_S_SCRIPT_POST_NOTIFY,
887 OPT_S_SCRIPT_POST_RUN_ON_FAIL);
888 tear_down(&globalcs, &cconfs);
889 }
890 END_TEST
891
switch_test(int expected_ret,const char * gbuf)892 static void switch_test(int expected_ret, const char *gbuf)
893 {
894 char orig_client_conf[256]="";
895 const char *clientconfdir;
896 struct conf **globalcs=NULL;
897 struct conf **cconfs=NULL;
898 const char *buf=MIN_CLIENTCONFDIR_BUF;
899 const char *orig_client_buf=MIN_CLIENTCONFDIR_BUF;
900
901 clientconfdir_setup(&globalcs, &cconfs, gbuf, buf);
902 clientconfdir=get_string(globalcs[OPT_CLIENTCONFDIR]);
903 fail_unless(!recursive_delete(clientconfdir));
904 snprintf(orig_client_conf, sizeof(orig_client_conf),
905 "%s/orig_client", clientconfdir);
906 build_file(orig_client_conf, orig_client_buf);
907 fail_unless(conf_switch_to_orig_client(globalcs, cconfs,
908 "orig_client")==expected_ret);
909 if(!expected_ret)
910 {
911 ck_assert_str_eq(get_string(cconfs[OPT_CNAME]),
912 "orig_client");
913 ck_assert_str_eq(get_string(cconfs[OPT_SUPER_CLIENT]),
914 "orig_client");
915 ck_assert_str_eq(get_string(cconfs[OPT_ORIG_CLIENT]),
916 "orig_client");
917 }
918 fail_unless(!recursive_delete(clientconfdir));
919 tear_down(&globalcs, &cconfs);
920 }
921
START_TEST(test_conf_switch_to_orig_client_fail_restore_client)922 START_TEST(test_conf_switch_to_orig_client_fail_restore_client)
923 {
924 const char *gbuf=MIN_SERVER_CONF
925 "restore_client=non-matching1\n"
926 "restore_client=non-matching2\n";
927 switch_test(-1, gbuf);
928 }
929 END_TEST
930
START_TEST(test_conf_switch_to_orig_client_ok_restore_client)931 START_TEST(test_conf_switch_to_orig_client_ok_restore_client)
932 {
933 const char *gbuf=MIN_SERVER_CONF
934 "restore_client=non-matching1\n"
935 "restore_client=utestclient\n";
936 switch_test(0, gbuf);
937 }
938 END_TEST
939
940 struct cndata
941 {
942 const char *cname;
943 int valid;
944 };
945
946 static struct cndata c[] = {
947 { "testclient", 1 },
948 { "test.client", 1 },
949 { "testclient..", 1 },
950 { ".testclient", 0 },
951 { "testclient~", 0 },
952 { ".", 0 },
953 { "..", 0 },
954 { "/testclient", 0 },
955 { "test/client", 0 },
956 { "test\\client", 0 },
957 { "/..", 0 },
958 { "../", 0 },
959 { "../../testclient", 0 },
960 { "testclient/../blah", 0 },
961 };
962
START_TEST(test_cname_valid)963 START_TEST(test_cname_valid)
964 {
965 FOREACH(c)
966 {
967 fail_unless(cname_valid(c[i].cname)==c[i].valid);
968 }
969 }
970 END_TEST
971
START_TEST(test_conf_switch_to_orig_client_fail_super_client)972 START_TEST(test_conf_switch_to_orig_client_fail_super_client)
973 {
974 const char *gbuf=MIN_SERVER_CONF
975 "super_client=non-matching1\n"
976 "super_client=non-matching2\n";
977 switch_test(-1, gbuf);
978 }
979 END_TEST
980
START_TEST(test_conf_switch_to_orig_client_ok_super_client)981 START_TEST(test_conf_switch_to_orig_client_ok_super_client)
982 {
983 const char *gbuf=MIN_SERVER_CONF
984 "super_client=non-matching1\n"
985 "super_client=utestclient\n";
986 switch_test(0, gbuf);
987 }
988 END_TEST
989
990 struct client_can_data
991 {
992 const char *config_str;
993 int force_backup;
994 int force_backup_orig;
995 int force_backup_expected;
996 int client_can;
997 int client_can_orig;
998 int client_can_expected;
999 };
1000
1001 static struct client_can_data ccd[] = {
1002 { "super_client", 0, 0, 0, 0, 0, 0 },
1003 { "super_client", 1, 0, 0, 1, 0, 1 },
1004 { "super_client", 0, 1, 0, 0, 1, 0 },
1005 { "super_client", 1, 1, 0, 1, 1, 1 },
1006 { "restore_client", 0, 0, 0, 0, 0, 0 },
1007 { "restore_client", 1, 0, 0, 1, 0, 0 },
1008 { "restore_client", 0, 1, 0, 0, 1, 0 },
1009 { "restore_client", 1, 1, 0, 1, 1, 1 },
1010 };
1011
START_TEST(test_conf_switch_to_orig_client_client_can)1012 START_TEST(test_conf_switch_to_orig_client_client_can)
1013 {
1014 FOREACH(ccd)
1015 {
1016 char orig_client_conf[256]="";
1017 const char *clientconfdir;
1018 struct conf **globalcs=NULL;
1019 struct conf **cconfs=NULL;
1020 char buf[4096]="";
1021 char obuf[4096]="";
1022 char gbuf[4096]="";
1023
1024 snprintf(gbuf, sizeof(gbuf), "%s%s=utestclient",
1025 MIN_SERVER_CONF, ccd[i].config_str);
1026
1027 snprintf(buf, sizeof(buf), "%s\n"
1028 "client_can_force_backup=%d\n"
1029 "client_can_delete=%d\n"
1030 "client_can_diff=%d\n"
1031 "client_can_list=%d\n"
1032 "client_can_monitor=%d\n"
1033 "client_can_restore=%d\n"
1034 "client_can_verify=%d\n",
1035 MIN_SERVER_CONF,
1036 ccd[i].force_backup,
1037 ccd[i].client_can,
1038 ccd[i].client_can,
1039 ccd[i].client_can,
1040 ccd[i].client_can,
1041 ccd[i].client_can,
1042 ccd[i].client_can);
1043 snprintf(obuf, sizeof(obuf), "%s\n"
1044 "client_can_force_backup=%d\n"
1045 "client_can_delete=%d\n"
1046 "client_can_diff=%d\n"
1047 "client_can_list=%d\n"
1048 "client_can_monitor=%d\n"
1049 "client_can_restore=%d\n"
1050 "client_can_verify=%d\n",
1051 MIN_SERVER_CONF,
1052 ccd[i].force_backup_orig,
1053 ccd[i].client_can_orig,
1054 ccd[i].client_can_orig,
1055 ccd[i].client_can_orig,
1056 ccd[i].client_can_orig,
1057 ccd[i].client_can_orig,
1058 ccd[i].client_can_orig);
1059
1060 clientconfdir_setup(&globalcs, &cconfs, gbuf, buf);
1061 clientconfdir=get_string(globalcs[OPT_CLIENTCONFDIR]);
1062 fail_unless(!recursive_delete(clientconfdir));
1063 snprintf(orig_client_conf, sizeof(orig_client_conf),
1064 "%s/orig_client", clientconfdir);
1065 build_file(orig_client_conf, obuf);
1066 fail_unless(conf_switch_to_orig_client(globalcs, cconfs,
1067 "orig_client")==0);
1068
1069 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_FORCE_BACKUP])
1070 ==ccd[i].force_backup_expected);
1071 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_DELETE])
1072 ==ccd[i].client_can_expected);
1073 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_DIFF])
1074 ==ccd[i].client_can_expected);
1075 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_LIST])
1076 ==ccd[i].client_can_expected);
1077 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_MONITOR])
1078 ==ccd[i].client_can_expected);
1079 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_RESTORE])
1080 ==ccd[i].client_can_expected);
1081 fail_unless(get_int(cconfs[OPT_CLIENT_CAN_VERIFY])
1082 ==ccd[i].client_can_expected);
1083
1084 fail_unless(!recursive_delete(clientconfdir));
1085 tear_down(&globalcs, &cconfs);
1086 }
1087 }
1088 END_TEST
1089
suite_conffile(void)1090 Suite *suite_conffile(void)
1091 {
1092 Suite *s;
1093 TCase *tc_core;
1094
1095 s=suite_create("conffile");
1096
1097 tc_core=tcase_create("Core");
1098
1099 tcase_add_test(tc_core, test_conf_get_pair);
1100 tcase_add_test(tc_core, test_client_conf);
1101 tcase_add_test(tc_core, test_client_conf_ca_conf_problems);
1102 tcase_add_test(tc_core, test_client_includes_excludes);
1103 tcase_add_test(tc_core, test_client_include_failures);
1104 tcase_add_test(tc_core, test_client_include_glob);
1105 tcase_add_test(tc_core, test_client_conf_monitor_exe);
1106 tcase_add_test(tc_core, test_client_conf_ports_opt_port_only);
1107 tcase_add_test(tc_core, test_client_conf_ports_opt_port_and_restore);
1108 tcase_add_test(tc_core, test_client_conf_ports_opt_port_and_all);
1109 tcase_add_test(tc_core, test_client_conf_ports_no_opt_port_and_all);
1110 tcase_add_test(tc_core, test_server_conf);
1111 tcase_add_test(tc_core, test_server_port_conf_one_max_child);
1112 tcase_add_test(tc_core, test_server_port_conf_too_many_max_child);
1113 tcase_add_test(tc_core, test_server_port_conf_few_max_child);
1114 tcase_add_test(tc_core, test_server_port_conf_complex);
1115 tcase_add_test(tc_core, test_server_script_pre_post);
1116 tcase_add_test(tc_core, test_server_script);
1117 tcase_add_test(tc_core, test_backup_script_pre_post);
1118 tcase_add_test(tc_core, test_backup_script);
1119 tcase_add_test(tc_core, test_restore_script_pre_post);
1120 tcase_add_test(tc_core, test_restore_script);
1121 tcase_add_test(tc_core, test_clientconfdir_conf);
1122 tcase_add_test(tc_core, test_clientconfdir_extra);
1123 tcase_add_test(tc_core, test_strlist_reset);
1124 tcase_add_test(tc_core, test_clientconfdir_server_script);
1125 tcase_add_test(tc_core, test_cname_valid);
1126 tcase_add_test(tc_core, test_conf_switch_to_orig_client_fail_restore_client);
1127 tcase_add_test(tc_core, test_conf_switch_to_orig_client_ok_restore_client);
1128 tcase_add_test(tc_core, test_conf_switch_to_orig_client_fail_super_client);
1129 tcase_add_test(tc_core, test_conf_switch_to_orig_client_ok_super_client);
1130 tcase_add_test(tc_core, test_conf_switch_to_orig_client_client_can);
1131
1132 suite_add_tcase(s, tc_core);
1133
1134 return s;
1135 }
1136