Skip to content

Commit

Permalink
core: configparser: CFG_TYPE_ALIST_STR: read all entries
Browse files Browse the repository at this point in the history
Generally, config directives in Bareos that can contain multiple values (list)
can be written in multiple lines and/or been seperated by comma (,):

Job {
  ...
  Run = run1a, run1b
  Run = run2a, run2b
  ...
}

The config types CFG_TYPE_ALIST_STR are lists.
However, before this change, directive using these types
silently ignores all characters after the first comma.

This change fix this.
  • Loading branch information
joergsteffens committed Oct 15, 2020
1 parent 0223f20 commit 32e9642
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions core/src/lib/res.cc
Original file line number Diff line number Diff line change
Expand Up @@ -760,34 +760,39 @@ void ConfigurationParser::StoreAlistStr(LEX* lc,
int index,
int pass)
{
alist** alistvalue = GetItemVariablePointer<alist**>(*item);
if (pass == 2) {
alist** alistvalue = GetItemVariablePointer<alist**>(*item);
if (!*alistvalue) { *alistvalue = new alist(10, owned_by_alist); }
alist* list = *alistvalue;
}
alist* list = *alistvalue;

int token = BCT_COMMA;
while (token == BCT_COMMA) {
LexGetToken(lc, BCT_STRING); /* scan next item */
Dmsg4(900, "Append %s to alist %p size=%d %s\n", lc->str, list,
list->size(), item->name);

/*
* See if we need to drop the default value from the alist.
*
* We first check to see if the config item has the CFG_ITEM_DEFAULT
* flag set and currently has exactly one entry.
*/
if ((item->flags & CFG_ITEM_DEFAULT) && list->size() == 1) {
char* entry;
if (pass == 2) {
Dmsg4(900, "Append %s to alist %p size=%d %s\n", lc->str, list,
list->size(), item->name);

entry = (char*)list->first();
if (bstrcmp(entry, item->default_value)) {
list->destroy();
list->init(10, owned_by_alist);
/*
* See if we need to drop the default value from the alist.
*
* We first check to see if the config item has the CFG_ITEM_DEFAULT
* flag set and currently has exactly one entry.
*/
if (!BitIsSet(index, (*item->allocated_resource)->item_present_)) {
if ((item->flags & CFG_ITEM_DEFAULT) && list->size() == 1) {
char* entry = (char*)list->first();
if (bstrcmp(entry, item->default_value)) {
list->destroy();
list->init(10, owned_by_alist);
}
}
}
list->append(strdup(lc->str));
}

list->append(strdup(lc->str));
token = LexGetToken(lc, BCT_ALL);
}
ScanToEol(lc);
SetBit(index, (*item->allocated_resource)->item_present_);
ClearBit(index, (*item->allocated_resource)->inherit_content_);
}
Expand Down

0 comments on commit 32e9642

Please sign in to comment.