xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb_echo.c (revision 7b59d02d2a384be9a08087b14defadd214b3c1dd)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <smbsrv/smb_incl.h>
29 
30 /*
31  * The echo request is used to test the connection to the server,
32  * and to see if the server is still responding.  The tid is ignored,
33  * so this request may be sent to the server even if there are no
34  * tree connections to the server.
35  *
36  * Each response echoes the data sent, though ByteCount may indicate
37  * no data. If echo-count is zero, no response is sent.
38  */
39 smb_sdrc_t
40 smb_com_echo(struct smb_request *sr)
41 {
42 	unsigned short necho;
43 	unsigned short nbytes;
44 	unsigned short i;
45 	struct mbuf_chain reply;
46 	char *data;
47 
48 	if (smbsr_decode_vwv(sr, "w", &necho) != 0)
49 		return (SDRC_ERROR_REPLY);
50 
51 	nbytes = sr->smb_bcc;
52 	data = smbsr_malloc(&sr->request_storage, nbytes);
53 
54 	if (smb_decode_mbc(&sr->smb_data, "#c", nbytes, data))
55 		return (SDRC_ERROR_REPLY);
56 
57 	for (i = 1; i <= necho; ++i) {
58 		MBC_INIT(&reply, SMB_HEADER_ED_LEN + 10 + nbytes);
59 
60 		(void) smb_encode_mbc(&reply, SMB_HEADER_ED_FMT,
61 		    sr->first_smb_com,
62 		    sr->smb_rcls,
63 		    sr->smb_reh,
64 		    sr->smb_err,
65 		    sr->smb_flg | SMB_FLAGS_REPLY,
66 		    sr->smb_flg2,
67 		    sr->smb_pid_high,
68 		    sr->smb_sig,
69 		    sr->smb_tid,
70 		    sr->smb_pid,
71 		    sr->smb_uid,
72 		    sr->smb_mid);
73 
74 		(void) smb_encode_mbc(&reply, "bww#c", 1, i,
75 		    nbytes, nbytes, data);
76 
77 		if (sr->session->signing.flags & SMB_SIGNING_ENABLED)
78 			smb_sign_reply(sr, &reply);
79 
80 		(void) smb_session_send(sr->session, 0, &reply);
81 	}
82 
83 	return (SDRC_NO_REPLY);
84 }
85 
86 /*
87  * Broadcast messages are not supported.
88  */
89 smb_sdrc_t /*ARGSUSED*/
90 smb_com_send_broadcast_message(struct smb_request *sr)
91 {
92 	return (SDRC_UNIMPLEMENTED);
93 }
94 
95 /*
96  * Multi-block messages are not supported.
97  */
98 smb_sdrc_t /*ARGSUSED*/
99 smb_com_send_end_mb_message(struct smb_request *sr)
100 {
101 	return (SDRC_UNIMPLEMENTED);
102 }
103 
104 /*
105  * Single-block messages are not supported.
106  */
107 smb_sdrc_t /*ARGSUSED*/
108 smb_com_send_single_message(struct smb_request *sr)
109 {
110 	return (SDRC_UNIMPLEMENTED);
111 }
112 
113 /*
114  * Multi-block messages are not supported.
115  */
116 smb_sdrc_t /*ARGSUSED*/
117 smb_com_send_start_mb_message(struct smb_request *sr)
118 {
119 	return (SDRC_UNIMPLEMENTED);
120 }
121 
122 /*
123  * Multi-block messages are not supported.
124  */
125 smb_sdrc_t /*ARGSUSED*/
126 smb_com_send_text_mb_message(struct smb_request *sr)
127 {
128 	return (SDRC_UNIMPLEMENTED);
129 }
130