summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhpa <hpa>2001-08-03 03:17:57 +0000
committerhpa <hpa>2001-08-03 03:17:57 +0000
commit266427bc5bc6653ca16fe80d374fb4f47deceeec (patch)
tree4fecd6c3def67fc35e0bb3557b7698be6270b01b
parent4003a672ce68f2439f16fa3a097c1c845db4b92b (diff)
downloadtftp-hpa-266427bc5bc6653ca16fe80d374fb4f47deceeec.tar.gz
Portability improvements. Now compiles and works on Solaris 8, as well
as Linux.
-rw-r--r--README5
-rw-r--r--config.h.in3
-rw-r--r--configure.in14
-rw-r--r--lib/bsdsignal.c15
-rw-r--r--tftp/main.c5
-rw-r--r--tftp/tftp.c8
-rw-r--r--tftp/tftpsubs.c44
-rw-r--r--tftp/tftpsubs.h2
-rw-r--r--tftpd/recvfrom.c3
-rw-r--r--tftpd/tftpd.c10
10 files changed, 79 insertions, 30 deletions
diff --git a/README b/README
index d44a3d1..3cc732a 100644
--- a/README
+++ b/README
@@ -18,6 +18,11 @@ improvements.
===> IMPORTANT: SEE THE FILE "README.security" FOR IMPORTANT SECURITY
===> CHANGES ENACTED IN VERSION 0.17!!!!!!!!!
+Changes in 0.20:
+ Portability improvements. Now known to compile and run on
+ Solaris 8.
+
+
Changes in 0.19:
Fork before performing tcpwrappers check.
diff --git a/config.h.in b/config.h.in
index 57676a8..1b328fe 100644
--- a/config.h.in
+++ b/config.h.in
@@ -23,4 +23,7 @@
#undef HAVE_SETREUID
#undef HAVE_SETREGID
#undef HAVE_SYSEXITS_H
+#undef HAVE_STRINGS_H
+#undef HAVE_LIBGEN_H
+#undef HAVE_SYS_FILIO_H
#undef WITH_REGEX
diff --git a/configure.in b/configure.in
index 6a4ccad..1df071e 100644
--- a/configure.in
+++ b/configure.in
@@ -9,6 +9,16 @@ AC_PROG_CC
AC_C_CONST
AC_C_INLINE
+AC_CHECK_HEADERS(sysexits.h)
+AC_CHECK_HEADERS(strings.h)
+AC_CHECK_HEADERS(libgen.h)
+AC_CHECK_HEADERS(sys/filio.h)
+
+AC_SEARCH_LIBS(socket, socket, , [AC_MSG_ERROR(socket library not found)])
+AC_SEARCH_LIBS(gethostbyname, [nsl resolv], , [AC_MSG_ERROR(gethostbyname not found)])
+AC_SEARCH_LIBS(inet_aton, [nsl resolv], , [AC_MSG_ERROR(inet_aton not found)])
+AC_SEARCH_LIBS(herror, [nsl resolv], , [AC_MSG_ERROR(herror not found)])
+
AC_CHECK_FUNCS(recvmsg)
AC_CHECK_FUNCS(setreuid)
AC_CHECK_FUNCS(setregid)
@@ -50,14 +60,10 @@ PA_ADD_CFLAGS(-pipe)
PA_SIGSETJMP([AC_DEFINE(HAVE_SIGSETJMP)])
-AC_CHECK_HEADERS(sysexits.h)
-
LIBXTRA=false
-
AC_SEARCH_LIBS(xmalloc, iberty, , LIBXTRA=true LIBOBJS="$LIBOBJS xmalloc.o")
AC_SEARCH_LIBS(xstrdup, iberty, , LIBXTRA=true LIBOBJS="$LIBOBJS xstrdup.o")
AC_SEARCH_LIBS(bsd_signal, bsd, , LIBXTRA=true LIBOBJS="$LIBOBJS bsdsignal.o")
-
if $LIBXTRA; then
LIBS="../lib/libxtra.a $LIBS"
fi
diff --git a/lib/bsdsignal.c b/lib/bsdsignal.c
index 7740740..27e3a34 100644
--- a/lib/bsdsignal.c
+++ b/lib/bsdsignal.c
@@ -8,14 +8,23 @@
#include <stdlib.h>
#include <string.h>
-void bsd_signal(int signum, void (*handler)(int))
+void (*bsd_signal(int signum, void (*handler)(int)))(int);
{
- struct sigaction action;
+ struct sigaction action, oldaction;
memset(&action, 0, sizeof action);
action.sa_handler = handler;
sigemptyset(&action.sa_mask);
+ sigaddset(&act.sa_mask, signum);
action.sa_flags = SA_RESTART;
- sigaction(hander, action, NULL);
+ if (sigaction(hander, action, &oldaction) == -1) {
+#ifdef SIG_ERR
+ return SIG_ERR;
+#else
+ return NULL;
+#endif
+ }
+
+ return oldaction.sa_handler;
}
diff --git a/tftp/main.c b/tftp/main.c
index 844b4b4..6a5dac4 100644
--- a/tftp/main.c
+++ b/tftp/main.c
@@ -68,8 +68,13 @@ static const char *rcsid UNUSED =
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
#include "extern.h"
+#include "../config.h"
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
#define TIMEOUT 5 /* secs between rexmt's */
#define LBUFLEN 200 /* size of input buffer */
diff --git a/tftp/tftp.c b/tftp/tftp.c
index f1e6961..03b048e 100644
--- a/tftp/tftp.c
+++ b/tftp/tftp.c
@@ -68,7 +68,9 @@ static const char *rcsid UNUSED =
#include "../config.h"
#include "extern.h"
-void bsd_signal(int, void (*)(int));
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
#ifndef HAVE_SIGSETJMP
#define sigsetjmp(x,y) setjmp(x)
@@ -322,7 +324,7 @@ makerequest(int request, const char *name,
char *cp;
tp->th_opcode = htons((u_short)request);
- cp = tp->th_stuff;
+ cp = (char *) &(tp->th_stuff);
strcpy(cp, name);
cp += strlen(name);
*cp++ = '\0';
@@ -397,7 +399,7 @@ tpacket(const char *s, struct tftphdr *tp, int n)
case RRQ:
case WRQ:
n -= 2;
- file = cp = tp->th_stuff;
+ file = cp = (char *) &(tp->th_stuff);
cp = strchr(cp, '\0');
printf("<file=%s, mode=%s>\n", file, cp + 1);
break;
diff --git a/tftp/tftpsubs.c b/tftp/tftpsubs.c
index 8f66f4b..8a6e654 100644
--- a/tftp/tftpsubs.c
+++ b/tftp/tftpsubs.c
@@ -59,12 +59,14 @@ static const char *rcsid UNUSED =
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/tftp.h>
-
#include <stdio.h>
#include <unistd.h>
+#include "../config.h"
+
#define PKTSIZE MAX_SEGSIZE+4 /* should be moved to tftp.h */
int segsize = SEGSIZE; /* Default segsize */
@@ -254,20 +256,28 @@ skipit:
int
synchnet(int f) /* socket to flush */
{
- int i, j = 0;
- char rbuf[PKTSIZE];
- struct sockaddr_in from;
- int fromlen;
-
- while (1) {
- (void) ioctl(f, FIONREAD, &i);
- if (i) {
- j++;
- fromlen = sizeof from;
- (void) recvfrom(f, rbuf, sizeof (rbuf), 0,
- (struct sockaddr *)&from, &fromlen);
- } else {
- return(j);
- }
- }
+ int pktcount = 0;
+ char rbuf[PKTSIZE];
+ struct sockaddr_in from;
+ int fromlen;
+ fd_set socketset;
+ struct timeval notime;
+
+ while ( 1 ) {
+ notime.tv_sec = notime.tv_usec = 0;
+
+ FD_ZERO(&socketset);
+ FD_SET(f, &socketset);
+
+ if ( select(f, &socketset, NULL, NULL, &notime) <= 0 )
+ break; /* Nothing to read */
+
+ /* Otherwise drain the packet */
+ pktcount++;
+ fromlen = sizeof from;
+ (void) recvfrom(f, rbuf, sizeof (rbuf), 0,
+ (struct sockaddr *)&from, &fromlen);
+ }
+
+ return pktcount; /* Return packets drained */
}
diff --git a/tftp/tftpsubs.h b/tftp/tftpsubs.h
index 0937dad..0dff16e 100644
--- a/tftp/tftpsubs.h
+++ b/tftp/tftpsubs.h
@@ -75,7 +75,7 @@ extern char *xstrdup(const char *);
/*
* Signal-related stuff
*/
-void bsd_signal(int, void (*)(int));
+void (*bsd_signal(int, void (*)(int)))(int);
#ifndef HAVE_SIGSETJMP
#define sigsetjmp(x,y) setjmp(x)
diff --git a/tftpd/recvfrom.c b/tftpd/recvfrom.c
index c8af007..38eac94 100644
--- a/tftpd/recvfrom.c
+++ b/tftpd/recvfrom.c
@@ -28,6 +28,9 @@
#include "../config.h"
#include "recvfrom.h"
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
#if defined(HAVE_RECVMSG) && defined(HAVE_MSGHDR_MSG_CONTROL)
diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c
index e97d0af..fda6ce1 100644
--- a/tftpd/tftpd.c
+++ b/tftpd/tftpd.c
@@ -89,6 +89,12 @@ int allow_severity = -1; /* Don't log at all */
struct request_info wrap_request;
#endif
+#ifdef HAVE_LIBGEN_H
+#include <libgen.h> /* Necessary for basename() on Solaris */
+#endif
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h> /* Necessary for FIONBIO on Solaris */
+#endif
#define TIMEOUT 5 /* Default timeout (seconds) */
#define TRIES 4 /* Number of attempts to send each packet */
@@ -101,7 +107,7 @@ struct request_info wrap_request;
#define EOPTNEG 8
#endif
-extern char *__progname;
+char *__progname;
int peer;
int timeout = TIMEOUT;
int rexmtval = TIMEOUT;
@@ -444,7 +450,7 @@ tftp(struct tftphdr *tp, int size)
((struct tftphdr *)ackbuf)->th_opcode = ntohs(OACK);
- origfilename = cp = tp->th_stuff;
+ origfilename = cp = (char *) &(tp->th_stuff);
argn = 0;
while ( cp < buf + size && *cp ) {