"Fossies" - the Fresh Open Source Software Archive

Member "burp-2.3.6/utest/test_conffile.c" (28 Apr 2019, 33478 Bytes) of package /linux/privat/burp-2.3.6.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "test_conffile.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.3.0_vs_2.3.6.

    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 
   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 
   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 
   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 
   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 
   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 
  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 
  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 
  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 
  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 
  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 
  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 
  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 
  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 
  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 
  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 
  242 static void assert_include(struct strlist **s, const char *path)
  243 {
  244     assert_strlist(s, path, 1);
  245 }
  246 
  247 static void assert_exclude(struct strlist **s, const char *path)
  248 {
  249     assert_strlist(s, path, 0);
  250 }
  251 
  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=/\ninclude=/\n"
  308 };
  309 
  310 START_TEST(test_client_include_failures)
  311 {
  312     struct conf **confs=NULL;
  313     FOREACH(include_failures)
  314     {
  315         setup(&confs, NULL);
  316         build_file(CONFFILE, include_failures[i]);
  317         fail_unless(conf_load_global_only(CONFFILE, confs)==-1);
  318         tear_down(NULL, &confs);
  319     }
  320 }
  321 END_TEST
  322 
  323 START_TEST(test_client_include_glob)
  324 {
  325     char cwd[1024];
  326     char buf[4096];
  327     char path1[2048];
  328     char path2[2048];
  329     struct strlist *s;
  330     struct conf **confs=NULL;
  331     fail_unless(getcwd(cwd, sizeof(cwd))!=NULL);
  332     snprintf(buf, sizeof(buf),
  333         "%sinclude_glob=%s/%s/*.glob\ninclude=/1\n",
  334         MIN_CLIENT_CONF, cwd, BASE);
  335     snprintf(path1, sizeof(path1), "%s/%s/a.glob", cwd, BASE);
  336     snprintf(path2, sizeof(path2), "%s/%s/b.glob", cwd, BASE);
  337     setup(&confs, NULL);
  338     build_file(CONFFILE, buf);
  339 
  340     fail_unless(!conf_load_global_only(CONFFILE, confs));
  341     s=get_strlist(confs[OPT_INCLUDE]);
  342     assert_include(&s, "/1");
  343     assert_include(&s, NULL);
  344 
  345     build_file(path1, "a");
  346     fail_unless(!reeval_glob(confs));
  347     s=get_strlist(confs[OPT_INCLUDE]);
  348     assert_include(&s, "/1");
  349     assert_include(&s, path1);
  350     assert_include(&s, NULL);
  351 
  352     build_file(path2, "b");
  353     fail_unless(!reeval_glob(confs));
  354     s=get_strlist(confs[OPT_INCLUDE]);
  355     assert_include(&s, "/1");
  356     assert_include(&s, path1);
  357     assert_include(&s, path2);
  358     assert_include(&s, NULL);
  359 
  360     tear_down(NULL, &confs);
  361 }
  362 END_TEST
  363 
  364 START_TEST(test_server_conf)
  365 {
  366     struct strlist *s;
  367     struct conf **confs=NULL;
  368     setup(&confs, NULL);
  369     build_file(CONFFILE, MIN_SERVER_CONF);
  370     fail_unless(!conf_load_global_only(CONFFILE, confs));
  371     fail_unless(get_e_burp_mode(confs[OPT_BURP_MODE])==BURP_MODE_SERVER);
  372     check_listen(confs, "0.0.0.0:1234", 5, "0.0.0.0:12345", 5);
  373     ck_assert_str_eq(get_string(confs[OPT_LOCKFILE]), "/lockfile/path");
  374     ck_assert_str_eq(get_string(confs[OPT_SSL_CERT]), "/ssl/cert/path");
  375     ck_assert_str_eq(get_string(confs[OPT_SSL_CERT_CA]), "/cert_ca/path");
  376     ck_assert_str_eq(get_string(confs[OPT_DIRECTORY]), "/a/directory");
  377     ck_assert_str_eq(get_string(confs[OPT_DEDUP_GROUP]), "a_group");
  378     ck_assert_str_eq(get_string(confs[OPT_CLIENTCONFDIR]), "clientconfdir");
  379     ck_assert_str_eq(get_string(confs[OPT_SSL_DHFILE]), "/a/dhfile");
  380     s=get_strlist(confs[OPT_KEEP]);
  381     assert_strlist(&s, "10", 10);
  382     assert_include(&s, NULL);
  383     tear_down(NULL, &confs);
  384 }
  385 END_TEST
  386 
  387 START_TEST(test_server_port_conf_one_max_child)
  388 {
  389     struct conf **confs=NULL;
  390     setup(&confs, NULL);
  391     build_file(CONFFILE, MIN_SERVER_CONF_NO_LISTEN
  392         "listen=0.0.0.0:1234\n"
  393         "listen_status=0.0.0.0:12345\n"
  394         "max_children=12\n"
  395         "max_status_children=21\n");
  396     fail_unless(!conf_load_global_only(CONFFILE, confs));
  397     check_listen(confs, "0.0.0.0:1234", 12, "0.0.0.0:12345", 21);
  398     tear_down(NULL, &confs);
  399 }
  400 END_TEST
  401 
  402 START_TEST(test_server_port_conf_too_many_max_child)
  403 {
  404     struct conf **confs=NULL;
  405     setup(&confs, NULL);
  406     build_file(CONFFILE, MIN_SERVER_CONF_NO_LISTEN
  407         "port=1234\n"
  408         "max_children=12\n"
  409         "max_children=21\n");
  410     fail_unless(conf_load_global_only(CONFFILE, confs)==-1);
  411     fail_unless(get_strlist(confs[OPT_STATUS_PORT])==NULL);
  412     tear_down(NULL, &confs);
  413 }
  414 END_TEST
  415 
  416 START_TEST(test_server_port_conf_few_max_child)
  417 {
  418     struct strlist *s;
  419     struct conf **confs=NULL;
  420     setup(&confs, NULL);
  421     build_file(CONFFILE, MIN_SERVER_CONF_NO_LISTEN
  422         "listen=0.0.0.0:1234\n"
  423         "listen=1.1.1.1:2345\n"
  424         "listen=9.8.7.6:3456\n"
  425         "max_children=12\n"
  426         "max_children=21\n");
  427     fail_unless(!conf_load_global_only(CONFFILE, confs));
  428 
  429     s=get_strlist(confs[OPT_LISTEN]);
  430     assert_strlist(&s, "0.0.0.0:1234", 12);
  431     assert_strlist(&s, "1.1.1.1:2345", 21);
  432     assert_strlist(&s, "9.8.7.6:3456", 21); // takes the previous as default
  433     fail_unless(get_strlist(confs[OPT_LISTEN_STATUS])==NULL);
  434     tear_down(NULL, &confs);
  435 }
  436 END_TEST
  437 
  438 START_TEST(test_server_port_conf_complex)
  439 {
  440     struct strlist *s;
  441     struct conf **confs=NULL;
  442     setup(&confs, NULL);
  443     build_file(CONFFILE, MIN_SERVER_CONF_NO_LISTEN
  444         "listen=0.0.0.0:1234\n"
  445         "listen=1.1.1.1:2345\n"
  446         "listen=9.8.7.6:3456\n"
  447         "max_children=12\n"
  448         "max_children=21\n"
  449         "max_children=37\n"
  450         "listen_status=::1:987\n"
  451         "listen_status=127.0.0.1:654\n"
  452         "listen_status=1abc:2323::9999:321\n"
  453         "max_status_children=4\n"
  454         "max_status_children=5\n"
  455         "max_status_children=6\n");
  456     fail_unless(!conf_load_global_only(CONFFILE, confs));
  457 
  458     s=get_strlist(confs[OPT_LISTEN]);
  459     assert_strlist(&s, "0.0.0.0:1234", 12);
  460     assert_strlist(&s, "1.1.1.1:2345", 21);
  461     assert_strlist(&s, "9.8.7.6:3456", 37);
  462     s=get_strlist(confs[OPT_LISTEN_STATUS]);
  463     assert_strlist(&s, "::1:987", 4);
  464     assert_strlist(&s, "127.0.0.1:654", 5);
  465     assert_strlist(&s, "1abc:2323::9999:321", 6);
  466     tear_down(NULL, &confs);
  467 }
  468 END_TEST
  469 
  470 static void pre_post_assertions(struct conf **confs, const char *pre_path,
  471     const char *post_path, const char *pre_arg1, const char *pre_arg2,
  472     const char *post_arg1, const char *post_arg2,
  473     enum conf_opt o_script_pre, enum conf_opt o_script_post,
  474     enum conf_opt o_script_pre_arg, enum conf_opt o_script_post_arg,
  475     enum conf_opt o_script_pre_notify, enum conf_opt o_script_post_notify,
  476     enum conf_opt o_script_post_run_on_fail)
  477 {
  478     struct strlist *s;
  479     ck_assert_str_eq(get_string(confs[o_script_pre]), pre_path);
  480     ck_assert_str_eq(get_string(confs[o_script_post]), post_path);
  481     s=get_strlist(confs[o_script_pre_arg]);
  482     assert_strlist(&s, pre_arg1, 0);
  483     assert_strlist(&s, pre_arg2, 0);
  484     assert_strlist(&s, NULL, 0);
  485     if(o_script_pre_notify!=OPT_MAX)
  486         fail_unless(get_int(confs[o_script_pre_notify])==1);
  487     s=get_strlist(confs[o_script_post_arg]);
  488     assert_strlist(&s, post_arg1, 0);
  489     assert_strlist(&s, post_arg2, 0);
  490     assert_strlist(&s, NULL, 0);
  491     if(o_script_post_notify!=OPT_MAX)
  492         fail_unless(get_int(confs[o_script_post_notify])==1);
  493     fail_unless(get_int(confs[o_script_post_run_on_fail])==1);
  494 }
  495 
  496 static void pre_post_checks(const char *buf, const char *pre_path,
  497     const char *post_path, const char *pre_arg1, const char *pre_arg2,
  498     const char *post_arg1, const char *post_arg2,
  499     enum conf_opt o_script_pre, enum conf_opt o_script_post,
  500     enum conf_opt o_script_pre_arg, enum conf_opt o_script_post_arg,
  501     enum conf_opt o_script_pre_notify, enum conf_opt o_script_post_notify,
  502     enum conf_opt o_script_post_run_on_fail)
  503 {
  504     struct conf **confs=NULL;
  505     setup(&confs, NULL);
  506     build_file(CONFFILE, buf);
  507     fail_unless(!conf_load_global_only(CONFFILE, confs));
  508     pre_post_assertions(confs, pre_path, post_path, pre_arg1, pre_arg2,
  509         post_arg1, post_arg2,
  510         o_script_pre, o_script_post,
  511         o_script_pre_arg, o_script_post_arg,
  512         o_script_pre_notify, o_script_post_notify,
  513         o_script_post_run_on_fail);
  514     tear_down(NULL, &confs);
  515 }
  516 
  517 static void server_pre_post_checks(const char *buf, const char *pre_path,
  518     const char *post_path, const char *pre_arg1, const char *pre_arg2,
  519     const char *post_arg1, const char *post_arg2)
  520 {
  521     pre_post_checks(buf, pre_path, post_path, pre_arg1, pre_arg2,
  522         post_arg1, post_arg2,
  523         OPT_S_SCRIPT_PRE, OPT_S_SCRIPT_POST,
  524         OPT_S_SCRIPT_PRE_ARG, OPT_S_SCRIPT_POST_ARG,
  525         OPT_S_SCRIPT_PRE_NOTIFY, OPT_S_SCRIPT_POST_NOTIFY,
  526         OPT_S_SCRIPT_POST_RUN_ON_FAIL);
  527 }
  528 
  529 #define SERVER_SCRIPT_PRE_POST          \
  530     "server_script_pre=pre_path\n"      \
  531     "server_script_pre_arg=pre_arg1\n"  \
  532     "server_script_pre_arg=pre_arg2\n"  \
  533     "server_script_pre_notify=1\n"      \
  534     "server_script_post=post_path\n"    \
  535     "server_script_post_arg=post_arg1\n"    \
  536     "server_script_post_arg=post_arg2\n"    \
  537     "server_script_post_notify=1\n"     \
  538     "server_script_post_run_on_fail=1\n"    \
  539 
  540 START_TEST(test_server_script_pre_post)
  541 {
  542     const char *buf=MIN_SERVER_CONF SERVER_SCRIPT_PRE_POST;
  543     server_pre_post_checks(buf, "pre_path", "post_path", "pre_arg1",
  544         "pre_arg2", "post_arg1", "post_arg2");
  545 }
  546 END_TEST
  547 
  548 #define SERVER_SCRIPT_CONF          \
  549     "server_script=path\n"          \
  550     "server_script_arg=arg1\n"      \
  551     "server_script_arg=arg2\n"      \
  552     "server_script_notify=1\n"      \
  553     "server_script_notify=1\n"      \
  554     "server_script_run_on_fail=1\n"     \
  555     "server_script_post_run_on_fail=1\n"    \
  556 
  557 // Same as test_server_script_pre_post, but use server_script to set both pre
  558 // and post at the same time.
  559 START_TEST(test_server_script)
  560 {
  561     const char *buf=MIN_SERVER_CONF SERVER_SCRIPT_CONF;
  562     server_pre_post_checks(buf, "path", "path", "arg1",
  563         "arg2", "arg1", "arg2");
  564 }
  565 END_TEST
  566 
  567 static void backup_script_pre_post_checks(const char *buf, const char *pre_path,
  568     const char *post_path, const char *pre_arg1, const char *pre_arg2,
  569     const char *post_arg1, const char *post_arg2)
  570 {
  571     pre_post_checks(buf, pre_path, post_path, pre_arg1, pre_arg2,
  572         post_arg1, post_arg2,
  573         OPT_B_SCRIPT_PRE, OPT_B_SCRIPT_POST,
  574         OPT_B_SCRIPT_PRE_ARG, OPT_B_SCRIPT_POST_ARG,
  575         OPT_MAX, OPT_MAX, OPT_B_SCRIPT_POST_RUN_ON_FAIL);
  576 }
  577 
  578 START_TEST(test_backup_script_pre_post)
  579 {
  580     const char *buf=MIN_CLIENT_CONF
  581         "backup_script_pre=pre_path\n"
  582         "backup_script_pre_arg=pre_arg1\n"
  583         "backup_script_pre_arg=pre_arg2\n"
  584         "backup_script_post=post_path\n"
  585         "backup_script_post_arg=post_arg1\n"
  586         "backup_script_post_arg=post_arg2\n"
  587         "backup_script_post_run_on_fail=1\n"
  588     ;
  589     backup_script_pre_post_checks(buf, "pre_path", "post_path", "pre_arg1",
  590         "pre_arg2", "post_arg1", "post_arg2");
  591 }
  592 END_TEST
  593 
  594 // Same as test_backup_script_pre_post, but use backup_script to set both pre
  595 // and post at the same time.
  596 START_TEST(test_backup_script)
  597 {
  598     const char *buf=MIN_CLIENT_CONF
  599         "backup_script=path\n"
  600         "backup_script_arg=arg1\n"
  601         "backup_script_arg=arg2\n"
  602         "backup_script_run_on_fail=1\n"
  603         "backup_script_post_run_on_fail=1\n"
  604     ;
  605     backup_script_pre_post_checks(buf, "path", "path", "arg1",
  606         "arg2", "arg1", "arg2");
  607 }
  608 END_TEST
  609 
  610 static void restore_script_pre_post_checks(const char *buf,
  611     const char *pre_path, const char *post_path,
  612     const char *pre_arg1, const char *pre_arg2,
  613     const char *post_arg1, const char *post_arg2)
  614 {
  615     pre_post_checks(buf, pre_path, post_path, pre_arg1, pre_arg2,
  616         post_arg1, post_arg2,
  617         OPT_R_SCRIPT_PRE, OPT_R_SCRIPT_POST,
  618         OPT_R_SCRIPT_PRE_ARG, OPT_R_SCRIPT_POST_ARG,
  619         OPT_MAX, OPT_MAX, OPT_R_SCRIPT_POST_RUN_ON_FAIL);
  620 }
  621 
  622 START_TEST(test_restore_script_pre_post)
  623 {
  624     const char *buf=MIN_CLIENT_CONF
  625         "restore_script_pre=pre_path\n"
  626         "restore_script_pre_arg=pre_arg1\n"
  627         "restore_script_pre_arg=pre_arg2\n"
  628         "restore_script_post=post_path\n"
  629         "restore_script_post_arg=post_arg1\n"
  630         "restore_script_post_arg=post_arg2\n"
  631         "restore_script_post_run_on_fail=1\n"
  632     ;
  633     restore_script_pre_post_checks(buf, "pre_path", "post_path", "pre_arg1",
  634         "pre_arg2", "post_arg1", "post_arg2");
  635 }
  636 END_TEST
  637 
  638 // Same as test_restore_script_pre_post, but use restore_script to set both pre
  639 // and post at the same time.
  640 START_TEST(test_restore_script)
  641 {
  642     const char *buf=MIN_CLIENT_CONF
  643         "restore_script=path\n"
  644         "restore_script_arg=arg1\n"
  645         "restore_script_arg=arg2\n"
  646         "restore_script_run_on_fail=1\n"
  647         "restore_script_post_run_on_fail=1\n"
  648     ;
  649     restore_script_pre_post_checks(buf, "path", "path", "arg1",
  650         "arg2", "arg1", "arg2");
  651 }
  652 END_TEST
  653 
  654 static void clientconfdir_setup(struct conf ***globalcs, struct conf ***cconfs,
  655     const char *gbuf, const char *buf)
  656 {
  657     const char *global_path=BASE "/burp-server.conf";
  658     setup(globalcs, cconfs);
  659     build_file(CONFFILE, gbuf);
  660     fail_unless(!conf_load_global_only(CONFFILE, *globalcs));
  661     set_string((*cconfs)[OPT_CNAME], "utestclient");
  662     build_file(global_path, buf);
  663     fail_unless(!conf_load_overrides(*globalcs, *cconfs, global_path));
  664     ck_assert_str_eq(get_string((*cconfs)[OPT_CNAME]), "utestclient");
  665 }
  666 
  667 #define NOTIFY_CONF             \
  668     "notify_success_script=/success_path\n" \
  669     "notify_success_arg=/success/arg1\n"    \
  670     "notify_success_arg=/success/arg2\n"    \
  671     "notify_success_warnings_only=1\n"  \
  672     "notify_success_changes_only=1\n"   \
  673     "notify_failure_script=/failure_path\n" \
  674     "notify_failure_arg=/failure/arg1\n"    \
  675     "notify_failure_arg=/failure/arg2\n"    \
  676 
  677 static void notify_assertions(struct conf **cconfs)
  678 {
  679     struct strlist *s;
  680     ck_assert_str_eq(get_string(cconfs[OPT_N_SUCCESS_SCRIPT]),
  681         "/success_path");
  682     s=get_strlist(cconfs[OPT_N_SUCCESS_ARG]);
  683     assert_strlist(&s, "/success/arg1", 0);
  684     assert_strlist(&s, "/success/arg2", 0);
  685     assert_include(&s, NULL);
  686     ck_assert_str_eq(get_string(cconfs[OPT_N_FAILURE_SCRIPT]),
  687         "/failure_path");
  688     fail_unless(get_int(cconfs[OPT_N_SUCCESS_WARNINGS_ONLY])==1);
  689     fail_unless(get_int(cconfs[OPT_N_SUCCESS_CHANGES_ONLY])==1);
  690     s=get_strlist(cconfs[OPT_N_FAILURE_ARG]);
  691     assert_strlist(&s, "/failure/arg1", 0);
  692     assert_strlist(&s, "/failure/arg2", 0);
  693     assert_include(&s, NULL);
  694 }
  695 
  696 #define MIN_CLIENTCONFDIR_BUF "# comment\n"
  697 
  698 START_TEST(test_clientconfdir_conf)
  699 {
  700     struct strlist *s;
  701     struct conf **globalcs=NULL;
  702     struct conf **cconfs=NULL;
  703     const char *gbuf=MIN_SERVER_CONF
  704         "restore_client=abc\n"
  705         "restore_client=xyz\n"
  706         "super_client=sss\n"
  707         "super_client=ttt\n"
  708         "timer_script=/timer/script\n"
  709         "timer_arg=/timer/arg1\n"
  710         "timer_arg=/timer/arg2\n"
  711         "label=qwe\n"
  712         "client_lockdir=/tmp/blah\n"
  713         NOTIFY_CONF
  714     ;
  715     const char *buf=MIN_CLIENTCONFDIR_BUF
  716         "protocol=1\n"
  717         "directory=/another/dir\n"
  718         "directory_tree=0\n"
  719         "timestamp_format=%H %M %S\n"
  720         "password_check=0\n"
  721         "keep=4\n"
  722         "keep=7\n"
  723         "working_dir_recovery_method=resume\n"
  724         "max_resume_attempts=5\n"
  725         "librsync=0\n"
  726         "librsync_max_size=10Mb\n"
  727         "version_warn=0\n"
  728         "path_length_warn=0\n"
  729         "syslog=1\n"
  730         "client_can_delete=0\n"
  731         "client_can_force_backup=0\n"
  732         "client_can_list=0\n"
  733         "client_can_monitor=0\n"
  734         "client_can_restore=0\n"
  735         "client_can_verify=0\n"
  736         "restore_client=123\n"
  737         "restore_client=456\n"
  738         "super_client=ppp\n"
  739         "super_client=qqq\n"
  740         "dedup_group=dd_group\n"
  741         "label=rty\n"
  742         "label=xyz\n"
  743     ;
  744 
  745     clientconfdir_setup(&globalcs, &cconfs, gbuf, buf);
  746 
  747     fail_unless(get_e_protocol(cconfs[OPT_PROTOCOL])==PROTO_1);
  748     ck_assert_str_eq(get_string(cconfs[OPT_DIRECTORY]), "/another/dir");
  749     fail_unless(get_int(cconfs[OPT_DIRECTORY_TREE])==0);
  750     ck_assert_str_eq(get_string(cconfs[OPT_TIMESTAMP_FORMAT]),
  751         "%H %M %S");
  752     fail_unless(get_int(cconfs[OPT_PASSWORD_CHECK])==0);
  753     s=get_strlist(cconfs[OPT_KEEP]);
  754     assert_strlist(&s, "4", 4);
  755     assert_strlist(&s, "7", 8); // The last one gets 1 added to it.
  756     assert_include(&s, NULL);
  757     s=get_strlist(cconfs[OPT_RESTORE_CLIENTS]);
  758     assert_strlist(&s, "123", 0);
  759     assert_strlist(&s, "456", 0);
  760     assert_strlist(&s, "abc", 0);
  761     assert_strlist(&s, "xyz", 0);
  762     assert_include(&s, NULL);
  763     s=get_strlist(cconfs[OPT_SUPER_CLIENTS]);
  764     assert_strlist(&s, "ppp", 0);
  765     assert_strlist(&s, "qqq", 0);
  766     assert_strlist(&s, "sss", 0);
  767     assert_strlist(&s, "ttt", 0);
  768     assert_include(&s, NULL);
  769     fail_unless(get_e_recovery_method(
  770       cconfs[OPT_WORKING_DIR_RECOVERY_METHOD])==RECOVERY_METHOD_RESUME);
  771     fail_unless(get_int(cconfs[OPT_MAX_RESUME_ATTEMPTS])==5);
  772     fail_unless(get_int(cconfs[OPT_LIBRSYNC])==0);
  773     fail_unless(get_uint64_t(cconfs[OPT_LIBRSYNC_MAX_SIZE])==10485760);
  774     fail_unless(get_int(cconfs[OPT_VERSION_WARN])==0);
  775     fail_unless(get_int(cconfs[OPT_PATH_LENGTH_WARN])==0);
  776     fail_unless(get_int(cconfs[OPT_SYSLOG])==1);
  777     fail_unless(get_int(cconfs[OPT_CLIENT_CAN_DELETE])==0);
  778     fail_unless(get_int(cconfs[OPT_CLIENT_CAN_FORCE_BACKUP])==0);
  779     fail_unless(get_int(cconfs[OPT_CLIENT_CAN_LIST])==0);
  780     fail_unless(get_int(cconfs[OPT_CLIENT_CAN_RESTORE])==0);
  781     fail_unless(get_int(cconfs[OPT_CLIENT_CAN_VERIFY])==0);
  782     s=get_strlist(cconfs[OPT_TIMER_ARG]);
  783     assert_strlist(&s, "/timer/arg1", 0);
  784     assert_strlist(&s, "/timer/arg2", 0);
  785     assert_include(&s, NULL);
  786     ck_assert_str_eq(get_string(cconfs[OPT_DEDUP_GROUP]), "dd_group");
  787     s=get_strlist(cconfs[OPT_LABEL]);
  788     assert_strlist(&s, "rty", 0);
  789     assert_strlist(&s, "xyz", 0);
  790     notify_assertions(cconfs);
  791     ck_assert_str_eq(get_string(globalcs[OPT_CLIENT_LOCKDIR]), "/tmp/blah");
  792     ck_assert_str_eq(get_string(cconfs[OPT_CLIENT_LOCKDIR]), "/tmp/blah");
  793     tear_down(&globalcs, &cconfs);
  794 }
  795 END_TEST
  796 
  797 START_TEST(test_clientconfdir_extra)
  798 {
  799     struct strlist *s;
  800     struct conf **globalcs=NULL;
  801     struct conf **cconfs=NULL;
  802     const char *gbuf=MIN_SERVER_CONF
  803         "restore_client=abc\n"
  804         "include = /ignored/include\n"
  805         "timer_script = /ignored/timer\n"
  806         "timer_arg = /ignored/timer/arg1\n"
  807         "timer_arg = /ignored/timer/arg2\n"
  808         "notify_success_script = /ignored/success\n"
  809         "notify_success_arg = /ignored/success/arg\n"
  810         "notify_failure_script = /ignored/failure\n"
  811         "notify_failure_arg = /ignored/failure/arg\n"
  812         SERVER_SCRIPT_CONF
  813     ;
  814     const char *buf=MIN_CLIENTCONFDIR_BUF
  815         "include = /testdir\n"
  816         "timer_script = /timer/script\n"
  817         "timer_arg = /timer/arg1\n"
  818         "timer_arg = /timer/arg2\n"
  819         SERVER_SCRIPT_PRE_POST
  820         NOTIFY_CONF
  821     ;
  822     clientconfdir_setup(&globalcs, &cconfs, gbuf, buf);
  823     s=get_strlist(cconfs[OPT_RESTORE_CLIENTS]);
  824     assert_strlist(&s, "abc", 0);
  825     assert_include(&s, NULL);
  826     s=get_strlist(cconfs[OPT_INCLUDE]);
  827     assert_strlist(&s, "/testdir", 1);
  828     assert_include(&s, NULL);
  829     ck_assert_str_eq(get_string(cconfs[OPT_TIMER_SCRIPT]), "/timer/script");
  830     s=get_strlist(cconfs[OPT_TIMER_ARG]);
  831     assert_strlist(&s, "/timer/arg1", 0);
  832     assert_strlist(&s, "/timer/arg2", 0);
  833     assert_include(&s, NULL);
  834     pre_post_assertions(cconfs, "pre_path", "post_path",
  835         "pre_arg1", "pre_arg2",
  836         "post_arg1", "post_arg2",
  837         OPT_S_SCRIPT_PRE, OPT_S_SCRIPT_POST,
  838         OPT_S_SCRIPT_PRE_ARG, OPT_S_SCRIPT_POST_ARG,
  839         OPT_S_SCRIPT_PRE_NOTIFY, OPT_S_SCRIPT_POST_NOTIFY,
  840         OPT_S_SCRIPT_POST_RUN_ON_FAIL);
  841     notify_assertions(cconfs);
  842     tear_down(&globalcs, &cconfs);
  843 }
  844 END_TEST
  845 
  846 START_TEST(test_strlist_reset)
  847 {
  848     struct strlist *s;
  849     struct conf **confs=NULL;
  850     setup(&confs, NULL);
  851     build_file(CONFFILE, MIN_SERVER_CONF
  852         "timer_arg = /ignored/timer/arg1\n"
  853         "timer_arg = /ignored/timer/arg2\n"
  854         "timer_arg := /timer/arg3\n"
  855         "timer_arg = /timer/arg4\n");
  856     fail_unless(!conf_load_global_only(CONFFILE, confs));
  857 
  858     s=get_strlist(confs[OPT_TIMER_ARG]);
  859     assert_strlist(&s, "/timer/arg3", 0);
  860     assert_strlist(&s, "/timer/arg4", 0);
  861     assert_include(&s, NULL);
  862     tear_down(NULL, &confs);
  863 }
  864 END_TEST
  865 
  866 START_TEST(test_clientconfdir_server_script)
  867 {
  868     struct conf **globalcs=NULL;
  869     struct conf **cconfs=NULL;
  870     const char *gbuf=MIN_SERVER_CONF SERVER_SCRIPT_PRE_POST;
  871     const char *buf=MIN_CLIENTCONFDIR_BUF SERVER_SCRIPT_CONF;
  872 
  873     clientconfdir_setup(&globalcs, &cconfs, gbuf, buf);
  874     pre_post_assertions(cconfs, "path", "path",
  875         "arg1", "arg2",
  876         "arg1", "arg2",
  877         OPT_S_SCRIPT_PRE, OPT_S_SCRIPT_POST,
  878         OPT_S_SCRIPT_PRE_ARG, OPT_S_SCRIPT_POST_ARG,
  879         OPT_S_SCRIPT_PRE_NOTIFY, OPT_S_SCRIPT_POST_NOTIFY,
  880         OPT_S_SCRIPT_POST_RUN_ON_FAIL);
  881     tear_down(&globalcs, &cconfs);
  882 }
  883 END_TEST
  884 
  885 static void switch_test(int expected_ret, const char *gbuf)
  886 {
  887     char orig_client_conf[256]="";
  888     const char *clientconfdir;
  889     struct conf **globalcs=NULL;
  890     struct conf **cconfs=NULL;
  891     const char *buf=MIN_CLIENTCONFDIR_BUF;
  892     const char *orig_client_buf=MIN_CLIENTCONFDIR_BUF;
  893 
  894     clientconfdir_setup(&globalcs, &cconfs, gbuf, buf);
  895     clientconfdir=get_string(globalcs[OPT_CLIENTCONFDIR]);
  896     fail_unless(!recursive_delete(clientconfdir));
  897     snprintf(orig_client_conf, sizeof(orig_client_conf),
  898         "%s/orig_client", clientconfdir);
  899     build_file(orig_client_conf, orig_client_buf);
  900     fail_unless(conf_switch_to_orig_client(globalcs, cconfs,
  901         "orig_client")==expected_ret);
  902     if(!expected_ret)
  903     {
  904         ck_assert_str_eq(get_string(cconfs[OPT_CNAME]),
  905             "orig_client");
  906         ck_assert_str_eq(get_string(cconfs[OPT_SUPER_CLIENT]),
  907             "orig_client");
  908         ck_assert_str_eq(get_string(cconfs[OPT_ORIG_CLIENT]),
  909             "orig_client");
  910     }
  911     fail_unless(!recursive_delete(clientconfdir));
  912     tear_down(&globalcs, &cconfs);
  913 }
  914 
  915 START_TEST(test_conf_switch_to_orig_client_fail_restore_client)
  916 {
  917     const char *gbuf=MIN_SERVER_CONF
  918         "restore_client=non-matching1\n"
  919         "restore_client=non-matching2\n";
  920     switch_test(-1, gbuf);
  921 }
  922 END_TEST
  923 
  924 START_TEST(test_conf_switch_to_orig_client_ok_restore_client)
  925 {
  926     const char *gbuf=MIN_SERVER_CONF
  927         "restore_client=non-matching1\n"
  928         "restore_client=utestclient\n";
  929     switch_test(0, gbuf);
  930 }
  931 END_TEST
  932 
  933 struct cndata
  934 {
  935     const char *cname;
  936     int valid;
  937 };
  938 
  939 static struct cndata c[] = {
  940     { "testclient", 1 },
  941     { "test.client", 1 },
  942     { "testclient..", 1 },
  943     { ".testclient", 0 },
  944     { "testclient~", 0 },
  945     { ".", 0 },
  946     { "..", 0 },
  947     { "/testclient", 0 },
  948     { "test/client", 0 },
  949     { "test\\client", 0 },
  950     { "/..", 0 },
  951     { "../", 0 },
  952     { "../../testclient", 0 },
  953     { "testclient/../blah", 0 },
  954 };
  955 
  956 START_TEST(test_cname_valid)
  957 {
  958     FOREACH(c)
  959     {
  960         fail_unless(cname_valid(c[i].cname)==c[i].valid);
  961     }
  962 }
  963 END_TEST
  964 
  965 START_TEST(test_conf_switch_to_orig_client_fail_super_client)
  966 {
  967     const char *gbuf=MIN_SERVER_CONF
  968         "super_client=non-matching1\n"
  969         "super_client=non-matching2\n";
  970     switch_test(-1, gbuf);
  971 }
  972 END_TEST
  973 
  974 START_TEST(test_conf_switch_to_orig_client_ok_super_client)
  975 {
  976     const char *gbuf=MIN_SERVER_CONF
  977         "super_client=non-matching1\n"
  978         "super_client=utestclient\n";
  979     switch_test(0, gbuf);
  980 }
  981 END_TEST
  982 
  983 struct client_can_data
  984 {
  985     const char *config_str;
  986     int force_backup;
  987     int force_backup_orig;
  988     int force_backup_expected;
  989     int client_can;
  990     int client_can_orig;
  991     int client_can_expected;
  992 };
  993 
  994 static struct client_can_data ccd[] = {
  995     { "super_client", 0, 0, 0,  0, 0, 0 },
  996     { "super_client", 1, 0, 0,  1, 0, 1 },
  997     { "super_client", 0, 1, 0,  0, 1, 0 },
  998     { "super_client", 1, 1, 0,  1, 1, 1 },
  999     { "restore_client", 0, 0, 0,  0, 0, 0 },
 1000     { "restore_client", 1, 0, 0,  1, 0, 0 },
 1001     { "restore_client", 0, 1, 0,  0, 1, 0 },
 1002     { "restore_client", 1, 1, 0,  1, 1, 1 },
 1003 };
 1004 
 1005 START_TEST(test_conf_switch_to_orig_client_client_can)
 1006 {
 1007     FOREACH(ccd)
 1008     {
 1009         char orig_client_conf[256]="";
 1010         const char *clientconfdir;
 1011         struct conf **globalcs=NULL;
 1012         struct conf **cconfs=NULL;
 1013         char buf[4096]="";
 1014         char obuf[4096]="";
 1015         char gbuf[4096]="";
 1016 
 1017         snprintf(gbuf, sizeof(gbuf), "%s%s=utestclient",
 1018             MIN_SERVER_CONF, ccd[i].config_str);
 1019 
 1020         snprintf(buf, sizeof(buf), "%s\n"
 1021             "client_can_force_backup=%d\n"
 1022             "client_can_delete=%d\n"
 1023             "client_can_diff=%d\n"
 1024             "client_can_list=%d\n"
 1025             "client_can_monitor=%d\n"
 1026             "client_can_restore=%d\n"
 1027             "client_can_verify=%d\n",
 1028             MIN_SERVER_CONF,
 1029             ccd[i].force_backup,
 1030             ccd[i].client_can,
 1031             ccd[i].client_can,
 1032             ccd[i].client_can,
 1033             ccd[i].client_can,
 1034             ccd[i].client_can,
 1035             ccd[i].client_can);
 1036         snprintf(obuf, sizeof(obuf), "%s\n"
 1037             "client_can_force_backup=%d\n"
 1038             "client_can_delete=%d\n"
 1039             "client_can_diff=%d\n"
 1040             "client_can_list=%d\n"
 1041             "client_can_monitor=%d\n"
 1042             "client_can_restore=%d\n"
 1043             "client_can_verify=%d\n",
 1044             MIN_SERVER_CONF,
 1045             ccd[i].force_backup_orig,
 1046             ccd[i].client_can_orig,
 1047             ccd[i].client_can_orig,
 1048             ccd[i].client_can_orig,
 1049             ccd[i].client_can_orig,
 1050             ccd[i].client_can_orig,
 1051             ccd[i].client_can_orig);
 1052 
 1053         clientconfdir_setup(&globalcs, &cconfs, gbuf, buf);
 1054         clientconfdir=get_string(globalcs[OPT_CLIENTCONFDIR]);
 1055         fail_unless(!recursive_delete(clientconfdir));
 1056         snprintf(orig_client_conf, sizeof(orig_client_conf),
 1057             "%s/orig_client", clientconfdir);
 1058         build_file(orig_client_conf, obuf);
 1059         fail_unless(conf_switch_to_orig_client(globalcs, cconfs,
 1060             "orig_client")==0);
 1061 
 1062         fail_unless(get_int(cconfs[OPT_CLIENT_CAN_FORCE_BACKUP])
 1063             ==ccd[i].force_backup_expected);
 1064         fail_unless(get_int(cconfs[OPT_CLIENT_CAN_DELETE])
 1065             ==ccd[i].client_can_expected);
 1066         fail_unless(get_int(cconfs[OPT_CLIENT_CAN_DIFF])
 1067             ==ccd[i].client_can_expected);
 1068         fail_unless(get_int(cconfs[OPT_CLIENT_CAN_LIST])
 1069             ==ccd[i].client_can_expected);
 1070         fail_unless(get_int(cconfs[OPT_CLIENT_CAN_MONITOR])
 1071             ==ccd[i].client_can_expected);
 1072         fail_unless(get_int(cconfs[OPT_CLIENT_CAN_RESTORE])
 1073             ==ccd[i].client_can_expected);
 1074         fail_unless(get_int(cconfs[OPT_CLIENT_CAN_VERIFY])
 1075             ==ccd[i].client_can_expected);
 1076 
 1077         fail_unless(!recursive_delete(clientconfdir));
 1078         tear_down(&globalcs, &cconfs);
 1079     }
 1080 }
 1081 END_TEST
 1082 
 1083 Suite *suite_conffile(void)
 1084 {
 1085     Suite *s;
 1086     TCase *tc_core;
 1087 
 1088     s=suite_create("conffile");
 1089 
 1090     tc_core=tcase_create("Core");
 1091 
 1092     tcase_add_test(tc_core, test_conf_get_pair);
 1093     tcase_add_test(tc_core, test_client_conf);
 1094     tcase_add_test(tc_core, test_client_conf_ca_conf_problems);
 1095     tcase_add_test(tc_core, test_client_includes_excludes);
 1096     tcase_add_test(tc_core, test_client_include_failures);
 1097     tcase_add_test(tc_core, test_client_include_glob);
 1098     tcase_add_test(tc_core, test_client_conf_monitor_exe);
 1099     tcase_add_test(tc_core, test_client_conf_ports_opt_port_only);
 1100     tcase_add_test(tc_core, test_client_conf_ports_opt_port_and_restore);
 1101     tcase_add_test(tc_core, test_client_conf_ports_opt_port_and_all);
 1102     tcase_add_test(tc_core, test_client_conf_ports_no_opt_port_and_all);
 1103     tcase_add_test(tc_core, test_server_conf);
 1104     tcase_add_test(tc_core, test_server_port_conf_one_max_child);
 1105     tcase_add_test(tc_core, test_server_port_conf_too_many_max_child);
 1106     tcase_add_test(tc_core, test_server_port_conf_few_max_child);
 1107     tcase_add_test(tc_core, test_server_port_conf_complex);
 1108     tcase_add_test(tc_core, test_server_script_pre_post);
 1109     tcase_add_test(tc_core, test_server_script);
 1110     tcase_add_test(tc_core, test_backup_script_pre_post);
 1111     tcase_add_test(tc_core, test_backup_script);
 1112     tcase_add_test(tc_core, test_restore_script_pre_post);
 1113     tcase_add_test(tc_core, test_restore_script);
 1114     tcase_add_test(tc_core, test_clientconfdir_conf);
 1115     tcase_add_test(tc_core, test_clientconfdir_extra);
 1116     tcase_add_test(tc_core, test_strlist_reset);
 1117     tcase_add_test(tc_core, test_clientconfdir_server_script);
 1118     tcase_add_test(tc_core, test_cname_valid);
 1119     tcase_add_test(tc_core, test_conf_switch_to_orig_client_fail_restore_client);
 1120     tcase_add_test(tc_core, test_conf_switch_to_orig_client_ok_restore_client);
 1121     tcase_add_test(tc_core, test_conf_switch_to_orig_client_fail_super_client);
 1122     tcase_add_test(tc_core, test_conf_switch_to_orig_client_ok_super_client);
 1123     tcase_add_test(tc_core, test_conf_switch_to_orig_client_client_can);
 1124 
 1125     suite_add_tcase(s, tc_core);
 1126 
 1127     return s;
 1128 }