source: rtems/cpukit/libmisc/shell/cmds.c @ c52568d

5
Last change on this file since c52568d was 7eada71, checked in by Sebastian Huber <sebastian.huber@…>, on 11/18/14 at 06:35:30

shell: Add mode, UID and GID to shell commands

Use this information to determine if a command is visible to the current
user and if the current user is allowed to execute this command.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 *  XXX -- Just monitor commands until those can be integrated better
3 *
4 *  Author: Fernando RUIZ CASAS
5 *  Work: fernando.ruiz@ctv.es
6 *  Home: correo@fernando-ruiz.com
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.org/license/LICENSE.
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <stdio.h>
18#include <string.h>
19#include <stdlib.h>
20
21#include <rtems.h>
22#include <rtems/monitor.h>
23#include <rtems/shell.h>
24#include "internal.h"
25
26/*-----------------------------------------------------------*
27 * with this you can call at all the rtems monitor commands.
28 * Not all work fine but you can show the rtems status and more.
29 *-----------------------------------------------------------*/
30int rtems_shell_main_monitor(int argc, char **argv) {
31  const rtems_monitor_command_entry_t *command = NULL;
32
33  if (argc < 1) {
34    return 1;
35  }
36
37  command = rtems_monitor_command_lookup(argv [0]);
38
39  if (command == NULL) {
40    return 1;
41  }
42
43  command->command_function(argc, argv, &command->command_arg, 0);
44
45  return 0;
46}
47
48static bool rtems_shell_register_command(const rtems_monitor_command_entry_t *e, void *arg __attribute__((unused)))
49{
50  /* Exclude EXIT (alias quit)*/
51  if (strcmp("exit", e->command) != 0) {
52    rtems_shell_cmd_t *shell_cmd =
53      (rtems_shell_cmd_t *) calloc(1, sizeof(*shell_cmd));
54
55    if (shell_cmd != NULL) {
56      shell_cmd->name    = e->command;
57      shell_cmd->topic   = "monitor";
58      shell_cmd->usage   = e->usage;
59      shell_cmd->command = rtems_shell_main_monitor;
60
61      if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) {
62        free(shell_cmd);
63      }
64    }
65  }
66
67  return true;
68}
69
70void rtems_shell_register_monitor_commands(void)
71{
72  rtems_monitor_command_iterate(rtems_shell_register_command, NULL);
73}
Note: See TracBrowser for help on using the repository browser.