[PATCH]: Eliminate HAVE_CYGWIN (and _UWIN) around calls to setgroups() [was Re: openssh for UWIN]

Corinna Vinschen vinschen at redhat.com
Sat Jun 8 08:02:41 EST 2002


Ok, this patch eliminates some of the Cygwin dependencies in the
code.  It contains a new file openbsd/fake-setgroups.c and a few
patches.  The NO_IPPORT_RESERVED_CONCEPT patch is included, too,
so that stuff could be applied in one go.

As sideeffect, David can rearrange his UWIN patches so that most
of the stuff can be sourced out to configure.ac.

Hope that helps,
Corinna
-------------- next part --------------
/*
 * fake library for ssh
 *
 * This file includes a fake setgroups().
 */

#include "includes.h"

#ifndef HAVE_SETGROUPS
int setgroups (size_t size, const gid_t *list)
{
  return 0;
}
#endif
-------------- next part --------------
? openbsd-compat/fake-setgroups.c
Index: acconfig.h
===================================================================
RCS file: /cvs/openssh_cvs/acconfig.h,v
retrieving revision 1.137
diff -u -p -r1.137 acconfig.h
--- acconfig.h	13 May 2002 03:15:43 -0000	1.137
+++ acconfig.h	7 Jun 2002 22:01:35 -0000
@@ -310,6 +310,9 @@
 /* Define if X11 doesn't support AF_UNIX sockets on that system */
 #undef NO_X11_UNIX_SOCKETS
 
+/* Define if the concept of ports only accessible to superusers isn't known */
+#undef NO_IPPORT_RESERVED_CONCEPT
+
 /* Needed for SCO and NeXT */
 #undef BROKEN_SAVED_UIDS
 
Index: configure.ac
===================================================================
RCS file: /cvs/openssh_cvs/configure.ac,v
retrieving revision 1.65
diff -u -p -r1.65 configure.ac
--- configure.ac	7 Jun 2002 14:37:00 -0000	1.65
+++ configure.ac	7 Jun 2002 22:01:36 -0000
@@ -85,6 +85,7 @@ case "$host" in
 	AC_DEFINE(IPV4_DEFAULT)
 	AC_DEFINE(IP_TOS_IS_BROKEN)
 	AC_DEFINE(NO_X11_UNIX_SOCKETS)
+	AC_DEFINE(NO_IPPORT_RESERVED_CONCEPT)
 	;;
 *-*-dgux*)
 	AC_DEFINE(IP_TOS_IS_BROKEN)
@@ -569,8 +570,8 @@ AC_CHECK_FUNCS(arc4random b64_ntop bcopy
 	inet_ntop innetgr login_getcapbool md5_crypt memmove \
 	mkdtemp mmap ngetaddrinfo openpty ogetaddrinfo readpassphrase \
 	realpath recvmsg rresvport_af sendmsg setdtablesize setegid \
-	setenv seteuid setlogin setproctitle setresgid setreuid setrlimit \
-	setsid setvbuf sigaction sigvec snprintf socketpair strerror \
+	setenv seteuid setgroups setlogin setproctitle setresgid setreuid \
+	setrlimit setsid setvbuf sigaction sigvec snprintf socketpair strerror \
 	strlcat strlcpy strmode strsep sysconf tcgetpgrp truncate utimes \
 	vhangup vsnprintf waitpid __b64_ntop _getpty)
 
