httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jfcl...@apache.org
Subject cvs commit: httpd-2.0/os/unix os.h unixd.c
Date Fri, 01 Oct 2004 16:03:09 GMT
jfclere     2004/10/01 09:03:09

  Modified:    os       config.m4
               os/unix  os.h unixd.c
  Log:
  Move the few BS2000 specific in unixd.c
  
  Revision  Changes    Path
  1.14      +1 -1      httpd-2.0/os/config.m4
  
  Index: config.m4
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/os/config.m4,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- config.m4	2 Dec 2002 13:40:27 -0000	1.13
  +++ config.m4	1 Oct 2004 16:03:08 -0000	1.14
  @@ -11,7 +11,7 @@
     ;;
   bs2000*)
     OS="unix"
  -  OS_DIR=bs2000  # only the OS_DIR is platform specific.
  +  OS_DIR=$OS
     ;;
   *cygwin*)
     OS="cygwin"
  
  
  
  1.24      +4 -0      httpd-2.0/os/unix/os.h
  
  Index: os.h
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/os/unix/os.h,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- os.h	9 Feb 2004 20:40:49 -0000	1.23
  +++ os.h	1 Oct 2004 16:03:08 -0000	1.24
  @@ -23,4 +23,8 @@
   #define PLATFORM "Unix"
   #endif
   
  +#ifdef _OSD_POSIX
  +pid_t os_fork(const char *user);
  +#endif
  +
   #endif	/* !APACHE_OS_H */
  
  
  
  1.70      +130 -0    httpd-2.0/os/unix/unixd.c
  
  Index: unixd.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/os/unix/unixd.c,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- unixd.c	24 Apr 2004 19:42:52 -0000	1.69
  +++ unixd.c	1 Oct 2004 16:03:08 -0000	1.70
  @@ -457,11 +457,26 @@
   {
       apr_socket_t *csd;
       apr_status_t status;
  +#ifdef _OSD_POSIX
  +    int sockdes;
  +#endif
   
       *accepted = NULL;
       status = apr_socket_accept(&csd, lr->sd, ptrans);
       if (status == APR_SUCCESS) { 
           *accepted = csd;
  +#ifdef _OSD_POSIX
  +        apr_os_sock_get(&sockdes, csd);
  +        if (sockdes >= FD_SETSIZE) {
  +            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
  +                         "new file descriptor %d is too large; you probably need "
  +                         "to rebuild Apache with a larger FD_SETSIZE "
  +                         "(currently %d)",
  +                         sockdes, FD_SETSIZE);
  +            apr_socket_close(csd);
  +            return APR_EINTR;
  +        }
  +#endif
           return APR_SUCCESS;
       }
   
  @@ -584,4 +599,119 @@
       }
       return status;
   }
  +
  +
  +#ifdef _OSD_POSIX
  +
  +#include "apr_lib.h"
  +
  +#define USER_LEN 8
  +
  +typedef enum
  +{
  +    bs2_unknown,     /* not initialized yet. */
  +    bs2_noFORK,      /* no fork() because -X flag was specified */
  +    bs2_FORK,        /* only fork() because uid != 0 */
  +    bs2_UFORK        /* Normally, ufork() is used to switch identities. */
  +} bs2_ForkType;
  +
  +static bs2_ForkType forktype = bs2_unknown;
  +
  +
  +static void ap_str_toupper(char *str)
  +{
  +    while (*str) {
  +	*str = apr_toupper(*str);
  +	++str;
  +    }
  +}
  +
  +/* Determine the method for forking off a child in such a way as to
  + * set both the POSIX and BS2000 user id's to the unprivileged user.
  + */
  +static bs2_ForkType os_forktype(int one_process)
  +{
  +    /* have we checked the OS version before? If yes return the previous
  +     * result - the OS release isn't going to change suddenly!
  +     */
  +    if (forktype == bs2_unknown) {
  +        /* not initialized yet */
  +
  +        /* No fork if the one_process option was set */
  +        if (one_process) {
  +            forktype = bs2_noFORK;
  +        }
  +        /* If the user is unprivileged, use the normal fork() only. */
  +        else if (getuid() != 0) {
  +            forktype = bs2_FORK;
  +        }
  +        else
  +            forktype = bs2_UFORK;
  +    }
  +    return forktype;
  +}
  +
  +
  +
  +/* This routine complements the setuid() call: it causes the BS2000 job
  + * environment to be switched to the target user's user id.
  + * That is important if CGI scripts try to execute native BS2000 commands.
  + */
  +int os_init_job_environment(server_rec *server, const char *user_name, int one_process)
  +{
  +    bs2_ForkType            type = os_forktype(one_process);
  +
  +    /* We can be sure that no change to uid==0 is possible because of
  +     * the checks in http_core.c:set_user()
  +     */
  +
  +    if (one_process) {
  +
  +	type = forktype = bs2_noFORK;
  +
  +	ap_log_error(APLOG_MARK, APLOG_ERR, 0, server,
  +		     "The debug mode of Apache should only "
  +		     "be started by an unprivileged user!");
  +	return 0;
  +    }
  +
  +    return 0;
  +}
  +
  +/* BS2000 requires a "special" version of fork() before a setuid() call */
  +pid_t os_fork(const char *user)
  +{
  +    pid_t pid;
  +    char  username[USER_LEN+1];
  +
  +    switch (os_forktype(0)) {
  +
  +      case bs2_FORK:
  +	pid = fork();
  +	break;
  +
  +      case bs2_UFORK:
  +	apr_cpystrn(username, user, sizeof username);
  +
  +	/* Make user name all upper case - for some versions of ufork() */
  +	ap_str_toupper(username);
  +
  +	pid = ufork(username);
  +	if (pid == -1 && errno == EPERM) {
  +	    ap_log_error(APLOG_MARK, APLOG_EMERG, errno,
  +			 NULL, "ufork: Possible mis-configuration "
  +			 "for user %s - Aborting.", user);
  +	    exit(1);
  +	}
  +	break;
  +
  +      default:
  +	pid = 0;
  +	break;
  +    }
  +
  +    return pid;
  +}
  +
  +#endif /* _OSD_POSIX */
   
  
  
  

Mime
View raw message