Skip to content

Commit ac59b39

Browse files
author
git-core
committed
Handle -l option
1 parent 69c1b43 commit ac59b39

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

su.c

Lines changed: 17 additions & 2 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+
.login = 0,
5556
.doshell = 1,
5657
.command = DEFAULT_COMMAND,
5758
};
@@ -299,6 +300,17 @@ static void allow(char *shell, mode_t mask)
299300
}
300301
exe = strrchr (shell, '/');
301302
exe = (exe) ? exe + 1 : shell;
303+
if (to->login) {
304+
int s = strlen(exe) + 2;
305+
char *p = malloc(s);
306+
307+
if (!p)
308+
exit(EXIT_FAILURE);
309+
310+
*p = '-';
311+
strcpy(p + 1, exe);
312+
exe = p;
313+
}
302314
if (setresgid(to->uid, to->uid, to->uid)) {
303315
PLOGE("setresgid (%u)", to->uid);
304316
exit(EXIT_FAILURE);
@@ -350,8 +362,10 @@ int main(int argc, char *argv[])
350362
case 'h':
351363
usage(EXIT_SUCCESS);
352364
break;
353-
case 'l': /* for compatibility */
354-
case 'm':
365+
case 'l':
366+
su_to.login = 1;
367+
break;
368+
case 'm': /* for compatibility */
355369
case 'p':
356370
break;
357371
case 's':
@@ -370,6 +384,7 @@ int main(int argc, char *argv[])
370384
}
371385
}
372386
if (optind < argc && !strcmp(argv[optind], "-")) {
387+
su_to.login = 1;
373388
optind++;
374389
}
375390
/*

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 login;
5152
int doshell;
5253
char *command;
5354
};

0 commit comments

Comments
 (0)