smb_echo.c revision bbf6f00c25b6a2bed23c35eac6d62998ecdb338c
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/*
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
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
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;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (smbsr_decode_vwv(sr, "w", &necho) != 0)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nbytes = sr->smb_bcc;
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown data = smb_srm_alloc(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) {
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,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_pid_high,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_sig,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_tid,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_pid,
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);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SDRC_NO_REPLY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}