udev_device->is_initialized = true;
}
+static bool is_valid_tag(const char *tag)
+{
+ return !strchr(tag, ':') && !strchr(tag, ' ');
+}
+
int udev_device_add_tag(struct udev_device *udev_device, const char *tag)
{
- if (strchr(tag, ':') != NULL || strchr(tag, ' ') != NULL)
+ if (!is_valid_tag(tag))
return -EINVAL;
udev_device->tags_uptodate = false;
if (udev_list_entry_add(&udev_device->tags_list, tag, NULL) != NULL)
return -ENOMEM;
}
+void udev_device_remove_tag(struct udev_device *udev_device, const char *tag)
+{
+ struct udev_list_entry *e;
+
+ if (!is_valid_tag(tag))
+ return;
+ e = udev_list_get_entry(&udev_device->tags_list);
+ e = udev_list_entry_get_by_name(e, tag);
+ if (e) {
+ udev_device->tags_uptodate = false;
+ udev_list_entry_delete(e);
+ }
+}
+
void udev_device_cleanup_tags_list(struct udev_device *udev_device)
{
udev_device->tags_uptodate = false;
return strbuf_add_string(rules->strbuf, s, strlen(s));
}
-/* KEY=="", KEY!="", KEY+="", KEY="", KEY:="" */
+/* KEY=="", KEY!="", KEY+="", KEY-="", KEY="", KEY:="" */
enum operation_type {
OP_UNSET,
OP_MATCH_MAX,
OP_ADD,
+ OP_REMOVE,
OP_ASSIGN,
OP_ASSIGN_FINAL,
};
[OP_MATCH_MAX] = "MATCH_MAX",
[OP_ADD] = "add",
+ [OP_REMOVE] = "remove",
[OP_ASSIGN] = "assign",
[OP_ASSIGN_FINAL] = "assign-final",
} ;
break;
if (linepos[0] == '=')
break;
- if ((linepos[0] == '+') || (linepos[0] == '!') || (linepos[0] == ':'))
+ if ((linepos[0] == '+') || (linepos[0] == '-') || (linepos[0] == '!') || (linepos[0] == ':'))
if (linepos[1] == '=')
break;
}
} else if (linepos[0] == '+' && linepos[1] == '=') {
*op = OP_ADD;
linepos += 2;
+ } else if (linepos[0] == '-' && linepos[1] == '=') {
+ *op = OP_REMOVE;
+ linepos += 2;
} else if (linepos[0] == '=') {
*op = OP_ASSIGN;
linepos++;
log_error("error parsing ATTR attribute");
goto invalid;
}
+ if (op == OP_REMOVE) {
+ log_error("invalid ATTR operation");
+ goto invalid;
+ }
if (op < OP_MATCH_MAX) {
rule_add_key(&rule_tmp, TK_M_ATTR, op, value, attr);
} else {
log_error("error parsing SECLABEL attribute");
goto invalid;
}
+ if (op == OP_REMOVE) {
+ log_error("invalid SECLABEL operation");
+ goto invalid;
+ }
rule_add_key(&rule_tmp, TK_A_SECLABEL, op, value, attr);
continue;
log_error("error parsing ENV attribute");
goto invalid;
}
+ if (op == OP_REMOVE) {
+ log_error("invalid ENV operation");
+ goto invalid;
+ }
if (op < OP_MATCH_MAX) {
if (rule_add_key(&rule_tmp, TK_M_ENV, op, value, attr) != 0)
goto invalid;
}
if (streq(key, "PROGRAM")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid PROGRAM operation");
+ goto invalid;
+ }
rule_add_key(&rule_tmp, TK_M_PROGRAM, op, value, NULL);
continue;
}
log_error("IMPORT{} type missing, ignoring IMPORT %s:%u", filename, lineno);
continue;
}
+ if (op == OP_REMOVE) {
+ log_error("invalid IMPORT operation");
+ goto invalid;
+ }
if (streq(attr, "program")) {
/* find known built-in command */
if (value[0] != '/') {
attr = get_key_attribute(rules->udev, key + strlen("RUN"));
if (attr == NULL)
attr = "program";
+ if (op == OP_REMOVE) {
+ log_error("invalid RUN operation");
+ goto invalid;
+ }
if (streq(attr, "builtin")) {
enum udev_builtin_cmd cmd = udev_builtin_lookup(value);
}
if (streq(key, "WAIT_FOR") || streq(key, "WAIT_FOR_SYSFS")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid WAIT_FOR/WAIT_FOR_SYSFS operation");
+ goto invalid;
+ }
rule_add_key(&rule_tmp, TK_M_WAITFOR, 0, value, NULL);
continue;
}
if (streq(key, "LABEL")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid LABEL operation");
+ goto invalid;
+ }
rule_tmp.rule.rule.label_off = rules_add_string(rules, value);
continue;
}
if (streq(key, "GOTO")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid GOTO operation");
+ goto invalid;
+ }
rule_add_key(&rule_tmp, TK_A_GOTO, 0, value, NULL);
continue;
}
if (startswith(key, "NAME")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid NAME operation");
+ goto invalid;
+ }
if (op < OP_MATCH_MAX) {
rule_add_key(&rule_tmp, TK_M_NAME, op, value, NULL);
} else {
}
if (streq(key, "SYMLINK")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid SYMLINK operation");
+ goto invalid;
+ }
if (op < OP_MATCH_MAX)
rule_add_key(&rule_tmp, TK_M_DEVLINK, op, value, NULL);
else
uid_t uid;
char *endptr;
+ if (op == OP_REMOVE) {
+ log_error("invalid OWNER operation");
+ goto invalid;
+ }
+
uid = strtoul(value, &endptr, 10);
if (endptr[0] == '\0') {
rule_add_key(&rule_tmp, TK_A_OWNER_ID, op, NULL, &uid);
gid_t gid;
char *endptr;
+ if (op == OP_REMOVE) {
+ log_error("invalid GROUP operation");
+ goto invalid;
+ }
+
gid = strtoul(value, &endptr, 10);
if (endptr[0] == '\0') {
rule_add_key(&rule_tmp, TK_A_GROUP_ID, op, NULL, &gid);
mode_t mode;
char *endptr;
+ if (op == OP_REMOVE) {
+ log_error("invalid MODE operation");
+ goto invalid;
+ }
+
mode = strtol(value, &endptr, 8);
if (endptr[0] == '\0')
rule_add_key(&rule_tmp, TK_A_MODE_ID, op, NULL, &mode);
if (streq(key, "OPTIONS")) {
const char *pos;
+ if (op == OP_REMOVE) {
+ log_error("invalid OPTIONS operation");
+ goto invalid;
+ }
+
pos = strstr(value, "link_priority=");
if (pos != NULL) {
int prio = atoi(&pos[strlen("link_priority=")]);
log_error("ignoring invalid tag name '%s'", tag);
break;
}
- udev_device_add_tag(event->dev, tag);
+ if (cur->key.op == OP_REMOVE)
+ udev_device_remove_tag(event->dev, tag);
+ else
+ udev_device_add_tag(event->dev, tag);
break;
}
case TK_A_NAME: {