Blame modules/md/mod_md_os.c

Packit 90a5c9
/* Licensed to the Apache Software Foundation (ASF) under one or more
Packit 90a5c9
 * contributor license agreements.  See the NOTICE file distributed with
Packit 90a5c9
 * this work for additional information regarding copyright ownership.
Packit 90a5c9
 * The ASF licenses this file to You under the Apache License, Version 2.0
Packit 90a5c9
 * (the "License"); you may not use this file except in compliance with
Packit 90a5c9
 * the License.  You may obtain a copy of the License at
Packit 90a5c9
 *
Packit 90a5c9
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 90a5c9
 *
Packit 90a5c9
 * Unless required by applicable law or agreed to in writing, software
Packit 90a5c9
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 90a5c9
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 90a5c9
 * See the License for the specific language governing permissions and
Packit 90a5c9
 * limitations under the License.
Packit 90a5c9
 */
Packit 90a5c9
 
Packit 90a5c9
#include <assert.h>
Packit 90a5c9
#include <apr_strings.h>
Packit 90a5c9
Packit 90a5c9
#ifndef AP_ENABLE_EXCEPTION_HOOK
Packit 90a5c9
#define AP_ENABLE_EXCEPTION_HOOK 0
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#include <mpm_common.h>
Packit 90a5c9
#include <httpd.h>
Packit 90a5c9
#include <http_log.h>
Packit 90a5c9
#include <ap_mpm.h>
Packit 90a5c9
Packit 90a5c9
#if APR_HAVE_UNISTD_H
Packit 90a5c9
#include <unistd.h>
Packit 90a5c9
#endif
Packit 90a5c9
#ifdef WIN32
Packit 90a5c9
#include "mpm_winnt.h"
Packit 90a5c9
#endif
Packit 90a5c9
#if AP_NEED_SET_MUTEX_PERMS
Packit 90a5c9
#include "unixd.h"
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#include "md_util.h"
Packit 90a5c9
#include "mod_md_os.h"
Packit 90a5c9
Packit 90a5c9
apr_status_t md_try_chown(const char *fname, unsigned int uid, int gid, apr_pool_t *p)
Packit 90a5c9
{
Packit 3944f1
#if AP_NEED_SET_MUTEX_PERMS && HAVE_UNISTD_H
Packit 3944f1
    /* Since we only switch user when running as root, we only need to chown directories
Packit 3944f1
     * in that case. Otherwise, the server will ignore any "user/group" directives and
Packit 3944f1
     * child processes have the same privileges as the parent.
Packit 3944f1
     */
Packit 3944f1
    if (!geteuid()) {
Packit 3944f1
        if (-1 == chown(fname, (uid_t)uid, (gid_t)gid)) {
Packit 3944f1
            apr_status_t rv = APR_FROM_OS_ERROR(errno);
Packit 3944f1
            if (!APR_STATUS_IS_ENOENT(rv)) {
Packit 3944f1
                ap_log_perror(APLOG_MARK, APLOG_ERR, rv, p, APLOGNO(10082)
Packit 3944f1
                              "Can't change owner of %s", fname);
Packit 3944f1
            }
Packit 3944f1
            return rv;
Packit 90a5c9
        }
Packit 90a5c9
    }
Packit 90a5c9
    return APR_SUCCESS;
Packit 90a5c9
#else 
Packit 90a5c9
    return APR_ENOTIMPL;
Packit 90a5c9
#endif
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
apr_status_t md_make_worker_accessible(const char *fname, apr_pool_t *p)
Packit 90a5c9
{
Packit 90a5c9
    return md_try_chown(fname, ap_unixd_config.user_id, -1, p);
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
#ifdef WIN32
Packit 90a5c9
Packit 90a5c9
apr_status_t md_server_graceful(apr_pool_t *p, server_rec *s)
Packit 90a5c9
{
Packit 90a5c9
    return APR_ENOTIMPL;
Packit 90a5c9
}
Packit 90a5c9
 
Packit 90a5c9
#else
Packit 90a5c9
Packit 90a5c9
apr_status_t md_server_graceful(apr_pool_t *p, server_rec *s)
Packit 90a5c9
{ 
Packit 90a5c9
    apr_status_t rv;
Packit 90a5c9
    
Packit 90a5c9
    (void)p;
Packit 90a5c9
    (void)s;
Packit 90a5c9
    rv = (kill(getppid(), AP_SIG_GRACEFUL) < 0)? APR_ENOTIMPL : APR_SUCCESS;
Packit 90a5c9
    ap_log_error(APLOG_MARK, APLOG_TRACE1, errno, NULL, "sent signal to parent");
Packit 90a5c9
    return rv;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
#endif
Packit 90a5c9