udev-rules.c revision 9ec6e95b046de71c0198cb9d17acc5462dc76c74
/*
* Copyright (C) 2003-2012 Kay Sievers <kay@vrfy.org>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stddef.h>
#include <limits.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <dirent.h>
#include <fnmatch.h>
#include <time.h>
#include "udev.h"
#include "path-util.h"
#include "conf-files.h"
#include "strbuf.h"
#include "strv.h"
#include "util.h"
#define PREALLOC_TOKEN 2048
struct uid_gid {
unsigned int name_off;
union {
};
};
static const char* const rules_dirs[] = {
UDEVLIBEXECDIR "/rules.d",
NULL};
struct udev_rules {
int resolve_names;
/* every key in the rules file becomes a token */
unsigned int token_cur;
unsigned int token_max;
/* all key strings are copied and de-duplicated in a single continuous string buffer */
unsigned int uids_cur;
unsigned int uids_max;
unsigned int gids_cur;
unsigned int gids_max;
};
}
}
/* KEY=="", KEY!="", KEY+="", KEY="", KEY:="" */
enum operation_type {
};
enum string_glob_type {
GL_PLAIN, /* no special chars */
GL_GLOB, /* shell globs ?,*,[] */
GL_SPLIT, /* multi-value A|B */
GL_SPLIT_GLOB, /* multi-value with glob A*|B* */
GL_SOMETHING, /* commonly used "?*" */
};
enum string_subst_type {
};
enum token_type {
TK_M_ACTION, /* val */
TK_M_DEVPATH, /* val */
TK_M_KERNEL, /* val */
TK_M_DEVLINK, /* val */
TK_M_NAME, /* val */
TK_M_ENV, /* val, attr */
TK_M_TAG, /* val */
TK_M_SUBSYSTEM, /* val */
TK_M_DRIVER, /* val */
TK_M_WAITFOR, /* val */
TK_M_ATTR, /* val, attr */
TK_M_KERNELS, /* val */
TK_M_SUBSYSTEMS, /* val */
TK_M_DRIVERS, /* val */
TK_M_ATTRS, /* val, attr */
TK_M_TAGS, /* val */
TK_M_TEST, /* val, mode_t */
TK_M_PROGRAM, /* val */
TK_M_IMPORT_FILE, /* val */
TK_M_IMPORT_PROG, /* val */
TK_M_IMPORT_BUILTIN, /* val */
TK_M_IMPORT_DB, /* val */
TK_M_IMPORT_CMDLINE, /* val */
TK_M_IMPORT_PARENT, /* val */
TK_M_RESULT, /* val */
TK_A_INOTIFY_WATCH, /* int */
TK_A_DEVLINK_PRIO, /* int */
TK_A_OWNER, /* val */
TK_A_GROUP, /* val */
TK_A_MODE, /* val */
TK_A_OWNER_ID, /* uid_t */
TK_A_GROUP_ID, /* gid_t */
TK_A_MODE_ID, /* mode_t */
TK_A_TAG, /* val */
TK_A_STATIC_NODE, /* val */
TK_A_SECLABEL, /* val, attr */
TK_A_ENV, /* val, attr */
TK_A_NAME, /* val */
TK_A_DEVLINK, /* val */
TK_A_ATTR, /* val, attr */
TK_A_RUN_BUILTIN, /* val, bool */
TK_A_RUN_PROGRAM, /* val, bool */
TK_A_GOTO, /* size_t */
};
/* we try to pack stuff in a way that we take only 12 bytes per token */
struct token {
union {
unsigned char type; /* same in rule and key */
struct {
bool can_set_name:1;
bool has_static_node:1;
unsigned int unused:6;
unsigned short token_count;
unsigned int label_off;
unsigned short filename_off;
unsigned short filename_line;
} rule;
struct {
unsigned int value_off;
union {
unsigned int attr_off;
unsigned int rule_goto;
int devlink_prio;
int watch;
enum udev_builtin_cmd builtin_cmd;
};
} key;
};
};
#define MAX_TK 64
struct rule_tmp {
struct udev_rules *rules;
unsigned int token_cur;
};
#ifdef DEBUG
static const char *operation_strs[] = {
[OP_UNSET] = "UNSET",
[OP_MATCH] = "match",
[OP_NOMATCH] = "nomatch",
[OP_MATCH_MAX] = "MATCH_MAX",
[OP_ADD] = "add",
[OP_ASSIGN] = "assign",
[OP_ASSIGN_FINAL] = "assign-final",
} ;
return operation_strs[type];
}
static const char *string_glob_strs[] = {
[GL_UNSET] = "UNSET",
[GL_PLAIN] = "plain",
[GL_GLOB] = "glob",
[GL_SPLIT] = "split",
[GL_SPLIT_GLOB] = "split-glob",
[GL_SOMETHING] = "split-glob",
};
return string_glob_strs[type];
}
static const char *token_strs[] = {
[TK_UNSET] = "UNSET",
[TK_RULE] = "RULE",
[TK_M_ACTION] = "M ACTION",
[TK_M_DEVPATH] = "M DEVPATH",
[TK_M_KERNEL] = "M KERNEL",
[TK_M_DEVLINK] = "M DEVLINK",
[TK_M_NAME] = "M NAME",
[TK_M_ENV] = "M ENV",
[TK_M_TAG] = "M TAG",
[TK_M_SUBSYSTEM] = "M SUBSYSTEM",
[TK_M_DRIVER] = "M DRIVER",
[TK_M_WAITFOR] = "M WAITFOR",
[TK_M_ATTR] = "M ATTR",
[TK_M_PARENTS_MIN] = "M PARENTS_MIN",
[TK_M_KERNELS] = "M KERNELS",
[TK_M_SUBSYSTEMS] = "M SUBSYSTEMS",
[TK_M_DRIVERS] = "M DRIVERS",
[TK_M_ATTRS] = "M ATTRS",
[TK_M_TAGS] = "M TAGS",
[TK_M_PARENTS_MAX] = "M PARENTS_MAX",
[TK_M_TEST] = "M TEST",
[TK_M_PROGRAM] = "M PROGRAM",
[TK_M_IMPORT_FILE] = "M IMPORT_FILE",
[TK_M_IMPORT_PROG] = "M IMPORT_PROG",
[TK_M_IMPORT_BUILTIN] = "M IMPORT_BUILTIN",
[TK_M_IMPORT_DB] = "M IMPORT_DB",
[TK_M_IMPORT_CMDLINE] = "M IMPORT_CMDLINE",
[TK_M_IMPORT_PARENT] = "M IMPORT_PARENT",
[TK_M_RESULT] = "M RESULT",
[TK_M_MAX] = "M MAX",
[TK_A_STRING_ESCAPE_NONE] = "A STRING_ESCAPE_NONE",
[TK_A_STRING_ESCAPE_REPLACE] = "A STRING_ESCAPE_REPLACE",
[TK_A_DB_PERSIST] = "A DB_PERSIST",
[TK_A_INOTIFY_WATCH] = "A INOTIFY_WATCH",
[TK_A_DEVLINK_PRIO] = "A DEVLINK_PRIO",
[TK_A_OWNER] = "A OWNER",
[TK_A_GROUP] = "A GROUP",
[TK_A_MODE] = "A MODE",
[TK_A_OWNER_ID] = "A OWNER_ID",
[TK_A_GROUP_ID] = "A GROUP_ID",
[TK_A_STATIC_NODE] = "A STATIC_NODE",
[TK_A_SECLABEL] = "A SECLABEL",
[TK_A_MODE_ID] = "A MODE_ID",
[TK_A_ENV] = "A ENV",
[TK_A_TAG] = "A ENV",
[TK_A_NAME] = "A NAME",
[TK_A_DEVLINK] = "A DEVLINK",
[TK_A_ATTR] = "A ATTR",
[TK_A_RUN_BUILTIN] = "A RUN_BUILTIN",
[TK_A_RUN_PROGRAM] = "A RUN_PROGRAM",
[TK_A_GOTO] = "A GOTO",
[TK_END] = "END",
};
return token_strs[type];
}
switch (type) {
case TK_RULE:
{
log_debug("* RULE %s:%u, token: %u, count: %u, label: '%s'",
break;
}
case TK_M_ACTION:
case TK_M_DEVPATH:
case TK_M_KERNEL:
case TK_M_SUBSYSTEM:
case TK_M_DRIVER:
case TK_M_WAITFOR:
case TK_M_DEVLINK:
case TK_M_NAME:
case TK_M_KERNELS:
case TK_M_SUBSYSTEMS:
case TK_M_DRIVERS:
case TK_M_TAGS:
case TK_M_PROGRAM:
case TK_M_IMPORT_FILE:
case TK_M_IMPORT_PROG:
case TK_M_IMPORT_DB:
case TK_M_IMPORT_CMDLINE:
case TK_M_IMPORT_PARENT:
case TK_M_RESULT:
case TK_A_NAME:
case TK_A_DEVLINK:
case TK_A_OWNER:
case TK_A_GROUP:
case TK_A_MODE:
case TK_A_RUN_BUILTIN:
case TK_A_RUN_PROGRAM:
log_debug("%s %s '%s'(%s)",
break;
case TK_M_IMPORT_BUILTIN:
break;
case TK_M_ATTR:
case TK_M_ATTRS:
case TK_M_ENV:
case TK_A_ATTR:
case TK_A_ENV:
log_debug("%s %s '%s' '%s'(%s)",
break;
case TK_M_TAG:
case TK_A_TAG:
break;
case TK_A_STRING_ESCAPE_NONE:
case TK_A_DB_PERSIST:
break;
case TK_M_TEST:
log_debug("%s %s '%s'(%s) %#o",
break;
case TK_A_INOTIFY_WATCH:
break;
case TK_A_DEVLINK_PRIO:
break;
case TK_A_OWNER_ID:
break;
case TK_A_GROUP_ID:
break;
case TK_A_MODE_ID:
break;
case TK_A_STATIC_NODE:
break;
case TK_A_SECLABEL:
break;
case TK_A_GOTO:
break;
case TK_END:
break;
case TK_M_PARENTS_MIN:
case TK_M_PARENTS_MAX:
case TK_M_MAX:
case TK_UNSET:
break;
}
}
unsigned int i;
log_debug("dumping %u (%zu bytes) tokens, %u (%zu bytes) strings",
}
#else
#endif /* DEBUG */
/* grow buffer if needed */
unsigned int add;
/* double the buffer size */
if (add < 8)
add = 8;
return -1;
}
return 0;
}
unsigned int i;
unsigned int off;
/* lookup, if we know it already */
return uid;
}
}
/* grow buffer if needed */
unsigned int add;
/* double the buffer size */
if (add < 1)
add = 8;
return uid;
}
if (off <= 0)
return uid;
return uid;
}
unsigned int i;
unsigned int off;
/* lookup, if we know it already */
return gid;
}
}
/* grow buffer if needed */
unsigned int add;
/* double the buffer size */
if (add < 1)
add = 8;
return gid;
}
if (off <= 0)
return gid;
return gid;
}
char *key;
char *val;
struct udev_list_entry *entry;
/* find key */
key++;
/* comment or empty line */
return -1;
return -1;
val[0] = '\0';
val++;
/* find value */
val++;
/* terminate key */
if (len == 0)
return -1;
len--;
/* terminate value */
if (len == 0)
return -1;
len--;
if (len == 0)
return -1;
/* unquote */
return -1;
}
val++;
}
/* store in db, skip private keys */
if (key[0] != '.')
udev_list_entry_set_num(entry, true);
return 0;
}
FILE *f;
char line[UTIL_LINE_SIZE];
if (f == NULL)
return -1;
fclose(f);
return 0;
}
char **envp;
char result[UTIL_LINE_SIZE];
char *line;
int err;
if (err < 0)
return err;
char *pos;
pos[0] = '\0';
}
}
return 0;
}
struct udev_device *dev_parent;
struct udev_list_entry *list_entry;
if (dev_parent == NULL)
return -1;
struct udev_list_entry *entry;
/* store in db, skip private keys */
if (key[0] != '.')
udev_list_entry_set_num(entry, true);
}
}
return 0;
}
#define WAIT_LOOP_PER_SECOND 50
char filepath[UTIL_PATH_SIZE];
char devicepath[UTIL_PATH_SIZE];
/* a relative path is a device attribute */
devicepath[0] = '\0';
if (file[0] != '/') {
}
while (--loop) {
/* lookup file */
return 0;
}
/* make sure, the device did not disappear in the meantime */
return -2;
}
}
return -1;
}
bool found = false;
char *pos;
char dirname[UTIL_PATH_SIZE];
const char *tail;
return -1;
pos[0] = '\0';
continue;
found = true;
break;
}
}
}
}
return found;
}
static int get_key(struct udev *udev, char **line, char **key, enum operation_type *op, char **value) {
char *linepos;
char *temp;
return -1;
/* skip whitespace */
linepos++;
/* get the key */
if (linepos[0] == '\0')
return -1;
for (;;) {
linepos++;
if (linepos[0] == '\0')
return -1;
break;
if (linepos[0] == '=')
break;
break;
}
/* remember end of key */
/* skip whitespace after key */
linepos++;
if (linepos[0] == '\0')
return -1;
/* get operation type */
linepos += 2;
*op = OP_NOMATCH;
linepos += 2;
linepos += 2;
} else if (linepos[0] == '=') {
linepos++;
*op = OP_ASSIGN_FINAL;
linepos += 2;
} else
return -1;
/* terminate key */
temp[0] = '\0';
/* skip whitespace after operator */
linepos++;
if (linepos[0] == '\0')
return -1;
/* get the value */
if (linepos[0] == '"')
linepos++;
else
return -1;
/* terminate */
if (!temp)
return -1;
temp[0] = '\0';
temp++;
/* move line to next key */
return 0;
}
/* extract possible KEY{attr} */
char *pos;
char *attr;
attr++;
log_error("missing closing brace for format");
return NULL;
}
pos[0] = '\0';
return attr;
}
return NULL;
}
enum operation_type op,
switch (type) {
case TK_M_ACTION:
case TK_M_DEVPATH:
case TK_M_KERNEL:
case TK_M_SUBSYSTEM:
case TK_M_DRIVER:
case TK_M_WAITFOR:
case TK_M_DEVLINK:
case TK_M_NAME:
case TK_M_KERNELS:
case TK_M_SUBSYSTEMS:
case TK_M_DRIVERS:
case TK_M_TAGS:
case TK_M_PROGRAM:
case TK_M_IMPORT_FILE:
case TK_M_IMPORT_PROG:
case TK_M_IMPORT_DB:
case TK_M_IMPORT_CMDLINE:
case TK_M_IMPORT_PARENT:
case TK_M_RESULT:
case TK_A_OWNER:
case TK_A_GROUP:
case TK_A_MODE:
case TK_A_DEVLINK:
case TK_A_NAME:
case TK_A_GOTO:
case TK_M_TAG:
case TK_A_TAG:
case TK_A_STATIC_NODE:
break;
case TK_M_IMPORT_BUILTIN:
break;
case TK_M_ENV:
case TK_M_ATTR:
case TK_M_ATTRS:
case TK_A_ATTR:
case TK_A_ENV:
case TK_A_SECLABEL:
break;
case TK_M_TEST:
break;
case TK_A_STRING_ESCAPE_NONE:
case TK_A_DB_PERSIST:
break;
case TK_A_RUN_BUILTIN:
case TK_A_RUN_PROGRAM:
break;
case TK_A_INOTIFY_WATCH:
case TK_A_DEVLINK_PRIO:
break;
case TK_A_OWNER_ID:
break;
case TK_A_GROUP_ID:
break;
case TK_A_MODE_ID:
break;
case TK_RULE:
case TK_M_PARENTS_MIN:
case TK_M_PARENTS_MAX:
case TK_M_MAX:
case TK_END:
case TK_UNSET:
return -1;
}
/* check if we need to split or call fnmatch() while matching rules */
enum string_glob_type glob;
int has_split;
int has_glob;
} else if (has_split) {
} else if (has_glob) {
glob = GL_SOMETHING;
else
} else {
}
}
/* check if assigned value has substitution chars */
if (value[0] == '[')
else
}
if (attr[0] == '[')
else
}
log_error("temporary rule array too small");
return -1;
}
return 0;
}
unsigned int i;
unsigned int start = 0;
unsigned int next_idx = 0;
unsigned int j;
/* find smallest value */
continue;
next_idx = j;
}
}
/* add token and mark done */
return -1;
/* shrink range */
start++;
end--;
}
return 0;
}
char *linepos;
const char *attr;
/* the offset in the rule is limited to unsigned short */
if (filename_off < USHRT_MAX)
for (;;) {
char *key;
char *value;
enum operation_type op;
/* Avoid erroring on trailing whitespace. This is probably rare
* so save the work for the error case instead of always trying
* to strip the trailing whitespace with strstrip(). */
linepos++;
/* If we aren't at the end of the line, this is a parsing error.
* Make a best effort to describe where the problem is. */
if (*linepos != '\n') {
_cleanup_free_ char *tmp;
"starting at character %tu ('%s')\n",
log_error("hint: comments can only start at beginning of line");
}
break;
}
if (op > OP_MATCH_MAX) {
log_error("invalid ACTION operation");
goto invalid;
}
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid DEVPATH operation");
goto invalid;
}
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid KERNEL operation");
goto invalid;
}
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid SUBSYSTEM operation");
goto invalid;
}
/* bus, class, subsystem events should all be the same */
log_error("'%s' must be specified as 'subsystem' "
} else
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid DRIVER operation");
goto invalid;
}
continue;
}
log_error("error parsing ATTR attribute");
goto invalid;
}
if (op < OP_MATCH_MAX) {
} else {
}
continue;
}
if (!attr) {
log_error("error parsing SECLABEL attribute");
goto invalid;
}
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid KERNELS operation");
goto invalid;
}
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid SUBSYSTEMS operation");
goto invalid;
}
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid DRIVERS operation");
goto invalid;
}
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid ATTRS operation");
goto invalid;
}
log_error("error parsing ATTRS attribute");
goto invalid;
}
log_error("the 'device' link may not be available in a future kernel, "
log_error("do not reference parent sysfs directories directly, "
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid TAGS operation");
goto invalid;
}
continue;
}
log_error("error parsing ENV attribute");
goto invalid;
}
if (op < OP_MATCH_MAX) {
goto invalid;
} else {
static const char *blacklist[] = {
"ACTION",
"SUBSYSTEM",
"DEVTYPE",
"MAJOR",
"MINOR",
"DRIVER",
"IFINDEX",
"DEVNAME",
"DEVLINKS",
"DEVPATH",
"TAGS",
};
unsigned int i;
for (i = 0; i < ELEMENTSOF(blacklist); i++) {
continue;
goto invalid;
}
goto invalid;
}
continue;
}
if (op < OP_MATCH_MAX)
else
continue;
}
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid RESULT operation");
goto invalid;
}
continue;
}
continue;
}
/* find known built-in command */
if (value[0] != '/') {
enum udev_builtin_cmd cmd;
if (cmd < UDEV_BUILTIN_MAX) {
log_debug("IMPORT found builtin '%s', replacing %s:%u",
continue;
}
}
if (cmd < UDEV_BUILTIN_MAX)
else
} else
continue;
}
if (op > OP_MATCH_MAX) {
log_error("invalid TEST operation");
goto invalid;
}
} else {
}
continue;
}
attr = "program";
if (cmd < UDEV_BUILTIN_MAX)
else
} else {
}
continue;
}
continue;
}
continue;
}
continue;
}
if (op < OP_MATCH_MAX) {
} else {
log_error("NAME=\"%%k\" is ignored, because it breaks kernel supplied names, "
continue;
}
if (value[0] == '\0') {
log_debug("NAME=\"\" is ignored, because udev will not delete any device nodes, "
continue;
}
}
continue;
}
if (op < OP_MATCH_MAX)
else
continue;
}
char *endptr;
if (endptr[0] == '\0') {
} else if (rules->resolve_names >= 0) {
}
continue;
}
char *endptr;
if (endptr[0] == '\0') {
} else if (rules->resolve_names >= 0) {
}
continue;
}
char *endptr;
if (endptr[0] == '\0')
else
continue;
}
const char *pos;
}
}
const int off = 0;
} else {
const int on = 1;
}
}
}
continue;
}
goto invalid;
}
/* add rule token */
goto invalid;
/* add tokens to list, sorted by type */
goto invalid;
return 0;
return -1;
}
FILE *f;
unsigned int first_token;
unsigned int filename_off;
char line[UTIL_LINE_SIZE];
int line_nr = 0;
unsigned int i;
if (!f) {
return 0;
else
return -errno;
}
if (null_or_empty_fd(fileno(f))) {
return 0;
} else
char *key;
/* skip whitespace */
line_nr++;
key++;
/* comment */
if (key[0] == '#')
continue;
if (len < 3)
continue;
/* continue reading if backslash+newline is found */
break;
break;
line_nr++;
}
continue;
}
}
fclose(f);
/* link GOTOs to LABEL rules in this file to be able to fast-forward */
unsigned int j;
continue;
continue;
continue;
break;
}
}
}
return 0;
}
struct udev_rules *rules;
char **files, **f;
int r;
return NULL;
/* init token array and string buffer */
return udev_rules_unref(rules);
return udev_rules_unref(rules);
if (r < 0) {
return udev_rules_unref(rules);
}
/*
* The offset value in the rules strct is limited; add all
* rules file names to the beginning of the string buffer.
*/
STRV_FOREACH(f, files)
rules_add_string(rules, *f);
STRV_FOREACH(f, files)
parse_file(rules, *f);
log_debug("rules contain %zu bytes tokens (%u * %zu bytes), %zu bytes strings",
rules->token_max * sizeof(struct token), rules->token_max, sizeof(struct token), rules->strbuf->len);
/* cleanup temporary strbuf data */
log_debug("%zu strings (%zu bytes), %zu de-duplicated (%zu bytes), %zu trie nodes used",
return rules;
}
return NULL;
return NULL;
}
if (!rules)
return false;
}
char *pos;
bool match = false;
val = "";
case GL_PLAIN:
break;
case GL_GLOB:
break;
case GL_SPLIT:
{
const char *s;
for (;;) {
const char *next;
if (match)
break;
} else {
break;
}
s = &next[1];
}
break;
}
case GL_SPLIT_GLOB:
{
char value[UTIL_PATH_SIZE];
pos[0] = '\0';
}
if (match)
break;
}
break;
}
case GL_SOMETHING:
break;
case GL_UNSET:
return -1;
}
return 0;
return 0;
return -1;
}
static int match_attr(struct udev_rules *rules, struct udev_device *dev, struct udev_event *event, struct token *cur) {
const char *name;
char nbuf[UTIL_NAME_SIZE];
const char *value;
char vbuf[UTIL_NAME_SIZE];
case SB_FORMAT:
/* fall through */
case SB_NONE:
return -1;
break;
case SB_SUBSYS:
return -1;
break;
default:
return -1;
}
/* remove trailing whitespace, if not asked to match for it */
const char *key_value;
}
}
}
}
enum escape_type {
};
struct udev_event *event,
bool can_set_name;
return -1;
/* loop through token list, match, run actions or forward to next rule */
for (;;) {
case TK_RULE:
/* current rule */
/* possibly skip rules which want to set NAME, SYMLINK, OWNER, GROUP, MODE */
goto nomatch;
esc = ESCAPE_UNSET;
break;
case TK_M_ACTION:
goto nomatch;
break;
case TK_M_DEVPATH:
goto nomatch;
break;
case TK_M_KERNEL:
goto nomatch;
break;
case TK_M_DEVLINK: {
struct udev_list_entry *list_entry;
bool match = false;
const char *devlink;
match = true;
break;
}
}
if (!match)
goto nomatch;
break;
}
case TK_M_NAME:
goto nomatch;
break;
case TK_M_ENV: {
const char *value;
value = "";
goto nomatch;
break;
}
case TK_M_TAG: {
struct udev_list_entry *list_entry;
bool match = false;
match = true;
break;
}
}
goto nomatch;
break;
}
case TK_M_SUBSYSTEM:
goto nomatch;
break;
case TK_M_DRIVER:
goto nomatch;
break;
case TK_M_WAITFOR: {
char filename[UTIL_PATH_SIZE];
int found;
goto nomatch;
break;
}
case TK_M_ATTR:
goto nomatch;
break;
case TK_M_KERNELS:
case TK_M_SUBSYSTEMS:
case TK_M_DRIVERS:
case TK_M_ATTRS:
case TK_M_TAGS: {
/* get whole sequence of parent matches */
next++;
/* loop over parents */
for (;;) {
/* loop over sequence of parent match keys */
case TK_M_KERNELS:
goto try_parent;
break;
case TK_M_SUBSYSTEMS:
goto try_parent;
break;
case TK_M_DRIVERS:
goto try_parent;
break;
case TK_M_ATTRS:
goto try_parent;
break;
case TK_M_TAGS: {
goto try_parent;
goto try_parent;
break;
}
default:
goto nomatch;
}
}
break;
goto nomatch;
}
/* move behind our sequence of parent match keys */
continue;
}
case TK_M_TEST: {
char filename[UTIL_PATH_SIZE];
int match;
if (filename[0] != '/') {
char tmp[UTIL_PATH_SIZE];
}
}
goto nomatch;
goto nomatch;
break;
}
case TK_M_PROGRAM: {
char program[UTIL_PATH_SIZE];
char **envp;
char result[UTIL_LINE_SIZE];
log_debug("PROGRAM '%s' %s:%u",
goto nomatch;
} else {
int count;
if (count > 0)
}
goto nomatch;
}
break;
}
case TK_M_IMPORT_FILE: {
char import[UTIL_PATH_SIZE];
goto nomatch;
break;
}
case TK_M_IMPORT_PROG: {
char import[UTIL_PATH_SIZE];
log_debug("IMPORT '%s' %s:%u",
goto nomatch;
break;
}
case TK_M_IMPORT_BUILTIN: {
char command[UTIL_PATH_SIZE];
/* check if we ran already */
log_debug("IMPORT builtin skip '%s' %s:%u",
/* return the result from earlier run */
goto nomatch;
break;
}
/* mark as ran */
}
log_debug("IMPORT builtin '%s' %s:%u",
/* remember failure */
log_debug("IMPORT builtin '%s' returned non-zero",
goto nomatch;
}
break;
}
case TK_M_IMPORT_DB: {
const char *value;
struct udev_list_entry *entry;
udev_list_entry_set_num(entry, true);
} else {
goto nomatch;
}
break;
}
case TK_M_IMPORT_CMDLINE: {
FILE *f;
bool imported = false;
if (f != NULL) {
char cmdline[4096];
char *pos;
struct udev_list_entry *entry;
/* we import simple flags as 'FLAG=1' */
udev_list_entry_set_num(entry, true);
imported = true;
} else if (pos[0] == '=') {
const char *value;
pos++;
pos++;
pos[0] = '\0';
udev_list_entry_set_num(entry, true);
imported = true;
}
}
}
fclose(f);
}
goto nomatch;
break;
}
case TK_M_IMPORT_PARENT: {
char import[UTIL_PATH_SIZE];
goto nomatch;
break;
}
case TK_M_RESULT:
goto nomatch;
break;
case TK_A_STRING_ESCAPE_NONE:
esc = ESCAPE_NONE;
break;
break;
case TK_A_DB_PERSIST:
break;
case TK_A_INOTIFY_WATCH:
if (event->inotify_watch_final)
break;
event->inotify_watch_final = true;
break;
case TK_A_DEVLINK_PRIO:
break;
case TK_A_OWNER: {
char owner[UTIL_NAME_SIZE];
if (event->owner_final)
break;
event->owner_final = true;
log_debug("OWNER %u %s:%u",
break;
}
case TK_A_GROUP: {
char group[UTIL_NAME_SIZE];
if (event->group_final)
break;
event->group_final = true;
log_debug("GROUP %u %s:%u",
break;
}
case TK_A_MODE: {
char mode_str[UTIL_NAME_SIZE];
char *endptr;
if (event->mode_final)
break;
if (endptr[0] != '\0') {
break;
}
event->mode_final = true;
log_debug("MODE %#o %s:%u",
break;
}
case TK_A_OWNER_ID:
if (event->owner_final)
break;
event->owner_final = true;
log_debug("OWNER %u %s:%u",
break;
case TK_A_GROUP_ID:
if (event->group_final)
break;
event->group_final = true;
log_debug("GROUP %u %s:%u",
break;
case TK_A_MODE_ID:
if (event->mode_final)
break;
event->mode_final = true;
log_debug("MODE %#o %s:%u",
break;
case TK_A_SECLABEL: {
log_debug("SECLABEL{%s}='%s' %s:%u",
break;
}
case TK_A_ENV: {
char value_new[UTIL_NAME_SIZE];
struct udev_list_entry *entry;
if (value[0] == '\0') {
break;
break;
}
if (value_old) {
char temp[UTIL_NAME_SIZE];
/* append value separated by space */
} else
/* store in db, skip private keys */
if (name[0] != '.')
udev_list_entry_set_num(entry, true);
break;
}
case TK_A_TAG: {
char tag[UTIL_PATH_SIZE];
const char *p;
for (p = tag; *p != '\0'; p++) {
if ((*p >= 'a' && *p <= 'z') ||
(*p >= 'A' && *p <= 'Z') ||
(*p >= '0' && *p <= '9') ||
*p == '-' || *p == '_')
continue;
break;
}
break;
}
case TK_A_NAME: {
char name_str[UTIL_PATH_SIZE];
int count;
if (event->name_final)
break;
event->name_final = true;
if (count > 0)
}
log_error("NAME=\"%s\" ignored, kernel device nodes "
"can not be renamed; please fix it in %s:%u\n", name,
break;
}
log_debug("NAME '%s' %s:%u",
break;
}
case TK_A_DEVLINK: {
char temp[UTIL_PATH_SIZE];
char filename[UTIL_PATH_SIZE];
int count = 0;
if (event->devlink_final)
break;
break;
event->devlink_final = true;
/* allow multiple symlinks separated by spaces */
if (esc == ESCAPE_UNSET)
else if (esc == ESCAPE_REPLACE)
if (count > 0)
pos++;
next[0] = '\0';
next++;
}
if (pos[0] != '\0') {
}
break;
}
case TK_A_ATTR: {
char attr[UTIL_PATH_SIZE];
char value[UTIL_NAME_SIZE];
FILE *f;
if (f != NULL) {
fclose(f);
} else {
}
break;
}
case TK_A_RUN_BUILTIN:
case TK_A_RUN_PROGRAM: {
struct udev_list_entry *entry;
log_debug("RUN '%s' %s:%u",
break;
}
case TK_A_GOTO:
break;
continue;
case TK_END:
return 0;
case TK_M_PARENTS_MIN:
case TK_M_PARENTS_MAX:
case TK_M_MAX:
case TK_UNSET:
goto nomatch;
}
cur++;
continue;
/* fast-forward to next rule */
}
}
char **t;
int r = 0;
return 0;
for (;;) {
case TK_RULE:
/* current rule */
/* skip rules without a static_node tag */
goto next;
uid = 0;
gid = 0;
mode = 0;
break;
case TK_A_OWNER_ID:
break;
case TK_A_GROUP_ID:
break;
case TK_A_MODE_ID:
break;
case TK_A_TAG:
if (r < 0)
goto finish;
break;
case TK_A_STATIC_NODE: {
char device_node[UTIL_PATH_SIZE];
char tags_dir[UTIL_PATH_SIZE];
char tag_symlink[UTIL_PATH_SIZE];
/* we assure, that the permissions tokens are sorted before the static token */
goto next;
break;
break;
/* export the tags to a directory as symlinks, allowing otherwise dead nodes to be tagged */
if (tags) {
STRV_FOREACH(t, tags) {
if (r < 0) {
return r;
}
return -errno;
} else
r = 0;
}
}
/* don't touch the permissions if only the tags were set */
break;
if (mode == 0) {
if (gid > 0)
mode = 0660;
else
mode = 0600;
}
if (r < 0) {
return -errno;
} else
}
if (r < 0) {
return -errno;
} else
}
break;
}
case TK_END:
goto finish;
}
cur++;
continue;
next:
/* fast-forward to next rule */
continue;
}
if (f) {
fflush(f);
r = -errno;
unlink("/run/udev/static_node-tags");
}
fclose(f);
}
return r;
}