mount.c revision 02d09e03eb27f3a2dc299de704e45dae5173f43f
/*
* 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
* 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.28.44.2 2005/06/02 00:55:41 lindak Exp $
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <pwd.h>
#include <grp.h>
#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#include <err.h>
#include <libintl.h>
#include <locale.h>
#include <libscf.h>
/* This needs to know ctx->ct_dev_fd, etc. */
extern char *optarg;
extern int optind;
static void usage(void);
const char * const optlist[] = {
/* Generic VFS options. */
#define OPT_RO 0
#define OPT_RW 1
#define OPT_SUID 2
#define OPT_NOSUID 3
#define OPT_DEVICES 4
#define OPT_NODEVICES 5
#define OPT_SETUID 6
#define OPT_NOSETUID 7
#define OPT_EXEC 8
#define OPT_NOEXEC 9
#define OPT_XATTR 10
#define OPT_NOXATTR 11
/* Sort of generic (from NFS) */
#define OPT_NOAC 12
#define OPT_ACTIMEO 13
#define OPT_ACREGMIN 14
#define OPT_ACREGMAX 15
#define OPT_ACDIRMIN 16
#define OPT_ACDIRMAX 17
/* smbfs-specifis options */
#define OPT_DOMAIN 18
"domain",
#define OPT_USER 19
"user",
#define OPT_UID 20
"uid",
#define OPT_GID 21
"gid",
#define OPT_DIRPERMS 22
"dirperms",
#define OPT_FILEPERMS 23
"fileperms",
#define OPT_NOPROMPT 24
"noprompt",
};
static int Oflg = 0; /* Overlay mounts */
static int qflg = 0; /* quiet - don't print warnings on bad options */
static int noprompt = 0; /* don't prompt for password */
/* Note: smbfs uses _both_ kinds of options. */
#define EX_OK 0 /* normal */
struct smbfs_args mdata;
/*
* Initialize this with "rw" just to have something there,
* so we don't have to decide whether to add a comma when
* we strcat another option. Note the "rw" may be changed
* to an "ro" by option processing.
*/
int
{
static char *fstype = MNTTYPE_SMBFS;
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
if (argc == 2) {
usage();
SMBFS_VERSION / 100000,
}
}
if (argc < 3)
usage();
gettext("mount_smbfs: service \"%s\" not enabled.\n"),
SERVICE);
}
/* Debugging support. */
if (smb_debug < 1)
smb_debug = 1;
}
error = smb_lib_init();
if (error)
if (error)
/*
* Parse the UNC path so we have the server (etc.)
* that we need during rcfile+sharectl parsing.
*/
if (argc < 3)
usage();
if (error)
if (error)
switch (opt) {
case 'O':
Oflg++;
break;
case 'q':
qflg++;
break;
case 'r':
break;
case 'o': {
int ret;
if (comma) {
*comma = '\0';
} else
if (ret != 0)
/* undo changes to optarg */
if (comma)
*comma = ',';
}
break;
}
case '?':
default:
usage();
}
}
if (Oflg)
mntflags |= MS_OVERLAY;
char *p;
/* convert "rw"->"ro" */
if (*(p+2) == ',' || *(p+2) == '\0')
*(p+1) = 'o';
}
}
usage();
}
/*
* Fill in mdata defaults.
*/
}
if (noprompt)
/*
* Resolve the server address,
* setup derived defaults.
*/
if (error)
/*
* Have server, share, etc. from above:
* smb_ctx_scan_argv, option settings.
* Get the session and tree.
*/
if (err2 == 0)
goto again;
}
if (error) {
}
if (error) {
}
/*
* Have tree connection, now mount it.
*/
} else {
else
}
}
return (0);
}
int
{
long val;
int index;
char *p;
if (equals) {
*equals = '\0';
} else
break;
}
/*
* Note: if the option was unknown, index will
* point to the NULL at the end of optlist[],
* and we'll take the switch default.
*/
switch (index) {
case OPT_SUID:
case OPT_NOSUID:
case OPT_DEVICES:
case OPT_NODEVICES:
case OPT_SETUID:
case OPT_NOSETUID:
case OPT_EXEC:
case OPT_NOEXEC:
case OPT_XATTR:
case OPT_NOXATTR:
/*
* These options are handled via the
* generic option string mechanism.
* None of these take an optarg.
*/
goto badval;
sizeof (optbuf)) {
if (!qflg)
}
break;
/*
* OPT_RO, OPT_RW, are actually generic too,
* but we use the mntflags for these, and
* then update the options string later.
*/
case OPT_RO:
break;
case OPT_RW:
break;
/*
* NFS-derived options for attribute cache
*/
case OPT_NOAC:
break;
case OPT_ACTIMEO:
errno = 0;
if (errno || *p != 0)
goto badval;
break;
case OPT_ACREGMIN:
errno = 0;
if (errno || *p != 0)
goto badval;
break;
case OPT_ACREGMAX:
errno = 0;
if (errno || *p != 0)
goto badval;
break;
case OPT_ACDIRMIN:
errno = 0;
if (errno || *p != 0)
goto badval;
break;
case OPT_ACDIRMAX:
errno = 0;
if (errno || *p != 0)
goto badval;
break;
/*
* SMBFS-specific options. Some of these
* don't go through the mount system call,
* but just set libsmbfs options.
*/
case OPT_DOMAIN:
break;
case OPT_USER:
break;
case OPT_UID:
if (!qflg)
} else {
}
break;
case OPT_GID:
if (!qflg)
} else {
}
break;
case OPT_DIRPERMS:
errno = 0;
if (errno || *p != 0)
goto badval;
break;
case OPT_FILEPERMS:
errno = 0;
if (errno || *p != 0)
goto badval;
break;
case OPT_NOPROMPT:
noprompt++;
break;
default:
if (!qflg)
break;
if (!qflg)
break;
}
/* Undo changes made to subopt */
if (equals)
*equals = '=';
return (rc);
}
static void
usage(void)
{
gettext("usage: mount -F smbfs [-Orq] [-o option[,option]]"
" //[workgroup;][user[:password]@]server[/share] path"));
}