"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/helper.c" between
dnsmasq-2.80.tar.gz and dnsmasq-2.81.tar.xz

About: Dnsmasq is a lightweight caching DNS forwarder and DHCP server.

helper.c  (dnsmasq-2.80):helper.c  (dnsmasq-2.81.tar.xz)
/* dnsmasq is Copyright (c) 2000-2018 Simon Kelley /* dnsmasq is Copyright (c) 2000-2020 Simon Kelley
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 dated June, 1991, or the Free Software Foundation; version 2 dated June, 1991, or
(at your option) version 3 dated 29 June, 2007. (at your option) version 3 dated 29 June, 2007.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
skipping to change at line 66 skipping to change at line 66
struct in_addr addr, giaddr; struct in_addr addr, giaddr;
unsigned int remaining_time; unsigned int remaining_time;
#ifdef HAVE_BROKEN_RTC #ifdef HAVE_BROKEN_RTC
unsigned int length; unsigned int length;
#else #else
time_t expires; time_t expires;
#endif #endif
#ifdef HAVE_TFTP #ifdef HAVE_TFTP
off_t file_len; off_t file_len;
#endif #endif
#ifdef HAVE_IPV6
struct in6_addr addr6; struct in6_addr addr6;
#endif
#ifdef HAVE_DHCP6 #ifdef HAVE_DHCP6
int iaid, vendorclass_count; int vendorclass_count;
unsigned int iaid;
#endif #endif
unsigned char hwaddr[DHCP_CHADDR_MAX]; unsigned char hwaddr[DHCP_CHADDR_MAX];
char interface[IF_NAMESIZE]; char interface[IF_NAMESIZE];
}; };
static struct script_data *buf = NULL; static struct script_data *buf = NULL;
static size_t bytes_in_buf = 0, buf_size = 0; static size_t bytes_in_buf = 0, buf_size = 0;
int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd) int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
{ {
pid_t pid; pid_t pid;
int i, pipefd[2]; int i, pipefd[2];
struct sigaction sigact; struct sigaction sigact;
unsigned char *alloc_buff = NULL;
/* create the pipe through which the main program sends us commands, /* create the pipe through which the main program sends us commands,
then fork our process. */ then fork our process. */
if (pipe(pipefd) == -1 || !fix_fd(pipefd[1]) || (pid = fork()) == -1) if (pipe(pipefd) == -1 || !fix_fd(pipefd[1]) || (pid = fork()) == -1)
{ {
send_event(err_fd, EVENT_PIPE_ERR, errno, NULL); send_event(err_fd, EVENT_PIPE_ERR, errno, NULL);
_exit(0); _exit(0);
} }
if (pid != 0) if (pid != 0)
skipping to change at line 133 skipping to change at line 133
send_event(err_fd, EVENT_USER_ERR, errno, daemon->scriptuser); send_event(err_fd, EVENT_USER_ERR, errno, daemon->scriptuser);
} }
_exit(0); _exit(0);
} }
} }
/* close all the sockets etc, we don't need them here. /* close all the sockets etc, we don't need them here.
Don't close err_fd, in case the lua-init fails. Don't close err_fd, in case the lua-init fails.
Note that we have to do this before lua init Note that we have to do this before lua init
so we don't close any lua fds. */ so we don't close any lua fds. */
for (max_fd--; max_fd >= 0; max_fd--) close_fds(max_fd, pipefd[0], event_fd, err_fd);
if (max_fd != STDOUT_FILENO && max_fd != STDERR_FILENO &&
max_fd != STDIN_FILENO && max_fd != pipefd[0] &&
max_fd != event_fd && max_fd != err_fd)
close(max_fd);
#ifdef HAVE_LUASCRIPT #ifdef HAVE_LUASCRIPT
if (daemon->luascript) if (daemon->luascript)
{ {
const char *lua_err = NULL; const char *lua_err = NULL;
lua = lua_open(); lua = lua_open();
luaL_openlibs(lua); luaL_openlibs(lua);
/* get Lua to load our script file */ /* get Lua to load our script file */
if (luaL_dofile(lua, daemon->luascript) != 0) if (luaL_dofile(lua, daemon->luascript) != 0)
skipping to change at line 190 skipping to change at line 186
/* All init done, close our copy of the error pipe, so that main process can r eturn */ /* All init done, close our copy of the error pipe, so that main process can r eturn */
if (err_fd != -1) if (err_fd != -1)
close(err_fd); close(err_fd);
/* loop here */ /* loop here */
while(1) while(1)
{ {
struct script_data data; struct script_data data;
char *p, *action_str, *hostname = NULL, *domain = NULL; char *p, *action_str, *hostname = NULL, *domain = NULL;
unsigned char *buf = (unsigned char *)daemon->namebuff; unsigned char *buf = (unsigned char *)daemon->namebuff;
unsigned char *end, *extradata, *alloc_buff = NULL; unsigned char *end, *extradata;
int is6, err = 0; int is6, err = 0;
int pipeout[2]; int pipeout[2];
free(alloc_buff); /* Free rarely-allocated memory from previous iteration. */
if (alloc_buff)
{
free(alloc_buff);
alloc_buff = NULL;
}
/* we read zero bytes when pipe closed: this is our signal to exit */ /* we read zero bytes when pipe closed: this is our signal to exit */
if (!read_write(pipefd[0], (unsigned char *)&data, sizeof(data), 1)) if (!read_write(pipefd[0], (unsigned char *)&data, sizeof(data), 1))
{ {
#ifdef HAVE_LUASCRIPT #ifdef HAVE_LUASCRIPT
if (daemon->luascript) if (daemon->luascript)
{ {
lua_getglobal(lua, "shutdown"); lua_getglobal(lua, "shutdown");
if (lua_type(lua, -1) == LUA_TFUNCTION) if (lua_type(lua, -1) == LUA_TFUNCTION)
lua_call(lua, 0, 0); lua_call(lua, 0, 0);
skipping to change at line 303 skipping to change at line 304
domain = dot+1; domain = dot+1;
*dot = 0; *dot = 0;
} }
} }
} }
extradata = buf + data.hostname_len; extradata = buf + data.hostname_len;
if (!is6) if (!is6)
inet_ntop(AF_INET, &data.addr, daemon->addrbuff, ADDRSTRLEN); inet_ntop(AF_INET, &data.addr, daemon->addrbuff, ADDRSTRLEN);
#ifdef HAVE_IPV6
else else
inet_ntop(AF_INET6, &data.addr6, daemon->addrbuff, ADDRSTRLEN); inet_ntop(AF_INET6, &data.addr6, daemon->addrbuff, ADDRSTRLEN);
#endif
#ifdef HAVE_TFTP #ifdef HAVE_TFTP
/* file length */ /* file length */
if (data.action == ACTION_TFTP) if (data.action == ACTION_TFTP)
sprintf(is6 ? daemon->packet : daemon->dhcp_buff, "%lu", (unsigned long)d ata.file_len); sprintf(is6 ? daemon->packet : daemon->dhcp_buff, "%lu", (unsigned long)d ata.file_len);
#endif #endif
#ifdef HAVE_LUASCRIPT #ifdef HAVE_LUASCRIPT
if (daemon->luascript) if (daemon->luascript)
{ {
skipping to change at line 827 skipping to change at line 826
filename_len = strlen(filename) + 1; filename_len = strlen(filename) + 1;
buff_alloc(sizeof(struct script_data) + filename_len); buff_alloc(sizeof(struct script_data) + filename_len);
memset(buf, 0, sizeof(struct script_data)); memset(buf, 0, sizeof(struct script_data));
buf->action = ACTION_TFTP; buf->action = ACTION_TFTP;
buf->hostname_len = filename_len; buf->hostname_len = filename_len;
buf->file_len = file_len; buf->file_len = file_len;
if ((buf->flags = peer->sa.sa_family) == AF_INET) if ((buf->flags = peer->sa.sa_family) == AF_INET)
buf->addr = peer->in.sin_addr; buf->addr = peer->in.sin_addr;
#ifdef HAVE_IPV6
else else
buf->addr6 = peer->in6.sin6_addr; buf->addr6 = peer->in6.sin6_addr;
#endif
memcpy((unsigned char *)(buf+1), filename, filename_len); memcpy((unsigned char *)(buf+1), filename, filename_len);
bytes_in_buf = sizeof(struct script_data) + filename_len; bytes_in_buf = sizeof(struct script_data) + filename_len;
} }
#endif #endif
void queue_arp(int action, unsigned char *mac, int maclen, int family, struct al l_addr *addr) void queue_arp(int action, unsigned char *mac, int maclen, int family, union all _addr *addr)
{ {
/* no script */ /* no script */
if (daemon->helperfd == -1) if (daemon->helperfd == -1)
return; return;
buff_alloc(sizeof(struct script_data)); buff_alloc(sizeof(struct script_data));
memset(buf, 0, sizeof(struct script_data)); memset(buf, 0, sizeof(struct script_data));
buf->action = action; buf->action = action;
buf->hwaddr_len = maclen; buf->hwaddr_len = maclen;
buf->hwaddr_type = ARPHRD_ETHER; buf->hwaddr_type = ARPHRD_ETHER;
if ((buf->flags = family) == AF_INET) if ((buf->flags = family) == AF_INET)
buf->addr = addr->addr.addr4; buf->addr = addr->addr4;
#ifdef HAVE_IPV6
else else
buf->addr6 = addr->addr.addr6; buf->addr6 = addr->addr6;
#endif
memcpy(buf->hwaddr, mac, maclen); memcpy(buf->hwaddr, mac, maclen);
bytes_in_buf = sizeof(struct script_data); bytes_in_buf = sizeof(struct script_data);
} }
int helper_buf_empty(void) int helper_buf_empty(void)
{ {
return bytes_in_buf == 0; return bytes_in_buf == 0;
} }
 End of changes. 15 change blocks. 
20 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)