1
/* Licensed to the Apache Software Foundation (ASF) under one or more
2
* contributor license agreements. See the NOTICE file distributed with
3
* this work for additional information regarding copyright ownership.
4
* The ASF licenses this file to You under the Apache License, Version 2.0
5
* (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
* This file will include OS specific functions which are not inlineable.
19
* Any inlineable functions should be defined in os-inline.c instead.
27
#include "http_config.h"
35
bs2_unknown, /* not initialized yet. */
36
bs2_noFORK, /* no fork() because -X flag was specified */
37
bs2_FORK, /* only fork() because uid != 0 */
38
bs2_UFORK /* Normally, ufork() is used to switch identities. */
41
static bs2_ForkType forktype = bs2_unknown;
44
static void ap_str_toupper(char *str)
47
*str = apr_toupper(*str);
52
/* Determine the method for forking off a child in such a way as to
53
* set both the POSIX and BS2000 user id's to the unprivileged user.
55
static bs2_ForkType os_forktype(int one_process)
57
/* have we checked the OS version before? If yes return the previous
58
* result - the OS release isn't going to change suddenly!
60
if (forktype == bs2_unknown) {
61
/* not initialized yet */
63
/* No fork if the one_process option was set */
65
forktype = bs2_noFORK;
67
/* If the user is unprivileged, use the normal fork() only. */
68
else if (getuid() != 0) {
79
/* This routine complements the setuid() call: it causes the BS2000 job
80
* environment to be switched to the target user's user id.
81
* That is important if CGI scripts try to execute native BS2000 commands.
83
int os_init_job_environment(server_rec *server, const char *user_name, int one_process)
85
bs2_ForkType type = os_forktype(one_process);
87
/* We can be sure that no change to uid==0 is possible because of
88
* the checks in http_core.c:set_user()
93
type = forktype = bs2_noFORK;
95
ap_log_error(APLOG_MARK, APLOG_ERR, 0, server,
96
"The debug mode of Apache should only "
97
"be started by an unprivileged user!");
104
/* BS2000 requires a "special" version of fork() before a setuid() call */
105
pid_t os_fork(const char *user)
108
char username[USER_LEN+1];
110
switch (os_forktype(0)) {
117
apr_cpystrn(username, user, sizeof username);
119
/* Make user name all upper case - for some versions of ufork() */
120
ap_str_toupper(username);
122
pid = ufork(username);
123
if (pid == -1 && errno == EPERM) {
124
ap_log_error(APLOG_MARK, APLOG_EMERG, errno,
125
NULL, "ufork: Possible mis-configuration "
126
"for user %s - Aborting.", user);
139
#else /* _OSD_POSIX */
140
void bs2000_os_is_not_here()
143
#endif /* _OSD_POSIX */