aboutsummaryrefslogtreecommitdiffstats
path: root/ports/darwin
diff options
context:
space:
mode:
authorSeebs <seebs@seebs.net>2018-01-16 19:11:51 -0600
committerSeebs <seebs@seebs.net>2018-01-16 19:11:51 -0600
commitfffb4fb3be46911e8725dae229f8a4a07ecd9ba8 (patch)
treeaef515c5bc367493824f993fba54c4a2f8ac603d /ports/darwin
parentbbebd1e85f4b3f30a355e8721052c568e8408cfc (diff)
downloadpseudo-fffb4fb3be46911e8725dae229f8a4a07ecd9ba8.tar.gz
pseudo-fffb4fb3be46911e8725dae229f8a4a07ecd9ba8.tar.bz2
pseudo-fffb4fb3be46911e8725dae229f8a4a07ecd9ba8.zip
Handle long lines in /etc/group
This allows the pseudo /etc/group to contain extremely long lines, e.g. when a group has a lot of members. Without this, chown and chgrp fail for group names that occur after such long lines. Signed-off-by: Zoltán Böszörményi <zboszor@pr.hu> Signed-off-by: Seebs <seebs@seebs.net> --- ports/darwin/guts/getgrouplist.c | 54 +++++++++++++++++++++++++++----------- ports/linux/guts/getgrouplist.c | 54 +++++++++++++++++++++++++++----------- ports/uids_generic/guts/getgrent.c | 26 +++++++++++++++--- ports/uids_generic/guts/getgrgid.c | 26 +++++++++++++++--- ports/uids_generic/guts/getgrnam.c | 25 +++++++++++++++--- 5 files changed, 146 insertions(+), 39 deletions(-)
Diffstat (limited to 'ports/darwin')
-rw-r--r--ports/darwin/guts/getgrouplist.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/ports/darwin/guts/getgrouplist.c b/ports/darwin/guts/getgrouplist.c
index 85fccc9..c5950bd 100644
--- a/ports/darwin/guts/getgrouplist.c
+++ b/ports/darwin/guts/getgrouplist.c
@@ -9,23 +9,47 @@
int found = 0;
int found_group = 0;
- char buf[PSEUDO_PWD_MAX];
- struct group grp, *gbuf = &grp;
-
- setgrent();
- while ((rc = wrap_getgrent_r(gbuf, buf, PSEUDO_PWD_MAX, &gbuf)) == 0) {
- int i = 0;
- for (i = 0; gbuf->gr_mem[i]; ++i) {
- if (!strcmp(gbuf->gr_mem[i], name)) {
- if (found < *ngroups)
- groups[found] = gbuf->gr_gid;
- ++found;
- if ((int) gbuf->gr_gid == basegid)
- found_group = 1;
+ size_t buflen = PSEUDO_PWD_MAX;
+ char *buf = NULL;
+ struct group grp;
+
+ rc = ERANGE;
+
+ do {
+ struct group *gbuf = &grp;
+ char *new_buf = buf;
+
+ if (rc == ERANGE)
+ new_buf = realloc(buf, buflen);
+
+ if (!new_buf) {
+ rc = ENOMEM;
+ break;
+ }
+
+ buf = new_buf;
+
+ found = 0;
+ found_group = 0;
+ setgrent();
+ while ((rc = wrap_getgrent_r(gbuf, buf, buflen, &gbuf)) == 0) {
+ int i = 0;
+ for (i = 0; gbuf->gr_mem[i]; ++i) {
+ if (!strcmp(gbuf->gr_mem[i], name)) {
+ if (found < *ngroups)
+ groups[found] = gbuf->gr_gid;
+ ++found;
+ if ((int) gbuf->gr_gid == basegid)
+ found_group = 1;
+ }
}
}
- }
- endgrent();
+ endgrent();
+
+ if (rc == ERANGE)
+ buflen = buflen << 1;
+ } while (rc == ERANGE);
+ free(buf);
if (!found_group) {
if (found < *ngroups)
groups[found] = basegid;