summaryrefslogtreecommitdiffstats
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r--sway/ipc-server.c45
1 files changed, 3 insertions, 42 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index be6e411a..dfe88ed6 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -125,6 +125,7 @@ struct sockaddr_un *ipc_user_sockaddr(void) {
125 return ipc_sockaddr; 125 return ipc_sockaddr;
126} 126}
127 127
128/*
128static pid_t get_client_pid(int client_fd) { 129static pid_t get_client_pid(int client_fd) {
129// FreeBSD supports getting uid/gid, but not pid 130// FreeBSD supports getting uid/gid, but not pid
130#ifdef __linux__ 131#ifdef __linux__
@@ -140,6 +141,7 @@ static pid_t get_client_pid(int client_fd) {
140 return -1; 141 return -1;
141#endif 142#endif
142} 143}
144*/
143 145
144int ipc_handle_connection(int fd, uint32_t mask, void *data) { 146int ipc_handle_connection(int fd, uint32_t mask, void *data) {
145 (void) fd; (void) data; 147 (void) fd; (void) data;
@@ -159,17 +161,6 @@ int ipc_handle_connection(int fd, uint32_t mask, void *data) {
159 return 0; 161 return 0;
160 } 162 }
161 163
162 pid_t pid = get_client_pid(client_fd);
163 if (!(get_feature_policy(pid) & FEATURE_IPC)) {
164 sway_log(L_INFO, "Permission to connect to IPC socket denied to %d", pid);
165 const char *error = "{\"success\": false, \"message\": \"Permission denied\"}";
166 if (write(client_fd, &error, sizeof(error)) < (int)sizeof(error)) {
167 sway_log(L_DEBUG, "Failed to write entire error");
168 }
169 close(client_fd);
170 return 0;
171 }
172
173 struct ipc_client* client = malloc(sizeof(struct ipc_client)); 164 struct ipc_client* client = malloc(sizeof(struct ipc_client));
174 if (!client) { 165 if (!client) {
175 sway_log(L_ERROR, "Unable to allocate ipc client"); 166 sway_log(L_ERROR, "Unable to allocate ipc client");
@@ -351,9 +342,6 @@ void ipc_client_handle_command(struct ipc_client *client) {
351 switch (client->current_command) { 342 switch (client->current_command) {
352 case IPC_COMMAND: 343 case IPC_COMMAND:
353 { 344 {
354 if (!(config->ipc_policy & IPC_FEATURE_COMMAND)) {
355 goto exit_denied;
356 }
357 struct cmd_results *results = handle_command(buf, CONTEXT_IPC); 345 struct cmd_results *results = handle_command(buf, CONTEXT_IPC);
358 const char *json = cmd_results_to_json(results); 346 const char *json = cmd_results_to_json(results);
359 char reply[256]; 347 char reply[256];
@@ -403,9 +391,6 @@ void ipc_client_handle_command(struct ipc_client *client) {
403 391
404 case IPC_GET_WORKSPACES: 392 case IPC_GET_WORKSPACES:
405 { 393 {
406 if (!(config->ipc_policy & IPC_FEATURE_GET_WORKSPACES)) {
407 goto exit_denied;
408 }
409 json_object *workspaces = json_object_new_array(); 394 json_object *workspaces = json_object_new_array();
410 container_map(&root_container, ipc_get_workspaces_callback, workspaces); 395 container_map(&root_container, ipc_get_workspaces_callback, workspaces);
411 const char *json_string = json_object_to_json_string(workspaces); 396 const char *json_string = json_object_to_json_string(workspaces);
@@ -416,9 +401,6 @@ void ipc_client_handle_command(struct ipc_client *client) {
416 401
417 case IPC_GET_INPUTS: 402 case IPC_GET_INPUTS:
418 { 403 {
419 if (!(config->ipc_policy & IPC_FEATURE_GET_INPUTS)) {
420 goto exit_denied;
421 }
422 json_object *inputs = json_object_new_array(); 404 json_object *inputs = json_object_new_array();
423 if (input_devices) { 405 if (input_devices) {
424 for(int i=0; i<input_devices->length; i++) { 406 for(int i=0; i<input_devices->length; i++) {
@@ -442,9 +424,6 @@ void ipc_client_handle_command(struct ipc_client *client) {
442 424
443 case IPC_GET_OUTPUTS: 425 case IPC_GET_OUTPUTS:
444 { 426 {
445 if (!(config->ipc_policy & IPC_FEATURE_GET_OUTPUTS)) {
446 goto exit_denied;
447 }
448 json_object *outputs = json_object_new_array(); 427 json_object *outputs = json_object_new_array();
449 container_map(&root_container, ipc_get_outputs_callback, outputs); 428 container_map(&root_container, ipc_get_outputs_callback, outputs);
450 const char *json_string = json_object_to_json_string(outputs); 429 const char *json_string = json_object_to_json_string(outputs);
@@ -455,9 +434,6 @@ void ipc_client_handle_command(struct ipc_client *client) {
455 434
456 case IPC_GET_TREE: 435 case IPC_GET_TREE:
457 { 436 {
458 if (!(config->ipc_policy & IPC_FEATURE_GET_TREE)) {
459 goto exit_denied;
460 }
461 json_object *tree = ipc_json_describe_container_recursive(&root_container); 437 json_object *tree = ipc_json_describe_container_recursive(&root_container);
462 const char *json_string = json_object_to_json_string(tree); 438 const char *json_string = json_object_to_json_string(tree);
463 ipc_send_reply(client, json_string, (uint32_t) strlen(json_string)); 439 ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
@@ -522,9 +498,6 @@ void ipc_client_handle_command(struct ipc_client *client) {
522 498
523 case IPC_GET_BAR_CONFIG: 499 case IPC_GET_BAR_CONFIG:
524 { 500 {
525 if (!(config->ipc_policy & IPC_FEATURE_GET_BAR_CONFIG)) {
526 goto exit_denied;
527 }
528 if (!buf[0]) { 501 if (!buf[0]) {
529 // Send list of configured bar IDs 502 // Send list of configured bar IDs
530 json_object *bars = json_object_new_array(); 503 json_object *bars = json_object_new_array();
@@ -565,7 +538,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
565 goto exit_cleanup; 538 goto exit_cleanup;
566 } 539 }
567 540
568exit_denied: 541//exit_denied:
569 ipc_send_reply(client, error_denied, (uint32_t)strlen(error_denied)); 542 ipc_send_reply(client, error_denied, (uint32_t)strlen(error_denied));
570 543
571exit_cleanup: 544exit_cleanup:
@@ -632,9 +605,6 @@ void ipc_send_event(const char *json_string, enum ipc_command_type event) {
632} 605}
633 606
634void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) { 607void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) {
635 if (!(config->ipc_policy & IPC_FEATURE_EVENT_WORKSPACE)) {
636 return;
637 }
638 sway_log(L_DEBUG, "Sending workspace::%s event", change); 608 sway_log(L_DEBUG, "Sending workspace::%s event", change);
639 json_object *obj = json_object_new_object(); 609 json_object *obj = json_object_new_object();
640 json_object_object_add(obj, "change", json_object_new_string(change)); 610 json_object_object_add(obj, "change", json_object_new_string(change));
@@ -659,9 +629,6 @@ void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) {
659} 629}
660 630
661void ipc_event_window(swayc_t *window, const char *change) { 631void ipc_event_window(swayc_t *window, const char *change) {
662 if (!(config->ipc_policy & IPC_FEATURE_EVENT_WINDOW)) {
663 return;
664 }
665 sway_log(L_DEBUG, "Sending window::%s event", change); 632 sway_log(L_DEBUG, "Sending window::%s event", change);
666 json_object *obj = json_object_new_object(); 633 json_object *obj = json_object_new_object();
667 json_object_object_add(obj, "change", json_object_new_string(change)); 634 json_object_object_add(obj, "change", json_object_new_string(change));
@@ -687,9 +654,6 @@ void ipc_event_barconfig_update(struct bar_config *bar) {
687} 654}
688 655
689void ipc_event_mode(const char *mode) { 656void ipc_event_mode(const char *mode) {
690 if (!(config->ipc_policy & IPC_FEATURE_EVENT_MODE)) {
691 return;
692 }
693 sway_log(L_DEBUG, "Sending mode::%s event", mode); 657 sway_log(L_DEBUG, "Sending mode::%s event", mode);
694 json_object *obj = json_object_new_object(); 658 json_object *obj = json_object_new_object();
695 json_object_object_add(obj, "change", json_object_new_string(mode)); 659 json_object_object_add(obj, "change", json_object_new_string(mode));
@@ -715,9 +679,6 @@ void ipc_event_modifier(uint32_t modifier, const char *state) {
715} 679}
716 680
717static void ipc_event_binding(json_object *sb_obj) { 681static void ipc_event_binding(json_object *sb_obj) {
718 if (!(config->ipc_policy & IPC_FEATURE_EVENT_BINDING)) {
719 return;
720 }
721 sway_log(L_DEBUG, "Sending binding::run event"); 682 sway_log(L_DEBUG, "Sending binding::run event");
722 json_object *obj = json_object_new_object(); 683 json_object *obj = json_object_new_object();
723 json_object_object_add(obj, "change", json_object_new_string("run")); 684 json_object_object_add(obj, "change", json_object_new_string("run"));