afab07c41dd5ddca0632087c8ad2cc504d14726d
[util-vserver.git] / src / secure-mount.c
1 // $Id: secure-mount.c 2403 2006-11-24 23:06:08Z dhozac $    --*- 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   // secure-mount <general mount(8) options> [--chroot]
20   //              [--mtab <mtabfile>] [--fstab <fstabfile>]
21   //
22   // Executes mount-operations under the current directory: it assumes sources
23   // in the current root-dir while destinations are expected in the chroot
24   // environment.
25
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #include "util.h"
32 #include "pathconfig.h"
33
34 #include <lib/internal.h>
35
36 #include <getopt.h>
37 #include <fcntl.h>
38 #include <errno.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <strings.h>
43 #include <unistd.h>
44 #include <stdbool.h>
45 #include <sys/mount.h>
46 #include <sys/stat.h>
47 #include <sys/types.h>
48 #include <sys/file.h>
49 #include <linux/fs.h>
50 #include <assert.h>
51 #include <ctype.h>
52 #include <sys/wait.h>
53 #include <libgen.h>
54 #include <signal.h>
55 #include <stdlib.h>
56
57 #define ENSC_WRAPPERS_FCNTL     1
58 #define ENSC_WRAPPERS_UNISTD    1
59 #include <wrappers.h>
60
61 #define MNTPOINT        "/etc"
62
63 typedef enum { rfsYES, rfsNO, rfsONLY }         RootFsOption;
64
65 struct MountInfo {
66     char const *        src;
67     char const *        dst;
68     char const *        type;
69     unsigned long       flag;
70     unsigned long       xflag;
71     unsigned long       mask;
72     char *              data;
73 };
74
75 struct Options {
76     char const *        mtab;
77     char const *        fstab;
78     bool                do_chroot;
79     bool                ignore_mtab;
80     bool                mount_all;
81     RootFsOption        rootfs;
82
83     int                 cur_dir_fd;
84     int                 cur_rootdir_fd;
85 };
86
87 #define OPTION_BIND     1024
88 #define OPTION_MOVE     1025
89 #define OPTION_MTAB     1026
90 #define OPTION_FSTAB    1027
91 #define OPTION_CHROOT   1028
92 #define OPTION_SECURE   1029
93 #define OPTION_RBIND    1030
94 #define OPTION_ROOTFS   1031
95
96 #define XFLAG_NOAUTO    0x01
97
98 static struct option const
99 CMDLINE_OPTIONS[] = {
100   { "help",    no_argument,       0, 'h' },
101   { "version", no_argument,       0, 'v' },
102   { "bind",    no_argument,       0, OPTION_BIND },
103   { "move",    no_argument,       0, OPTION_MOVE },
104   { "mtab",    required_argument, 0, OPTION_MTAB },
105   { "fstab",   required_argument, 0, OPTION_FSTAB },
106   { "rootfs",  required_argument, 0, OPTION_ROOTFS },
107   { "chroot",  no_argument,       0, OPTION_CHROOT },
108   { "secure",  no_argument,       0, OPTION_SECURE },
109   { "rbind",   no_argument,       0, OPTION_RBIND },
110   { 0, 0, 0, 0 }
111 };
112
113 #ifndef MS_REC
114 #  define MS_REC        0x4000
115 #endif
116
117 static struct FstabOption {
118     char const * const  opt;
119     unsigned long const         flag;
120     unsigned long const         mask;
121     unsigned long const         xflag;
122     bool const                  is_dflt;
123 } const FSTAB_OPTIONS[] = {
124   { "defaults",   0,             (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|
125                                   MS_SYNCHRONOUS), 0, false },
126   { "rbind",      MS_BIND|MS_REC, MS_BIND|MS_REC,  0, false },
127   { "bind",       MS_BIND,        MS_BIND,         0, false },
128   { "move",       MS_MOVE,        MS_MOVE,         0, false },
129   { "async",      0,              MS_SYNCHRONOUS,  0, false },
130   { "sync",       MS_SYNCHRONOUS, MS_SYNCHRONOUS,  0, false },
131   { "atime",      0,              MS_NOATIME,      0, false },
132   { "noatime",    MS_NOATIME,     MS_NOATIME,      0, false },
133   { "dev",        0,              MS_NODEV,        0, false },
134   { "nodev",      MS_NODEV,       MS_NODEV,        0, false },
135   { "exec",       0,              MS_NOEXEC,       0, false },
136   { "noexec",     MS_NOEXEC,      MS_NOEXEC,       0, false },
137   { "suid",       0,              MS_NOSUID,       0, false },
138   { "nosuid",     MS_NOSUID,      MS_NOSUID,       0, false },
139   { "ro",         MS_RDONLY,      MS_RDONLY,       0, false },
140   { "rw",         0,              MS_RDONLY,       0, false },
141   
142   { "remount",    MS_REMOUNT,     MS_REMOUNT,      0, false },
143   { "users",      MS_NOEXEC|MS_NOSUID|MS_NODEV,
144                   MS_NOEXEC|MS_NOSUID|MS_NODEV,    0, false },
145   { "mandlock",   MS_MANDLOCK,    MS_MANDLOCK,     0, false },
146   { "nodiratime", MS_NODIRATIME,  MS_NODIRATIME,   0, false },
147 #ifdef MS_DIRSYNC  
148   { "dirsync",    MS_DIRSYNC,     MS_DIRSYNC,      0, false },
149 #endif
150   { "_netdev",    0,              0,               0, false },
151   { "auto",       0,              0,               0, false },
152   { "noauto",     0,              0,               XFLAG_NOAUTO, false },
153   { "user",       0,              0,               0, false },
154   { "nouser",     0,              0,               0, false },
155 };
156
157 int                     wrapper_exit_code = 1;
158
159 static void
160 showHelp(int fd, char const *cmd, int res)
161 {
162   VSERVER_DECLARE_CMD(cmd);
163   
164   WRITE_MSG(fd, "Usage:  ");
165   WRITE_STR(fd, cmd);
166   WRITE_MSG(fd,
167             " [--help] [--version] [--bind] [--move] [--rbind] [-t <type>] [--chroot]\n"
168             "            [--mtab <filename>] [--fstab <filename>] [--rootfs yes|no|only]\n"
169             "            [-n] -a|([-o <options>] [--] <src> <dst>)\n\n"
170             "Executes mount-operations under the current directory: it assumes sources in\n"
171             "the current root-dir while destinations are expected in the chroot environment.\n\n"
172             "For non-trivial mount-operations it uses the external 'mount' program which\n"
173             "can be overridden by the $MOUNT environment variable.\n\n"
174             "Options:\n"
175             "  --bind|move|rbind        ...  set the correspond flags; with this options\n"
176             "                                the mount will be executed internally without\n"
177             "                                calling an external mount program.\n"
178             "  -t <type>                ...  assume the given filesystem type\n"
179             "  -o <options>             ...  set additional options; see mount(2) for details\n"
180             "  -n                       ...  do not update the mtab-file\n"
181             "  --mtab <filename>        ...  use <filename> as an alternative mtab file\n"
182             "                                [default: /etc/mtab]\n"
183             "  --chroot                 ...  chroot into the current directory before\n"
184             "                                mounting the filesystem\n"
185             "  --fstab <filename>       ...  use <filename> as an alternative fstab file;\n"
186             "                                this option has an effect only with the '-a'\n"
187             "                                option [default: /etc/fstab]\n"
188             "  --rootfs yes|no|only     ...  specifies how to handle an entry for a rootfs\n"
189             "                                ('/') when processing an fstab file. 'yes' will\n"
190             "                                mount it among the other entries, 'only' will\n"
191             "                                mount only the rootfs entry, and 'no' will ignore\n"
192             "                                it and mount only the other entries [default: yes]\n"
193             "  -a                       ...  mount everything listed in the fstab-file\n\n"
194             "  <src>                    ...  the source-filesystem; this path is absolute\n"
195             "                                to the current root-filesystem. Only valid\n"
196             "                                without the '-a' option.\n"
197             "  <dst>                    ...  the destination mount-point; when used with\n"
198             "                                '--chroot', this path is relative to the current\n"
199             "                                directory. Only valid without the '-a' option\n\n"
200             "Please report bugs to " PACKAGE_BUGREPORT "\n");
201
202   exit(res);
203 }
204
205 static void
206 showVersion()
207 {
208   WRITE_MSG(1,
209             "secure-mount " VERSION " -- secure mounting of directories\n"
210             "This program is part of " PACKAGE_STRING "\n\n"
211             "Copyright (C) 2003 Enrico Scholz\n"
212             VERSION_COPYRIGHT_DISCLAIMER);
213   exit(0);
214 }
215
216 inline static bool
217 isSameObject(struct stat const *lhs,
218              struct stat const *rhs)
219 {
220   return (lhs->st_dev==rhs->st_dev &&
221           lhs->st_ino==rhs->st_ino);
222 }
223
224 static int
225 fchroot(int fd)
226 {
227   if (fchdir(fd)==-1 || chroot(".")==-1) return -1;
228   return 0;
229 }
230
231 static int
232 writeX(int fd, void const *buf, size_t len)
233 {
234   if ((size_t)(write(fd, buf, len))!=len) return -1;
235   return 0;
236 }
237
238 static int
239 writeStrX(int fd, char const *str)
240 {
241   return writeX(fd, str, strlen(str));
242 }
243
244 static inline char const *
245 getType(struct MountInfo const *mnt)
246 {
247   if (mnt->type==0)                         return "none";
248   else if (strncmp(mnt->type, "ext", 3)==0) return "ufs";
249   else                                      return mnt->type;
250 }
251
252 inline static void
253 restoreRoot(struct Options const *opt)
254 {
255   if (opt->do_chroot!=0 && fchroot(opt->cur_rootdir_fd)==-1) {
256     perror("secure-mount: fchdir(\"/\")");
257     WRITE_MSG(2, "Failed to restore root-directory; aborting\n");
258     exit(1);
259   }
260 }
261
262 static int
263 updateMtab(struct MountInfo const *mnt, struct Options const *opt)
264 {
265   int           res = -1;
266   int           fd;
267   assert(opt->mtab!=0);
268
269   if (opt->do_chroot && fchroot(opt->cur_dir_fd)==-1) {
270       perror("secure-mount: fchroot(\".\")");
271       return -1;
272   }
273
274   fd=open(opt->mtab, O_CREAT|O_APPEND|O_WRONLY, 0644);
275   
276   if (fd==-1) {
277     perror("secure-mount: open(<mtab>)");
278     goto err0;
279   }
280
281   if (flock(fd, LOCK_EX)==-1) {
282     perror("secure-mount: flock()");
283     goto err1;
284   }
285
286   if (writeStrX(fd, mnt->src)==-1 ||
287       writeStrX(fd, " ")==-1 ||
288       writeStrX(fd, mnt->dst)==-1 ||
289       writeStrX(fd, " ")==-1 ||
290       writeStrX(fd, getType(mnt))==-1 ||
291       writeStrX(fd, " ")==-1 ||
292       writeStrX(fd, mnt->data ? mnt->data : "defaults")==-1 ||
293       writeStrX(fd, " 0 0\n")==-1) {
294     perror("secure-mount: write()");
295     goto err1;
296   }
297
298   res = 0;
299
300   err1: close(fd);
301   err0:
302   restoreRoot(opt);
303   return res;
304 }
305
306 static bool
307 callExternalMount(struct MountInfo const *mnt)
308 {
309   char const *  argv[10];
310   size_t        idx = 0;
311   pid_t         pid;
312   int           status;
313   char const *  mount_prog = getenv("MOUNT");
314
315   if (mount_prog==0) mount_prog = MOUNT_PROG;
316
317   argv[idx++] = mount_prog;
318   argv[idx++] = "-n";
319   if      (mnt->flag & MS_BIND) argv[idx++] = "--bind";
320   else if (mnt->flag & MS_MOVE) argv[idx++] = "--move";
321
322   argv[idx++] = "-o";
323   if (mnt->data && *mnt->data &&
324       strcmp(mnt->data, "defaults")!=0) {
325     if (mnt->mask & MS_NODEV)
326       argv[idx++] = mnt->data;
327     else {
328       char *    tmp = alloca(strlen(mnt->data) + sizeof("nodev,"));
329       strcpy(tmp, "nodev,");
330       strcat(tmp, mnt->data);
331       argv[idx++] = tmp;
332     }
333   }
334   else
335     argv[idx++] = "nodev";
336
337   if (mnt->type) {
338     argv[idx++] = "-t";
339     argv[idx++] = mnt->type;
340   }
341
342   argv[idx++] = mnt->src;
343   argv[idx++] = ".";
344   argv[idx]   = 0;
345
346   pid = fork();
347   if (pid==-1) {
348     perror("secure-mount: fork()");
349     return false;
350   }
351
352   if (pid==0) {
353     execv(mount_prog, const_cast(char **)(argv));
354     PERROR_Q("secure-mount: execv", mount_prog);
355     exit(1);
356   }
357
358   if (wait4(pid, &status, 0, 0)==-1) {
359     perror("secure-mount: wait4()");
360     return false;
361   }
362
363   return (WIFEXITED(status)) && (WEXITSTATUS(status)==0);
364 }
365
366 inline static bool
367 secureChdir(char const *dir, struct Options const *opt)
368 {
369   int           dir_fd;
370   bool          res = false;
371   
372   if (opt->do_chroot!=0 && fchroot(opt->cur_dir_fd)==-1) {
373     perror("secure-mount: fchroot(\".\")");
374     return false;
375   }
376
377   if (chdir(dir)==-1) {
378     PERROR_Q("secure-mount: chdir", dir);
379     goto err;
380   }
381
382   dir_fd = open(".", O_RDONLY|O_DIRECTORY);
383   if (dir_fd==-1) {
384     perror("secure-mount: open(\".\")");
385     goto err;
386   }
387
388   restoreRoot(opt);
389   if (fchdir(dir_fd)==-1)
390     PERROR_Q("secure-mount: fchdir", dir);
391   else
392     res = true;
393   
394   close(dir_fd);
395   return res;
396
397   err:
398   restoreRoot(opt);
399   return false;
400 }
401
402 static bool
403 canHandleInternal(struct MountInfo const *mnt)
404 {
405   static char const *   FS[] = {
406     "tmpfs", "sysfs", "proc", "sockfs", "pipefs", "futexfs",
407     "inotifyfs", "devpts", "ext3", "ext2", "ramfs",
408     "hugetlbfs", "usbfs", "binfmt_misc",
409     0
410   };
411   char const **         i;
412   
413   if (!mnt)                                 return false;
414   else if ((mnt->flag & (MS_BIND|MS_MOVE))) return true;
415   else if (mnt->type==0)                    return false;
416
417   for (i=FS+0; *i!=0; ++i)
418     if (strcmp(mnt->type, *i)==0) return true;
419
420   return false;
421 }
422
423 static bool
424 mountSingle(struct MountInfo const *mnt, struct Options const *opt)
425 {
426   assert(mnt->dst!=0);
427   
428   if (!secureChdir(mnt->dst, opt))
429     return false;
430
431   if (canHandleInternal(mnt)) {
432     if (mount(mnt->src, ".",
433               mnt->type ? mnt->type : "",
434               mnt->flag,  mnt->data)==-1) {
435       perror("secure-mount: mount()");
436       return false;
437     }
438   }
439   else if (!callExternalMount(mnt))
440     return false;
441
442   if (!opt->ignore_mtab &&
443       updateMtab(mnt, opt)==-1) {
444     WRITE_MSG(2, "Failed to update mtab-file\n");
445       // no error
446   }
447   
448   return true;
449 }
450
451 static struct FstabOption const *
452 searchOption(char const *opt, size_t len)
453 {
454   struct FstabOption const *            i;
455   for (i=FSTAB_OPTIONS+0; i<FSTAB_OPTIONS+DIM_OF(FSTAB_OPTIONS); ++i)
456     if (strncmp(i->opt, opt, len)==0) return i;
457
458   return 0;
459 }
460
461 static bool
462 transformOptionList(struct MountInfo *info, size_t UNUSED *col)
463 {
464   char const *                  ptr = info->data;
465   char *                        data = malloc(strlen(info->data));
466   char *                        dst = data;
467
468   do {
469     char const *                pos = strchr(ptr, ',');
470     struct FstabOption const *  opt;
471     
472     if (pos==0) pos = ptr+strlen(ptr);
473     opt = searchOption(ptr, pos-ptr);
474
475     if (opt!=0) {
476       info->flag  &= ~opt->mask;
477       info->flag  |=  opt->flag;
478       info->mask  |=  opt->mask;
479       info->xflag |=  opt->xflag;
480     }
481     else {
482       if (dst != data)
483         *(dst++) = ',';
484       strncpy(dst, ptr, pos-ptr);
485       dst += pos - ptr;
486       *dst = '\0';
487     }
488
489     if (*pos!='\0')
490       ptr = pos+1;
491     else
492       ptr = pos;
493
494   } while (*ptr!='\0');
495
496   info->data = data;
497   return true;
498 }
499
500 #define MOVE_TO_NEXT_FIELD(PTR,ALLOW_EOL)               \
501   while (!isspace(*PTR) && *PTR!='\0') ++PTR;           \
502   if (col) *col = buf-start_buf+1;                      \
503   if (!(ALLOW_EOL) && *PTR=='\0') return prFAIL;        \
504   *PTR++ = '\0';                                        \
505   while (isspace(*PTR)) ++PTR
506
507 static enum {prDOIT, prFAIL, prIGNORE}
508   parseFstabLine(struct MountInfo *info, char *buf, size_t *col)
509 {
510   char const * const    start_buf = buf;
511   size_t                err_col;
512
513   while (isspace(*buf)) ++buf;
514   if (*buf=='#' || *buf=='\0')  return prIGNORE;
515
516   info->src  = buf;
517   MOVE_TO_NEXT_FIELD(buf, false);
518   info->dst  = buf;
519   MOVE_TO_NEXT_FIELD(buf, false);
520   info->type = buf;
521   MOVE_TO_NEXT_FIELD(buf, false);
522   err_col    = buf-start_buf+1;
523   info->data = buf;
524   MOVE_TO_NEXT_FIELD(buf, true);
525
526   info->flag  = MS_NODEV;
527   info->mask  = 0;
528   info->xflag = 0;
529
530   if      (strcmp(info->type, "swap")  ==0) return prIGNORE;
531   else if (strcmp(info->type, "none")  ==0) info->type  = 0;
532   else if (strcmp(info->type, "devpts")==0) {
533     info->mask |=  MS_NODEV;
534     info->flag &= ~MS_NODEV;
535   }
536
537   if (col) *col = err_col;
538   if (!transformOptionList(info,col)) return prFAIL;
539   if (info->xflag & XFLAG_NOAUTO)     return prIGNORE;
540
541   return prDOIT;
542 }
543
544 #undef MOVE_TO_NEXT_FIELD
545
546 static void
547 showFstabPosition(int fd, char const *fname, size_t line_nr, size_t col_nr)
548 {
549   char          buf[3*sizeof(line_nr)*2 + 4];
550   size_t        len = utilvserver_fmt_uint(buf+1, line_nr)+1;
551   
552   buf[0]     = ':';
553   buf[len++] = ':';
554   len += utilvserver_fmt_uint(buf+len, col_nr);
555   WRITE_STR(fd, fname);
556   Vwrite(fd, buf, len);
557 }
558
559
560 static bool
561 mountFstab(struct Options const *opt)
562 {
563   bool          res = false;
564   int           fd;
565   off_t         len;
566
567   assert(opt->fstab!=0);
568   fd = open(opt->fstab, O_RDONLY);
569   if (fd==-1) {
570     perror("secure-mount: open(<fstab>)");
571     goto err0;
572   }
573
574   len = lseek(fd, 0, SEEK_END); 
575   if (len==-1 ||
576       lseek(fd, 0, SEEK_SET)==-1) {
577     perror("secure-mount: lseek(<fstab>)");
578     goto err1;
579   }
580
581   {
582     char        buf[len+2];
583     char        *ptr, *ptrptr;
584     size_t      line_nr=0, col_nr;
585
586     if (read(fd, buf, len+1)!=len) {
587       perror("secure-mount: read()");
588       goto err1;
589     }
590     buf[len]   = '#';   // workaround for broken dietlibc strtok_r()
591                         // implementation
592     buf[len+1] = '\0';
593     ptrptr     = buf;
594
595     while ((ptr=strsep(&ptrptr, "\n")) != 0) {
596       struct MountInfo  mnt;
597       ++line_nr;
598
599       switch (parseFstabLine(&mnt, ptr, &col_nr)) {
600         case prFAIL     :
601           showFstabPosition(2, opt->fstab, line_nr, col_nr);
602           WRITE_MSG(2, ": syntax error\n");
603           goto err1;
604
605         case prIGNORE   :  break;
606         case prDOIT     : {
607           bool          is_rootfs = (strcmp(mnt.dst, "/")==0);
608           Echdir("/");
609           if (( is_rootfs && opt->rootfs==rfsNO) ||
610               (!is_rootfs && opt->rootfs==rfsONLY)) { /* ignore the entry */ }
611           else if (!mountSingle(&mnt, opt)) {
612             showFstabPosition(2, opt->fstab, line_nr, 1);
613             WRITE_MSG(2, ": failed to mount fstab-entry\n");
614           }
615           break;
616         }
617         default         :
618           assert(false);
619       }
620     }
621   }
622
623   res = true;
624
625   err1: close(fd);
626   err0: return res;
627 }
628
629 static void
630 initFDs(struct Options *opt)
631 {
632   opt->cur_dir_fd     = Eopen(".", O_RDONLY|O_DIRECTORY, 0);
633   opt->cur_rootdir_fd = Eopen("/", O_RDONLY|O_DIRECTORY, 0);
634
635   Efcntl(opt->cur_dir_fd,     F_SETFD, FD_CLOEXEC);
636   Efcntl(opt->cur_rootdir_fd, F_SETFD, FD_CLOEXEC);
637 }
638
639 static RootFsOption
640 parseRootFS(char const *str)
641 {
642   if      (strcasecmp(str, "yes")==0)  return rfsYES;
643   else if (strcasecmp(str, "no")==0)   return rfsNO;
644   else if (strcasecmp(str, "only")==0) return rfsONLY;
645   else {
646     WRITE_MSG(2, "secure-mount: invalid option for '--rootfs': '");
647     WRITE_STR(2, str);
648     WRITE_MSG(2, "'\n");
649     exit(wrapper_exit_code);
650   }
651 }
652
653 int main(int argc, char *argv[])
654 {
655   struct MountInfo      mnt = {
656     .src         = 0,
657     .dst         = 0,
658     .type        = 0,
659     .flag        = MS_NODEV,
660     .xflag       = 0,
661     .data        = 0,
662   };
663
664   struct Options        opt = {
665     .mtab           = "/etc/mtab",
666     .fstab          = "/etc/fstab",
667     .do_chroot      = 0,
668     .ignore_mtab    = false,
669     .mount_all      = false,
670     .cur_dir_fd     = -1,
671     .cur_rootdir_fd = -1,
672     .rootfs         = rfsYES
673   };
674
675   while (1) {
676     int         c = getopt_long(argc, argv, "ht:nao:", CMDLINE_OPTIONS, 0);
677     if (c==-1) break;
678     
679     switch (c) {
680       case 'h'          :  showHelp(1, argv[0], 0);
681       case 'v'          :  showVersion();
682       case 't'          :  mnt.type = optarg;         break;
683       case 'n'          :  opt.ignore_mtab = true;    break;
684       case 'a'          :  opt.mount_all   = true;    break;
685       case 'o'          :  mnt.data        = optarg;  break;
686       case OPTION_RBIND :  mnt.flag       |= MS_REC;  /*@fallthrough@*/
687       case OPTION_BIND  :  mnt.flag       |= MS_BIND; break;
688       case OPTION_MOVE  :  mnt.flag       |= MS_MOVE; break;
689       case OPTION_MTAB  :  opt.mtab        = optarg;  break;
690       case OPTION_FSTAB :  opt.fstab       = optarg;  break;
691       case OPTION_CHROOT:  opt.do_chroot   = true;    break;
692       case OPTION_ROOTFS:  opt.rootfs      = parseRootFS(optarg); break;
693       case OPTION_SECURE:
694         WRITE_MSG(2, "secure-mount: The '--secure' option is deprecated...\n");
695         break;
696       default           :
697         WRITE_MSG(2, "Try '");
698         WRITE_STR(2, argv[0]);
699         WRITE_MSG(2, " --help' for more information.\n");
700         return EXIT_FAILURE;
701         break;
702     }
703   }
704
705
706   if (opt.mount_all && optind<argc) {
707     WRITE_MSG(2, "Can not specify <src> and '-a' at the same time\n");
708     return EXIT_FAILURE;
709   }
710
711   initFDs(&opt);
712   signal(SIGCHLD, SIG_DFL);
713   
714   if (opt.mount_all) {
715     if (!mountFstab(&opt)) return EXIT_FAILURE;
716     else                   return EXIT_SUCCESS;
717   }
718
719   if (optind+2!=argc) {
720     WRITE_MSG(2, "Invalid <src> <dst> pair specified\n");
721     return EXIT_FAILURE;
722   }
723
724   if (mnt.data) {
725     mnt.data = strdup(mnt.data);
726     if (!transformOptionList(&mnt, 0)) {
727       WRITE_MSG(2, "Invalid options specified\n");
728       return EXIT_FAILURE;
729     }
730   }
731     
732   mnt.src  = argv[optind++];
733   mnt.dst  = argv[optind++];
734
735   if (!mountSingle(&mnt, &opt)) return EXIT_FAILURE;
736     
737   return EXIT_SUCCESS;
738 }