mount.c revision 2f5e3e911e1b9131c50e30d6887ed0c4e36f300c
/*
* 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 <sysexits.h>
#include <libintl.h>
#include <locale.h>
#include <libscf.h>
#include <cflib.h>
#include "mntopts.h"
static void usage(void);
static int setsubopt(int, char *, struct smbfs_args *);
/* smbfs options */
#define MNTOPT_RETRY "retry"
#define MNTOPT_TIMEOUT "timeout"
#define MNTOPT_DIRPERMS "dirperms"
#define MNTOPT_FILEPERMS "fileperms"
#define MNTOPT_GID "gid"
#define MNTOPT_UID "uid"
#define MNTOPT_NOPROMPT "noprompt"
#define OPT_RETRY 1
#define OPT_TIMEOUT 2
#define OPT_DIRPERMS 3
#define OPT_FILEPERMS 4
#define OPT_GID 5
#define OPT_UID 6
#define OPT_NOPROMPT 7
/* generic VFS options */
#define OPT_RO 10
#define OPT_RW 11
#define OPT_SUID 12
#define OPT_NOSUID 13
#define OPT_DEVICES 14
#define OPT_NODEVICES 15
#define OPT_SETUID 16
#define OPT_NOSETUID 17
#define OPT_EXEC 18
#define OPT_NOEXEC 19
struct smbfsopts {
char *name;
int index;
};
{MNTOPT_GID, OPT_GID},
{MNTOPT_UID, OPT_UID},
{MNTOPT_SUID, OPT_SUID},
{MNTOPT_EXEC, OPT_EXEC},
{NULL, 0}
};
static int Oflg = 0; /* Overlay mounts */
static int qflg = 0; /* quiet - don't print warnings on bad options */
static int ro = 0; /* read-only mount */
static int noprompt = 0; /* don't prompt for password */
static int retry = -1;
static int timeout = -1;
#define RET_ERR 33
int
{
struct smbfs_args mdata;
char optbuf[MAX_MNTOPT_STR];
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);
exit(1);
}
/* Debugging support. */
if (smb_debug < 1)
smb_debug = 1;
}
error = smb_lib_init();
if (error)
if (error)
if (error)
switch (opt) {
case 'O':
Oflg++;
break;
case 'q':
qflg++;
break;
case 'r':
ro++;
break;
case 'o': {
int i, ret;
if (!qflg)
"option string too long"));
}
if (comma) {
*comma = '\0';
} else
if (equals) {
*equals = '\0';
} else
break;
}
if (equals)
*equals = '=';
if (!qflg)
"Bad option '%s'"), sopt);
if (comma)
*comma = ',';
continue;
}
if (ret != 0)
if (equals)
*equals = '=';
if (comma)
*comma = ',';
}
break;
}
case '?':
default:
usage();
}
}
if (Oflg)
mntflags |= MS_OVERLAY;
if (ro) {
char *p;
/* convert "rw"->"ro" */
if (*(p+2) == ',' || *(p+2) == '\0')
*(p+1) = 'o';
}
}
optind++;
usage();
}
/*
* Fill in mdata defaults.
*/
}
/*
* XXX: The driver can fill these in more reliably,
* so why do we set them here? (Just set both = -1)
*/
opt = 0;
opt |= SMBM_EXECGRP;
opt |= SMBM_EXECOTH;
if (noprompt)
if (retry != -1)
if (timeout != -1)
/*
* If we got our password from the keychain and get an
* authorization error, we come back here to obtain a new
* password from user input.
*/
if (error)
goto again; /* try again using share name as given */
}
goto reauth;
}
if (error)
mntp->mnt_mountp);
} else {
mntp->mnt_mountp);
else
mntp->mnt_special);
if (error) /* unable to clean up?! */
}
}
if (error) {
}
return (0);
}
int
{
long l;
int err = 0;
char *next;
switch (index) {
case OPT_RO:
case OPT_RW:
case OPT_SUID:
case OPT_NOSUID:
case OPT_DEVICES:
case OPT_NODEVICES:
case OPT_SETUID:
case OPT_NOSETUID:
case OPT_EXEC:
case OPT_NOEXEC:
/* We don't have to handle generic options here */
return (0);
case OPT_UID:
if (!qflg)
err = -1;
} else {
}
break;
case OPT_GID:
if (!qflg)
err = -1;
} else {
}
break;
case OPT_DIRPERMS:
errno = 0;
if (!qflg)
"invalid value for directory mode"));
err = -1;
} else {
}
break;
case OPT_FILEPERMS:
errno = 0;
if (!qflg)
err = -1;
} else {
}
break;
case OPT_RETRY:
break;
case OPT_TIMEOUT:
break;
case OPT_NOPROMPT:
noprompt++;
}
return (err);
}
static void
usage(void)
{
gettext("usage: mount -F smbfs [-Orq] [-o option[,option]]"
" //[workgroup;][user[:password]@]server[/share] path"));
}