X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_libc_wrapper.c;h=1711811e83f0483fadc94e8a46a39c0876f50285;hp=d69f2ac48e11dfb0dcc01daa6125089697307b93;hb=5263fb3464fdb43b1ca0eb6e7b71eb4ff91c6a17;hpb=4f8d44c220d811352b63c65b5a66403339005aac diff --git a/udev_libc_wrapper.c b/udev_libc_wrapper.c index d69f2ac48..1711811e8 100644 --- a/udev_libc_wrapper.c +++ b/udev_libc_wrapper.c @@ -25,12 +25,10 @@ #include #include #include +#include #include -#include "udev_libc_wrapper.h" #include "udev.h" -#include "udev_utils.h" -#include "logging.h" #ifdef __KLIBC__ #define __OWN_USERDB_PARSER__ @@ -58,8 +56,10 @@ size_t strlcpy(char *dst, const char *src, size_t size) bytes++; } + /* If size == 0 there is no space for a final null... */ if (size) *q = '\0'; + return bytes; } @@ -83,8 +83,7 @@ size_t strlcat(char *dst, const char *src, size_t size) bytes++; } - if (size) - *q = '\0'; + *q = '\0'; return bytes; } #endif /* __OWN_STRLCPYCAT__ */ @@ -101,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; @@ -115,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; @@ -143,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); @@ -158,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 */