#include <fcntl.h>
#include <sys/types.h>
-#include "../udev_libc_wrapper.h"
-#include "../udev.h"
-#include "../udev_utils.h"
-#include "../logging.h"
-
+#include "udev_libc_wrapper.h"
+#include "udev.h"
+#include "udev_utils.h"
+#include "logging.h"
#ifdef __KLIBC__
#define __OWN_USERDB_PARSER__
#endif
+
+#ifdef __GLIBC__
+#define __OWN_STRLCPYCAT__
+#endif
+
#ifdef USE_STATIC
#define __OWN_USERDB_PARSER__
#endif
-#ifndef __OWN_USERDB_PARSER__
+#ifdef __OWN_STRLCPYCAT__
+size_t strlcpy(char *dst, const char *src, size_t size)
+{
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
+
+ while ((ch = *p++)) {
+ if (bytes+1 < size)
+ *q++ = ch;
+ bytes++;
+ }
+
+ /* If size == 0 there is no space for a final null... */
+ if (size)
+ *q = '\0';
+
+ return bytes;
+}
+size_t strlcat(char *dst, const char *src, size_t size)
+{
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
+
+ while (bytes < size && *q) {
+ q++;
+ bytes++;
+ }
+ if (bytes == size)
+ return (bytes + strlen(src));
+
+ while ((ch = *p++)) {
+ if (bytes+1 < size)
+ *q++ = ch;
+ bytes++;
+ }
+
+ *q = '\0';
+ return bytes;
+}
+#endif /* __OWN_STRLCPYCAT__ */
+
+#ifndef __OWN_USERDB_PARSER__
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
dbg("can't open '%s' as db file", dbfile);
return 0;
}
- dbg("reading '%s' as db file", dbfile);
+ dbg("search '%s' in '%s'", uname, dbfile);
/* loop through the whole file */
cur = 0;
bufline = &buf[cur];
cur += count+1;
- if (count >= LINE_SIZE)
+ if (count >= sizeof(line))
continue;
- strncpy(line, bufline, count);
- line[count] = '\0';
+ memcpy(line, bufline, count-1);
+ line[count-1] = '\0';
pos = line;
/* get name */
id = get_id_by_name(group, GROUP_FILE);
return (gid_t) id;
}
-
#endif /* __OWN_USERDB_PARSER__ */