summaryrefslogtreecommitdiffstats
path: root/contrib/smbfs/mount_smbfs
diff options
context:
space:
mode:
authorsheldonh <sheldonh@FreeBSD.org>2001-12-14 11:06:03 +0000
committersheldonh <sheldonh@FreeBSD.org>2001-12-14 11:06:03 +0000
commit4e260b134ff188548ec2c8a16a37570a4abf1257 (patch)
tree672d7786f89ed3b67f221098cb86cf0bc53ad5e3 /contrib/smbfs/mount_smbfs
downloadFreeBSD-src-4e260b134ff188548ec2c8a16a37570a4abf1257.zip
FreeBSD-src-4e260b134ff188548ec2c8a16a37570a4abf1257.tar.gz
Import smbfs-1.4.1.
This is Boris Popov's SMB/CIFS file system implementation for FreeBSD. Obtained from: Boris Popov via ftp://ftp.butya.kz/pub/smbfs/
Diffstat (limited to 'contrib/smbfs/mount_smbfs')
-rw-r--r--contrib/smbfs/mount_smbfs/Makefile18
-rw-r--r--contrib/smbfs/mount_smbfs/getmntopts.c108
-rw-r--r--contrib/smbfs/mount_smbfs/mntopts.h91
-rw-r--r--contrib/smbfs/mount_smbfs/mount_smbfs.8158
-rw-r--r--contrib/smbfs/mount_smbfs/mount_smbfs.c265
5 files changed, 640 insertions, 0 deletions
diff --git a/contrib/smbfs/mount_smbfs/Makefile b/contrib/smbfs/mount_smbfs/Makefile
new file mode 100644
index 0000000..ffd79c9
--- /dev/null
+++ b/contrib/smbfs/mount_smbfs/Makefile
@@ -0,0 +1,18 @@
+# $Id: Makefile,v 1.7 2001/04/16 04:34:26 bp Exp $
+
+PROG= mount_smbfs
+SRCS= mount_smbfs.c getmntopts.c
+MAN8= mount_smbfs.8
+
+BINDIR= /sbin
+#NOSHARED=yes
+
+MOUNT= ${.CURDIR}/../mount
+CFLAGS+= -DSMBFS -I${MOUNT}
+
+.PATH: ${MOUNT}
+
+LDADD+= -lsmb
+DPADD+= ${LIBSMB}
+
+.include <bsd.prog.mk>
diff --git a/contrib/smbfs/mount_smbfs/getmntopts.c b/contrib/smbfs/mount_smbfs/getmntopts.c
new file mode 100644
index 0000000..895b61c
--- /dev/null
+++ b/contrib/smbfs/mount_smbfs/getmntopts.c
@@ -0,0 +1,108 @@
+/*-
+ * 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
new file mode 100644
index 0000000..5b6d52e
--- /dev/null
+++ b/contrib/smbfs/mount_smbfs/mntopts.h
@@ -0,0 +1,91 @@
+/*-
+ * 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.1 2000/03/29 01:26:41 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 }
+#define MOPT_NOATIME { "atime", 1, MNT_NOATIME, 0 }
+#define MOPT_NODEV { "dev", 1, MNT_NODEV, 0 }
+#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 }
+#define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 }
+#define MOPT_NOSYMFOLLOW { "symfollow", 1, MNT_NOSYMFOLLOW, 0 }
+#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 }
+#define MOPT_NOCLUSTERR { "clusterr", 1, MNT_NOCLUSTERR, 0 }
+#define MOPT_NOCLUSTERW { "clusterw", 1, MNT_NOCLUSTERW, 0 }
+#define MOPT_SUIDDIR { "suiddir", 0, MNT_SUIDDIR, 0 }
+
+/* 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. */
+#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
+
+void getmntopts __P((const char *, const struct mntopt *, int *, int *));
+extern int getmnt_silent;
diff --git a/contrib/smbfs/mount_smbfs/mount_smbfs.8 b/contrib/smbfs/mount_smbfs/mount_smbfs.8
new file mode 100644
index 0000000..b2c68d2
--- /dev/null
+++ b/contrib/smbfs/mount_smbfs/mount_smbfs.8
@@ -0,0 +1,158 @@
+.\" $Id: mount_smbfs.8,v 1.8 2000/06/09 13:52:56 bp Exp $
+.Dd Mar 10, 2000
+.Dt MOUNT_SMBFS 8
+.Os FreeBSD
+.Sh NAME
+.Nm mount_smbfs
+.Nd mounts a shared resource from an SMB file server
+.Sh SYNOPSIS
+.Nm mount_smbfs
+.Op Fl E Ar cs1:cs2
+.Op Fl I Ar host
+.Op Fl L Ar locale
+.Op Fl M Ar crights:srights
+.Op Fl N
+.Op Fl O Ar cowner:cgroup/sowner:sgroup
+.Op Fl R Ar retrycount
+.Op Fl T Ar timeout
+.Op Fl W Ar workgroup
+.Op Fl c Ar case
+.Op Fl d Ar mode
+.Op Fl f Ar mode
+.Op Fl g Ar gid
+.Op Fl n Ar opt
+.Op Fl u Ar uid
+.Ar //user@server/share
+.Ar node
+.Sh DESCRIPTION
+The
+.Nm
+command mounts a share from a remote server using SMB/CIFS protocol.
+.Pp
+The options are:
+.Bl -tag -width indent
+.It Fl E Ar cs1:cs2
+Specifies local
+.Ar (cs1)
+and server's
+.Ar (cs2)
+character sets.
+.It Fl I Ar host
+Do not use NetBIOS name resolver and connect directly to
+.Ar host ,
+which can be either a valid DNS name or an IP address.
+.It Fl L Ar locale
+Use
+.Ar locale
+for lower/upper case conversion routines.
+Set the locale for case conversion.
+By default
+.Nm
+tries to use an environment variable
+.Ev LC_*
+to determine it.
+.It Fl M Ar crights:srights
+Assign access rights to the newly created connection.
+See
+.Xr nsmb 8
+for theory.
+.It Fl N
+Do not ask for a password.
+At run time,
+.Nm
+reads the
+.Pa ~/.nsmbrc
+file for additional configuration parameters and a password.
+If no password is found the
+.Nm
+prompts for it.
+.It Fl O Ar cowner:cgroup/sowner:sgroup
+Assign owner/group attributes to the newly created connection.
+See
+.Xr nsmb 8
+for theory.
+.It Fl R Ar retrycount
+How many retries should be done before the SMB requester decides to drop
+the connection.
+.It Fl T Ar timeout
+Timeout in seconds for each request.
+.It Fl W Ar workgroup
+This option specifies the workgroup to be used in the authentication request.
+.It Fl c Ar case
+Set a
+.Ar case
+option which affects name representation.
+.Ar case
+can be one of the following:
+.Bl -tag -width "ValueXX"
+.It Em Value
+.Em Meaning
+.It l
+All existing file names converted to lower case.
+Newly created file gets a lower case.
+.It u
+All existing file names converted to upper case.
+Newly created file gets an upper case unde.
+.El
+.It Fl f Ar mode , Fl d Ar mode
+Specify permissions that should be assigned to files and directories.
+The values must be specified as octal numbers.
+Default value for the file mode
+is taken from mount point, default value for the dir mode adds execute
+permission where the file mode gives read permission.
+
+Note that these permissions can differ from the rights granted by SMB
+server.
+.It Fl u Ar uid , Fl g Ar gid
+User id and group id assigned to files.
+The default is owner and group id from
+directory where the volume is mounted.
+.It Ar //user@server/share
+The
+.Nm
+command will use
+.Ar server
+as the NetBIOS name of remote computer,
+.Ar user
+as the remote user name and
+.Ar share
+as the resource name on a remote server.
+.It Ar node
+Path to mount point.
+.El
+.Sh FILES
+.Bl -tag -width /var/log/wtmp -compact
+.It Pa ~/.nsmbrc
+Keeps static parameters for connections and other information.
+See
+.Pa ./examples/dot.nsmbrc
+for details.
+.El
+
+.Sh EXAMPLES
+The following examples illustrate how to connect to a SMB server
+.Em SAMBA
+as user
+.Em GUEST
+and mount shares
+.Em PUBLIC
+and
+.Em TMP :
+.Bd -literal -offset indent
+mount_smbfs -I samba.mydomain.com //guest@samba/public /smb/public
+mount_smbfs -I 192.168.20.3 -E koi8-r:cp866 //guest@samba/tmp /smb/tmp
+.Ed
+.Pp
+It is possible to use
+.Xr fstab 5
+for smbfs mounts:
+.Bd -literal -offset indent
+//guest@samba/public /smb/public smbfs rw,noauto 0 0
+.Ed
+
+.Sh BUGS
+Please report bugs to the author.
+
+.Sh AUTHORS
+.An Boris Popov Aq bp@butya.kz ,
+.Aq bp@freebsd.org
diff --git a/contrib/smbfs/mount_smbfs/mount_smbfs.c b/contrib/smbfs/mount_smbfs/mount_smbfs.c
new file mode 100644
index 0000000..3122bc4
--- /dev/null
+++ b/contrib/smbfs/mount_smbfs/mount_smbfs.c
@@ -0,0 +1,265 @@
+/*
+ * Copyright (c) 2000-2001, Boris Popov
+ * 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 Boris Popov.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 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.
+ *
+ * $Id: mount_smbfs.c,v 1.13 2001/04/16 12:46:46 bp Exp $
+ */
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/errno.h>
+#include <sys/mount.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <pwd.h>
+#include <grp.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <err.h>
+#include <sysexits.h>
+
+#include <cflib.h>
+
+#include <netsmb/smb.h>
+#include <netsmb/smb_conn.h>
+#include <netsmb/smb_lib.h>
+
+#include <fs/smbfs/smbfs.h>
+
+#include "mntopts.h"
+
+static char mount_point[MAXPATHLEN + 1];
+static void usage(void);
+
+static struct mntopt mopts[] = {
+ MOPT_STDOPTS,
+ { NULL }
+};
+
+
+int
+main(int argc, char *argv[])
+{
+ struct smb_ctx sctx, *ctx = &sctx;
+ struct smbfs_args mdata;
+ struct stat st;
+ struct vfsconf vfc;
+ char *next;
+ int opt, error, mntflags, caseopt;
+
+ 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)
+ usage();
+
+ error = getvfsbyname(SMBFS_VFSNAME, &vfc);
+ if (error && vfsisloadable(SMBFS_VFSNAME)) {
+ if(vfsload(SMBFS_VFSNAME))
+ err(EX_OSERR, "vfsload("SMBFS_VFSNAME")");
+ endvfsent();
+ error = getvfsbyname(SMBFS_VFSNAME, &vfc);
+ }
+ if (error)
+ errx(EX_OSERR, "SMB filesystem is not available");
+
+ if (smb_lib_init() != 0)
+ exit(1);
+
+ mntflags = error = 0;
+ bzero(&mdata, sizeof(mdata));
+ mdata.uid = mdata.gid = -1;
+ caseopt = SMB_CS_NONE;
+
+ if (smb_ctx_init(ctx, argc, argv, SMBL_SHARE, SMBL_SHARE, SMB_ST_DISK) != 0)
+ exit(1);
+ if (smb_ctx_readrc(ctx) != 0)
+ exit(1);
+ if (smb_rc)
+ rc_close(smb_rc);
+
+ while ((opt = getopt(argc, argv, STDPARAM_OPT"c:d:f:g:l:n:o:u:w:")) != -1) {
+ switch (opt) {
+ case STDPARAM_ARGS:
+ error = smb_ctx_opt(ctx, opt, optarg);
+ if (error)
+ exit(1);
+ break;
+ case 'u': {
+ struct passwd *pwd;
+
+ pwd = isdigit(optarg[0]) ?
+ getpwuid(atoi(optarg)) : getpwnam(optarg);
+ if (pwd == NULL)
+ errx(EX_NOUSER, "unknown user '%s'", optarg);
+ mdata.uid = pwd->pw_uid;
+ break;
+ }
+ case 'g': {
+ struct group *grp;
+
+ grp = isdigit(optarg[0]) ?
+ getgrgid(atoi(optarg)) : getgrnam(optarg);
+ if (grp == NULL)
+ errx(EX_NOUSER, "unknown group '%s'", optarg);
+ mdata.gid = grp->gr_gid;
+ break;
+ }
+ case 'd':
+ errno = 0;
+ mdata.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);
+ if (errno || *next != 0)
+ errx(EX_DATAERR, "invalid value for file mode");
+ break;
+ case '?':
+ usage();
+ /*NOTREACHED*/
+ case 'n': {
+ char *inp, *nsp;
+
+ 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);
+ }
+ break;
+ };
+ case 'o':
+ getmntopts(optarg, mopts, &mntflags, 0);
+ break;
+ case 'c':
+ switch (optarg[0]) {
+ case 'l':
+ caseopt |= SMB_CS_LOWER;
+ break;
+ case 'u':
+ caseopt |= SMB_CS_UPPER;
+ break;
+ default:
+ errx(EX_DATAERR, "invalid suboption '%c' for -c",
+ optarg[0]);
+ }
+ break;
+ default:
+ usage();
+ }
+ }
+
+ if (optind == argc - 2)
+ optind++;
+
+ if (optind != argc - 1)
+ usage();
+ realpath(argv[optind], mount_point);
+
+ if (stat(mount_point, &st) == -1)
+ err(EX_OSERR, "could not find mount point %s", mount_point);
+ if (!S_ISDIR(st.st_mode)) {
+ errno = ENOTDIR;
+ err(EX_OSERR, "can't mount on %s", mount_point);
+ }
+/*
+ if (smb_getextattr(mount_point, &einfo) == 0)
+ errx(EX_OSERR, "can't mount on %s twice", mount_point);
+*/
+ if (mdata.uid == -1)
+ mdata.uid = st.st_uid;
+ if (mdata.gid == -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;
+ }
+ /*
+ * 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;
+ opt = 0;
+ if (mdata.dir_mode & S_IXGRP)
+ opt |= SMBM_EXECGRP;
+ if (mdata.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);
+ error = smb_ctx_lookup(ctx, SMBL_SHARE, SMBLK_CREATE);
+ 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);
+ smb_ctx_done(ctx);
+ if (error) {
+ smb_error("mount error: %s", error, mdata.mount_point);
+ exit(1);
+ }
+ return 0;
+}
+
+static void
+usage(void)
+{
+ fprintf(stderr, "%s\n%s\n%s\n%s\n",
+ "usage: mount_smbfs [-Chv] [-U user] [-connection options]",
+ " [-M mode] [-c case] [-d mode] [-f mode]",
+ " [-g gid] [-l locale] [-n os2] [-u uid] [-w scheme]",
+ " /user@server/share node");
+
+ exit (1);
+}
OpenPOWER on IntegriCloud