os.c revision e63f7c6f556aef66ff81fb128605f9eadf1ddcd9
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <config.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <syslog.h>
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
#ifdef HAVE_LINUXTHREADS
#endif
#ifdef HAVE_LINUX_CAPABILITY_H
#include <linux/capability.h>
#ifndef SYS_capset
#define SYS_capset __NR_capset
#endif
static void
linux_setcaps(unsigned int caps) {
struct __user_cap_header_struct caphead;
struct __user_cap_data_struct cap;
if (getuid() != 0)
return;
}
static void
linux_initialprivs(void) {
unsigned int caps;
/*
* Drop all privileges except the abilities to bind() to privileged
* ports and chroot().
*/
caps = 0;
/*
* XXX We might want to add CAP_SYS_RESOURCE, though it's not
* clear it would work right given the way linuxthreads work.
*/
}
static void
linux_minprivs(void) {
unsigned int caps;
/*
* Drop all privileges except the abilities to bind() to privileged
* ports.
*/
caps = 0;
}
#endif /* HAVE_LINUX_CAPABILITY_H */
static void
setup_syslog(void) {
int options;
#ifdef LOG_NDELAY
options |= LOG_NDELAY;
#endif
}
void
ns_os_init(void) {
setup_syslog();
#ifdef HAVE_LINUX_CAPABILITY_H
#endif
#ifdef HAVE_LINUXTHREADS
#endif
}
void
ns_os_daemonize(void) {
int fd;
if (pid == -1)
if (pid != 0)
_exit(0);
/*
* We're the child.
*/
#ifdef HAVE_LINUXTHREADS
#endif
if (setsid() == -1)
/*
* on even if it fails.
*/
if (fd != -1) {
if (fd != STDIN_FILENO &&
fd != STDOUT_FILENO &&
fd != STDERR_FILENO)
}
}
static isc_boolean_t
all_digits(const char *s) {
if (*s == '\0')
return (ISC_FALSE);
while (*s != '\0') {
if (!isdigit((*s)&0xff))
return (ISC_FALSE);
s++;
}
return (ISC_TRUE);
}
void
ns_os_chroot(const char *root) {
if (chdir("/") < 0)
}
#ifdef HAVE_LINUX_CAPABILITY_H
/*
* We must drop the chroot() capability, otherwise it could be used
* to escape.
*/
#endif
}
void
ns_os_changeuser(const char *username) {
return;
if (all_digits(username))
else
endpwent();
}
static int
return (-1);
return (-1);
}
static void
cleanup_pidfile(void) {
}
void
ns_os_writepidfile(const char *filename) {
int fd;
/*
* The caller must ensure any required synchronization.
*/
ns_main_earlyfatal("couldn't malloc '%s': %s",
/* This is safe. */
if (fd < 0)
ns_main_earlyfatal("couldn't open pid file '%s': %s",
ns_main_earlyfatal("could not fdopen() pid file '%s': %s",
#ifdef HAVE_LINUXTHREADS
#else
#endif
ns_main_earlyfatal("fprintf() to pid file '%s' failed",
filename);
ns_main_earlyfatal("fflush() to pid file '%s' failed",
filename);
}
void
ns_os_shutdown(void) {
closelog();
}