Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/dist/smbfs/mount_smbfs Make mount_smbfs follow the standard ...



details:   https://anonhg.NetBSD.org/src/rev/a1296449d3f4
branches:  trunk
changeset: 747172:a1296449d3f4
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Sep 04 18:22:37 2009 +0000

description:
Make mount_smbfs follow the standard MOUNT_NOMAIN and parseargs() structure.
(yes, this is dist, but considering the last and only import from
upstream was 7 years ago, I'm not exactly worried this will make
importing future versions harder)

diffstat:

 dist/smbfs/mount_smbfs/mount_smbfs.c |  111 +++++++++++++++++++++-------------
 dist/smbfs/mount_smbfs/mount_smbfs.h |   37 +++++++++++
 2 files changed, 105 insertions(+), 43 deletions(-)

diffs (260 lines):

diff -r e2fbe945f865 -r a1296449d3f4 dist/smbfs/mount_smbfs/mount_smbfs.c
--- a/dist/smbfs/mount_smbfs/mount_smbfs.c      Fri Sep 04 18:14:41 2009 +0000
+++ b/dist/smbfs/mount_smbfs/mount_smbfs.c      Fri Sep 04 18:22:37 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mount_smbfs.c,v 1.9 2007/07/14 16:03:05 dsl Exp $ */
+/* $NetBSD: mount_smbfs.c,v 1.10 2009/09/04 18:22:37 pooka Exp $ */
 
 /*
  * Copyright (c) 2000-2002, Boris Popov
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: mount_smbfs.c,v 1.9 2007/07/14 16:03:05 dsl Exp $");
+__RCSID("$NetBSD: mount_smbfs.c,v 1.10 2009/09/04 18:22:37 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -61,6 +61,8 @@
 
 #include <fs/smbfs/smbfs.h>
 
+#include "mount_smbfs.h"
+
 #include "mntopts.h"
 
 static void usage(void);
@@ -70,16 +72,25 @@
        { NULL, 0, 0, 0 }
 };
 
-
+#ifndef MOUNT_NOMAIN
 int
 main(int argc, char *argv[])
 {
-       struct smb_ctx sctx, *ctx = &sctx;
-       struct smbfs_args mdata;
+
+       setprogname(argv[0]);
+       return mount_smbfs(argc, argv);
+}
+#endif
+
+struct smb_ctx sctx;
+void
+mount_smbfs_parseargs(int argc, char *argv[], struct smbfs_args *mdatap,
+       int *mntflagsp, char *canon_dev, char *mount_point)
+{
+       struct smb_ctx *ctx = &sctx;
        struct stat st;
        char *next;
-       int opt, error, mntflags, caseopt;
-       char mount_point[MAXPATHLEN + 1];
+       int opt, error, caseopt;
 
        if (argc == 2) {
                if (strcmp(argv[1], "-h") == 0) {
@@ -96,9 +107,9 @@
        if (smb_lib_init() != 0)
                exit(1);
 
-       mntflags = error = 0;
-       bzero(&mdata, sizeof(mdata));
-       mdata.uid = mdata.gid = -1;
+       *mntflagsp = error = 0;
+       memset(mdatap, 0, sizeof(*mdatap));
+       mdatap->uid = mdatap->gid = -1;
        caseopt = SMB_CS_NONE;
 
        if (smb_ctx_init(ctx, argc, argv, SMBL_SHARE, SMBL_SHARE, SMB_ST_DISK) != 0)
@@ -122,7 +133,7 @@
                            getpwuid(atoi(optarg)) : getpwnam(optarg);
                        if (pwd == NULL)
                                errx(EX_NOUSER, "unknown user '%s'", optarg);
-                       mdata.uid = pwd->pw_uid;
+                       mdatap->uid = pwd->pw_uid;
                        break;
                    }
                    case 'g': {
@@ -132,18 +143,18 @@
                            getgrgid(atoi(optarg)) : getgrnam(optarg);
                        if (grp == NULL)
                                errx(EX_NOUSER, "unknown group '%s'", optarg);
-                       mdata.gid = grp->gr_gid;
+                       mdatap->gid = grp->gr_gid;
                        break;
                    }
                    case 'd':
                        errno = 0;
-                       mdata.dir_mode = strtol(optarg, &next, 8);
+                       mdatap->dir_mode = strtol(optarg, &next, 8);
                        if (errno || *next != 0)
                                errx(EX_DATAERR, "invalid value for directory mode");
                        break;
                    case 'f':
                        errno = 0;
-                       mdata.file_mode = strtol(optarg, &next, 8);
+                       mdatap->file_mode = strtol(optarg, &next, 8);
                        if (errno || *next != 0)
                                errx(EX_DATAERR, "invalid value for file mode");
                        break;
@@ -156,14 +167,14 @@
                        nsp = inp = optarg;
                        while ((nsp = strsep(&inp, ",;:")) != NULL) {
                                if (strcasecmp(nsp, "LONG") == 0)
-                                       mdata.flags |= SMBFS_MOUNT_NO_LONG;
+                                       mdatap->flags |= SMBFS_MOUNT_NO_LONG;
                                else
                                        errx(EX_DATAERR, "unknown suboption '%s'", nsp);
                        }
                        break;
                    };
                    case 'o':
-                       getmntopts(optarg, mopts, &mntflags, 0);
+                       getmntopts(optarg, mopts, mntflagsp, 0);
                        break;
                    case 'c':
                        switch (optarg[0]) {
@@ -185,7 +196,7 @@
 
        if (optind == argc - 2)
                optind++;
-       
+
        if (optind != argc - 1)
                usage();
        realpath(argv[optind], mount_point);
@@ -200,20 +211,20 @@
        if (smb_getextattr(mount_point, &einfo) == 0)
                errx(EX_OSERR, "can't mount on %s twice", mount_point);
 */
