15331Samw /* 25331Samw * CDDL HEADER START 35331Samw * 45331Samw * The contents of this file are subject to the terms of the 55331Samw * Common Development and Distribution License (the "License"). 65331Samw * You may not use this file except in compliance with the License. 75331Samw * 85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95331Samw * or http://www.opensolaris.org/os/licensing. 105331Samw * See the License for the specific language governing permissions 115331Samw * and limitations under the License. 125331Samw * 135331Samw * When distributing Covered Code, include this CDDL HEADER in each 145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155331Samw * If applicable, add the following below this CDDL HEADER, with the 165331Samw * fields enclosed by brackets "[]" replaced with your own identifying 175331Samw * information: Portions Copyright [yyyy] [name of copyright owner] 185331Samw * 195331Samw * CDDL HEADER END 205331Samw */ 215331Samw /* 226139Sjb150015 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 235331Samw * Use is subject to license terms. 245331Samw */ 255331Samw 26*7348SJose.Borrego@Sun.COM #pragma ident "@(#)smb_init.c 1.4 08/07/08 SMI" 275331Samw 285331Samw #include <sys/types.h> 295331Samw #include <sys/ddi.h> 305331Samw #include <sys/modctl.h> 315331Samw #include <sys/cred.h> 325331Samw #include <sys/ioccom.h> 335331Samw #include <sys/policy.h> 345331Samw #include <smbsrv/smb_incl.h> 355331Samw #include <smbsrv/mlsvc.h> 365331Samw #include <smbsrv/smb_door_svc.h> 375331Samw #include <smbsrv/smb_ioctl.h> 385331Samw #include <smbsrv/smb_kproto.h> 396139Sjb150015 406139Sjb150015 static int smb_drv_open(dev_t *, int, int, cred_t *); 416139Sjb150015 static int smb_drv_close(dev_t, int, int, cred_t *); 426139Sjb150015 static int smb_drv_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 435331Samw static int smb_drv_attach(dev_info_t *, ddi_attach_cmd_t); 445331Samw static int smb_drv_detach(dev_info_t *, ddi_detach_cmd_t); 455331Samw static int smb_drv_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **); 466139Sjb150015 476139Sjb150015 /* 486139Sjb150015 * ***************************************************************************** 496139Sjb150015 * ****************************** Global Variables ***************************** 506139Sjb150015 * ***************************************************************************** 516139Sjb150015 * 526139Sjb150015 * These variables can only be changed through the /etc/system file. 536139Sjb150015 */ 545331Samw 555331Samw /* 566139Sjb150015 * Maximum buffer size for NT: configurable based on the client environment. 576139Sjb150015 * IR104720 Experiments with Windows 2000 indicate that we achieve better 586139Sjb150015 * SmbWriteX performance with a buffer size of 64KB instead of the 37KB used 596139Sjb150015 * with Windows NT4.0. Previous experiments with NT4.0 resulted in directory 606139Sjb150015 * listing problems so this buffer size is configurable based on the end-user 616139Sjb150015 * environment. When in doubt use 37KB. 625331Samw */ 636139Sjb150015 int smb_maxbufsize = SMB_NT_MAXBUF; 646139Sjb150015 clock_t smb_oplock_timeout = OPLOCK_STD_TIMEOUT; 656139Sjb150015 int smb_flush_required = 1; 666139Sjb150015 int smb_dirsymlink_enable = 1; 676139Sjb150015 int smb_announce_quota = 0; 68*7348SJose.Borrego@Sun.COM int smb_sign_debug = 0; 696139Sjb150015 706139Sjb150015 /* 716139Sjb150015 * ***************************************************************************** 726139Sjb150015 * ********************** Static Variables / Module Linkage ******************** 736139Sjb150015 * ***************************************************************************** 746139Sjb150015 */ 756139Sjb150015 765331Samw static struct cb_ops cbops = { 775331Samw smb_drv_open, /* cb_open */ 785331Samw smb_drv_close, /* cb_close */ 795331Samw nodev, /* cb_strategy */ 805331Samw nodev, /* cb_print */ 815331Samw nodev, /* cb_dump */ 825331Samw nodev, /* cb_read */ 835331Samw nodev, /* cb_write */ 845331Samw smb_drv_ioctl, /* cb_ioctl */ 855331Samw nodev, /* cb_devmap */ 865331Samw nodev, /* cb_mmap */ 875331Samw nodev, /* cb_segmap */ 885331Samw nochpoll, /* cb_chpoll */ 895331Samw ddi_prop_op, /* cb_prop_op */ 905331Samw NULL, /* cb_streamtab */ 915331Samw D_MP, /* cb_flag */ 925331Samw CB_REV, /* cb_rev */ 935331Samw nodev, /* cb_aread */ 945331Samw nodev, /* cb_awrite */ 955331Samw }; 965331Samw 975331Samw static struct dev_ops devops = { 985331Samw DEVO_REV, /* devo_rev */ 995331Samw 0, /* devo_refcnt */ 1005331Samw smb_drv_getinfo, /* devo_getinfo */ 1015331Samw nulldev, /* devo_identify */ 1025331Samw nulldev, /* devo_probe */ 1035331Samw smb_drv_attach, /* devo_attach */ 1045331Samw smb_drv_detach, /* devo_detach */ 1055331Samw nodev, /* devo_reset */ 1065331Samw &cbops, /* devo_cb_ops */ 1075331Samw NULL, /* devo_bus_ops */ 1085331Samw NULL, /* devo_power */ 1095331Samw }; 1105331Samw 1115331Samw static struct modldrv modldrv = { 1125331Samw &mod_driverops, /* drv_modops */ 113*7348SJose.Borrego@Sun.COM "CIFS Server Protocol 1.4", /* drv_linkinfo */ 1145331Samw &devops, 1155331Samw }; 1165331Samw 1175331Samw static struct modlinkage modlinkage = { 1185331Samw MODREV_1, /* revision of the module, must be: MODREV_1 */ 1195331Samw &modldrv, /* ptr to linkage structures */ 1205331Samw NULL, 1215331Samw }; 1225331Samw 1235331Samw static dev_info_t *smb_drv_dip = NULL; 1245331Samw 1255331Samw /* 1266139Sjb150015 * **************************************************************************** 1276139Sjb150015 * Module Interface 1286139Sjb150015 * **************************************************************************** 1295331Samw */ 1305331Samw 1315331Samw int 1325331Samw _init(void) 1335331Samw { 1346139Sjb150015 return (mod_install(&modlinkage)); 1355331Samw } 1365331Samw 1375331Samw int 1385331Samw _info(struct modinfo *modinfop) 1395331Samw { 1405331Samw return (mod_info(&modlinkage, modinfop)); 1415331Samw } 1425331Samw 1435331Samw int 1445331Samw _fini(void) 1455331Samw { 1466139Sjb150015 return (mod_remove(&modlinkage)); 1476139Sjb150015 } 1486139Sjb150015 1496139Sjb150015 /* 1506139Sjb150015 * **************************************************************************** 1516139Sjb150015 * Pseudo Device Entry Points 1526139Sjb150015 * **************************************************************************** 1536139Sjb150015 */ 1546139Sjb150015 /* ARGSUSED */ 1556139Sjb150015 static int 1566139Sjb150015 smb_drv_open(dev_t *devp, int flag, int otyp, cred_t *credp) 1576139Sjb150015 { 1586139Sjb150015 /* 1596139Sjb150015 * Check caller's privileges. 1606139Sjb150015 */ 1616139Sjb150015 if (secpolicy_smb(credp) != 0) 1626139Sjb150015 return (EPERM); 1636139Sjb150015 1646139Sjb150015 /* 1656139Sjb150015 * Start SMB service state machine 1666139Sjb150015 */ 1676139Sjb150015 return (smb_server_create()); 1686139Sjb150015 } 1696139Sjb150015 1706139Sjb150015 /* ARGSUSED */ 1716139Sjb150015 static int 1726139Sjb150015 smb_drv_close(dev_t dev, int flag, int otyp, cred_t *credp) 1736139Sjb150015 { 1746139Sjb150015 return (smb_server_delete()); 1756139Sjb150015 } 1765331Samw 1776139Sjb150015 /* ARGSUSED */ 1786139Sjb150015 static int 1796139Sjb150015 smb_drv_ioctl(dev_t drv, int cmd, intptr_t argp, int flag, cred_t *cred, 1806139Sjb150015 int *retval) 1816139Sjb150015 { 1826139Sjb150015 int rc = 0; 1836139Sjb150015 smb_io_t smb_io; 1846139Sjb150015 1856139Sjb150015 if (ddi_copyin((smb_io_t *)argp, &smb_io, sizeof (smb_io), flag) || 1866139Sjb150015 (smb_io.sio_version != SMB_IOC_VERSION)) 1876139Sjb150015 return (EFAULT); 1886139Sjb150015 1896139Sjb150015 switch (cmd) { 1906139Sjb150015 case SMB_IOC_CONFIG: 1916139Sjb150015 rc = smb_server_configure(&smb_io.sio_data.cfg); 1926139Sjb150015 break; 1936139Sjb150015 case SMB_IOC_START: 1946139Sjb150015 rc = smb_server_start(&smb_io.sio_data.start); 1956139Sjb150015 break; 1966139Sjb150015 case SMB_IOC_NBT_LISTEN: 1976139Sjb150015 rc = smb_server_nbt_listen(smb_io.sio_data.error); 1986139Sjb150015 break; 1996139Sjb150015 case SMB_IOC_TCP_LISTEN: 2006139Sjb150015 rc = smb_server_tcp_listen(smb_io.sio_data.error); 2016139Sjb150015 break; 2026139Sjb150015 case SMB_IOC_NBT_RECEIVE: 2036139Sjb150015 rc = smb_server_nbt_receive(); 2046139Sjb150015 break; 2056139Sjb150015 case SMB_IOC_TCP_RECEIVE: 2066139Sjb150015 rc = smb_server_tcp_receive(); 2076139Sjb150015 break; 2086139Sjb150015 case SMB_IOC_GMTOFF: 2096139Sjb150015 rc = smb_server_set_gmtoff(smb_io.sio_data.gmtoff); 2106139Sjb150015 break; 2116139Sjb150015 default: 2126139Sjb150015 rc = ENOTTY; 2136139Sjb150015 break; 2145331Samw } 2155331Samw 2165331Samw return (rc); 2175331Samw } 2185331Samw 2195331Samw /* 2206139Sjb150015 * **************************************************************************** 2216139Sjb150015 * Pseudo Device Operations 2226139Sjb150015 * **************************************************************************** 2235331Samw */ 2246139Sjb150015 static int 2256139Sjb150015 smb_drv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 2266139Sjb150015 { 2276139Sjb150015 if (cmd == DDI_ATTACH) { 2286139Sjb150015 /* we only allow instance 0 to attach */ 2296139Sjb150015 if (ddi_get_instance(dip) == 0) { 2306139Sjb150015 /* create the minor node */ 2316139Sjb150015 if (ddi_create_minor_node(dip, "smbsrv", S_IFCHR, 0, 2326139Sjb150015 DDI_PSEUDO, 0) == DDI_SUCCESS) { 2336139Sjb150015 if (smb_server_svc_init() == 0) { 2346139Sjb150015 smb_drv_dip = dip; 2356139Sjb150015 return (DDI_SUCCESS); 2366139Sjb150015 } 2376139Sjb150015 ddi_remove_minor_node(dip, NULL); 2386139Sjb150015 } else { 2396139Sjb150015 cmn_err(CE_WARN, "smb_drv_attach:" 2406139Sjb150015 " failed creating minor node"); 2416139Sjb150015 } 2426139Sjb150015 } 2436139Sjb150015 } 2446139Sjb150015 return (DDI_FAILURE); 2456139Sjb150015 } 2466139Sjb150015 2476139Sjb150015 static int 2486139Sjb150015 smb_drv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 2496139Sjb150015 { 2506139Sjb150015 if (cmd == DDI_DETACH) { 2516139Sjb150015 ASSERT(dip == smb_drv_dip); 2526139Sjb150015 if (smb_server_svc_fini() == 0) { 2536139Sjb150015 ddi_remove_minor_node(dip, NULL); 2546139Sjb150015 smb_drv_dip = NULL; 2556139Sjb150015 return (DDI_SUCCESS); 2566139Sjb150015 } 2576139Sjb150015 } 2586139Sjb150015 return (DDI_FAILURE); 2596139Sjb150015 } 2605331Samw 2615331Samw /* ARGSUSED */ 2625331Samw static int 2635331Samw smb_drv_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 2645331Samw { 2655331Samw ulong_t instance = getminor((dev_t)arg); 2665331Samw 2675331Samw switch (cmd) { 2685331Samw case DDI_INFO_DEVT2DEVINFO: 2695331Samw *result = smb_drv_dip; 2705331Samw return (DDI_SUCCESS); 2715331Samw 2725331Samw case DDI_INFO_DEVT2INSTANCE: 2735331Samw *result = (void *)instance; 2745331Samw return (DDI_SUCCESS); 2755331Samw 2765331Samw default: 2775331Samw break; 2785331Samw } 2795331Samw 2805331Samw return (DDI_FAILURE); 2815331Samw } 282