|
Tim Waugh |
9f2386 |
--- coreutils-5.97/src/su.c.setsid 2006-07-21 14:09:29.000000000 +0100
|
|
Tim Waugh |
9f2386 |
+++ coreutils-5.97/src/su.c 2006-07-21 14:20:28.000000000 +0100
|
|
Tim Waugh |
9f2386 |
@@ -199,9 +199,13 @@
|
|
Tim Waugh |
9f2386 |
/* If true, change some environment vars to indicate the user su'd to. */
|
|
Tim Waugh |
9f2386 |
static bool change_environment;
|
|
Tim Waugh |
9f2386 |
|
|
Tim Waugh |
9f2386 |
+/* If true, then don't call setsid() with a command. */
|
|
Tim Waugh |
9f2386 |
+int same_session = 0;
|
|
Tim Waugh |
9f2386 |
+
|
|
Tim Waugh |
9f2386 |
static struct option const longopts[] =
|
|
Tim Waugh |
9f2386 |
{
|
|
Tim Waugh |
9f2386 |
{"command", required_argument, NULL, 'c'},
|
|
Tim Waugh |
9f2386 |
+ {"session-command", required_argument, NULL, 'C'},
|
|
Tim Waugh |
9f2386 |
{"fast", no_argument, NULL, 'f'},
|
|
Tim Waugh |
9f2386 |
{"login", no_argument, NULL, 'l'},
|
|
Tim Waugh |
9f2386 |
{"preserve-environment", no_argument, NULL, 'p'},
|
|
Tim Waugh |
9f2386 |
@@ -497,6 +501,8 @@
|
|
Tim Waugh |
eb20fc |
if (child == 0) { /* child shell */
|
|
Tim Waugh |
eb20fc |
change_identity (pw);
|
|
Tim Waugh |
eb20fc |
pam_end(pamh, 0);
|
|
Tim Waugh |
9f2386 |
+ if (!same_session)
|
|
Tim Waugh |
eb20fc |
+ setsid ();
|
|
Tim Waugh |
eb20fc |
#endif
|
|
Tim Waugh |
eb20fc |
|
|
Tim Waugh |
eb20fc |
if (simulate_login)
|
|
Tim Waugh |
9f2386 |
@@ -551,13 +557,27 @@
|
|
Tim Waugh |
eb20fc |
sigemptyset(&action.sa_mask);
|
|
Tim Waugh |
eb20fc |
action.sa_flags = 0;
|
|
Tim Waugh |
eb20fc |
sigemptyset(&ourset);
|
|
Tim Waugh |
eb20fc |
- if (sigaddset(&ourset, SIGTERM)
|
|
Tim Waugh |
eb20fc |
- || sigaddset(&ourset, SIGALRM)
|
|
Tim Waugh |
eb20fc |
- || sigaction(SIGTERM, &action, NULL)
|
|
Tim Waugh |
eb20fc |
- || sigprocmask(SIG_UNBLOCK, &ourset, NULL)) {
|
|
Tim Waugh |
9f2386 |
+ if (!same_session)
|
|
Tim Waugh |
eb20fc |
+ {
|
|
Tim Waugh |
eb20fc |
+ if (sigaddset(&ourset, SIGINT) || sigaddset(&ourset, SIGQUIT))
|
|
Tim Waugh |
eb20fc |
+ {
|
|
Tim Waugh |
eb20fc |
+ fprintf(stderr, "%s: signal masking malfunction\n", PROGRAM_NAME);
|
|
Tim Waugh |
eb20fc |
+ caught = 1;
|
|
Tim Waugh |
eb20fc |
+ }
|
|
Tim Waugh |
eb20fc |
+ }
|
|
Tim Waugh |
eb20fc |
+ if (!caught && (sigaddset(&ourset, SIGTERM)
|
|
Tim Waugh |
eb20fc |
+ || sigaddset(&ourset, SIGALRM)
|
|
Tim Waugh |
eb20fc |
+ || sigaction(SIGTERM, &action, NULL)
|
|
Tim Waugh |
eb20fc |
+ || sigprocmask(SIG_UNBLOCK, &ourset, NULL))) {
|
|
Tim Waugh |
eb20fc |
fprintf(stderr, "%s: signal masking malfunction\n", PROGRAM_NAME);
|
|
Tim Waugh |
eb20fc |
caught = 1;
|
|
Tim Waugh |
eb20fc |
}
|
|
Tim Waugh |
9f2386 |
+ if (!caught && !same_session && (sigaction(SIGINT, &action, NULL)
|
|
Tim Waugh |
9f2386 |
+ || sigaction(SIGQUIT, &action, NULL)))
|
|
Tim Waugh |
eb20fc |
+ {
|
|
Tim Waugh |
eb20fc |
+ fprintf(stderr, "%s: signal masking malfunction\n", PROGRAM_NAME);
|
|
Tim Waugh |
eb20fc |
+ caught = 1;
|
|
Tim Waugh |
eb20fc |
+ }
|
|
Tim Waugh |
eb20fc |
}
|
|
Tim Waugh |
eb20fc |
if (!caught) {
|
|
Tim Waugh |
eb20fc |
do {
|
|
Tim Waugh |
9f2386 |
@@ -628,6 +648,8 @@
|
|
Tim Waugh |
9f2386 |
\n\
|
|
Tim Waugh |
9f2386 |
-, -l, --login make the shell a login shell\n\
|
|
Tim Waugh |
9f2386 |
-c, --commmand=COMMAND pass a single COMMAND to the shell with -c\n\
|
|
Tim Waugh |
9f2386 |
+ --session-command=COMMAND pass a single COMMAND to the shell with -c\n\
|
|
Tim Waugh |
9f2386 |
+ and do not create a new session\n\
|
|
Tim Waugh |
9f2386 |
-f, --fast pass -f to the shell (for csh or tcsh)\n\
|
|
Tim Waugh |
9f2386 |
-m, --preserve-environment do not reset environment variables\n\
|
|
Tim Waugh |
9f2386 |
-p same as -m\n\
|
|
Tim Waugh |
9f2386 |
@@ -650,6 +672,7 @@
|
|
Tim Waugh |
9f2386 |
int optc;
|
|
Tim Waugh |
9f2386 |
const char *new_user = DEFAULT_USER;
|
|
Tim Waugh |
9f2386 |
char *command = NULL;
|
|
Tim Waugh |
9f2386 |
+ int request_same_session = 0;
|
|
Tim Waugh |
9f2386 |
char *shell = NULL;
|
|
Tim Waugh |
9f2386 |
struct passwd *pw;
|
|
Tim Waugh |
9f2386 |
struct passwd pw_copy;
|
|
Tim Waugh |
9f2386 |
@@ -675,6 +698,11 @@
|
|
Tim Waugh |
9f2386 |
command = optarg;
|
|
Tim Waugh |
9f2386 |
break;
|
|
Tim Waugh |
9f2386 |
|
|
Tim Waugh |
9f2386 |
+ case 'C':
|
|
Tim Waugh |
9f2386 |
+ command = optarg;
|
|
Tim Waugh |
9f2386 |
+ request_same_session = 1;
|
|
Tim Waugh |
9f2386 |
+ break;
|
|
Tim Waugh |
9f2386 |
+
|
|
Tim Waugh |
9f2386 |
case 'f':
|
|
Tim Waugh |
9f2386 |
fast_startup = true;
|
|
Tim Waugh |
9f2386 |
break;
|
|
Tim Waugh |
9f2386 |
@@ -744,6 +772,9 @@
|
|
Tim Waugh |
9f2386 |
}
|
|
Tim Waugh |
9f2386 |
#endif
|
|
Tim Waugh |
9f2386 |
|
|
Tim Waugh |
9f2386 |
+ if (request_same_session || !command || !pw->pw_uid)
|
|
Tim Waugh |
9f2386 |
+ same_session = 1;
|
|
Tim Waugh |
9f2386 |
+
|
|
Tim Waugh |
9f2386 |
if (!shell && !change_environment)
|
|
Tim Waugh |
9f2386 |
shell = getenv ("SHELL");
|
|
Tim Waugh |
9f2386 |
if (shell && getuid () != 0 && restricted_shell (pw->pw_shell))
|