galeb

Једноставна статичка дистрибуција заснована на musl-у
git clone https://git.sr.ht/~strahinja/galeb
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

login-proper-login-shell-minus.patch (1152B)


      1 diff --git a/login.c b/login.c
      2 index 25a59e4..7c671db 100644
      3 --- a/login.c
      4 +++ b/login.c
      5 @@ -4,6 +4,7 @@
      6  
      7  #include <errno.h>
      8  #include <grp.h>
      9 +#include <limits.h>
     10  #include <pwd.h>
     11  #include <stdio.h>
     12  #include <stdlib.h>
     13 @@ -45,18 +46,29 @@ writeutmp(const char *user, const char *tty)
     14  static int
     15  dologin(struct passwd *pw, int preserve)
     16  {
     17 -	char *shell = pw->pw_shell[0] == '\0' ? "/bin/sh" : pw->pw_shell;
     18 +	char shell[2][4096];
     19 +	char* slash = NULL;
     20 +
     21 +	if (!pw->pw_shell[0]) {
     22 +		strcpy(shell[0], "/bin/sh");
     23 +		strcpy(shell[1], "-sh");
     24 +	} else {
     25 +		strcpy(shell[0], pw->pw_shell);
     26 +		*shell[1] = '-';
     27 +		slash = strrchr(shell[0], '/');
     28 +		strcpy(shell[1]+1, slash ? slash+1 : shell[0]);
     29 +	}
     30  
     31  	if (preserve == 0)
     32  		clearenv();
     33  	setenv("HOME", pw->pw_dir, 1);
     34 -	setenv("SHELL", shell, 1);
     35 +	setenv("SHELL", shell[0], 1);
     36  	setenv("USER", pw->pw_name, 1);
     37  	setenv("LOGNAME", pw->pw_name, 1);
     38  	setenv("PATH", ENV_PATH, 1);
     39  	if (chdir(pw->pw_dir) < 0)
     40  		eprintf("chdir %s:", pw->pw_dir);
     41 -	execlp(shell, shell, "-l", NULL);
     42 +	execlp(shell[0], shell[1], NULL);
     43  	weprintf("execlp %s:", shell);
     44  	return (errno == ENOENT) ? 127 : 126;
     45  }