Remove allowed shell check from swayrun

Because swayrun should be run from a safe environment, validating
the user's shell against /etc/shells seems unnecessary.
This commit is contained in:
Corey Hinshaw 2019-02-10 20:41:04 -05:00
parent f1d64f811d
commit eb22dee79c
3 changed files with 5 additions and 44 deletions

View file

@ -1,48 +1,16 @@
#define _POSIX_C_SOURCE 200809L // for getline
#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "stringop.h"
#define SWAY_COMMAND "sway"
char allowed_shell(char *shell) {
FILE *fp;
char *line = NULL;
size_t len = 0;
char allowed = false;
if (strstr(shell, "false") != NULL || strstr(shell, "nologin") != NULL) {
return false;
}
fp = fopen("/etc/shells", "r");
if (fp == NULL) {
return true;
}
while (getline(&line, &len, fp) != -1) {
strip_whitespace(line);
if (strcmp(shell, line) == 0) {
allowed = true;
break;
}
}
fclose(fp);
if (line) {
free(line);
}
return allowed;
}
int main(int argc, char **argv) {
char *shell = getenv("SHELL");
if (shell && allowed_shell(shell)) {
if (shell) {
// 3 exec arguments + argc + argv[argc] NULL pointer
int exec_argc = 4 + argc;
char **exec_argv = malloc(exec_argc * sizeof(char*));

View file

@ -1,7 +1,5 @@
executable(
'swayrun',
'main.c',
include_directories: [sway_inc],
link_with: [lib_sway_common],
install: true
)

View file

@ -11,16 +11,11 @@ _swayrun_ [options...] [command]
# DESCRIPTION
Attempts to run *sway*(1) via the user's login shell. This allows environment
configuration and other login actions, for example when run via a login manager.
configuration and other login actions, for example when run via a display manager.
All arguments to swayrun will be passed through unaltered to sway.
If a valid login shell cannot be determined, sway will be executed normally.
# CONFIGURATION
swayrun will consult */etc/shells* if it exists for a list of valid login
shells. In addition, *false* and *nologin* will be considered invalid shells.
If a login shell cannot be determined, sway will be executed normally.
# ENVIRONMENT
@ -31,4 +26,4 @@ _SHELL_
# SEE
*sway*(1) *shells*(5)
*sway*(1)