From a4bb497140b235ad88462a8953c05fb4474a0ec9 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Wed, 17 Jul 2013 19:30:24 +0200 Subject: [PATCH] Implement a store_alist_dir function We currently have the following functions: - store_dir() (For storing a string with shell expansion to a dir/file) - store_str() (For storing a string) - store_alist_str() (For storing a list of strings) we are missing a store_alist_dir() which stores a list of shell expanded dirs/files. Fixes #209: Implement a store_alist_dir function --- src/filed/filed_conf.c | 8 ++++---- src/lib/parse_conf.c | 44 +++++++++++++++++++++++++++++++++++------- src/lib/parse_conf.h | 1 + 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/filed/filed_conf.c b/src/filed/filed_conf.c index cfcc18b690b..195b66b4c3b 100644 --- a/src/filed/filed_conf.c +++ b/src/filed/filed_conf.c @@ -105,8 +105,8 @@ static RES_ITEM cli_items[] = { { "pkisignatures", store_bool, ITEM(res_client.pki_sign), 0, ITEM_DEFAULT, "false" }, { "pkiencryption", store_bool, ITEM(res_client.pki_encrypt), 0, ITEM_DEFAULT, "false" }, { "pkikeypair", store_dir, ITEM(res_client.pki_keypair_file), 0, 0, NULL }, - { "pkisigner", store_alist_str, ITEM(res_client.pki_signing_key_files), 0, 0, NULL }, - { "pkimasterkey", store_alist_str, ITEM(res_client.pki_master_key_files), 0, 0, NULL }, + { "pkisigner", store_alist_dir, ITEM(res_client.pki_signing_key_files), 0, 0, NULL }, + { "pkimasterkey", store_alist_dir, ITEM(res_client.pki_master_key_files), 0, 0, NULL }, { "pkicipher", store_cipher, ITEM(res_client.pki_cipher), 0, ITEM_DEFAULT, "aes128" }, #endif { "tlsauthenticate", store_bool, ITEM(res_client.tls_authenticate), 0, 0, NULL }, @@ -122,7 +122,7 @@ static RES_ITEM cli_items[] = { { "compatible", store_bool, ITEM(res_client.compatible), 0, ITEM_DEFAULT, "true" }, { "maximumbandwidthperjob", store_speed, ITEM(res_client.max_bandwidth_per_job), 0, 0, NULL }, { "allowbandwidthbursting", store_bool, ITEM(res_client.allow_bw_bursting), 0, ITEM_DEFAULT, "false" }, - { "allowedscriptdir", store_alist_str, ITEM(res_client.allowed_script_dirs), 0, 0, NULL }, + { "allowedscriptdir", store_alist_dir, ITEM(res_client.allowed_script_dirs), 0, 0, NULL }, { "allowedjobcommand", store_alist_str, ITEM(res_client.allowed_job_cmds), 0, 0, NULL }, { NULL, NULL, { 0 }, 0, 0, NULL } }; @@ -148,7 +148,7 @@ static RES_ITEM dir_items[] = { { "tlsdhfile", store_dir, ITEM(res_dir.tls_dhfile), 0, 0, NULL }, { "tlsallowedcn", store_alist_str, ITEM(res_dir.tls_allowed_cns), 0, 0, NULL }, { "maximumbandwidthperjob", store_speed, ITEM(res_dir.max_bandwidth_per_job), 0, 0, NULL }, - { "allowedscriptdir", store_alist_str, ITEM(res_dir.allowed_script_dirs), 0, 0, NULL }, + { "allowedscriptdir", store_alist_dir, ITEM(res_dir.allowed_script_dirs), 0, 0, NULL }, { "allowedjobcommand", store_alist_str, ITEM(res_dir.allowed_job_cmds), 0, 0, NULL }, { NULL, NULL, { 0 }, 0, 0, NULL } }; diff --git a/src/lib/parse_conf.c b/src/lib/parse_conf.c index 808148d4014..3400da01ced 100644 --- a/src/lib/parse_conf.c +++ b/src/lib/parse_conf.c @@ -487,8 +487,8 @@ void store_str(LEX *lc, RES_ITEM *item, int index, int pass) /* * Store a directory name at specified address. Note, we do - * shell expansion except if the string begins with a vertical - * bar (i.e. it will likely be passed to the shell later). + * shell expansion except if the string begins with a vertical + * bar (i.e. it will likely be passed to the shell later). */ void store_dir(LEX *lc, RES_ITEM *item, int index, int pass) { @@ -565,10 +565,10 @@ void store_res(LEX *lc, RES_ITEM *item, int index, int pass) /* * Store a resource pointer in an alist. default_value indicates how many - * times this routine can be called -- i.e. how many alists - * there are. - * If we are in pass 2, do a lookup of the - * resource. + * times this routine can be called -- i.e. how many alists + * there are. + * + * If we are in pass 2, do a lookup of the resource. */ void store_alist_res(LEX *lc, RES_ITEM *item, int index, int pass) { @@ -636,7 +636,37 @@ void store_alist_str(LEX *lc, RES_ITEM *item, int index, int pass) lex_get_token(lc, T_STRING); /* scan next item */ Dmsg4(900, "Append %s to alist %p size=%d %s\n", - lc->str, list, list->size(), item->name); + lc->str, list, list->size(), item->name); + list->append(bstrdup(lc->str)); + *(item->value) = (char *)list; + } + scan_to_eol(lc); + set_bit(index, res_all.hdr.item_present); +} + +/* + * Store a directory name at specified address in an alist. + * Note, we do shell expansion except if the string begins + * with a vertical bar (i.e. it will likely be passed to the + * shell later). + */ +void store_alist_dir(LEX *lc, RES_ITEM *item, int index, int pass) +{ + alist *list; + + if (pass == 2) { + if (*(item->value) == NULL) { + list = New(alist(10, owned_by_alist)); + } else { + list = (alist *)(*(item->value)); + } + + lex_get_token(lc, T_STRING); /* scan next item */ + Dmsg4(900, "Append %s to alist %p size=%d %s\n", + lc->str, list, list->size(), item->name); + if (lc->str[0] != '|') { + do_shell_expansion(lc->str, sizeof(lc->str)); + } list->append(bstrdup(lc->str)); *(item->value) = (char *)list; } diff --git a/src/lib/parse_conf.h b/src/lib/parse_conf.h index fd361fe2e77..307adf5094a 100644 --- a/src/lib/parse_conf.h +++ b/src/lib/parse_conf.h @@ -232,6 +232,7 @@ void store_strname(LEX *lc, RES_ITEM *item, int index, int pass); void store_res(LEX *lc, RES_ITEM *item, int index, int pass); void store_alist_res(LEX *lc, RES_ITEM *item, int index, int pass); void store_alist_str(LEX *lc, RES_ITEM *item, int index, int pass); +void store_alist_dir(LEX *lc, RES_ITEM *item, int index, int pass); void store_int32(LEX *lc, RES_ITEM *item, int index, int pass); void store_pint32(LEX *lc, RES_ITEM *item, int index, int pass); void store_msgs(LEX *lc, RES_ITEM *item, int index, int pass);