Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: check SHELL if (and only if) neither --sh nor --csh is specified #661

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions p11-kit/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static bool need_children_cleanup = false;
static bool terminate = false;
static unsigned children_avail = 0;
static bool quiet = false;
static bool csh_opt = false;
static int shell_opt = 0;

#define P11_KIT_SERVER_ADDRESS_ENV "P11_KIT_SERVER_ADDRESS"
#define P11_KIT_SERVER_PID_ENV "P11_KIT_SERVER_PID"
Expand Down Expand Up @@ -502,7 +502,7 @@ server_loop (Server *server,
close (STDOUT_FILENO);
}
if (pid != 0) {
if (!print_environment (pid, server, csh_opt))
if (!print_environment (pid, server, shell_opt == 'c'))
return 1;
exit (0);
}
Expand Down Expand Up @@ -536,7 +536,7 @@ server_loop (Server *server,
/* for testing purposes, even when started in foreground,
* print the envvars */
if (foreground) {
if (!print_environment (getpid (), server, csh_opt))
if (!print_environment (getpid (), server, shell_opt == 'c'))
return 1;
fflush (stdout);
}
Expand Down Expand Up @@ -763,10 +763,10 @@ main (int argc,
kill_opt = true;
break;
case opt_csh:
csh_opt = true;
shell_opt = opt_csh;
break;
case opt_sh:
csh_opt = false;
shell_opt = opt_sh;
break;
case opt_help:
case '?':
Expand All @@ -786,12 +786,12 @@ main (int argc,
return 2;
}

if (!opt_sh && !opt_csh) {
if (!shell_opt) {
const char *shell = secure_getenv ("SHELL");
size_t len;
if (shell != NULL && (len = strlen (shell)) > 2 &&
strncmp (shell + len - 3, "csh", 3) == 0)
csh_opt = true;
shell_opt = opt_csh;
}

if (kill_opt) {
Expand All @@ -815,7 +815,7 @@ main (int argc,
exit (1);
}

if (csh_opt) {
if (shell_opt == opt_csh) {
printf ("unsetenv %s;\n",
P11_KIT_SERVER_ADDRESS_ENV);
printf ("unsetenv %s;\n",
Expand Down
Loading