X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_libc_wrapper.c;h=35e01e619d3f5c5c1d59371f18e01fe03cb9d9c7;hp=23cb7b43168bc9ff7c3619bcf1440627f67f8b42;hb=258e77a55577f1cdf9209bb2a4add0bbee182d6e;hpb=8a4c0c32f4252efb0f0adbf5cdc0261d359cd568 diff --git a/udev_libc_wrapper.c b/udev_libc_wrapper.c index 23cb7b431..35e01e619 100644 --- a/udev_libc_wrapper.c +++ b/udev_libc_wrapper.c @@ -25,14 +25,12 @@ #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 @@ -58,7 +56,10 @@ size_t strlcpy(char *dst, const char *src, size_t size) bytes++; } - *q = '\0'; + /* If size == 0 there is no space for a final null... */ + if (size) + *q = '\0'; + return bytes; } @@ -99,7 +100,7 @@ uid_t lookup_user(const char *user) pw = getpwnam(user); if (pw == NULL) - dbg("specified user unknown '%s'", user); + err("error resolving user '%s': %s", user, strerror(errno)); else uid = pw->pw_uid; @@ -113,7 +114,7 @@ gid_t lookup_group(const char *group) gr = getgrnam(group); if (gr == NULL) - dbg("specified group unknown '%s'", group); + err("error resolving group '%s': %s", group, strerror(errno)); else gid = gr->gr_gid; @@ -141,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); @@ -156,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 */