diff options
Diffstat (limited to 'sway/commands/ipc.c')
-rw-r--r-- | sway/commands/ipc.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/sway/commands/ipc.c b/sway/commands/ipc.c index 113a975b..8a7b849f 100644 --- a/sway/commands/ipc.c +++ b/sway/commands/ipc.c | |||
@@ -1,18 +1,26 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include "sway/security.h" | ||
3 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
4 | #include "sway/config.h" | 5 | #include "sway/config.h" |
5 | #include "ipc.h" | 6 | #include "ipc.h" |
6 | #include "log.h" | 7 | #include "log.h" |
7 | #include "util.h" | 8 | #include "util.h" |
8 | 9 | ||
10 | static struct ipc_policy *current_policy = NULL; | ||
11 | |||
9 | struct cmd_results *cmd_ipc(int argc, char **argv) { | 12 | struct cmd_results *cmd_ipc(int argc, char **argv) { |
10 | struct cmd_results *error = NULL; | 13 | struct cmd_results *error = NULL; |
11 | if ((error = checkarg(argc, "ipc", EXPECTED_EQUAL_TO, 1))) { | 14 | if ((error = checkarg(argc, "ipc", EXPECTED_EQUAL_TO, 2))) { |
15 | return error; | ||
16 | } | ||
17 | if ((error = check_security_config())) { | ||
12 | return error; | 18 | return error; |
13 | } | 19 | } |
14 | 20 | ||
15 | if (config->reading && strcmp("{", argv[0]) != 0) { | 21 | const char *program = argv[0]; |
22 | |||
23 | if (config->reading && strcmp("{", argv[1]) != 0) { | ||
16 | return cmd_results_new(CMD_INVALID, "ipc", | 24 | return cmd_results_new(CMD_INVALID, "ipc", |
17 | "Expected '{' at start of IPC config definition."); | 25 | "Expected '{' at start of IPC config definition."); |
18 | } | 26 | } |
@@ -21,10 +29,8 @@ struct cmd_results *cmd_ipc(int argc, char **argv) { | |||
21 | return cmd_results_new(CMD_FAILURE, "ipc", "Can only be used in config file."); | 29 | return cmd_results_new(CMD_FAILURE, "ipc", "Can only be used in config file."); |
22 | } | 30 | } |
23 | 31 | ||
24 | if (!current_config_path || strcmp(SYSCONFDIR "/sway/security", current_config_path) != 0) { | 32 | current_policy = alloc_ipc_policy(program); |
25 | return cmd_results_new(CMD_INVALID, "permit", | 33 | list_add(config->ipc_policies, current_policy); |
26 | "This command is only permitted to run from " SYSCONFDIR "/sway/security"); | ||
27 | } | ||
28 | 34 | ||
29 | return cmd_results_new(CMD_BLOCK_IPC, NULL, NULL); | 35 | return cmd_results_new(CMD_BLOCK_IPC, NULL, NULL); |
30 | } | 36 | } |
@@ -67,6 +73,7 @@ struct cmd_results *cmd_ipc_cmd(int argc, char **argv) { | |||
67 | char *name; | 73 | char *name; |
68 | enum ipc_feature type; | 74 | enum ipc_feature type; |
69 | } types[] = { | 75 | } types[] = { |
76 | { "*", IPC_FEATURE_ALL_COMMANDS }, | ||
70 | { "command", IPC_FEATURE_COMMAND }, | 77 | { "command", IPC_FEATURE_COMMAND }, |
71 | { "workspaces", IPC_FEATURE_GET_WORKSPACES }, | 78 | { "workspaces", IPC_FEATURE_GET_WORKSPACES }, |
72 | { "outputs", IPC_FEATURE_GET_OUTPUTS }, | 79 | { "outputs", IPC_FEATURE_GET_OUTPUTS }, |
@@ -86,10 +93,10 @@ struct cmd_results *cmd_ipc_cmd(int argc, char **argv) { | |||
86 | } | 93 | } |
87 | 94 | ||
88 | if (enabled) { | 95 | if (enabled) { |
89 | config->ipc_policy |= type; | 96 | current_policy->features |= type; |
90 | sway_log(L_DEBUG, "Enabled IPC %s feature", argv[-1]); | 97 | sway_log(L_DEBUG, "Enabled IPC %s feature", argv[-1]); |
91 | } else { | 98 | } else { |
92 | config->ipc_policy &= ~type; | 99 | current_policy->features &= ~type; |
93 | sway_log(L_DEBUG, "Disabled IPC %s feature", argv[-1]); | 100 | sway_log(L_DEBUG, "Disabled IPC %s feature", argv[-1]); |
94 | } | 101 | } |
95 | 102 | ||
@@ -116,6 +123,7 @@ struct cmd_results *cmd_ipc_event_cmd(int argc, char **argv) { | |||
116 | char *name; | 123 | char *name; |
117 | enum ipc_feature type; | 124 | enum ipc_feature type; |
118 | } types[] = { | 125 | } types[] = { |
126 | { "*", IPC_FEATURE_ALL_EVENTS }, | ||
119 | { "workspace", IPC_FEATURE_EVENT_WORKSPACE }, | 127 | { "workspace", IPC_FEATURE_EVENT_WORKSPACE }, |
120 | { "output", IPC_FEATURE_EVENT_OUTPUT }, | 128 | { "output", IPC_FEATURE_EVENT_OUTPUT }, |
121 | { "mode", IPC_FEATURE_EVENT_MODE }, | 129 | { "mode", IPC_FEATURE_EVENT_MODE }, |
@@ -134,10 +142,10 @@ struct cmd_results *cmd_ipc_event_cmd(int argc, char **argv) { | |||
134 | } | 142 | } |
135 | 143 | ||
136 | if (enabled) { | 144 | if (enabled) { |
137 | config->ipc_policy |= type; | 145 | current_policy->features |= type; |
138 | sway_log(L_DEBUG, "Enabled IPC %s event", argv[-1]); | 146 | sway_log(L_DEBUG, "Enabled IPC %s event", argv[-1]); |
139 | } else { | 147 | } else { |
140 | config->ipc_policy &= ~type; | 148 | current_policy->features &= ~type; |
141 | sway_log(L_DEBUG, "Disabled IPC %s event", argv[-1]); | 149 | sway_log(L_DEBUG, "Disabled IPC %s event", argv[-1]); |
142 | } | 150 | } |
143 | 151 | ||