smb_nt_create_andx.c revision faa1795a28a5c712eed6d0a3f84d98c368a316c6
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
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 * CDDL HEADER END
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma ident "%Z%%M% %I% %E% SMI"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This command is used to create or open a file or directory.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_com_nt_create_andx
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This command is used to create or open a file or directory.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Client Request Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ================================= ==================================
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR WordCount; Count of parameter words = 24
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AndXCommand; Secondary command; 0xFF = None
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AndXReserved; Reserved (must be 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT AndXOffset; Offset to next command WordCount
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR Reserved; Reserved (must be 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT NameLength; Length of Name[] in bytes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG Flags; Create bit set:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0x02 - Request an oplock
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0x04 - Request a batch oplock
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0x08 - Target of open must be
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * directory
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG RootDirectoryFid; If non-zero, open is relative to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * this directory
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ACCESS_MASK DesiredAccess; access desired
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * LARGE_INTEGER AllocationSize; Initial allocation size
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG ExtFileAttributes; File attributes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG ShareAccess; Type of share access
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG CreateDisposition; Action to take if file exists or
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG CreateOptions; Options to use if creating a file
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG ImpersonationLevel; Security QOS information
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR SecurityFlags; Security tracking mode flags:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0x1 - SECURITY_CONTEXT_TRACKING
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0x2 - SECURITY_EFFECTIVE_ONLY
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT ByteCount; Length of byte parameters
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * STRING Name[]; File to open or create
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The DesiredAccess parameter is specified in section 3.7 on Access Mask
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Encoding.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If no value is specified, it still allows an application to query
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * attributes without actually accessing the file.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The ExtFIleAttributes parameter specifies the file attributes and flags
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * for the file. The parameter's value is the sum of allowed attributes and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * flags defined in section 3.11 on Extended File Attribute Encoding
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The ShareAccess field Specifies how this file can be shared. This
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * parameter must be some combination of the following values:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Name Value Meaning
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0 Prevents the file from being shared.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FILE_SHARE_READ 0x00000001 Other open operations can be performed on
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the file for read access.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FILE_SHARE_WRITE 0x00000002 Other open operations can be performed on
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the file for write access.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FILE_SHARE_DELETE 0x00000004 Other open operations can be performed on
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the file for delete access.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The CreateDisposition parameter can contain one of the following values:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CREATE_NEW Creates a new file. The function fails if the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * specified file already exists.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CREATE_ALWAYS Creates a new file. The function overwrites the file
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * if it exists.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * OPEN_EXISTING Opens the file. The function fails if the file does
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * not exist.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * OPEN_ALWAYS Opens the file, if it exists. If the file does not
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * exist, act like CREATE_NEW.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TRUNCATE_EXISTING Opens the file. Once opened, the file is truncated so
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * that its size is zero bytes. The calling process must
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * open the file with at least GENERIC_WRITE access. The
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * function fails if the file does not exist.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The ImpersonationLevel parameter can contain one or more of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * following values:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SECURITY_ANONYMOUS Specifies to impersonate the client at the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Anonymous impersonation level.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SECURITY_IDENTIFICATION Specifies to impersonate the client at the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Identification impersonation level.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SECURITY_IMPERSONATION Specifies to impersonate the client at the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Impersonation impersonation level.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SECURITY_DELEGATION Specifies to impersonate the client at the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Delegation impersonation level.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The SecurityFlags parameter can have either of the following two flags
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SECURITY_CONTEXT_TRACKING Specifies that the security tracking mode is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * dynamic. If this flag is not specified,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Security Tracking Mode is static.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SECURITY_EFFECTIVE_ONLY Specifies that only the enabled aspects of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the client's security context are available
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to the server. If you do not specify this
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * flag, all aspects of the client's security
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * context are available. This flag allows the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * client to limit the groups and privileges
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * that a server can use while impersonating the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The response is as follows:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Server Response Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ================================= ==================================
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR WordCount; Count of parameter words = 26
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AndXCommand; Secondary 0xFF = None
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * command;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR AndXReserved; MBZ
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT AndXOffset; Offset to next command WordCount
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR OplockLevel; The oplock level granted
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0 - No oplock granted
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 1 - Exclusive oplock granted
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 2 - Batch oplock granted
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 3 - Level II oplock granted
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT Fid; The file ID
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG CreateAction; The action taken
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TIME CreationTime; The time the file was created
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TIME LastAccessTime; The time the file was accessed
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TIME LastWriteTime; The time the file was last written
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TIME ChangeTime; The time the file was last changed
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG ExtFileAttributes; The file attributes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * LARGE_INTEGER AllocationSize; The number of bytes allocated
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * LARGE_INTEGER EndOfFile; The end of file offset
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT FileType;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT DeviceState; state of IPC device (e.g. pipe)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * BOOLEAN Directory; TRUE if this is a directory
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT ByteCount; = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The following SMBs may follow SMB_COM_NT_CREATE_ANDX:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_READ SMB_COM_READ_ANDX
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_IOCTL
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (rc == 0) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (NameLength == 0) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb unsigned char OplockLevel;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb unsigned char DirFlag;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Set up the directory flag and ensure that
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * we don't return a stale file size.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw node->attr.sa_vattr.va_size = new_attr.sa_vattr.va_size;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb rc = smbsr_encode_result(sr, 34, 0, "bb.wbwlTTTTlqqwwbw",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Named PIPE */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb rc = smbsr_encode_result(sr, 34, 0, "bb.wbwlqqqqlqqwwbw",