Return-Path: Delivered-To: apmail-new-httpd-archive@apache.org Received: (qmail 84740 invoked by uid 500); 13 Nov 2000 02:14:59 -0000 Mailing-List: contact new-httpd-help@apache.org; run by ezmlm Precedence: bulk Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list new-httpd@apache.org Received: (qmail 84726 invoked from network); 13 Nov 2000 02:14:59 -0000 X-Authentication-Warning: adsl-77-241-65.rdu.bellsouth.net: trawick set sender to trawickj@bellsouth.net using -f Sender: trawick@bellsouth.net To: new-httpd@apache.org Subject: Re: [PATCH] move getpwnam hackery to APR References: From: Jeff Trawick Date: 12 Nov 2000 21:12:28 -0500 In-Reply-To: rbb@covalent.net's message of "Sun, 12 Nov 2000 09:42:47 -0800 (PST)" Message-ID: Lines: 373 User-Agent: Gnus/5.0807 (Gnus v5.8.7) Emacs/20.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N Here is the latest patch, taking into account comments from Ryan and OtherBill. ? lib/apr/user --lib/apr/user/unix/homedir.c---------------------- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ #include "apr_strings.h" #include "apr_portable.h" #include "apr_user.h" #include "apr_private.h" #ifdef HAVE_PWD_H #include #endif #if APR_HAVE_SYS_TYPES_H #include #endif apr_status_t apr_get_home_directory(char **dirname, const char *userid, apr_pool_t *p) { struct passwd *pw; #if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) struct passwd pwd; char pwbuf[512]; #endif #if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) if (!getpwnam_r(userid, &pwd, pwbuf, sizeof(pwbuf), &pw)) { #else if ((pw = getpwnam(userid)) != NULL) { #endif *dirname = apr_pstrdup(p, pw->pw_dir); } else { return errno; } return APR_SUCCESS; } ----lib/apr/user/unix/Makefile.in-------------------- RM=@RM@ CC=@CC@ RANLIB=@RANLIB@ CFLAGS=@CFLAGS@ @OPTIM@ LIBS=@LIBS@ LDFLAGS=@LDFLAGS@ $(LIBS) INCDIR=../../include INCLUDES=-I$(INCDIR) -I$(INCDIR)/arch OBJS=homedir.o .c.o: $(CC) $(CFLAGS) -c $(INCLUDES) $< all: $(OBJS) clean: $(RM) -f *.o *.a *.so distclean: clean -$(RM) -f Makefile # # We really don't expect end users to use this rule. It works only with # gcc, and rebuilds Makefile.in. You have to re-run configure after # using it. # depend: cp Makefile.in Makefile.in.bak \ && sed -ne '1,/^# DO NOT REMOVE/p' Makefile.in > Makefile.new \ && gcc -MM $(INCLUDES) $(CFLAGS) *.c >> Makefile.new \ && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' \ -e '1,$$s: $(OSDIR)/: $$(OSDIR)/:g' Makefile.new \ > Makefile.in \ && rm Makefile.new # DO NOT REMOVE homedir.o: homedir.c $(INCDIR)/apr_strings.h $(INCDIR)/apr.h \ $(INCDIR)/apr_lib.h $(INCDIR)/apr_pools.h \ $(INCDIR)/apr_thread_proc.h $(INCDIR)/apr_file_io.h \ $(INCDIR)/apr_general.h $(INCDIR)/apr_errno.h \ $(INCDIR)/apr_time.h $(INCDIR)/apr_tables.h \ $(INCDIR)/apr_portable.h $(INCDIR)/apr_network_io.h \ $(INCDIR)/apr_lock.h $(INCDIR)/apr_dso.h \ $(INCDIR)/apr_user.h $(INCDIR)/apr_private.h ? lib/apr/include/apr_user.h --------------------apr_user.h----------------- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ #ifndef APR_USER_H #define APR_USER_H #include "apr.h" #if APR_HAS_USER #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** * @package APR user id services */ /*** * Get the home directory for a specified userid. * @param dirname Pointer to new string containing directory name (on output) * @param userid The userid * @param p The pool from which to allocate the string * @deffunc apr_status_t apr_get_home_directory(char **dirname, const char *userid, apr_pool_t *p) * @tip This function is available only if APR_HAS_USER is defined. */ apr_status_t apr_get_home_directory(char **dirname, const char *userid, apr_pool_t *p); #ifdef __cplusplus } #endif #endif /* ! APR_HAS_USER */ #endif /* ! APR_USER_H */ Index: lib/apr/configure.in =================================================================== RCS file: /home/cvspublic/apache-2.0/src/lib/apr/configure.in,v retrieving revision 1.170 diff -u -r1.170 configure.in --- lib/apr/configure.in 2000/11/11 06:05:58 1.170 +++ lib/apr/configure.in 2000/11/12 22:12:08 @@ -35,7 +35,7 @@ # These added to allow default directories to be used... DEFAULT_OSDIR="unix" echo "(Default will be ${DEFAULT_OSDIR})" -MODULES="file_io network_io threadproc misc locks time mmap shmem i18n" +MODULES="file_io network_io threadproc misc locks time mmap shmem i18n user" # Most platforms use a prefix of 'lib' on their library files. LIBPREFIX='lib' @@ -265,6 +265,7 @@ AC_CHECK_HEADERS(netdb.h) AC_CHECK_HEADERS(osreldate.h) AC_CHECK_HEADERS(process.h) +AC_CHECK_HEADERS(pwd.h) AC_CHECK_HEADERS(sys/sem.h) AC_CHECK_HEADERS(signal.h, signalh="1", signalh="0") AC_CHECK_HEADERS(stdarg.h, stdargh="1", stdargh="0") Index: lib/apr/include/apr.h.in =================================================================== RCS file: /home/cvspublic/apache-2.0/src/lib/apr/include/apr.h.in,v retrieving revision 1.50 diff -u -r1.50 apr.h.in --- lib/apr/include/apr.h.in 2000/11/11 06:05:59 1.50 +++ lib/apr/include/apr.h.in 2000/11/12 22:12:09 @@ -96,6 +96,7 @@ #define APR_HAS_OTHER_CHILD @oc@ #define APR_HAS_DSO @aprdso@ #define APR_HAS_UNICODE_FS 0 +#define APR_HAS_USER 1 /* This macro tells APR that it is safe to make a file masquerade as a * socket. This is necessary, because some platforms support poll'ing Index: lib/apr/include/apr.hw =================================================================== RCS file: /home/cvspublic/apache-2.0/src/lib/apr/include/apr.hw,v retrieving revision 1.34 diff -u -r1.34 apr.hw --- lib/apr/include/apr.hw 2000/11/02 15:24:08 1.34 +++ lib/apr/include/apr.hw 2000/11/12 22:12:10 @@ -160,6 +160,8 @@ */ #define APR_HAS_UNICODE_FS 1 +#define APR_HAS_USER 0 + /* Typedefs that APR needs. */ typedef short apr_int16_t; Index: modules/standard/config.m4 =================================================================== RCS file: /home/cvspublic/apache-2.0/src/modules/standard/config.m4,v retrieving revision 1.31 diff -u -r1.31 config.m4 --- modules/standard/config.m4 2000/11/10 23:52:18 1.31 +++ modules/standard/config.m4 2000/11/12 22:12:15 @@ -25,9 +25,7 @@ APACHE_CHECK_STANDARD_MODULE(imap, internal imagemaps, , yes) APACHE_CHECK_STANDARD_MODULE(actions, Action triggering on requests, action, yes) APACHE_CHECK_STANDARD_MODULE(speling, correct common URL misspellings, , no) -APACHE_CHECK_STANDARD_MODULE(userdir, mapping of user requests, , yes, [ - AC_CHECK_FUNCS(getpwnam_r) -]) +APACHE_CHECK_STANDARD_MODULE(userdir, mapping of user requests, , yes) APACHE_CHECK_STANDARD_MODULE(suexec, set uid and gid for spawned processes, , no) APACHE_CHECK_STANDARD_MODULE(alias, translation of requests, , yes) Index: modules/standard/mod_userdir.c =================================================================== RCS file: /home/cvspublic/apache-2.0/src/modules/standard/mod_userdir.c,v retrieving revision 1.26 diff -u -r1.26 mod_userdir.c --- modules/standard/mod_userdir.c 2000/11/10 23:52:18 1.26 +++ modules/standard/mod_userdir.c 2000/11/12 22:20:58 @@ -96,6 +96,7 @@ #endif #include "apr_strings.h" +#include "apr_user.h" #include "ap_config.h" #include "httpd.h" #include "http_config.h" @@ -103,9 +104,6 @@ #ifdef HAVE_UNIX_SUEXEC #include "unixd.h" /* Contains the suexec_identity hook used on Unix */ #endif -#ifdef HAVE_PWD_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -320,29 +318,23 @@ return HTTP_MOVED_TEMPORARILY; } else { -#ifdef WIN32 - /* Need to figure out home dirs on NT */ - return DECLINED; -#else /* WIN32 */ - struct passwd *pw; - -#if APR_HAS_THREADS && defined(HAVE_GETPWNAM_R) - struct passwd pwd; - size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX); - char *buf = apr_pcalloc(r->pool, buflen); +#if APR_HAS_USER + char *homedir; - if (!getpwnam_r(w, &pwd, buf, buflen, &pw)) { -#else - if ((pw = getpwnam(w))) { -#endif -#ifdef OS2 + if (apr_get_home_directory(&homedir, w, r->pool) == APR_SUCCESS) { +#ifdef OS2 /* XXX should this OS/2 logic move to APR? */ /* Need to manually add user name for OS/2 */ - filename = apr_pstrcat(r->pool, pw->pw_dir, w, "/", userdir, NULL); + filename = apr_pstrcat(r->pool, homedir, w, "/", userdir, NULL); #else - filename = apr_pstrcat(r->pool, pw->pw_dir, "/", userdir, NULL); + filename = apr_pstrcat(r->pool, homedir, "/", userdir, NULL); #endif } -#endif /* WIN32 */ + else { + /* XXX old code ignored this error... */ + } +#else + return DECLINED; +#endif } /* -- Jeff Trawick | trawick@ibm.net | PGP public key at web site: http://www.geocities.com/SiliconValley/Park/9289/ Born in Roswell... married an alien...