da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or http://www.opensolaris.org/os/licensing.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
12b65585e720714b31036daaa2b30eb76014048eGordon Ross * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/types.h>
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#include <sys/conf.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/ddi.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/modctl.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/cred.h>
08344b293eab865a57e4629b178f2003dced397eGordon Ross#include <sys/disp.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/ioccom.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/policy.h>
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wright#include <sys/cmn_err.h>
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/smb_kproto.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/smb_ioctl.h>
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#ifdef _FAKE_KERNEL
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#error "See libfksmbsrv"
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#endif /* _FAKE_KERNEL */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_drv_open(dev_t *, int, int, cred_t *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_drv_close(dev_t, int, int, cred_t *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int smb_drv_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbstatic int smb_drv_attach(dev_info_t *, ddi_attach_cmd_t);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbstatic int smb_drv_detach(dev_info_t *, ddi_detach_cmd_t);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbstatic int smb_drv_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * *****************************************************************************
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * ****************************** Global Variables *****************************
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * *****************************************************************************
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb *
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * These variables can only be changed through the /etc/system file.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb/*
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Maximum buffer size for NT: configurable based on the client environment.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * IR104720 Experiments with Windows 2000 indicate that we achieve better
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * SmbWriteX performance with a buffer size of 64KB instead of the 37KB used
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * with Windows NT4.0. Previous experiments with NT4.0 resulted in directory
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * listing problems so this buffer size is configurable based on the end-user
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * environment. When in doubt use 37KB.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbint smb_maxbufsize = SMB_NT_MAXBUF;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshint smb_oplock_levelII = 1;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borregoint smb_oplock_timeout = OPLOCK_STD_TIMEOUT;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshint smb_oplock_min_timeout = OPLOCK_MIN_TIMEOUT;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbint smb_flush_required = 1;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbint smb_dirsymlink_enable = 1;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borregoint smb_sign_debug = 0;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshint smb_shortnames = 1;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borregouint_t smb_audit_flags =
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego#ifdef DEBUG
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego SMB_AUDIT_NODE;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego#else
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego 0;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego#endif
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh/*
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Maximum number of simultaneous authentication, share mapping, pipe open
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * requests to be processed.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh */
12b65585e720714b31036daaa2b30eb76014048eGordon Rossint smb_ssetup_threshold = SMB_AUTHSVC_MAXTHREAD;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshint smb_tcon_threshold = 1024;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshint smb_opipe_threshold = 1024;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh/*
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Number of milliseconds that a request will be stalled if it comes in after
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * the maximum number of inflight operations are being proccessed.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh */
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshint smb_ssetup_timeout = (30 * 1000);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshint smb_tcon_timeout = (30 * 1000);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshint smb_opipe_timeout = (30 * 1000);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
08344b293eab865a57e4629b178f2003dced397eGordon Ross/*
08344b293eab865a57e4629b178f2003dced397eGordon Ross * Thread priorities used in smbsrv. Our threads spend most of their time
08344b293eab865a57e4629b178f2003dced397eGordon Ross * blocked on various conditions. However, if the system gets heavy load,
08344b293eab865a57e4629b178f2003dced397eGordon Ross * the scheduler has to choose an order to run these. We want the order:
08344b293eab865a57e4629b178f2003dced397eGordon Ross * (a) timers, (b) notifications, (c) workers, (d) receivers (and etc.)
08344b293eab865a57e4629b178f2003dced397eGordon Ross * where notifications are oplock and change notify work. Aside from this
08344b293eab865a57e4629b178f2003dced397eGordon Ross * relative ordering, smbsrv threads should run with a priority close to
08344b293eab865a57e4629b178f2003dced397eGordon Ross * that of normal user-space threads (thus minclsyspri below), just like
08344b293eab865a57e4629b178f2003dced397eGordon Ross * NFS and other "file service" kinds of processing.
08344b293eab865a57e4629b178f2003dced397eGordon Ross */
08344b293eab865a57e4629b178f2003dced397eGordon Rossint smbsrv_base_pri = MINCLSYSPRI;
08344b293eab865a57e4629b178f2003dced397eGordon Rossint smbsrv_listen_pri = MINCLSYSPRI;
08344b293eab865a57e4629b178f2003dced397eGordon Rossint smbsrv_receive_pri = MINCLSYSPRI;
08344b293eab865a57e4629b178f2003dced397eGordon Rossint smbsrv_worker_pri = MINCLSYSPRI + 1;
08344b293eab865a57e4629b178f2003dced397eGordon Rossint smbsrv_notify_pri = MINCLSYSPRI + 2;
08344b293eab865a57e4629b178f2003dced397eGordon Rossint smbsrv_timer_pri = MINCLSYSPRI + 5;
08344b293eab865a57e4629b178f2003dced397eGordon Ross
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb/*
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * *****************************************************************************
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * ********************** Static Variables / Module Linkage ********************
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * *****************************************************************************
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic struct cb_ops cbops = {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_drv_open, /* cb_open */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_drv_close, /* cb_close */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* cb_strategy */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* cb_print */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* cb_dump */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* cb_read */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* cb_write */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_drv_ioctl, /* cb_ioctl */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* cb_devmap */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* cb_mmap */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* cb_segmap */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nochpoll, /* cb_chpoll */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ddi_prop_op, /* cb_prop_op */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NULL, /* cb_streamtab */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw D_MP, /* cb_flag */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw CB_REV, /* cb_rev */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* cb_aread */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* cb_awrite */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic struct dev_ops devops = {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw DEVO_REV, /* devo_rev */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, /* devo_refcnt */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_drv_getinfo, /* devo_getinfo */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nulldev, /* devo_identify */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nulldev, /* devo_probe */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_drv_attach, /* devo_attach */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_drv_detach, /* devo_detach */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nodev, /* devo_reset */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &cbops, /* devo_cb_ops */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NULL, /* devo_bus_ops */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NULL, /* devo_power */
193974072f41a843678abf5f61979c748687e66bSherry Moore ddi_quiesce_not_needed, /* devo_quiesce */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic struct modldrv modldrv = {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &mod_driverops, /* drv_modops */
193974072f41a843678abf5f61979c748687e66bSherry Moore "CIFS Server Protocol", /* drv_linkinfo */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &devops,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic struct modlinkage modlinkage = {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw MODREV_1, /* revision of the module, must be: MODREV_1 */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &modldrv, /* ptr to linkage structures */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NULL,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic dev_info_t *smb_drv_dip = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * ****************************************************************************
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Module Interface
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * ****************************************************************************
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw_init(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright int rc;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
8622ec4569457733001d4982ef7f5b44427069beGordon Ross if ((rc = smb_server_g_init()) != 0) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright return (rc);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if ((rc = mod_install(&modlinkage)) != 0) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smb_server_g_fini();
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego return (rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw_info(struct modinfo *modinfop)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (mod_info(&modlinkage, modinfop));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw_fini(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego int rc;
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (smb_server_get_count() != 0)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross return (EBUSY);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if ((rc = mod_remove(&modlinkage)) == 0) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smb_server_g_fini();
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego return (rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * ****************************************************************************
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Pseudo Device Entry Points
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * ****************************************************************************
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* ARGSUSED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
8622ec4569457733001d4982ef7f5b44427069beGordon Rosssmb_drv_open(dev_t *devp, int flag, int otyp, cred_t *cr)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
8622ec4569457733001d4982ef7f5b44427069beGordon Ross zoneid_t zid;
8622ec4569457733001d4982ef7f5b44427069beGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Check caller's privileges.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
8622ec4569457733001d4982ef7f5b44427069beGordon Ross if (secpolicy_smb(cr) != 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (EPERM);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8622ec4569457733001d4982ef7f5b44427069beGordon Ross /*
8622ec4569457733001d4982ef7f5b44427069beGordon Ross * We need a unique minor per zone otherwise an smbd in any other
8622ec4569457733001d4982ef7f5b44427069beGordon Ross * zone will keep this minor open and we won't get a close call.
8622ec4569457733001d4982ef7f5b44427069beGordon Ross * The zone ID is good enough as a minor number.
8622ec4569457733001d4982ef7f5b44427069beGordon Ross */
8622ec4569457733001d4982ef7f5b44427069beGordon Ross zid = crgetzoneid(cr);
8622ec4569457733001d4982ef7f5b44427069beGordon Ross if (zid < 0)
8622ec4569457733001d4982ef7f5b44427069beGordon Ross return (ENODEV);
8622ec4569457733001d4982ef7f5b44427069beGordon Ross *devp = makedevice(getmajor(*devp), zid);
8622ec4569457733001d4982ef7f5b44427069beGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Start SMB service state machine
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (smb_server_create());
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* ARGSUSED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_drv_close(dev_t dev, int flag, int otyp, cred_t *credp)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (smb_server_delete());
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb/* ARGSUSED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wrightsmb_drv_ioctl(dev_t drv, int cmd, intptr_t argp, int flags, cred_t *cred,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb int *retval)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smb_ioc_t *ioc;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smb_ioc_header_t ioc_hdr;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright uint32_t crc;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright boolean_t copyout = B_FALSE;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb int rc = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (ddi_copyin((const void *)argp, &ioc_hdr, sizeof (smb_ioc_header_t),
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright flags) || (ioc_hdr.version != SMB_IOC_VERSION))
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (EFAULT);
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright crc = ioc_hdr.crc;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright ioc_hdr.crc = 0;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (smb_crc_gen((uint8_t *)&ioc_hdr, sizeof (ioc_hdr)) != crc)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright return (EFAULT);
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright ioc = kmem_alloc(ioc_hdr.len, KM_SLEEP);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (ddi_copyin((const void *)argp, ioc, ioc_hdr.len, flags)) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright kmem_free(ioc, ioc_hdr.len);
94fff7907278e4540aa7abee2b1b0ea71d36f7faAlan Wright return (EFAULT);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb switch (cmd) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb case SMB_IOC_CONFIG:
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smb_server_configure(&ioc->ioc_cfg);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb break;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb case SMB_IOC_START:
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smb_server_start(&ioc->ioc_start);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb break;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States case SMB_IOC_STOP:
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States rc = smb_server_stop();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States break;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States case SMB_IOC_EVENT:
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States rc = smb_server_notify_event(&ioc->ioc_event);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States break;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb case SMB_IOC_GMTOFF:
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = smb_server_set_gmtoff(&ioc->ioc_gmt);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright break;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright case SMB_IOC_SHARE:
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright rc = smb_kshare_export_list(&ioc->ioc_share);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright break;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright case SMB_IOC_UNSHARE:
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright rc = smb_kshare_unexport_list(&ioc->ioc_share);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright break;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh case SMB_IOC_SHAREINFO:
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh rc = smb_kshare_info(&ioc->ioc_shareinfo);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh copyout = B_TRUE;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh break;
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown case SMB_IOC_NUMOPEN:
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown rc = smb_server_numopen(&ioc->ioc_opennum);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright copyout = B_TRUE;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright break;
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown case SMB_IOC_SVCENUM:
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown rc = smb_server_enum(&ioc->ioc_svcenum);
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright copyout = B_TRUE;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb break;
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown case SMB_IOC_SESSION_CLOSE:
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown rc = smb_server_session_close(&ioc->ioc_session);
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown break;
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown case SMB_IOC_FILE_CLOSE:
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown rc = smb_server_file_close(&ioc->ioc_fileid);
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown break;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh case SMB_IOC_SPOOLDOC:
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh rc = smb_server_spooldoc(&ioc->ioc_spooldoc);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh copyout = B_TRUE;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh break;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb default:
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb rc = ENOTTY;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if ((rc == 0) && copyout) {
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright if (ddi_copyout((const void *)ioc, (void *)argp, ioc_hdr.len,
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright flags))
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright rc = EFAULT;
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright }
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright kmem_free(ioc, ioc_hdr.len);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * ****************************************************************************
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Pseudo Device Operations
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * ****************************************************************************
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbstatic int
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_drv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (cmd == DDI_ATTACH) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb /* we only allow instance 0 to attach */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (ddi_get_instance(dip) == 0) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb /* create the minor node */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (ddi_create_minor_node(dip, "smbsrv", S_IFCHR, 0,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb DDI_PSEUDO, 0) == DDI_SUCCESS) {
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego smb_drv_dip = dip;
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego return (DDI_SUCCESS);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb } else {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb cmn_err(CE_WARN, "smb_drv_attach:"
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb " failed creating minor node");
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (DDI_FAILURE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_drv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (cmd == DDI_DETACH) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb ASSERT(dip == smb_drv_dip);
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego ddi_remove_minor_node(dip, NULL);
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego smb_drv_dip = NULL;
f9a15d2c042edba37d61b071eb7ea274eb2754d1jose borrego return (DDI_SUCCESS);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (DDI_FAILURE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb/* ARGSUSED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_drv_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb ulong_t instance = getminor((dev_t)arg);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb switch (cmd) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb case DDI_INFO_DEVT2DEVINFO:
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb *result = smb_drv_dip;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (DDI_SUCCESS);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb case DDI_INFO_DEVT2INSTANCE:
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb *result = (void *)instance;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (DDI_SUCCESS);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb default:
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (DDI_FAILURE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}