[Pkg-shadow-commits] r3032 - in upstream/trunk: . libmisc src

Nicolas FRANÇOIS nekral-guest at alioth.debian.org
Mon Jul 20 14:00:56 UTC 2009


Author: nekral-guest
Date: 2009-07-20 14:00:50 +0000 (Mon, 20 Jul 2009)
New Revision: 3032

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/NEWS
   upstream/trunk/libmisc/shell.c
   upstream/trunk/src/su.c
Log:
	* NEWS, src/su.c, libmisc/shell.c: Added support for shells being a
	shell script without a shebang.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2009-07-19 11:54:44 UTC (rev 3031)
+++ upstream/trunk/ChangeLog	2009-07-20 14:00:50 UTC (rev 3032)
@@ -1,3 +1,8 @@
+2009-07-20  Nicolas François  <nicolas.francois at centraliens.net>
+
+	* NEWS, src/su.c, libmisc/shell.c: Added support for shells being a
+	shell script without a shebang.
+
 2009-07-19  Jean-Louis Dupond  <info at dupondje.be>
 
 	* po/nl.po: Fix obvious mistake in Dutch translation.

Modified: upstream/trunk/NEWS
===================================================================
--- upstream/trunk/NEWS	2009-07-19 11:54:44 UTC (rev 3031)
+++ upstream/trunk/NEWS	2009-07-20 14:00:50 UTC (rev 3032)
@@ -12,9 +12,12 @@
     reverse order, accounts are packed close to SYS_?ID_MAX if SYS_?ID_MIN
     is already used but there are still dome gaps.
 
+- login
+  * Add support for shells being a shell script without a shebang.
 - su
   * Preserve the DISPLAY and XAUTHORITY environment variables. This was
     only the case in the non PAM enabled versions.
+  * Add support for shells being a shell script without a shebang.
 
 *** translation
   * The Finnish translation of passwd(1) was outdated and is no more

Modified: upstream/trunk/libmisc/shell.c
===================================================================
--- upstream/trunk/libmisc/shell.c	2009-07-19 11:54:44 UTC (rev 3031)
+++ upstream/trunk/libmisc/shell.c	2009-07-20 14:00:50 UTC (rev 3032)
@@ -2,6 +2,7 @@
  * Copyright (c) 1989 - 1991, Julianne Frances Haugh
  * Copyright (c) 1996 - 1998, Marek Michałkiewicz
  * Copyright (c) 2003 - 2006, Tomasz Kłoczko
+ * Copyright (c) 2009       , Nicolas François
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -79,6 +80,15 @@
 	execle (file, arg, (char *) 0, envp);
 	err = errno;
 
+	if (access (file, R_OK|X_OK) == 0) {
+		/*
+		 * Assume this is a shell script (with no shebang).
+		 * Interpret it with /bin/sh
+		 */
+		execle ("/bin/sh", "sh", file, (char *)0, envp);
+		err = errno;
+	}
+
 	/*
 	 * Obviously something is really wrong - I can't figure out
 	 * how to execute this stupid shell, so I might as well give

Modified: upstream/trunk/src/su.c
===================================================================
--- upstream/trunk/src/su.c	2009-07-19 11:54:44 UTC (rev 3031)
+++ upstream/trunk/src/su.c	2009-07-20 14:00:50 UTC (rev 3032)
@@ -2,7 +2,7 @@
  * Copyright (c) 1989 - 1994, Julianne Frances Haugh
  * Copyright (c) 1996 - 2000, Marek Michałkiewicz
  * Copyright (c) 2000 - 2006, Tomasz Kłoczko
- * Copyright (c) 2007 - 2008, Nicolas François
+ * Copyright (c) 2007 - 2009, Nicolas François
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -174,7 +174,41 @@
 	exit (1);
 }
 
+/*
+ * execve_shell - Execute a shell with execve, or interpret it with
+ * /bin/sh
+ */
+void execve_shell (const char *shellstr, char *args[], char *const envp[])
+{
+	int err;
+	(void) execve (shellstr, (char **) args, envp);
+	err = errno;
 
+	if (access (shellstr, R_OK|X_OK) == 0) {
+		/*
+		 * Assume this is a shell script (with no shebang).
+		 * Interpret it with /bin/sh
+		 */
+		size_t n_args = 0;
+		char **targs;
+		while (NULL != args[n_args]) {
+			n_args++;
+		}
+		targs = (char **) xmalloc ((n_args + 2) * sizeof (args[0]));
+		targs[0] = "sh";
+		targs[1] = xstrdup (shellstr);
+		targs[n_args+1] = NULL;
+		while (1 != n_args) {
+			targs[n_args] = args[n_args - 1];
+			n_args--;
+		}
+
+		(void) execve ("/bin/sh", targs, envp);
+	} else {
+		errno = err;
+	}
+}
+
 #ifdef USE_PAM
 /* Signal handler for parent process later */
 static void catch_signals (unused int sig)
@@ -206,8 +240,9 @@
 		if (doshell) {
 			(void) shell (shellstr, (char *) args[0], envp);
 		} else {
-			(void) execve (shellstr, (char **) args, envp);
+			execve_shell (shellstr, (char **) args, envp);
 		}
+
 		exit (errno == ENOENT ? E_CMD_NOTFOUND : E_CMD_NOEXEC);
 	} else if ((pid_t)-1 == child) {
 		(void) fprintf (stderr, "%s: Cannot fork user shell\n", Prog);
@@ -315,7 +350,7 @@
  */
 int main (int argc, char **argv)
 {
-	char *cp;
+	const char *cp;
 	const char *tty = NULL;	/* Name of tty SU is run from        */
 	bool doshell = false;
 	bool fakelogin = false;
@@ -949,7 +984,7 @@
 		 */
 		argv[-1] = shellstr;
 #ifndef USE_PAM
-		(void) execve (shellstr, &argv[-1], environ);
+		execve_shell (shellstr, &argv[-1], environ);
 		err = errno;
 		(void) fputs (_("No shell\n"), stderr);
 		SYSLOG ((LOG_WARN, "Cannot execute %s", shellstr));




More information about the Pkg-shadow-commits mailing list