Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/dhclient/dhclient.c
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
#define whitechar(c) ((c) == ' ' || (c) == '\t') | #define whitechar(c) ((c) == ' ' || (c) == '\t') | ||||
#define borderchar(c) (alphachar(c) || digitchar(c)) | #define borderchar(c) (alphachar(c) || digitchar(c)) | ||||
#define middlechar(c) (borderchar(c) || hyphenchar(c)) | #define middlechar(c) (borderchar(c) || hyphenchar(c)) | ||||
#define domainchar(c) ((c) > 0x20 && (c) < 0x7f) | #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) | ||||
#define CLIENT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin" | #define CLIENT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin" | ||||
cap_channel_t *capsyslog; | |||||
time_t cur_time; | time_t cur_time; | ||||
time_t default_lease_time = 43200; /* 12 hours... */ | time_t default_lease_time = 43200; /* 12 hours... */ | ||||
char *path_dhclient_conf = _PATH_DHCLIENT_CONF; | char *path_dhclient_conf = _PATH_DHCLIENT_CONF; | ||||
char *path_dhclient_db = NULL; | char *path_dhclient_db = NULL; | ||||
int log_perror = 1; | int log_perror = 1; | ||||
int privfd; | int privfd; | ||||
▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Lines | die: | ||||
if (ifi->client->alias) | if (ifi->client->alias) | ||||
script_write_params("alias_", ifi->client->alias); | script_write_params("alias_", ifi->client->alias); | ||||
script_go(); | script_go(); | ||||
if (pidfile != NULL) | if (pidfile != NULL) | ||||
pidfile_remove(pidfile); | pidfile_remove(pidfile); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
static void | |||||
init_casper(void) | |||||
{ | |||||
cap_channel_t *casper; | |||||
casper = cap_init(); | |||||
if (casper == NULL) | |||||
error("unable to start casper"); | |||||
capsyslog = cap_service_open(casper, "system.syslog"); | |||||
cap_close(casper); | |||||
if (capsyslog == NULL) | |||||
error("unable to open system.syslog service"); | |||||
} | |||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
extern char *__progname; | extern char *__progname; | ||||
int ch, fd, quiet = 0, i = 0; | int ch, fd, quiet = 0, i = 0; | ||||
int pipe_fd[2]; | int pipe_fd[2]; | ||||
int immediate_daemon = 0; | int immediate_daemon = 0; | ||||
struct passwd *pw; | struct passwd *pw; | ||||
pid_t otherpid; | pid_t otherpid; | ||||
cap_rights_t rights; | cap_rights_t rights; | ||||
init_casper(); | |||||
/* Initially, log errors to stderr as well as to syslogd. */ | /* Initially, log errors to stderr as well as to syslogd. */ | ||||
openlog(__progname, LOG_PID | LOG_NDELAY, DHCPD_LOG_FACILITY); | cap_openlog(capsyslog, __progname, LOG_PID | LOG_NDELAY, DHCPD_LOG_FACILITY); | ||||
setlogmask(LOG_UPTO(LOG_DEBUG)); | cap_setlogmask(capsyslog, LOG_UPTO(LOG_DEBUG)); | ||||
while ((ch = getopt(argc, argv, "bc:dl:p:qu")) != -1) | while ((ch = getopt(argc, argv, "bc:dl:p:qu")) != -1) | ||||
switch (ch) { | switch (ch) { | ||||
case 'b': | case 'b': | ||||
immediate_daemon = 1; | immediate_daemon = 1; | ||||
break; | break; | ||||
case 'c': | case 'c': | ||||
path_dhclient_conf = optarg; | path_dhclient_conf = optarg; | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | if (setgroups(1, &pw->pw_gid) || | ||||
setegid(pw->pw_gid) || setgid(pw->pw_gid) || | setegid(pw->pw_gid) || setgid(pw->pw_gid) || | ||||
seteuid(pw->pw_uid) || setuid(pw->pw_uid)) | seteuid(pw->pw_uid) || setuid(pw->pw_uid)) | ||||
error("can't drop privileges: %m"); | error("can't drop privileges: %m"); | ||||
endpwent(); | endpwent(); | ||||
setproctitle("%s", ifi->name); | setproctitle("%s", ifi->name); | ||||
if (cap_enter() < 0 && errno != ENOSYS) | if (CASPER_SUPPORT && cap_enter() < 0 && errno != ENOSYS) | ||||
error("can't enter capability mode: %m"); | error("can't enter capability mode: %m"); | ||||
if (immediate_daemon) | if (immediate_daemon) | ||||
go_daemon(); | go_daemon(); | ||||
ifi->client->state = S_INIT; | ifi->client->state = S_INIT; | ||||
state_reboot(ifi); | state_reboot(ifi); | ||||
▲ Show 20 Lines • Show All 2,266 Lines • Show Last 20 Lines |