1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000 The Apache Software Foundation. All rights
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Apache Software Foundation (http://www.apache.org/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
26 * 4. The names "Apache" and "Apache Software Foundation" must
27 * not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact apache@apache.org.
31 * 5. Products derived from this software may not be called "Apache",
32 * nor may "Apache" appear in their name, without prior written
33 * permission of the Apache Software Foundation.
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation. For more
51 * information on the Apache Software Foundation, please see
52 * <http://www.apache.org/>.
54 * Portions of this software are based upon public domain software
55 * originally written at the National Center for Supercomputing Applications,
56 * University of Illinois, Urbana-Champaign.
60 #include "http_config.h"
61 #include "http_main.h"
65 beosd_config_rec beosd_config;
67 void beosd_detach(void)
73 RAISE_SIGSTOP(DETACH);
75 if ((pgrp = setsid()) == -1) {
77 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
78 "%s: setsid failed", ap_server_argv0);
82 /* close out the standard file descriptors */
83 if (freopen("/dev/null", "r", stdin) == NULL) {
84 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
85 "%s: unable to replace stdin with /dev/null: %s",
86 ap_server_argv0, strerror(errno));
87 /* continue anyhow -- note we can't close out descriptor 0 because we
88 * have nothing to replace it with, and if we didn't have a descriptor
89 * 0 the next file would be created with that value ... leading to
93 if (freopen("/dev/null", "w", stdout) == NULL) {
94 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
95 "%s: unable to replace stdout with /dev/null: %s",
96 ap_server_argv0, strerror(errno));
98 /* stderr is a tricky one, we really want it to be the error_log,
99 * but we haven't opened that yet. So leave it alone for now and it'll
100 * be reopened moments later.
104 /* Set group privileges.
106 * Note that we use the username as set in the config files, rather than
107 * the lookup of to uid --- the same uid may have multiple passwd entries,
108 * with different sets of groups for each.
111 static int set_group_privs(void)
113 #if B_BEOS_VERSION < 0x0460
118 /* Get username if passed as a uid */
120 if (beosd_config.user_name[0] == '#') {
122 uid_t uid = atoi(&beosd_config.user_name[1]);
124 if ((ent = getpwuid(uid)) == NULL) {
125 ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
126 "getpwuid: couldn't determine user name from uid %u, "
127 "you probably need to modify the User directive",
135 name = beosd_config.user_name;
137 if (setgid(beosd_config.group_id) == -1) {
138 ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
139 "setgid: unable to set group id to Group %u",
140 (unsigned)beosd_config.group_id);
144 /* Reset `groups' attributes. */
146 if (initgroups(name, beosd_config.group_id) == -1) {
147 ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
148 "initgroups: unable to set groups for User %s "
149 "and Group %u", name, (unsigned)beosd_config.group_id);
158 int beosd_setup_child(void)
160 /* TODO: revisit the whole issue of users/groups for BeOS as
161 * R4.5.2 and below doesn't really have much concept of them.
168 const char *beosd_set_user(cmd_parms *cmd, void *dummy, char *arg)
170 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
175 beosd_config.user_name = arg;
176 beosd_config.user_id = ap_uname2id(arg);
177 #if !defined (BIG_SECURITY_HOLE) && !defined (OS2)
178 if (beosd_config.user_id == 0) {
179 return "Error:\tApache has not been designed to serve pages while\n"
180 "\trunning as root. There are known race conditions that\n"
181 "\twill allow any local user to read any file on the system.\n"
182 "\tIf you still desire to serve pages as root then\n"
183 "\tadd -DBIG_SECURITY_HOLE to the EXTRA_CFLAGS line in your\n"
184 "\tsrc/Configuration file and rebuild the server. It is\n"
185 "\tstrongly suggested that you instead modify the User\n"
186 "\tdirective in your httpd.conf file to list a non-root\n"
194 const char *beosd_set_group(cmd_parms *cmd, void *dummy, char *arg)
196 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
201 beosd_config.group_id = ap_gname2id(arg);
206 void beosd_pre_config(void)
208 beosd_config.user_name = DEFAULT_USER;
209 beosd_config.user_id = ap_uname2id(DEFAULT_USER);
210 beosd_config.group_id = ap_gname2id(DEFAULT_GROUP);