busybox: squashed commit of merging cm-12.1
With fixes to LOCAL_C_INCLUDES for libsepol in M and fixed
some missing includes to enable building for 64 bit devices
Conflicts:
Android.mk
android/libc/arch-x86/syscalls/swapoff.S
android/libc/arch-x86/syscalls/swapon.S
android/libc/arch-x86/syscalls/sysinfo.S
android/librpc/pmap_rmt.c
android/reboot.c
include-full/copy-current.sh
include-minimal/copy-current.sh
include/platform.h
networking/interface.c
networking/nslookup.c
Change-Id: If6092fa87f3d21190db1af4f70daa150eb462660
diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c
index 4829b72..d5e651c 100644
--- a/libbb/bb_pwd.c
+++ b/libbb/bb_pwd.c
@@ -15,9 +15,31 @@
* pointers to static data (getpwuid)
*/
-struct passwd* FAST_FUNC xgetpwnam(const char *name)
+struct passwd* FAST_FUNC safegetpwnam(const char *name)
{
struct passwd *pw = getpwnam(name);
+#ifdef __BIONIC__
+ if (pw && !pw->pw_passwd) {
+ pw->pw_passwd = "";
+ }
+#endif
+ return pw;
+}
+
+struct passwd* FAST_FUNC safegetpwuid(uid_t uid)
+{
+ struct passwd *pw = getpwuid(uid);
+#ifdef __BIONIC__
+ if (pw && !pw->pw_passwd) {
+ pw->pw_passwd = "";
+ }
+#endif
+ return pw;
+}
+
+struct passwd* FAST_FUNC xgetpwnam(const char *name)
+{
+ struct passwd *pw = safegetpwnam(name);
if (!pw)
bb_error_msg_and_die("unknown user %s", name);
return pw;
@@ -31,10 +53,9 @@
return gr;
}
-
struct passwd* FAST_FUNC xgetpwuid(uid_t uid)
{
- struct passwd *pw = getpwuid(uid);
+ struct passwd *pw = safegetpwuid(uid);
if (!pw)
bb_error_msg_and_die("unknown uid %u", (unsigned)uid);
return pw;
@@ -110,3 +131,51 @@
return xname2id(s);
return r;
}
+
+/* Experimental "mallocing" API.
+ * The goal is nice: "we want to support a case when "guests" group is very large"
+ * but the code is butt-ugly.
+ */
+#if 0
+static char *find_latest(char last, char *cp)
+{
+ if (!cp)
+ return last;
+ cp += strlen(cp) + 1;
+ if (last < cp)
+ last = cp;
+ return last;
+}
+
+struct group* FAST_FUNC xmalloc_getgrnam(const char *name)
+{
+ struct {
+ struct group gr;
+ // May still be not enough!
+ char buf[64*1024 - sizeof(struct group) - 16];
+ } *s;
+ struct group *grp;
+ int r;
+ char *last;
+ char **gr_mem;
+
+ s = xmalloc(sizeof(*s));
+ r = getgrnam_r(name, &s->gr, s->buf, sizeof(s->buf), &grp);
+ if (!grp) {
+ free(s);
+ return grp;
+ }
+ last = find_latest(s->buf, grp->gr_name);
+ last = find_latest(last, grp->gr_passwd);
+ gr_mem = grp->gr_mem;
+ while (*gr_mem)
+ last = find_latest(last, *gr_mem++);
+ gr_mem++; /* points past NULL */
+ if (last < (char*)gr_mem)
+ last = (char*)gr_mem;
+//FIXME: what if we get not only truncated, but also moved here?
+// grp->gr_name pointer and friends are invalid now!!!
+ s = xrealloc(s, last - (char*)s);
+ return grp;
+}
+#endif