From: Andre Noll Date: Sun, 31 Jul 2016 08:32:57 +0000 (+0200) Subject: server: Remove support for non-lopsub commands. X-Git-Tag: v0.6.0~2^2~54 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=b3f6c5fa7f0fe78e825ecc83f3b9f9893c0427c6;p=paraslash.git server: Remove support for non-lopsub commands. Now that all commands have been converted to lopsub, struct server_command is no longer needed and can be removed, along with the helper functions for lookup and permission checking. --- diff --git a/command.c b/command.c index 8608f309..d7b68a45 100644 --- a/command.c +++ b/command.c @@ -37,7 +37,6 @@ #include "ipc.h" #include "server_cmd.lsg.h" #include "user_list.h" -#include "afs.command_list.h" #include "signal.h" #include "version.h" @@ -48,26 +47,6 @@ static const unsigned server_command_perms[] = {LSG_SERVER_CMD_AUX_INFOS}; static const char * const server_command_perms_txt[] = {LSG_SERVER_CMD_AUX_INFOS}; #undef SERVER_CMD_AUX_INFO -typedef int server_command_handler_t(struct command_context *); - -/* Defines one command of para_server. */ -struct server_command { - /* The name of the command. */ - const char *name; - /* Pointer to the function that handles the command. */ - server_command_handler_t *handler; - /* The privileges a user must have to execute this command. */ - unsigned int perms; - /* One-line description of the command. */ - const char *description; - /* Summary of the command line options. */ - const char *usage; - /* The long help text. */ - const char *help; -}; - -static struct server_command afs_cmds[] = {DEFINE_AFS_CMD_ARRAY}; - /** Commands including options must be shorter than this. */ #define MAX_COMMAND_LEN 32768 @@ -583,21 +562,6 @@ static int send_list_of_commands(struct command_context *cc) return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false); } -/* returns string that must be freed by the caller */ -static struct server_command *get_cmd_ptr(const char *name, char **handler) -{ - struct server_command *cmd; - - /* not found, look for commands supported by afs */ - for (cmd = afs_cmds; cmd->name; cmd++) - if (!strcmp(cmd->name, name)) { - if (handler) - *handler = para_strdup("afs"); - return cmd; - } - return NULL; -} - static int com_help(struct command_context *cc, struct lls_parse_result *lpr) { const char *perms; @@ -790,16 +754,6 @@ static int com_tasks(struct command_context *cc, } EXPORT_SERVER_CMD_HANDLER(tasks); -/* - * check if perms are sufficient to exec a command having perms cmd_perms. - * Returns 0 if perms are sufficient, -E_PERM otherwise. - */ -static int check_perms(unsigned int perms, const struct server_command *cmd_ptr) -{ - PARA_DEBUG_LOG("checking permissions\n"); - return (cmd_ptr->perms & perms) < cmd_ptr->perms ? -E_PERM : 0; -} - static void reset_signals(void) { para_sigaction(SIGCHLD, SIG_IGN); @@ -860,7 +814,6 @@ static int run_command(struct command_context *cc, struct iovec *iov, { int ret, i; char *p, *end; - struct server_command *cmd = NULL; const struct lls_command *lcmd = NULL; unsigned perms; struct lls_parse_result *lpr; @@ -872,22 +825,14 @@ static int run_command(struct command_context *cc, struct iovec *iov, p[iov->iov_len - 1] = '\0'; /* just to be sure */ ret = lls(lls_lookup_subcmd(p, server_cmd_suite, &errctx)); - if (ret >= 0) { - perms = server_command_perms[ret]; - if ((perms & cc->u->perms) != perms) - return -E_PERM; - lcmd = lls_cmd(ret, server_cmd_suite); - } else { - cmd = get_cmd_ptr(p, NULL); - if (!cmd) { - send_errctx(cc, errctx); - return ret; - } - perms = cmd->perms; - ret = check_perms(cc->u->perms, cmd); - if (ret < 0) - return ret; + if (ret < 0) { + send_errctx(cc, errctx); + return ret; } + perms = server_command_perms[ret]; + if ((perms & cc->u->perms) != perms) + return -E_PERM; + lcmd = lls_cmd(ret, server_cmd_suite); end = iov->iov_base + iov->iov_len; for (i = 0; p < end; i++) p += strlen(p) + 1; @@ -898,19 +843,15 @@ static int run_command(struct command_context *cc, struct iovec *iov, p += strlen(p) + 1; } cc->argv[cc->argc] = NULL; - PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", lcmd? - lls_command_name(lcmd) : cmd->name, cc->u->name, peername); - if (lcmd) { - ret = lls(lls_parse(cc->argc, cc->argv, lcmd, &lpr, &errctx)); - if (ret >= 0) { - const struct server_cmd_user_data *ud = lls_user_data(lcmd); - ret = ud->handler(cc, lpr); - lls_free_parse_result(lpr, lcmd); - } else - send_errctx(cc, errctx); - } else { - ret = cmd->handler(cc); - } + PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", lls_command_name(lcmd), + cc->u->name, peername); + ret = lls(lls_parse(cc->argc, cc->argv, lcmd, &lpr, &errctx)); + if (ret >= 0) { + const struct server_cmd_user_data *ud = lls_user_data(lcmd); + ret = ud->handler(cc, lpr); + lls_free_parse_result(lpr, lcmd); + } else + send_errctx(cc, errctx); free_argv(cc->argv); mutex_lock(mmd_mutex); mmd->num_commands++;