use $(LIBENSCVECTOR) instead of libensc_vector.a
[util-vserver.git] / util-vserver / src / secure-umount.c
1 // $Id$    --*- c++ -*--
2
3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 //  
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
8 //  
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //  
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "pathconfig.h"
24
25 #include "wrappers.h"
26 #include "util.h"
27
28 int     wrapper_exit_code = 1;
29
30 static void
31 showHelp(int fd, char const *cmd, int res)
32 {
33   WRITE_MSG(fd, "Usage:  ");
34   WRITE_STR(fd, cmd);
35   WRITE_MSG(fd,
36             "[--help] [--version] <dir>\n\n"
37             "Please report bugs to " PACKAGE_BUGREPORT "\n");
38
39   exit(res);
40 }
41
42 static void
43 showVersion()
44 {
45   WRITE_MSG(1,
46             "secure-umount " VERSION " -- secure umounting of directories\n"
47             "This program is part of " PACKAGE_STRING "\n\n"
48             "Copyright (C) 2003 Enrico Scholz\n"
49             VERSION_COPYRIGHT_DISCLAIMER);
50   exit(0);
51 }
52
53 int main(int argc, char *argv[])
54 {
55   char const *  dir;
56   int           root_fd;
57   int           this_fd;
58   char *        umount_cmd[] = { UMOUNT_PROG, "-l", "-n", ".", 0 };
59
60   if (argc<2) {
61     WRITE_MSG(2, "Try '");
62     WRITE_STR(2, argv[0]);
63     WRITE_MSG(2, " --help\" for more information.\n");
64     return EXIT_FAILURE;
65   }
66
67   if (strcmp(argv[1], "--help")==0)    showHelp(1, argv[0], 0);
68   if (strcmp(argv[1], "--version")==0) showVersion();
69
70   dir = argv[1];
71   if (strcmp(dir, "--")==0 && argc>=3) dir = argv[2];
72
73   root_fd = Eopen("/", O_RDONLY, 0);
74   Echroot(".");
75   Echdir(dir);
76   this_fd = Eopen(".", O_RDONLY, 0);
77   Efchdir(root_fd);
78   Echroot(".");
79   Efchdir(this_fd);
80
81   Eclose(root_fd);
82   Eclose(this_fd);
83
84   Eexecv(umount_cmd[0], umount_cmd);
85 }