gentoo: use /var/run for new /run compatibility
[util-vserver.git] / src / chroot-sh.c
index addb0f9..d6a710a 100644 (file)
@@ -142,6 +142,118 @@ execTestFile(int argc, char *argv[])
   return res!=-1 && S_ISREG(res) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
+static int
+execMkdir(int argc, char *argv[])
+{
+  int          i   = 1;
+  int          res = EXIT_SUCCESS;
+  
+  if (argc<2) {
+    WRITE_MSG(2, "No files specified for 'mkdir' operation; try '--help' for more information\n");
+    return wrapper_exit_code;
+  }
+
+  for (;i<argc; ++i) {
+    if (mkdir(argv[i], 0755)==-1) {
+      PERROR_Q(ENSC_WRAPPERS_PREFIX "mkdir", argv[i]);
+      res = EXIT_FAILURE;
+    }
+  }
+
+  return res;
+}
+
+static int
+execChmod(int argc, char *argv[])
+{
+  int          i   = 2;
+  int          res = EXIT_SUCCESS;
+  unsigned long mode;
+  
+  if (argc<3) {
+    WRITE_MSG(2, "No files specified for 'chmod' operation; try '--help' for more information\n");
+    return wrapper_exit_code;
+  }
+
+  if (!isNumberUnsigned(argv[1], &mode, 1)) {
+    WRITE_MSG(2, "Invalid mode: '");
+    WRITE_STR(2, argv[1]);
+    WRITE_MSG(2, "'\n");
+    return EXIT_FAILURE;
+  }
+
+  for (;i<argc; ++i) {
+    if (chmod(argv[i], mode)==-1) {
+      PERROR_Q(ENSC_WRAPPERS_PREFIX "chmod", argv[i]);
+      res = EXIT_FAILURE;
+    }
+  }
+
+  return res;
+}
+
+static int
+execLink(int argc, char *argv[])
+{
+  int          res = EXIT_SUCCESS;
+
+  if (argc!=3) {
+    WRITE_MSG(2, "Need exactly two files for 'link' operation; try '--help' for more information\n");
+    return wrapper_exit_code;
+  }
+
+  if (symlink(argv[1], argv[2])==-1) {
+    PERROR_Q(ENSC_WRAPPERS_PREFIX "link", argv[1]);
+    res = EXIT_FAILURE;
+  }
+
+  return res;
+}
+
+static int
+execMv(int argc, char *argv[])
+{
+  int          res = EXIT_SUCCESS;
+
+  if (argc!=3) {
+    WRITE_MSG(2, "Need exactly two files for 'mv' operation; try '--help' for more information\n");
+    return wrapper_exit_code;
+  }
+
+  if (rename(argv[1], argv[2])==-1) {
+    PERROR_Q(ENSC_WRAPPERS_PREFIX "mv", argv[1]);
+    res = EXIT_FAILURE;
+  }
+
+  return res;
+}
+
+static int
+execRealpath(int argc, char *argv[])
+{
+  int          res = EXIT_SUCCESS,
+               i;
+
+  if (argc < 2) {
+    WRITE_MSG(2, "Need some files to work on for 'realpath' operation; try '--help' for more information\n");
+    return wrapper_exit_code;
+  }
+
+  for (i = 1; i< argc; i++) {
+    char buf[4096];
+
+    if (realpath(argv[i], buf) == NULL) {
+      PERROR_Q(ENSC_WRAPPERS_PREFIX "realpath", argv[i]);
+      res = EXIT_FAILURE;
+    }
+    else {
+      WRITE_STR(1, buf);
+      WRITE_MSG(1, "\n");
+    }
+  }
+
+  return res;
+}
 
 static struct Command {
     char const         *cmd;
@@ -152,6 +264,11 @@ static struct Command {
   { "truncate", execTruncate },
   { "testfile", execTestFile },
   { "rm",       execRm },
+  { "mkdir",    execMkdir },
+  { "chmod",    execChmod },
+  { "link",     execLink },
+  { "mv",       execMv },
+  { "realpath", execRealpath },
   { 0,0 }
 };
 
@@ -166,12 +283,18 @@ showHelp()
            "directory, and symlinks can point to files under the current path only.\n"
            "\n"
            "The supported commands are:\n"
-           "  cat <file>      ...  gives out <file> to stdout\n"
-           "  append <file>   ...  appends stdin to <file> which is created when needed\n"
-           "  truncate <file> ...  clear <file> and fill it with stdin; the <file> is\n"
+           "  cat <file>       ...  gives out <file> to stdout\n"
+           "  append <file>    ...  appends stdin to <file> which is created when needed\n"
+           "  truncate <file>  ...  clear <file> and fill it with stdin; the <file> is\n"
            "                       created when needed\n"
-           "  rm <file>+      ...  unlink the given files\n\n"
-           "Please report bugs to " PACKAGE_BUGREPORT "\n");
+           "  rm <file>+       ...  unlink the given files\n"
+           "  mkdir <file>+    ...  create the given directories\n"
+           "  chmod <mode> <file>+\n"
+           "                   ...  change access permissions of files\n"
+           "  link <src> <dst> ...  create a symbolic link from <src> to <dst>\n"
+           "  mv <src> <dst>   ...  rename <src> to <dst>\n"
+           "  realpath <file>+ ...  output real path of each <file>\n"
+           "\nPlease report bugs to " PACKAGE_BUGREPORT "\n");
   exit(0);
 }