X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fchroot-sh.c;h=d6a710ae5a3c7df22b4775342282a31bc31d366d;hb=eef2d73a81a9a7941c9e6be8c4fc4acd7da4d00f;hp=a7aa7441b8f5629375e59e1dc6dbe593af5849c0;hpb=77716ebf1cde97db63dfbc2aa2c50f084e7c126f;p=util-vserver.git diff --git a/src/chroot-sh.c b/src/chroot-sh.c index a7aa744..d6a710a 100644 --- a/src/chroot-sh.c +++ b/src/chroot-sh.c @@ -178,6 +178,7 @@ execChmod(int argc, char *argv[]) if (!isNumberUnsigned(argv[1], &mode, 1)) { WRITE_MSG(2, "Invalid mode: '"); WRITE_STR(2, argv[1]); + WRITE_MSG(2, "'\n"); return EXIT_FAILURE; } @@ -191,6 +192,69 @@ execChmod(int argc, char *argv[]) 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; int (*handler)(int argc, char *argv[]); @@ -202,6 +266,9 @@ static struct Command { { "rm", execRm }, { "mkdir", execMkdir }, { "chmod", execChmod }, + { "link", execLink }, + { "mv", execMv }, + { "realpath", execRealpath }, { 0,0 } }; @@ -216,15 +283,18 @@ showHelp() "directory, and symlinks can point to files under the current path only.\n" "\n" "The supported commands are:\n" - " cat ... gives out to stdout\n" - " append ... appends stdin to which is created when needed\n" - " truncate ... clear and fill it with stdin; the is\n" + " cat ... gives out to stdout\n" + " append ... appends stdin to which is created when needed\n" + " truncate ... clear and fill it with stdin; the is\n" " created when needed\n" - " rm + ... unlink the given files\n" - " mkdir + ... create the given directories\n" + " rm + ... unlink the given files\n" + " mkdir + ... create the given directories\n" " chmod +\n" - " ... change access permissions of files\n\n" - "Please report bugs to " PACKAGE_BUGREPORT "\n"); + " ... change access permissions of files\n" + " link ... create a symbolic link from to \n" + " mv ... rename to \n" + " realpath + ... output real path of each \n" + "\nPlease report bugs to " PACKAGE_BUGREPORT "\n"); exit(0); }