From: Ryan Bloom Date: Sat, 20 Jan 2001 06:05:15 +0000 (+0000) Subject: Move initgroupgs, ap_uname2id and ap_gname2id from util.c to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=68abccae46835f0dba38f436ab3e25cfa07f9313;p=apache Move initgroupgs, ap_uname2id and ap_gname2id from util.c to mpm_common.c. These functions are only valid on some platforms, so they should not be in the main-line code. These functions are also not portable to non-unix platforms, so they don't really belong in APR. Since they are only used in MPMs, for right now, I am moving them to mpm_common.c git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87755 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 74d4447e4f..a4fc6095e8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ Changes with Apache 2.0b1 + *) Move initgroupgs, ap_uname2id and ap_gname2id from util.c to + mpm_common.c. These functions are only valid on some platforms, + so they should not be in the main-line code. [Ryan Bloom] + *) Remove ap_chdir_file(). This function is not thread-safe, and nobody is currently using it. [Ryan Bloom] diff --git a/include/httpd.h b/include/httpd.h index 388a5d3601..5c03a75797 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -1505,20 +1505,6 @@ AP_DECLARE(int) ap_rind(const char *str, char c); AP_DECLARE(char *) ap_escape_quotes(apr_pool_t *p, const char *instring); /* Misc system hackery */ -/** - * Convert a username to a numeric ID - * @param name The name to convert - * @return The user id corresponding to a name - * @deffunc uid_t ap_uname2id(const char *name) - */ -AP_DECLARE(uid_t) ap_uname2id(const char *name); -/** - * Convert a group name to a numeric ID - * @param name The name to convert - * @return The group id corresponding to a name - * @deffunc gid_t ap_gname2id(const char *name) - */ -AP_DECLARE(gid_t) ap_gname2id(const char *name); /** * Given the name of an object in the file system determine if it is a directory * @param p The pool to allocate out of diff --git a/include/mpm_common.h b/include/mpm_common.h index dc96d38f49..9ac37754f7 100644 --- a/include/mpm_common.h +++ b/include/mpm_common.h @@ -128,6 +128,20 @@ void ap_sock_disable_nagle(apr_socket_t *s); #define ap_sock_disable_nagle(s) /* NOOP */ #endif +/** + * Convert a username to a numeric ID + * @param name The name to convert + * @return The user id corresponding to a name + * @deffunc uid_t ap_uname2id(const char *name) + */ +AP_DECLARE(uid_t) ap_uname2id(const char *name); +/** + * Convert a group name to a numeric ID + * @param name The name to convert + * @return The group id corresponding to a name + * @deffunc gid_t ap_gname2id(const char *name) + */ +AP_DECLARE(gid_t) ap_gname2id(const char *name); #define AP_MPM_HARD_LIMITS_FILE "src/" APACHE_MPM_DIR "/mpm_default.h" diff --git a/os/unix/unixd.c b/os/unix/unixd.c index 1db01cddf6..dc2eb2def2 100644 --- a/os/unix/unixd.c +++ b/os/unix/unixd.c @@ -63,6 +63,7 @@ #include "http_main.h" #include "http_log.h" #include "unixd.h" +#include "mpm_common.h" #include "os.h" #include "ap_mpm.h" #include "apr_thread_proc.h" diff --git a/server/mpm_common.c b/server/mpm_common.c index 8708a10c91..375eadd791 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -74,6 +74,7 @@ #include "httpd.h" #include "http_config.h" #include "http_log.h" +#include "http_main.h" #include "mpm.h" #include "mpm_common.h" @@ -276,3 +277,62 @@ void ap_sock_disable_nagle(apr_socket_t *s) } } #endif + +AP_DECLARE(uid_t) ap_uname2id(const char *name) +{ + struct passwd *ent; + + if (name[0] == '#') + return (atoi(&name[1])); + + if (!(ent = getpwnam(name))) { ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad user name %s", ap_server_argv0, name); + exit(1); + } + return (ent->pw_uid); +} + +AP_DECLARE(gid_t) ap_gname2id(const char *name) +{ + struct group *ent; + + if (name[0] == '#') + return (atoi(&name[1])); + + if (!(ent = getgrnam(name))) { + ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad group name %s", ap_server_argv0, name); exit(1); + } + return (ent->gr_gid); +} + +#ifndef HAVE_INITGROUPS +int initgroups(const char *name, gid_t basegid) +{ +#if defined(QNX) || defined(MPE) || defined(BEOS) || defined(_OSD_POSIX) || defined(TPF) || defined(__TANDEM) || defined(OS2) || defined(WIN32) +/* QNX, MPE and BeOS do not appear to support supplementary groups. */ + return 0; +#else /* ndef QNX */ + gid_t groups[NGROUPS_MAX]; + struct group *g; + int index = 0; + + setgrent(); + + groups[index++] = basegid; + + while (index < NGROUPS_MAX && ((g = getgrent()) != NULL)) + if (g->gr_gid != basegid) { + char **names; + + for (names = g->gr_mem; *names != NULL; ++names) + if (!strcmp(*names, name)) + groups[index++] = g->gr_gid; + } + + endgrent(); + + return setgroups(index, groups); +#endif /* def QNX */ +} +#endif /* def NEED_INITGROUPS */ + + diff --git a/server/util.c b/server/util.c index 3c273ca057..891e3112ed 100644 --- a/server/util.c +++ b/server/util.c @@ -1728,37 +1728,6 @@ AP_DECLARE(int) ap_is_url(const char *u) return (x ? 1 : 0); /* If the first character is ':', it's broken, too */ } -#ifndef HAVE_INITGROUPS -int initgroups(const char *name, gid_t basegid) -{ -#if defined(QNX) || defined(MPE) || defined(BEOS) || defined(_OSD_POSIX) || defined(TPF) || defined(__TANDEM) || defined(OS2) || defined(WIN32) -/* QNX, MPE and BeOS do not appear to support supplementary groups. */ - return 0; -#else /* ndef QNX */ - gid_t groups[NGROUPS_MAX]; - struct group *g; - int index = 0; - - setgrent(); - - groups[index++] = basegid; - - while (index < NGROUPS_MAX && ((g = getgrent()) != NULL)) - if (g->gr_gid != basegid) { - char **names; - - for (names = g->gr_mem; *names != NULL; ++names) - if (!strcmp(*names, name)) - groups[index++] = g->gr_gid; - } - - endgrent(); - - return setgroups(index, groups); -#endif /* def QNX */ -} -#endif /* def NEED_INITGROUPS */ - AP_DECLARE(int) ap_ind(const char *s, char c) { register int x; @@ -1789,43 +1758,6 @@ AP_DECLARE(void) ap_str_tolower(char *str) } } -AP_DECLARE(uid_t) ap_uname2id(const char *name) -{ -#ifdef WIN32 - return (1); -#else - struct passwd *ent; - - if (name[0] == '#') - return (atoi(&name[1])); - - if (!(ent = getpwnam(name))) { - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad user name %s", ap_server_argv0, name); - exit(1); - } - return (ent->pw_uid); -#endif -} - -AP_DECLARE(gid_t) ap_gname2id(const char *name) -{ -#ifdef WIN32 - return (1); -#else - struct group *ent; - - if (name[0] == '#') - return (atoi(&name[1])); - - if (!(ent = getgrnam(name))) { - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s: bad group name %s", ap_server_argv0, name); - exit(1); - } - return (ent->gr_gid); -#endif -} - - static char *find_fqdn(apr_pool_t *a, struct hostent *p) { int x;