udev-rules.c revision 91418155ae9034f466d436c314cd136309bc557d
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering/*
7c66aeba0f28cb82027d6015405ed71afa3b6059Kay Sievers * Copyright (C) 2003-2010 Kay Sievers <kay.sievers@vrfy.org>
7c66aeba0f28cb82027d6015405ed71afa3b6059Kay Sievers * Copyright (C) 2008 Alan Jenkins <alan-jenkins@tuffmail.co.uk>
c904f64d84db8c4eebedf210ba10893f19ba05edLennart Poettering *
c904f64d84db8c4eebedf210ba10893f19ba05edLennart Poettering * This program is free software: you can redistribute it and/or modify
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers * it under the terms of the GNU General Public License as published by
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers * the Free Software Foundation, either version 2 of the License, or
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers * (at your option) any later version.
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers *
9a36607584bbd1d78775353e022a51794b4e27b1Lennart Poettering * This program is distributed in the hope that it will be useful,
9a36607584bbd1d78775353e022a51794b4e27b1Lennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
a40593a0d0d740efa387e35411e1e456a6c5aba7Lennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20ffc4c4a9226b0e45cc02ad9c0108981626c0bbKay Sievers * GNU General Public License for more details.
2d19f95caef8668aeb5c05a18b39c6b79f710856Kay Sievers *
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering * You should have received a copy of the GNU General Public License
a4cc3e5ccc0a3033d764a9eb3ae5ee90db560682Lennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
a4cc3e5ccc0a3033d764a9eb3ae5ee90db560682Lennart Poettering */
a4cc3e5ccc0a3033d764a9eb3ae5ee90db560682Lennart Poettering
0028da22f194f7c0ca7169a48cf32e1bc0f9138aLennart Poettering#include <stddef.h>
a4cc3e5ccc0a3033d764a9eb3ae5ee90db560682Lennart Poettering#include <limits.h>
7e2c2bcf1285d124c9c656ff46cafa4db0a987c9Lennart Poettering#include <stdlib.h>
f0c15f288513aa4da012db7497a4aec3f7763ebbLennart Poettering#include <stdbool.h>
7b4da18c1717f811bae67ea3d39290495857c03eLennart Poettering#include <string.h>
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering#include <stdio.h>
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering#include <fcntl.h>
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering#include <ctype.h>
dd359de89b1fbabf6f4eb5003d2b5a806b6185c1Lennart Poettering#include <unistd.h>
dd359de89b1fbabf6f4eb5003d2b5a806b6185c1Lennart Poettering#include <errno.h>
dd359de89b1fbabf6f4eb5003d2b5a806b6185c1Lennart Poettering#include <dirent.h>
61a9648f022049ac14c5667958752e8dcff857c1Lennart Poettering#include <fnmatch.h>
61a9648f022049ac14c5667958752e8dcff857c1Lennart Poettering#include <time.h>
61a9648f022049ac14c5667958752e8dcff857c1Lennart Poettering
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering#include "udev.h"
3df82d5a8cdc510f518fd5e234ccb3233b748719Lennart Poettering
461bd8e47cafacfcd38389e7558330bfb6e902adLennart Poettering#define PREALLOC_TOKEN 2048
461bd8e47cafacfcd38389e7558330bfb6e902adLennart Poettering#define PREALLOC_STRBUF 32 * 1024
461bd8e47cafacfcd38389e7558330bfb6e902adLennart Poettering#define PREALLOC_TRIE 256
248f07758638f0a7053740a36e7d3ff4ae62c731Lennart Poettering
248f07758638f0a7053740a36e7d3ff4ae62c731Lennart Poetteringstruct uid_gid {
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering unsigned int name_off;
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering union {
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering uid_t uid;
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering gid_t gid;
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering };
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering};
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poetteringstruct trie_node {
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering /* this node's first child */
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering unsigned int child_idx;
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering /* the next child of our parent node's child list */
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering unsigned int next_child_idx;
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering /* this node's last child (shortcut for append) */
ab8e074ce25b9947314c69e17afe1bd2527ee26dLennart Poettering unsigned int last_child_idx;
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering unsigned int value_off;
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering unsigned short value_len;
b454b11220e87add6d0f011695c7912b009c853dLennart Poettering unsigned char key;
4a449ed73d2c1cfb91a1c773b70231b3457b3046Lennart Poettering};
755123030a4b4c82251b49155aa0e7f523081558Harald Hoyer
4a449ed73d2c1cfb91a1c773b70231b3457b3046Lennart Poetteringstruct udev_rules {
4a449ed73d2c1cfb91a1c773b70231b3457b3046Lennart Poettering struct udev *udev;
4a449ed73d2c1cfb91a1c773b70231b3457b3046Lennart Poettering int resolve_names;
d8d3d8a781031d6b1ee4e5f57ec21f16c20a4cf2Lennart Poettering
4a449ed73d2c1cfb91a1c773b70231b3457b3046Lennart Poettering /* every key in the rules file becomes a token */
4a449ed73d2c1cfb91a1c773b70231b3457b3046Lennart Poettering struct token *tokens;
4a449ed73d2c1cfb91a1c773b70231b3457b3046Lennart Poettering unsigned int token_cur;
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering unsigned int token_max;
4a449ed73d2c1cfb91a1c773b70231b3457b3046Lennart Poettering
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering /* all key strings are copied to a single string buffer */
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering char *buf;
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering size_t buf_cur;
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering size_t buf_max;
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering unsigned int buf_count;
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering /* during rule parsing, strings are indexed to find duplicates */
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering struct trie_node *trie_nodes;
4ff49cb63075aba646b578f2516b37a8dfd5a65bLennart Poettering unsigned int trie_nodes_cur;
a53824ea7466bee2c5e6ac9a11b58b79adceb98bLennart Poettering unsigned int trie_nodes_max;
a53824ea7466bee2c5e6ac9a11b58b79adceb98bLennart Poettering
a53824ea7466bee2c5e6ac9a11b58b79adceb98bLennart Poettering /* during rule parsing, uid/gid lookup results are cached */
b8b4d3dddc7611dce3bf28004b0375d661120c62Lennart Poettering struct uid_gid *uids;
b8b4d3dddc7611dce3bf28004b0375d661120c62Lennart Poettering unsigned int uids_cur;
b8b4d3dddc7611dce3bf28004b0375d661120c62Lennart Poettering unsigned int uids_max;
b8b4d3dddc7611dce3bf28004b0375d661120c62Lennart Poettering struct uid_gid *gids;
b8b4d3dddc7611dce3bf28004b0375d661120c62Lennart Poettering unsigned int gids_cur;
b8b4d3dddc7611dce3bf28004b0375d661120c62Lennart Poettering unsigned int gids_max;
b8b4d3dddc7611dce3bf28004b0375d661120c62Lennart Poettering};
3df82d5a8cdc510f518fd5e234ccb3233b748719Lennart Poettering
3df82d5a8cdc510f518fd5e234ccb3233b748719Lennart Poettering/* KEY=="", KEY!="", KEY+="", KEY="", KEY:="" */
3df82d5a8cdc510f518fd5e234ccb3233b748719Lennart Poetteringenum operation_type {
3df82d5a8cdc510f518fd5e234ccb3233b748719Lennart Poettering OP_UNSET,
5666ea6fcaaf1e829de07625b7c185949b23fecdKay Sievers
5666ea6fcaaf1e829de07625b7c185949b23fecdKay Sievers OP_MATCH,
5666ea6fcaaf1e829de07625b7c185949b23fecdKay Sievers OP_NOMATCH,
a9602630c64791571ca37606a0a5eabfac85820aLennart Poettering OP_MATCH_MAX,
b6b7d4337976eeac610b9ed2c3e1fd596a247b14Lennart Poettering
b6b7d4337976eeac610b9ed2c3e1fd596a247b14Lennart Poettering OP_ADD,
b6b7d4337976eeac610b9ed2c3e1fd596a247b14Lennart Poettering OP_ASSIGN,
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering OP_ASSIGN_FINAL,
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering};
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poetteringenum string_glob_type {
b5c03638d48c07aa0eaf13b5f54000c7133e1883Lennart Poettering GL_UNSET,
752beb0c8560fb7e989d2f8da5e10c4692d78422Lennart Poettering GL_PLAIN, /* no special chars */
752beb0c8560fb7e989d2f8da5e10c4692d78422Lennart Poettering GL_GLOB, /* shell globs ?,*,[] */
eece8c6fb5f4d354dcef6fd369e876c4f3a3f163Lennart Poettering GL_SPLIT, /* multi-value A|B */
eece8c6fb5f4d354dcef6fd369e876c4f3a3f163Lennart Poettering GL_SPLIT_GLOB, /* multi-value with glob A*|B* */
eece8c6fb5f4d354dcef6fd369e876c4f3a3f163Lennart Poettering GL_SOMETHING, /* commonly used "?*" */
d325d9bcfa8846a65767087f958a2dd11139d0e7Kay Sievers};
d325d9bcfa8846a65767087f958a2dd11139d0e7Kay Sievers
d325d9bcfa8846a65767087f958a2dd11139d0e7Kay Sieversenum string_subst_type {
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering SB_UNSET,
64e30145fce09b87a0b0a7e08c84a100818a5d5aLennart Poettering SB_NONE,
64e30145fce09b87a0b0a7e08c84a100818a5d5aLennart Poettering SB_FORMAT,
64e30145fce09b87a0b0a7e08c84a100818a5d5aLennart Poettering SB_SUBSYS,
64e30145fce09b87a0b0a7e08c84a100818a5d5aLennart Poettering};
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poettering
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poettering/* tokens of a rule are sorted/handled in this order */
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poetteringenum token_type {
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poettering TK_UNSET,
bfa00bc6c05d0f896e9632eccd47d442fea556b9Lennart Poettering TK_RULE,
bfa00bc6c05d0f896e9632eccd47d442fea556b9Lennart Poettering
3b953d68c628c6ae70adba871719ac0f16083b51Josh Triplett TK_M_ACTION, /* val */
3b953d68c628c6ae70adba871719ac0f16083b51Josh Triplett TK_M_DEVPATH, /* val */
3b953d68c628c6ae70adba871719ac0f16083b51Josh Triplett TK_M_KERNEL, /* val */
3b953d68c628c6ae70adba871719ac0f16083b51Josh Triplett TK_M_DEVLINK, /* val */
3b953d68c628c6ae70adba871719ac0f16083b51Josh Triplett TK_M_NAME, /* val */
09f727eebd87661f263d3c2c1e0de7b7771acd40Lennart Poettering TK_M_ENV, /* val, attr */
09f727eebd87661f263d3c2c1e0de7b7771acd40Lennart Poettering TK_M_TAG, /* val */
09f727eebd87661f263d3c2c1e0de7b7771acd40Lennart Poettering TK_M_SUBSYSTEM, /* val */
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering TK_M_DRIVER, /* val */
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering TK_M_WAITFOR, /* val */
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering TK_M_ATTR, /* val, attr */
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering TK_M_PARENTS_MIN,
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering TK_M_KERNELS, /* val */
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering TK_M_SUBSYSTEMS, /* val */
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering TK_M_DRIVERS, /* val */
795607b22308f5b92073b012e43be1892fdd97c0Lennart Poettering TK_M_ATTRS, /* val, attr */
247c873b421291f711d8a57796011520a6b790afLennart Poettering TK_M_TAGS, /* val */
247c873b421291f711d8a57796011520a6b790afLennart Poettering TK_M_PARENTS_MAX,
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering TK_M_TEST, /* val, mode_t */
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering TK_M_EVENT_TIMEOUT, /* int */
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering TK_M_PROGRAM, /* val */
0be8342c04bbf129b4a21e5073eacccbbce4e896Lennart Poettering TK_M_IMPORT_FILE, /* val */
6bc80e94b66e6b008cdc21101fc7409ebcb279dbLennart Poettering TK_M_IMPORT_PROG, /* val */
6bc80e94b66e6b008cdc21101fc7409ebcb279dbLennart Poettering TK_M_IMPORT_BUILTIN, /* val */
487060c2394b7703e59650ef332053645ffae2a3Lennart Poettering TK_M_IMPORT_DB, /* val */
487060c2394b7703e59650ef332053645ffae2a3Lennart Poettering TK_M_IMPORT_CMDLINE, /* val */
e5ec62c56963d997edaffa904af5dc45dac23988Lennart Poettering TK_M_IMPORT_PARENT, /* val */
54c31a79f72ff57ac8eba089acacc4ab482b745dLennart Poettering TK_M_RESULT, /* val */
826872b61e4857dfffe63ba84e2b005623baecd6Lennart Poettering TK_M_MAX,
826872b61e4857dfffe63ba84e2b005623baecd6Lennart Poettering
54c31a79f72ff57ac8eba089acacc4ab482b745dLennart Poettering TK_A_STRING_ESCAPE_NONE,
826872b61e4857dfffe63ba84e2b005623baecd6Lennart Poettering TK_A_STRING_ESCAPE_REPLACE,
e5ec62c56963d997edaffa904af5dc45dac23988Lennart Poettering TK_A_DB_PERSIST,
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_INOTIFY_WATCH, /* int */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_DEVLINK_PRIO, /* int */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_OWNER, /* val */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_GROUP, /* val */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_MODE, /* val */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_OWNER_ID, /* uid_t */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_GROUP_ID, /* gid_t */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_MODE_ID, /* mode_t */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_STATIC_NODE, /* val */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_ENV, /* val, attr */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_TAG, /* val */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_NAME, /* val */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_DEVLINK, /* val */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_ATTR, /* val, attr */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_RUN, /* val, bool */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_A_GOTO, /* size_t */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering TK_END,
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering};
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering/* we try to pack stuff in a way that we take only 12 bytes per token */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poetteringstruct token {
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering union {
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering unsigned char type; /* same in rule and key */
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering struct {
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering enum token_type type:8;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering bool can_set_name:1;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering bool has_static_node:1;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering unsigned int unused:6;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering unsigned short token_count;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering unsigned int label_off;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering unsigned short filename_off;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering unsigned short filename_line;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering } rule;
cbb7712189527f9f483321607e44c4ead3dd11b8Lennart Poettering struct {
cbb7712189527f9f483321607e44c4ead3dd11b8Lennart Poettering enum token_type type:8;
dd359de89b1fbabf6f4eb5003d2b5a806b6185c1Lennart Poettering enum operation_type op:8;
dd359de89b1fbabf6f4eb5003d2b5a806b6185c1Lennart Poettering enum string_glob_type glob:8;
d01a73b6396f57792113c1b5df6e8492fc703e5eLennart Poettering enum string_subst_type subst:4;
d01a73b6396f57792113c1b5df6e8492fc703e5eLennart Poettering enum string_subst_type attrsubst:4;
990ffbe5cffe7f11a8d3ab2258a85fc52b97bf60Lennart Poettering unsigned int value_off;
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering union {
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering unsigned int attr_off;
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering int devlink_unique;
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering unsigned int rule_goto;
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering mode_t mode;
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering uid_t uid;
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering gid_t gid;
356ce9915ab1a4a1e6dc26954df34936a69e7c12Lennart Poettering int devlink_prio;
490b7e47093d491a2bdb1084fe92b796f4e07eefLennart Poettering int event_timeout;
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering int watch;
490b7e47093d491a2bdb1084fe92b796f4e07eefLennart Poettering enum udev_builtin_cmd builtin_cmd;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering };
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering } key;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering };
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering};
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering#define MAX_TK 64
e41814846c19a48f4490169d82e359e005c4db45Lennart Poetteringstruct rule_tmp {
c0fe5db522b52f27e030655ce2c03e05cbbc1558Kay Sievers struct udev_rules *rules;
e9fd44b728ff1fc0d1f24fccb87a767f6865df27Lennart Poettering struct token rule;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering struct token token[MAX_TK];
e9fd44b728ff1fc0d1f24fccb87a767f6865df27Lennart Poettering unsigned int token_cur;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering};
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
3040728b6691ea2e9df3a2060e2d49a792bbaedaLennart Poettering#ifdef ENABLE_DEBUG
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poetteringstatic const char *operation_str(enum operation_type type)
8ed206517c2be381324ac5832bf34cc14024270eLennart Poettering{
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering static const char *operation_strs[] = {
e6c6e7afffa80ad74efdb1ddfa815294624f1608Lennart Poettering [OP_UNSET] = "UNSET",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [OP_MATCH] = "match",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [OP_NOMATCH] = "nomatch",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [OP_MATCH_MAX] = "MATCH_MAX",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [OP_ADD] = "add",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [OP_ASSIGN] = "assign",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [OP_ASSIGN_FINAL] = "assign-final",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering} ;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering return operation_strs[type];
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering}
e5ec62c56963d997edaffa904af5dc45dac23988Lennart Poettering
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poetteringstatic const char *string_glob_str(enum string_glob_type type)
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering{
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poettering static const char *string_glob_strs[] = {
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [GL_UNSET] = "UNSET",
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poettering [GL_PLAIN] = "plain",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [GL_GLOB] = "glob",
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poettering [GL_SPLIT] = "split",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [GL_SPLIT_GLOB] = "split-glob",
b87b8b2b5205c0584da220f73322ea4732d44013Kay Sievers [GL_SOMETHING] = "split-glob",
b87b8b2b5205c0584da220f73322ea4732d44013Kay Sievers };
b87b8b2b5205c0584da220f73322ea4732d44013Kay Sievers
c06bf414042cd1bf94e0af63e9e2a0c291bfc546Kay Sievers return string_glob_strs[type];
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering}
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poetteringstatic const char *token_str(enum token_type type)
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering{
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering static const char *token_strs[] = {
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_UNSET] = "UNSET",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_RULE] = "RULE",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_ACTION] = "M ACTION",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_DEVPATH] = "M DEVPATH",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_KERNEL] = "M KERNEL",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_DEVLINK] = "M DEVLINK",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_NAME] = "M NAME",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_ENV] = "M ENV",
f47ec8ebb3858553dec870e1c596e39525f46360Lennart Poettering [TK_M_TAG] = "M TAG",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_SUBSYSTEM] = "M SUBSYSTEM",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_DRIVER] = "M DRIVER",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_WAITFOR] = "M WAITFOR",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_ATTR] = "M ATTR",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_PARENTS_MIN] = "M PARENTS_MIN",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_KERNELS] = "M KERNELS",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_SUBSYSTEMS] = "M SUBSYSTEMS",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_DRIVERS] = "M DRIVERS",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_ATTRS] = "M ATTRS",
f47ec8ebb3858553dec870e1c596e39525f46360Lennart Poettering [TK_M_TAGS] = "M TAGS",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_PARENTS_MAX] = "M PARENTS_MAX",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_TEST] = "M TEST",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_EVENT_TIMEOUT] = "M EVENT_TIMEOUT",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_PROGRAM] = "M PROGRAM",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_IMPORT_FILE] = "M IMPORT_FILE",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_IMPORT_PROG] = "M IMPORT_PROG",
2e4015f3e73173a4346c03a1ed7962f7d3423ed2Lennart Poettering [TK_M_IMPORT_BUILTIN] = "M IMPORT_BUILTIN",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_IMPORT_DB] = "M IMPORT_DB",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_IMPORT_CMDLINE] = "M IMPORT_CMDLINE",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_IMPORT_PARENT] = "M IMPORT_PARENT",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_RESULT] = "M RESULT",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_M_MAX] = "M MAX",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_STRING_ESCAPE_NONE] = "A STRING_ESCAPE_NONE",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_STRING_ESCAPE_REPLACE] = "A STRING_ESCAPE_REPLACE",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_DB_PERSIST] = "A DB_PERSIST",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_INOTIFY_WATCH] = "A INOTIFY_WATCH",
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering [TK_A_DEVLINK_PRIO] = "A DEVLINK_PRIO",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_OWNER] = "A OWNER",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_GROUP] = "A GROUP",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_MODE] = "A MODE",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_OWNER_ID] = "A OWNER_ID",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_GROUP_ID] = "A GROUP_ID",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_STATIC_NODE] = "A STATIC_NODE",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_MODE_ID] = "A MODE_ID",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_ENV] = "A ENV",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_TAG] = "A ENV",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_NAME] = "A NAME",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_DEVLINK] = "A DEVLINK",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_ATTR] = "A ATTR",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_RUN] = "A RUN",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering [TK_A_GOTO] = "A GOTO",
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
7ba9719595ee13612c9aea786233ffdd4d77ee46Zbigniew Jędrzejewski-Szmek [TK_END] = "END",
7ba9719595ee13612c9aea786233ffdd4d77ee46Zbigniew Jędrzejewski-Szmek };
7ba9719595ee13612c9aea786233ffdd4d77ee46Zbigniew Jędrzejewski-Szmek
8b04b925e587ff56568c62ff5ad3f2ea2b34ca7aLennart Poettering return token_strs[type];
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poettering}
e673ad0415d89c322e5b1a121e411f1b1d8075c0Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poetteringstatic void dump_token(struct udev_rules *rules, struct token *token)
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering{
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering enum token_type type = token->type;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering enum operation_type op = token->key.op;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering enum string_glob_type glob = token->key.glob;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering const char *value = &rules->buf[token->key.value_off];
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering const char *attr = &rules->buf[token->key.attr_off];
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering switch (type) {
d2e83c23f5f0cdd3b6ec05c5c40209708721e704Kay Sievers case TK_RULE:
d2e83c23f5f0cdd3b6ec05c5c40209708721e704Kay Sievers {
d2e83c23f5f0cdd3b6ec05c5c40209708721e704Kay Sievers const char *tks_ptr = (char *)rules->tokens;
d2e83c23f5f0cdd3b6ec05c5c40209708721e704Kay Sievers const char *tk_ptr = (char *)token;
f6113d42d015ad9f3a9e702a09eb8006511a4424Kay Sievers unsigned int idx = (tk_ptr - tks_ptr) / sizeof(struct token);
f6113d42d015ad9f3a9e702a09eb8006511a4424Kay Sievers
d2e83c23f5f0cdd3b6ec05c5c40209708721e704Kay Sievers dbg(rules->udev, "* RULE %s:%u, token: %u, count: %u, label: '%s'\n",
7a43e910ce00eef22fd42925ae4c85cbea1b1320Kay Sievers &rules->buf[token->rule.filename_off], token->rule.filename_line,
d2e83c23f5f0cdd3b6ec05c5c40209708721e704Kay Sievers idx, token->rule.token_count,
c55b1b59b837dfd924b704d457ed77c55f8bfeabLennart Poettering &rules->buf[token->rule.label_off]);
6c1703cc35b3a5f93ad3cc813fea10cb9a636102Kay Sievers break;
6c1703cc35b3a5f93ad3cc813fea10cb9a636102Kay Sievers }
6c1703cc35b3a5f93ad3cc813fea10cb9a636102Kay Sievers case TK_M_ACTION:
08f9588885c5d65694b324846b0ed19211d2c178Lennart Poettering case TK_M_DEVPATH:
59704f3e937c664f7324bfbb08483c358dfbc4c6Lennart Poettering case TK_M_KERNEL:
59704f3e937c664f7324bfbb08483c358dfbc4c6Lennart Poettering case TK_M_SUBSYSTEM:
59704f3e937c664f7324bfbb08483c358dfbc4c6Lennart Poettering case TK_M_DRIVER:
9ec82de1725ddaab333149171b790d62c47ae133Lennart Poettering case TK_M_WAITFOR:
e707c49485b8f4f2ec040d3da232d39153e650b9Lennart Poettering case TK_M_DEVLINK:
e707c49485b8f4f2ec040d3da232d39153e650b9Lennart Poettering case TK_M_NAME:
e707c49485b8f4f2ec040d3da232d39153e650b9Lennart Poettering case TK_M_KERNELS:
7f8732835295fce29479b1afc9e8ee801852db09Lennart Poettering case TK_M_SUBSYSTEMS:
7f8732835295fce29479b1afc9e8ee801852db09Lennart Poettering case TK_M_DRIVERS:
7f8732835295fce29479b1afc9e8ee801852db09Lennart Poettering case TK_M_TAGS:
e707c49485b8f4f2ec040d3da232d39153e650b9Lennart Poettering case TK_M_PROGRAM:
e707c49485b8f4f2ec040d3da232d39153e650b9Lennart Poettering case TK_M_IMPORT_FILE:
e707c49485b8f4f2ec040d3da232d39153e650b9Lennart Poettering case TK_M_IMPORT_PROG:
a19554ed92a7460b4e709cc40c558cde827ab85bLennart Poettering case TK_M_IMPORT_DB:
a19554ed92a7460b4e709cc40c558cde827ab85bLennart Poettering case TK_M_IMPORT_CMDLINE:
1cb88f2c61f590083847d65cd5a518e834da87d3Lennart Poettering case TK_M_IMPORT_PARENT:
1cb88f2c61f590083847d65cd5a518e834da87d3Lennart Poettering case TK_M_RESULT:
1cb88f2c61f590083847d65cd5a518e834da87d3Lennart Poettering case TK_A_NAME:
1cb88f2c61f590083847d65cd5a518e834da87d3Lennart Poettering case TK_A_DEVLINK:
1cb88f2c61f590083847d65cd5a518e834da87d3Lennart Poettering case TK_A_OWNER:
603cd8fe07cb03e8b11722d1a732e569e5a46347Lennart Poettering case TK_A_GROUP:
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering case TK_A_MODE:
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering case TK_A_RUN:
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering dbg(rules->udev, "%s %s '%s'(%s)\n",
a7a3f28be404875eff20443a0fa8088bcc4c18dfLennart Poettering token_str(type), operation_str(op), value, string_glob_str(glob));
a7a3f28be404875eff20443a0fa8088bcc4c18dfLennart Poettering break;
9b27910bb0c23e5225fc1177176e4f9bf9bf787bLennart Poettering case TK_M_IMPORT_BUILTIN:
9b27910bb0c23e5225fc1177176e4f9bf9bf787bLennart Poettering dbg(rules->udev, "%s %i '%s'\n", token_str(type), token->key.builtin_cmd, value);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering break;
08f9588885c5d65694b324846b0ed19211d2c178Lennart Poettering case TK_M_ATTR:
7d8197d1f25c1291855bb6cffc705444978c6d8dKay Sievers case TK_M_ATTRS:
7d8197d1f25c1291855bb6cffc705444978c6d8dKay Sievers case TK_M_ENV:
7d8197d1f25c1291855bb6cffc705444978c6d8dKay Sievers case TK_A_ATTR:
7d8197d1f25c1291855bb6cffc705444978c6d8dKay Sievers case TK_A_ENV:
7d8197d1f25c1291855bb6cffc705444978c6d8dKay Sievers dbg(rules->udev, "%s %s '%s' '%s'(%s)\n",
7d8197d1f25c1291855bb6cffc705444978c6d8dKay Sievers token_str(type), operation_str(op), attr, value, string_glob_str(glob));
7d8197d1f25c1291855bb6cffc705444978c6d8dKay Sievers break;
9ee58bddeb6eb044753167e0047fe836479ca5dbKay Sievers case TK_M_TAG:
9ee58bddeb6eb044753167e0047fe836479ca5dbKay Sievers case TK_A_TAG:
dcfc4b2e5c1af6375488c00bdc6fb8122f86c4d7Lennart Poettering dbg(rules->udev, "%s %s '%s'\n", token_str(type), operation_str(op), value);
71ef24d09573874c0f7bc323c07c3aec2a458707Lennart Poettering break;
71ef24d09573874c0f7bc323c07c3aec2a458707Lennart Poettering case TK_A_STRING_ESCAPE_NONE:
71ef24d09573874c0f7bc323c07c3aec2a458707Lennart Poettering case TK_A_STRING_ESCAPE_REPLACE:
71ef24d09573874c0f7bc323c07c3aec2a458707Lennart Poettering case TK_A_DB_PERSIST:
1b89884ba31cbe98f159ce2c7d6fac5f6a57698fLennart Poettering dbg(rules->udev, "%s\n", token_str(type));
1b89884ba31cbe98f159ce2c7d6fac5f6a57698fLennart Poettering break;
1920e37ef9fec04a1fd882f66bfa7a9a5b91c536Lennart Poettering case TK_M_TEST:
1920e37ef9fec04a1fd882f66bfa7a9a5b91c536Lennart Poettering dbg(rules->udev, "%s %s '%s'(%s) %#o\n",
15abdb9a6f34628b04b887e0b9649fa582d6cd37Lennart Poettering token_str(type), operation_str(op), value, string_glob_str(glob), token->key.mode);
1920e37ef9fec04a1fd882f66bfa7a9a5b91c536Lennart Poettering break;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering case TK_A_INOTIFY_WATCH:
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering dbg(rules->udev, "%s %u\n", token_str(type), token->key.watch);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering break;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering case TK_A_DEVLINK_PRIO:
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering dbg(rules->udev, "%s %u\n", token_str(type), token->key.devlink_prio);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering break;
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering case TK_A_OWNER_ID:
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering dbg(rules->udev, "%s %s %u\n", token_str(type), operation_str(op), token->key.uid);
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering break;
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering case TK_A_GROUP_ID:
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering dbg(rules->udev, "%s %s %u\n", token_str(type), operation_str(op), token->key.gid);
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering break;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering case TK_A_MODE_ID:
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering dbg(rules->udev, "%s %s %#o\n", token_str(type), operation_str(op), token->key.mode);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering break;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering case TK_A_STATIC_NODE:
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering dbg(rules->udev, "%s '%s'\n", token_str(type), value);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering break;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering case TK_M_EVENT_TIMEOUT:
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering dbg(rules->udev, "%s %u\n", token_str(type), token->key.event_timeout);
f801968466fed39d50d410b30ac828c26722cc95Lennart Poettering break;
de34a42bcad31f0648ac0f249801310e0dbf83f9Lennart Poettering case TK_A_GOTO:
de34a42bcad31f0648ac0f249801310e0dbf83f9Lennart Poettering dbg(rules->udev, "%s '%s' %u\n", token_str(type), value, token->key.rule_goto);
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poettering break;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering case TK_END:
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poettering dbg(rules->udev, "* %s\n", token_str(type));
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poettering break;
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poettering case TK_M_PARENTS_MIN:
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poettering case TK_M_PARENTS_MAX:
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poettering case TK_M_MAX:
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering case TK_UNSET:
d05c556b6b2a680ec8b51ecbbc99a9ab14c28eedZbigniew Jędrzejewski-Szmek dbg(rules->udev, "unknown type %u\n", type);
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering break;
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering }
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering}
4a30847b9d71e0381948d68279c8f775b9de7850Lennart Poettering
4a30847b9d71e0381948d68279c8f775b9de7850Lennart Poetteringstatic void dump_rules(struct udev_rules *rules)
5e8b28838e493b59628322b69580097ef7dd9384Lennart Poettering{
5e8b28838e493b59628322b69580097ef7dd9384Lennart Poettering unsigned int i;
d87be9b0af81a6e07d4fb3028e45c4409100dc26Lennart Poettering
d87be9b0af81a6e07d4fb3028e45c4409100dc26Lennart Poettering dbg(rules->udev, "dumping %u (%zu bytes) tokens, %u (%zu bytes) strings\n",
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering rules->token_cur,
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering rules->token_cur * sizeof(struct token),
38a60d7112d33ffd596b23e8df53d75a7c09e71bLennart Poettering rules->buf_count,
38a60d7112d33ffd596b23e8df53d75a7c09e71bLennart Poettering rules->buf_cur);
d8b78264a5245307babbf5af8e39d6d4a1ae095fLennart Poettering for(i = 0; i < rules->token_cur; i++)
d8b78264a5245307babbf5af8e39d6d4a1ae095fLennart Poettering dump_token(rules, &rules->tokens[i]);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poettering}
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poettering#else
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poetteringstatic inline const char *operation_str(enum operation_type type) { return NULL; }
0790b9fed42eefc4e22dbbe2337cba9713b7848cLennart Poetteringstatic inline const char *token_str(enum token_type type) { return NULL; }
5a7e959984788cf89719dec31999409b63bb802bLennart Poetteringstatic inline void dump_token(struct udev_rules *rules, struct token *token) {}
5a7e959984788cf89719dec31999409b63bb802bLennart Poetteringstatic inline void dump_rules(struct udev_rules *rules) {}
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering#endif /* ENABLE_DEBUG */
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poetteringstatic int add_new_string(struct udev_rules *rules, const char *str, size_t bytes)
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering{
edca2e2348b314e2d892fe6f8ae276fdc223f014Thomas Hindoe Paaboel Andersen int off;
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering
0790b9fed42eefc4e22dbbe2337cba9713b7848cLennart Poettering /* grow buffer if needed */
5aea932fd54db835b77709ddeba30732648aae53Lennart Poettering if (rules->buf_cur + bytes+1 >= rules->buf_max) {
5aea932fd54db835b77709ddeba30732648aae53Lennart Poettering char *buf;
918943c75fbd9dee87ff396de3a7c63a8d228433Lennart Poettering unsigned int add;
918943c75fbd9dee87ff396de3a7c63a8d228433Lennart Poettering
fd4d89b2c0b31da01d134301e30916931ae3c7d9Lennart Poettering /* double the buffer size */
fd4d89b2c0b31da01d134301e30916931ae3c7d9Lennart Poettering add = rules->buf_max;
8230e26dc954a40d8c9dbc8ddd9376117021f9d2Lennart Poettering if (add < bytes * 8)
8230e26dc954a40d8c9dbc8ddd9376117021f9d2Lennart Poettering add = bytes * 8;
4d9909c93e9c58789c71b34555a1908307c6849eLennart Poettering
4d9909c93e9c58789c71b34555a1908307c6849eLennart Poettering buf = realloc(rules->buf, rules->buf_max + add);
47ae7201b1df43bd3da83a19e38483b0e5694c99Lennart Poettering if (buf == NULL)
47ae7201b1df43bd3da83a19e38483b0e5694c99Lennart Poettering return -1;
88a6c5894c9d3f85d63b87b040c130366b4006ceKay Sievers dbg(rules->udev, "extend buffer from %zu to %zu\n", rules->buf_max, rules->buf_max + add);
8351ceaea9480d9c2979aa2ff0f4982cfdfef58dLennart Poettering rules->buf = buf;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering rules->buf_max += add;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering }
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering off = rules->buf_cur;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering memcpy(&rules->buf[rules->buf_cur], str, bytes);
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering rules->buf_cur += bytes;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering rules->buf_count++;
c66d36e5b5ae81f3c5297d6dacadc13c88c530f6Lennart Poettering return off;
be0aa78406c73a6625308dc0672b5ff27ec6f9a8Lennart Poettering}
be0aa78406c73a6625308dc0672b5ff27ec6f9a8Lennart Poettering
9946996cda11a18b44d82344676e5a0e96339408Lennart Poetteringstatic int add_string(struct udev_rules *rules, const char *str)
9946996cda11a18b44d82344676e5a0e96339408Lennart Poettering{
9946996cda11a18b44d82344676e5a0e96339408Lennart Poettering unsigned int node_idx;
3471bedc005fab03f40b99bf6599645330adcd9eLennart Poettering struct trie_node *new_node;
3471bedc005fab03f40b99bf6599645330adcd9eLennart Poettering unsigned int new_node_idx;
eeb875144e5a80d0521461a139f13fc8014d77d8Lennart Poettering unsigned char key;
eeb875144e5a80d0521461a139f13fc8014d77d8Lennart Poettering unsigned short len;
59cea26a349cfa8db906b520dac72563dd773ff2Lennart Poettering unsigned int depth;
35eb6b124ebdf82bd77aad6e44962a9a039c4d33Lennart Poettering unsigned int off;
9473414219330b9febc1d0712bbf49ad74cf962fLennart Poettering struct trie_node *parent;
f1a8e221ecacea23883df57951e291a910463948Lennart Poettering
7b63bde1ed0d4f30c799c9b4737fa926465929f9Lennart Poettering /* walk trie, start from last character of str to find matching tails */
7b63bde1ed0d4f30c799c9b4737fa926465929f9Lennart Poettering len = strlen(str);
5b40d33761376354116a8cddb9b9fbdb6c4727d6Lennart Poettering key = str[len-1];
5b40d33761376354116a8cddb9b9fbdb6c4727d6Lennart Poettering node_idx = 0;
b86fa936ce36976cd6a96034cf14ea267695bcb2Lennart Poettering for (depth = 0; depth <= len; depth++) {
b86fa936ce36976cd6a96034cf14ea267695bcb2Lennart Poettering struct trie_node *node;
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers unsigned int child_idx;
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers node = &rules->trie_nodes[node_idx];
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers off = node->value_off + node->value_len - len;
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers /* match against current node */
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers if (depth == len || (node->value_len >= len && memcmp(&rules->buf[off], str, len) == 0))
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers return off;
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers
d3a3f22267a7dac426b07a7ed0baa1632f5daf04Kay Sievers /* lookup child node */
465349c06d994dd2cc6b6fc4109ac0b9952d500aLennart Poettering key = str[len - 1 - depth];
06dab8e18aebf822392c7ca66c5bf3c1200fdec8Lennart Poettering child_idx = node->child_idx;
06dab8e18aebf822392c7ca66c5bf3c1200fdec8Lennart Poettering while (child_idx > 0) {
e01a15b71e18bf2008aec7e75041ffa42eb80b80Kay Sievers struct trie_node *child;
a888b352eb53b07daa24fa859ceeb254336b293dLennart Poettering
98ef27df896f36f0407eaa7ed9e295203b9c271bLennart Poettering child = &rules->trie_nodes[child_idx];
a0a3844815b0f346dba03f41245c620f432e462fLennart Poettering if (child->key == key)
abd55b16547d0bb0ed1c31e72e16838f0f59f48bKay Sievers break;
3f60bcb5e69846fe8a3156ca1c9a7e0813ac158aKay Sievers child_idx = child->next_child_idx;
abd55b16547d0bb0ed1c31e72e16838f0f59f48bKay Sievers }
abd55b16547d0bb0ed1c31e72e16838f0f59f48bKay Sievers if (child_idx == 0)
abd55b16547d0bb0ed1c31e72e16838f0f59f48bKay Sievers break;
abd55b16547d0bb0ed1c31e72e16838f0f59f48bKay Sievers node_idx = child_idx;
b8217b7bd5fd171916a095b150fad4c3a37f5a41Kay Sievers }
18b754d345ecb0b15e369978aaffa72e9814b86aKay Sievers
068665b6fd9839f27bcace7e8f56c0baa6935272Lennart Poettering /* string not found, add it */
231931ffba1bca9d8759bbd6f797e56f8c6971faLennart Poettering off = add_new_string(rules, str, len + 1);
231931ffba1bca9d8759bbd6f797e56f8c6971faLennart Poettering
169c4f65131fbc7bcb51e7d5487a715cdcd0e0ebLennart Poettering /* grow trie nodes if needed */
169c4f65131fbc7bcb51e7d5487a715cdcd0e0ebLennart Poettering if (rules->trie_nodes_cur >= rules->trie_nodes_max) {
bd08f2422491169e92dc0899d5ba848fcae4c15cLennart Poettering struct trie_node *nodes;
bd08f2422491169e92dc0899d5ba848fcae4c15cLennart Poettering unsigned int add;
fb0864e7b9c6d26269ccea6ec5c0fd921c029781Lennart Poettering
fb0864e7b9c6d26269ccea6ec5c0fd921c029781Lennart Poettering /* double the buffer size */
9586cdfab6a2638078702b7fea7e16b3a71899e2Lennart Poettering add = rules->trie_nodes_max;
9586cdfab6a2638078702b7fea7e16b3a71899e2Lennart Poettering if (add < 8)
7f110ff9b8828b477e87de7b28c708cf69a3d008Lennart Poettering add = 8;
7f110ff9b8828b477e87de7b28c708cf69a3d008Lennart Poettering
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering nodes = realloc(rules->trie_nodes, (rules->trie_nodes_max + add) * sizeof(struct trie_node));
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering if (nodes == NULL)
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering return -1;
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering dbg(rules->udev, "extend trie nodes from %u to %u\n",
53ed2eeb2e709a6c0d152d7bdf2d9a4b9f997a16Lennart Poettering rules->trie_nodes_max, rules->trie_nodes_max + add);
53ed2eeb2e709a6c0d152d7bdf2d9a4b9f997a16Lennart Poettering rules->trie_nodes = nodes;
abd55b16547d0bb0ed1c31e72e16838f0f59f48bKay Sievers rules->trie_nodes_max += add;
680a1dbc354b2f437b4e06e27d4c43217977efdfLennart Poettering }
a6e87e90ede66815989ba2db92a07102a69906feLennart Poettering
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering /* get a new node */
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering new_node_idx = rules->trie_nodes_cur;
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering rules->trie_nodes_cur++;
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering new_node = &rules->trie_nodes[new_node_idx];
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering memset(new_node, 0x00, sizeof(struct trie_node));
5ba081b0fb02380cee4c2ff5bc7e05f869eb8415Lennart Poettering new_node->value_off = off;
5ba081b0fb02380cee4c2ff5bc7e05f869eb8415Lennart Poettering new_node->value_len = len;
4cbd9ecf45f64c3a9acc99d473fbf3be3687ae24Lennart Poettering new_node->key = key;
4cbd9ecf45f64c3a9acc99d473fbf3be3687ae24Lennart Poettering
65c0cf7108ae3537a357c74b4586a783baba82f9Lennart Poettering /* join the parent's child list */
65c0cf7108ae3537a357c74b4586a783baba82f9Lennart Poettering parent = &rules->trie_nodes[node_idx];
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers if (parent->child_idx == 0) {
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers parent->child_idx = new_node_idx;
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers } else {
ad740100d108282d0244d5739d4dcc86fe4c5fdeLennart Poettering struct trie_node *last_child;
ad740100d108282d0244d5739d4dcc86fe4c5fdeLennart Poettering
de6c78f8795743894431a099d26ec562a8acf3dfLennart Poettering last_child = &rules->trie_nodes[parent->last_child_idx];
7d441ddb5ca090b5a97f58ac4b4d97b3e84fa81eLennart Poettering last_child->next_child_idx = new_node_idx;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering }
14e639ae7a1dbf156273ce697d30fbc6c6594209Lennart Poettering parent->last_child_idx = new_node_idx;
ff01d048b4c1455241c894cf7982662c9d28fd34Lennart Poettering return off;
ff01d048b4c1455241c894cf7982662c9d28fd34Lennart Poettering}
d3c7d7dd77b2b72315164b672462825cef6c0f9aKay Sievers
72b9ed828bd22f3ddd74b6853c183eebf006d6d8Lennart Poetteringstatic int add_token(struct udev_rules *rules, struct token *token)
1d6702e8d3877c0bebf3ac817dc45ff72f5ecfa9Lennart Poettering{
1d6702e8d3877c0bebf3ac817dc45ff72f5ecfa9Lennart Poettering /* grow buffer if needed */
1d6702e8d3877c0bebf3ac817dc45ff72f5ecfa9Lennart Poettering if (rules->token_cur+1 >= rules->token_max) {
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering struct token *tokens;
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering unsigned int add;
1258097cd3cdbc5dd3d264850119e553a29c5068Lennart Poettering
1258097cd3cdbc5dd3d264850119e553a29c5068Lennart Poettering /* double the buffer size */
1258097cd3cdbc5dd3d264850119e553a29c5068Lennart Poettering add = rules->token_max;
a4c279f87451186b8beb1b8cc21c7cad561ecf4bLennart Poettering if (add < 8)
a4c279f87451186b8beb1b8cc21c7cad561ecf4bLennart Poettering add = 8;
7c697168102cb64c5cb65a542959684014da99c7Lennart Poettering
253ee27a0c7a410d27d490bb79ea97caed6a2b68Lennart Poettering tokens = realloc(rules->tokens, (rules->token_max + add ) * sizeof(struct token));
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering if (tokens == NULL)
8d0e38a2b966799af884e78a54fd6a2dffa44788Lennart Poettering return -1;
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering dbg(rules->udev, "extend tokens from %u to %u\n", rules->token_max, rules->token_max + add);
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering rules->tokens = tokens;
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering rules->token_max += add;
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering }
88a07670cfa974a605c7c7b520b8a3135fce37f9Lennart Poettering memcpy(&rules->tokens[rules->token_cur], token, sizeof(struct token));
88a07670cfa974a605c7c7b520b8a3135fce37f9Lennart Poettering rules->token_cur++;
88a07670cfa974a605c7c7b520b8a3135fce37f9Lennart Poettering return 0;
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering}
916abb21d0a6653e0187b91591e492026886b0a4Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poetteringstatic uid_t add_uid(struct udev_rules *rules, const char *owner)
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering{
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering unsigned int i;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering uid_t uid;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering unsigned int off;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering
b23de6af893c11da4286bc416455cd0926d1532eLennart Poettering /* lookup, if we know it already */
21bdae12e11ae20460715475d8a0c991f15464acLennart Poettering for (i = 0; i < rules->uids_cur; i++) {
21bdae12e11ae20460715475d8a0c991f15464acLennart Poettering off = rules->uids[i].name_off;
9534ce54858c67363b841cdbdc315140437bfdb4Lennart Poettering if (strcmp(&rules->buf[off], owner) == 0) {
9534ce54858c67363b841cdbdc315140437bfdb4Lennart Poettering uid = rules->uids[i].uid;
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering dbg(rules->udev, "return existing %u for '%s'\n", uid, owner);
796b06c21b62d13c9021e2fbd9c58a5c6edb2764Kay Sievers return uid;
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering }
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering }
7a2a0b907b5cc60f5d9a871997d7d6e7f62bf4d8Lennart Poettering uid = util_lookup_user(rules->udev, owner);
253ee27a0c7a410d27d490bb79ea97caed6a2b68Lennart Poettering
5d0fcd7c8d29340ac9425c309e8ac436a9af699cLennart Poettering /* grow buffer if needed */
5d0fcd7c8d29340ac9425c309e8ac436a9af699cLennart Poettering if (rules->uids_cur+1 >= rules->uids_max) {
8bbabc447b1d913bd21faf97c7b17d20d315d2b4Lennart Poettering struct uid_gid *uids;
f530371f1f85a070d7d0fb5112146a43533ae00bLennart Poettering unsigned int add;
e707c49485b8f4f2ec040d3da232d39153e650b9Lennart Poettering
a19554ed92a7460b4e709cc40c558cde827ab85bLennart Poettering /* double the buffer size */
a73d88fa024b5668ed7dde681e99547d41e6a864Lennart Poettering add = rules->uids_max;
a74a8793b04de9886b4f6987b9cb86fa02c73520Lennart Poettering if (add < 1)
3040728b6691ea2e9df3a2060e2d49a792bbaedaLennart Poettering add = 8;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering uids = realloc(rules->uids, (rules->uids_max + add ) * sizeof(struct uid_gid));
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering if (uids == NULL)
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering return uid;
3679d1126bae52e02f6cd60fca196f616b9e660dLennart Poettering dbg(rules->udev, "extend uids from %u to %u\n", rules->uids_max, rules->uids_max + add);
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering rules->uids = uids;
44143309dd0b37d61d7d842ca58f01a65646ec71Kay Sievers rules->uids_max += add;
3d57c6ab801f4437f12948e29589e3d00c3ad9dbLennart Poettering }
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering rules->uids[rules->uids_cur].uid = uid;
3f7a8c4e9f1d3ce48919e24eb2c9d56dd6fd88d8Kay Sievers off = add_string(rules, owner);
260abb780a135e4cae8c10715c7e85675efc345aLennart Poettering if (off <= 0)
260abb780a135e4cae8c10715c7e85675efc345aLennart Poettering return uid;
260abb780a135e4cae8c10715c7e85675efc345aLennart Poettering rules->uids[rules->uids_cur].name_off = off;
2791a8f8dc8764a9247cdba3562bd4c04010f144Lennart Poettering rules->uids_cur++;
a8f11321c209830a35edd0357e8def5d4437d854Lennart Poettering return uid;
a8f11321c209830a35edd0357e8def5d4437d854Lennart Poettering}
21bdae12e11ae20460715475d8a0c991f15464acLennart Poettering
Error!

 

There was an error!

null

java.lang.NullPointerException