summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorrodrigc <rodrigc@FreeBSD.org>2005-11-16 02:47:12 +0000
committerrodrigc <rodrigc@FreeBSD.org>2005-11-16 02:47:12 +0000
commit3d724a19e420e0a62fbcb58bf82dfee3837147c9 (patch)
tree7d6ad39331f8f576fb97e74fff4f90891dfa514a /contrib
parentbda951e1164669108d22ffa80eec70c9ff1cfcf1 (diff)
downloadFreeBSD-src-3d724a19e420e0a62fbcb58bf82dfee3837147c9.zip
FreeBSD-src-3d724a19e420e0a62fbcb58bf82dfee3837147c9.tar.gz
Convert mount_smbfs to use nmount().
Reviewed by: bp (smbfs maintainer)
Diffstat (limited to 'contrib')
-rw-r--r--contrib/smbfs/mount_smbfs/getmntopts.c108
-rw-r--r--contrib/smbfs/mount_smbfs/mntopts.h109
-rw-r--r--contrib/smbfs/mount_smbfs/mount_smbfs.c111
3 files changed, 67 insertions, 261 deletions
diff --git a/contrib/smbfs/mount_smbfs/getmntopts.c b/contrib/smbfs/mount_smbfs/getmntopts.c
deleted file mode 100644
index 895b61c..0000000
--- a/contrib/smbfs/mount_smbfs/getmntopts.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/*-
- * Copyright (c) 1994
- * The Regents of the University of California. 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS 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 lint
-#if 0
-static char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95";
-#else
-static const char rcsid[] =
- "$Id: getmntopts.c,v 1.1 2000/03/29 01:26:41 bp Exp $";
-#endif
-#endif /* not lint */
-
-#include <sys/param.h>
-
-#include <err.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mntopts.h"
-
-int getmnt_silent = 0;
-
-void
-getmntopts(options, m0, flagp, altflagp)
- const char *options;
- const struct mntopt *m0;
- int *flagp;
- int *altflagp;
-{
- const struct mntopt *m;
- int negative, len;
- char *opt, *optbuf, *p;
- int *thisflagp;
-
- /* Copy option string, since it is about to be torn asunder... */
- if ((optbuf = strdup(options)) == NULL)
- err(1, NULL);
-
- for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
- /* Check for "no" prefix. */
- if (opt[0] == 'n' && opt[1] == 'o') {
- negative = 1;
- opt += 2;
- } else
- negative = 0;
-
- /*
- * for options with assignments in them (ie. quotas)
- * ignore the assignment as it's handled elsewhere
- */
- p = strchr(opt, '=');
- if (p)
- *++p = '\0';
-
- /* Scan option table. */
- for (m = m0; m->m_option != NULL; ++m) {
- len = strlen(m->m_option);
- if (strncasecmp(opt, m->m_option, len) == 0)
- if ( m->m_option[len] == '\0'
- || m->m_option[len] == '='
- )
- break;
- }
-
- /* Save flag, or fail if option is not recognized. */
- if (m->m_option) {
- thisflagp = m->m_altloc ? altflagp : flagp;
- if (negative == m->m_inverse)
- *thisflagp |= m->m_flag;
- else
- *thisflagp &= ~m->m_flag;
- } else if (!getmnt_silent) {
- errx(1, "-o %s: option not supported", opt);
- }
- }
-
- free(optbuf);
-}
diff --git a/contrib/smbfs/mount_smbfs/mntopts.h b/contrib/smbfs/mount_smbfs/mntopts.h
deleted file mode 100644
index c14b27c..0000000
--- a/contrib/smbfs/mount_smbfs/mntopts.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*-
- * Copyright (c) 1994
- * The Regents of the University of California. 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS 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.
- *
- * @(#)mntopts.h 8.7 (Berkeley) 3/29/95
- * $Id: mntopts.h,v 1.2 2001/08/22 03:32:52 bp Exp $
- */
-
-struct mntopt {
- const char *m_option; /* option name */
- int m_inverse; /* if a negative option, e.g. "dev" */
- int m_flag; /* bit to set, e.g. MNT_RDONLY */
- int m_altloc; /* 1 => set bit in altflags */
-};
-
-/* User-visible MNT_ flags. */
-#define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 }
-#ifndef APPLE
-#define MOPT_NOATIME { "atime", 1, MNT_NOATIME, 0 }
-#endif
-#define MOPT_NODEV { "dev", 1, MNT_NODEV, 0 }
-#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 }
-#define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 }
-#ifndef APPLE
-#define MOPT_NOSYMFOLLOW { "symfollow", 1, MNT_NOSYMFOLLOW, 0 }
-#endif
-#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY, 0 }
-#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 }
-#define MOPT_UNION { "union", 0, MNT_UNION, 0 }
-#define MOPT_USERQUOTA { "userquota", 0, 0, 0 }
-#define MOPT_GROUPQUOTA { "groupquota", 0, 0, 0 }
-#ifndef APPLE
-#define MOPT_NOCLUSTERR { "clusterr", 1, MNT_NOCLUSTERR, 0 }
-#define MOPT_NOCLUSTERW { "clusterw", 1, MNT_NOCLUSTERW, 0 }
-#define MOPT_SUIDDIR { "suiddir", 0, MNT_SUIDDIR, 0 }
-#endif
-
-/* Control flags. */
-#define MOPT_FORCE { "force", 0, MNT_FORCE, 0 }
-#define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 }
-#define MOPT_RO { "ro", 0, MNT_RDONLY, 0 }
-#define MOPT_RW { "rw", 1, MNT_RDONLY, 0 }
-
-/* This is parsed by mount(8), but is ignored by specific mount_*(8)s. */
-#define MOPT_AUTO { "auto", 0, 0, 0 }
-
-#define MOPT_FSTAB_COMPAT \
- MOPT_RO, \
- MOPT_RW, \
- MOPT_AUTO
-
-/* Standard options which all mounts can understand. */
-#ifdef APPLE
-#define MOPT_STDOPTS \
- MOPT_USERQUOTA, \
- MOPT_GROUPQUOTA, \
- MOPT_FSTAB_COMPAT, \
- MOPT_NODEV, \
- MOPT_NOEXEC, \
- MOPT_NOSUID, \
- MOPT_RDONLY, \
- MOPT_UNION
-#else
-#define MOPT_STDOPTS \
- MOPT_USERQUOTA, \
- MOPT_GROUPQUOTA, \
- MOPT_FSTAB_COMPAT, \
- MOPT_NOATIME, \
- MOPT_NODEV, \
- MOPT_NOEXEC, \
- MOPT_SUIDDIR, /* must be before MOPT_NOSUID */ \
- MOPT_NOSUID, \
- MOPT_NOSYMFOLLOW, \
- MOPT_RDONLY, \
- MOPT_UNION, \
- MOPT_NOCLUSTERR, \
- MOPT_NOCLUSTERW
-#endif /* APPLE */
-
-void getmntopts __P((const char *, const struct mntopt *, int *, int *));
-extern int getmnt_silent;
diff --git a/contrib/smbfs/mount_smbfs/mount_smbfs.c b/contrib/smbfs/mount_smbfs/mount_smbfs.c
index 487e9cd..1c0d6f7 100644
--- a/contrib/smbfs/mount_smbfs/mount_smbfs.c
+++ b/contrib/smbfs/mount_smbfs/mount_smbfs.c
@@ -63,15 +63,17 @@ static void usage(void);
static struct mntopt mopts[] = {
MOPT_STDOPTS,
- { NULL, 0, 0, 0 }
+ MOPT_END
};
+static char smbfs_vfsname[] = "smbfs";
int
main(int argc, char *argv[])
{
+ struct iovec *iov;
+ unsigned int iovlen;
struct smb_ctx sctx, *ctx = &sctx;
- struct smbfs_args mdata;
struct stat st;
#ifdef APPLE
extern void dropsuid();
@@ -80,8 +82,20 @@ main(int argc, char *argv[])
struct xvfsconf vfc;
#endif
char *next;
- int opt, error, mntflags, caseopt;
+ int opt, error, mntflags, caseopt, dev;
+ uid_t uid;
+ gid_t gid;
+ mode_t dir_mode, file_mode;
+ char errmsg[255] = { 0 };
+ iov = NULL;
+ iovlen = 0;
+ dev = 0;
+ uid = -1;
+ gid = -1;
+ caseopt = 0;
+ file_mode = 0;
+ dir_mode = 0;
#ifdef APPLE
dropsuid();
@@ -89,10 +103,6 @@ main(int argc, char *argv[])
if (argc == 2) {
if (strcmp(argv[1], "-h") == 0) {
usage();
- } else if (strcmp(argv[1], "-v") == 0) {
- errx(EX_OK, "version %d.%d.%d", SMBFS_VERSION / 100000,
- (SMBFS_VERSION % 10000) / 1000,
- (SMBFS_VERSION % 1000) / 100);
}
}
if (argc < 3)
@@ -101,11 +111,11 @@ main(int argc, char *argv[])
#ifdef APPLE
error = loadsmbvfs();
#else
- error = getvfsbyname(SMBFS_VFSNAME, &vfc);
+ error = getvfsbyname(smbfs_vfsname, &vfc);
if (error) {
- if (kldload(SMBFS_VFSNAME) < 0)
- err(EX_OSERR, "kldload("SMBFS_VFSNAME")");
- error = getvfsbyname(SMBFS_VFSNAME, &vfc);
+ if (kldload(smbfs_vfsname) < 0)
+ err(EX_OSERR, "kldload(%s)", smbfs_vfsname);
+ error = getvfsbyname(smbfs_vfsname, &vfc);
}
#endif
if (error)
@@ -115,8 +125,8 @@ main(int argc, char *argv[])
exit(1);
mntflags = error = 0;
- bzero(&mdata, sizeof(mdata));
- mdata.uid = mdata.gid = -1;
+ uid = gid = -1;
+
caseopt = SMB_CS_NONE;
if (smb_ctx_init(ctx, argc, argv, SMBL_SHARE, SMBL_SHARE, SMB_ST_DISK) != 0)
@@ -140,7 +150,7 @@ main(int argc, char *argv[])
getpwuid(atoi(optarg)) : getpwnam(optarg);
if (pwd == NULL)
errx(EX_NOUSER, "unknown user '%s'", optarg);
- mdata.uid = pwd->pw_uid;
+ uid = pwd->pw_uid;
break;
}
case 'g': {
@@ -150,18 +160,18 @@ main(int argc, char *argv[])
getgrgid(atoi(optarg)) : getgrnam(optarg);
if (grp == NULL)
errx(EX_NOUSER, "unknown group '%s'", optarg);
- mdata.gid = grp->gr_gid;
+ gid = grp->gr_gid;
break;
}
case 'd':
errno = 0;
- mdata.dir_mode = strtol(optarg, &next, 8);
+ 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);
+ file_mode = strtol(optarg, &next, 8);
if (errno || *next != 0)
errx(EX_DATAERR, "invalid value for file mode");
break;
@@ -173,10 +183,13 @@ main(int argc, char *argv[])
nsp = inp = optarg;
while ((nsp = strsep(&inp, ",;:")) != NULL) {
- if (strcasecmp(nsp, "LONG") == 0)
- mdata.flags |= SMBFS_MOUNT_NO_LONG;
- else
- errx(EX_DATAERR, "unknown suboption '%s'", nsp);
+ if (strcasecmp(nsp, "LONG") == 0) {
+ build_iovec(&iov, &iovlen,
+ "nolong", NULL, 0);
+ } else {
+ errx(EX_DATAERR,
+ "unknown suboption '%s'", nsp);
+ }
}
break;
};
@@ -218,31 +231,31 @@ main(int argc, char *argv[])
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 (uid == (size_t)-1)
+ uid = st.st_uid;
+ if (gid == (size_t)-1)
+ gid = st.st_gid;
+ if (file_mode == 0 )
+ file_mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
+ if (dir_mode == 0) {
+ dir_mode = file_mode;
+ if (dir_mode & S_IRUSR)
+ dir_mode |= S_IXUSR;
+ if (dir_mode & S_IRGRP)
+ dir_mode |= S_IXGRP;
+ if (dir_mode & S_IROTH)
+ dir_mode |= S_IXOTH;
}
/*
* For now, let connection be private for this mount
*/
ctx->ct_ssn.ioc_opt |= SMBVOPT_PRIVATE;
ctx->ct_ssn.ioc_owner = ctx->ct_sh.ioc_owner = 0; /* root */
- ctx->ct_ssn.ioc_group = ctx->ct_sh.ioc_group = mdata.gid;
+ ctx->ct_ssn.ioc_group = ctx->ct_sh.ioc_group = gid;
opt = 0;
- if (mdata.dir_mode & S_IXGRP)
+ if (dir_mode & S_IXGRP)
opt |= SMBM_EXECGRP;
- if (mdata.dir_mode & S_IXOTH)
+ if (dir_mode & S_IXOTH)
opt |= SMBM_EXECOTH;
ctx->ct_ssn.ioc_rights |= opt;
ctx->ct_sh.ioc_rights |= opt;
@@ -253,14 +266,24 @@ main(int argc, char *argv[])
if (error) {
exit(1);
}
- strcpy(mdata.mount_point,mount_point);
- mdata.version = SMBFS_VERSION;
- mdata.dev = ctx->ct_fd;
- mdata.caseopt = caseopt;
- error = mount(SMBFS_VFSNAME, mdata.mount_point, mntflags, (void*)&mdata);
+
+ dev = ctx->ct_fd;
+
+ build_iovec(&iov, &iovlen, "fstype", strdup("smbfs"), -1);
+ build_iovec(&iov, &iovlen, "fspath", mount_point, -1);
+ build_iovec_argf(&iov, &iovlen, "dev", "%d", dev);
+ build_iovec(&iov, &iovlen, "mountpoint", mount_point, -1);
+ build_iovec_argf(&iov, &iovlen, "uid", "%d", uid);
+ build_iovec_argf(&iov, &iovlen, "gid", "%d", gid);
+ build_iovec_argf(&iov, &iovlen, "file_mode", "%d", file_mode);
+ build_iovec_argf(&iov, &iovlen, "dir_mode", "%d", dir_mode);
+ build_iovec_argf(&iov, &iovlen, "caseopt", "%d", caseopt);
+ build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof errmsg);
+
+ error = nmount(iov, iovlen, mntflags);
smb_ctx_done(ctx);
if (error) {
- smb_error("mount error: %s", error, mdata.mount_point);
+ smb_error("mount error: %s %s", error, mount_point, errmsg);
exit(1);
}
return 0;
OpenPOWER on IntegriCloud