smb_tree_connect.c revision 7b59d02d2a384be9a08087b14defadd214b3c1dd
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/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma ident "%Z%%M% %I% %E% SMI"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: tree_connect
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When a client connects to a server resource, an SMB_COM_TREE_CONNECT
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * message is generated to the server. This command is almost exactly like
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_TREE_CONNECT_ANDX, except that no AndX command may follow; see
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * section 4.1.4.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Client Request Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ================================== =================================
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR WordCount; Count of parameter words = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT ByteCount; Count of data bytes; min = 4
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR BufferFormat1; 0x04
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING Path[]; Server name and share name
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR BufferFormat2; 0x04
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING Password[]; Password
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR BufferFormat3; 0x04
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING Service[]; Service name
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The CIFS server responds with:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Server Response Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ================================ =================================
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR WordCount; Count of parameter words = 2
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT MaxBufferSize; Max size message the server handles
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT Tid; Tree ID
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT ByteCount; Count of data bytes = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the negotiated dialect is MICROSOFT NETWORKS 1.03 or earlier,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * MaxBufferSize in the response message indicates the maximum size message
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * that the server can handle. The client should not generate messages,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * nor expect to receive responses, larger than this. This must be
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * constant for a given server. For newer dialects, this field is ignored.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Tid should be included in any future SMBs referencing this tree
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * connection.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/smb_incl.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * If the negotiated dialect is MICROSOFT NETWORKS 1.03 or earlier,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * MaxBufferSize in the response message indicates the maximum size
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * message that the server can handle. The client should not generate
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * messages, nor expect to receive responses, larger than this. This
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * must be constant for a given server. For newer dialects, this field
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * is ignored.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_sdrc_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_com_tree_connect(struct smb_request *sr)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb int rc;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Perhaps this should be "%A.sA" now that unicode is enabled.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb rc = smbsr_decode_data(sr, "%AAA", sr, &sr->arg.tcon.path,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb &sr->arg.tcon.password, &sr->arg.tcon.service);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (rc != 0)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (SDRC_ERROR_REPLY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->arg.tcon.flags = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (smbsr_connect_tree(sr) != 0)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (SDRC_ERROR_REPLY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb rc = smbsr_encode_result(sr, 2, 0, "bwww",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 2, /* wct */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (WORD)smb_maxbufsize, /* MaxBufferSize */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_tid, /* TID */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0); /* bcc */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return ((rc == 0) ? SDRC_NORMAL_REPLY : SDRC_ERROR_REPLY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}