2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
2017-11-27 15:23:17 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2001-04-10 07:59:06 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2003-06-11 05:37:42 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
2014-03-16 10:55:57 +00:00
|
|
|
#include <sys/capsicum.h>
|
2004-05-30 20:27:19 +00:00
|
|
|
#include <sys/module.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/systm.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/fcntl.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/ioccom.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/malloc.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/file.h> /* Must come after sys/malloc.h */
|
2003-01-01 01:56:19 +00:00
|
|
|
#include <sys/filedesc.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/mbuf.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/poll.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/select.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/socket.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/sysctl.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/uio.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <netsmb/smb.h>
|
|
|
|
#include <netsmb/smb_conn.h>
|
|
|
|
#include <netsmb/smb_subr.h>
|
|
|
|
#include <netsmb/smb_dev.h>
|
|
|
|
|
2013-05-04 14:03:18 +00:00
|
|
|
static struct cdev *nsmb_dev;
|
2001-04-10 07:59:06 +00:00
|
|
|
|
|
|
|
static d_open_t nsmb_dev_open;
|
|
|
|
static d_ioctl_t nsmb_dev_ioctl;
|
|
|
|
|
2003-09-26 20:26:25 +00:00
|
|
|
MODULE_DEPEND(netsmb, libiconv, 1, 1, 2);
|
2001-04-10 07:59:06 +00:00
|
|
|
MODULE_VERSION(netsmb, NSMB_VERSION);
|
|
|
|
|
|
|
|
static int smb_version = NSMB_VERSION;
|
2013-05-04 14:03:18 +00:00
|
|
|
struct sx smb_lock;
|
2001-04-10 07:59:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
SYSCTL_DECL(_net_smb);
|
|
|
|
SYSCTL_INT(_net_smb, OID_AUTO, version, CTLFLAG_RD, &smb_version, 0, "");
|
|
|
|
|
|
|
|
static MALLOC_DEFINE(M_NSMBDEV, "NETSMBDEV", "NET/SMB device");
|
|
|
|
|
|
|
|
static struct cdevsw nsmb_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = nsmb_dev_open,
|
|
|
|
.d_ioctl = nsmb_dev_ioctl,
|
2004-02-11 12:49:49 +00:00
|
|
|
.d_name = NSMB_NAME
|
2001-04-10 07:59:06 +00:00
|
|
|
};
|
|
|
|
|
2013-05-04 14:03:18 +00:00
|
|
|
static int
|
|
|
|
nsmb_dev_init(void)
|
2001-04-10 07:59:06 +00:00
|
|
|
{
|
|
|
|
|
2013-05-04 14:03:18 +00:00
|
|
|
nsmb_dev = make_dev(&nsmb_cdevsw, 0, UID_ROOT, GID_OPERATOR,
|
|
|
|
0600, "nsmb");
|
|
|
|
if (nsmb_dev == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
return (0);
|
|
|
|
}
|
2008-11-03 14:23:15 +00:00
|
|
|
|
2013-05-04 14:03:18 +00:00
|
|
|
static void
|
|
|
|
nsmb_dev_destroy(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
MPASS(nsmb_dev != NULL);
|
|
|
|
destroy_dev(nsmb_dev);
|
|
|
|
nsmb_dev = NULL;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 14:03:18 +00:00
|
|
|
static struct smb_dev *
|
|
|
|
smbdev_alloc(struct cdev *dev)
|
2001-04-10 07:59:06 +00:00
|
|
|
{
|
|
|
|
struct smb_dev *sdp;
|
2013-05-04 14:03:18 +00:00
|
|
|
|
|
|
|
sdp = malloc(sizeof(struct smb_dev), M_NSMBDEV, M_WAITOK | M_ZERO);
|
|
|
|
sdp->dev = dev;
|
2001-04-10 07:59:06 +00:00
|
|
|
sdp->sd_level = -1;
|
|
|
|
sdp->sd_flags |= NSMBFL_OPEN;
|
2013-05-04 14:03:18 +00:00
|
|
|
sdp->refcount = 1;
|
|
|
|
return (sdp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sdp_dtor(void *arg)
|
|
|
|
{
|
|
|
|
struct smb_dev *dev;
|
|
|
|
|
|
|
|
dev = (struct smb_dev *)arg;
|
|
|
|
SMB_LOCK();
|
|
|
|
sdp_trydestroy(dev);
|
|
|
|
SMB_UNLOCK();
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-05-04 14:03:18 +00:00
|
|
|
nsmb_dev_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
|
2001-04-10 07:59:06 +00:00
|
|
|
{
|
|
|
|
struct smb_dev *sdp;
|
2013-05-04 14:03:18 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
sdp = smbdev_alloc(dev);
|
|
|
|
error = devfs_set_cdevpriv(sdp, sdp_dtor);
|
|
|
|
if (error) {
|
|
|
|
free(sdp, M_NSMBDEV);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sdp_trydestroy(struct smb_dev *sdp)
|
|
|
|
{
|
2001-04-10 07:59:06 +00:00
|
|
|
struct smb_vc *vcp;
|
|
|
|
struct smb_share *ssp;
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
|
2013-05-04 14:03:18 +00:00
|
|
|
SMB_LOCKASSERT();
|
|
|
|
if (!sdp)
|
|
|
|
panic("No smb_dev upon device close");
|
|
|
|
MPASS(sdp->refcount > 0);
|
|
|
|
sdp->refcount--;
|
|
|
|
if (sdp->refcount)
|
|
|
|
return;
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = malloc(sizeof(struct smb_cred), M_NSMBDEV, M_WAITOK);
|
2013-05-04 14:03:18 +00:00
|
|
|
smb_makescred(scred, curthread, NULL);
|
2001-04-10 07:59:06 +00:00
|
|
|
ssp = sdp->sd_share;
|
2013-05-04 14:18:10 +00:00
|
|
|
if (ssp != NULL) {
|
|
|
|
smb_share_lock(ssp);
|
2012-10-31 03:34:07 +00:00
|
|
|
smb_share_rele(ssp, scred);
|
2013-05-04 14:18:10 +00:00
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
vcp = sdp->sd_vc;
|
2013-05-04 14:18:10 +00:00
|
|
|
if (vcp != NULL) {
|
|
|
|
smb_vc_lock(vcp);
|
2012-10-31 03:34:07 +00:00
|
|
|
smb_vc_rele(vcp, scred);
|
2013-05-04 14:18:10 +00:00
|
|
|
}
|
2012-10-31 03:34:07 +00:00
|
|
|
free(scred, M_NSMBDEV);
|
2013-05-04 14:03:18 +00:00
|
|
|
free(sdp, M_NSMBDEV);
|
|
|
|
return;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
nsmb_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
2001-04-10 07:59:06 +00:00
|
|
|
{
|
|
|
|
struct smb_dev *sdp;
|
|
|
|
struct smb_vc *vcp;
|
|
|
|
struct smb_share *ssp;
|
2012-10-31 03:34:07 +00:00
|
|
|
struct smb_cred *scred;
|
2001-04-10 07:59:06 +00:00
|
|
|
int error = 0;
|
|
|
|
|
2013-05-04 14:03:18 +00:00
|
|
|
error = devfs_get_cdevpriv((void **)&sdp);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2012-10-31 03:34:07 +00:00
|
|
|
scred = malloc(sizeof(struct smb_cred), M_NSMBDEV, M_WAITOK);
|
2013-05-04 14:03:18 +00:00
|
|
|
SMB_LOCK();
|
2012-10-31 03:34:07 +00:00
|
|
|
smb_makescred(scred, td, NULL);
|
2001-04-10 07:59:06 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case SMBIOC_OPENSESSION:
|
2012-10-31 03:34:07 +00:00
|
|
|
if (sdp->sd_vc) {
|
|
|
|
error = EISCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
error = smb_usr_opensession((struct smbioc_ossn*)data,
|
2012-10-31 03:34:07 +00:00
|
|
|
scred, &vcp);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
sdp->sd_vc = vcp;
|
2013-05-04 14:18:10 +00:00
|
|
|
smb_vc_unlock(vcp);
|
2001-04-10 07:59:06 +00:00
|
|
|
sdp->sd_level = SMBL_VC;
|
|
|
|
break;
|
|
|
|
case SMBIOC_OPENSHARE:
|
2012-10-31 03:34:07 +00:00
|
|
|
if (sdp->sd_share) {
|
|
|
|
error = EISCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (sdp->sd_vc == NULL) {
|
|
|
|
error = ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
error = smb_usr_openshare(sdp->sd_vc,
|
2012-10-31 03:34:07 +00:00
|
|
|
(struct smbioc_oshare*)data, scred, &ssp);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
sdp->sd_share = ssp;
|
2013-05-04 14:18:10 +00:00
|
|
|
smb_share_unlock(ssp);
|
2001-04-10 07:59:06 +00:00
|
|
|
sdp->sd_level = SMBL_SHARE;
|
|
|
|
break;
|
|
|
|
case SMBIOC_REQUEST:
|
2012-10-31 03:34:07 +00:00
|
|
|
if (sdp->sd_share == NULL) {
|
|
|
|
error = ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
error = smb_usr_simplerequest(sdp->sd_share,
|
2012-10-31 03:34:07 +00:00
|
|
|
(struct smbioc_rq*)data, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
break;
|
|
|
|
case SMBIOC_T2RQ:
|
2012-10-31 03:34:07 +00:00
|
|
|
if (sdp->sd_share == NULL) {
|
|
|
|
error = ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
error = smb_usr_t2request(sdp->sd_share,
|
2012-10-31 03:34:07 +00:00
|
|
|
(struct smbioc_t2rq*)data, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
break;
|
|
|
|
case SMBIOC_SETFLAGS: {
|
|
|
|
struct smbioc_flags *fl = (struct smbioc_flags*)data;
|
|
|
|
int on;
|
|
|
|
|
|
|
|
if (fl->ioc_level == SMBL_VC) {
|
|
|
|
if (fl->ioc_mask & SMBV_PERMANENT) {
|
|
|
|
on = fl->ioc_flags & SMBV_PERMANENT;
|
2012-10-31 03:34:07 +00:00
|
|
|
if ((vcp = sdp->sd_vc) == NULL) {
|
|
|
|
error = ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
2013-05-04 14:18:10 +00:00
|
|
|
error = smb_vc_get(vcp, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
if (on && (vcp->obj.co_flags & SMBV_PERMANENT) == 0) {
|
|
|
|
vcp->obj.co_flags |= SMBV_PERMANENT;
|
2001-12-02 08:47:29 +00:00
|
|
|
smb_vc_ref(vcp);
|
2001-04-10 07:59:06 +00:00
|
|
|
} else if (!on && (vcp->obj.co_flags & SMBV_PERMANENT)) {
|
|
|
|
vcp->obj.co_flags &= ~SMBV_PERMANENT;
|
2012-10-31 03:34:07 +00:00
|
|
|
smb_vc_rele(vcp, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
2012-10-31 03:34:07 +00:00
|
|
|
smb_vc_put(vcp, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
} else if (fl->ioc_level == SMBL_SHARE) {
|
|
|
|
if (fl->ioc_mask & SMBS_PERMANENT) {
|
|
|
|
on = fl->ioc_flags & SMBS_PERMANENT;
|
2012-10-31 03:34:07 +00:00
|
|
|
if ((ssp = sdp->sd_share) == NULL) {
|
|
|
|
error = ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
2013-05-04 14:18:10 +00:00
|
|
|
error = smb_share_get(ssp, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
if (on && (ssp->obj.co_flags & SMBS_PERMANENT) == 0) {
|
|
|
|
ssp->obj.co_flags |= SMBS_PERMANENT;
|
2001-12-02 08:47:29 +00:00
|
|
|
smb_share_ref(ssp);
|
2001-04-10 07:59:06 +00:00
|
|
|
} else if (!on && (ssp->obj.co_flags & SMBS_PERMANENT)) {
|
|
|
|
ssp->obj.co_flags &= ~SMBS_PERMANENT;
|
2012-10-31 03:34:07 +00:00
|
|
|
smb_share_rele(ssp, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
2012-10-31 03:34:07 +00:00
|
|
|
smb_share_put(ssp, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SMBIOC_LOOKUP:
|
2012-10-31 03:34:07 +00:00
|
|
|
if (sdp->sd_vc || sdp->sd_share) {
|
|
|
|
error = EISCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
vcp = NULL;
|
|
|
|
ssp = NULL;
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smb_usr_lookup((struct smbioc_lookup*)data, scred, &vcp, &ssp);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
if (vcp) {
|
|
|
|
sdp->sd_vc = vcp;
|
2013-05-04 14:18:10 +00:00
|
|
|
smb_vc_unlock(vcp);
|
2001-04-10 07:59:06 +00:00
|
|
|
sdp->sd_level = SMBL_VC;
|
|
|
|
}
|
|
|
|
if (ssp) {
|
|
|
|
sdp->sd_share = ssp;
|
2013-05-04 14:18:10 +00:00
|
|
|
smb_share_unlock(ssp);
|
2001-04-10 07:59:06 +00:00
|
|
|
sdp->sd_level = SMBL_SHARE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SMBIOC_READ: case SMBIOC_WRITE: {
|
|
|
|
struct smbioc_rw *rwrq = (struct smbioc_rw*)data;
|
|
|
|
struct uio auio;
|
|
|
|
struct iovec iov;
|
|
|
|
|
2012-10-31 03:34:07 +00:00
|
|
|
if ((ssp = sdp->sd_share) == NULL) {
|
|
|
|
error = ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
iov.iov_base = rwrq->ioc_base;
|
|
|
|
iov.iov_len = rwrq->ioc_cnt;
|
|
|
|
auio.uio_iov = &iov;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_offset = rwrq->ioc_offset;
|
|
|
|
auio.uio_resid = rwrq->ioc_cnt;
|
|
|
|
auio.uio_segflg = UIO_USERSPACE;
|
|
|
|
auio.uio_rw = (cmd == SMBIOC_READ) ? UIO_READ : UIO_WRITE;
|
2001-12-02 08:47:29 +00:00
|
|
|
auio.uio_td = td;
|
2001-04-10 07:59:06 +00:00
|
|
|
if (cmd == SMBIOC_READ)
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smb_read(ssp, rwrq->ioc_fh, &auio, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
else
|
2012-10-31 03:34:07 +00:00
|
|
|
error = smb_write(ssp, rwrq->ioc_fh, &auio, scred);
|
2001-04-10 07:59:06 +00:00
|
|
|
rwrq->ioc_cnt -= auio.uio_resid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
error = ENODEV;
|
|
|
|
}
|
2012-10-31 03:34:07 +00:00
|
|
|
out:
|
|
|
|
free(scred, M_NSMBDEV);
|
2013-05-04 14:03:18 +00:00
|
|
|
SMB_UNLOCK();
|
2001-04-10 07:59:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nsmb_dev_load(module_t mod, int cmd, void *arg)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
error = smb_sm_init();
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
error = smb_iod_init();
|
|
|
|
if (error) {
|
|
|
|
smb_sm_done();
|
|
|
|
break;
|
|
|
|
}
|
2013-05-04 14:03:18 +00:00
|
|
|
error = nsmb_dev_init();
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
sx_init(&smb_lock, "samba device lock");
|
2001-04-10 07:59:06 +00:00
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
smb_iod_done();
|
|
|
|
error = smb_sm_done();
|
2005-11-22 02:15:46 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
2013-05-04 14:03:18 +00:00
|
|
|
nsmb_dev_destroy();
|
|
|
|
sx_destroy(&smb_lock);
|
2001-04-10 07:59:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEV_MODULE (dev_netsmb, nsmb_dev_load, 0);
|
|
|
|
|
|
|
|
int
|
|
|
|
smb_dev2share(int fd, int mode, struct smb_cred *scred,
|
2013-05-04 14:03:18 +00:00
|
|
|
struct smb_share **sspp, struct smb_dev **ssdp)
|
2001-04-10 07:59:06 +00:00
|
|
|
{
|
2013-05-04 14:03:18 +00:00
|
|
|
struct file *fp, *fptmp;
|
2001-04-10 07:59:06 +00:00
|
|
|
struct smb_dev *sdp;
|
|
|
|
struct smb_share *ssp;
|
2013-05-04 14:03:18 +00:00
|
|
|
struct thread *td;
|
2001-04-10 07:59:06 +00:00
|
|
|
int error;
|
|
|
|
|
2013-05-04 14:03:18 +00:00
|
|
|
td = curthread;
|
2018-05-09 18:47:24 +00:00
|
|
|
error = fget(td, fd, &cap_read_rights, &fp);
|
2013-05-04 14:03:18 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
fptmp = td->td_fpop;
|
|
|
|
td->td_fpop = fp;
|
|
|
|
error = devfs_get_cdevpriv((void **)&sdp);
|
|
|
|
td->td_fpop = fptmp;
|
|
|
|
fdrop(fp, td);
|
|
|
|
if (error || sdp == NULL)
|
|
|
|
return (error);
|
|
|
|
SMB_LOCK();
|
|
|
|
*ssdp = sdp;
|
2001-04-10 07:59:06 +00:00
|
|
|
ssp = sdp->sd_share;
|
2002-01-13 11:58:06 +00:00
|
|
|
if (ssp == NULL) {
|
2013-05-04 14:03:18 +00:00
|
|
|
SMB_UNLOCK();
|
|
|
|
return (ENOTCONN);
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
2013-05-04 14:18:10 +00:00
|
|
|
error = smb_share_get(ssp, scred);
|
2013-05-04 14:03:18 +00:00
|
|
|
if (error == 0) {
|
|
|
|
sdp->refcount++;
|
2002-01-13 11:58:06 +00:00
|
|
|
*sspp = ssp;
|
2013-05-04 14:03:18 +00:00
|
|
|
}
|
|
|
|
SMB_UNLOCK();
|
2002-01-13 11:58:06 +00:00
|
|
|
return error;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|