mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 10:18:25 +00:00
import of dnsmasq-2.48.tar.gz
This commit is contained in:
@@ -33,9 +33,6 @@ static char *compile_opts =
|
||||
#ifdef NO_FORK
|
||||
"no-MMU "
|
||||
#endif
|
||||
#ifdef HAVE_BSD_BRIDGE
|
||||
"BSD-bridge "
|
||||
#endif
|
||||
#ifndef HAVE_DBUS
|
||||
"no-"
|
||||
#endif
|
||||
@@ -44,6 +41,10 @@ static char *compile_opts =
|
||||
"no-"
|
||||
#endif
|
||||
"I18N "
|
||||
#ifndef HAVE_DHCP
|
||||
"no-"
|
||||
#endif
|
||||
"DHCP "
|
||||
#ifndef HAVE_TFTP
|
||||
"no-"
|
||||
#endif
|
||||
@@ -67,9 +68,11 @@ int main (int argc, char **argv)
|
||||
struct iname *if_tmp;
|
||||
int piperead, pipefd[2], err_pipe[2];
|
||||
struct passwd *ent_pw = NULL;
|
||||
#ifdef HAVE_DHCP
|
||||
uid_t script_uid = 0;
|
||||
gid_t script_gid = 0;
|
||||
struct group *gp= NULL;
|
||||
#endif
|
||||
struct group *gp = NULL;
|
||||
long i, max_fd = sysconf(_SC_OPEN_MAX);
|
||||
char *baduser = NULL;
|
||||
int log_err;
|
||||
@@ -108,11 +111,13 @@ int main (int argc, char **argv)
|
||||
daemon->edns_pktsz : DNSMASQ_PACKETSZ;
|
||||
daemon->packet = safe_malloc(daemon->packet_buff_sz);
|
||||
|
||||
#ifdef HAVE_DHCP
|
||||
if (!daemon->lease_file)
|
||||
{
|
||||
if (daemon->dhcp)
|
||||
daemon->lease_file = LEASEFILE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Close any file descriptors we inherited apart from std{in|out|err} */
|
||||
for (i = 0; i < max_fd; i++)
|
||||
@@ -145,23 +150,16 @@ int main (int argc, char **argv)
|
||||
|
||||
now = dnsmasq_time();
|
||||
|
||||
#ifdef HAVE_DHCP
|
||||
if (daemon->dhcp)
|
||||
{
|
||||
#if !defined(HAVE_LINUX_NETWORK) && !defined(IP_RECVIF)
|
||||
int c;
|
||||
struct iname *tmp;
|
||||
for (c = 0, tmp = daemon->if_names; tmp; tmp = tmp->next)
|
||||
if (!tmp->isloop)
|
||||
c++;
|
||||
if (c != 1)
|
||||
die(_("must set exactly one interface on broken systems without IP_RECVIF"), NULL, EC_BADCONF);
|
||||
#endif
|
||||
/* Note that order matters here, we must call lease_init before
|
||||
creating any file descriptors which shouldn't be leaked
|
||||
to the lease-script init process. */
|
||||
lease_init(now);
|
||||
dhcp_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!enumerate_interfaces())
|
||||
die(_("failed to find list of interfaces: %s"), NULL, EC_MISC);
|
||||
@@ -204,6 +202,7 @@ int main (int argc, char **argv)
|
||||
if (daemon->port != 0)
|
||||
pre_allocate_sfds();
|
||||
|
||||
#ifdef HAVE_DHCP
|
||||
/* Note getpwnam returns static storage */
|
||||
if (daemon->dhcp && daemon->lease_change_command && daemon->scriptuser)
|
||||
{
|
||||
@@ -215,6 +214,7 @@ int main (int argc, char **argv)
|
||||
else
|
||||
baduser = daemon->scriptuser;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (daemon->username && !(ent_pw = getpwnam(daemon->username)))
|
||||
baduser = daemon->username;
|
||||
@@ -290,8 +290,9 @@ int main (int argc, char **argv)
|
||||
When startup is complete we close this and the process terminates. */
|
||||
safe_pipe(err_pipe, 0);
|
||||
|
||||
if ((pid = fork()) == -1 )
|
||||
die(_("cannot fork into background: %s"), NULL, EC_MISC);
|
||||
if ((pid = fork()) == -1)
|
||||
/* fd == -1 since we've not forked, never returns. */
|
||||
send_event(-1, EVENT_FORK_ERR, errno);
|
||||
|
||||
if (pid != 0)
|
||||
{
|
||||
@@ -312,9 +313,11 @@ int main (int argc, char **argv)
|
||||
/* NO calls to die() from here on. */
|
||||
|
||||
setsid();
|
||||
pid = fork();
|
||||
|
||||
if (pid != 0 && pid != -1)
|
||||
|
||||
if ((pid = fork()) == -1)
|
||||
send_event(err_pipe[1], EVENT_FORK_ERR, errno);
|
||||
|
||||
if (pid != 0)
|
||||
_exit(0);
|
||||
}
|
||||
#endif
|
||||
@@ -349,7 +352,7 @@ int main (int argc, char **argv)
|
||||
|
||||
/* if we are to run scripts, we need to fork a helper before dropping root. */
|
||||
daemon->helperfd = -1;
|
||||
#ifndef NO_FORK
|
||||
#if defined(HAVE_DHCP) && !defined(NO_FORK)
|
||||
if (daemon->dhcp && daemon->lease_change_command)
|
||||
daemon->helperfd = create_helper(pipewrite, err_pipe[1], script_uid, script_gid, max_fd);
|
||||
#endif
|
||||
@@ -380,7 +383,7 @@ int main (int argc, char **argv)
|
||||
if (capset(hdr, data) == -1 || prctl(PR_SET_KEEPCAPS, 1) == -1)
|
||||
bad_capabilities = errno;
|
||||
|
||||
#elif defined(HAVE_SOLARIS_PRIVS)
|
||||
#elif defined(HAVE_SOLARIS_NETWORK)
|
||||
/* http://developers.sun.com/solaris/articles/program_privileges.html */
|
||||
priv_set_t *priv_set;
|
||||
|
||||
@@ -400,9 +403,6 @@ int main (int argc, char **argv)
|
||||
if (priv_set)
|
||||
priv_freeset(priv_set);
|
||||
|
||||
#elif defined(HAVE_SOLARIS_NETWORK)
|
||||
|
||||
bad_capabilities = ENOTSUP;
|
||||
#endif
|
||||
|
||||
if (bad_capabilities != 0)
|
||||
@@ -482,6 +482,7 @@ int main (int argc, char **argv)
|
||||
if (daemon->max_logs != 0)
|
||||
my_syslog(LOG_INFO, _("asynchronous logging enabled, queue limit is %d messages"), daemon->max_logs);
|
||||
|
||||
#ifdef HAVE_DHCP
|
||||
if (daemon->dhcp)
|
||||
{
|
||||
struct dhcp_context *dhcp_tmp;
|
||||
@@ -490,13 +491,16 @@ int main (int argc, char **argv)
|
||||
{
|
||||
prettyprint_time(daemon->dhcp_buff2, dhcp_tmp->lease_time);
|
||||
strcpy(daemon->dhcp_buff, inet_ntoa(dhcp_tmp->start));
|
||||
my_syslog(LOG_INFO,
|
||||
my_syslog(MS_DHCP | LOG_INFO,
|
||||
(dhcp_tmp->flags & CONTEXT_STATIC) ?
|
||||
_("DHCP, static leases only on %.0s%s, lease time %s") :
|
||||
(dhcp_tmp->flags & CONTEXT_PROXY) ?
|
||||
_("DHCP, proxy on subnet %.0s%s%.0s") :
|
||||
_("DHCP, IP range %s -- %s, lease time %s"),
|
||||
daemon->dhcp_buff, inet_ntoa(dhcp_tmp->end), daemon->dhcp_buff2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TFTP
|
||||
if (daemon->options & OPT_TFTP)
|
||||
@@ -506,7 +510,7 @@ int main (int argc, char **argv)
|
||||
max_fd = FD_SETSIZE;
|
||||
#endif
|
||||
|
||||
my_syslog(LOG_INFO, "TFTP %s%s %s",
|
||||
my_syslog(MS_TFTP | LOG_INFO, "TFTP %s%s %s",
|
||||
daemon->tftp_prefix ? _("root is ") : _("enabled"),
|
||||
daemon->tftp_prefix ? daemon->tftp_prefix: "",
|
||||
daemon->options & OPT_TFTP_SECURE ? _("secure mode") : "");
|
||||
@@ -534,7 +538,7 @@ int main (int argc, char **argv)
|
||||
if (daemon->tftp_max > max_fd)
|
||||
{
|
||||
daemon->tftp_max = max_fd;
|
||||
my_syslog(LOG_WARNING,
|
||||
my_syslog(MS_TFTP | LOG_WARNING,
|
||||
_("restricting maximum simultaneous TFTP transfers to %d"),
|
||||
daemon->tftp_max);
|
||||
}
|
||||
@@ -582,11 +586,13 @@ int main (int argc, char **argv)
|
||||
set_dbus_listeners(&maxfd, &rset, &wset, &eset);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DHCP
|
||||
if (daemon->dhcp)
|
||||
{
|
||||
FD_SET(daemon->dhcpfd, &rset);
|
||||
bump_maxfd(daemon->dhcpfd, &maxfd);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LINUX_NETWORK
|
||||
FD_SET(daemon->netlinkfd, &rset);
|
||||
@@ -596,7 +602,8 @@ int main (int argc, char **argv)
|
||||
FD_SET(piperead, &rset);
|
||||
bump_maxfd(piperead, &maxfd);
|
||||
|
||||
#ifndef NO_FORK
|
||||
#ifdef HAVE_DHCP
|
||||
# ifdef NO_FORK
|
||||
while (helper_buf_empty() && do_script_run(now));
|
||||
|
||||
if (!helper_buf_empty())
|
||||
@@ -604,11 +611,12 @@ int main (int argc, char **argv)
|
||||
FD_SET(daemon->helperfd, &wset);
|
||||
bump_maxfd(daemon->helperfd, &maxfd);
|
||||
}
|
||||
#else
|
||||
# else
|
||||
/* need this for other side-effects */
|
||||
while (do_script_run(now));
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/* must do this just before select(), when we know no
|
||||
more calls to my_syslog() can occur */
|
||||
set_log_writer(&wset, &maxfd);
|
||||
@@ -662,12 +670,14 @@ int main (int argc, char **argv)
|
||||
check_tftp_listeners(&rset, now);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DHCP
|
||||
if (daemon->dhcp && FD_ISSET(daemon->dhcpfd, &rset))
|
||||
dhcp_packet(now);
|
||||
|
||||
#ifndef NO_FORK
|
||||
# ifndef NO_FORK
|
||||
if (daemon->helperfd != -1 && FD_ISSET(daemon->helperfd, &wset))
|
||||
helper_write();
|
||||
# endif
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -737,6 +747,9 @@ static void fatal_event(struct event_desc *ev)
|
||||
{
|
||||
case EVENT_DIE:
|
||||
exit(0);
|
||||
|
||||
case EVENT_FORK_ERR:
|
||||
die(_("cannot fork into background: %s"), NULL, EC_MISC);
|
||||
|
||||
case EVENT_PIPE_ERR:
|
||||
die(_("failed to create helper: %s"), NULL, EC_MISC);
|
||||
@@ -777,7 +790,9 @@ static void async_event(int pipe, time_t now)
|
||||
reload_servers(daemon->resolv_files->name);
|
||||
check_servers();
|
||||
}
|
||||
#ifdef HAVE_DHCP
|
||||
rerun_scripts();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case EVENT_DUMP:
|
||||
@@ -786,11 +801,13 @@ static void async_event(int pipe, time_t now)
|
||||
break;
|
||||
|
||||
case EVENT_ALARM:
|
||||
#ifdef HAVE_DHCP
|
||||
if (daemon->dhcp)
|
||||
{
|
||||
lease_prune(NULL, now);
|
||||
lease_update_file(now);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case EVENT_CHILD:
|
||||
@@ -840,7 +857,7 @@ static void async_event(int pipe, time_t now)
|
||||
if (daemon->tcp_pids[i] != 0)
|
||||
kill(daemon->tcp_pids[i], SIGALRM);
|
||||
|
||||
#ifndef NO_FORK
|
||||
#if defined(HAVE_DHCP) && !defined(NO_FORK)
|
||||
/* handle pending lease transitions */
|
||||
if (daemon->helperfd != -1)
|
||||
{
|
||||
@@ -904,7 +921,7 @@ static void poll_resolv()
|
||||
warned = 0;
|
||||
check_servers();
|
||||
if (daemon->options & OPT_RELOAD)
|
||||
cache_reload(daemon->addn_hosts);
|
||||
cache_reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -921,8 +938,9 @@ static void poll_resolv()
|
||||
void clear_cache_and_reload(time_t now)
|
||||
{
|
||||
if (daemon->port != 0)
|
||||
cache_reload(daemon->addn_hosts);
|
||||
cache_reload();
|
||||
|
||||
#ifdef HAVE_DHCP
|
||||
if (daemon->dhcp)
|
||||
{
|
||||
if (daemon->options & OPT_ETHERS)
|
||||
@@ -934,6 +952,7 @@ void clear_cache_and_reload(time_t now)
|
||||
lease_update_file(now);
|
||||
lease_update_dns();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int set_dns_listeners(time_t now, fd_set *set, int *maxfdp)
|
||||
@@ -1135,7 +1154,7 @@ static void check_dns_listeners(fd_set *set, time_t now)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_DHCP
|
||||
int make_icmp_sock(void)
|
||||
{
|
||||
int fd;
|
||||
@@ -1258,5 +1277,6 @@ int icmp_ping(struct in_addr addr)
|
||||
|
||||
return gotreply;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user