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:
parent
11cda91356
commit
86dc79030d
3 changed files with 26 additions and 6 deletions
|
@ -1,5 +1,7 @@
|
|||
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
|
||||
everywhere.
|
||||
|
||||
|
|
2
config.h
2
config.h
|
@ -95,7 +95,7 @@
|
|||
#define STDC_HEADERS 1
|
||||
|
||||
/* Most recent revision number in the version control system */
|
||||
#define VCS_REVISION "71"
|
||||
#define VCS_REVISION "72"
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "2.4"
|
||||
|
|
|
@ -227,12 +227,30 @@ const char *getGroupName(gid_t gid) {
|
|||
gid_t getGroupId(const char *name) {
|
||||
struct group grbuf, *gr;
|
||||
char *buf;
|
||||
int len = sysconf(_SC_GETGR_R_SIZE_MAX);
|
||||
if (len <= 0) {
|
||||
len = 4096;
|
||||
int gr_len = sysconf(_SC_GETGR_R_SIZE_MAX);
|
||||
if (gr_len <= 0) {
|
||||
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);
|
||||
}
|
||||
gid_t gid = gr->gr_gid;
|
||||
|
|
Loading…
Reference in a new issue