return tmpattr;
}
-static int compare_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device, struct sysfs_pair *pair)
+static int compare_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device, struct key_pair *pair)
{
struct sysfs_attribute *tmpattr;
int i;
int len;
- if ((pair == NULL) || (pair->file[0] == '\0') || (pair->value == '\0'))
+ if ((pair == NULL) || (pair->name[0] == '\0') || (pair->value == '\0'))
return -ENODEV;
- tmpattr = find_sysfs_attribute(class_dev, sysfs_device, pair->file);
+ tmpattr = find_sysfs_attribute(class_dev, sysfs_device, pair->name);
if (tmpattr == NULL)
return -ENODEV;
}
dbg("compare attribute '%s' value '%s' with '%s'",
- pair->file, tmpattr->value, pair->value);
+ pair->name, tmpattr->value, pair->value);
if (strcmp_pattern(pair->value, tmpattr->value) != 0)
return -ENODEV;
dbg("found matching attribute '%s' with value '%s'",
- pair->file, pair->value);
- return 0;
-}
-
-static int match_sysfs_pairs(struct udev_rule *rule, struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
-{
- struct sysfs_pair *pair;
- int i;
-
- for (i = 0; i < MAX_SYSFS_PAIRS; ++i) {
- pair = &rule->sysfs_pair[i];
- if ((pair->file[0] == '\0') || (pair->value[0] == '\0'))
- break;
- if (compare_sysfs_attribute(class_dev, sysfs_device, pair) != 0) {
- dbg("sysfs pair #%u does not match", i);
- if (pair->operation != KEY_OP_NOMATCH)
- return -1;
- } else {
- dbg("sysfs pair #%u matches", i);
- if (pair->operation == KEY_OP_NOMATCH)
- return -1;
- }
- }
-
- return 0;
-}
-
-static int match_id(struct udev_rule *rule, struct sysfs_device *sysfs_device)
-{
- char path[PATH_SIZE];
- char *temp;
-
- strlcpy(path, sysfs_device->path, sizeof(path));
- temp = strrchr(path, '/');
- temp++;
- dbg("search '%s' in '%s', path='%s'", rule->id, temp, path);
- if (strcmp_pattern(rule->id, temp) != 0)
- return -ENODEV;
-
+ pair->name, pair->value);
return 0;
}
dbg(KEY_SUBSYSTEM " key is true");
}
+ if (rule->env_pair_count) {
+ int i;
+
+ dbg("check for " KEY_ENV " pairs");
+ for (i = 0; i < rule->env_pair_count; i++) {
+ struct key_pair *pair;
+ const char *value;
+
+ pair = &rule->env_pair[i];
+ value = getenv(pair->name);
+ if (!value) {
+ dbg(KEY_ENV "{'%s'} is not found", pair->name);
+ goto exit;
+ }
+ if (strcmp_pattern(pair->value, value) != 0) {
+ dbg(KEY_ENV "{'%s'} is not matching", pair->name);
+ if (pair->operation != KEY_OP_NOMATCH)
+ goto exit;
+ } else {
+ dbg(KEY_ENV "{'%s'} matches", pair->name);
+ if (pair->operation == KEY_OP_NOMATCH)
+ goto exit;
+ }
+ }
+ dbg(KEY_ENV " key is true");
+ }
+
/* walk up the chain of physical devices and find a match */
while (1) {
/* check for matching driver */
goto try_parent;
}
dbg("check " KEY_ID);
- if (match_id(rule, sysfs_device) != 0) {
+ if (strcmp_pattern(rule->id, sysfs_device->bus_id) != 0) {
dbg(KEY_ID " is not matching");
if (rule->id_operation != KEY_OP_NOMATCH)
goto try_parent;
}
/* check for matching sysfs pairs */
- if (rule->sysfs_pair[0].file[0] != '\0') {
+ if (rule->sysfs_pair_count) {
+ int i;
+
dbg("check " KEY_SYSFS " pairs");
- if (match_sysfs_pairs(rule, class_dev, sysfs_device) != 0) {
- dbg(KEY_SYSFS " is not matching");
- goto try_parent;
+ for (i = 0; i < rule->sysfs_pair_count; i++) {
+ struct key_pair *pair;
+
+ pair = &rule->sysfs_pair[i];
+ if (compare_sysfs_attribute(class_dev, sysfs_device, pair) != 0) {
+ dbg(KEY_SYSFS "{'%s'} is not matching", pair->name);
+ if (pair->operation != KEY_OP_NOMATCH)
+ goto try_parent;
+ } else {
+ dbg(KEY_SYSFS "{'%s'} matches", pair->name);
+ if (pair->operation == KEY_OP_NOMATCH)
+ goto try_parent;
+ }
}
dbg(KEY_SYSFS " keys are true");
}