chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update Fedora rules
[elogind.git]
/
udev_rules_parse.c
diff --git
a/udev_rules_parse.c
b/udev_rules_parse.c
index b664b983fb57a34661de4885a3f2d389f5d540a6..91cc9744fb6cb044e643a62906dbbd9cd628395b 100644
(file)
--- a/
udev_rules_parse.c
+++ b/
udev_rules_parse.c
@@
-28,10
+28,7
@@
#include <sys/stat.h>
#include <errno.h>
#include <sys/stat.h>
#include <errno.h>
-#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev.h"
-#include "udev_utils.h"
-#include "logging.h"
#include "udev_rules.h"
#include "udev_rules.h"
@@
-238,7
+235,7
@@
static int add_rule_key_pair(struct udev_rule *rule, struct key_pairs *pairs,
return 0;
}
return 0;
}
-static int add_to_rules(struct udev_rules *rules, char *line)
+static int add_to_rules(struct udev_rules *rules, char *line
, const char *filename, unsigned int lineno
)
{
struct udev_rule *rule;
size_t rule_size;
{
struct udev_rule *rule;
size_t rule_size;
@@
-279,42
+276,77
@@
static int add_to_rules(struct udev_rules *rules, char *line)
}
if (strcasecmp(key, "KERNEL") == 0) {
}
if (strcasecmp(key, "KERNEL") == 0) {
+ if (operation != KEY_OP_MATCH &&
+ operation != KEY_OP_NOMATCH) {
+ err("invalid KERNEL operation");
+ goto invalid;
+ }
add_rule_key(rule, &rule->kernel_name, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "SUBSYSTEM") == 0) {
add_rule_key(rule, &rule->kernel_name, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "SUBSYSTEM") == 0) {
+ if (operation != KEY_OP_MATCH &&
+ operation != KEY_OP_NOMATCH) {
+ err("invalid SUBSYSTEM operation");
+ goto invalid;
+ }
add_rule_key(rule, &rule->subsystem, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "ACTION") == 0) {
add_rule_key(rule, &rule->subsystem, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "ACTION") == 0) {
+ if (operation != KEY_OP_MATCH &&
+ operation != KEY_OP_NOMATCH) {
+ err("invalid ACTION operation");
+ goto invalid;
+ }
add_rule_key(rule, &rule->action, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "DEVPATH") == 0) {
add_rule_key(rule, &rule->action, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "DEVPATH") == 0) {
+ if (operation != KEY_OP_MATCH &&
+ operation != KEY_OP_NOMATCH) {
+ err("invalid DEVPATH operation");
+ goto invalid;
+ }
add_rule_key(rule, &rule->devpath, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "BUS") == 0) {
add_rule_key(rule, &rule->devpath, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "BUS") == 0) {
+ if (operation != KEY_OP_MATCH &&
+ operation != KEY_OP_NOMATCH) {
+ err("invalid BUS operation");
+ goto invalid;
+ }
add_rule_key(rule, &rule->bus, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "ID") == 0) {
add_rule_key(rule, &rule->bus, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "ID") == 0) {
+ if (operation != KEY_OP_MATCH &&
+ operation != KEY_OP_NOMATCH) {
+ err("invalid ID operation");
+ goto invalid;
+ }
add_rule_key(rule, &rule->id, operation, value);
valid = 1;
continue;
}
if (strncasecmp(key, "SYSFS", sizeof("SYSFS")-1) == 0) {
add_rule_key(rule, &rule->id, operation, value);
valid = 1;
continue;
}
if (strncasecmp(key, "SYSFS", sizeof("SYSFS")-1) == 0) {
+ if (operation != KEY_OP_MATCH &&
+ operation != KEY_OP_NOMATCH) {
+ err("invalid SYSFS operation");
+ goto invalid;
+ }
attr = get_key_attribute(key + sizeof("SYSFS")-1);
if (attr == NULL) {
err("error parsing SYSFS attribute in '%s'", line);
attr = get_key_attribute(key + sizeof("SYSFS")-1);
if (attr == NULL) {
err("error parsing SYSFS attribute in '%s'", line);
@@
-369,6
+401,16
@@
static int add_to_rules(struct udev_rules *rules, char *line)
pos = strchr(file, ' ');
if (pos)
pos[0] = '\0';
pos = strchr(file, ' ');
if (pos)
pos[0] = '\0';
+
+ /* allow programs in /lib/udev called without the path */
+ if (strchr(file, '/') == NULL) {
+ strlcpy(file, "/lib/udev/", sizeof(file));
+ strlcat(file, value, sizeof(file));
+ pos = strchr(file, ' ');
+ if (pos)
+ pos[0] = '\0';
+ }
+
dbg("IMPORT auto mode for '%s'", file);
if (!lstat(file, &stats) && (stats.st_mode & S_IXUSR)) {
dbg("IMPORT is executable, will be executed (autotype)");
dbg("IMPORT auto mode for '%s'", file);
if (!lstat(file, &stats) && (stats.st_mode & S_IXUSR)) {
dbg("IMPORT is executable, will be executed (autotype)");
@@
-384,12
+426,22
@@
static int add_to_rules(struct udev_rules *rules, char *line)
}
if (strcasecmp(key, "DRIVER") == 0) {
}
if (strcasecmp(key, "DRIVER") == 0) {
+ if (operation != KEY_OP_MATCH &&
+ operation != KEY_OP_NOMATCH) {
+ err("invalid DRIVER operation");
+ goto invalid;
+ }
add_rule_key(rule, &rule->driver, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "RESULT") == 0) {
add_rule_key(rule, &rule->driver, operation, value);
valid = 1;
continue;
}
if (strcasecmp(key, "RESULT") == 0) {
+ if (operation != KEY_OP_MATCH &&
+ operation != KEY_OP_NOMATCH) {
+ err("invalid RESULT operation");
+ goto invalid;
+ }
add_rule_key(rule, &rule->result, operation, value);
valid = 1;
continue;
add_rule_key(rule, &rule->result, operation, value);
valid = 1;
continue;
@@
-414,7
+466,7
@@
static int add_to_rules(struct udev_rules *rules, char *line)
}
}
if (value[0] == '\0')
}
}
if (value[0] == '\0')
- dbg("name empty, no
t
creation supressed");
+ dbg("name empty, no
de
creation supressed");
add_rule_key(rule, &rule->name, operation, value);
continue;
}
add_rule_key(rule, &rule->name, operation, value);
continue;
}
@@
-497,14
+549,12
@@
static int add_to_rules(struct udev_rules *rules, char *line)
continue;
}
continue;
}
- err("unknown key '%s'
, in '%s'", key, line
);
+ err("unknown key '%s'
", key
);
}
/* skip line if not any valid key was found */
}
/* skip line if not any valid key was found */
- if (!valid) {
- err("invalid rule '%s'", line);
- goto exit;
- }
+ if (!valid)
+ goto invalid;
/* grow buffer and add rule */
rule_size = sizeof(struct udev_rule) + rule->bufsize;
/* grow buffer and add rule */
rule_size = sizeof(struct udev_rule) + rule->bufsize;
@@
-524,13
+574,18
@@
static int add_to_rules(struct udev_rules *rules, char *line)
exit:
free(rule);
return 0;
exit:
free(rule);
return 0;
+
+invalid:
+ free(rule);
+ err("invalid rule '%s:%u'", filename, lineno);
+ return -1;
}
static int parse_file(struct udev_rules *rules, const char *filename)
{
char line[LINE_SIZE];
char *bufline;
}
static int parse_file(struct udev_rules *rules, const char *filename)
{
char line[LINE_SIZE];
char *bufline;
- int lineno;
+
unsigned
int lineno;
char *buf;
size_t bufsize;
size_t cur;
char *buf;
size_t bufsize;
size_t cur;
@@
-555,7
+610,7
@@
static int parse_file(struct udev_rules *rules, const char *filename)
lineno++;
if (count >= sizeof(line)) {
lineno++;
if (count >= sizeof(line)) {
-
info("line too long, rule skipped %s, line %d
", filename, lineno);
+
err("line too long, rule skipped '%s:%u'
", filename, lineno);
continue;
}
continue;
}
@@
-581,7
+636,7
@@
static int parse_file(struct udev_rules *rules, const char *filename)
line[j] = '\0';
dbg("read '%s'", line);
line[j] = '\0';
dbg("read '%s'", line);
- add_to_rules(rules, line);
+ add_to_rules(rules, line
, filename, lineno
);
}
file_unmap(buf, bufsize);
}
file_unmap(buf, bufsize);
@@
-617,7
+672,7
@@
int udev_rules_init(struct udev_rules *rules, int resolve_names)
else
dbg("empty rules file '%s'", name_loop->name);
} else
else
dbg("empty rules file '%s'", name_loop->name);
} else
-
dbg("could not read '%s'", name_loop->name
);
+
err("could not read '%s': %s", name_loop->name, strerror(errno)
);
list_del(&name_loop->node);
free(name_loop);
}
list_del(&name_loop->node);
free(name_loop);
}
@@
-626,7
+681,7
@@
int udev_rules_init(struct udev_rules *rules, int resolve_names)
return retval;
}
return retval;
}
-void udev_rules_cl
ose
(struct udev_rules *rules)
+void udev_rules_cl
eanup
(struct udev_rules *rules)
{
if (rules->buf) {
free(rules->buf);
{
if (rules->buf) {
free(rules->buf);