|
Lines 46-51
static char url [] = "For info, please v
Link Here
|
| 46 |
#include "dhcpd.h" |
46 |
#include "dhcpd.h" |
| 47 |
#include "version.h" |
47 |
#include "version.h" |
| 48 |
#include <omapip/omapip_p.h> |
48 |
#include <omapip/omapip_p.h> |
|
|
49 |
#include <sys/types.h> |
| 50 |
#include <unistd.h> |
| 51 |
#include <pwd.h> |
| 52 |
#define group real_group |
| 53 |
#include <grp.h> |
| 54 |
#undef group |
| 49 |
|
55 |
|
| 50 |
static void usage PROTO ((void)); |
56 |
static void usage PROTO ((void)); |
| 51 |
|
57 |
|
|
Lines 193-198
static void omapi_listener_start (void *
Link Here
|
| 193 |
omapi_object_dereference (&listener, MDL); |
199 |
omapi_object_dereference (&listener, MDL); |
| 194 |
} |
200 |
} |
| 195 |
|
201 |
|
|
|
202 |
static int drop_priv(const char *server_user, const char *server_jail) |
| 203 |
{ |
| 204 |
struct passwd *pw; |
| 205 |
|
| 206 |
if (!server_user) |
| 207 |
server_user = "dhcpd"; |
| 208 |
if (!server_jail) |
| 209 |
server_jail = "/var/lib/dhcp/dhcpd"; |
| 210 |
if (!*server_user || !*server_jail) |
| 211 |
return 0; |
| 212 |
|
| 213 |
if (!(pw = getpwnam(server_user))) |
| 214 |
return -1; |
| 215 |
|
| 216 |
if (initgroups(server_user, pw->pw_gid) || setgid(pw->pw_gid)) |
| 217 |
return -1; |
| 218 |
|
| 219 |
if (chroot(server_jail) || chdir("/")) |
| 220 |
return -1; |
| 221 |
|
| 222 |
if (setuid(pw->pw_uid)) |
| 223 |
return -1; |
| 224 |
|
| 225 |
return 0; |
| 226 |
} |
| 227 |
|
| 196 |
int main (argc, argv, envp) |
228 |
int main (argc, argv, envp) |
| 197 |
int argc; |
229 |
int argc; |
| 198 |
char **argv, **envp; |
230 |
char **argv, **envp; |
|
Lines 226-231
int main (argc, argv, envp)
Link Here
|
| 226 |
char *traceoutfile = (char *)0; |
258 |
char *traceoutfile = (char *)0; |
| 227 |
#endif |
259 |
#endif |
| 228 |
|
260 |
|
|
|
261 |
char *server_user = NULL; |
| 262 |
char *server_jail = NULL; |
| 263 |
|
| 229 |
/* Make sure we have stdin, stdout and stderr. */ |
264 |
/* Make sure we have stdin, stdout and stderr. */ |
| 230 |
status = open ("/dev/null", O_RDWR); |
265 |
status = open ("/dev/null", O_RDWR); |
| 231 |
if (status == 0) |
266 |
if (status == 0) |
|
Lines 252-257
int main (argc, argv, envp)
Link Here
|
| 252 |
dhcp_common_objects_setup (); |
287 |
dhcp_common_objects_setup (); |
| 253 |
|
288 |
|
| 254 |
/* Initially, log errors to stderr as well as to syslogd. */ |
289 |
/* Initially, log errors to stderr as well as to syslogd. */ |
|
|
290 |
tzset(); |
| 255 |
#ifdef SYSLOG_4_2 |
291 |
#ifdef SYSLOG_4_2 |
| 256 |
openlog ("dhcpd", LOG_NDELAY); |
292 |
openlog ("dhcpd", LOG_NDELAY); |
| 257 |
log_priority = DHCPD_LOG_FACILITY; |
293 |
log_priority = DHCPD_LOG_FACILITY; |
|
Lines 320-325
int main (argc, argv, envp)
Link Here
|
| 320 |
} else if (!strcmp (argv [i], "-q")) { |
356 |
} else if (!strcmp (argv [i], "-q")) { |
| 321 |
quiet = 1; |
357 |
quiet = 1; |
| 322 |
quiet_interface_discovery = 1; |
358 |
quiet_interface_discovery = 1; |
|
|
359 |
} else if (!strcmp (argv [i], "-u")) { |
| 360 |
if (++i == argc) |
| 361 |
usage(); |
| 362 |
server_user = argv[i]; |
| 363 |
} else if (!strcmp (argv [i], "-j")) { |
| 364 |
if (++i == argc) |
| 365 |
usage(); |
| 366 |
server_jail = argv[i]; |
| 323 |
} else if (!strcmp (argv [i], "--version")) { |
367 |
} else if (!strcmp (argv [i], "--version")) { |
| 324 |
log_info ("isc-dhcpd-%s", DHCP_VERSION); |
368 |
log_info ("isc-dhcpd-%s", DHCP_VERSION); |
| 325 |
exit (0); |
369 |
exit (0); |
|
Lines 499-510
int main (argc, argv, envp)
Link Here
|
| 499 |
|
543 |
|
| 500 |
group_write_hook = group_writer; |
544 |
group_write_hook = group_writer; |
| 501 |
|
545 |
|
| 502 |
/* Start up the database... */ |
|
|
| 503 |
db_startup (lftest); |
| 504 |
|
| 505 |
if (lftest) |
| 506 |
exit (0); |
| 507 |
|
| 508 |
/* Discover all the network interfaces and initialize them. */ |
546 |
/* Discover all the network interfaces and initialize them. */ |
| 509 |
discover_interfaces (DISCOVER_SERVER); |
547 |
discover_interfaces (DISCOVER_SERVER); |
| 510 |
|
548 |
|
|
Lines 525-531
int main (argc, argv, envp)
Link Here
|
| 525 |
#if defined (TRACING) |
563 |
#if defined (TRACING) |
| 526 |
trace_seed_stash (trace_srandom, seed + cur_time); |
564 |
trace_seed_stash (trace_srandom, seed + cur_time); |
| 527 |
#endif |
565 |
#endif |
| 528 |
postdb_startup (); |
566 |
|
|
|
567 |
/* Initialize the omapi listener state. */ |
| 568 |
if (omapi_port != -1) { |
| 569 |
omapi_listener_start (0); |
| 570 |
} |
| 529 |
|
571 |
|
| 530 |
#ifndef DEBUG |
572 |
#ifndef DEBUG |
| 531 |
if (daemon) { |
573 |
if (daemon) { |
|
Lines 560-565
int main (argc, argv, envp)
Link Here
|
| 560 |
} |
602 |
} |
| 561 |
} |
603 |
} |
| 562 |
|
604 |
|
|
|
605 |
if (pidfilewritten) { |
| 606 |
if (drop_priv(server_user, server_jail) < 0) |
| 607 |
log_fatal("Failed to lower privileges."); |
| 608 |
} |
| 609 |
|
| 563 |
/* If we were requested to log to stdout on the command line, |
610 |
/* If we were requested to log to stdout on the command line, |
| 564 |
keep doing so; otherwise, stop. */ |
611 |
keep doing so; otherwise, stop. */ |
| 565 |
if (log_perror == -1) |
612 |
if (log_perror == -1) |
|
Lines 588-594
int main (argc, argv, envp)
Link Here
|
| 588 |
close (i); |
635 |
close (i); |
| 589 |
pidfilewritten = 1; |
636 |
pidfilewritten = 1; |
| 590 |
} |
637 |
} |
|
|
638 |
if (drop_priv(server_user, server_jail) < 0) |
| 639 |
log_fatal("Failed to lower privileges."); |
| 591 |
} |
640 |
} |
|
|
641 |
|
| 642 |
/* Start up the database... */ |
| 643 |
db_startup (lftest); |
| 644 |
|
| 645 |
if (lftest) |
| 646 |
exit (0); |
| 647 |
|
| 648 |
#if defined (FAILOVER_PROTOCOL) |
| 649 |
/* Initialize the failover listener state. */ |
| 650 |
dhcp_failover_startup (); |
| 651 |
#endif |
| 652 |
|
| 592 |
#endif /* !DEBUG */ |
653 |
#endif /* !DEBUG */ |
| 593 |
|
654 |
|
| 594 |
#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \ |
655 |
#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \ |
|
Lines 881-888
static void usage ()
Link Here
|
| 881 |
log_info (copyright); |
942 |
log_info (copyright); |
| 882 |
log_info (arr); |
943 |
log_info (arr); |
| 883 |
|
944 |
|
| 884 |
log_fatal ("Usage: dhcpd [-p <UDP port #>] [-d] [-f]%s%s%s%s", |
945 |
log_fatal ("Usage: dhcpd [-p <UDP port #>] [-d] [-f]%s%s%s%s%s", |
| 885 |
"\n [-cf config-file] [-lf lease-file]", |
946 |
"\n [-cf config-file] [-lf lease-file]", |
|
|
947 |
"\n [-u user] [-j chroot-dir]", |
| 886 |
#if defined (TRACING) |
948 |
#if defined (TRACING) |
| 887 |
"\n [-tf trace-output-file]", |
949 |
"\n [-tf trace-output-file]", |
| 888 |
"\n [-play trace-input-file]", |
950 |
"\n [-play trace-input-file]", |