File indexing completed on 2025-05-11 08:24:19
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifdef HAVE_CONFIG_H
0010 #include "config.h"
0011 #endif
0012
0013 #include <errno.h>
0014 #include <stdio.h>
0015 #include <string.h>
0016 #include <unistd.h>
0017
0018 #include <rtems/shellconfig.h>
0019 #include <rtems/stringto.h>
0020
0021 #include "internal.h"
0022
0023 static int usage(void)
0024 {
0025 puts(rtems_shell_CMDCHMOD_Command.usage);
0026
0027 return -1;
0028 }
0029
0030 static void error(const char *s, int eno)
0031 {
0032 printf("%s: %s\n", s, strerror(eno));
0033 }
0034
0035 static int rtems_shell_main_cmdchmod(int argc, char **argv)
0036 {
0037 if (argc >= 2) {
0038 unsigned long mode;
0039 rtems_status_code sc;
0040 uid_t task_uid;
0041 int i;
0042
0043 sc = rtems_string_to_unsigned_long(argv[1], &mode, NULL, 8);
0044 if (sc != RTEMS_SUCCESSFUL) {
0045 return usage();
0046 }
0047
0048 task_uid = getuid();
0049
0050 for (i = 2; i < argc; ++i) {
0051 const char *cmd = argv[i];
0052 rtems_shell_cmd_t *shell_cmd = rtems_shell_lookup_cmd(cmd);
0053
0054 if (shell_cmd != NULL) {
0055 if (task_uid == 0 || task_uid == shell_cmd->uid) {
0056 shell_cmd->mode = mode
0057 & (S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
0058 } else if (rtems_shell_can_see_cmd(shell_cmd)) {
0059 error(cmd, EACCES);
0060 } else {
0061 error(cmd, ENOENT);
0062 }
0063 } else {
0064 error(cmd, ENOENT);
0065 }
0066 }
0067 } else {
0068 return usage();
0069 }
0070
0071 return 0;
0072 }
0073
0074 rtems_shell_cmd_t rtems_shell_CMDCHMOD_Command = {
0075 .name = "cmdchmod",
0076 .usage = "cmdchmod OCTAL-MODE COMMAND...",
0077 .topic = "misc",
0078 .command = rtems_shell_main_cmdchmod
0079 };