"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/tftp.c" between
dnsmasq-2.84.tar.xz and dnsmasq-2.85.tar.xz

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

tftp.c  (dnsmasq-2.84.tar.xz):tftp.c  (dnsmasq-2.85.tar.xz)
skipping to change at line 25 skipping to change at line 25
*/ */
#include "dnsmasq.h" #include "dnsmasq.h"
#ifdef HAVE_TFTP #ifdef HAVE_TFTP
static void handle_tftp(time_t now, struct tftp_transfer *transfer, ssize_t len) ; static void handle_tftp(time_t now, struct tftp_transfer *transfer, ssize_t len) ;
static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix); static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix);
static void free_transfer(struct tftp_transfer *transfer); static void free_transfer(struct tftp_transfer *transfer);
static ssize_t tftp_err(int err, char *packet, char *message, char *file); static ssize_t tftp_err(int err, char *packet, char *message, char *file);
static ssize_t tftp_err_oops(char *packet, char *file); static ssize_t tftp_err_oops(char *packet, const char *file);
static ssize_t get_block(char *packet, struct tftp_transfer *transfer); static ssize_t get_block(char *packet, struct tftp_transfer *transfer);
static char *next(char **p, char *end); static char *next(char **p, char *end);
static void sanitise(char *buf); static void sanitise(char *buf);
#define OP_RRQ 1 #define OP_RRQ 1
#define OP_WRQ 2 #define OP_WRQ 2
#define OP_DATA 3 #define OP_DATA 3
#define OP_ACK 4 #define OP_ACK 4
#define OP_ERR 5 #define OP_ERR 5
#define OP_OACK 6 #define OP_OACK 6
#define ERR_NOTDEF 0 #define ERR_NOTDEF 0
#define ERR_FNF 1 #define ERR_FNF 1
#define ERR_PERM 2 #define ERR_PERM 2
#define ERR_FULL 3 #define ERR_FULL 3
#define ERR_ILL 4 #define ERR_ILL 4
#define ERR_TID 5
void tftp_request(struct listener *listen, time_t now) void tftp_request(struct listener *listen, time_t now)
{ {
ssize_t len; ssize_t len;
char *packet = daemon->packet; char *packet = daemon->packet;
char *filename, *mode, *p, *end, *opt; char *filename, *mode, *p, *end, *opt;
union mysockaddr addr, peer; union mysockaddr addr, peer;
struct msghdr msg; struct msghdr msg;
struct iovec iov; struct iovec iov;
struct ifreq ifr; struct ifreq ifr;
skipping to change at line 586 skipping to change at line 587
void check_tftp_listeners(time_t now) void check_tftp_listeners(time_t now)
{ {
struct tftp_transfer *transfer, *tmp, **up; struct tftp_transfer *transfer, *tmp, **up;
/* In single port mode, all packets come via port 69 and tftp_request() */ /* In single port mode, all packets come via port 69 and tftp_request() */
if (!option_bool(OPT_SINGLE_PORT)) if (!option_bool(OPT_SINGLE_PORT))
for (transfer = daemon->tftp_trans; transfer; transfer = transfer->next) for (transfer = daemon->tftp_trans; transfer; transfer = transfer->next)
if (poll_check(transfer->sockfd, POLLIN)) if (poll_check(transfer->sockfd, POLLIN))
{ {
union mysockaddr peer;
socklen_t addr_len = sizeof(union mysockaddr);
ssize_t len;
/* we overwrote the buffer... */ /* we overwrote the buffer... */
daemon->srv_save = NULL; daemon->srv_save = NULL;
handle_tftp(now, transfer, recv(transfer->sockfd, daemon->packet, daemo
n->packet_buff_sz, 0)); if ((len = recvfrom(transfer->sockfd, daemon->packet, daemon->packet_bu
ff_sz, 0, &peer.sa, &addr_len)) > 0)
{
if (sockaddr_isequal(&peer, &transfer->peer))
handle_tftp(now, transfer, len);
else
{
/* Wrong source address. See rfc1350 para 4. */
prettyprint_addr(&peer, daemon->addrbuff);
len = tftp_err(ERR_TID, daemon->packet, _("ignoring packet from
%s (TID mismatch)"), daemon->addrbuff);
sendto(transfer->sockfd, daemon->packet, len, 0, &peer.sa, sa_l
en(&peer));
}
}
} }
for (transfer = daemon->tftp_trans, up = &daemon->tftp_trans; transfer; transf er = tmp) for (transfer = daemon->tftp_trans, up = &daemon->tftp_trans; transfer; transf er = tmp)
{ {
tmp = transfer->next; tmp = transfer->next;
if (difftime(now, transfer->timeout) >= 0.0) if (difftime(now, transfer->timeout) >= 0.0)
{ {
int endcon = 0; int endcon = 0;
ssize_t len; ssize_t len;
skipping to change at line 739 skipping to change at line 756
static ssize_t tftp_err(int err, char *packet, char *message, char *file) static ssize_t tftp_err(int err, char *packet, char *message, char *file)
{ {
struct errmess { struct errmess {
unsigned short op, err; unsigned short op, err;
char message[]; char message[];
} *mess = (struct errmess *)packet; } *mess = (struct errmess *)packet;
ssize_t len, ret = 4; ssize_t len, ret = 4;
char *errstr = strerror(errno); char *errstr = strerror(errno);
memset(packet, 0, daemon->packet_buff_sz); memset(packet, 0, daemon->packet_buff_sz);
sanitise(file); if (file)
sanitise(file);
mess->op = htons(OP_ERR); mess->op = htons(OP_ERR);
mess->err = htons(err); mess->err = htons(err);
len = snprintf(mess->message, MAXMESSAGE, message, file, errstr); len = snprintf(mess->message, MAXMESSAGE, message, file, errstr);
ret += (len < MAXMESSAGE) ? len + 1 : MAXMESSAGE; /* include terminating zero */ ret += (len < MAXMESSAGE) ? len + 1 : MAXMESSAGE; /* include terminating zero */
my_syslog(MS_TFTP | LOG_ERR, "%s", mess->message); my_syslog(MS_TFTP | LOG_ERR, "%s", mess->message);
return ret; return ret;
} }
static ssize_t tftp_err_oops(char *packet, char *file) static ssize_t tftp_err_oops(char *packet, const char *file)
{ {
/* May have >1 refs to file, so potentially mangle a copy of the name */ /* May have >1 refs to file, so potentially mangle a copy of the name */
strcpy(daemon->namebuff, file); if (file != daemon->namebuff)
strcpy(daemon->namebuff, file);
return tftp_err(ERR_NOTDEF, packet, _("cannot read %s: %s"), daemon->namebuff) ; return tftp_err(ERR_NOTDEF, packet, _("cannot read %s: %s"), daemon->namebuff) ;
} }
/* return -1 for error, zero for done. */ /* return -1 for error, zero for done. */
static ssize_t get_block(char *packet, struct tftp_transfer *transfer) static ssize_t get_block(char *packet, struct tftp_transfer *transfer)
{ {
memset(packet, 0, daemon->packet_buff_sz); memset(packet, 0, daemon->packet_buff_sz);
if (transfer->block == 0) if (transfer->block == 0)
{ {
 End of changes. 7 change blocks. 
6 lines changed or deleted 27 lines changed or added

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