From 187ec3b1e51a42c10f5f57143c524a610176d651 Mon Sep 17 00:00:00 2001 From: Mark Eichin Date: Fri, 5 Aug 1994 23:45:30 +0000 Subject: [PATCH] rest of signal cleanups plus strsave git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4053 dc483132-0cff-0310-8789-dd5450dbe970 --- src/appl/bsd/configure.in | 3 +++ src/appl/bsd/kcmd.c | 5 +++-- src/appl/bsd/krcp.c | 39 ++++++++++++++++++++++++++++++++------- src/appl/bsd/krlogin.c | 11 +++++++++++ src/appl/bsd/krsh.c | 18 ++++++++++++++++++ src/appl/bsd/login.c | 30 +++++++++++++++++++++--------- 6 files changed, 88 insertions(+), 18 deletions(-) diff --git a/src/appl/bsd/configure.in b/src/appl/bsd/configure.in index 98ffd4bae..04225d789 100644 --- a/src/appl/bsd/configure.in +++ b/src/appl/bsd/configure.in @@ -7,6 +7,7 @@ AC_SET_BUILDTOP AC_PROG_INSTALL AC_HAVE_LIBRARY(socket) AC_HAVE_LIBRARY(nsl) +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)) @@ -15,6 +16,8 @@ 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 ], diff --git a/src/appl/bsd/kcmd.c b/src/appl/bsd/kcmd.c index 094bc55f3..b7db46fba 100644 --- a/src/appl/bsd/kcmd.c +++ b/src/appl/bsd/kcmd.c @@ -241,7 +241,7 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, #endif /* !(defined(ultrix) || defined(sun)) */ perror(hp->h_name); #ifdef POSIX_SIGNALS - sigprocmask(SIG_SETMASK, &oldmask, (sigset_t*)0); + sigprocmask(SIG_SETMASK, &oldmask, (sigset_t*)0); #else #ifndef sgi sigsetmask(oldmask); @@ -654,6 +654,7 @@ int setreuid(real,eff) +#ifndef HAVE_STRSAVE /* Strsave was a routine in the version 4 krb library: we put it here for compatablilty with version 5 krb library, since kcmd.o is linked into all programs. */ @@ -672,7 +673,7 @@ char *sp; return(ret); } - +#endif #ifdef SYSV diff --git a/src/appl/bsd/krcp.c b/src/appl/bsd/krcp.c index 57b5d8464..b181a5cab 100644 --- a/src/appl/bsd/krcp.c +++ b/src/appl/bsd/krcp.c @@ -1,12 +1,7 @@ /* - * $Source$ - * $Header$ + * appl/bsd/krcp.c */ -#ifndef lint -static char *rcsid_rcp_c = "$Header$"; -#endif /* lint */ - /* * Copyright (c) 1983 The Regents of the University of California. * All rights reserved. @@ -60,6 +55,11 @@ static char sccsid[] = "@(#)rcp.c 5.10 (Berkeley) 9/20/88"; #include #include +#ifdef HAVE_SETRESUID +#ifndef HAVE_SETREUID +#define setreuid(r,e) setresuid(r,e,-1) +#endif +#endif #ifndef roundup #define roundup(x,y) ((((x)+(y)-1)/(y))*(y)) #endif @@ -88,7 +88,10 @@ krb5_encrypt_block eblock; /* eblock for encrypt/decrypt */ krb5_keyblock *session_key; /* static key for session */ void try_normal(); -char **save_argv(), *strsave(); +char **save_argv(); +#ifndef HAVE_STRSAVE +char *strsave(); +#endif int des_write(), des_read(); void send_auth(), answer_auth(); int encryptflag = 0; @@ -446,17 +449,39 @@ main(argc, argv) if (encryptflag) send_auth(); } +#ifdef HAVE_SETREUID (void) setreuid(0, userid); sink(1, argv+argc-1); (void) setreuid(userid, 0); +#else + (void) setuid(0); + if(seteuid(userid)) { + perror("rcp seteuid user"); errs++; exit(errs); + } + sink(1, argv+argc-1); + if(seteuid(0)) { + perror("rcp seteuid 0"); errs++; exit(errs); + } +#endif #else rem = rcmd(&host, port, pwd->pw_name, suser, buf, 0); if (rem < 0) continue; +#ifdef HAVE_SETREUID (void) setreuid(0, userid); sink(1, argv+argc-1); (void) setreuid(userid, 0); +#else + (void) setuid(0); + if(seteuid(userid)) { + perror("rcp seteuid user"); errs++; exit(errs); + } + sink(1, argv+argc-1); + if(seteuid(0)) { + perror("rcp seteuid 0"); errs++; exit(errs); + } +#endif #endif /* KERBEROS */ (void) close(rem); rem = -1; diff --git a/src/appl/bsd/krlogin.c b/src/appl/bsd/krlogin.c index ba66f823a..f1ea22f8f 100644 --- a/src/appl/bsd/krlogin.c +++ b/src/appl/bsd/krlogin.c @@ -803,17 +803,28 @@ setsignal(sig, act) int sig; krb5_sigtype (*act)(); { +#ifdef POSIX_SIGNALS + sigset_t omask, igmask; + sigemptyset(&igmask); + sigaddset(&igmask, sig); + sigprocmask(SIG_BLOCK, &igmask, &omask); +#else #ifdef sgi int omask = sigignore(sigmask(sig)); #else int omask = sigblock(sigmask(sig)); #endif +#endif /* POSIX_SIGNALS */ if (signal(sig, act) == SIG_IGN) (void) signal(sig, SIG_IGN); +#ifdef POSIX_SIGNALS + sigprocmask(SIG_SETMASK, &omask, (sigset_t*)0); +#else #ifndef sgi (void) sigsetmask(omask); #endif +#endif } diff --git a/src/appl/bsd/krsh.c b/src/appl/bsd/krsh.c index cabfc6c6b..d25b15401 100644 --- a/src/appl/bsd/krsh.c +++ b/src/appl/bsd/krsh.c @@ -87,7 +87,9 @@ void try_normal(); #endif /* KERBEROS */ #endif /* !RLOGIN_PROGRAM */ +#ifndef POSIX_SIGNALS #define mask(s) (1 << ((s) - 1)) +#endif /* POSIX_SIGNALS */ main(argc, argv0) int argc; @@ -101,7 +103,11 @@ main(argc, argv0) int readfrom, ready; int one = 1; struct servent *sp; +#ifdef POSIX_SIGNALS + sigset_t omask, igmask; +#else int omask; +#endif #ifdef KERBEROS krb5_flags authopts; krb5_error_code status; @@ -339,11 +345,19 @@ main(argc, argv0) perror("setsockopt (stderr)"); } (void) setuid(getuid()); +#ifdef POSIX_SIGNALS + sigemptyset(&igmask); + sigaddset(&igmask, SIGINT); + sigaddset(&igmask, SIGQUIT); + sigaddset(&igmask, SIGTERM); + sigprocmask(SIG_BLOCK, &igmask, &omask); +#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) @@ -393,9 +407,13 @@ main(argc, argv0) (void) shutdown(rem, 1); exit(0); } +#ifdef POSIX_SIGNALS + sigprocmask(SIG_SETMASK, &omask, (sigset_t*)0); +#else #ifndef sgi sigsetmask(omask); #endif +#endif /* POSIX_SIGNALS */ readfrom = (1< #endif -#ifndef HAVE_GETDTABLESIZE -#include -int getdtablesize() { - struct rlimit rl; - getrlimit(RLIMIT_NOFILE, &rl); - return rl.rlim_cur; -} -#endif - #if defined(_AIX) #define PRIO_OFFSET 20 #else @@ -1343,6 +1334,27 @@ dofork() #endif /* KRB4 */ +#ifndef HAVE_STRSAVE +/* Strsave was a routine in the version 4 krb library: we put it here + for compatablilty with version 5 krb library, since kcmd.o is linked + into all programs. */ + +char * + strsave(sp) +char *sp; +{ + register char *ret; + + if((ret = (char *) malloc((unsigned) strlen(sp)+1)) == NULL) { + fprintf(stderr, "no memory for saving args\n"); + exit(1); + } + (void) strcpy(ret,sp); + return(ret); +} + +#endif + #ifdef _IBMR2 update_ref_count(int adj) { -- 2.26.2