logo

skeud

Simple and portable utilities to deal with user accounts (su, login)git clone https://anongit.hacktivis.me/git/skeud.git/
commit: ac7eca22806f1d17e66b640bcebfec06a19a6bf1
parent a6db836fe6eb640fd9a034fe379fcbe9ec5b63b4
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 10 Nov 2025 08:38:49 +0100

login: prefix shell argv0 with - instead of using -l option

This way no argument is passed to the user's login shell.

Diffstat:

Mlogin.c10+++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/login.c b/login.c @@ -14,6 +14,7 @@ #include <errno.h> // errno #include <grp.h> // getgrnam, initgroups +#include <limits.h> // NAME_MAX #include <pwd.h> // getpwnam #include <stdbool.h> // bool #include <stdio.h> // fprintf, perror @@ -251,9 +252,16 @@ main(int argc, char *argv[]) free(username_buf); + const char *sh_basename = strrchr(shell, '/'); + + sh_basename = sh_basename ? sh_basename + 1 : shell; + + char shell0[NAME_MAX] = "-sh"; + strlcpy(shell0 + 1, sh_basename, NAME_MAX - 1); + errno = 0; /* flawfinder: ignore CWE-78 */ - if(execl(shell, shell, "-l", NULL) < 0) + if(execl(shell, shell0, NULL) < 0) { if(errno == ENOENT) {