-       if (mdata.uid == (uid_t)-1)
-               mdata.uid = st.st_uid;
-       if (mdata.gid == (gid_t)-1)
-               mdata.gid = st.st_gid;
-       if (mdata.file_mode == 0 )
-               mdata.file_mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
-       if (mdata.dir_mode == 0) {
-               mdata.dir_mode = mdata.file_mode;
-               if (mdata.dir_mode & S_IRUSR)
-                       mdata.dir_mode |= S_IXUSR;
-               if (mdata.dir_mode & S_IRGRP)
-                       mdata.dir_mode |= S_IXGRP;
-               if (mdata.dir_mode & S_IROTH)
-                       mdata.dir_mode |= S_IXOTH;
+       if (mdatap->uid == (uid_t)-1)
+               mdatap->uid = st.st_uid;
+       if (mdatap->gid == (gid_t)-1)
+               mdatap->gid = st.st_gid;
+       if (mdatap->file_mode == 0 )
+               mdatap->file_mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
+       if (mdatap->dir_mode == 0) {
+               mdatap->dir_mode = mdatap->file_mode;
+               if (mdatap->dir_mode & S_IRUSR)
+                       mdatap->dir_mode |= S_IXUSR;
+               if (mdatap->dir_mode & S_IRGRP)
+                       mdatap->dir_mode |= S_IXGRP;
+               if (mdatap->dir_mode & S_IROTH)
+                       mdatap->dir_mode |= S_IXOTH;
        }
        /*
         * For now, let connection be private for this mount
@@ -222,29 +233,43 @@
        if (getuid() == 0)
                ctx->ct_ssn.ioc_owner = ctx->ct_sh.ioc_owner = 0; /* root */
        else
-               ctx->ct_ssn.ioc_owner = ctx->ct_sh.ioc_owner = mdata.uid;
-       ctx->ct_ssn.ioc_group = ctx->ct_sh.ioc_group = mdata.gid;
+               ctx->ct_ssn.ioc_owner = ctx->ct_sh.ioc_owner = mdatap->uid;
+       ctx->ct_ssn.ioc_group = ctx->ct_sh.ioc_group = mdatap->gid;
        opt = 0;
-       if (mdata.dir_mode & S_IXGRP)
+       if (mdatap->dir_mode & S_IXGRP)
                opt |= SMBM_EXECGRP;
-       if (mdata.dir_mode & S_IXOTH)
+       if (mdatap->dir_mode & S_IXOTH)
                opt |= SMBM_EXECOTH;
        ctx->ct_ssn.ioc_rights |= opt;
        ctx->ct_sh.ioc_rights |= opt;
        error = smb_ctx_resolve(ctx);
        if (error)
-               exit(1);
+               err(1, "resolve %d", error);
        error = smb_ctx_lookup(ctx, SMBL_SHARE, SMBLK_CREATE);
        if (error) {
-               exit(1);
+               err(1, "lookup %d", error);
        }
-       mdata.version = SMBFS_VERSION;
-       mdata.dev_fd = ctx->ct_fd;
-       mdata.caseopt = caseopt;
-       error = mount(SMBFS_VFSNAME, mount_point, mntflags, (void*)&mdata, sizeof mdata);
-       smb_ctx_done(ctx);
+       mdatap->version = SMBFS_VERSION;
+       mdatap->dev_fd = ctx->ct_fd;
+       mdatap->caseopt = caseopt;
+}
+
+int
+mount_smbfs(int argc, char *argv[])
+{
+       char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
+       struct smbfs_args mdata;
+       int mntflags, error;
+
+       mount_smbfs_parseargs(argc, argv, &mdata, &mntflags,
+           canon_dev, canon_dir);
+
+       error = mount(SMBFS_VFSNAME, canon_dir, mntflags,
+           &mdata, sizeof mdata);
+       smb_ctx_done(&sctx); /* XXX */
+
        if (error) {
-               smb_error("mount error for %s: %s", error, mount_point,
+               smb_error("mount error for %s: %s", error, canon_dir,
                        strerror(errno));
                exit(1);
        }
diff -r e2fbe945f865 -r a1296449d3f4 dist/smbfs/mount_smbfs/mount_smbfs.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/dist/smbfs/mount_smbfs/mount_smbfs.h      Fri Sep 04 18:22:37 2009 +0000
@@ -0,0 +1,37 @@
+/*     $NetBSD: mount_smbfs.h,v 1.1 2009/09/04 18:22:37 pooka Exp $    */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SBIN_MOUNT_SMBFS_MOUNT_SMBFS_H_
+#define _SBIN_MOUNT_SMBFS_MOUNT_SMBFS_H_
+
+#include <fs/smbfs/smbfs.h>
+
+int    mount_smbfs(int, char **);
+void   mount_smbfs_parseargs(int, char **, struct smbfs_args *, int *,
+                             char *, char *);
+
+#endif /* _SBIN_MOUNT_SMBFS_MOUNT_SMBFS_H_ */



Home | Main Index | Thread Index | Old Index