forked from mirrors/tftp-hpa-google
Even more portability work...
This commit is contained in:
parent
5b21a932a6
commit
3df5c1f25c
9 changed files with 100 additions and 32 deletions
18
aclocal.m4
vendored
18
aclocal.m4
vendored
|
@ -31,6 +31,24 @@ AC_DEFUN(PA_SIGSETJMP,
|
|||
AC_MSG_RESULT([no])
|
||||
$2)])
|
||||
|
||||
dnl --------------------------------------------------------------------------
|
||||
dnl PA_HAVE_LONG_LONG
|
||||
dnl
|
||||
dnl Does the C compiler support long long?
|
||||
dnl --------------------------------------------------------------------------
|
||||
AC_DEFUN(PA_HAVE_LONG_LONG,
|
||||
[AC_MSG_CHECKING([if C compiler supports long long])
|
||||
AC_TRY_LINK(
|
||||
[],
|
||||
[long long foo = 1LL;
|
||||
unsigned long long bar = 1ULL;
|
||||
return (int)(foo-bar);
|
||||
],
|
||||
AC_MSG_RESULT([yes])
|
||||
$1,
|
||||
AC_MSG_RESULT([no])
|
||||
$2)])
|
||||
|
||||
dnl --------------------------------------------------------------------------
|
||||
dnl PA_MSGHDR_MSG_CONTROL
|
||||
dnl
|
||||
|
|
26
config.h.in
26
config.h.in
|
@ -28,4 +28,30 @@
|
|||
#undef HAVE_STRINGS_H
|
||||
#undef HAVE_LIBGEN_H
|
||||
#undef HAVE_SYS_FILIO_H
|
||||
#undef HAVE_INTTYPES_H
|
||||
#undef HAVE_LONG_LONG
|
||||
#undef WITH_REGEX
|
||||
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#ifdef HAVE_LONG_LONG
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
#define PRIdMAX "%Ld"
|
||||
#define PRIuMAX "%Lu"
|
||||
#define PRIxMAX "%Lx"
|
||||
#define INTMAX_C(x) (x##LL)
|
||||
#define UINTMAX_C(x) (x##ULL)
|
||||
#define strtoumax(p,e,b) strtoull(p,e,b)
|
||||
#else
|
||||
typedef long intmax_t;
|
||||
typedef unsigned long uintmax_t;
|
||||
#define PRIdMAX "%ld"
|
||||
#define PRIuMAX "%lu"
|
||||
#define PRIxMAX "%lx"
|
||||
#define INTMAX_C(x) (x##L)
|
||||
#define UINTMAX_C(x) (x##UL)
|
||||
#define strtoumax(p,e,b) strtoul(p,e,b)
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -11,8 +11,8 @@ AC_PROG_CC
|
|||
AC_C_CONST
|
||||
AC_C_INLINE
|
||||
|
||||
PA_ADD_CFLAGS(-Wall)
|
||||
PA_ADD_CFLAGS(-W)
|
||||
PA_ADD_CFLAGS(-Wall)
|
||||
PA_ADD_CFLAGS(-Wpointer-arith)
|
||||
PA_ADD_CFLAGS(-Wbad-function-cast)
|
||||
PA_ADD_CFLAGS(-Wcast-equal)
|
||||
|
@ -22,11 +22,15 @@ PA_ADD_CFLAGS(-Wmissing-declarations)
|
|||
PA_ADD_CFLAGS(-Wnested-externs)
|
||||
PA_ADD_CFLAGS(-Winline)
|
||||
PA_ADD_CFLAGS(-Wwrite-strings)
|
||||
PA_ADD_CFLAGS(-Wundef)
|
||||
PA_ADD_CFLAGS(-Wshadow)
|
||||
PA_ADD_CFLAGS(-Wsign-compare)
|
||||
PA_ADD_CFLAGS(-pipe)
|
||||
|
||||
AC_CHECK_HEADERS(sysexits.h)
|
||||
AC_CHECK_HEADERS(strings.h)
|
||||
AC_CHECK_HEADERS(libgen.h)
|
||||
AC_CHECK_HEADERS(inttypes.h)
|
||||
AC_CHECK_HEADERS(sys/filio.h)
|
||||
|
||||
AC_SEARCH_LIBS(socket, socket, , [AC_MSG_ERROR(socket library not found)])
|
||||
|
@ -64,6 +68,7 @@ PA_WITH_BOOL(remap, 1,
|
|||
],:)
|
||||
|
||||
PA_SIGSETJMP([AC_DEFINE(HAVE_SIGSETJMP)])
|
||||
PA_HAVE_LONG_LONG([AC_DEFINE(HAVE_LONG_LONG)])
|
||||
|
||||
LIBXTRA=false
|
||||
AC_SEARCH_LIBS(xmalloc, iberty, , LIBXTRA=true LIBOBJS="$LIBOBJS xmalloc.o")
|
||||
|
|
|
@ -11,6 +11,7 @@ tftp: $(OBJS)
|
|||
$(OBJS): tftpsubs.h
|
||||
|
||||
install: tftp
|
||||
mkdir -p $(INSTALLROOT)$(BINDIR) $(INSTALLROOT)$(MANDIR)/man1
|
||||
$(INSTALL_PROGRAM) -s tftp $(INSTALLROOT)$(BINDIR)
|
||||
$(INSTALL_DATA) tftp.1 $(INSTALLROOT)$(MANDIR)/man1
|
||||
|
||||
|
|
|
@ -349,7 +349,6 @@ put(int argc, char *argv[])
|
|||
}
|
||||
targ = argv[argc - 1];
|
||||
if (strchr(argv[argc - 1], ':')) {
|
||||
char *cp;
|
||||
struct hostent *hp;
|
||||
|
||||
for (n = 1; n < argc - 1; n++)
|
||||
|
|
|
@ -16,6 +16,7 @@ tftpsubs.h:
|
|||
$(OBJS): tftpsubs.h
|
||||
|
||||
install: tftpd
|
||||
mkdir -p $(INSTALLROOT)$(SBINDIR) $(INSTALLROOT)$(MANDIR)/man8
|
||||
$(INSTALL_PROGRAM) tftpd $(INSTALLROOT)$(SBINDIR)/in.tftpd
|
||||
$(INSTALL_DATA) tftpd.8 $(INSTALLROOT)$(MANDIR)/man8/in.tftpd.8
|
||||
ln -sf in.tftpd.8 $(INSTALLROOT)$(MANDIR)/man8/tftpd.8
|
||||
|
|
|
@ -26,13 +26,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../config.h"
|
||||
#include "recvfrom.h"
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "../config.h"
|
||||
#include "recvfrom.h"
|
||||
#include "tftpsubs.h"
|
||||
|
||||
#if defined(HAVE_RECVMSG) && defined(HAVE_MSGHDR_MSG_CONTROL)
|
||||
|
||||
#include <sys/uio.h>
|
||||
|
|
|
@ -295,7 +295,7 @@ char *rewrite_string(const char *input, const struct rule *rules, int is_put)
|
|||
|
||||
if ( ruleptr->rule_flags & RULE_ABORT ) {
|
||||
if ( verbosity >= 3 ) {
|
||||
syslog(LOG_INFO, "remap: rule %d: abort",
|
||||
syslog(LOG_INFO, "remap: rule %d: abort: %s",
|
||||
ruleptr->nrule, current);
|
||||
}
|
||||
free(current);
|
||||
|
|
|
@ -201,12 +201,12 @@ main(int argc, char **argv)
|
|||
int n;
|
||||
int on = 1;
|
||||
int fd = 0;
|
||||
int listen = 0; /* Standalone (listen) mode */
|
||||
int standalone = 0; /* Standalone (listen) mode */
|
||||
char *address = NULL; /* Address to listen to */
|
||||
int pid;
|
||||
int c;
|
||||
int setrv;
|
||||
int timeout = 900; /* Default timeout */
|
||||
int waittime = 900; /* Default time to wait for a connect*/
|
||||
const char *user = "nobody"; /* Default user */
|
||||
char *p;
|
||||
#ifdef WITH_REGEX
|
||||
|
@ -229,13 +229,13 @@ main(int argc, char **argv)
|
|||
secure = 1;
|
||||
break;
|
||||
case 'l':
|
||||
listen = 1;
|
||||
standalone = 1;
|
||||
break;
|
||||
case 'a':
|
||||
address = optarg;
|
||||
break;
|
||||
case 't':
|
||||
timeout = atoi(optarg);
|
||||
waittime = atoi(optarg);
|
||||
break;
|
||||
case 'u':
|
||||
user = optarg;
|
||||
|
@ -307,7 +307,7 @@ main(int argc, char **argv)
|
|||
#endif
|
||||
|
||||
/* If we're running standalone, set up the input port */
|
||||
if ( listen ) {
|
||||
if ( standalone ) {
|
||||
fd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
memset(&bindaddr, 0, sizeof bindaddr);
|
||||
|
@ -376,7 +376,11 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
/* This means we don't want to wait() for children */
|
||||
#ifdef SA_NOCLDWAIT
|
||||
set_signal(SIGCHLD, SIG_IGN, SA_NOCLDSTOP|SA_NOCLDWAIT);
|
||||
#else
|
||||
set_signal(SIGCHLD, SIG_IGN, SA_NOCLDSTOP);
|
||||
#endif
|
||||
|
||||
/* Take SIGHUP and use it to set a variable. This
|
||||
is polled synchronously to make sure we don't
|
||||
|
@ -385,12 +389,12 @@ main(int argc, char **argv)
|
|||
|
||||
while ( 1 ) {
|
||||
fd_set readset;
|
||||
struct timeval tv_timeout;
|
||||
struct timeval tv_waittime;
|
||||
int rv;
|
||||
|
||||
if ( caught_sighup ) {
|
||||
caught_sighup = 0;
|
||||
if ( listen ) {
|
||||
if ( standalone ) {
|
||||
#ifdef HAVE_REGEX
|
||||
if ( rewrite_file ) {
|
||||
freerules(rewrite_rules);
|
||||
|
@ -405,11 +409,11 @@ main(int argc, char **argv)
|
|||
|
||||
FD_ZERO(&readset);
|
||||
FD_SET(fd, &readset);
|
||||
tv_timeout.tv_sec = timeout;
|
||||
tv_timeout.tv_usec = 0;
|
||||
tv_waittime.tv_sec = waittime;
|
||||
tv_waittime.tv_usec = 0;
|
||||
|
||||
/* Never time out if we're in listen mode */
|
||||
rv = select(fd+1, &readset, NULL, NULL, listen ? NULL : &tv_timeout);
|
||||
/* Never time out if we're in standalone mode */
|
||||
rv = select(fd+1, &readset, NULL, NULL, standalone ? NULL : &tv_waittime);
|
||||
if ( rv == -1 && errno == EINTR )
|
||||
continue; /* Signal caught, reloop */
|
||||
if ( rv == -1 ) {
|
||||
|
@ -424,7 +428,7 @@ main(int argc, char **argv)
|
|||
(struct sockaddr *)&from, &fromlen,
|
||||
&myaddr);
|
||||
|
||||
if ( listen && myaddr.sin_addr.s_addr == INADDR_ANY ) {
|
||||
if ( standalone && myaddr.sin_addr.s_addr == INADDR_ANY ) {
|
||||
/* myrecvfrom() didn't capture the source address; but we might
|
||||
have bound to a specific address, if so we should use it */
|
||||
memcpy(&myaddr.sin_addr, &bindaddr.sin_addr, sizeof bindaddr.sin_addr);
|
||||
|
@ -651,9 +655,12 @@ int
|
|||
set_blksize(char *val, char **ret)
|
||||
{
|
||||
static char b_ret[6];
|
||||
unsigned int sz = atoi(val);
|
||||
unsigned int sz;
|
||||
char *vend;
|
||||
|
||||
if ( blksize_set )
|
||||
sz = (unsigned int)strtoul(val, &vend, 10);
|
||||
|
||||
if ( blksize_set || *vend )
|
||||
return 0;
|
||||
|
||||
if (sz < 8)
|
||||
|
@ -676,9 +683,12 @@ int
|
|||
set_blksize2(char *val, char **ret)
|
||||
{
|
||||
static char b_ret[6];
|
||||
unsigned int sz = atoi(val);
|
||||
unsigned int sz;
|
||||
char *vend;
|
||||
|
||||
if ( blksize_set )
|
||||
sz = (unsigned int)strtoul(val, &vend, 10);
|
||||
|
||||
if ( blksize_set || *vend )
|
||||
return 0;
|
||||
|
||||
if (sz < 8)
|
||||
|
@ -711,15 +721,19 @@ set_blksize2(char *val, char **ret)
|
|||
int
|
||||
set_tsize(char *val, char **ret)
|
||||
{
|
||||
static char b_ret[sizeof(off_t)*CHAR_BIT/3+2];
|
||||
off_t sz = atol(val);
|
||||
static char b_ret[sizeof(uintmax_t)*CHAR_BIT/3+2];
|
||||
uintmax_t sz;
|
||||
char *vend;
|
||||
|
||||
if ( !tsize_ok )
|
||||
sz = strtoumax(val, &vend, 10);
|
||||
|
||||
if ( !tsize_ok || *vend )
|
||||
return 0;
|
||||
|
||||
if (sz == 0)
|
||||
sz = tsize;
|
||||
sprintf(*ret = b_ret, "%lu", sz);
|
||||
sz = (uintmax_t)tsize;
|
||||
|
||||
sprintf(*ret = b_ret, "%"PRIuMAX, sz);
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
@ -730,9 +744,12 @@ int
|
|||
set_timeout(char *val, char **ret)
|
||||
{
|
||||
static char b_ret[4];
|
||||
unsigned long to = atol(val);
|
||||
unsigned long to;
|
||||
char *vend;
|
||||
|
||||
if ( to < 1 || to > 255 )
|
||||
to = strtoul(val, &vend, 10);
|
||||
|
||||
if ( to < 1 || to > 255 || *vend )
|
||||
return 0;
|
||||
|
||||
timeout = to;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue