Skip to content

Commit

Permalink
Implement a store_alist_dir function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 3fd37c5 commit a4bb497
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/filed/filed_conf.c
Expand Up @@ -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 },
Expand All @@ -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 }
};
Expand All @@ -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 }
};
Expand Down
44 changes: 37 additions & 7 deletions src/lib/parse_conf.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/parse_conf.h
Expand Up @@ -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);
Expand Down

0 comments on commit a4bb497

Please sign in to comment.