add mkdir and chmod functions to chroot-sh
authorBenedikt Boehm <hollow@gentoo.org>
Wed, 1 Nov 2006 15:34:06 +0000 (15:34 +0000)
committerBenedikt Boehm <hollow@gentoo.org>
Wed, 1 Nov 2006 15:34:06 +0000 (15:34 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2359 94cd875c-1c1d-0410-91d2-eb244daf1a30

src/Makefile-files
src/chroot-sh.c

index c6e8588..aa6af6c 100644 (file)
@@ -181,6 +181,7 @@ src_filetime_LDFLAGS                =  $(VSERVER_LDFLGS)
 
 src_chain_echo_SOURCES         =  src/chain-echo.c
 src_chroot_sh_SOURCES          =  src/chroot-sh.c
+src_chroot_sh_LDADD            =  $(LIBINTERNAL)
 src_exec_cd_SOURCES            =  src/exec-cd.c
 src_fakerunlevel_SOURCES       =  src/fakerunlevel.c
 src_ifspec_SOURCES             =  src/ifspec.c
index addb0f9..a7aa744 100644 (file)
@@ -142,6 +142,54 @@ 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]);
+    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 struct Command {
     char const         *cmd;
@@ -152,6 +200,8 @@ static struct Command {
   { "truncate", execTruncate },
   { "testfile", execTestFile },
   { "rm",       execRm },
+  { "mkdir",    execMkdir },
+  { "chmod",    execChmod },
   { 0,0 }
 };
 
@@ -170,7 +220,10 @@ showHelp()
            "  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"
+           "  rm <file>+      ...  unlink the given files\n"
+           "  mkdir <file>+   ...  create the given directories\n"
+           "  chmod <mode> <file>+\n"
+           "                  ...  change access permissions of files\n\n"
            "Please report bugs to " PACKAGE_BUGREPORT "\n");
   exit(0);
 }