Index: readconf.c
===================================================================
RCS file: /cvs/openssh_cvs/readconf.c,v
retrieving revision 1.70
diff -u -p -r1.70 readconf.c
--- readconf.c	5 Feb 2002 01:26:35 -0000	1.70
+++ readconf.c	7 Jun 2002 22:01:38 -0000
@@ -200,7 +200,7 @@ add_local_forward(Options *options, u_sh
 		  u_short host_port)
 {
 	Forward *fwd;
-#ifndef HAVE_CYGWIN
+#ifndef NO_IPPORT_RESERVED_CONCEPT
 	extern uid_t original_real_uid;
 	if (port < IPPORT_RESERVED && original_real_uid != 0)
 		fatal("Privileged ports can only be forwarded by root.");
Index: serverloop.c
===================================================================
RCS file: /cvs/openssh_cvs/serverloop.c,v
retrieving revision 1.100
diff -u -p -r1.100 serverloop.c
--- serverloop.c	2 Apr 2002 20:48:20 -0000	1.100
+++ serverloop.c	7 Jun 2002 22:01:40 -0000
@@ -974,8 +974,11 @@ server_input_global_request(int type, u_
 
 		/* check permissions */
 		if (!options.allow_tcp_forwarding ||
-		    no_port_forwarding_flag ||
-		    (listen_port < IPPORT_RESERVED && pw->pw_uid != 0)) {
+		    no_port_forwarding_flag
+#ifndef NO_IPPORT_RESERVED_CONCEPT
+		    || (listen_port < IPPORT_RESERVED && pw->pw_uid != 0)
+#endif
+		   ) {
 			success = 0;
 			packet_send_debug("Server has disabled port forwarding.");
 		} else {
Index: sshd.c
===================================================================
RCS file: /cvs/openssh_cvs/sshd.c,v
retrieving revision 1.209
diff -u -p -r1.209 sshd.c
--- sshd.c	6 Jun 2002 20:46:26 -0000	1.209
+++ sshd.c	7 Jun 2002 22:01:40 -0000
@@ -1018,7 +1018,6 @@ main(int ac, char **av)
 	if (test_flag)
 		exit(0);
 
-#ifndef HAVE_CYGWIN
 	/*
 	 * Clear out any supplemental groups we may have inherited.  This
 	 * prevents inadvertent creation of files with bad modes (in the
@@ -1028,7 +1027,6 @@ main(int ac, char **av)
 	 */
 	if (setgroups(0, NULL) < 0)
 		debug("setgroups() failed: %.200s", strerror(errno));
-#endif /* !HAVE_CYGWIN */
 
 	/* Initialize the log (it is reinitialized below in case we forked). */
 	if (debug_flag && !inetd_flag)
Index: uidswap.c
===================================================================
RCS file: /cvs/openssh_cvs/uidswap.c,v
retrieving revision 1.32
diff -u -p -r1.32 uidswap.c
--- uidswap.c	6 Jun 2002 20:44:06 -0000	1.32
+++ uidswap.c	7 Jun 2002 22:01:40 -0000
@@ -80,11 +80,9 @@ temporarily_use_uid(struct passwd *pw)
 		if (user_groupslen < 0)
 			fatal("getgroups: %.100s", strerror(errno));
 	}
-#ifndef HAVE_CYGWIN
 	/* Set the effective uid to the given (unprivileged) uid. */
 	if (setgroups(user_groupslen, user_groups) < 0)
 		fatal("setgroups: %.100s", strerror(errno));
-#endif /* !HAVE_CYGWIN */
 #ifndef SAVED_IDS_WORK_WITH_SETEUID
 	/* Propagate the privileged gid to all of our gids. */
 	if (setgid(getegid()) < 0)
@@ -130,10 +128,8 @@ restore_uid(void)
 	setgid(getgid());
 #endif /* SAVED_IDS_WORK_WITH_SETEUID */
 
-#ifndef HAVE_CYGWIN
 	if (setgroups(saved_egroupslen, saved_egroups) < 0)
 		fatal("setgroups: %.100s", strerror(errno));
-#endif /* !HAVE_CYGWIN */
 	temporarily_use_uid_effective = 0;
 }
 
Index: openbsd-compat/Makefile.in
===================================================================
RCS file: /cvs/openssh_cvs/openbsd-compat/Makefile.in,v
retrieving revision 1.21
diff -u -p -r1.21 Makefile.in
--- openbsd-compat/Makefile.in	19 Feb 2002 20:27:57 -0000	1.21
+++ openbsd-compat/Makefile.in	7 Jun 2002 22:01:40 -0000
@@ -18,7 +18,7 @@ LDFLAGS=-L. @LDFLAGS@
 
 OPENBSD=base64.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o
 
-COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o
+COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o fake-setgroups.o
 
 PORTS=port-irix.o port-aix.o
 


More information about the openssh-unix-dev mailing list