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/*
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross *
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/smb_kproto.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The echo request is used to test the connection to the server,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and to see if the server is still responding. The tid is ignored,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * so this request may be sent to the server even if there are no
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * tree connections to the server.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Each response echoes the data sent, though ByteCount may indicate
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * no data. If echo-count is zero, no response is sent.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_sdrc_t
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_pre_echo(smb_request_t *sr)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb DTRACE_SMB_1(op__Echo__start, smb_request_t *, sr);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_SUCCESS);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb}
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbvoid
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_post_echo(smb_request_t *sr)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb DTRACE_SMB_1(op__Echo__done, smb_request_t *, sr);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb}
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
7f3ef643e446c82e27a9386991b140b128baf22cGordon Rossstatic unsigned short smb_max_echo = 10;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_sdrc_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_com_echo(struct smb_request *sr)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short necho;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short nbytes;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct mbuf_chain reply;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *data;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross uint16_t pid_hi, pid_lo;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross pid_hi = sr->smb_pid >> 16;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross pid_lo = (uint16_t)sr->smb_pid;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (smbsr_decode_vwv(sr, "w", &necho) != 0)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross /*
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross * Don't let the client fool us into doing
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross * more work than is "reasonable".
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross */
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (necho > smb_max_echo)
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross necho = smb_max_echo;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nbytes = sr->smb_bcc;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States data = smb_srm_zalloc(sr, nbytes);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (smb_mbc_decodef(&sr->smb_data, "#c", nbytes, data))
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 1; i <= necho; ++i) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross /*
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross * According to [MS-CIFS] 3.3.5.32 echo is
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross * subject to cancellation.
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross */
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (sr->sr_state != SMB_REQ_STATE_ACTIVE)
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross break;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw MBC_INIT(&reply, SMB_HEADER_ED_LEN + 10 + nbytes);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw (void) smb_mbc_encodef(&reply, SMB_HEADER_ED_FMT,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->first_smb_com,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_rcls,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_reh,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_err,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_flg | SMB_FLAGS_REPLY,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_flg2,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross pid_hi,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_sig,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_tid,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross pid_lo,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_uid,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_mid);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw (void) smb_mbc_encodef(&reply, "bww#c", 1, i,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nbytes, nbytes, data);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (sr->session->signing.flags & SMB_SIGNING_ENABLED)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_sign_reply(sr, &reply);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) smb_session_send(sr->session, 0, &reply);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross delay(MSEC_TO_TICK(100));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SDRC_NO_REPLY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}