aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-11-26 13:46:18 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-11-26 13:46:18 +0100
commitcffe28ef876a6fe8a8154321bf5feb409d87cf1a (patch)
tree424e34cc63705a9744eeb94cebfbb1e16381ea64 /libbb
parent4d8ad381abe9a37a8e2abc4d27afb0dea78b4f76 (diff)
downloadbusybox-cffe28ef876a6fe8a8154321bf5feb409d87cf1a.tar.gz
libbb: add sketch of tentative 'better' passwd/group API
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/bb_pwd.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c
index 4829b723a..8250cd446 100644
--- a/libbb/bb_pwd.c
+++ b/libbb/bb_pwd.c
@@ -110,3 +110,51 @@ unsigned long FAST_FUNC get_ug_id(const char *s,
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