From c072d36bb918825d157424cd39c2b0bc6381ad2a Mon Sep 17 00:00:00 2001 From: tjr Date: Fri, 28 Feb 2003 04:31:29 +0000 Subject: Use a character device and ioctl() for communication between libncp and the kernel instead of adding more syscalls at runtime. As a bonus, you can now restrict access to the kernel NCP interface with chmod. --- lib/libncp/ncpl_subr.c | 58 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 18 deletions(-) (limited to 'lib/libncp/ncpl_subr.c') diff --git a/lib/libncp/ncpl_subr.c b/lib/libncp/ncpl_subr.c index ed70eb8..b534995 100644 --- a/lib/libncp/ncpl_subr.c +++ b/lib/libncp/ncpl_subr.c @@ -37,9 +37,11 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include #include +#include +#include #include #include #include @@ -49,9 +51,9 @@ __FBSDID("$FreeBSD$"); #include #include /*#include */ -#include "ncp_mod.h" +#include -int sysentoffset; +#define _PATH_NCP _PATH_DEV NCP_NAME void ncp_add_word_lh(struct ncp_buf *conn, u_int16_t x) { @@ -158,7 +160,17 @@ ncp_reply_dword_lh(struct ncp_buf *conn, int offset) { int ncp_connect(struct ncp_conn_args *li, int *connHandle) { - return syscall(NCP_CONNECT,li,connHandle); + struct ncpioc_connect args; + int fd, r; + if ((fd = open(_PATH_NCP, O_RDWR)) < 0) + return (errno); + args.ioc_li = li; + args.ioc_connhandle = connHandle; + errno = 0; + (void)ioctl(fd, NCPIOC_CONNECT, &args); + r = errno; + close(fd); + return (r); } int @@ -172,18 +184,38 @@ ncp_disconnect(int cH) { int ncp_request(int connHandle,int function, struct ncp_buf *ncpbuf){ - int err = syscall(SNCP_REQUEST,connHandle,function,ncpbuf); - return (err<0) ? errno : 0; + struct ncpioc_request args; + int fd, r; + if ((fd = open(_PATH_NCP, O_RDWR)) < 0) + return (errno); + args.ioc_connhandle = connHandle; + args.ioc_fn = function; + args.ioc_ncpbuf = ncpbuf; + errno = 0; + (void)ioctl(fd, NCPIOC_REQUEST, &args); + r = errno; + close(fd); + return (r); } int ncp_conn_request(int connHandle, struct ncp_buf *ncpbuf){ - return syscall(SNCP_REQUEST, connHandle, NCP_CONN, ncpbuf); + return (ncp_request(connHandle, NCP_CONN, ncpbuf)); } int ncp_conn_scan(struct ncp_conn_loginfo *li, int *connid) { - return syscall(NCP_CONNSCAN,li, connid); + struct ncpioc_connscan args; + int fd, r; + if ((fd = open(_PATH_NCP, O_RDWR)) < 0) + return (errno); + args.ioc_li = li; + args.ioc_connhandle = connid; + errno = 0; + (void)ioctl(fd, NCPIOC_CONNSCAN, &args); + r = errno; + close(fd); + return (r); } NWCCODE @@ -211,22 +243,12 @@ NWRequest(NWCONN_HANDLE cH, nuint16 fn, int ncp_initlib(void){ int error; - int len = sizeof(sysentoffset); int kv, kvlen = sizeof(kv); static int ncp_initialized; if (ncp_initialized) return 0; #if __FreeBSD_version < 400001 - error = sysctlbyname("net.ipx.ncp.sysent", &sysentoffset, &len, NULL, 0); -#else - error = sysctlbyname("net.ncp.sysent", &sysentoffset, &len, NULL, 0); -#endif - if (error) { - fprintf(stderr, "%s: can't find kernel module\n", __FUNCTION__); - return error; - } -#if __FreeBSD_version < 400001 error = sysctlbyname("net.ipx.ncp.version", &kv, &kvlen, NULL, 0); #else error = sysctlbyname("net.ncp.version", &kv, &kvlen, NULL, 0); -- cgit v1.1