X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_libc_wrapper.c;h=48a893cfb10040031178781434a6d7b7fa846ed2;hp=16d90913cf84606d38cf5ac794cd391b957f29d7;hb=05ec6e7507d159e5a02a82927c6571b7e516c52e;hpb=68c2c0b5b1dedfe0fd3346560999791efdf48c25 diff --git a/udev_libc_wrapper.c b/udev_libc_wrapper.c index 16d90913c..48a893cfb 100644 --- a/udev_libc_wrapper.c +++ b/udev_libc_wrapper.c @@ -25,22 +25,24 @@ #include #include #include +#include #include -#include "udev_libc_wrapper.h" #include "udev.h" -#include "udev_utils.h" -#include "logging.h" -#ifdef __KLIBC__ +#ifndef __GLIBC__ #define __OWN_USERDB_PARSER__ #endif +#ifdef __GLIBC__ +#define __OWN_STRLCPYCAT__ +#endif + #ifdef USE_STATIC #define __OWN_USERDB_PARSER__ #endif -#ifndef strlcpy +#ifdef __OWN_STRLCPYCAT__ size_t strlcpy(char *dst, const char *src, size_t size) { size_t bytes = 0; @@ -49,17 +51,18 @@ size_t strlcpy(char *dst, const char *src, size_t size) char ch; while ((ch = *p++)) { - if (bytes < size) + if (bytes+1 < size) *q++ = ch; bytes++; } - *q = '\0'; + /* If size == 0 there is no space for a final null... */ + if (size) + *q = '\0'; + return bytes; } -#endif -#ifndef strlcat size_t strlcat(char *dst, const char *src, size_t size) { size_t bytes = 0; @@ -71,9 +74,11 @@ size_t strlcat(char *dst, const char *src, size_t size) q++; bytes++; } + if (bytes == size) + return (bytes + strlen(src)); while ((ch = *p++)) { - if (bytes < size) + if (bytes+1 < size) *q++ = ch; bytes++; } @@ -81,7 +86,7 @@ size_t strlcat(char *dst, const char *src, size_t size) *q = '\0'; return bytes; } -#endif +#endif /* __OWN_STRLCPYCAT__ */ #ifndef __OWN_USERDB_PARSER__ #include @@ -95,7 +100,7 @@ uid_t lookup_user(const char *user) pw = getpwnam(user); if (pw == NULL) - dbg("specified user unknown '%s'", user); + info("specified user unknown '%s'", user); else uid = pw->pw_uid; @@ -109,7 +114,7 @@ gid_t lookup_group(const char *group) gr = getgrnam(group); if (gr == NULL) - dbg("specified group unknown '%s'", group); + info("specified group unknown '%s'", group); else gid = gr->gr_gid; @@ -137,7 +142,7 @@ static unsigned long get_id_by_name(const char *uname, const char *dbfile) char *tail; if (file_map(dbfile, &buf, &bufsize) != 0) { - dbg("can't open '%s' as db file", dbfile); + err("can't open '%s' as db file: %s", dbfile, strerror(errno)); return 0; } dbg("search '%s' in '%s'", uname, dbfile); @@ -152,7 +157,8 @@ static unsigned long get_id_by_name(const char *uname, const char *dbfile) if (count >= sizeof(line)) continue; - strlcpy(line, bufline, count); + memcpy(line, bufline, count-1); + line[count-1] = '\0'; pos = line; /* get name */