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
This commit is contained in:
Ryan Bloom
2001-01-20 06:05:15 +00:00
parent b610678807
commit 86a67eff47
6 changed files with 79 additions and 82 deletions

View File

@ -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]

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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 */

View File

@ -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;