diff options
Diffstat (limited to 'sway/security.c')
-rw-r--r-- | sway/security.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/sway/security.c b/sway/security.c index ef9e81c..de54455 100644 --- a/sway/security.c +++ b/sway/security.c @@ -1,6 +1,9 @@ #define _POSIX_C_SOURCE 200809L +#include <errno.h> +#include <fcntl.h> #include <stdlib.h> #include <string.h> +#include <sys/socket.h> #include "sway/security.h" struct feature_name feature_names[] = { @@ -15,19 +18,58 @@ struct feature_name feature_names[] = { }; struct feature_policy *get_feature_policy( - struct sway_config *config, const char *program) { - if (!program) { + struct sway_config *config, const char *command) { + if (!command) { return &config->default_policy; } struct feature_policy *policy; for (int i = 0; i < config->feature_policies->length; ++i) { policy = config->feature_policies->items[i]; - if (strcmp(policy->program, program) == 0) { + if (strcmp(policy->command, command) == 0) { return policy; } } policy = calloc(1, sizeof(struct feature_policy)); - policy->program = strdup(program); + policy->command = strdup(command); return policy; } + +struct wl_client *create_secure_client(struct wl_display *display, + int fd, const char *command) { + struct feature_policy *policy; + int i; + for (i = 0; i < config->feature_policies->length; ++i) { + policy = config->feature_policies->items[i]; + if (strcmp(policy->command, command) == 0) { + break; + } + } + if (i == config->feature_policies->length) { + policy = &config->default_policy; + } + // TODO: Something useful with policy + struct wl_client *client = wl_client_create(display, fd); + // TODO: Destroy listener + return client; +} + +bool create_client_socket(int sv[2]) { + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) < 0 || errno == EINVAL) { + return false; + } + int flags; + if ((flags = fcntl(sv[0], F_GETFD)) == -1) { + return false; + } + if ((fcntl(sv[0], F_SETFD, flags | FD_CLOEXEC)) == -1) { + return false; + } + if ((flags = fcntl(sv[1], F_GETFD)) == -1) { + return false; + } + if ((fcntl(sv[1], F_SETFD, flags | FD_CLOEXEC)) == -1) { + return false; + } + return true; +} |