mirror of
https://github.com/swaywm/sway.git
synced 2026-04-30 06:46:24 -04:00
Flesh out security-related data structures
This commit is contained in:
parent
bce7068b65
commit
633cafb0d5
5 changed files with 25 additions and 172 deletions
|
|
@ -436,86 +436,6 @@ struct cmd_results *config_subcommand(char **argv, int argc,
|
|||
"This command is shimmed, but unimplemented");
|
||||
}
|
||||
|
||||
struct cmd_results *config_commands_command(char *exec) {
|
||||
struct cmd_results *results = NULL;
|
||||
int argc;
|
||||
char **argv = split_args(exec, &argc);
|
||||
if (!argc) {
|
||||
results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Find handler for the command this is setting a policy for
|
||||
char *cmd = argv[0];
|
||||
|
||||
if (strcmp(cmd, "}") == 0) {
|
||||
results = cmd_results_new(CMD_BLOCK_END, NULL, NULL);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
struct cmd_handler *handler = find_handler(cmd, NULL, 0);
|
||||
if (!handler && strcmp(cmd, "*") != 0) {
|
||||
results = cmd_results_new(CMD_INVALID, cmd, "Unknown/invalid command");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
enum command_context context = 0;
|
||||
|
||||
struct {
|
||||
char *name;
|
||||
enum command_context context;
|
||||
} context_names[] = {
|
||||
{ "config", CONTEXT_CONFIG },
|
||||
{ "binding", CONTEXT_BINDING },
|
||||
{ "ipc", CONTEXT_IPC },
|
||||
{ "criteria", CONTEXT_CRITERIA },
|
||||
{ "all", CONTEXT_ALL },
|
||||
};
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
size_t j;
|
||||
for (j = 0; j < sizeof(context_names) / sizeof(context_names[0]); ++j) {
|
||||
if (strcmp(context_names[j].name, argv[i]) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == sizeof(context_names) / sizeof(context_names[0])) {
|
||||
results = cmd_results_new(CMD_INVALID, cmd,
|
||||
"Invalid command context %s", argv[i]);
|
||||
goto cleanup;
|
||||
}
|
||||
context |= context_names[j].context;
|
||||
}
|
||||
|
||||
struct command_policy *policy = NULL;
|
||||
for (int i = 0; i < config->command_policies->length; ++i) {
|
||||
struct command_policy *p = config->command_policies->items[i];
|
||||
if (strcmp(p->command, cmd) == 0) {
|
||||
policy = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!policy) {
|
||||
policy = alloc_command_policy(cmd);
|
||||
if (!sway_assert(policy, "Unable to allocate security policy")) {
|
||||
results = cmd_results_new(CMD_INVALID, cmd,
|
||||
"Unable to allocate memory");
|
||||
goto cleanup;
|
||||
}
|
||||
list_add(config->command_policies, policy);
|
||||
}
|
||||
policy->context = context;
|
||||
|
||||
wlr_log(WLR_INFO, "Set command policy for %s to %d",
|
||||
policy->command, policy->context);
|
||||
|
||||
results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
|
||||
cleanup:
|
||||
free_argv(argc, argv);
|
||||
return results;
|
||||
}
|
||||
|
||||
struct cmd_results *cmd_results_new(enum cmd_status status,
|
||||
const char *input, const char *format, ...) {
|
||||
struct cmd_results *results = malloc(sizeof(struct cmd_results));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue