udev_rules_parse.c revision 282988c4f8a85c28468e6442e86efe51dc71cc93
/*
* Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
* Copyright (C) 2003-2006 Kay Sievers <kay.sievers@vrfy.org>
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include "udev.h"
#include "udev_rules.h"
#include "udev_selinux.h"
{
}
{
if (!rules)
return NULL;
dbg("no more rules\n");
return NULL;
}
/* get next rule */
return rule;
}
{
next:
dbg("no more rules\n");
return NULL;
}
goto next;
}
return rule;
}
{
char *linepos;
char *temp;
return -1;
/* skip whitespace */
linepos++;
/* get the key */
if (linepos[0] == '\0')
return -1;
while (1) {
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;
dbg("operator=match\n");
linepos += 2;
dbg("operator=nomatch\n");
*operation = KEY_OP_ADD;
linepos += 2;
dbg("operator=add\n");
} else if (linepos[0] == '=') {
linepos++;
dbg("operator=assign\n");
linepos += 2;
dbg("operator=assign_final\n");
} 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;
if (!temp)
return -1;
temp[0] = '\0';
temp++;
/* move line to next key */
return 0;
}
/* extract possible KEY{attr} */
static char *get_key_attribute(char *str)
{
char *pos;
char *attr;
attr++;
err("missing closing brace for format\n");
return NULL;
}
pos[0] = '\0';
return attr;
}
return NULL;
}
{
return 0;
}
{
err("skip, too many keys of the same type in a single rule\n");
return -1;
}
/* add the key-name of the pair */
return 0;
}
static int add_to_rules(struct udev_rules *rules, char *line, const char *filename, unsigned int lineno)
{
int valid;
char *linepos;
char *attr;
int physdev = 0;
int retval;
valid = 0;
/* get all the keys */
while (1) {
char *key;
char *value;
if (retval)
break;
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid ACTION operation\n");
goto invalid;
}
valid = 1;
continue;
}
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid DEVPATH operation\n");
goto invalid;
}
valid = 1;
continue;
}
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid KERNEL operation\n");
goto invalid;
}
valid = 1;
continue;
}
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid SUBSYSTEM operation\n");
goto invalid;
}
/* bus, class, subsystem events should all be the same */
err("'%s' must be specified as 'subsystem' \n"
} else
valid = 1;
continue;
}
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid DRIVER operation\n");
goto invalid;
}
valid = 1;
continue;
}
err("error parsing ATTR attribute\n");
goto invalid;
}
goto invalid;
valid = 1;
continue;
}
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid KERNELS operation\n");
goto invalid;
}
valid = 1;
continue;
}
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid SUBSYSTEMS operation\n");
goto invalid;
}
valid = 1;
continue;
}
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid DRIVERS operation\n");
goto invalid;
}
valid = 1;
continue;
}
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid ATTRS operation\n");
goto invalid;
}
err("error parsing ATTRS attribute\n");
goto invalid;
}
err("the 'device' link is deprecated and will be removed from a future kernel, \n"
err("do not reference parent sysfs directories directly, that may break with a future kernel, \n"
goto invalid;
valid = 1;
continue;
}
err("error parsing ENV attribute\n");
goto invalid;
}
physdev = 1;
goto invalid;
valid = 1;
continue;
}
valid = 1;
continue;
}
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid RESULT operation\n");
goto invalid;
}
valid = 1;
continue;
}
dbg("IMPORT will be executed\n");
dbg("IMPORT will be included as file\n");
dbg("IMPORT will include the parent values\n");
} else {
/* figure it out if it is executable */
char *pos;
if (pos)
pos[0] = '\0';
if (pos)
pos[0] = '\0';
}
dbg("IMPORT is executable, will be executed (autotype)\n");
} else {
dbg("IMPORT is not executable, will be included as file (autotype)\n");
}
}
valid = 1;
continue;
}
if (operation != KEY_OP_MATCH &&
operation != KEY_OP_NOMATCH) {
err("invalid TEST operation\n");
goto invalid;
}
valid = 1;
continue;
}
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
dbg("creation of partition nodes requested\n");
}
dbg("remove event should be ignored\n");
}
}
if (value[0] == '\0')
dbg("name empty, node creation supressed\n");
continue;
}
if (operation == KEY_OP_MATCH ||
else
valid = 1;
continue;
}
valid = 1;
char *endptr;
if (endptr[0] != '\0') {
char owner[32];
continue;
}
}
continue;
}
valid = 1;
char *endptr;
if (endptr[0] != '\0') {
char group[32];
continue;
}
}
continue;
}
valid = 1;
continue;
}
const char *pos;
dbg("last rule to be applied\n");
}
dbg("device should be ignored\n");
}
dbg("remove event should be ignored\n");
}
}
}
}
dbg("creation of partition nodes requested\n");
}
valid = 1;
continue;
}
}
err("PHYSDEV* values are deprecated and will be removed from a future kernel, \n"
/* skip line if not any valid key was found */
if (!valid)
goto invalid;
/* grow buffer and add rule */
err("realloc failed\n");
goto exit;
}
exit:
return 0;
return -1;
}
{
char *bufline;
unsigned int lineno;
char *buf;
int retval = 0;
return -1;
}
/* loop through the whole file */
cur = 0;
lineno = 0;
unsigned int i, j;
lineno++;
/* eat the whitespace */
bufline++;
count--;
}
if (count == 0)
continue;
/* see if this is a comment */
if (bufline[0] == COMMENT_CHARACTER)
continue;
continue;
}
/* skip backslash and newline from multiline rules */
for (i = j = 0; i < count; i++) {
continue;
}
line[j] = '\0';
}
return retval;
}
{
int retval = 0;
if (udev_rules_dir[0] != '\0') {
/* custom rules location for testing */
} else {
/* read default rules */
}
/* sort all rules files by basename into list of files */
continue;
continue;
break;
}
}
}
/* parse list of files */
else
} else
}
return retval;
}
{
}
}