smb_dev.c revision 9c9af2590af49bb395bc8d2eace0f2d4ea16d165
/*
* 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: smb_dev.c,v 1.21 2004/12/13 00:25:18 lindak Exp $
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/sysmacros.h>
#include <sys/pathname.h>
#ifdef APPLE
#include <sys/smb_apple.h>
#else
#include <netsmb/smb_osdep.h>
#endif
#include <netsmb/smb_conn.h>
#include <netsmb/smb_subr.h>
#include <netsmb/smb_pass.h>
/* for version checks */
/*
* Userland code loops through minor #s 0 to 1023, looking for one which opens.
* Intially we create minor 0 and leave it for anyone. Minor zero will never
* actually get used - opening triggers creation of another (but private) minor,
* which userland code will get to and mark busy.
*/
#define SMBMINORS 1024
static void *statep;
static major_t nsmb_major;
#define ILP32 1
#define LP64 2
/* Zone support */
/*
* cb_ops device operations.
*/
/* smbfs cb_ops */
static struct cb_ops nsmb_cbops = {
nsmb_open, /* open */
nsmb_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
nsmb_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* prop_op */
NULL, /* stream */
D_MP, /* cb_flag */
CB_REV, /* rev */
nodev, /* int (*cb_aread)() */
nodev /* int (*cb_awrite)() */
};
/*
* Device options
*/
DEVO_REV, /* devo_rev, */
0, /* refcnt */
nsmb_getinfo, /* info */
nulldev, /* identify */
nulldev, /* probe */
nsmb_attach, /* attach */
nsmb_detach, /* detach */
nodev, /* reset */
&nsmb_cbops, /* driver ops - devctl interfaces */
NULL, /* bus operations */
NULL, /* power */
ddi_quiesce_not_needed, /* quiesce */
};
/*
* Module linkage information.
*/
static struct modldrv nsmb_modldrv = {
&mod_driverops, /* Driver module */
"SMBFS network driver v" NSMB_VER_STR,
&nsmb_ops /* Driver ops */
};
static struct modlinkage nsmb_modlinkage = {
(void *)&nsmb_modldrv,
};
int
_init(void)
{
int error;
/* Can initialize some mutexes also. */
/*
* Create a major name and number.
*/
nsmb_minor = 0;
/* Connection data structures. */
(void) smb_sm_init();
/* Initialize password Key chain DB. */
/* Initialize crypto mechanisms. */
/*
* Install the module. Do this after other init,
* to prevent entrances before we're ready.
*/
/* Same as 2nd half of _fini */
(void) zone_key_delete(nsmb_zone_key);
smb_sm_done();
return (error);
}
return (0);
}
int
_fini(void)
{
int status;
/*
* Prevent unload if we have active VCs
* or stored passwords
*/
if ((status = smb_sm_idle()) != 0)
return (status);
if ((status = smb_pkey_idle()) != 0)
return (status);
/*
* Remove the module. Do this before destroying things,
* to prevent new entrances while we're destorying.
*/
return (status);
}
(void) zone_key_delete(nsmb_zone_key);
/* Destroy password Key chain DB. */
smb_sm_done();
return (status);
}
int
{
}
/*ARGSUSED*/
static int
{
int ret = DDI_SUCCESS;
switch (cmd) {
case DDI_INFO_DEVT2DEVINFO:
*result = 0;
break;
case DDI_INFO_DEVT2INSTANCE:
*result = 0;
break;
default:
ret = DDI_FAILURE;
}
return (ret);
}
static int
{
if (cmd != DDI_ATTACH)
return (DDI_FAILURE);
/*
* only one instance - but we clone using the open routine
*/
if (ddi_get_instance(dip) > 0)
return (DDI_FAILURE);
/*
* This is the Zero'th minor device which is created.
*/
goto attach_failed;
}
NULL) == DDI_FAILURE) {
goto attach_failed;
}
goto attach_failed;
}
/*
* Need to see if this field is required.
* REVISIT
*/
return (DDI_SUCCESS);
return (DDI_FAILURE);
}
/*ARGSUSED*/
static int
{
if (cmd != DDI_DETACH)
return (DDI_FAILURE);
if (ddi_get_instance(dip) > 0)
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
/*ARGSUSED*/
static int
int cmd,
int mode,
int *rvalp)
{
/* Free any+all of these at end of switch. */
return (DDI_FAILURE);
}
return (EBADF);
}
/*
* Dont give access if the zone id is not as the same as we
* set in the nsmb_open or dont belong to the global zone.
* Check if the user belongs to this zone..
*/
return (EIO);
if (cmd != SMBIOC_TDIS &&
return (EIO);
error = 0;
switch (cmd) {
case SMBIOC_GETVERS:
sizeof (nsmb_version), mode);
break;
case SMBIOC_REQUEST:
break;
}
break;
}
break;
case SMBIOC_T2RQ:
break;
}
break;
}
break;
case SMBIOC_READ:
case SMBIOC_WRITE:
break;
}
break;
}
break;
case SMBIOC_FINDVC:
/* Should be no VC and no share */
break;
}
break;
}
if (error)
break;
if (vcp) {
/*
* The VC has a hold from _findvc
* which we keep until nsmb_close().
*/
}
break;
case SMBIOC_NEGOTIATE:
/* Should be no VC (and no share) */
break;
}
break;
}
if (error)
break;
if (vcp) {
/*
* The VC has a hold from _negotiate
* which we keep until nsmb_close().
*/
/*
* If we just created this VC, and
* this minor is doing the setup,
* keep track of that fact here.
*/
}
/*
* Copyout the "out token" (security blob).
*
* This code used to be near the end of
* smb_usr_negotiate(). Moved the copyout
* calls here so we know the "mode"
*/
/*
* Note: will copyout sioc below
* including sioc.vc_outtoklen,
* so we no longer put the length
* at the start of the outtok data.
*/
err = ddi_copyout(
if (err) {
break;
}
/*
* Save this blob in vc_negtok.
* We need it in case we have to
* reconnect.
*
* Set vc_negtok = vc_outtok
* but free vc_negtok first.
*/
vcp->vc_negtoklen);
vcp->vc_negtoklen = 0;
}
vcp->vc_outtoklen = 0;
}
/*
* Added copyout here of (almost)
* the whole struct, even though
* the lib only needs _outtoklen.
* We may put other things in this
* struct that user-land needs.
*/
if (err)
break;
case SMBIOC_SSNSETUP:
/* Must have a VC, but no share. */
break;
}
break;
}
break;
}
if (error)
break;
/*
* If this minor has finished ssn setup,
* turn off the NEWVC flag, otherwise we
* will kill this VC when we close.
*/
/*
* Copyout the "out token" (security blob).
*
* This code used to be near the end of
* smb_usr_ssnsetup(). Moved the copyout
* calls here so we know the "mode"
*/
/*
* Note: will copyout sioc below
* including sioc.vc_outtoklen,
* so we no longer put the length
* at the start of the outtok data.
*/
err = ddi_copyout(
if (err) {
break;
}
/*
* Done with vc_outtok. Similar,
* but NOT the same as after the
* smb_usr_negotiate call above.
*/
vcp->vc_outtoklen);
vcp->vc_outtoklen = 0;
}
/* Added copyout here... (see above) */
if (err)
break;
case SMBIOC_TCON:
/* Must have a VC, but no share. */
break;
}
break;
}
break;
}
if (error)
break;
if (ssp) {
/*
* The share has a hold from _tcon
* which we keep until nsmb_close()
* or the SMBIOC_TDIS below.
*/
}
/* No need for copyout here. */
break;
case SMBIOC_TDIS:
break;
}
break;
case SMBIOC_FLAGS2:
break;
}
break;
}
/*
* Return the flags2 value.
*/
break;
case SMBIOC_PK_ADD:
break;
}
break;
case SMBIOC_PK_DEL:
break;
}
break;
case SMBIOC_PK_CHK:
break;
}
/*
* Note: Intentionally DO NOT copyout
* the pasword here. It can only be
* retrieved by internal calls. This
* ioctl only tells the caller if the
* keychain entry exists.
*/
break;
case SMBIOC_PK_DEL_OWNER:
break;
case SMBIOC_PK_DEL_EVERYONE:
break;
default:
}
/*
* Let's just do all the kmem_free stuff HERE,
* instead of at every switch break.
*/
/* SMBIOC_REQUEST */
if (srq)
/* SMBIOC_T2RQ */
if (strq)
/* SMBIOC_READ */
/* SMBIOC_WRITE */
if (rwrq)
/* SMBIOC_FINDVC */
/* SMBIOC_NEGOTIATE */
/* SMBIOC_SSNSETUP */
/* SMBIOC_TCON */
if (sioc) {
/*
* This data structure may contain
* cleartext passwords, so zap it.
*/
}
/* SMBIOC_PK_... */
if (pk) {
/*
* This data structure may contain
* cleartext passwords, so zap it.
*/
}
return (error);
}
/*ARGSUSED*/
static int
{
for (; ; ) {
do {
if (nsmb_minor >= MAXMIN32) {
else
nsmb_minor = 0;
} else {
nsmb_minor++;
}
if (nsmb_minor == start) {
/*
* The condition we need to solve here is all the
* MAXMIN32(~262000) minors numbers are reached. We
* need to create a new major number.
* zfs uses getudev() to create a new major number.
*/
"nsmb: Can't get unique major "
"device number.");
return (-1);
}
nsmb_minor = 0;
} else {
break;
}
}
/*
* This is called by mount or open call.
* The open() routine is passed a pointer to a device number so
* that the driver can change the minor number. This allows
* drivers to dynamically create minor instances of the dev-
* ice. An example of this might be a pseudo-terminal driver
* that creates a new pseudo-terminal whenever it is opened.
* A driver that chooses the minor number dynamically, normally
* creates only one minor device node in attach(9E) with
* ddi_create_minor_node(9F) then changes the minor number com-
* ponent of *devp using makedevice(9F) and getmajor(9F) The
* driver needs to keep track of available minor numbers inter-
* nally.
* Stuff the structure smb_dev.
* return.
*/
return (ENXIO);
}
return (ENXIO);
}
return (0);
}
/*ARGSUSED*/
static int
{
/*
* 1. Check the validity of the minor number.
* 3. Can close the minor number.
* 4. Deallocate any resources allocated in open() call.
*/
/*
* time to call ddi_get_soft_state()
*/
/*
* If this dev minor was doing session setup
* and failed to authenticate (or whatever)
* then we need to put the VC in a state that
* allows later commands to try again.
*/
}
/*
* Free the instance
*/
return (0);
}
int
{
return (EBADF);
}
return (DDI_FAILURE);
}
return (ENOTCONN);
}
/*
* The share is already locked and referenced by the TCON ioctl
* We NULL to hand off share to caller (mount)
* This allows further ioctls against connection, for instance
* another tree connect and mount, in the automounter case
*
* We're effectively giving our reference to the mount.
*
* XXX: I'm not sure I like this. I'd rather see the ioctl
* caller do something explicit to give up this reference,
* (i.e. SMBIOC_TDIS above) and increment the hold here.
*/
return (0);
}