Skip to content

Commit 9d96604

Browse files
committed
Log: libcrmcommon: Set config warnings and errors for acl_permission
An acl_permission element's ID is currently used only for logging. So we can be permissive and allow this. It seems that our usual approach to things that the schema doesn't allow is to continue processing them if it's possible (for example, if it doesn't result in a broken reference). So warn here. For missing or invalid "kind" attribute, we have to ignore the element, so set a config error. It doesn't look as if we're very consistent about when we set warnings vs. errors, so I'm just doing what feels like it makes the most sense. We could just as well call all of these warnings or call all of these errors. Also, log the parent type and ID parenthetically for errors other than missing ID. If we proceeded with unpacking an acl_permission element without an ID, we want any further log messages to have some identifying information about where or what the acl_permission element is. It doesn't hurt to log this even if the acl_permission's ID is set. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent 0fc264b commit 9d96604

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

lib/common/acl.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,42 @@ create_acl(const xmlNode *xml, GList *acls, enum pcmk__xml_flags mode)
146146
static GList *
147147
unpack_acl_permission(const xmlNode *xml, GList *acls)
148148
{
149-
// ID unset is not possible with schema validation enabled
150-
const char *id = pcmk__s(pcmk__xe_id(xml), "(no ID)");
149+
const char *id = pcmk__xe_id(xml);
151150
const char *type = (const char *) xml->name;
151+
const char *parent_id = pcmk__s(pcmk__xe_id(xml->parent), "without ID");
152+
const char *parent_type = (const char *) xml->parent->name;
153+
152154
const char *kind_s = pcmk__xe_get(xml, PCMK_XA_KIND);
153155
enum pcmk__xml_flags kind = pcmk__xf_none;
154156

157+
if (id == NULL) {
158+
// Not possible with schema validation enabled
159+
pcmk__config_warn("<%s> element in <%s> %s has no " PCMK_XA_ID " "
160+
"attribute", type, parent_type, parent_id);
161+
162+
// Set a value to use for logging and continue unpacking
163+
id = "without ID";
164+
}
165+
155166
if (kind_s == NULL) {
156167
// Not possible with schema validation enabled
157-
pcmk__warn("Ignoring <%s> element %s with no " PCMK_XA_KIND " "
158-
"attribute", type, id);
168+
pcmk__config_err("Ignoring <%s> element %s (in <%s> %s) with no "
169+
PCMK_XA_KIND " attribute", type, id, parent_type,
170+
parent_id);
159171
return acls;
160172
}
161173

162174
kind = parse_acl_mode(kind_s);
163175
if (kind == pcmk__xf_none) {
164-
pcmk__warn("Ignoring <%s> element %s with unknown ACL kind '%s'", type,
165-
id, kind_s);
176+
// Not possible with schema validation enabled
177+
pcmk__config_err("Ignoring <%s> element %s (in <%s> %s) with unknown "
178+
"ACL kind '%s'", type, id, parent_type, parent_id,
179+
kind_s);
166180
return acls;
167181
}
168182

169-
pcmk__trace("Unpacking <%s> element %s with " PCMK_XA_KIND "='%s'", type,
170-
id, kind_s);
183+
pcmk__trace("Unpacking <%s> element %s (in <%s> %s) with "
184+
PCMK_XA_KIND "='%s'", type, id, parent_type, parent_id, kind_s);
171185

172186
return create_acl(xml, acls, kind);
173187
}

0 commit comments

Comments
 (0)