xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb_echo.c (revision bea83d026ee1bd1b2a2419e1d0232f107a5d7d9b)
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 2007 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 int
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 		smbsr_decode_error(sr);
50 		/* NOTREACHED */
51 	}
52 
53 	nbytes = sr->smb_bcc;
54 
55 	data = smbsr_malloc(&sr->request_storage, nbytes);
56 
57 	(void) smb_decode_mbc(&sr->smb_data, "#c", nbytes, data);
58 
59 	for (i = 1; i <= necho; ++i) {
60 
61 		MBC_INIT(&reply, SMB_HEADER_ED_LEN + 10 + nbytes);
62 
63 		(void) smb_encode_mbc(&reply, SMB_HEADER_ED_FMT,
64 		    sr->first_smb_com,
65 		    sr->smb_rcls,
66 		    sr->smb_reh,
67 		    sr->smb_err,
68 		    sr->smb_flg | SMB_FLAGS_REPLY,
69 		    sr->smb_flg2,
70 		    sr->smb_pid_high,
71 		    sr->smb_sig,
72 		    sr->smb_tid,
73 		    sr->smb_pid,
74 		    sr->smb_uid,
75 		    sr->smb_mid);
76 
77 		(void) smb_encode_mbc(&reply, "bww#c", 1, i,
78 		    nbytes, nbytes, data);
79 
80 		if (sr->session->signing.flags & SMB_SIGNING_ENABLED)
81 			smb_sign_reply(sr, &reply);
82 
83 		(void) smb_session_send(sr->session, 0, &reply);
84 	}
85 
86 	return (SDRC_NO_REPLY);
87 }
88 
89 /*
90  * Broadcast messages are not supported.
91  */
92 int /*ARGSUSED*/
93 smb_com_send_broadcast_message(struct smb_request *sr)
94 {
95 	return (SDRC_UNIMPLEMENTED);
96 }
97 
98 /*
99  * Multi-block messages are not supported.
100  */
101 int /*ARGSUSED*/
102 smb_com_send_end_mb_message(struct smb_request *sr)
103 {
104 	return (SDRC_UNIMPLEMENTED);
105 }
106 
107 /*
108  * Single-block messages are not supported.
109  */
110 int /*ARGSUSED*/
111 smb_com_send_single_message(struct smb_request *sr)
112 {
113 	return (SDRC_UNIMPLEMENTED);
114 }
115 
116 /*
117  * Multi-block messages are not supported.
118  */
119 int /*ARGSUSED*/
120 smb_com_send_start_mb_message(struct smb_request *sr)
121 {
122 	return (SDRC_UNIMPLEMENTED);
123 }
124 
125 /*
126  * Multi-block messages are not supported.
127  */
128 int /*ARGSUSED*/
129 smb_com_send_text_mb_message(struct smb_request *sr)
130 {
131 	return (SDRC_UNIMPLEMENTED);
132 }
133