Work-around for systems that don't define a "nogroup" group.

git-svn-id: https://shellinabox.googlecode.com/svn/trunk@72 0da03de8-d603-11dd-86c2-0f8696b7b6f9
This commit is contained in:
zodiac 2009-02-28 04:15:34 +00:00
parent 11cda91356
commit 86dc79030d
3 changed files with 26 additions and 6 deletions

View file

@ -1,5 +1,7 @@
2009-02-27 Markus Gutschke <markus@shellinabox.com> 2009-02-27 Markus Gutschke <markus@shellinabox.com>
* Work-around for systems that don't define a "nogroup" group.
* Remove the dependency on fdopendir, which does not exist * Remove the dependency on fdopendir, which does not exist
everywhere. everywhere.

View file

@ -95,7 +95,7 @@
#define STDC_HEADERS 1 #define STDC_HEADERS 1
/* Most recent revision number in the version control system */ /* Most recent revision number in the version control system */
#define VCS_REVISION "71" #define VCS_REVISION "72"
/* Version number of package */ /* Version number of package */
#define VERSION "2.4" #define VERSION "2.4"

View file

@ -227,12 +227,30 @@ const char *getGroupName(gid_t gid) {
gid_t getGroupId(const char *name) { gid_t getGroupId(const char *name) {
struct group grbuf, *gr; struct group grbuf, *gr;
char *buf; char *buf;
int len = sysconf(_SC_GETGR_R_SIZE_MAX); int gr_len = sysconf(_SC_GETGR_R_SIZE_MAX);
if (len <= 0) { if (gr_len <= 0) {
len = 4096; gr_len = 4096;
}
check(buf = malloc(gr_len));
if (getgrnam_r(name, &grbuf, buf, gr_len, &gr) || !gr) {
// Maybe, this system does not have a "nogroup" group. Substitute the
// group of the "nobody" user.
if (!strcmp(name, "nogroup")) {
struct passwd pwbuf, *pw;
int pw_len = sysconf(_SC_GETPW_R_SIZE_MAX);
if (pw_len <= 0) {
pw_len = 4096;
}
if (pw_len > gr_len) {
check(buf = realloc(buf, pw_len));
}
if (!getpwnam_r("nobody", &pwbuf, buf, pw_len, &pw) && pw) {
debug("Substituting \"nobody's\" primary group for \"nogroup\"");
gid_t gid = pw->pw_gid;
free(buf);
return gid;
}
} }
check(buf = malloc(len));
if (getgrnam_r(name, &grbuf, buf, len, &gr) || !gr) {
fatal("Cannot look up group \"%s\"", name); fatal("Cannot look up group \"%s\"", name);
} }
gid_t gid = gr->gr_gid; gid_t gid = gr->gr_gid;