1999-10-02 04:06:24 +00:00
|
|
|
/*
|
2003-02-28 04:31:29 +00:00
|
|
|
* Copyright (c) 2003 Tim J. Robbins.
|
2001-03-10 05:24:45 +00:00
|
|
|
* Copyright (c) 1999, 2000, 2001 Boris Popov
|
1999-10-02 04:06:24 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2003-06-11 05:37:42 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-10-02 04:06:24 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2003-02-28 04:31:29 +00:00
|
|
|
#include <sys/conf.h>
|
1999-10-02 04:06:24 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:27:19 +00:00
|
|
|
#include <sys/module.h>
|
1999-10-02 04:06:24 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/uio.h>
|
2003-02-28 04:31:29 +00:00
|
|
|
#include <sys/ioccom.h>
|
1999-10-02 04:06:24 +00:00
|
|
|
|
|
|
|
#include <netncp/ncp.h>
|
|
|
|
#include <netncp/ncp_conn.h>
|
|
|
|
#include <netncp/ncp_subr.h>
|
|
|
|
#include <netncp/ncp_ncp.h>
|
|
|
|
#include <netncp/ncp_user.h>
|
|
|
|
#include <netncp/ncp_rq.h>
|
|
|
|
#include <netncp/ncp_nls.h>
|
2003-02-28 04:31:29 +00:00
|
|
|
#include <netncp/ncpio.h>
|
1999-10-02 04:06:24 +00:00
|
|
|
|
|
|
|
int ncp_version = NCP_VERSION;
|
|
|
|
|
|
|
|
SYSCTL_NODE(_net, OID_AUTO, ncp, CTLFLAG_RW, NULL, "NetWare requester");
|
|
|
|
SYSCTL_INT(_net_ncp, OID_AUTO, version, CTLFLAG_RD, &ncp_version, 0, "");
|
|
|
|
|
2000-04-29 13:34:28 +00:00
|
|
|
MODULE_VERSION(ncp, 1);
|
2001-03-10 05:24:45 +00:00
|
|
|
MODULE_DEPEND(ncp, libmchain, 1, 1, 1);
|
2000-04-29 13:34:28 +00:00
|
|
|
|
2004-06-16 09:47:26 +00:00
|
|
|
static struct cdev *ncp_dev;
|
2003-02-28 04:31:29 +00:00
|
|
|
|
|
|
|
static d_ioctl_t ncp_ioctl;
|
|
|
|
|
|
|
|
static struct cdevsw ncp_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_flags = D_NEEDGIANT,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_ioctl = ncp_ioctl,
|
|
|
|
.d_name = "ncp",
|
2003-02-28 04:31:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int ncp_conn_frag_rq(struct ncp_conn *, struct thread *,
|
|
|
|
struct ncp_conn_frag *);
|
|
|
|
static int ncp_conn_handler(struct thread *, struct ncpioc_request *,
|
|
|
|
struct ncp_conn *, struct ncp_handle *);
|
|
|
|
static int sncp_conn_scan(struct thread *, struct ncpioc_connscan *);
|
|
|
|
static int sncp_connect(struct thread *, struct ncpioc_connect *);
|
|
|
|
static int sncp_request(struct thread *, struct ncpioc_request *);
|
|
|
|
|
1999-10-02 04:06:24 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
ncp_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
2003-02-28 04:31:29 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case NCPIOC_CONNECT:
|
|
|
|
return (sncp_connect(td, (struct ncpioc_connect *)data));
|
|
|
|
case NCPIOC_CONNSCAN:
|
|
|
|
return (sncp_conn_scan(td, (struct ncpioc_connscan *)data));
|
|
|
|
case NCPIOC_REQUEST:
|
|
|
|
return (sncp_request(td, (struct ncpioc_request *)data));
|
|
|
|
}
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
1999-10-02 04:06:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach to NCP server
|
|
|
|
*/
|
|
|
|
|
2003-02-26 21:25:55 +00:00
|
|
|
static int
|
2003-02-28 04:31:29 +00:00
|
|
|
sncp_connect(struct thread *td, struct ncpioc_connect *args)
|
2001-03-10 05:24:45 +00:00
|
|
|
{
|
1999-10-02 04:06:24 +00:00
|
|
|
int connHandle = 0, error;
|
|
|
|
struct ncp_conn *conn;
|
|
|
|
struct ncp_handle *handle;
|
|
|
|
struct ncp_conn_args li;
|
|
|
|
|
2003-02-28 04:31:29 +00:00
|
|
|
checkbad(copyin(args->ioc_li,&li,sizeof(li)));
|
|
|
|
/* XXX Should be useracc() */
|
|
|
|
checkbad(copyout(&connHandle,args->ioc_connhandle,
|
|
|
|
sizeof(connHandle)));
|
1999-10-02 04:06:24 +00:00
|
|
|
li.password = li.user = NULL;
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_getattached(&li, td, td->td_ucred, NCPM_WRITE | NCPM_EXECUTE, &conn);
|
1999-10-02 04:06:24 +00:00
|
|
|
if (error) {
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_alloc(&li, td, td->td_ucred, &conn);
|
2001-03-10 05:24:45 +00:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
error = ncp_conn_reconnect(conn);
|
|
|
|
if (error)
|
|
|
|
ncp_conn_free(conn);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
if (!error) {
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_gethandle(conn, td, &handle);
|
2003-02-28 04:31:29 +00:00
|
|
|
copyout(&handle->nh_id, args->ioc_connhandle,
|
|
|
|
sizeof(args->ioc_connhandle));
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_unlock(conn,td);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
bad:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-02-28 04:31:29 +00:00
|
|
|
sncp_request(struct thread *td, struct ncpioc_request *args)
|
2001-03-10 05:24:45 +00:00
|
|
|
{
|
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
struct ncp_conn *conn;
|
|
|
|
struct ncp_handle *handle;
|
2001-03-10 05:24:45 +00:00
|
|
|
int error = 0, rqsize;
|
1999-10-02 04:06:24 +00:00
|
|
|
|
2003-02-28 04:31:29 +00:00
|
|
|
error = ncp_conn_findhandle(args->ioc_connhandle, td, &handle);
|
2001-03-10 05:24:45 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
1999-10-02 04:06:24 +00:00
|
|
|
conn = handle->nh_conn;
|
2003-02-28 04:31:29 +00:00
|
|
|
if (args->ioc_fn == NCP_CONN)
|
|
|
|
return ncp_conn_handler(td, args, conn, handle);
|
|
|
|
error = copyin(&args->ioc_ncpbuf->rqsize, &rqsize, sizeof(int));
|
2001-03-10 05:24:45 +00:00
|
|
|
if (error)
|
|
|
|
return(error);
|
2003-02-28 04:31:29 +00:00
|
|
|
error = ncp_rq_alloc(args->ioc_fn, conn, td, td->td_ucred, &rqp);
|
2001-03-10 05:24:45 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
if (rqsize) {
|
2003-02-28 04:31:29 +00:00
|
|
|
error = mb_put_mem(&rqp->rq, (caddr_t)args->ioc_ncpbuf->packet,
|
2001-03-10 05:24:45 +00:00
|
|
|
rqsize, MB_MUSER);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
2001-03-10 05:24:45 +00:00
|
|
|
rqp->nr_flags |= NCPR_DONTFREEONERR;
|
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (error == 0 && rqp->nr_rpsize)
|
2003-02-28 04:31:29 +00:00
|
|
|
error = md_get_mem(&rqp->rp, (caddr_t)args->ioc_ncpbuf->packet,
|
2001-03-10 05:24:45 +00:00
|
|
|
rqp->nr_rpsize, MB_MUSER);
|
2003-02-28 04:31:29 +00:00
|
|
|
copyout(&rqp->nr_cs, &args->ioc_ncpbuf->cs, sizeof(rqp->nr_cs));
|
|
|
|
copyout(&rqp->nr_cc, &args->ioc_ncpbuf->cc, sizeof(rqp->nr_cc));
|
|
|
|
copyout(&rqp->nr_rpsize, &args->ioc_ncpbuf->rpsize, sizeof(rqp->nr_rpsize));
|
2001-03-10 05:24:45 +00:00
|
|
|
bad:
|
1999-10-02 04:06:24 +00:00
|
|
|
ncp_rq_done(rqp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2001-03-22 10:38:16 +00:00
|
|
|
static int
|
|
|
|
ncp_mod_login(struct ncp_conn *conn, char *user, int objtype, char *password,
|
2003-02-26 21:25:55 +00:00
|
|
|
struct thread *td, struct ucred *cred)
|
2001-03-22 10:38:16 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (ncp_suser(cred) != 0 && cred->cr_uid != conn->nc_owner->cr_uid)
|
|
|
|
return EACCES;
|
|
|
|
conn->li.user = ncp_str_dup(user);
|
|
|
|
if (conn->li.user == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
conn->li.password = ncp_str_dup(password);
|
|
|
|
if (conn->li.password == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
ncp_str_upper(conn->li.user);
|
|
|
|
if ((conn->li.opt & NCP_OPT_NOUPCASEPASS) == 0)
|
|
|
|
ncp_str_upper(conn->li.password);
|
|
|
|
conn->li.objtype = objtype;
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_login(conn, td, cred);
|
2001-03-22 10:38:16 +00:00
|
|
|
return error;
|
|
|
|
bad:
|
|
|
|
if (conn->li.user) {
|
|
|
|
free(conn->li.user, M_NCPDATA);
|
|
|
|
conn->li.user = NULL;
|
|
|
|
}
|
|
|
|
if (conn->li.password) {
|
|
|
|
free(conn->li.password, M_NCPDATA);
|
|
|
|
conn->li.password = NULL;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1999-10-02 04:06:24 +00:00
|
|
|
static int
|
2003-02-28 04:31:29 +00:00
|
|
|
ncp_conn_handler(struct thread *td, struct ncpioc_request *args,
|
1999-10-02 04:06:24 +00:00
|
|
|
struct ncp_conn *conn, struct ncp_handle *hp)
|
|
|
|
{
|
2003-02-26 21:25:55 +00:00
|
|
|
int error = 0, rqsize, subfn;
|
1999-10-02 04:06:24 +00:00
|
|
|
struct ucred *cred;
|
2003-02-26 21:25:55 +00:00
|
|
|
|
1999-10-02 04:06:24 +00:00
|
|
|
char *pdata;
|
|
|
|
|
2003-02-26 21:25:55 +00:00
|
|
|
cred = td->td_ucred;
|
2003-02-28 04:31:29 +00:00
|
|
|
error = copyin(&args->ioc_ncpbuf->rqsize, &rqsize, sizeof(int));
|
2003-02-26 21:25:55 +00:00
|
|
|
if (error)
|
|
|
|
return(error);
|
1999-10-02 04:06:24 +00:00
|
|
|
error = 0;
|
2003-02-28 04:31:29 +00:00
|
|
|
pdata = args->ioc_ncpbuf->packet;
|
1999-10-02 04:06:24 +00:00
|
|
|
subfn = *(pdata++) & 0xff;
|
|
|
|
rqsize--;
|
|
|
|
switch (subfn) {
|
|
|
|
case NCP_CONN_READ: case NCP_CONN_WRITE: {
|
|
|
|
struct ncp_rw rwrq;
|
|
|
|
struct uio auio;
|
|
|
|
struct iovec iov;
|
2003-02-26 21:25:55 +00:00
|
|
|
|
|
|
|
if (rqsize != sizeof(rwrq))
|
|
|
|
return (EBADRPC);
|
1999-10-02 04:06:24 +00:00
|
|
|
error = copyin(pdata,&rwrq,rqsize);
|
2003-02-26 21:25:55 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
1999-10-02 04:06:24 +00:00
|
|
|
iov.iov_base = rwrq.nrw_base;
|
|
|
|
iov.iov_len = rwrq.nrw_cnt;
|
|
|
|
auio.uio_iov = &iov;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_offset = rwrq.nrw_offset;
|
|
|
|
auio.uio_resid = rwrq.nrw_cnt;
|
|
|
|
auio.uio_segflg = UIO_USERSPACE;
|
|
|
|
auio.uio_rw = (subfn == NCP_CONN_READ) ? UIO_READ : UIO_WRITE;
|
2003-02-26 21:25:55 +00:00
|
|
|
auio.uio_td = td;
|
1999-10-02 04:06:24 +00:00
|
|
|
if (subfn == NCP_CONN_READ)
|
|
|
|
error = ncp_read(conn, &rwrq.nrw_fh, &auio, cred);
|
|
|
|
else
|
|
|
|
error = ncp_write(conn, &rwrq.nrw_fh, &auio, cred);
|
|
|
|
rwrq.nrw_cnt -= auio.uio_resid;
|
2003-02-28 04:31:29 +00:00
|
|
|
/*td->td_retval[0] = rwrq.nrw_cnt;*/
|
1999-10-02 04:06:24 +00:00
|
|
|
break;
|
|
|
|
} /* case int_read/write */
|
|
|
|
case NCP_CONN_SETFLAGS: {
|
|
|
|
u_int16_t mask, flags;
|
|
|
|
|
|
|
|
error = copyin(pdata,&mask, sizeof(mask));
|
2003-02-26 21:25:55 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
1999-10-02 04:06:24 +00:00
|
|
|
pdata += sizeof(mask);
|
|
|
|
error = copyin(pdata,&flags,sizeof(flags));
|
2003-02-26 21:25:55 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = ncp_conn_lock(conn, td, cred, NCPM_WRITE);
|
|
|
|
if (error)
|
|
|
|
return error;
|
1999-10-02 04:06:24 +00:00
|
|
|
if (mask & NCPFL_PERMANENT) {
|
|
|
|
conn->flags &= ~NCPFL_PERMANENT;
|
|
|
|
conn->flags |= (flags & NCPFL_PERMANENT);
|
|
|
|
}
|
|
|
|
if (mask & NCPFL_PRIMARY) {
|
|
|
|
error = ncp_conn_setprimary(conn, flags & NCPFL_PRIMARY);
|
|
|
|
if (error) {
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_unlock(conn, td);
|
1999-10-02 04:06:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_unlock(conn, td);
|
1999-10-02 04:06:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NCP_CONN_LOGIN: {
|
|
|
|
struct ncp_conn_login la;
|
|
|
|
|
2001-03-22 10:38:16 +00:00
|
|
|
if (rqsize != sizeof(la))
|
|
|
|
return EBADRPC;
|
|
|
|
if (conn->flags & NCPFL_LOGGED)
|
|
|
|
return EALREADY;
|
|
|
|
if ((error = copyin(pdata,&la,rqsize)) != 0)
|
|
|
|
break;
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_lock(conn, td, cred, NCPM_EXECUTE | NCPM_WRITE);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = ncp_mod_login(conn, la.username, la.objtype,
|
|
|
|
la.password, td, td->td_ucred);
|
|
|
|
ncp_conn_unlock(conn, td);
|
1999-10-02 04:06:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NCP_CONN_GETINFO: {
|
|
|
|
struct ncp_conn_stat ncs;
|
|
|
|
int len = sizeof(ncs);
|
|
|
|
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_lock(conn, td, td->td_ucred, NCPM_READ);
|
|
|
|
if (error)
|
|
|
|
return error;
|
1999-10-02 04:06:24 +00:00
|
|
|
ncp_conn_getinfo(conn, &ncs);
|
2003-02-28 04:31:29 +00:00
|
|
|
copyout(&len, &args->ioc_ncpbuf->rpsize, sizeof(int));
|
|
|
|
error = copyout(&ncs, &args->ioc_ncpbuf->packet, len);
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_unlock(conn, td);
|
1999-10-02 04:06:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NCP_CONN_GETUSER: {
|
|
|
|
int len;
|
|
|
|
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_lock(conn, td, td->td_ucred, NCPM_READ);
|
|
|
|
if (error)
|
|
|
|
return error;
|
1999-10-02 04:06:24 +00:00
|
|
|
len = (conn->li.user) ? strlen(conn->li.user) + 1 : 0;
|
2003-02-28 04:31:29 +00:00
|
|
|
copyout(&len, &args->ioc_ncpbuf->rpsize, sizeof(int));
|
1999-10-02 04:06:24 +00:00
|
|
|
if (len) {
|
2003-02-28 04:31:29 +00:00
|
|
|
error = copyout(conn->li.user,
|
|
|
|
&args->ioc_ncpbuf->packet, len);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_unlock(conn, td);
|
1999-10-02 04:06:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NCP_CONN_CONN2REF: {
|
|
|
|
int len = sizeof(int);
|
|
|
|
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_lock(conn, td, td->td_ucred, NCPM_READ);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2003-02-28 04:31:29 +00:00
|
|
|
copyout(&len, &args->ioc_ncpbuf->rpsize, sizeof(int));
|
1999-10-02 04:06:24 +00:00
|
|
|
if (len) {
|
2003-02-28 04:31:29 +00:00
|
|
|
error = copyout(&conn->nc_id,
|
|
|
|
&args->ioc_ncpbuf->packet, len);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_unlock(conn, td);
|
1999-10-02 04:06:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NCP_CONN_FRAG: {
|
|
|
|
struct ncp_conn_frag nf;
|
|
|
|
|
2003-02-26 21:25:55 +00:00
|
|
|
if (rqsize != sizeof(nf))
|
|
|
|
return (EBADRPC);
|
1999-10-02 04:06:24 +00:00
|
|
|
if ((error = copyin(pdata, &nf, rqsize)) != 0) break;
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_lock(conn, td, cred, NCPM_EXECUTE);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = ncp_conn_frag_rq(conn, td, &nf);
|
|
|
|
ncp_conn_unlock(conn, td);
|
1999-10-02 04:06:24 +00:00
|
|
|
copyout(&nf, &pdata, sizeof(nf));
|
2003-02-26 21:25:55 +00:00
|
|
|
td->td_retval[0] = error;
|
1999-10-02 04:06:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NCP_CONN_DUP: {
|
|
|
|
struct ncp_handle *newhp;
|
|
|
|
int len = sizeof(NWCONN_HANDLE);
|
|
|
|
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_lock(conn, td, cred, NCPM_READ);
|
1999-10-02 04:06:24 +00:00
|
|
|
if (error) break;
|
2003-02-28 04:31:29 +00:00
|
|
|
copyout(&len, &args->ioc_ncpbuf->rpsize, len);
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_gethandle(conn, td, &newhp);
|
1999-10-02 04:06:24 +00:00
|
|
|
if (!error)
|
2003-02-28 04:31:29 +00:00
|
|
|
error = copyout(&newhp->nh_id,
|
|
|
|
args->ioc_ncpbuf->packet, len);
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_unlock(conn, td);
|
1999-10-02 04:06:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NCP_CONN_CONNCLOSE: {
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_lock(conn, td, cred, NCPM_EXECUTE);
|
1999-10-02 04:06:24 +00:00
|
|
|
if (error) break;
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_puthandle(hp, td, 0);
|
2001-03-10 05:24:45 +00:00
|
|
|
error = ncp_conn_free(conn);
|
1999-10-02 04:06:24 +00:00
|
|
|
if (error)
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_unlock(conn, td);
|
1999-10-02 04:06:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2003-02-26 21:25:55 +00:00
|
|
|
static int
|
2003-02-28 04:31:29 +00:00
|
|
|
sncp_conn_scan(struct thread *td, struct ncpioc_connscan *args)
|
2001-03-10 05:24:45 +00:00
|
|
|
{
|
1999-10-02 04:06:24 +00:00
|
|
|
int connHandle = 0, error;
|
|
|
|
struct ncp_conn_args li, *lip;
|
|
|
|
struct ncp_conn *conn;
|
|
|
|
struct ncp_handle *hp;
|
|
|
|
char *user = NULL, *password = NULL;
|
|
|
|
|
2003-02-28 04:31:29 +00:00
|
|
|
if (args->ioc_li) {
|
|
|
|
if (copyin(args->ioc_li, &li, sizeof(li)))
|
2003-02-26 21:25:55 +00:00
|
|
|
return EFAULT;
|
1999-10-02 04:06:24 +00:00
|
|
|
lip = &li;
|
|
|
|
} else {
|
|
|
|
lip = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lip != NULL) {
|
|
|
|
lip->server[sizeof(lip->server)-1]=0; /* just to make sure */
|
|
|
|
ncp_str_upper(lip->server);
|
|
|
|
if (lip->user) {
|
|
|
|
user = ncp_str_dup(lip->user);
|
2003-02-26 21:25:55 +00:00
|
|
|
if (user == NULL)
|
|
|
|
return EINVAL;
|
1999-10-02 04:06:24 +00:00
|
|
|
ncp_str_upper(user);
|
|
|
|
}
|
|
|
|
if (lip->password) {
|
|
|
|
password = ncp_str_dup(lip->password);
|
|
|
|
if (password == NULL) {
|
|
|
|
if (user)
|
|
|
|
free(user, M_NCPDATA);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
ncp_str_upper(password);
|
|
|
|
}
|
|
|
|
lip->user = user;
|
|
|
|
lip->password = password;
|
|
|
|
}
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_conn_getbyli(lip, td, td->td_ucred, NCPM_EXECUTE, &conn);
|
|
|
|
if (!error) { /* already have this login */
|
|
|
|
ncp_conn_gethandle(conn, td, &hp);
|
1999-10-02 04:06:24 +00:00
|
|
|
connHandle = hp->nh_id;
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_unlock(conn, td);
|
2003-02-28 04:31:29 +00:00
|
|
|
copyout(&connHandle, args->ioc_connhandle, sizeof(connHandle));
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
2003-02-26 21:25:55 +00:00
|
|
|
if (user)
|
|
|
|
free(user, M_NCPDATA);
|
|
|
|
if (password)
|
|
|
|
free(password, M_NCPDATA);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_conn_frag_rq(struct ncp_conn *conn, struct thread *td,
|
|
|
|
struct ncp_conn_frag *nfp)
|
2001-03-10 05:24:45 +00:00
|
|
|
{
|
1999-10-02 04:06:24 +00:00
|
|
|
NW_FRAGMENT *fp;
|
2001-03-10 05:24:45 +00:00
|
|
|
struct ncp_rq *rqp;
|
|
|
|
u_int32_t fsize;
|
|
|
|
int error, i, rpsize;
|
1999-10-02 04:06:24 +00:00
|
|
|
|
2003-02-26 21:25:55 +00:00
|
|
|
error = ncp_rq_alloc(nfp->fn, conn, td, td->td_ucred, &rqp);
|
2001-03-10 05:24:45 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
for(fp = nfp->rqf, i = 0; i < nfp->rqfcnt; i++, fp++) {
|
|
|
|
error = mb_put_mem(&rqp->rq, (caddr_t)fp->fragAddress, fp->fragSize, MB_MUSER);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
2001-03-10 05:24:45 +00:00
|
|
|
rqp->nr_flags |= NCPR_DONTFREEONERR;
|
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
rpsize = rqp->nr_rpsize;
|
1999-10-02 04:06:24 +00:00
|
|
|
if (rpsize && nfp->rpfcnt) {
|
|
|
|
for(fp = nfp->rpf, i = 0; i < nfp->rpfcnt; i++, fp++) {
|
2001-03-10 05:24:45 +00:00
|
|
|
error = copyin(&fp->fragSize, &fsize, sizeof (fsize));
|
|
|
|
if (error)
|
|
|
|
break;
|
1999-10-02 04:06:24 +00:00
|
|
|
fsize = min(fsize, rpsize);
|
2001-03-10 05:24:45 +00:00
|
|
|
error = md_get_mem(&rqp->rp, (caddr_t)fp->fragAddress, fsize, MB_MUSER);
|
|
|
|
if (error)
|
|
|
|
break;
|
1999-10-02 04:06:24 +00:00
|
|
|
rpsize -= fsize;
|
2001-03-10 05:24:45 +00:00
|
|
|
error = copyout(&fsize, &fp->fragSize, sizeof (fsize));
|
|
|
|
if (error)
|
|
|
|
break;
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-10 05:24:45 +00:00
|
|
|
nfp->cs = rqp->nr_cs;
|
|
|
|
nfp->cc = rqp->nr_cc;
|
|
|
|
bad:
|
|
|
|
ncp_rq_done(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-02-26 21:25:55 +00:00
|
|
|
ncp_load(void)
|
|
|
|
{
|
2003-02-28 04:31:29 +00:00
|
|
|
int error;
|
1999-10-02 04:06:24 +00:00
|
|
|
|
2003-02-28 04:31:29 +00:00
|
|
|
if ((error = ncp_init()) != 0)
|
|
|
|
return (error);
|
|
|
|
ncp_dev = make_dev(&ncp_cdevsw, 0, 0, 0, 0666, "ncp");
|
|
|
|
printf("ncp_load: loaded\n");
|
|
|
|
return (0);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-03-10 05:24:45 +00:00
|
|
|
ncp_unload(void)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = ncp_done();
|
|
|
|
if (error)
|
2003-02-28 04:31:29 +00:00
|
|
|
return (error);
|
|
|
|
destroy_dev(ncp_dev);
|
|
|
|
printf("ncp_unload: unloaded\n");
|
|
|
|
return (0);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ncp_mod_handler(module_t mod, int type, void *data)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (type) {
|
2003-02-26 21:25:55 +00:00
|
|
|
case MOD_LOAD:
|
1999-10-02 04:06:24 +00:00
|
|
|
error = ncp_load();
|
|
|
|
break;
|
2003-02-26 21:25:55 +00:00
|
|
|
case MOD_UNLOAD:
|
1999-10-02 04:06:24 +00:00
|
|
|
error = ncp_unload();
|
|
|
|
break;
|
2003-02-26 21:25:55 +00:00
|
|
|
default:
|
1999-10-02 04:06:24 +00:00
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
2003-02-26 21:25:55 +00:00
|
|
|
|
1999-10-02 04:06:24 +00:00
|
|
|
static moduledata_t ncp_mod = {
|
|
|
|
"ncp",
|
|
|
|
ncp_mod_handler,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
DECLARE_MODULE(ncp, ncp_mod, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);
|