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