Skip to content

Commit e39e1e3

Browse files
author
git-core
committed
Accurately handle -c option
1 parent aa74885 commit e39e1e3

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

su.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static struct su_initiator su_from = {
5252

5353
static struct su_request su_to = {
5454
.uid = AID_ROOT,
55+
.doshell = 1,
5556
.command = DEFAULT_COMMAND,
5657
};
5758

@@ -309,11 +310,11 @@ static void allow(char *shell, mode_t mask)
309310
LOGD("%u %s executing %u %s using shell %s : %s", from->uid, from->bin,
310311
to->uid, to->command, shell, exe);
311312
argv[argc++] = exe;
312-
if (strcmp(to->command, DEFAULT_COMMAND)) {
313+
if (to->doshell) {
314+
argv[argc++] = "-";
315+
} else {
313316
argv[argc++] = "-c";
314317
argv[argc++] = to->command;
315-
} else {
316-
argv[argc++] = "-";
317318
}
318319
argv[argc] = NULL;
319320
execv(shell, argv);
@@ -344,6 +345,7 @@ int main(int argc, char *argv[])
344345
switch(c) {
345346
case 'c':
346347
su_to.command = optarg;
348+
su_to.doshell = 0;
347349
break;
348350
case 'h':
349351
usage(EXIT_SUCCESS);

su.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct su_initiator {
4848

4949
struct su_request {
5050
unsigned uid;
51+
int doshell;
5152
char *command;
5253
};
5354

0 commit comments

Comments
 (0)