#include "ipc.h"
#include "server_cmd.lsg.h"
#include "user_list.h"
-#include "afs.command_list.h"
#include "signal.h"
#include "version.h"
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
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;
}
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);
{
int ret, i;
char *p, *end;
- struct server_command *cmd = NULL;
const struct lls_command *lcmd = NULL;
unsigned perms;
struct lls_parse_result *lpr;
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;
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++;