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
* 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
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
* 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
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 */
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);
*/
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;
*/
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));