forked from mirrors/tftp-hpa-google
Portability improvements.
This commit is contained in:
parent
8c3d63fba8
commit
68c0102aa6
6 changed files with 35 additions and 21 deletions
3
README
3
README
|
@ -21,6 +21,9 @@ improvements.
|
|||
Changes in 0.21:
|
||||
Support running in standalone mode, without inetd.
|
||||
|
||||
Even more portability improvements. Now known to compile
|
||||
and run on Solaris 5, 5.1, 6 and 7 as well as 8.
|
||||
|
||||
|
||||
Changes in 0.20:
|
||||
Portability improvements. Now known to compile and run on
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#undef HAVE_STRUCT_IN_PKTINFO
|
||||
#undef HAVE_SETREUID
|
||||
#undef HAVE_SETREGID
|
||||
#undef HAVE_SETSID
|
||||
#undef HAVE_SYSEXITS_H
|
||||
#undef HAVE_STRINGS_H
|
||||
#undef HAVE_LIBGEN_H
|
||||
|
|
|
@ -19,6 +19,7 @@ AC_SEARCH_LIBS(gethostbyname, [nsl resolv], , [AC_MSG_ERROR(gethostbyname not fo
|
|||
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(setsid)
|
||||
AC_CHECK_FUNCS(recvmsg)
|
||||
AC_CHECK_FUNCS(setreuid)
|
||||
AC_CHECK_FUNCS(setregid)
|
||||
|
|
|
@ -8,17 +8,19 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void (*bsd_signal(int signum, void (*handler)(int)))(int);
|
||||
void (*bsd_signal(int, void (*)(int)))(int);
|
||||
|
||||
void (*bsd_signal(int signum, void (*handler)(int)))(int)
|
||||
{
|
||||
struct sigaction action, oldaction;
|
||||
|
||||
memset(&action, 0, sizeof action);
|
||||
action.sa_handler = handler;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaddset(&act.sa_mask, signum);
|
||||
sigaddset(&action.sa_mask, signum);
|
||||
action.sa_flags = SA_RESTART;
|
||||
|
||||
if (sigaction(hander, action, &oldaction) == -1) {
|
||||
if (sigaction(signum, &action, &oldaction) == -1) {
|
||||
#ifdef SIG_ERR
|
||||
return SIG_ERR;
|
||||
#else
|
||||
|
|
|
@ -63,6 +63,7 @@ static const char *rcsid UNUSED =
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/tftp.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../config.h"
|
||||
|
|
|
@ -352,7 +352,7 @@ main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
if ( bind(fd, &bindaddr, sizeof bindaddr) ) {
|
||||
if (bind(fd, (struct sockaddr *)&bindaddr, sizeof bindaddr) < 0) {
|
||||
syslog(LOG_ERR, "cannot bind to local socket: %m");
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
|
@ -367,8 +367,13 @@ main(int argc, char **argv)
|
|||
exit(EX_OSERR);
|
||||
}
|
||||
close(0); close(1); close(2);
|
||||
#ifdef HAVE_SETSID
|
||||
setsid();
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
/* 0 is our socket descriptor */
|
||||
close(1); close(2);
|
||||
}
|
||||
|
||||
/* This means we don't want to wait() for children */
|
||||
|
@ -445,6 +450,9 @@ main(int argc, char **argv)
|
|||
|
||||
/* Child process: handle the actual request here */
|
||||
|
||||
/* Ignore SIGHUP */
|
||||
set_signal(SIGHUP, SIG_IGN, 0);
|
||||
|
||||
#ifdef HAVE_TCPWRAPPERS
|
||||
/* Verify if this was a legal request for us. This has to be
|
||||
done before the chroot, while /etc is still accessible. */
|
||||
|
@ -466,6 +474,18 @@ main(int argc, char **argv)
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Close file descriptors we don't need */
|
||||
close(fd);
|
||||
|
||||
/* Get a socket. This has to be done before the chroot(), since
|
||||
some systems require access to /dev to create a socket. */
|
||||
|
||||
peer = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (peer < 0) {
|
||||
syslog(LOG_ERR, "socket: %m");
|
||||
exit(EX_IOERR);
|
||||
}
|
||||
|
||||
/* Chroot and drop privileges */
|
||||
|
||||
if (secure && chroot(".")) {
|
||||
|
@ -492,32 +512,18 @@ main(int argc, char **argv)
|
|||
exit(EX_OSERR);
|
||||
}
|
||||
|
||||
/* Ignore SIGHUP */
|
||||
set_signal(SIGHUP, SIG_IGN, 0);
|
||||
|
||||
/* Close file descriptors we don't need */
|
||||
close(fd);
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
|
||||
/* Other basic setup */
|
||||
from.sin_family = AF_INET;
|
||||
alarm(0);
|
||||
|
||||
/* Process the request... */
|
||||
|
||||
peer = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (peer < 0) {
|
||||
syslog(LOG_ERR, "socket: %m");
|
||||
exit(EX_IOERR);
|
||||
}
|
||||
myaddr.sin_port = htons(0); /* We want a new local port */
|
||||
if (bind(peer, (struct sockaddr *)&myaddr, sizeof (myaddr)) < 0) {
|
||||
if (bind(peer, (struct sockaddr *)&myaddr, sizeof myaddr) < 0) {
|
||||
syslog(LOG_ERR, "bind: %m");
|
||||
exit(EX_IOERR);
|
||||
}
|
||||
if (connect(peer, (struct sockaddr *)&from, sizeof(from)) < 0) {
|
||||
if (connect(peer, (struct sockaddr *)&from, sizeof from) < 0) {
|
||||
syslog(LOG_ERR, "connect: %m");
|
||||
exit(EX_IOERR);
|
||||
}
|
||||
|
@ -634,7 +640,7 @@ tftp(struct tftphdr *tp, int size)
|
|||
else
|
||||
(*pf->f_send)(pf, NULL, 0);
|
||||
}
|
||||
exit(EX_SOFTWARE); /* We should never get here */
|
||||
exit(0); /* Request completed */
|
||||
}
|
||||
|
||||
static int blksize_set;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue