../../udev/lib/libudev.c \
../../udev/lib/libudev-util.c \
../../udev/udev_sysdeps.c \
- ../../udev/udev_utils.c \
- ../../udev/udev_utils_string.c
+ ../../udev/udev_utils.c
if USE_SELINUX
create_floppy_devices_LDADD = \
../../udev/lib/libudev-util.c \
../../udev/udev_sysdeps.c \
../../udev/udev_sysfs.c \
- ../../udev/udev_utils.c \
- ../../udev/udev_utils_string.c
+ ../../udev/udev_utils.c
if USE_SELINUX
usb_id_LDADD = \
udev_sysfs.c \
udev_utils.c \
udev_utils_file.c \
- udev_utils_string.c \
lib/list.h \
lib/libudev.h \
lib/libudev-private.h \
extern uid_t lookup_user(struct udev *udev, const char *user);
extern gid_t lookup_group(struct udev *udev, const char *group);
-/* udev_utils_string.c */
-extern int string_is_true(const char *str);
-extern void remove_trailing_chars(char *path, char c);
-extern size_t path_encode(char *s, size_t len);
-extern size_t path_decode(char *s);
-extern int replace_chars(char *str, const char *white);
-
/* udev_utils_file.c */
extern int create_path(struct udev *udev, const char *path);
extern int delete_path(struct udev *udev, const char *path);
strlcpy(filename, udev_get_dev_path(udev), len);
start = strlcat(filename, "/.udev/db/", len);
strlcat(filename, devpath, len);
- return path_encode(&filename[start], len - start);
+ return util_path_encode(&filename[start], len - start);
}
/* reverse mapping from the device file name to the devpath */
strlcpy(filename, udev_get_dev_path(udev), sizeof(filename));
start = strlcat(filename, "/.udev/names/", sizeof(filename));
strlcat(filename, name, sizeof(filename));
- path_encode(&filename[start], sizeof(filename) - start);
+ util_path_encode(&filename[start], sizeof(filename) - start);
/* entry with the devpath */
strlcpy(device, devpath, sizeof(device));
- path_encode(device, sizeof(device));
+ util_path_encode(device, sizeof(device));
strlcat(filename, "/", sizeof(filename));
strlcat(filename, device, sizeof(filename));
strlcpy(dirname, udev_get_dev_path(udev), sizeof(dirname));
start = strlcat(dirname, "/.udev/names/", sizeof(dirname));
strlcat(dirname, name, sizeof(dirname));
- path_encode(&dirname[start], sizeof(dirname) - start);
+ util_path_encode(&dirname[start], sizeof(dirname) - start);
dir = opendir(dirname);
if (dir == NULL) {
continue;
strlcpy(device, ent->d_name, sizeof(device));
- path_decode(device);
+ util_path_decode(device);
name_list_add(udev, name_list, device, 0);
rc++;
}
continue;
strlcpy(device, ent->d_name, sizeof(device));
- path_decode(device);
+ util_path_decode(device);
name_list_add(udev, name_list, device, 1);
dbg(udev, "added '%s'\n", device);
}
}
/* export symlinks to environment */
- remove_trailing_chars(symlinks, ' ');
+ util_remove_trailing_chars(symlinks, ' ');
if (symlinks[0] != '\0')
setenv("DEVLINKS", symlinks, 1);
size = sizeof(temp2)-1;
while (size > 0 && isspace(temp2[size-1]))
temp2[--size] = '\0';
- count = replace_chars(temp2, ALLOWED_CHARS_INPUT);
+ count = util_replace_chars(temp2, ALLOWED_CHARS_INPUT);
if (count > 0)
info(udevice->udev, "%i character(s) replaced\n" , count);
strlcat(string, temp2, maxsize);
strlcat(symlinks, name_loop->name, sizeof(symlinks));
strlcat(symlinks, " ", sizeof(symlinks));
}
- remove_trailing_chars(symlinks, ' ');
+ util_remove_trailing_chars(symlinks, ' ');
strlcat(string, symlinks, maxsize);
}
break;
int count;
dbg(udevice->udev, "PROGRAM matches\n");
- remove_trailing_chars(result, '\n');
+ util_remove_trailing_chars(result, '\n');
if (rule->string_escape == ESCAPE_UNSET ||
rule->string_escape == ESCAPE_REPLACE) {
- count = replace_chars(result, ALLOWED_CHARS_INPUT);
+ count = util_replace_chars(result, ALLOWED_CHARS_INPUT);
if (count > 0)
info(udevice->udev, "%i character(s) replaced\n" , count);
}
udev_rules_apply_format(udevice, temp, sizeof(temp));
if (rule->string_escape == ESCAPE_UNSET ||
rule->string_escape == ESCAPE_REPLACE) {
- count = replace_chars(temp, ALLOWED_CHARS_FILE " ");
+ count = util_replace_chars(temp, ALLOWED_CHARS_FILE " ");
if (count > 0)
info(udevice->udev, "%i character(s) replaced\n" , count);
}
udev_rules_apply_format(udevice, udevice->name, sizeof(udevice->name));
if (rule->string_escape == ESCAPE_UNSET ||
rule->string_escape == ESCAPE_REPLACE) {
- count = replace_chars(udevice->name, ALLOWED_CHARS_FILE);
+ count = util_replace_chars(udevice->name, ALLOWED_CHARS_FILE);
if (count > 0)
info(udevice->udev, "%i character(s) replaced\n", count);
}
dbg(udev, "open '%s'\n", devpath);
strlcpy(devpath_real, devpath, sizeof(devpath_real));
- remove_trailing_chars(devpath_real, '/');
+ util_remove_trailing_chars(devpath_real, '/');
if (devpath[0] == '\0' )
return NULL;
/* got a valid value, store and return it */
value[size] = '\0';
- remove_trailing_chars(value, '\n');
+ util_remove_trailing_chars(value, '\n');
dbg(udev, "cache '%s' with attribute value '%s'\n", path_full, value);
strlcpy(attr->value_local, value, sizeof(attr->value_local));
attr->value = attr->value_local;
#include "udev.h"
-
-int log_priority(const char *priority)
-{
- char *endptr;
- int prio;
-
- prio = strtol(priority, &endptr, 10);
- if (endptr[0] == '\0')
- return prio;
- if (strncasecmp(priority, "err", 3) == 0)
- return LOG_ERR;
- if (strcasecmp(priority, "info") == 0)
- return LOG_INFO;
- if (strcasecmp(priority, "debug") == 0)
- return LOG_DEBUG;
- if (string_is_true(priority))
- return LOG_ERR;
-
- return 0;
-}
-
struct name_entry *name_list_add(struct udev *udev, struct list_head *name_list, const char *name, int sort)
{
struct name_entry *name_loop;
+++ /dev/null
-/*
- * Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
- *
- * This program is free software: you can redistribute it and/or modify
- * 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 <stdlib.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <ctype.h>
-#include <dirent.h>
-#include <syslog.h>
-#include <sys/utsname.h>
-
-#include "udev.h"
-
-int string_is_true(const char *str)
-{
- if (strcasecmp(str, "true") == 0)
- return 1;
- if (strcasecmp(str, "yes") == 0)
- return 1;
- if (strcasecmp(str, "1") == 0)
- return 1;
- return 0;
-}
-
-void remove_trailing_chars(char *path, char c)
-{
- size_t len;
-
- if (path == NULL)
- return;
- len = strlen(path);
- while (len > 0 && path[len-1] == c)
- path[--len] = '\0';
-}
-
-size_t path_encode(char *s, size_t len)
-{
- char t[(len * 3)+1];
- size_t i, j;
-
- t[0] = '\0';
- for (i = 0, j = 0; s[i] != '\0'; i++) {
- if (s[i] == '/') {
- memcpy(&t[j], "\\x2f", 4);
- j += 4;
- } else if (s[i] == '\\') {
- memcpy(&t[j], "\\x5c", 4);
- j += 4;
- } else {
- t[j] = s[i];
- j++;
- }
- }
- t[j] = '\0';
- strncpy(s, t, len);
- return j;
-}
-
-size_t path_decode(char *s)
-{
- size_t i, j;
-
- for (i = 0, j = 0; s[i] != '\0'; j++) {
- if (memcmp(&s[i], "\\x2f", 4) == 0) {
- s[j] = '/';
- i += 4;
- }else if (memcmp(&s[i], "\\x5c", 4) == 0) {
- s[j] = '\\';
- i += 4;
- } else {
- s[j] = s[i];
- i++;
- }
- }
- s[j] = '\0';
- return j;
-}
-
-/* count of characters used to encode one unicode char */
-static int utf8_encoded_expected_len(const char *str)
-{
- unsigned char c = (unsigned char)str[0];
-
- if (c < 0x80)
- return 1;
- if ((c & 0xe0) == 0xc0)
- return 2;
- if ((c & 0xf0) == 0xe0)
- return 3;
- if ((c & 0xf8) == 0xf0)
- return 4;
- if ((c & 0xfc) == 0xf8)
- return 5;
- if ((c & 0xfe) == 0xfc)
- return 6;
- return 0;
-}
-
-/* decode one unicode char */
-static int utf8_encoded_to_unichar(const char *str)
-{
- int unichar;
- int len;
- int i;
-
- len = utf8_encoded_expected_len(str);
- switch (len) {
- case 1:
- return (int)str[0];
- case 2:
- unichar = str[0] & 0x1f;
- break;
- case 3:
- unichar = (int)str[0] & 0x0f;
- break;
- case 4:
- unichar = (int)str[0] & 0x07;
- break;
- case 5:
- unichar = (int)str[0] & 0x03;
- break;
- case 6:
- unichar = (int)str[0] & 0x01;
- break;
- default:
- return -1;
- }
-
- for (i = 1; i < len; i++) {
- if (((int)str[i] & 0xc0) != 0x80)
- return -1;
- unichar <<= 6;
- unichar |= (int)str[i] & 0x3f;
- }
-
- return unichar;
-}
-
-/* expected size used to encode one unicode char */
-static int utf8_unichar_to_encoded_len(int unichar)
-{
- if (unichar < 0x80)
- return 1;
- if (unichar < 0x800)
- return 2;
- if (unichar < 0x10000)
- return 3;
- if (unichar < 0x200000)
- return 4;
- if (unichar < 0x4000000)
- return 5;
- return 6;
-}
-
-/* check if unicode char has a valid numeric range */
-static int utf8_unichar_valid_range(int unichar)
-{
- if (unichar > 0x10ffff)
- return 0;
- if ((unichar & 0xfffff800) == 0xd800)
- return 0;
- if ((unichar > 0xfdcf) && (unichar < 0xfdf0))
- return 0;
- if ((unichar & 0xffff) == 0xffff)
- return 0;
- return 1;
-}
-
-/* validate one encoded unicode char and return its length */
-static int utf8_encoded_valid_unichar(const char *str)
-{
- int len;
- int unichar;
- int i;
-
- len = utf8_encoded_expected_len(str);
- if (len == 0)
- return -1;
-
- /* ascii is valid */
- if (len == 1)
- return 1;
-
- /* check if expected encoded chars are available */
- for (i = 0; i < len; i++)
- if ((str[i] & 0x80) != 0x80)
- return -1;
-
- unichar = utf8_encoded_to_unichar(str);
-
- /* check if encoded length matches encoded value */
- if (utf8_unichar_to_encoded_len(unichar) != len)
- return -1;
-
- /* check if value has valid range */
- if (!utf8_unichar_valid_range(unichar))
- return -1;
-
- return len;
-}
-
-/* allow chars in whitelist, plain ascii, hex-escaping and valid utf8 */
-int replace_chars(char *str, const char *white)
-{
- size_t i = 0;
- int replaced = 0;
-
- while (str[i] != '\0') {
- int len;
-
- /* accept whitelist */
- if (white != NULL && strchr(white, str[i]) != NULL) {
- i++;
- continue;
- }
-
- /* accept plain ascii char */
- if ((str[i] >= '0' && str[i] <= '9') ||
- (str[i] >= 'A' && str[i] <= 'Z') ||
- (str[i] >= 'a' && str[i] <= 'z')) {
- i++;
- continue;
- }
-
- /* accept hex encoding */
- if (str[i] == '\\' && str[i+1] == 'x') {
- i += 2;
- continue;
- }
-
- /* accept valid utf8 */
- len = utf8_encoded_valid_unichar(&str[i]);
- if (len > 1) {
- i += len;
- continue;
- }
-
- /* if space is allowed, replace whitespace with ordinary space */
- if (isspace(str[i]) && strchr(white, ' ') != NULL) {
- str[i] = ' ';
- i++;
- replaced++;
- continue;
- }
-
- /* everything else is replaced with '_' */
- str[i] = '_';
- i++;
- replaced++;
- }
-
- return replaced;
-}
switch (option) {
case 'l':
case 'l' + 256:
- i = log_priority(optarg);
+ i = util_log_priority(optarg);
if (i < 0) {
fprintf(stderr, "invalid number '%s'\n", optarg);
goto exit;
}
- udev_ctrl_send_set_log_level(uctrl, log_priority(optarg));
+ udev_ctrl_send_set_log_level(uctrl, util_log_priority(optarg));
rc = 0;
break;
case 's':
"this will stop working in a future release\n");
if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
- udev_ctrl_send_set_log_level(uctrl, log_priority(&arg[strlen("log_priority=")]));
+ udev_ctrl_send_set_log_level(uctrl, util_log_priority(&arg[strlen("log_priority=")]));
rc = 0;
goto exit;
} else if (!strcmp(arg, "stop_exec_queue")) {
strlcpy(name, &optarg[strlen(udev_get_dev_path(udev))+1], sizeof(name));
else
strlcpy(name, optarg, sizeof(name));
- remove_trailing_chars(name, '/');
+ util_remove_trailing_chars(name, '/');
dbg(udev, "name: %s\n", name);
break;
case 'p':
strlcpy(path, &optarg[strlen(udev_get_sys_path(udev))], sizeof(path));
else
strlcpy(path, optarg, sizeof(path));
- remove_trailing_chars(path, '/');
+ util_remove_trailing_chars(path, '/');
/* possibly resolve to real devpath */
if (sysfs_resolve_link(udev, path, sizeof(path)) != 0) {
strlcat(path, name_loop->name, sizeof(path));
strlcat(path, " ", sizeof(path));
}
- remove_trailing_chars(path, ' ');
+ util_remove_trailing_chars(path, ' ');
if (path[0] != '\0') {
bufpos += snprintf(&buf[bufpos], sizeof(buf)-1, "DEVLINKS=%s", path);
bufpos++;
if (size < 0)
return 0;
value[size] = '\0';
- remove_trailing_chars(value, '\n');
+ util_remove_trailing_chars(value, '\n');
/* match if attribute value matches */
if (fnmatch(match_value, value, 0) == 0)
if(start >= sizeof(device))
start = sizeof(device) - 1;
strlcat(device, dent->d_name, sizeof(device));
- path_decode(&device[start]);
+ util_path_decode(&device[start]);
device_list_insert(udev, device);
}
closedir(dir);
strlcat(filename_failed, "/", sizeof(filename_failed));
start = strlcat(filename_failed, ".udev/failed/", sizeof(filename_failed));
strlcat(filename_failed, msg->devpath, sizeof(filename_failed));
- path_encode(&filename_failed[start], sizeof(filename_failed) - start);
+ util_path_encode(&filename_failed[start], sizeof(filename_failed) - start);
switch (state) {
case EVENT_QUEUED:
strlcat(filename_failed_old, "/", sizeof(filename_failed_old));
start = strlcat(filename_failed_old, ".udev/failed/", sizeof(filename_failed_old));
strlcat(filename_failed_old, msg->devpath_old, sizeof(filename_failed_old));
- path_encode(&filename_failed_old[start], sizeof(filename) - start);
+ util_path_encode(&filename_failed_old[start], sizeof(filename) - start);
if (rename(filename_failed_old, filename_failed) == 0)
info(msg->udev, "renamed devpath, moved failed state of '%s' to %s'\n",