2010-11-15 12:16:04 +00:00
|
|
|
diff -urNp coreutils-8.6-orig/src/su.c coreutils-8.6/src/su.c
|
|
|
|
--- coreutils-8.6-orig/src/su.c 2010-11-03 13:56:11.679069689 +0100
|
|
|
|
+++ coreutils-8.6/src/su.c 2010-11-03 13:56:45.304325661 +0100
|
|
|
|
@@ -153,6 +153,9 @@ static bool simulate_login;
|
2006-07-21 13:26:30 +00:00
|
|
|
/* If true, change some environment vars to indicate the user su'd to. */
|
|
|
|
static bool change_environment;
|
|
|
|
|
|
|
|
+/* If true, then don't call setsid() with a command. */
|
|
|
|
+int same_session = 0;
|
|
|
|
+
|
2010-11-15 12:16:04 +00:00
|
|
|
#ifdef USE_PAM
|
|
|
|
static bool _pam_session_opened;
|
|
|
|
static bool _pam_cred_established;
|
|
|
|
@@ -161,6 +164,7 @@ static bool _pam_cred_established;
|
2006-07-21 13:26:30 +00:00
|
|
|
static struct option const longopts[] =
|
|
|
|
{
|
|
|
|
{"command", required_argument, NULL, 'c'},
|
|
|
|
+ {"session-command", required_argument, NULL, 'C'},
|
|
|
|
{"fast", no_argument, NULL, 'f'},
|
|
|
|
{"login", no_argument, NULL, 'l'},
|
|
|
|
{"preserve-environment", no_argument, NULL, 'p'},
|
2010-11-15 12:16:04 +00:00
|
|
|
@@ -335,14 +339,27 @@ create_watching_parent (void)
|
|
|
|
sigemptyset (&action.sa_mask);
|
|
|
|
action.sa_flags = 0;
|
|
|
|
sigemptyset (&ourset);
|
|
|
|
- if (sigaddset (&ourset, SIGTERM)
|
|
|
|
- || sigaddset (&ourset, SIGALRM)
|
|
|
|
- || sigaction (SIGTERM, &action, NULL)
|
|
|
|
- || sigprocmask (SIG_UNBLOCK, &ourset, NULL))
|
|
|
|
- {
|
2006-07-21 13:26:30 +00:00
|
|
|
+ if (!same_session)
|
2005-11-14 10:57:28 +00:00
|
|
|
+ {
|
2009-09-12 09:28:49 +00:00
|
|
|
+ if (sigaddset(&ourset, SIGINT) || sigaddset(&ourset, SIGQUIT))
|
|
|
|
+ {
|
2010-11-15 12:16:04 +00:00
|
|
|
+ error (0, errno, _("cannot set signal handler"));
|
|
|
|
+ caught_signal = true;
|
2009-09-12 09:28:49 +00:00
|
|
|
+ }
|
2005-11-14 10:57:28 +00:00
|
|
|
+ }
|
2010-11-15 12:16:04 +00:00
|
|
|
+ if (!caught_signal && (sigaddset(&ourset, SIGTERM)
|
2009-09-12 09:28:49 +00:00
|
|
|
+ || sigaddset(&ourset, SIGALRM)
|
|
|
|
+ || sigaction(SIGTERM, &action, NULL)
|
|
|
|
+ || sigprocmask(SIG_UNBLOCK, &ourset, NULL))) {
|
2010-11-15 12:16:04 +00:00
|
|
|
error (0, errno, _("cannot set signal handler"));
|
|
|
|
caught_signal = true;
|
|
|
|
}
|
|
|
|
+ if (!caught_signal && !same_session && (sigaction(SIGINT, &action, NULL)
|
2009-09-12 09:28:49 +00:00
|
|
|
+ || sigaction(SIGQUIT, &action, NULL)))
|
2005-11-14 10:57:28 +00:00
|
|
|
+ {
|
2010-11-15 12:16:04 +00:00
|
|
|
+ error (0, errno, _("cannot set signal handler"));
|
|
|
|
+ caught_signal = true;
|
2005-11-14 10:57:28 +00:00
|
|
|
+ }
|
2010-11-15 12:16:04 +00:00
|
|
|
}
|
|
|
|
if (!caught_signal)
|
|
|
|
{
|
|
|
|
@@ -627,6 +644,8 @@ Change the effective user id and group i
|
2006-07-21 13:26:30 +00:00
|
|
|
\n\
|
|
|
|
-, -l, --login make the shell a login shell\n\
|
2007-01-09 19:29:30 +00:00
|
|
|
-c, --command=COMMAND pass a single COMMAND to the shell with -c\n\
|
2006-07-21 13:26:30 +00:00
|
|
|
+ --session-command=COMMAND pass a single COMMAND to the shell with -c\n\
|
|
|
|
+ and do not create a new session\n\
|
|
|
|
-f, --fast pass -f to the shell (for csh or tcsh)\n\
|
|
|
|
-m, --preserve-environment do not reset environment variables\n\
|
|
|
|
-p same as -m\n\
|
2010-11-15 12:16:04 +00:00
|
|
|
@@ -649,6 +668,7 @@ main (int argc, char **argv)
|
2006-07-21 13:26:30 +00:00
|
|
|
int optc;
|
|
|
|
const char *new_user = DEFAULT_USER;
|
|
|
|
char *command = NULL;
|
|
|
|
+ int request_same_session = 0;
|
|
|
|
char *shell = NULL;
|
|
|
|
struct passwd *pw;
|
|
|
|
struct passwd pw_copy;
|
2010-11-15 12:16:04 +00:00
|
|
|
@@ -674,6 +694,11 @@ main (int argc, char **argv)
|
2009-09-12 09:28:49 +00:00
|
|
|
command = optarg;
|
|
|
|
break;
|
2006-07-21 13:26:30 +00:00
|
|
|
|
2009-09-12 09:28:49 +00:00
|
|
|
+ case 'C':
|
|
|
|
+ command = optarg;
|
|
|
|
+ request_same_session = 1;
|
|
|
|
+ break;
|
2006-07-21 13:26:30 +00:00
|
|
|
+
|
2009-09-12 09:28:49 +00:00
|
|
|
case 'f':
|
|
|
|
fast_startup = true;
|
|
|
|
break;
|
2010-11-15 12:16:04 +00:00
|
|
|
@@ -743,6 +768,9 @@ main (int argc, char **argv)
|
2006-07-21 13:26:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
+ if (request_same_session || !command || !pw->pw_uid)
|
|
|
|
+ same_session = 1;
|
|
|
|
+
|
|
|
|
if (!shell && !change_environment)
|
|
|
|
shell = getenv ("SHELL");
|
|
|
|
if (shell && getuid () != 0 && restricted_shell (pw->pw_shell))
|
2010-11-15 12:16:04 +00:00
|
|
|
@@ -764,6 +792,8 @@ main (int argc, char **argv)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
change_identity (pw);
|
|
|
|
+ if (!same_session)
|
|
|
|
+ setsid ();
|
|
|
|
|
|
|
|
/* Set environment after pam_open_session, which may put KRB5CCNAME
|
|
|
|
into the pam_env, etc. */
|