aboutsummaryrefslogtreecommitdiff
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
parent4d8ad381abe9a37a8e2abc4d27afb0dea78b4f76 (diff)
downloadbusybox-w32-cffe28ef876a6fe8a8154321bf5feb409d87cf1a.tar.gz
busybox-w32-cffe28ef876a6fe8a8154321bf5feb409d87cf1a.tar.bz2
busybox-w32-cffe28ef876a6fe8a8154321bf5feb409d87cf1a.zip
libbb: add sketch of tentative 'better' passwd/group API
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-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,
110 return xname2id(s); 110 return xname2id(s);
111 return r; 111 return r;
112} 112}
113
114/* Experimental "mallocing" API.
115 * The goal is nice: "we want to support a case when "guests" group is very large"
116 * but the code is butt-ugly.
117 */
118#if 0
119static char *find_latest(char last, char *cp)
120{
121 if (!cp)
122 return last;
123 cp += strlen(cp) + 1;
124 if (last < cp)
125 last = cp;
126 return last;
127}
128
129struct group* FAST_FUNC xmalloc_getgrnam(const char *name)
130{
131 struct {
132 struct group gr;
133 // May still be not enough!
134 char buf[64*1024 - sizeof(struct group) - 16];
135 } *s;
136 struct group *grp;
137 int r;
138 char *last;
139 char **gr_mem;
140
141 s = xmalloc(sizeof(*s));
142 r = getgrnam_r(name, &s->gr, s->buf, sizeof(s->buf), &grp);
143 if (!grp) {
144 free(s);
145 return grp;
146 }
147 last = find_latest(s->buf, grp->gr_name);
148 last = find_latest(last, grp->gr_passwd);
149 gr_mem = grp->gr_mem;
150 while (*gr_mem)
151 last = find_latest(last, *gr_mem++);
152 gr_mem++; /* points past NULL */
153 if (last < (char*)gr_mem)
154 last = (char*)gr_mem;
155//FIXME: what if we get not only truncated, but also moved here?
156// grp->gr_name pointer and friends are invalid now!!!
157 s = xrealloc(s, last - (char*)s);
158 return grp;
159}
160#endif