summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Vargas Caballero <k0ga@shike2.com>2014-08-19 00:55:02 +0200
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2014-08-20 09:03:44 +0200
commita3549c2eecf12b3453e6c86ba1721e7837f23746 (patch)
treea32736e55e1b1150000e66bb0a33ef3cad3733d4
parentFix definition of CONTROLC0 (diff)
downloadst-a3549c2eecf12b3453e6c86ba1721e7837f23746.tar.gz
st-a3549c2eecf12b3453e6c86ba1721e7837f23746.zip
Improve execsh() and don't allow anonymous shells
This patch improves the shell selection on execsh and forbid shell with users don't registered in the passwd file.
Diffstat (limited to '')
-rw-r--r--st.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/st.c b/st.c
index 1c998ec..009388c 100644
--- a/st.c
+++ b/st.c
@@ -1139,23 +1139,29 @@ die(const char *errstr, ...) {
1139 1139
1140void 1140void
1141execsh(void) { 1141execsh(void) {
1142 char **args; 1142 char **args, *sh;
1143 char *envshell = getenv("SHELL"); 1143 const struct passwd *pw;
1144 const struct passwd *pass = getpwuid(getuid());
1145 char buf[sizeof(long) * 8 + 1]; 1144 char buf[sizeof(long) * 8 + 1];
1146 1145
1146 errno = 0;
1147 if((pw = getpwuid(getuid())) == NULL) {
1148 if(errno)
1149 die("getpwuid:%s\n", strerror(errno));
1150 else
1151 die("who are you?\n");
1152 }
1147 unsetenv("COLUMNS"); 1153 unsetenv("COLUMNS");
1148 unsetenv("LINES"); 1154 unsetenv("LINES");
1149 unsetenv("TERMCAP"); 1155 unsetenv("TERMCAP");
1150 1156
1151 if(pass) { 1157 sh = (pw->pw_shell[0]) ? pw->pw_shell : shell;
1152 setenv("LOGNAME", pass->pw_name, 1);
1153 setenv("USER", pass->pw_name, 1);
1154 setenv("SHELL", pass->pw_shell, 0);
1155 setenv("HOME", pass->pw_dir, 0);
1156 }
1157
1158 snprintf(buf, sizeof(buf), "%lu", xw.win); 1158 snprintf(buf, sizeof(buf), "%lu", xw.win);
1159
1160 setenv("LOGNAME", pw->pw_name, 1);
1161 setenv("USER", pw->pw_name, 1);
1162 setenv("SHELL", sh, 1);
1163 setenv("HOME", pw->pw_dir, 1);
1164 setenv("TERM", termname, 1);
1159 setenv("WINDOWID", buf, 1); 1165 setenv("WINDOWID", buf, 1);
1160 1166
1161 signal(SIGCHLD, SIG_DFL); 1167 signal(SIGCHLD, SIG_DFL);
@@ -1165,9 +1171,7 @@ execsh(void) {
1165 signal(SIGTERM, SIG_DFL); 1171 signal(SIGTERM, SIG_DFL);
1166 signal(SIGALRM, SIG_DFL); 1172 signal(SIGALRM, SIG_DFL);
1167 1173
1168 DEFAULT(envshell, shell); 1174 args = opt_cmd ? opt_cmd : (char *[]){sh, "-i", NULL};
1169 setenv("TERM", termname, 1);
1170 args = opt_cmd ? opt_cmd : (char *[]){envshell, "-i", NULL};
1171 execvp(args[0], args); 1175 execvp(args[0], args);
1172 exit(EXIT_FAILURE); 1176 exit(EXIT_FAILURE);
1173} 1177}