mirror of
https://github.com/swaywm/sway.git
synced 2024-12-02 03:16:47 +00:00
Refactor code into resolve_ipc_path
This commit is contained in:
parent
04c2221190
commit
403dccabce
|
@ -15,4 +15,5 @@ struct feature_policy *alloc_feature_policy(const char *program);
|
||||||
struct ipc_policy *alloc_ipc_policy(const char *program);
|
struct ipc_policy *alloc_ipc_policy(const char *program);
|
||||||
struct command_policy *alloc_command_policy(const char *command);
|
struct command_policy *alloc_command_policy(const char *command);
|
||||||
|
|
||||||
|
char *resolve_ipc_path(const char* program);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,23 +18,19 @@ struct cmd_results *cmd_ipc(int argc, char **argv) {
|
||||||
if ((error = check_security_config())) {
|
if ((error = check_security_config())) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config->reading && strcmp("{", argv[1]) != 0) {
|
if (config->reading && strcmp("{", argv[1]) != 0) {
|
||||||
return cmd_results_new(CMD_INVALID, "ipc",
|
return cmd_results_new(CMD_INVALID, "ipc",
|
||||||
"Expected '{' at start of IPC config definition.");
|
"Expected '{' at start of IPC config definition.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config->reading) {
|
if (!config->reading) {
|
||||||
return cmd_results_new(CMD_FAILURE, "ipc", "Can only be used in config file.");
|
return cmd_results_new(CMD_FAILURE, "ipc", "Can only be used in config file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
char *program = NULL;
|
char *program = NULL;
|
||||||
|
|
||||||
if (!strcmp(argv[0], "*")) {
|
if (!(program = resolve_ipc_path(argv[0]))) {
|
||||||
program = strdup(argv[0]);
|
|
||||||
} else if (!(program = resolve_path(argv[0]))) {
|
|
||||||
return cmd_results_new(
|
return cmd_results_new(
|
||||||
CMD_INVALID, "ipc", "Unable to resolve IPC Policy target.");
|
CMD_FAILURE, "ipc", "Memory allocation error occured.");
|
||||||
}
|
}
|
||||||
current_policy = alloc_ipc_policy(program);
|
current_policy = alloc_ipc_policy(program);
|
||||||
list_add(config->ipc_policies, current_policy);
|
list_add(config->ipc_policies, current_policy);
|
||||||
|
|
|
@ -50,17 +50,8 @@ struct cmd_results *cmd_permit(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *program = NULL;
|
char *program = NULL;
|
||||||
|
if (!(program = resolve_ipc_path(argv[0]))) {
|
||||||
if (!strcmp(argv[0], "*")) {
|
sway_abort("memory allocation failed");
|
||||||
program = strdup(argv[0]);
|
|
||||||
} else {
|
|
||||||
program = resolve_path(argv[0]);
|
|
||||||
}
|
|
||||||
if (!program) {
|
|
||||||
sway_assert(program, "Unable to resolve IPC permit target '%s'."
|
|
||||||
" will issue empty policy", argv[0]);
|
|
||||||
assign_perms = false;
|
|
||||||
program = strdup(argv[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct feature_policy *policy = get_feature_policy(program);
|
struct feature_policy *policy = get_feature_policy(program);
|
||||||
|
@ -87,16 +78,8 @@ struct cmd_results *cmd_reject(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *program = NULL;
|
char *program = NULL;
|
||||||
if (!strcmp(argv[0], "*")) {
|
if (!(program = resolve_ipc_path(argv[0]))) {
|
||||||
program = strdup(argv[0]);
|
sway_abort("memory allocation failed");
|
||||||
} else {
|
|
||||||
program = resolve_path(argv[0]);
|
|
||||||
}
|
|
||||||
if (!program) {
|
|
||||||
// Punt
|
|
||||||
sway_log(L_INFO, "Unable to resolve IPC reject target '%s'."
|
|
||||||
" Will use provided path", argv[0]);
|
|
||||||
program = strdup(argv[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct feature_policy *policy = get_feature_policy(program);
|
struct feature_policy *policy = get_feature_policy(program);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
#include "sway/security.h"
|
#include "sway/security.h"
|
||||||
|
#include "util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
static bool validate_ipc_target(const char *program) {
|
static bool validate_ipc_target(const char *program) {
|
||||||
|
@ -222,3 +223,21 @@ const char *command_policy_str(enum command_context context) {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An IPC-specific version of util.c:resolve_path()
|
||||||
|
* Always returns the "best" path It can unless an ENOMEM occurs ,
|
||||||
|
* in which case it returns NULL.
|
||||||
|
*/
|
||||||
|
char *resolve_ipc_path(const char* name) {
|
||||||
|
char *program = NULL;
|
||||||
|
if (!strcmp(name, "*")) {
|
||||||
|
program = strdup(name);
|
||||||
|
} else {
|
||||||
|
program = resolve_path(name);
|
||||||
|
if (!program) {
|
||||||
|
program = strdup(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return program;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue