xref: /titanic_52/usr/src/uts/common/fs/smbsrv/smb_echo.c (revision 799823bbed51a695d01e13511bbb1369980bb714)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <smbsrv/smb_kproto.h>
27 
28 /*
29  * The echo request is used to test the connection to the server,
30  * and to see if the server is still responding.  The tid is ignored,
31  * so this request may be sent to the server even if there are no
32  * tree connections to the server.
33  *
34  * Each response echoes the data sent, though ByteCount may indicate
35  * no data. If echo-count is zero, no response is sent.
36  */
37 smb_sdrc_t
38 smb_pre_echo(smb_request_t *sr)
39 {
40 	DTRACE_SMB_1(op__Echo__start, smb_request_t *, sr);
41 	return (SDRC_SUCCESS);
42 }
43 
44 void
45 smb_post_echo(smb_request_t *sr)
46 {
47 	DTRACE_SMB_1(op__Echo__done, smb_request_t *, sr);
48 }
49 
50 static unsigned short smb_max_echo = 10;
51 
52 smb_sdrc_t
53 smb_com_echo(struct smb_request *sr)
54 {
55 	unsigned short necho;
56 	unsigned short nbytes;
57 	unsigned short i;
58 	struct mbuf_chain reply;
59 	char *data;
60 
61 	if (smbsr_decode_vwv(sr, "w", &necho) != 0)
62 		return (SDRC_ERROR);
63 
64 	/*
65 	 * Don't let the client fool us into doing
66 	 * more work than is "reasonable".
67 	 */
68 	if (necho > smb_max_echo)
69 		necho = smb_max_echo;
70 
71 	nbytes = sr->smb_bcc;
72 	data = smb_srm_zalloc(sr, nbytes);
73 
74 	if (smb_mbc_decodef(&sr->smb_data, "#c", nbytes, data))
75 		return (SDRC_ERROR);
76 
77 	for (i = 1; i <= necho; ++i) {
78 
79 		/*
80 		 * According to [MS-CIFS] 3.3.5.32 echo is
81 		 * subject to cancellation.
82 		 */
83 		if (sr->sr_state != SMB_REQ_STATE_ACTIVE)
84 			break;
85 
86 		MBC_INIT(&reply, SMB_HEADER_ED_LEN + 10 + nbytes);
87 
88 		(void) smb_mbc_encodef(&reply, SMB_HEADER_ED_FMT,
89 		    sr->first_smb_com,
90 		    sr->smb_rcls,
91 		    sr->smb_reh,
92 		    sr->smb_err,
93 		    sr->smb_flg | SMB_FLAGS_REPLY,
94 		    sr->smb_flg2,
95 		    sr->smb_pid_high,
96 		    sr->smb_sig,
97 		    sr->smb_tid,
98 		    sr->smb_pid,
99 		    sr->smb_uid,
100 		    sr->smb_mid);
101 
102 		(void) smb_mbc_encodef(&reply, "bww#c", 1, i,
103 		    nbytes, nbytes, data);
104 
105 		if (sr->session->signing.flags & SMB_SIGNING_ENABLED)
106 			smb_sign_reply(sr, &reply);
107 
108 		(void) smb_session_send(sr->session, 0, &reply);
109 
110 		delay(MSEC_TO_TICK(100));
111 	}
112 
113 	return (SDRC_NO_REPLY);
114 }
115