Patch for systems with no setreuid()

Jon Peatfield J.S.Peatfield at damtp.cam.ac.uk
Fri Jun 8 01:58:26 EST 2001


Sorry if I'm duplicating an existing patch, but...

On systems with no seteuid() that have setreuid() there is an
emulation, but if both are lacking (but we do have setresuid()),
nothing is done.  The following seems to be right, but I've only got
one machine (running an ancient version of HP-UX) which needs this so
it may not be general:

--cut-here--
--- config.h.in.orig	Thu Jun  7 14:18:57 2001
+++ config.h.in	Thu Jun  7 14:19:33 2001
@@ -503,6 +503,9 @@
 /* Define if you have the setreuid function.  */
 #undef HAVE_SETREUID
 
+/* Define if you have the setresuid function.  */
+#undef HAVE_SETRESUID
+
 /* Define if you have the setrlimit function.  */
 #undef HAVE_SETRLIMIT
 
--- configure.orig	Thu Jun  7 14:12:53 2001
+++ configure	Thu Jun  7 14:13:40 2001
@@ -3184,7 +3184,7 @@
 fi
 
 
-for ac_func in arc4random atexit b64_ntop bcopy bindresvport_sa clock fchown fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent getusershell glob inet_aton inet_ntoa inet_ntop innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv setegid seteuid setlogin setproctitle setresgid setreuid setrlimit setsid sigaction sigvec snprintf strerror strlcat strlcpy strmode strsep strtok_r sysconf tcgetpgrp utimes vsnprintf vhangup vis waitpid _getpty __b64_ntop
+for ac_func in arc4random atexit b64_ntop bcopy bindresvport_sa clock fchown fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent getusershell glob inet_aton inet_ntoa inet_ntop innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv setegid seteuid setlogin setproctitle setresgid setreuid setresuid setrlimit setsid sigaction sigvec snprintf strerror strlcat strlcpy strmode strsep strtok_r sysconf tcgetpgrp utimes vsnprintf vhangup vis waitpid _getpty __b64_ntop
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo "configure:3191: checking for $ac_func" >&5
--- configure.in.orig	Thu Jun  7 14:12:44 2001
+++ configure.in	Thu Jun  7 14:13:10 2001
@@ -447,7 +447,7 @@
 )
 
 dnl    Checks for library functions.
-AC_CHECK_FUNCS(arc4random atexit b64_ntop bcopy bindresvport_sa clock fchown fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent getusershell glob inet_aton inet_ntoa inet_ntop innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv setegid seteuid setlogin setproctitle setresgid setreuid setrlimit setsid sigaction sigvec snprintf strerror strlcat strlcpy strmode strsep strtok_r sysconf tcgetpgrp utimes vsnprintf vhangup vis waitpid _getpty __b64_ntop)
+AC_CHECK_FUNCS(arc4random atexit b64_ntop bcopy bindresvport_sa clock fchown fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent getusershell glob inet_aton inet_ntoa inet_ntop innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv setegid seteuid setlogin setproctitle setresgid setreuid setresuid setrlimit setsid sigaction sigvec snprintf strerror strlcat strlcpy strmode strsep strtok_r sysconf tcgetpgrp utimes vsnprintf vhangup vis waitpid _getpty __b64_ntop)
 dnl    Checks for time functions
 AC_CHECK_FUNCS(gettimeofday time)
 dnl    Checks for libutil functions
--- openbsd-compat/bsd-misc.c.orig	Thu Jun  7 14:07:58 2001
+++ openbsd-compat/bsd-misc.c	Thu Jun  7 14:26:12 2001
@@ -70,6 +70,20 @@
 }
 #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */
 
+#if !defined(HAVE_SETEUID) && defined(HAVE_SETRESUID)
+int seteuid(uid_t euid)
+{
+	return(setresuid(-1,euid,-1));
+}
+#endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETRESUID) */
+
+#if !defined(HAVE_SETREUID) && defined(HAVE_SETRESUID)
+int setreuid(uid_t ruid, uid_t euid)
+{
+	return(setresuid(ruid,euid,-1));
+}
+#endif /* !defined(HAVE_SETREUID) && defined(HAVE_SETRESUID) */
+
 #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID)
 int setegid(uid_t egid)
 {
--cut-here--

Of course on this particular platform I need other patches (to turn
off HP-UX specific stuff which are missing (hpsecurity etc)), but the
above might be useful elsewhere...

-- 
Jon Peatfield,  DAMTP,  Computer Officer,   University of Cambridge
Telephone: +44 1223  3 37852    Mail: J.S.Peatfield at damtp.cam.ac.uk



More information about the openssh-unix-dev mailing list