summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Tso <tytso@mit.edu>1994-11-08 02:37:55 +0000
committerTheodore Tso <tytso@mit.edu>1994-11-08 02:37:55 +0000
commite9f3b506a40b94b0e114f5e5a4fa98c90be949bc (patch)
tree4866ec989489026f64706d250e32489b5f0ada0a
parentc07299c91e3053726681cdce475ab9e0bd967791 (diff)
downloadkrb5-e9f3b506a40b94b0e114f5e5a4fa98c90be949bc.tar.gz
krb5-e9f3b506a40b94b0e114f5e5a4fa98c90be949bc.tar.xz
krb5-e9f3b506a40b94b0e114f5e5a4fa98c90be949bc.zip
Checked in Richard's changes of November 2nd. (See changelog). Lots of
portability fixes: POSIX_SIGNALS, POSIX_SETJMP, use of POSIX waitpid, etc. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4632 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r--src/appl/bsd/ChangeLog56
-rw-r--r--src/appl/bsd/configure.in12
-rw-r--r--src/appl/bsd/kcmd.c9
-rw-r--r--src/appl/bsd/krcp.c98
-rw-r--r--src/appl/bsd/krlogin.c305
-rw-r--r--src/appl/bsd/krlogind.c120
-rw-r--r--src/appl/bsd/krsh.c20
-rw-r--r--src/appl/bsd/krshd.c65
-rw-r--r--src/appl/bsd/login.c94
-rw-r--r--src/appl/bsd/logutil.c7
10 files changed, 565 insertions, 221 deletions
diff --git a/src/appl/bsd/ChangeLog b/src/appl/bsd/ChangeLog
index 9e98a094e..603529b1e 100644
--- a/src/appl/bsd/ChangeLog
+++ b/src/appl/bsd/ChangeLog
@@ -1,8 +1,64 @@
Mon Nov 7 21:22:00 1994 Theodore Y. Ts'o (tytso@dcl)
+ * configure.in: Remove unused check for HAVE_GETDTABLESIZE
+ (especially since we replace it with AC_REPLACE_FUNCS
+ later!)
+
* getdtablesize.c: Use POSIX method of obtaining fd table size,
if available.
+Wed Nov 02 22:21:00 1994 Richard Basch (probe@tardis)
+
+ * configure.in:
+ Moved POSIX signal check to aclocal.m4, and calls it (CHECK_SIGNALS)
+ Added POSIX setjmp check (CHECK_SETJMP).
+ Added checks for waitpid and setsid functions.
+
+ * kcmd.c:
+ Include <signal.h> not <sys/signal.h>.
+ Don't bother declaring sigmask when POSIX_SIGNALS is set.
+
+ * krcp.c:
+ Replaced the conditionalized BITS64 code with more portable code.
+ Use mode_t instead of int, for file modes.
+ Use waitpid, instead of wait, where available (HAVE_WAITPID).
+ Added POSIX signal handling (POSIX_SIGNALS).
+
+ * krlogin.c:
+ Include <unistd.h> and <stdlib.h> if available
+ Replaced the conditionalized BITS64 code with more portable code.
+ Use cfgetospeed() if POSIX_TERMIOS is defined. It was already being
+ used, so there is no need to use two methods.
+ Use waitpid, instead of wait, where available (HAVE_WAITPID).
+ Added POSIX setjmp handling (POSIX_SETJMP)
+ Added POSIX signal handling (POSIX_SIGNALS).
+
+ * krlogind.c:
+ Added POSIX signal handling (POSIX_SIGNALS).
+ Corrected an error in the arguments to chmod().
+ Call setsid() if HAVE_SETSID is defined.
+ Try not conditionalizing on __alpha; use other #ifdef's.
+ Replaced the conditionalized BITS64 code with more portable code.
+
+ * krsh.c:
+ Added POSIX signal handling (POSIX_SIGNALS)
+
+ * krshd.c:
+ Declare and manipulate the file descriptor arrays properly,
+ rather than bit shifting and passing them to select as
+ (long *). Some systems (eg. AIX) declare them to be structs.
+ Added POSIX signal handling (POSIX_SIGNALS)
+
+ * login.c:
+ Include <unistd.h> and <stdlib.h> if available
+ Added POSIX setjmp handling (POSIX_SETJMP)
+ Added POSIX signal handling (POSIX_SIGNALS)
+ Use waitpid, instead of wait, where available (HAVE_WAITPID).
+
+ * logutil.c:
+ Don't redeclare time(); it may conflict with the system header files.
+ Include <unistd.h> first.
+
Thu Oct 27 20:07:03 1994 Mark Eichin (eichin@cygnus.com)
* login.c (main): if CSTATUS is missing, don't set c_cc[VSTATUS]
diff --git a/src/appl/bsd/configure.in b/src/appl/bsd/configure.in
index 6fb739541..59ef052b7 100644
--- a/src/appl/bsd/configure.in
+++ b/src/appl/bsd/configure.in
@@ -21,22 +21,19 @@ AC_CHECK_LIB(odm,main,
AC_SUBST(LOGINLIBS)
dnl
AC_VFORK
+AC_TYPE_MODE_T
AC_FUNC_CHECK(strsave,AC_DEFINE(HAS_STRSAVE))
AC_FUNC_CHECK(utimes,AC_DEFINE(HAS_UTIMES))
AC_FUNC_CHECK(getutent,AC_DEFINE(HAVE_GETUTENT))
AC_FUNC_CHECK(setreuid,AC_DEFINE(HAVE_SETREUID))
AC_FUNC_CHECK(gettosbyname,AC_DEFINE(HAVE_GETTOSBYNAME))
AC_FUNC_CHECK(killpg,AC_DEFINE(HAVE_KILLPG))
-AC_FUNC_CHECK(getdtablesize,AC_DEFINE(HAVE_GETDTABLESIZE))
AC_FUNC_CHECK(initgroups,AC_DEFINE(HAVE_INITGROUPS))
AC_FUNC_CHECK(setpriority,AC_DEFINE(HAVE_SETPRIORITY))
AC_FUNC_CHECK(setreuid,AC_DEFINE(HAVE_SETREUID))
AC_FUNC_CHECK(setresuid,AC_DEFINE(HAVE_SETRESUID))
-AC_FUNC_CHECK(sigprocmask,
-AC_COMPILE_CHECK([sigset_t],
-[#include <signal.h>],
-[sigset_t x],
-AC_DEFINE(POSIX_SIGNALS)))
+AC_FUNC_CHECK(waitpid,AC_DEFINE(HAVE_WAITPID))
+AC_FUNC_CHECK(setsid,AC_DEFINE(HAVE_SETSID))
AC_HAVE_HEADERS(sys/filio.h sys/sockio.h unistd.h sys/label.h ttyent.h lastlog.h sys/select.h sys/ptyvar.h)
AC_COMPILE_CHECK([use streams interface],
[#include <sys/tty.h>
@@ -44,10 +41,11 @@ AC_COMPILE_CHECK([use streams interface],
#include <sys/ptyvar.h>],
[], AC_DEFINE(HAVE_STREAMS))
AC_REPLACE_FUNCS(getdtablesize)
+CHECK_SIGNALS
+CHECK_SETJMP
CHECK_DIRENT
CHECK_FCNTL
CHECK_WAIT_TYPE
-AC_WAIT3
AC_HEADER_CHECK(termios.h,AC_FUNC_CHECK([tcsetattr],AC_DEFINE(POSIX_TERMIOS)))
AC_COMPILE_CHECK([F_SETOWN],
[#include <sys/types.h>
diff --git a/src/appl/bsd/kcmd.c b/src/appl/bsd/kcmd.c
index 185b9cdf1..c64e4544e 100644
--- a/src/appl/bsd/kcmd.c
+++ b/src/appl/bsd/kcmd.c
@@ -40,15 +40,16 @@
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
+#include <signal.h>
#include <sys/file.h>
-#include <sys/signal.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
#ifndef POSIX_SIGNALS
#ifndef sigmask
#define sigmask(m) (1 << ((m)-1))
#endif
-#endif /* POSIX_SIGNALS */
-#include <sys/socket.h>
-#include <sys/stat.h>
+#endif
#include <netinet/in.h>
#include <netdb.h>
diff --git a/src/appl/bsd/krcp.c b/src/appl/bsd/krcp.c
index 31094f3f7..ccc05aa81 100644
--- a/src/appl/bsd/krcp.c
+++ b/src/appl/bsd/krcp.c
@@ -98,13 +98,6 @@ void send_auth(), answer_auth();
int encryptflag = 0;
#define UCB_RCP "/bin/rcp"
-
-#ifdef CRAY
-#ifndef BITS64
-#define BITS64
-#endif
-#endif
-
#else /* !KERBEROS */
#define des_read read
#define des_write write
@@ -146,6 +139,9 @@ main(argc, argv)
char buf[BUFSIZ], cmd[16];
struct servent *sp;
static char curhost[256];
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+#endif
#ifdef KERBEROS
krb5_flags authopts;
krb5_error_code status;
@@ -155,10 +151,10 @@ main(argc, argv)
krb5_init_ets();
desinbuf.data = des_inbuf;
desoutbuf.data = des_outbuf; /* Set up des buffers */
-
#else
sp = getservbyname("shell", "tcp");
#endif /* KERBEROS */
+
if (sp == NULL) {
#ifdef KERBEROS
fprintf(stderr, "rcp: kshell/tcp: unknown service\n");
@@ -245,13 +241,19 @@ main(argc, argv)
encryptflag ? " -x" : "",
targetshouldbedirectory ? " -d" : "");
#else /* !KERBEROS */
-
(void) sprintf(cmd, "rcp%s%s%s",
iamrecursive ? " -r" : "", pflag ? " -p" : "",
targetshouldbedirectory ? " -d" : "");
#endif /* KERBEROS */
+#ifdef POSIX_SIGNALS
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = lostconn;
+ (void) sigaction(SIGPIPE, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGPIPE, lostconn);
+#endif
targ = colon(argv[argc - 1]);
/* Check if target machine is the current machine. */
@@ -548,21 +550,46 @@ okname(cp0)
susystem(s)
char *s;
{
- int status, pid, w;
+ int status;
+ pid_t pid, w;
+#ifdef POSIX_SIGNALS
+ struct sigaction sa, isa, qsa;
+#else
register krb5_sigtype (*istat)(), (*qstat)();
+#endif
if ((pid = vfork()) == 0) {
execl("/bin/sh", "sh", "-c", s, (char *)0);
_exit(127);
}
+
+#ifdef POSIX_SIGNALS
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_IGN;
+ (void) sigaction(SIGINT, &sa, &isa);
+ (void) sigaction(SIGQUIT, &sa, &qsa);
+#else
istat = signal(SIGINT, SIG_IGN);
qstat = signal(SIGQUIT, SIG_IGN);
- while ((w = wait(&status)) != pid && w != -1)
- ;
- if (w == -1)
+#endif
+
+#ifdef HAVE_WAITPID
+ w = waitpid(pid, &status, 0);
+#else
+ while ((w = wait(&status)) != pid && w != -1) /*void*/ ;
+#endif
+ if (w == (pid_t)-1)
status = -1;
+
+#ifdef POSIX_SIGNALS
+ (void) sigaction(SIGINT, &isa, (struct sigaction *)0);
+ (void) sigaction(SIGQUIT, &qsa, (struct sigaction *)0);
+#else
(void) signal(SIGINT, istat);
(void) signal(SIGQUIT, qstat);
+#endif
+
return (status);
}
@@ -787,14 +814,15 @@ sink(argc, argv)
int argc;
char **argv;
{
+ mode_t mode;
+ mode_t mask = umask(0);
off_t i, j;
char *targ, *whopp, *cp;
- int of, mode, wrerr, exists, first, count, amt, size;
+ int of, wrerr, exists, first, count, amt, size;
struct buffer *bp;
static struct buffer buffer;
struct stat stb;
int targisdir = 0;
- int mask = umask(0);
char *myargv[1];
char cmdbuf[BUFSIZ], nambuf[BUFSIZ];
int setimes = 0;
@@ -919,12 +947,13 @@ sink(argc, argv)
error("rcp: %s: %s\n", nambuf, sys_errlist[errno]);
continue;
}
- if (exists && pflag)
+ if (exists && pflag) {
#ifdef NOFCHMOD
- (void) chmod(nambuf, mode);
+ (void) chmod(nambuf, mode);
#else
- (void) fchmod(of, mode);
+ (void) fchmod(of, mode);
#endif
+ }
ga();
if ((bp = allocbuf(&buffer, of, BUFSIZ)) == NULLBUF) {
(void) close(of);
@@ -1040,7 +1069,7 @@ usage()
#ifdef KERBEROS
fprintf(stderr,
"Usage: \trcp [-p] [-x] [-k realm] f1 f2; or:\n\trcp [-r] [-p] [-x] [-k realm] f1 ... fn d2\n");
-#else /* !KERBEROS */
+#else
fputs("usage: rcp [-p] f1 f2; or: rcp [-rp] f1 ... fn d2\n", stderr);
#endif
exit(1);
@@ -1350,6 +1379,7 @@ int des_read(fd, buf, len)
long net_len,rd_len;
int cc;
krb5_error_code status;
+ unsigned char len_buf[4];
if (!encryptflag)
return(read(fd, buf, len));
@@ -1367,21 +1397,12 @@ int des_read(fd, buf, len)
nstored = 0;
}
-#ifdef BITS64
- /*
- * XXX Ick; this assumes a big-endian word order....
- */
- rd_len = 0;
- if ((cc = krb5_net_read(fd, (char *)&rd_len + 4, 4)) != 4) {
-#else
- if ((cc = krb5_net_read(fd, (char *)&rd_len, sizeof(rd_len))) !=
- sizeof(rd_len)) {
-#endif
- /* XXX can't read enough, pipe
- must have closed */
+ if ((cc = krb5_net_read(fd, (char *)&len_buf, 4)) != 4) {
+ /* XXX can't read enough, pipe must have closed */
return(0);
}
- rd_len = ntohl(rd_len);
+ rd_len =
+ ((len_buf[0]<<24) | (len_buf[1]<<16) | (len_buf[2]<<8) | len_buf[3]);
net_len = krb5_encrypt_size(rd_len,eblock.crypto_entry);
if (net_len <= 0 || net_len > sizeof(des_inbuf)) {
/* preposterous length; assume out-of-sync; only
@@ -1429,7 +1450,7 @@ int des_write(fd, buf, len)
char *buf;
int len;
{
- long net_len;
+ unsigned char len_buf[4];
if (!encryptflag)
return(write(fd, buf, len));
@@ -1446,12 +1467,11 @@ int des_write(fd, buf, len)
return(-1);
}
- net_len = htonl(len);
-#ifdef BITS64
- (void) write(fd,(char *)&net_len + 4, 4);
-#else
- (void) write(fd, &net_len, sizeof(net_len));
-#endif
+ len_buf[0] = (len & 0xff000000);
+ len_buf[1] = (len & 0xff0000);
+ len_buf[2] = (len & 0xff00);
+ len_buf[3] = (len & 0xff);
+ (void) write(fd, len_buf, 4);
if (write(fd, desoutbuf.data,desoutbuf.length) != desoutbuf.length){
return(-1);
}
diff --git a/src/appl/bsd/krlogin.c b/src/appl/bsd/krlogin.c
index b9a69efad..065a05f26 100644
--- a/src/appl/bsd/krlogin.c
+++ b/src/appl/bsd/krlogin.c
@@ -35,7 +35,15 @@ char copyright[] =
#ifdef _AIX
#undef _BSD
#endif
-
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+
#include <sys/types.h>
#include <sys/param.h>
#include <sys/ioctl.h>
@@ -113,9 +121,6 @@ char copyright[] =
#include <sys/ioctl_compat.h>
#endif
-struct termios deftty;
-
-
#ifdef POSIX_TERMIOS
#ifdef CRAY
#include <sys/ttold.h>
@@ -156,24 +161,23 @@ struct sockaddr_in local, foreign;
#define UCB_RLOGIN "/usr/ucb/rlogin"
-#ifdef CRAY
-#ifndef BITS64
-#define BITS64
-#endif
-#endif
-
#include "rpaths.h"
#else /* !KERBEROS */
#define des_read read
#define des_write write
#endif /* KERBEROS */
-
# ifndef TIOCPKT_WINDOW
# define TIOCPKT_WINDOW 0x80
# endif /* TIOCPKT_WINDOW */
+#ifdef POSIX_TERMIOS
+struct termios deftty;
+#endif
+
+krb5_sigtype exit();
char *getenv();
+
char *name;
int rem = -1; /* Remote socket fd */
char cmdchar = '~';
@@ -201,25 +205,30 @@ char *speeds[] =
#endif
char term[256] = "network";
extern int errno;
-krb5_sigtype lostpeer();
-int dosigwinch = 0;
+
#ifndef POSIX_SIGNALS
#ifndef sigmask
#define sigmask(m) (1 << ((m)-1))
#endif
#endif /* POSIX_SIGNALS */
+
#ifdef NO_WINSIZE
struct winsize {
unsigned short ws_row, ws_col;
unsigned short ws_xpixel, ws_ypixel;
};
#endif /* NO_WINSIZE */
+int dosigwinch = 0;
struct winsize winsize;
-krb5_sigtype sigwinch(), oob();
+
char *host=0; /* external, so it can be
reached from confirm_death() */
-
+krb5_sigtype sigwinch(), oob();
+krb5_sigtype lostpeer();
+#if __STDC__
+int setsignal(int sig, krb5_sigtype (*act)());
+#endif
/*
* The following routine provides compatibility (such as it is)
@@ -304,6 +313,7 @@ main(argc, argv)
struct servent *sp;
int uid, options = 0;
#ifdef POSIX_SIGNALS
+ struct sigaction sa;
sigset_t *oldmask, omask, urgmask;
#else
int oldmask;
@@ -315,7 +325,7 @@ main(argc, argv)
krb5_flags authopts;
krb5_error_code status;
int debug_port = 0;
-#endif /* KERBEROS */
+#endif
if (strrchr(argv[0], '/'))
argv[0] = strrchr(argv[0], '/')+1;
@@ -485,11 +495,14 @@ main(argc, argv)
not a table index. */
sprintf (term + strlen (term), "%d", ospeed);
else {
-#ifdef CBAUD
-/* some "posix" systems don't have cfget... so used CBAUD if it's there */
+ (void) strcat(term, speeds[ospeed]);
+#if 0
+ /* XXX - Not used, since the above code was
+ * not ifdef'd and it relied on cfget... */
+
+ /* some "posix" systems don't have cfget...
+ * so used CBAUD if it's there */
(void) strcat(term, speeds[ttyb.c_cflag & CBAUD]);
-#else
- (void) strcat(term, speeds[cfgetospeed(&ttyb)]);
#endif
}
}
@@ -509,19 +522,25 @@ main(argc, argv)
/**** moved before rcmd call so that if get a SIGPIPE in rcmd **/
/**** we will have the defmodes set already. ***/
(void)ioctl(fileno(stdin), TIOCGETP, &defmodes);
- (void)ioctl(fileno(stdin), TIOCGETP,&ixon_state);
+ (void)ioctl(fileno(stdin), TIOCGETP, &ixon_state);
#endif
#endif
- (void) signal(SIGPIPE, lostpeer);
-
+
+ /* Catch SIGPIPE, as that means we lost the connection */
/* will use SIGUSR1 for window size hack, so hold it off */
#ifdef POSIX_SIGNALS
- sigemptyset(&urgmask);
- sigaddset(&urgmask, SIGURG);
- sigaddset(&urgmask, SIGUSR1);
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = lostpeer;
+ (void) sigaction(SIGPIPE, &sa, (struct sigaction *)0);
+
+ (void) sigemptyset(&urgmask);
+ (void) sigaddset(&urgmask, SIGURG);
+ (void) sigaddset(&urgmask, SIGUSR1);
oldmask = &omask;
- sigprocmask(SIG_BLOCK, &urgmask, oldmask);
+ (void) sigprocmask(SIG_BLOCK, &urgmask, oldmask);
#else
+ (void) signal(SIGPIPE, lostpeer);
#ifdef sgi
oldmask = sigignore(sigmask(SIGURG) | sigmask(SIGUSR1));
#else
@@ -701,18 +720,21 @@ struct ltchars noltc = { -1, -1, -1, -1, -1, -1 };
doit(oldmask)
#ifdef POSIX_SIGNALS
- sigset_t *oldmask;
+ sigset_t *oldmask;
#endif
{
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+#endif
+
#ifdef POSIX_TERMIOS
- (void) tcgetattr(0, &deftty);
-/* was __svr4__ */
+ (void) tcgetattr(0, &deftty);
#ifdef VLNEXT
- /* there's a POSIX way of doing this, but do we need it general? */
- deftty.c_cc[VLNEXT] = 0;
+ /* there's a POSIX way of doing this, but do we need it general? */
+ deftty.c_cc[VLNEXT] = 0;
#endif
#ifdef TIOCGLTC
- (void) ioctl(0, TIOCGLTC, (char *)&defltc);
+ (void) ioctl(0, TIOCGLTC, (char *)&defltc);
#endif
#else
#ifdef USE_TERMIO
@@ -749,10 +771,19 @@ doit(oldmask)
notc.t_startc = deftc.t_startc;
notc.t_stopc = deftc.t_stopc;
(void) ioctl(0, TIOCGLTC, (char *)&defltc);
-#endif
+#endif
+#ifdef POSIX_SIGNALS
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_IGN;
+ (void) sigaction(SIGINT, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGINT, SIG_IGN);
+#endif
+
setsignal(SIGHUP, exit);
- setsignal(SIGQUIT,exit);
+ setsignal(SIGQUIT, exit);
+
child = fork();
if (child == -1) {
perror("rlogin: fork");
@@ -775,17 +806,26 @@ doit(oldmask)
* the reader. Set a trap that simply copies such signals to
* the child.
*/
- (void) signal(SIGURG, copytochild);
- (void) signal(SIGUSR1, writeroob);
-
#ifdef POSIX_SIGNALS
+ /* "sa" has already been initialized above. */
+ sa.sa_handler = copytochild;
+ (void) sigaction(SIGURG, &sa, (struct sigaction *)0);
+
+ sa.sa_handler = writeroob;
+ (void) sigaction(SIGUSR1, &sa, (struct sigaction *)0);
+
sigprocmask(SIG_SETMASK, oldmask, (sigset_t*)0);
+
+ sa.sa_handler = catchild;
+ (void) sigaction(SIGCHLD, &sa, (struct sigaction *)0);
#else
+ (void) signal(SIGURG, copytochild);
+ (void) signal(SIGUSR1, writeroob);
#ifndef sgi
(void) sigsetmask(oldmask);
#endif
-#endif /* POSIX_SIGNALS */
(void) signal(SIGCHLD, catchild);
+#endif /* POSIX_SIGNALS */
writer();
prf("Closed connection.");
done(0);
@@ -802,6 +842,8 @@ setsignal(sig, act)
{
#ifdef POSIX_SIGNALS
sigset_t omask, igmask;
+ struct sigaction sa;
+
sigemptyset(&igmask);
sigaddset(&igmask, sig);
sigprocmask(SIG_BLOCK, &igmask, &omask);
@@ -813,11 +855,18 @@ setsignal(sig, act)
#endif
#endif /* POSIX_SIGNALS */
- if (signal(sig, act) == SIG_IGN)
- (void) signal(sig, SIG_IGN);
#ifdef POSIX_SIGNALS
+ (void) sigaction(sig, (struct sigaction *)0, &sa);
+ if (sa.sa_handler != SIG_IGN) {
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = act;
+ (void) sigaction(sig, &sa, (struct sigaction *)0);
+ }
sigprocmask(SIG_SETMASK, &omask, (sigset_t*)0);
#else
+ if (signal(sig, act) == SIG_IGN)
+ (void) signal(sig, SIG_IGN);
#ifndef sgi
(void) sigsetmask(omask);
#endif
@@ -829,15 +878,33 @@ setsignal(sig, act)
done(status)
int status;
{
- int w;
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+#endif
+#ifndef HAVE_WAITPID
+ pid_t w;
+#endif
mode(0);
if (child > 0) {
/* make sure catchild does not snap it up */
+#ifdef POSIX_SIGNALS
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_DFL;
+ (void) sigaction(SIGCHLD, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGCHLD, SIG_DFL);
- if (kill(child, SIGKILL) >= 0)
- while ((w = wait(0)) > 0 && w != child)
- /*void*/;
+#endif
+
+ if (kill(child, SIGKILL) >= 0) {
+#ifdef HAVE_WAITPID
+ (void) waitpid(child, 0, 0);
+#else
+ while ((w = wait(0)) > 0 && w != child)
+ /*void*/;
+#endif
+ }
}
exit(status);
}
@@ -850,7 +917,6 @@ done(status)
krb5_sigtype
copytochild()
{
-
(void) kill(child, SIGURG);
}
@@ -863,10 +929,20 @@ krb5_sigtype
krb5_sigtype
writeroob()
{
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+#endif
if (dosigwinch == 0) {
sendwindow();
+#ifdef POSIX_SIGNALS
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = sigwinch;
+ (void) sigaction(SIGWINCH, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGWINCH, sigwinch);
+#endif
}
dosigwinch = 1;
}
@@ -884,10 +960,10 @@ krb5_sigtype
int pid;
again:
-#ifdef HAVE_WAIT3
- pid = wait3(&status, WNOHANG|WUNTRACED, (struct rusage *)0);
-#else
+#ifdef HAVE_WAITPID
pid = waitpid(-1, &status, WNOHANG|WUNTRACED);
+#else
+ pid = wait3(&status, WNOHANG|WUNTRACED, (struct rusage *)0);
#endif
if (pid == 0)
return;
@@ -902,7 +978,7 @@ krb5_sigtype
/* I think this one is wrong: XXX -- [eichin:19940727.1853EST] */
if ((pid < 0) || ((pid == child) && (!WIFSTOPPED(status.w_stopval))))
#else
- if ((pid < 0) || ((pid == child) && (!WIFSTOPPED( status))))
+ if ((pid < 0) || ((pid == child) && (!WIFSTOPPED(status))))
#endif
done((int)(status.w_termsig | status.w_retcode));
#endif
@@ -1056,8 +1132,21 @@ echo(c)
stop(cmdc)
char cmdc;
{
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+#endif
+
mode(0);
+
+#ifdef POSIX_SIGNALS
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_IGN;
+ (void) sigaction(SIGCHLD, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGCHLD, SIG_IGN);
+#endif
+
#ifdef TIOCGLTC
(void) kill(cmdc == defltc.t_suspc ? 0 : getpid(), SIGTSTP);
#else
@@ -1065,7 +1154,14 @@ stop(cmdc)
(void) kill(cmdc == deftty.c_cc[VSUSP] ? 0 : getpid(), SIGTSTP);
#endif
#endif
+
+#ifdef POSIX_SIGNALS
+ sa.sa_handler = catchild;
+ (void) sigaction(SIGCHLD, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGCHLD, catchild);
+#endif
+
mode(1);
sigwinch(); /* check for size changes */
}
@@ -1117,7 +1213,12 @@ char rcvbuf[8 * 1024];
int rcvcnt;
int rcvstate;
int ppid;
-jmp_buf rcvtop;
+
+#ifdef POSIX_SETJMP
+sigjmp_buf rcvtop;
+#else
+jmp_buf rcvtop;
+#endif
krb5_sigtype
oob()
@@ -1240,7 +1341,11 @@ krb5_sigtype
* restart anyway.
*/
rcvcnt = 0;
+#ifdef POSIX_SETJMP
+ siglongjmp(rcvtop, 1);
+#else
longjmp(rcvtop, 1);
+#endif
}
/*
@@ -1252,8 +1357,13 @@ krb5_sigtype
* longjmp to the top to restart appropriately. Don't abort
* a pending write, however, or we won't know how much was written.
*/
+#ifdef POSIX_SETJMP
+ if (rcvd && rcvstate == READING)
+ siglongjmp(rcvtop, 1);
+#else
if (rcvd && rcvstate == READING)
- longjmp(rcvtop, 1);
+ longjmp(rcvtop, 1);
+#endif
}
@@ -1275,14 +1385,31 @@ reader(oldmask)
#endif
int n, remaining;
char *bufp = rcvbuf;
-
+
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_IGN;
+ (void) sigaction(SIGTTOU, &sa, (struct sigaction *)0);
+
+ sa.sa_handler = oob;
+ (void) sigaction(SIGURG, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGTTOU, SIG_IGN);
(void) signal(SIGURG, oob);
+#endif
+
ppid = getppid();
#ifdef HAVE_SETOWN
(void) fcntl(rem, F_SETOWN, pid);
#endif
+#ifdef POSIX_SETJMP
+ (void) sigsetjmp(rcvtop, 1);
+#else
(void) setjmp(rcvtop);
+#endif
#ifdef POSIX_SIGNALS
sigprocmask(SIG_SETMASK, oldmask, (sigset_t*)0);
#else
@@ -1533,6 +1660,7 @@ int des_read(fd, buf, len)
int nreturned = 0;
long net_len,rd_len;
int cc;
+ unsigned char len_buf[4];
if (!encrypt_flag)
return(read(fd, buf, len));
@@ -1550,23 +1678,14 @@ int des_read(fd, buf, len)
nstored = 0;
}
-#ifdef BITS64
- /*
- * XXX Ick. This assumes big endian byte order.
- */
- rd_len = 0;
- if ((cc = krb5_net_read(fd, (char *)&rd_len + 4, 4)) != 4) {
-#else
- if ((cc = krb5_net_read(fd, (char *)&rd_len, sizeof(rd_len))) !=
- sizeof(rd_len)) {
-#endif
- /* XXX can't read enough, pipe
- must have closed */
+ if ((cc = krb5_net_read(fd, (char *)&len_buf, 4)) != 4) {
+ /* XXX can't read enough, pipe must have closed */
return(0);
}
- rd_len = ntohl(rd_len);
+ rd_len =
+ ((len_buf[0]<<24) | (len_buf[1]<<16) | (len_buf[2]<<8) | len_buf[3]);
net_len = krb5_encrypt_size(rd_len,eblock.crypto_entry);
- if (net_len <= 0 || net_len > sizeof(des_inbuf)) {
+ if ((net_len <= 0) || (net_len > sizeof(des_inbuf))) {
/* preposterous length; assume out-of-sync; only
recourse is to close connection, so return 0 */
fprintf(stderr,"Read size problem.\n");
@@ -1610,7 +1729,7 @@ int des_write(fd, buf, len)
char *buf;
int len;
{
- long net_len;
+ unsigned char len_buf[4];
if (!encrypt_flag)
return(write(fd, buf, len));
@@ -1629,12 +1748,11 @@ int des_write(fd, buf, len)
return(-1);
}
- net_len = htonl(len);
-#ifdef BITS64
- (void) write(fd,(char *)&net_len + 4, 4);
-#else
- (void) write(fd, &net_len, sizeof(net_len));
-#endif
+ len_buf[0] = (len & 0xff000000);
+ len_buf[1] = (len & 0xff0000);
+ len_buf[2] = (len & 0xff00);
+ len_buf[3] = (len & 0xff);
+ (void) write(fd, len_buf, 4);
if (write(fd, desoutbuf.data,desoutbuf.length) != desoutbuf.length){
fprintf(stderr,"Could not write out all data.\n");
return(-1);
@@ -1661,6 +1779,7 @@ int des_read(fd, buf, len)
int nreturned = 0;
long net_len, rd_len;
int cc;
+ unsigned char len_buf[4];
if (!encrypt_flag)
return(read(fd, buf, len));
@@ -1677,18 +1796,12 @@ int des_read(fd, buf, len)
len -= nstored;
nstored = 0;
}
-#ifdef BITS64
- net_len = 0;
- if ((cc = krb5_net_read(fd, (char *)&net_len + 4, 4)) != 4) {
-#else
- if ((cc = krb5_net_read(fd, &net_len, sizeof(net_len))) !=
- sizeof(net_len)) {
-#endif
- /* XXX can't read enough, pipe
- must have closed */
+ if ((cc = krb5_net_read(fd, len_buf, 4)) != 4) {
+ /* XXX can't read enough, pipe must have closed */
return(0);
}
- net_len = ntohl(net_len);
+ net_len =
+ ((len_buf[0]<<24) | (len_buf[1]<<16) | (len_buf[2]<<8) | len_buf[3]);
if (net_len < 0 || net_len > sizeof(des_inbuf)) {
/* XXX preposterous length, probably out of sync.
act as if pipe closed */
@@ -1741,8 +1854,8 @@ int des_write(fd, buf, len)
char *buf;
int len;
{
- long net_len;
static char garbage_buf[8];
+ unsigned char len_buf[4];
if (!encrypt_flag)
return(write(fd, buf, len));
@@ -1764,12 +1877,11 @@ int des_write(fd, buf, len)
/* tell the other end the real amount, but send an 8-byte padded
packet */
- net_len = htonl(len);
-#ifdef BITS64
- (void) write(fd,(char *)&net_len + 4, 4);
-#else
- (void) write(fd, &net_len, sizeof(net_len));
-#endif
+ len_buf[0] = (len & 0xff000000);
+ len_buf[1] = (len & 0xff0000);
+ len_buf[2] = (len & 0xff00);
+ len_buf[3] = (len & 0xff);
+ (void) write(fd, len_buf, 4);
#ifdef NOROUNDUP
(void) write(fd, des_outbuf, ((((len)+((8)-1))/(8))*(8)));
#else
@@ -1785,8 +1897,17 @@ int des_write(fd, buf, len)
krb5_sigtype lostpeer()
{
-
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_IGN;
+ (void) sigaction(SIGPIPE, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGPIPE, SIG_IGN);
+#endif
+
prf("\007Connection closed.");
done(1);
}
diff --git a/src/appl/bsd/krlogind.c b/src/appl/bsd/krlogind.c
index 867945801..d8bd1f746 100644
--- a/src/appl/bsd/krlogind.c
+++ b/src/appl/bsd/krlogind.c
@@ -244,12 +244,6 @@ krb5_encrypt_block eblock; /* eblock for encrypt/decrypt */
krb5_authenticator *kdata;
krb5_ticket *ticket = 0;
-#ifdef CRAY
-#ifndef BITS64
-#define BITS64
-#endif
-#endif
-
#define ARGSTR "rRkKeExXpPD:?"
#else /* !KERBEROS */
#define ARGSTR "rRpPD:?"
@@ -303,6 +297,7 @@ static int Pfd;
void fatal(), fatalperror(), doit(), usage(), do_krb_login();
int princ_maps_to_lname(), default_realm();
+krb5_sigtype cleanup();
int must_pass_rhosts = 0, must_pass_k5 = 0, must_pass_one = 0;
int do_encrypt = 0, passwd_if_fail = 0, passwd_req = 0;
@@ -481,7 +476,6 @@ main(argc, argv)
#endif
int child;
-int cleanup();
int netf;
char line[MAXPATHLEN];
extern char *inet_ntoa();
@@ -501,6 +495,9 @@ void doit(f, fromp)
char c;
char buferror[255];
struct passwd *pwd;
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+#endif
netf = -1;
alarm(60);
@@ -509,8 +506,15 @@ void doit(f, fromp)
if (c != 0){
exit(1);
}
-
+
alarm(0);
+
+#ifdef POSIX_SIGNALS
+ /* Initialize "sa" structure. */
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+#endif
+
fromp->sin_port = ntohs((u_short)fromp->sin_port);
hp = gethostbyaddr(&fromp->sin_addr, sizeof (struct in_addr),
fromp->sin_family);
@@ -571,30 +575,36 @@ void doit(f, fromp)
/* Make sure we can open slave pty, then close it for system 5 so that
the process group is set correctly..... */
-#ifdef __alpha
- /* osf/1 method of losing controlling tty...*/
- setsid();
-#endif
#ifdef VHANG_FIRST
vfd = open(line, O_RDWR);
if (vfd < 0)
fatalperror(f, line);
#ifdef NOFCHMOD
- if (chmod(vfd,0))
+ if (chmod(line, 0))
+ fatalperror(f, line);
#else
if (fchmod(vfd, 0))
-#endif
fatalperror(f, line);
+#endif
#ifndef SYSV
if (f == 0) { /* if operating standalone, do not reset tty!! */
+#ifdef POSIX_SIGNALS
+ sa.sa_handler = SIG_IGN;
+ (void) sigaction(SIGHUP, &sa, (struct sigaction *)0);
+ vhangup();
+ sa.sa_handler = SIG_DFL;
+ (void) sigaction(SIGHUP, &sa, (struct sigaction *)0);
+#else
signal(SIGHUP, SIG_IGN);
vhangup();
signal(SIGHUP, SIG_DFL);
+#endif
}
#endif
#endif /* VHANG_FIRST */
-#if defined (sun) || defined (POSIX)
- setsid();
+
+#ifdef HAVE_SETSID
+ (void) setsid();
#endif
t = open(line, O_RDWR);
@@ -605,7 +615,7 @@ void doit(f, fromp)
#endif /* VHANG_FIRST */
if (t < 0)
fatalperror(f, line);
-#ifdef __alpha
+#ifdef TIOCSCTTY
if(ioctl(t, TIOCSCTTY, 0) < 0) /* set controlling tty */
fatalperror(f, "setting controlling tty");
#endif
@@ -613,8 +623,14 @@ void doit(f, fromp)
close(t);
#endif
#endif /* sysvimp */
+#ifdef POSIX_SIGNALS
+ sa.sa_handler = cleanup;
+ (void) sigaction(SIGCHLD, &sa, (struct sigaction *)0);
+ (void) sigaction(SIGTERM, &sa, (struct sigaction *)0);
+#else
signal(SIGCHLD, cleanup);
signal(SIGTERM, cleanup);
+#endif
pid = fork();
if (pid < 0)
fatalperror(f, "", errno);
@@ -664,20 +680,17 @@ void doit(f, fromp)
#else
pid = getpgrp(getpid());
#endif
-#endif
-#ifdef POSIX_TERMIOS /* solaris */
+#endif /* sysvimp */
+
+#ifdef POSIX_TERMIOS
/* we've already done setsid above. Just do tcsetpgrp here. */
tcsetpgrp(0, pid);
#else
-#ifndef hpux
ioctl(0, TIOCSPGRP, &pid);
-#else
- /* we've already done setsid above. Just do tcsetpgrp here. */
- tcsetpgrp(0, pid);
-#endif
#endif /* posix */
pid = 0; /*reset pid incase exec fails*/
-#endif
+#endif /* !sysv || sysvimp */
+
#ifdef STREAMS
if (line_push(t) < 0)
fatalperror(f, "IPUSH",errno);
@@ -818,7 +831,12 @@ void doit(f, fromp)
#if defined(TIOCPKT) && !defined(__svr4__) || defined(solaris20)
ioctl(p, TIOCPKT, &on);
#endif
+#ifdef POSIX_SIGNALS
+ sa.sa_handler = SIG_IGN;
+ (void) sigaction(SIGTSTP, &sa, (struct sigaction *)0);
+#else
signal(SIGTSTP, SIG_IGN);
+#endif
#ifdef hpux
setpgrp2(0, 0);
#else
@@ -895,13 +913,23 @@ protocol(f, p)
register pcc = 0, fcc = 0;
int cc;
char cntl;
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+#endif
/*
* Must ignore SIGTTOU, otherwise we'll stop
* when we try and set slave pty's window shape
* (our controlling tty is the master pty).
*/
+#ifdef POSIX_SIGNALS
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_IGN;
+ (void) sigaction(SIGTTOU, &sa, (struct sigaction *)0);
+#else
signal(SIGTTOU, SIG_IGN);
+#endif
#ifdef TIOCSWINSZ
send(f, oobdata, 1, MSG_OOB); /* indicate new rlogin */
#endif
@@ -1015,7 +1043,7 @@ protocol(f, p)
-int cleanup()
+krb5_sigtype cleanup()
{
char *p;
@@ -1058,6 +1086,9 @@ void fatal(f, msg)
{
char buf[512];
int out = 1 ; /* Output queue of f */
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+#endif
buf[0] = '\01'; /* error indicator */
(void) sprintf(buf + 1, "%s: %s.\r\n",progname, msg);
@@ -1067,7 +1098,14 @@ void fatal(f, msg)
(void) write(f, buf, strlen(buf));
syslog(LOG_ERR,"%s\n",msg);
if (pid > 0) {
+#ifdef POSIX_SIGNALS
+ (void) sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_IGN;
+ (void) sigaction(SIGCHLD, &sa, (struct sigaction *)0);
+#else
signal(SIGCHLD,SIG_IGN);
+#endif
kill(pid,SIGKILL);
#ifdef TIOCFLUSH
(void) ioctl(f, TIOCFLUSH, (char *)&out);
@@ -1223,6 +1261,7 @@ v5_des_read(fd, buf, len)
int nreturned = 0;
long net_len,rd_len;
int cc,retry;
+ unsigned char len_buf[4];
if (!do_encrypt)
return(read(fd, buf, len));
@@ -1240,19 +1279,14 @@ v5_des_read(fd, buf, len)
nstored = 0;
}
-#ifdef BITS64
- rd_len = 0;
- if ((cc = krb5_net_read(fd, (char *)&rd_len + 4, 4)) != 4) {
-#else
- if ((cc = krb5_net_read(fd, (char *)&rd_len, sizeof(rd_len))) !=
- sizeof(rd_len)) {
-#endif
+ if ((cc = krb5_net_read(fd, (char *)&len_buf, 4)) != 4) {
if ((cc < 0) && ((errno == EWOULDBLOCK) || (errno == EAGAIN)))
return(cc);
/* XXX can't read enough, pipe must have closed */
return(0);
}
- rd_len = ntohl(rd_len);
+ rd_len =
+ ((len_buf[0]<<24) | (len_buf[1]<<16) | (len_buf[2]<<8) | len_buf[3]);
net_len = krb5_encrypt_size(rd_len,eblock.crypto_entry);
if (net_len < 0 || net_len > sizeof(des_inbuf)) {
/* XXX preposterous length, probably out of sync.
@@ -1263,8 +1297,7 @@ v5_des_read(fd, buf, len)
retry = 0;
datard:
if ((cc = krb5_net_read(fd, desinbuf.data, net_len)) != net_len) {
- /* XXX can't read enough, pipe
- must have closed */
+ /* XXX can't read enough, pipe must have closed */
if ((cc < 0) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) {
retry++;
sleep(1);
@@ -1311,7 +1344,7 @@ v5_des_write(fd, buf, len)
char *buf;
int len;
{
- long net_len;
+ unsigned char len_buf[4];
if (!do_encrypt)
return(write(fd, buf, len));
@@ -1330,13 +1363,12 @@ v5_des_write(fd, buf, len)
syslog(LOG_ERR,"Write encrypt problem.");
return(-1);
}
-
- net_len = htonl(len);
-#ifdef BITS64
- (void) write(fd,(char *)&net_len + 4, 4);
-#else
- (void) write(fd, &net_len, sizeof(net_len));
-#endif
+
+ len_buf[0] = (len & 0xff000000);
+ len_buf[1] = (len & 0xff0000);
+ len_buf[2] = (len & 0xff00);
+ len_buf[3] = (len & 0xff);
+ (void) write(fd, len_buf, 4);
if (write(fd, desoutbuf.data,desoutbuf.length) != desoutbuf.length){
syslog(LOG_ERR,"Could not write out all data.");
return(-1);
diff --git a/src/appl/bsd/krsh.c b/src/appl/bsd/krsh.c
index ae1a2d964..aca041da8 100644
--- a/src/appl/bsd/krsh.c
+++ b/src/appl/bsd/krsh.c
@@ -101,6 +101,7 @@ main(argc, argv0)
struct servent *sp;
#ifdef POSIX_SIGNALS
sigset_t omask, igmask;
+ struct sigaction sa, osa;
#else
int omask;
#endif
@@ -347,19 +348,35 @@ main(argc, argv0)
sigaddset(&igmask, SIGQUIT);
sigaddset(&igmask, SIGTERM);
sigprocmask(SIG_BLOCK, &igmask, &omask);
+
+ (void)sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = sendsig;
+
+ (void)sigaction(SIGINT, (struct sigaction *)0, &osa);
+ if (osa.sa_handler != SIG_IGN)
+ (void)sigaction(SIGINT, &sa, (struct sigaction *)0);
+
+ (void)sigaction(SIGQUIT, (struct sigaction *)0, &osa);
+ if (osa.sa_handler != SIG_IGN)
+ (void)sigaction(SIGQUIT, &sa, (struct sigaction *)0);
+
+ (void)sigaction(SIGTERM, (struct sigaction *)0, &osa);
+ if (osa.sa_handler != SIG_IGN)
+ (void)sigaction(SIGTERM, &sa, (struct sigaction *)0);
#else
#ifdef sgi
omask = sigignore(mask(SIGINT)|mask(SIGQUIT)|mask(SIGTERM));
#else
omask = sigblock(mask(SIGINT)|mask(SIGQUIT)|mask(SIGTERM));
#endif
-#endif /* POSIX_SIGNALS */
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
signal(SIGINT, sendsig);
if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
signal(SIGQUIT, sendsig);
if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
signal(SIGTERM, sendsig);
+#endif /* POSIX_SIGNALS */
if (nflag == 0) {
pid = fork();
if (pid < 0) {
@@ -455,7 +472,6 @@ main(argc, argv0)
krb5_sigtype sendsig(signo)
char signo;
{
-
(void) write(rfd2, &signo, 1);
}
diff --git a/src/appl/bsd/krshd.c b/src/appl/bsd/krshd.c
index 7cb75bce0..a10782b95 100644
--- a/src/appl/bsd/krshd.c
+++ b/src/appl/bsd/krshd.c
@@ -479,13 +479,16 @@ doit(f, fromp)
char *hostname;
short port;
int pv[2], cc;
- long ready, readfrom;
+ fd_set ready, readfrom;
char buf[BUFSIZ], sig;
int one = 1;
krb5_sigtype cleanup();
int fd;
struct sockaddr_in fromaddr;
int non_privileged = 0;
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+#endif
#ifdef IP_TOS
/* solaris has IP_TOS, but only IPTOS_* values */
@@ -504,9 +507,18 @@ doit(f, fromp)
fromaddr = *fromp;
+#ifdef POSIX_SIGNALS
+ (void)sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_DFL;
+ (void)sigaction(SIGINT, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGQUIT, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGTERM, &sa, (struct sigaction *)0);
+#else
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
+#endif
#ifdef DEBUG
{ int t = open("/dev/tty", 2);
if (t >= 0) {
@@ -1033,16 +1045,30 @@ doit(f, fromp)
goto signout_please;
}
if (pid) {
+#ifdef POSIX_SIGNALS
+ sa.sa_handler = cleanup;
+ (void)sigaction(SIGINT, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGQUIT, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGTERM, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGPIPE, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGHUP, &sa, (struct sigaction *)0);
+
+ sa.sa_handler = SIG_IGN;
+ (void)sigaction(SIGCHLD, &sa, (struct sigaction *)0);
+#else
signal(SIGINT, cleanup);
signal(SIGQUIT, cleanup);
signal(SIGTERM, cleanup);
signal(SIGPIPE, cleanup);
signal(SIGHUP, cleanup);
signal(SIGCHLD,SIG_IGN);
+#endif
(void) close(0); (void) close(1); (void) close(2);
(void) close(f); (void) close(pv[1]);
- readfrom = (1L<<s) | (1L<<pv[0]);
+ FD_ZERO(&readfrom);
+ FD_SET(s, &readfrom);
+ FD_SET(pv[0], &readfrom);
ioctl(pv[0], FIONBIO, (char *)&one);
/* should set s nbio! */
do {
@@ -1050,24 +1076,30 @@ doit(f, fromp)
if (select(16, &ready, (fd_set *)0,
(fd_set *)0, (struct timeval *)0) < 0)
break;
- if (ready & (1L<<s)) {
+ if (FD_ISSET(s, &ready)) {
if (read(s, &sig, 1) <= 0)
- readfrom &= ~(1L<<s);
+ FD_CLR(s, &readfrom);
else {
+#ifdef POSIX_SIGNALS
+ sa.sa_handler = cleanup;
+ (void)sigaction(sig, &sa, (struct sigaction *)0);
+ kill(-pid, sig);
+#else
signal(sig, cleanup);
killpg(pid, sig);
+#endif
}
}
- if (ready & (1L<<pv[0])) {
+ if (FD_ISSET(pv[0], &ready)) {
errno = 0;
cc = read(pv[0], buf, sizeof (buf));
if (cc <= 0) {
shutdown(s, 1+1);
- readfrom &= ~(1L<<pv[0]);
+ FD_CLR(pv[0], &readfrom);
} else
- (void) write(s, buf, cc);
+ (void) write(s, buf, cc);
}
- } while (readfrom);
+ } while (FD_ISSET(s, &readfrom) || FD_ISSET(pv[0], &readfrom));
#ifdef KERBEROS
syslog(LOG_INFO ,
"Shell process completed.");
@@ -1173,6 +1205,20 @@ getstr(fd, buf, cnt, err)
krb5_sigtype
cleanup()
{
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+
+ (void)sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_IGN;
+ (void)sigaction(SIGINT, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGQUIT, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGTERM, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGPIPE, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGHUP, &sa, (struct sigaction *)0);
+
+ (void)kill(-pid, SIGTERM);
+#else
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
@@ -1180,6 +1226,7 @@ krb5_sigtype
signal(SIGHUP, SIG_IGN);
killpg(pid, SIGTERM);
+#endif
wait(0);
#ifdef SYSV
@@ -1354,7 +1401,7 @@ loglogin(host, flag, failures, ue)
return;
}
-#endif CRAY
+#endif /* CRAY */
diff --git a/src/appl/bsd/login.c b/src/appl/bsd/login.c
index c7bdeeafb..b612ed2eb 100644
--- a/src/appl/bsd/login.c
+++ b/src/appl/bsd/login.c
@@ -45,6 +45,12 @@ char copyright[] =
* only one of: -r -h -k -K
*/
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
#include <sys/types.h>
#include <sys/param.h>
#ifdef OQUOTA
@@ -59,9 +65,6 @@ char copyright[] =
#ifdef NEED_SYS_FCNTL_H
#include <sys/fcntl.h>
#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#include <utmp.h>
#include <signal.h>
@@ -98,9 +101,6 @@ char copyright[] =
#endif /* KRB4 */
#include "loginpaths.h"
-#ifdef POSIX
-#include <stdlib.h>
-#endif
#ifdef POSIX_TERMIOS
#include <termios.h>
#ifdef _AIX
@@ -212,11 +212,8 @@ void dofork();
char * strsave();
#endif
-#ifdef POSIX
-typedef void sigtype;
-#else
-typedef int sigtype;
-#endif /* POSIX */
+typedef RETSIGTYPE sigtype;
+
#define EXCL_AUTH_TEST if (rflag || kflag || Kflag || eflag || fflag || Fflag ) { \
fprintf(stderr, \
@@ -251,11 +248,26 @@ main(argc, argv)
#ifdef POSIX_TERMIOS
struct termios tc;
#endif
+#ifdef POSIX_SIGNALS
+ struct sigaction sa;
+#endif
+#ifdef POSIX_SIGNALS
+ (void)sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = timedout;
+ (void)sigaction(SIGALRM, &sa, (struct sigaction *)0);
+#else
(void)signal(SIGALRM, timedout);
+#endif
(void)alarm((u_int)timeout);
+#ifdef POSIX_SIGNALS
+ sa.sa_handler = SIG_IGN;
+ (void)sigaction(SIGALRM, &sa, (struct sigaction *)0);
+#else
(void)signal(SIGQUIT, SIG_IGN);
(void)signal(SIGINT, SIG_IGN);
+#endif
#ifdef HAVE_SETPRIORITY
(void)setpriority(PRIO_PROCESS, 0, 0 + PRIO_OFFSET);
#endif
@@ -946,10 +958,20 @@ bad_login:
#ifndef OQUOTA
if (! access( QUOTAWARN, X_OK)) (void) system(QUOTAWARN);
#endif
+#ifdef POSIX_SIGNALS
+ sa.sa_handler = SIG_DFL;
+ (void)sigaction(SIGALRM, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGQUIT, &sa, (struct sigaction *)0);
+ (void)sigaction(SIGINT, &sa, (struct sigaction *)0);
+
+ sa.sa_handler = SIG_IGN;
+ (void)sigaction(SIGTSTP, &sa, (struct sigaction *)0);
+#else
(void)signal(SIGALRM, SIG_DFL);
(void)signal(SIGQUIT, SIG_DFL);
(void)signal(SIGINT, SIG_DFL);
(void)signal(SIGTSTP, SIG_IGN);
+#endif
tbuf[0] = '-';
(void) strcpy(tbuf + 1, (p = strrchr(pwd->pw_shell, '/')) ?
@@ -1008,28 +1030,58 @@ rootterm(tty)
#endif /* HAVE_TTYENT_H */
}
+#ifdef POSIX_SETJMP
+sigjmp_buf motdinterrupt;
+#else
jmp_buf motdinterrupt;
+#endif
motd()
{
register int fd, nchars;
- sigtype (*oldint)(), sigint();
char tbuf[8192];
+ sigtype sigint();
+#ifdef POSIX_SIGNALS
+ struct sigaction sa, osa;
+#else
+ sigtype (*oldint)();
+#endif
if ((fd = open(MOTDFILE, O_RDONLY, 0)) < 0)
return;
+#ifdef POSIX_SIGNALS
+ (void)sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = sigint;
+ (void)sigaction(SIGINT, &sa, &osa);
+#else
oldint = signal(SIGINT, sigint);
+#endif
+#ifdef POSIX_SETJMP
+ if (sigsetjmp(motdinterrupt, 1) == 0)
+ while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
+ (void)write(fileno(stdout), tbuf, nchars);
+#else
if (setjmp(motdinterrupt) == 0)
while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
(void)write(fileno(stdout), tbuf, nchars);
+#endif
+#ifdef POSIX_SIGNALS
+ (void)sigaction(SIGINT, &osa, (struct sigaction *)0);
+#else
(void)signal(SIGINT, oldint);
+#endif
(void)close(fd);
}
sigtype
sigint()
{
+#ifdef POSIX_SETJMP
+ siglongjmp(motdinterrupt, 1);
+#else
longjmp(motdinterrupt, 1);
+#endif
}
checknologin()
@@ -1313,11 +1365,6 @@ sleepexit(eval)
* It exits only in the child process.
*/
#include <sys/wait.h>
-#ifdef WAIT_USES_INT
-#define WAIT_TYPE int
-#else
-#define WAIT_TYPE union wait
-#endif
void
dofork()
{
@@ -1333,9 +1380,16 @@ dofork()
(void) chdir("/"); /* Let's not keep the fs busy... */
/* If we're the parent, watch the child until it dies */
- while(wait((WAIT_TYPE *)0) != child)
- ;
-
+#ifdef HAVE_WAITPID
+ (void)waitpid(child, 0, 0);
+#else
+#ifdef WAIT_USES_INT
+ while(wait((int *)0) != child) /*void*/ ;
+#else
+ while(wait((union wait *)0) != child) /*void*/ ;
+#endif
+#endif
+
/* Cleanup stuff */
/* Run dest_tkt to destroy tickets */
(void) dest_tkt(); /* If this fails, we lose quietly */
diff --git a/src/appl/bsd/logutil.c b/src/appl/bsd/logutil.c
index 0f7bc5963..9ee9b2433 100644
--- a/src/appl/bsd/logutil.c
+++ b/src/appl/bsd/logutil.c
@@ -15,6 +15,9 @@
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include <sys/types.h>
#include <sys/file.h>
#include <utmp.h>
@@ -25,9 +28,6 @@
#ifdef NEED_SYS_FCNTL_H
#include <sys/fcntl.h>
#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#ifndef UTMP_FILE
#define UTMP_FILE "/etc/utmp"
@@ -131,7 +131,6 @@ logwtmp(line, name, host, keep_open, logingin)
{
struct utmp ut;
struct stat buf;
- time_t time();
if (fd < 0 && (fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) < 0)
return;