da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
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 * CDDL HEADER END
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross/* How many iovec we'll handle as a local array (no allocation) */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define SMB_NEW_KID() atomic_inc_64_nv(&smb_kids)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * We track the keepalive in minutes, but this constant
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * specifies it in seconds, so convert to minutes.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossuint32_t smb_keep_alive = SMB_PI_KEEP_ALIVE_MIN / 60;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borregostatic void smb_session_cancel(smb_session_t *);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic int smb_session_xprt_puthdr(smb_session_t *,
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiserstatic smb_tree_t *smb_session_get_tree(smb_session_t *, smb_tree_t *);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic void smb_session_logoff(smb_session_t *);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbstatic void smb_request_init_command_mbuf(smb_request_t *sr);
f9bc6dadd79442185db5c8eb201c7475554fc7d7Dmitry.Savitsky@nexenta.comstatic void smb_session_genkey(smb_session_t *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Walk through the table and decrement each keep_alive
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * timer that has not timed out yet. (keepalive > 0)
4163af6adeecee26a894ae83a4ffbd3d0f2ec8f2jose borregosmb_session_correct_keep_alive_values(smb_llist_t *ll, uint32_t new_keep_alive)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Caller specifies seconds, but we track in minutes, so
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * convert to minutes (rounded up).
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * keep alive == 0 means do not drop connection if it's idle
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Walk through the table and set each session to the new keep_alive
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * value if they have not already timed out. Block clock interrupts.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Send a session message - supports SMB-over-NBT and SMB-over-TCP.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * If an mbuf chain is provided (optional), it will be freed and
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * set to NULL -- unconditionally! (error or not)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Builds a I/O vector (uio/iov) to do the send from mbufs, plus one
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * segment for the 4-byte NBT header.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rosssmb_session_send(smb_session_t *session, uint8_t nbt_type, mbuf_chain_t *mbc)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Setup the IOV. First, count the number of IOV segments
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * (plus one for the NBT header) and decide whether we
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * need to allocate an iovec or can use local_iov;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross while (m != NULL) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Build the iov list, meanwhile computing the length of
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * the SMB payload (to put in the NBT header).
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross while (m != NULL) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Set the NBT header, set uio_resid
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross rc = smb_session_xprt_puthdr(session, nbt_type, nbt_len,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smb_server_add_txb(session->s_server, (int64_t)uio.uio_resid);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Read, process and respond to a NetBIOS session request.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A NetBIOS session must be established for SMB-over-NetBIOS. Validate
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the calling and called name format and save the client NetBIOS name,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * which is used when a NetBIOS session is established to check for and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * cleanup leftover state from a previous session.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Session requests are not valid for SMB-over-TCP, which is unfortunate
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * because without the client name leftover state cannot be cleaned up
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * if the client is behind a NAT server.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rosssmb_netbios_session_request(struct smb_session *session)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw DTRACE_PROBE2(receive__session__req__xprthdr, struct session *, session,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (hdr.xh_length != NETBIOS_SESSION_REQUEST_DATA_LENGTH)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((rc = smb_sorecv(session->sock, names, hdr.xh_length)) != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw DTRACE_PROBE3(receive__session__req__data, struct session *, session,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) smb_session_send(session, NEGATIVE_SESSION_RESPONSE,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The client NetBIOS name is in oem codepage format.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * We need to convert it to unicode and store it in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * multi-byte format. We also need to strip off any
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * spaces added as part of the NetBIOS name encoding.
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown wbuf = kmem_alloc((SMB_PI_MAX_HOST * sizeof (smb_wchar_t)), KM_SLEEP);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown (void) oemtoucs(wbuf, client_name, SMB_PI_MAX_HOST, OEM_CPG_850);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown (void) smb_wcstombs(session->workstation, wbuf, SMB_PI_MAX_HOST);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown kmem_free(wbuf, (SMB_PI_MAX_HOST * sizeof (smb_wchar_t)));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *p = '\0';
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (smb_session_send(session, POSITIVE_SESSION_RESPONSE, NULL));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Read 4-byte header from the session socket and build an in-memory
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * session transport header. See smb_xprt_t definition for header
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * format information.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Direct hosted NetBIOS-less SMB (SMB-over-TCP) uses port 445. The
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * first byte of the four-byte header must be 0 and the next three
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * bytes contain the length of the remaining data.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_session_xprt_gethdr(smb_session_t *session, smb_xprt_t *ret_hdr)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if ((rc = smb_sorecv(session->sock, buf, NETBIOS_HDR_SZ)) != 0)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (rc);
49b5df1eac768235abeb210f61310e88b7d172b6Gordon Ross cmn_err(CE_WARN, "invalid NBT type (%u) from %s",
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego cmn_err(CE_WARN, "invalid port %u", session->s_local_port);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Encode a transport session packet header into a 4-byte buffer.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* Per RFC 1001, 1002: msg. len < 128KB */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross return (-1);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB over TCP is like NetBIOS but the one byte
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * message type is always zero, and the length
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * part is three bytes. It could actually use
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * longer messages, but this is conservative.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross return (-1);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego cmn_err(CE_WARN, "invalid port %u", session->s_local_port);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbstatic void
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross * Setup mbuf using the buffer we allocated.
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross MBC_ATTACH_BUF(&sr->command, sr->sr_request_buf, sr->sr_req_length);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_request_cancel
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Handle a cancel for a request properly depending on the current request
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This request is waiting on a lock. Wakeup everything
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * waiting on the lock so that the relevant thread regains
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * control and notices that is has been canceled. The
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * other lock request threads waiting on this lock will go
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * back to sleep when they discover they are still blocked.
ccc71be50bb49efb4e31004c77fb3e065e9c0596Gordon Ross * This request is waiting in change notify.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * No action required for these states since the request
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is completing.
4163af6adeecee26a894ae83a4ffbd3d0f2ec8f2jose borrego * smb_session_receiver
4163af6adeecee26a894ae83a4ffbd3d0f2ec8f2jose borrego * Receives request from the network and dispatches them to a worker.
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright if (session->s_local_port == IPPORT_NETBIOS_SSN) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw DTRACE_PROBE2(session__drop, struct session *, session, int, rc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * At this point everything related to the session should have been
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * cleaned up and we expect that nothing will attempt to use the
4163af6adeecee26a894ae83a4ffbd3d0f2ec8f2jose borrego * smb_session_disconnect
4163af6adeecee26a894ae83a4ffbd3d0f2ec8f2jose borrego * Disconnects the session passed in.
4163af6adeecee26a894ae83a4ffbd3d0f2ec8f2jose borrego session->s_state = SMB_SESSION_STATE_DISCONNECTED;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Read and process SMB requests.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Returns:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0 Success
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 1 Unable to read transport header
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 2 Invalid transport header type
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 3 Invalid SMB length (too small)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4 Unable to read SMB header
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 5 Invalid SMB header (bad magic number)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 6 Unable to read SMB data
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb for (;;) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (rc);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb DTRACE_PROBE2(session__receive__xprthdr, session_t *, session,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Anything other than SESSION_MESSAGE or
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * SESSION_KEEP_ALIVE is an error. A SESSION_REQUEST
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * may indicate a new session request but we need to
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * close this session and we can treat it as an error
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* zero length is another form of keep alive */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Allocate a request context, read the whole message.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* accounting: requests, received bytes */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Initialize command MBC to represent the received data.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb DTRACE_PROBE1(session__receive__smb, smb_request_t *, sr);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * This is the initial handler for new smb requests, called from
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * from smb_session_reader when we have not yet seen any requests.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * The first SMB request must be "negotiate", which determines
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * which protocol and dialect we'll be using. That's the ONLY
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * request type handled here, because with all later requests,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * we know the protocol and handle those with either the SMB1 or
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * SMB2 handlers: smb1sr_post() or smb2sr_post().
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Those do NOT allow SMB negotiate, because that's only allowed
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * as the first request on new session.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * This and other "post a request" handlers must either enqueue
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * the new request for the session taskq, or smb_request_free it
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * (in case we've decided to drop this connection). In this
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * (special) new request handler, we always free the request.
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright * Port will be IPPORT_NETBIOS_SSN or IPPORT_SMB.
7f667e74610492ddbce8ce60f52ece95d2401949jose borregosmb_session_create(ksocket_t new_so, uint16_t port, smb_server_t *sv,
8622ec4569457733001d4982ef7f5b44427069beGordon Ross session = kmem_cache_alloc(smb_cache_session, KM_SLEEP);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser if (smb_idpool_constructor(&session->s_tid_pool)) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross mutex_init(&session->s_credits_mutex, NULL, MUTEX_DEFAULT, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_slist_constructor(&session->s_req_list, sizeof (smb_request_t),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_llist_constructor(&session->s_user_list, sizeof (smb_user_t),
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser smb_llist_constructor(&session->s_tree_list, sizeof (smb_tree_t),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_llist_constructor(&session->s_xa_list, sizeof (smb_xa_t),
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * The initial new request handler is special,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * and only accepts negotiation requests.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* These may increase in SMB2 negotiate. */
4163af6adeecee26a894ae83a4ffbd3d0f2ec8f2jose borrego if (session->s_local_port == IPPORT_NETBIOS_SSN)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* All the request currently being treated must be canceled. */
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego smb_session_cancel_requests(session, NULL, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * We wait for the completion of all the requests associated with
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * this session.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * At this point the reference count of the users, trees, files,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * directories should be zero. It should be possible to destroy them
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * without any problem.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_session_logoff(session);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * Cancel requests. If a non-null tree is specified, only requests specific
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * to that tree will be cancelled. If a non-null sr is specified, that sr
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * will be not be cancelled - this would typically be the caller's sr.
12b65585e720714b31036daaa2b30eb76014048eGordon Ross * Find a user on the specified session by SMB UID.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statessmb_user_t *
12b65585e720714b31036daaa2b30eb76014048eGordon Rosssmb_session_lookup_uid(smb_session_t *session, uint16_t uid)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statessmb_user_t *
12b65585e720714b31036daaa2b30eb76014048eGordon Rosssmb_session_lookup_uid_st(smb_session_t *session, uint16_t uid,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_user_t *user;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_llist_t *user_list;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States SMB_SESSION_VALID(session);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States user_list = &session->s_user_list;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_llist_enter(user_list, RW_READER);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States user = smb_llist_head(user_list);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States while (user) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States SMB_USER_VALID(user);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States ASSERT(user->u_session == session);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
12b65585e720714b31036daaa2b30eb76014048eGordon Ross if (user->u_uid == uid && user->u_state == st) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States user = smb_llist_next(user_list, user);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_llist_exit(user_list);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesvoid
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statessmb_session_post_user(smb_session_t *session, smb_user_t *user)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States SMB_USER_VALID(user);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States ASSERT(user->u_refcnt == 0);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States ASSERT(user->u_state == SMB_USER_STATE_LOGGED_OFF);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States ASSERT(user->u_session == session);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_llist_post(&session->s_user_list, user, smb_user_delete);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States/*
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * Find a tree by tree-id.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States SMB_SESSION_VALID(session);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser smb_llist_enter(&session->s_tree_list, RW_READER);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser tree = smb_llist_next(&session->s_tree_list, tree);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * Find the first connected tree that matches the specified sharename.
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * If the specified tree is NULL the search starts from the beginning of
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * the user's tree list. If a tree is provided the search starts just
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * after that tree.
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser smb_llist_enter(&session->s_tree_list, RW_READER);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser tree = smb_llist_next(&session->s_tree_list, tree);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser if (smb_strcasecmp(tree->t_sharename, sharename, 0) == 0) {
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser tree = smb_llist_next(&session->s_tree_list, tree);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * Find the first connected tree that matches the specified volume name.
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * If the specified tree is NULL the search starts from the beginning of
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * the user's tree list. If a tree is provided the search starts just
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * after that tree.
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser smb_llist_enter(&session->s_tree_list, RW_READER);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser tree = smb_llist_next(&session->s_tree_list, tree);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser if (smb_strcasecmp(tree->t_volume, name, 0) == 0) {
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser tree = smb_llist_next(&session->s_tree_list, tree);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * Disconnect all trees that match the specified client process-id.
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser /* release the ref acquired during the traversal loop */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States/*
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * Disconnect all trees that this user has connected.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesvoid
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser smb_llist_t *tree_list = &session->s_tree_list;
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * smb_tree_hold() succeeded, hence we are in state
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * SMB_TREE_STATE_CONNECTED; schedule this tree
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * for asynchronous disconnect, which will fire
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * after we drop the llist traversal lock.
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser smb_llist_post(tree_list, tree, smb_session_tree_dtor);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser /* drop the lock and flush the dtor queue */
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * Disconnect all trees that this user has connected.
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * Disconnect all trees that match the specified share name.
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser tree = smb_session_lookup_share(session, sharename, NULL);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser smb_session_cancel_requests(session, tree, NULL);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser next = smb_session_lookup_share(session, sharename, tree);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keisersmb_session_post_tree(smb_session_t *session, smb_tree_t *tree)
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser ASSERT(tree->t_state == SMB_TREE_STATE_DISCONNECTED);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser smb_llist_post(&session->s_tree_list, tree, smb_tree_dealloc);
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * Get the next connected tree in the list. A reference is taken on
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * the tree, which can be released later with smb_tree_release().
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * If the specified tree is NULL the search starts from the beginning of
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * the tree list. If a tree is provided the search starts just after
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * Returns NULL if there are no connected trees in the list.
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser * Logoff all users associated with the specified session.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_user_t *user;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States SMB_SESSION_VALID(session);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_llist_enter(&session->s_user_list, RW_READER);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States user = smb_llist_head(&session->s_user_list);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States while (user) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States SMB_USER_VALID(user);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States ASSERT(user->u_session == session);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_user_release(user);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States user = smb_llist_next(&session->s_user_list, user);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_llist_exit(&session->s_user_list);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Copy the session workstation/client name to buf. If the workstation
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * is an empty string (which it will be on TCP connections), use the
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * client IP address.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brownsmb_session_getclient(smb_session_t *sn, char *buf, size_t buflen)
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Check whether or not the specified client name is the client of this
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * session. The name may be in UNC format (\\CLIENT).
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * A workstation/client name is setup on NBT connections as part of the
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * NetBIOS session request but that isn't available on TCP connections.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * If the session doesn't have a client name we typically return the
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * client IP address as the workstation name on MSRPC requests. So we
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * check for the IP address here in addition to the workstation name.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brownsmb_session_isclient(smb_session_t *sn, const char *client)
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown if (smb_strcasecmp(client, sn->workstation, 0) == 0)
49b5df1eac768235abeb210f61310e88b7d172b6Gordon Ross if (smb_strcasecmp(client, sn->ip_addr_str, 0) == 0)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * smb_request_alloc
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Allocate an smb_request_t structure from the kmem_cache. Partially
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * initialize the found/new request.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Returns pointer to a request
8622ec4569457733001d4982ef7f5b44427069beGordon Ross sr = kmem_cache_alloc(smb_cache_request, KM_SLEEP);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Future: Use constructor to pre-initialize some fields. For now
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * there are so many fields that it is easiest just to zero the
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * whole thing and start over.
ccc71be50bb49efb4e31004c77fb3e065e9c0596Gordon Ross cv_init(&sr->sr_ncr.nc_cv, NULL, CV_DEFAULT, NULL);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (sr);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * smb_request_free
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * release the memories which have been allocated for a smb request.
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borregosmb_session_oplocks_enable(smb_session_t *session)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshsmb_session_levelII_oplocks(smb_session_t *session)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* Clients using SMB2 and later always know about oplocks. */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* Older clients only do Level II oplocks if negotiated. */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if ((session->capabilities & CAP_LEVEL_II_OPLOCKS) != 0)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * smb_session_oplock_break
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Send an oplock break request to the client,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * recalling some cache delegation.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rosssmb_session_oplock_break(smb_request_t *sr, uint8_t brk)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Build the break message in sr->reply and then send it.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * The mbc is free'd later, in smb_request_free().
f9bc6dadd79442185db5c8eb201c7475554fc7d7Dmitry.Savitsky@nexenta.comsmb_session_genkey(smb_session_t *session)
f9bc6dadd79442185db5c8eb201c7475554fc7d7Dmitry.Savitsky@nexenta.com uint8_t tmp_key[SMB_CHALLENGE_SZ];
f9bc6dadd79442185db5c8eb201c7475554fc7d7Dmitry.Savitsky@nexenta.com (void) random_get_pseudo_bytes(tmp_key, SMB_CHALLENGE_SZ);
f9bc6dadd79442185db5c8eb201c7475554fc7d7Dmitry.Savitsky@nexenta.com bcopy(tmp_key, &session->challenge_key, SMB_CHALLENGE_SZ);
f9bc6dadd79442185db5c8eb201c7475554fc7d7Dmitry.Savitsky@nexenta.com session->challenge_len = SMB_CHALLENGE_SZ;
f9bc6dadd79442185db5c8eb201c7475554fc7d7Dmitry.Savitsky@nexenta.com (void) random_get_pseudo_bytes(tmp_key, 4);
f9bc6dadd79442185db5c8eb201c7475554fc7d7Dmitry.Savitsky@nexenta.com session->sesskey = tmp_key[0] | tmp_key[1] << 8 |
f9bc6dadd79442185db5c8eb201c7475554fc7d7Dmitry.Savitsky@nexenta.com tmp_key[2] << 16 | tmp_key[3] << 24;