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/*
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
b24e356b384ccc80805e7150979de2373d44347cPeer Dampmann * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This command is used to create or open a file or directory.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/smb_kproto.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/smb_fsops.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/smb_vops.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_com_nt_create_andx
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This command is used to create or open a file or directory.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Client Request Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ================================= ==================================
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 * not
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The DesiredAccess parameter is specified in section 3.7 on Access Mask
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Encoding.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If no value is specified, it still allows an application to query
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * attributes without actually accessing the file.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The ShareAccess field Specifies how this file can be shared. This
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * parameter must be some combination of the following values:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The CreateDisposition parameter can contain one of the following values:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The ImpersonationLevel parameter can contain one or more of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * following values:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The SecurityFlags parameter can have either of the following two flags
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * set:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
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 * client.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The response is as follows:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Server Response Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ================================= ==================================
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 *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The following SMBs may follow SMB_COM_NT_CREATE_ANDX:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_READ SMB_COM_READ_ANDX
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB_COM_IOCTL
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_sdrc_t
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_pre_nt_create_andx(smb_request_t *sr)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb struct open_param *op = &sr->arg.open;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb uint8_t SecurityFlags;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb uint32_t ImpersonationLevel;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb uint16_t NameLength;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int rc;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb bzero(op, sizeof (sr->arg.open));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smbsr_decode_vwv(sr, "5.wlllqlllllb",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &NameLength,
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego &op->nt_flags,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb &op->rootdirfid,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &op->desired_access,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &op->dsize,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb &op->dattr,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &op->share_access,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &op->create_disposition,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &op->create_options,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &ImpersonationLevel,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &SecurityFlags);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (rc == 0) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (NameLength == 0) {
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States op->fqi.fq_path.pn_path = "\\";
b24e356b384ccc80805e7150979de2373d44347cPeer Dampmann } else if (NameLength >= SMB_MAXPATHLEN) {
b24e356b384ccc80805e7150979de2373d44347cPeer Dampmann smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb ERRDOS, ERROR_PATH_NOT_FOUND);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb rc = -1;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb } else {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb rc = smbsr_decode_data(sr, "%#u", sr, NameLength,
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States &op->fqi.fq_path.pn_path);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego op->op_oplock_level = SMB_OPLOCK_NONE;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego if (op->nt_flags & NT_CREATE_FLAG_REQUEST_OPLOCK) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego if (op->nt_flags & NT_CREATE_FLAG_REQUEST_OPBATCH)
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego op->op_oplock_level = SMB_OPLOCK_BATCH;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego else
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego op->op_oplock_level = SMB_OPLOCK_EXCLUSIVE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb DTRACE_SMB_2(op__NtCreateX__start, smb_request_t *, sr,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb struct open_param *, op);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb}
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbvoid
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_post_nt_create_andx(smb_request_t *sr)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb DTRACE_SMB_1(op__NtCreateX__done, smb_request_t *, sr);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown if (sr->arg.open.dir != NULL) {
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown smb_ofile_release(sr->arg.open.dir);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown sr->arg.open.dir = NULL;
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb}
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_sdrc_t
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_com_nt_create_andx(struct smb_request *sr)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb struct open_param *op = &sr->arg.open;
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross smb_attr_t *ap = &op->fqi.fq_fattr;
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross smb_ofile_t *of;
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross int rc;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb unsigned char DirFlag;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross uint32_t status;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if ((op->create_options & FILE_DELETE_ON_CLOSE) &&
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb !(op->desired_access & DELETE)) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego ERRDOS, ERRbadaccess);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego return (SDRC_ERROR);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego }
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego if (op->create_disposition > FILE_MAXIMUM_DISPOSITION) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego ERRDOS, ERRbadaccess);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (op->dattr & FILE_FLAG_WRITE_THROUGH)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->create_options |= FILE_WRITE_THROUGH;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (op->dattr & FILE_FLAG_DELETE_ON_CLOSE)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->create_options |= FILE_DELETE_ON_CLOSE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (op->dattr & FILE_FLAG_BACKUP_SEMANTICS)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States op->create_options |= FILE_OPEN_FOR_BACKUP_INTENT;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States if (op->create_options & FILE_OPEN_FOR_BACKUP_INTENT)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States sr->user_cr = smb_user_getprivcred(sr->uid_user);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (op->rootdirfid == 0) {
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States op->fqi.fq_dnode = sr->tid_tree->t_snode;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
3b13a1ef7511135ec0c75b5f94de8075454efd79Thomas Keiser op->dir = smb_ofile_lookup_by_fid(sr, (uint16_t)op->rootdirfid);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown if (op->dir == NULL) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ERRDOS, ERRbadfid);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown op->fqi.fq_dnode = op->dir->f_node;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh op->op_oplock_levelII = B_TRUE;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross status = smb_common_open(sr);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (status != NT_STATUS_SUCCESS) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smbsr_status(sr, status, 0, 0);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross /*
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross * NB: after the above smb_common_open() success,
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross * we have a handle allocated (sr->fid_ofile).
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross * If we don't return success, we must close it.
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross */
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross of = sr->fid_ofile;
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright switch (sr->tid_tree->t_res_type & STYPE_MASK) {
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright case STYPE_DISKTREE:
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright case STYPE_PRINTQ:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (op->create_options & FILE_DELETE_ON_CLOSE)
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross smb_ofile_set_delete_on_close(of);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross DirFlag = smb_node_is_dir(of->f_node) ? 1 : 0;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb rc = smbsr_encode_result(sr, 34, 0, "bb.wbwlTTTTlqqwwbw",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 34,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->andx_com,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0x67,
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh op->op_oplock_level,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_fid,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->action_taken,
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross &ap->sa_crtime,
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross &ap->sa_vattr.va_atime,
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross &ap->sa_vattr.va_mtime,
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross &ap->sa_vattr.va_ctime,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->dattr & FILE_ATTRIBUTE_MASK,
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross ap->sa_allocsz,
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross ap->sa_vattr.va_size,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->ftype,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->devstate,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw DirFlag,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0);
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright break;
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright case STYPE_IPC:
7b59d02d2a384be9a08087b14defadd214b3c1ddjb rc = smbsr_encode_result(sr, 34, 0, "bb.wbwlqqqqlqqwwbw",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 34,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->andx_com,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0x67,
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh 0,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_fid,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->action_taken,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0LL,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0LL,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0LL,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0LL,
3db3f65c6274eb042354801a308c8e9bc4994553amw FILE_ATTRIBUTE_NORMAL,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0x1000LL,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0LL,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->ftype,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->devstate,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0);
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright break;
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright default:
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright smbsr_error(sr, NT_STATUS_INVALID_DEVICE_REQUEST,
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright ERRDOS, ERROR_INVALID_FUNCTION);
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross goto errout;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross if (rc == 0)
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross return (SDRC_SUCCESS);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Rosserrout:
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross smb_ofile_close(of, 0);
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross return (SDRC_ERROR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}