smb_common_open.c revision 148c5f43199ca0b43fc8e3b643aab11cd66ea327
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 */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This module provides the common open functionality to the various
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * open and create SMB interface functions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <sys/types.h>
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <sys/cmn_err.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/fcntl.h>
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as#include <sys/nbmlock.h>
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/string.h>
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/smb_kproto.h>
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/smb_fsops.h>
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/smbinfo.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbvolatile uint32_t smb_fids = 0;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic uint32_t smb_open_subr(smb_request_t *);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbextern uint32_t smb_is_executable(char *);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic void smb_delete_new_object(smb_request_t *);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintoshstatic int smb_set_open_timestamps(smb_request_t *, smb_ofile_t *, boolean_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_access_generic_to_file
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Search MSDN for IoCreateFile to see following mapping.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * GENERIC_READ STANDARD_RIGHTS_READ, FILE_READ_DATA,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FILE_READ_ATTRIBUTES and FILE_READ_EA
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * GENERIC_WRITE STANDARD_RIGHTS_WRITE, FILE_WRITE_DATA,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FILE_WRITE_ATTRIBUTES, FILE_WRITE_EA, and FILE_APPEND_DATA
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * GENERIC_EXECUTE STANDARD_RIGHTS_EXECUTE, SYNCHRONIZE, and FILE_EXECUTE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwuint32_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_access_generic_to_file(uint32_t desired_access)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t access = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (desired_access & GENERIC_ALL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FILE_ALL_ACCESS & ~SYNCHRONIZE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (desired_access & GENERIC_EXECUTE) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw desired_access &= ~GENERIC_EXECUTE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw access |= (STANDARD_RIGHTS_EXECUTE |
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw SYNCHRONIZE | FILE_EXECUTE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (desired_access & GENERIC_WRITE) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw desired_access &= ~GENERIC_WRITE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw access |= (FILE_GENERIC_WRITE & ~SYNCHRONIZE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (desired_access & GENERIC_READ) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw desired_access &= ~GENERIC_READ;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw access |= FILE_GENERIC_READ;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (access | desired_access);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_omode_to_amask
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function converts open modes used by Open and Open AndX
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * commands to desired access bits used by NT Create AndX command.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwuint32_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_omode_to_amask(uint32_t desired_access)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (desired_access & SMB_DA_ACCESS_MASK) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SMB_DA_ACCESS_READ:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FILE_GENERIC_READ);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SMB_DA_ACCESS_WRITE:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FILE_GENERIC_WRITE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SMB_DA_ACCESS_READ_WRITE:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FILE_GENERIC_READ | FILE_GENERIC_WRITE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SMB_DA_ACCESS_EXECUTE:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FILE_GENERIC_EXECUTE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego default:
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego return (FILE_GENERIC_ALL);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_denymode_to_sharemode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function converts deny modes used by Open and Open AndX
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * commands to share access bits used by NT Create AndX command.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwuint32_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_denymode_to_sharemode(uint32_t desired_access, char *fname)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (desired_access & SMB_DA_SHARE_MASK) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SMB_DA_SHARE_COMPATIBILITY:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smb_is_executable(fname))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FILE_SHARE_READ | FILE_SHARE_WRITE);
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (FILE_SHARE_ALL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SMB_DA_SHARE_EXCLUSIVE:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FILE_SHARE_NONE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SMB_DA_SHARE_DENY_WRITE:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FILE_SHARE_READ);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SMB_DA_SHARE_DENY_READ:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FILE_SHARE_WRITE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case SMB_DA_SHARE_DENY_NONE:
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego default:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FILE_SHARE_READ | FILE_SHARE_WRITE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_ofun_to_crdisposition
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function converts open function values used by Open and Open AndX
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * commands to create disposition values used by NT Create AndX command.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwuint32_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_ofun_to_crdisposition(uint16_t ofun)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw static int ofun_cr_map[3][2] =
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw { -1, FILE_CREATE },
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw { FILE_OPEN, FILE_OPEN_IF },
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw { FILE_OVERWRITE, FILE_OVERWRITE_IF }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw };
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int row = ofun & SMB_OFUN_OPEN_MASK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int col = (ofun & SMB_OFUN_CREATE_MASK) >> 4;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (row == 3)
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego return (FILE_MAXIMUM_DISPOSITION + 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (ofun_cr_map[row][col]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Retry opens to avoid spurious sharing violations, due to timing
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * issues between closes and opens. The client that already has the
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * file open may be in the process of closing it.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbuint32_t
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_common_open(smb_request_t *sr)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smb_arg_open_t *parg;
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown uint32_t status = NT_STATUS_SUCCESS;
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown int count;
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown parg = kmem_alloc(sizeof (*parg), KM_SLEEP);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown bcopy(&sr->arg.open, parg, sizeof (*parg));
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb for (count = 0; count <= 4; count++) {
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown if (count != 0)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb delay(MSEC_TO_TICK(400));
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb status = smb_open_subr(sr);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (status != NT_STATUS_SHARING_VIOLATION)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb break;
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown bcopy(parg, &sr->arg.open, sizeof (*parg));
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (status == NT_STATUS_SHARING_VIOLATION) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smbsr_error(sr, NT_STATUS_SHARING_VIOLATION,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb ERRDOS, ERROR_SHARING_VIOLATION);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego if (status == NT_STATUS_NO_SUCH_FILE) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smbsr_error(sr, NT_STATUS_OBJECT_NAME_NOT_FOUND,
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego ERRDOS, ERROR_FILE_NOT_FOUND);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego }
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown kmem_free(parg, sizeof (*parg));
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (status);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_open_subr
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Notes on write-through behaviour. It looks like pre-LM0.12 versions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * of the protocol specify the write-through mode when a file is opened,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * (SmbOpen, SmbOpenAndX) so the write calls (SmbWrite, SmbWriteAndClose,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SmbWriteAndUnlock) don't need to contain a write-through flag.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * With LM0.12, the open calls (SmbCreateAndX, SmbNtTransactCreate)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * don't indicate which write-through mode to use. Instead the write
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * calls (SmbWriteAndX, SmbWriteRaw) specify the mode on a per call
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * basis.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * We don't care which open call was used to get us here, we just need
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to ensure that the write-through mode flag is copied from the open
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * parameters to the node. We test the omode write-through flag in all
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * write functions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function will return NT status codes but it also raises errors,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in which case it won't return to the caller. Be careful how you
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * handle things in here.
8c10a8659ac31335ed870a1711c0182623f72fd6as *
8c10a8659ac31335ed870a1711c0182623f72fd6as * The following rules apply when processing a file open request:
8c10a8659ac31335ed870a1711c0182623f72fd6as *
8c10a8659ac31335ed870a1711c0182623f72fd6as * - Oplocks must be broken prior to share checking to prevent open
8c10a8659ac31335ed870a1711c0182623f72fd6as * starvation due to batch oplocks. Checking share reservations first
8c10a8659ac31335ed870a1711c0182623f72fd6as * could potentially result in unnecessary open failures due to
8c10a8659ac31335ed870a1711c0182623f72fd6as * open/close batching on the client.
8c10a8659ac31335ed870a1711c0182623f72fd6as *
8c10a8659ac31335ed870a1711c0182623f72fd6as * - Share checks must take place prior to access checks for correct
8c10a8659ac31335ed870a1711c0182623f72fd6as * Windows semantics and to prevent unnecessary NFS delegation recalls.
8c10a8659ac31335ed870a1711c0182623f72fd6as *
8c10a8659ac31335ed870a1711c0182623f72fd6as * - Oplocks must be acquired after open to ensure the correct
8c10a8659ac31335ed870a1711c0182623f72fd6as * synchronization with NFS delegation and FEM installation.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego *
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego *
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * DOS readonly bit rules
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego *
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * 1. The creator of a readonly file can write to/modify the size of the file
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * using the original create fid, even though the file will appear as readonly
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * to all other fids and via a CIFS getattr call.
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * The readonly bit therefore cannot be set in the filesystem until the file
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * is closed (smb_ofile_close). It is accounted for via ofile and node flags.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego *
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * 2. A setinfo operation (using either an open fid or a path) to set/unset
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * readonly will be successful regardless of whether a creator of a readonly
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * file has an open fid (and has the special privilege mentioned in #1,
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * above). I.e., the creator of a readonly fid holding that fid will no longer
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * have a special privilege.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego *
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * 3. The DOS readonly bit affects only data and some metadata.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * The following metadata can be changed regardless of the readonly bit:
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * - security descriptors
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * - DOS attributes
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * - timestamps
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego *
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * In the current implementation, the file size cannot be changed (except for
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * the exceptions in #1 and #2, above).
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego *
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego *
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * DOS attribute rules
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego *
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * These rules are specific to creating / opening files and directories.
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * How the attribute value (specifically ZERO or FILE_ATTRIBUTE_NORMAL)
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * should be interpreted may differ in other requests.
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego *
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * - An attribute value equal to ZERO or FILE_ATTRIBUTE_NORMAL means that the
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * file's attributes should be cleared.
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * - If FILE_ATTRIBUTE_NORMAL is specified with any other attributes,
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * FILE_ATTRIBUTE_NORMAL is ignored.
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego *
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * 1. Creating a new file
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * - The request attributes + FILE_ATTRIBUTE_ARCHIVE are applied to the file.
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego *
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * 2. Creating a new directory
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * - The request attributes + FILE_ATTRIBUTE_DIRECTORY are applied to the file.
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * - FILE_ATTRIBUTE_ARCHIVE does not get set.
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego *
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * 3. Overwriting an existing file
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * - the request attributes are used as search attributes. If the existing
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * file does not meet the search criteria access is denied.
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * - otherwise, applies attributes + FILE_ATTRIBUTE_ARCHIVE.
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego *
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * 4. Opening an existing file or directory
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * The request attributes are ignored.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic uint32_t
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_open_subr(smb_request_t *sr)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States boolean_t created = B_FALSE;
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States boolean_t last_comp_found = B_FALSE;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_t *node = NULL;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_t *dnode = NULL;
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_t *cur_node = NULL;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smb_arg_open_t *op = &sr->sr_open;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego int rc;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_ofile_t *of;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_attr_t new_attr;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego int max_requested = 0;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego uint32_t max_allowed;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego uint32_t status = NT_STATUS_SUCCESS;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego int is_dir;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_error_t err;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego boolean_t is_stream = B_FALSE;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego int lookup_flags = SMB_FOLLOW_LINKS;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego uint32_t uniq_fid;
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smb_pathname_t *pn = &op->fqi.fq_path;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw is_dir = (op->create_options & FILE_DIRECTORY_FILE) ? 1 : 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh /*
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * If the object being created or opened is a directory
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * the Disposition parameter must be one of FILE_CREATE,
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * FILE_OPEN, or FILE_OPEN_IF
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (is_dir) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((op->create_disposition != FILE_CREATE) &&
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (op->create_disposition != FILE_OPEN_IF) &&
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (op->create_disposition != FILE_OPEN)) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ERRDOS, ERROR_INVALID_ACCESS);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_INVALID_PARAMETER);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (op->desired_access & MAXIMUM_ALLOWED) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw max_requested = 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->desired_access &= ~MAXIMUM_ALLOWED;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->desired_access = smb_access_generic_to_file(op->desired_access);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (sr->session->s_file_cnt >= SMB_SESSION_OFILE_MAX) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ASSERT(sr->uid_user);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright cmn_err(CE_NOTE, "smbd[%s\\%s]: TOO_MANY_OPENED_FILES",
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright sr->uid_user->u_domain, sr->uid_user->u_name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_TOO_MANY_OPENED_FILES,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ERRDOS, ERROR_TOO_MANY_OPEN_FILES);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_TOO_MANY_OPENED_FILES);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* This must be NULL at this point */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->fid_ofile = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->devstate = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (sr->tid_tree->t_res_type & STYPE_MASK) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case STYPE_DISKTREE:
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright case STYPE_PRINTQ:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case STYPE_IPC:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * No further processing for IPC, we need to either
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * raise an exception or return success here.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
3db3f65c6274eb042354801a308c8e9bc4994553amw if ((status = smb_opipe_open(sr)) != NT_STATUS_SUCCESS)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smbsr_error(sr, status, 0, 0);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (status);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw default:
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smbsr_error(sr, NT_STATUS_BAD_DEVICE_TYPE,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb ERRDOS, ERROR_BAD_DEV_TYPE);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_BAD_DEVICE_TYPE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier smb_pathname_init(sr, pn, pn->pn_path);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (!smb_pathname_validate(sr, pn))
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier return (sr->smb_error.status);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (strlen(pn->pn_path) >= MAXPATHLEN) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, 0, ERRSRV, ERRfilespecs);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_NAME_TOO_LONG);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (is_dir) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (!smb_validate_dirname(sr, pn))
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier return (sr->smb_error.status);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier } else {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (!smb_validate_object_name(sr, pn))
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier return (sr->smb_error.status);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States cur_node = op->fqi.fq_dnode ?
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States op->fqi.fq_dnode : sr->tid_tree->t_snode;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States /*
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States * if no path or filename are specified the stream should be
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States * created on cur_node
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States */
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States if (!is_dir && !pn->pn_pname && !pn->pn_fname && pn->pn_sname) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States /*
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Can't currently handle a stream on the tree root.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * If a stream is being opened return "not found", otherwise
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * return "access denied".
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States */
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States if (cur_node == sr->tid_tree->t_snode) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (op->create_disposition == FILE_OPEN) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smbsr_error(sr, NT_STATUS_OBJECT_NAME_NOT_FOUND,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States ERRDOS, ERROR_FILE_NOT_FOUND);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_OBJECT_NAME_NOT_FOUND);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smbsr_error(sr, NT_STATUS_ACCESS_DENIED, ERRDOS,
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States ERROR_ACCESS_DENIED);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_ACCESS_DENIED);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States }
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States (void) snprintf(op->fqi.fq_last_comp,
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States sizeof (op->fqi.fq_last_comp),
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States "%s%s", cur_node->od_name, pn->pn_sname);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown op->fqi.fq_dnode = cur_node->n_dnode;
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_ref(op->fqi.fq_dnode);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States } else {
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States if (rc = smb_pathname_reduce(sr, sr->user_cr, pn->pn_path,
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States sr->tid_tree->t_snode, cur_node, &op->fqi.fq_dnode,
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States op->fqi.fq_last_comp)) {
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smbsr_errno(sr, rc);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States return (sr->smb_error.status);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the access mask has only DELETE set (ignore
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FILE_READ_ATTRIBUTES), then assume that this
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is a request to delete the link (if a link)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and do not follow links. Otherwise, follow
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the link to the target.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if ((op->desired_access & ~FILE_READ_ATTRIBUTES) == DELETE)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw lookup_flags &= ~SMB_FOLLOW_LINKS;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smb_fsop_lookup_name(sr, kcred, lookup_flags,
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States sr->tid_tree->t_snode, op->fqi.fq_dnode, op->fqi.fq_last_comp,
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh &op->fqi.fq_fnode);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc == 0) {
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States last_comp_found = B_TRUE;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh rc = smb_node_getattr(sr, op->fqi.fq_fnode,
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh &op->fqi.fq_fattr);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (rc != 0) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_node_release(op->fqi.fq_fnode);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_node_release(op->fqi.fq_dnode);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smbsr_error(sr, NT_STATUS_INTERNAL_ERROR,
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh ERRDOS, ERROR_INTERNAL_ERROR);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh return (sr->smb_error.status);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else if (rc == ENOENT) {
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States last_comp_found = B_FALSE;
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States op->fqi.fq_fnode = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_release(op->fqi.fq_dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_errno(sr, rc);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (sr->smb_error.status);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as /*
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * The uniq_fid is a CIFS-server-wide unique identifier for an ofile
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * which is used to uniquely identify open instances for the
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * VFS share reservation and POSIX locks.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as */
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as uniq_fid = SMB_UNIQ_FID();
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States if (last_comp_found) {
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States node = op->fqi.fq_fnode;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States dnode = op->fqi.fq_dnode;
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (!smb_node_is_file(node) && !smb_node_is_dir(node) &&
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States !smb_node_is_symlink(node)) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_release(node);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_release(dnode);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas smbsr_error(sr, NT_STATUS_ACCESS_DENIED, ERRDOS,
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas ERRnoaccess);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas return (NT_STATUS_ACCESS_DENIED);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas }
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * Reject this request if either:
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * - the target IS a directory and the client requires that
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * it must NOT be (required by Lotus Notes)
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * - the target is NOT a directory and client requires that
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego * it MUST be.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_node_is_dir(node)) {
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego if (op->create_options & FILE_NON_DIRECTORY_FILE) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_FILE_IS_A_DIRECTORY,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ERRDOS, ERROR_ACCESS_DENIED);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_FILE_IS_A_DIRECTORY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego } else {
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego if ((op->create_options & FILE_DIRECTORY_FILE) ||
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego (op->nt_flags & NT_CREATE_FLAG_OPEN_TARGET_DIR)) {
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego smb_node_release(node);
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego smb_node_release(dnode);
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego smbsr_error(sr, NT_STATUS_NOT_A_DIRECTORY,
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego ERRDOS, ERROR_DIRECTORY);
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego return (NT_STATUS_NOT_A_DIRECTORY);
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * No more open should be accepted when "Delete on close"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * flag is set.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (node->flags & NODE_FLAGS_DELETE_ON_CLOSE) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_DELETE_PENDING,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ERRDOS, ERROR_ACCESS_DENIED);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_DELETE_PENDING);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Specified file already exists so the operation should fail.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (op->create_disposition == FILE_CREATE) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_OBJECT_NAME_COLLISION,
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States ERRDOS, ERROR_FILE_EXISTS);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_OBJECT_NAME_COLLISION);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Windows seems to check read-only access before file
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sharing check.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego *
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * Check to see if the file is currently readonly (irrespective
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego * of whether this open will make it readonly).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if (SMB_PATHFILE_IS_READONLY(sr, node)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Files data only */
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (!smb_node_is_dir(node)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (op->desired_access & (FILE_WRITE_DATA |
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw FILE_APPEND_DATA)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as ERRDOS, ERRnoaccess);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_ACCESS_DENIED);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8c10a8659ac31335ed870a1711c0182623f72fd6as if (smb_oplock_conflict(node, sr->session, op))
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright (void) smb_oplock_break(node, sr->session, B_FALSE);
8c10a8659ac31335ed870a1711c0182623f72fd6as
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_wrlock(node);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if ((op->create_disposition == FILE_SUPERSEDE) ||
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as (op->create_disposition == FILE_OVERWRITE_IF) ||
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as (op->create_disposition == FILE_OVERWRITE)) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego if ((!(op->desired_access &
8c10a8659ac31335ed870a1711c0182623f72fd6as (FILE_WRITE_DATA | FILE_APPEND_DATA |
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA))) ||
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh (!smb_sattr_check(op->fqi.fq_fattr.sa_dosattr,
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego op->dattr))) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_unlock(node);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smb_node_release(node);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smb_node_release(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as ERRDOS, ERRnoaccess);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_ACCESS_DENIED);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as status = smb_fsop_shrlock(sr->user_cr, node, uniq_fid,
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego op->desired_access, op->share_access);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (status == NT_STATUS_SHARING_VIOLATION) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_unlock(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (status);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw status = smb_fsop_access(sr, sr->user_cr, node,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->desired_access);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (status != NT_STATUS_SUCCESS) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smb_fsop_unshrlock(sr->user_cr, node, uniq_fid);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_unlock(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (status == NT_STATUS_PRIVILEGE_NOT_HELD) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, status,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as ERRDOS, ERROR_PRIVILEGE_NOT_HELD);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (status);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as ERRDOS, ERROR_ACCESS_DENIED);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_ACCESS_DENIED);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (op->create_disposition) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case FILE_SUPERSEDE:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case FILE_OVERWRITE_IF:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case FILE_OVERWRITE:
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (smb_node_is_dir(node)) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smb_fsop_unshrlock(sr->user_cr, node, uniq_fid);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_unlock(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as ERRDOS, ERROR_ACCESS_DENIED);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_ACCESS_DENIED);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego op->dattr |= FILE_ATTRIBUTE_ARCHIVE;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh /* Don't apply readonly bit until smb_ofile_close */
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego if (op->dattr & FILE_ATTRIBUTE_READONLY) {
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego op->created_readonly = B_TRUE;
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego op->dattr &= ~FILE_ATTRIBUTE_READONLY;
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego }
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh bzero(&new_attr, sizeof (new_attr));
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh new_attr.sa_dosattr = op->dattr;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh new_attr.sa_vattr.va_size = op->dsize;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh new_attr.sa_mask = SMB_AT_DOSATTR | SMB_AT_SIZE;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh rc = smb_fsop_setattr(sr, sr->user_cr, node, &new_attr);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (rc != 0) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_fsop_unshrlock(sr->user_cr, node, uniq_fid);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_node_unlock(node);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_node_release(node);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_node_release(dnode);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smbsr_errno(sr, rc);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh return (sr->smb_error.status);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * If file is being replaced, remove existing streams
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States if (SMB_IS_STREAM(node) == 0) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh rc = smb_fsop_remove_streams(sr, sr->user_cr,
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh node);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (rc != 0) {
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smb_fsop_unshrlock(sr->user_cr, node,
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States uniq_fid);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_unlock(node);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_release(node);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_release(dnode);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States return (sr->smb_error.status);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States }
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->action_taken = SMB_OACT_TRUNCATED;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw default:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FILE_OPEN or FILE_OPEN_IF.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->action_taken = SMB_OACT_OPENED;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Last component was not found. */
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States dnode = op->fqi.fq_dnode;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (is_dir == 0)
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States is_stream = smb_is_stream_name(pn->pn_path);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((op->create_disposition == FILE_OPEN) ||
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (op->create_disposition == FILE_OVERWRITE)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb smbsr_error(sr, NT_STATUS_OBJECT_NAME_NOT_FOUND,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb ERRDOS, ERROR_FILE_NOT_FOUND);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (NT_STATUS_OBJECT_NAME_NOT_FOUND);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (pn->pn_fname && smb_is_invalid_filename(pn->pn_fname)) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_release(dnode);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego ERRDOS, ERROR_INVALID_NAME);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego return (NT_STATUS_OBJECT_NAME_INVALID);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego }
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * lock the parent dir node in case another create
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * request to the same parent directory comes in.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_wrlock(dnode);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh /* Don't apply readonly bit until smb_ofile_close */
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (op->dattr & FILE_ATTRIBUTE_READONLY) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh op->dattr &= ~FILE_ATTRIBUTE_READONLY;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh op->created_readonly = B_TRUE;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh bzero(&new_attr, sizeof (new_attr));
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego if ((op->crtime.tv_sec != 0) &&
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego (op->crtime.tv_sec != UINT_MAX)) {
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego new_attr.sa_mask |= SMB_AT_CRTIME;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego new_attr.sa_crtime = op->crtime;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego }
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (is_dir == 0) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh op->dattr |= FILE_ATTRIBUTE_ARCHIVE;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh new_attr.sa_dosattr = op->dattr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw new_attr.sa_vattr.va_type = VREG;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb new_attr.sa_vattr.va_mode = is_stream ? S_IRUSR :
7b59d02d2a384be9a08087b14defadd214b3c1ddjb S_IRUSR | S_IRGRP | S_IROTH |
7b59d02d2a384be9a08087b14defadd214b3c1ddjb S_IWUSR | S_IWGRP | S_IWOTH;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh new_attr.sa_mask |=
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh SMB_AT_DOSATTR | SMB_AT_TYPE | SMB_AT_MODE;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas if (op->dsize) {
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas new_attr.sa_vattr.va_size = op->dsize;
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2eas new_attr.sa_mask |= SMB_AT_SIZE;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smb_fsop_create(sr, sr->user_cr, dnode,
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh op->fqi.fq_last_comp, &new_attr, &op->fqi.fq_fnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_unlock(dnode);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_errno(sr, rc);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (sr->smb_error.status);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States node = op->fqi.fq_fnode;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_wrlock(node);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb status = smb_fsop_shrlock(sr->user_cr, node, uniq_fid,
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego op->desired_access, op->share_access);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (status == NT_STATUS_SHARING_VIOLATION) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_unlock(node);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_delete_new_object(sr);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smb_node_release(node);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_unlock(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smb_node_release(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as return (status);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw op->dattr |= FILE_ATTRIBUTE_DIRECTORY;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh new_attr.sa_dosattr = op->dattr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw new_attr.sa_vattr.va_type = VDIR;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw new_attr.sa_vattr.va_mode = 0777;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh new_attr.sa_mask |=
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh SMB_AT_DOSATTR | SMB_AT_TYPE | SMB_AT_MODE;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smb_fsop_mkdir(sr, sr->user_cr, dnode,
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh op->fqi.fq_last_comp, &new_attr, &op->fqi.fq_fnode);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_unlock(dnode);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_errno(sr, rc);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (sr->smb_error.status);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States node = op->fqi.fq_fnode;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_wrlock(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States created = B_TRUE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->action_taken = SMB_OACT_CREATED;
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego }
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego if (max_requested) {
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego smb_fsop_eaccess(sr, sr->user_cr, node, &max_allowed);
2c1b14e51525da2c09064641416fc4aed457c72fjose borrego op->desired_access |= max_allowed;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego }
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh status = NT_STATUS_SUCCESS;
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego of = smb_ofile_open(sr->tid_tree, node, sr->smb_pid, op, SMB_FTYPE_DISK,
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego uniq_fid, &err);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (of == NULL) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, err.status, err.errcls, err.errcode);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh status = err.status;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (status == NT_STATUS_SUCCESS) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (!smb_tree_is_connected(sr->tid_tree)) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smbsr_error(sr, 0, ERRSRV, ERRinvnid);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh status = NT_STATUS_UNSUCCESSFUL;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh /*
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * This MUST be done after ofile creation, so that explicitly
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * set timestamps can be remembered on the ofile.
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh */
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (status == NT_STATUS_SUCCESS) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if ((rc = smb_set_open_timestamps(sr, of, created)) != 0) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smbsr_errno(sr, rc);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh status = sr->smb_error.status;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (status == NT_STATUS_SUCCESS) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (smb_node_getattr(sr, node, &op->fqi.fq_fattr) != 0) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smbsr_error(sr, NT_STATUS_INTERNAL_ERROR,
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh ERRDOS, ERROR_INTERNAL_ERROR);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh status = NT_STATUS_INTERNAL_ERROR;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh /*
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * smb_fsop_unshrlock is a no-op if node is a directory
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * smb_fsop_unshrlock is done in smb_ofile_close
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh */
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (status != NT_STATUS_SUCCESS) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (of == NULL) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_fsop_unshrlock(sr->user_cr, node, uniq_fid);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh } else {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_ofile_close(of, 0);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_ofile_release(of);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States if (created)
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States smb_delete_new_object(sr);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_unlock(node);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_release(node);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States if (created)
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_unlock(dnode);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_release(dnode);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh return (status);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States }
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States
8c10a8659ac31335ed870a1711c0182623f72fd6as /*
8c10a8659ac31335ed870a1711c0182623f72fd6as * Propagate the write-through mode from the open params
8c10a8659ac31335ed870a1711c0182623f72fd6as * to the node: see the notes in the function header.
8c10a8659ac31335ed870a1711c0182623f72fd6as */
8c10a8659ac31335ed870a1711c0182623f72fd6as if (sr->sr_cfg->skc_sync_enable ||
8c10a8659ac31335ed870a1711c0182623f72fd6as (op->create_options & FILE_WRITE_THROUGH))
8c10a8659ac31335ed870a1711c0182623f72fd6as node->flags |= NODE_FLAGS_WRITE_THROUGH;
8c10a8659ac31335ed870a1711c0182623f72fd6as
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh /*
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * Set up the fileid and dosattr in open_param for response
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh */
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States op->fileid = op->fqi.fq_fattr.sa_vattr.va_nodeid;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh op->dattr = op->fqi.fq_fattr.sa_dosattr;
8c10a8659ac31335ed870a1711c0182623f72fd6as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Set up the file type in open_param for the response
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw op->ftype = SMB_FTYPE_DISK;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->smb_fid = of->f_fid;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->fid_ofile = of;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_unlock(node);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (created)
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_node_unlock(dnode);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_node_is_file(node)) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smb_oplock_acquire(node, of, op);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States op->dsize = op->fqi.fq_fattr.sa_vattr.va_size;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States } else {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States /* directory or symlink */
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego op->op_oplock_level = SMB_OPLOCK_NONE;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego op->dsize = 0;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States smb_node_release(node);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_node_release(dnode);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (NT_STATUS_SUCCESS);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh/*
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * smb_set_open_timestamps
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh *
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * Last write time:
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * - If the last_write time specified in the open params is not 0 or -1,
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * use it as file's mtime. This will be considered an explicitly set
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * timestamps, not reset by subsequent writes.
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh *
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * Opening existing file (not directory):
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * - If opening an existing file for overwrite set initial ATIME, MTIME
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * & CTIME to now. (This is achieved by setting them as pending then forcing
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * an smb_node_setattr() to apply pending times.)
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh *
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * - Note If opening an existing file NOT for overwrite, windows would
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * set the atime on file close, however setting the atime would cause
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * the ARCHIVE attribute to be set, which does not occur on windows,
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * so we do not do the atime update.
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh *
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh * Returns: errno
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh */
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintoshstatic int
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintoshsmb_set_open_timestamps(smb_request_t *sr, smb_ofile_t *of, boolean_t created)
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh{
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh int rc = 0;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smb_arg_open_t *op = &sr->sr_open;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_node_t *node = of->f_node;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh boolean_t existing_file, set_times;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_attr_t attr;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh bzero(&attr, sizeof (smb_attr_t));
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh set_times = B_FALSE;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if ((op->mtime.tv_sec != 0) && (op->mtime.tv_sec != UINT_MAX)) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh attr.sa_mask = SMB_AT_MTIME;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh attr.sa_vattr.va_mtime = op->mtime;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh set_times = B_TRUE;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh existing_file = !(created || smb_node_is_dir(node));
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (existing_file) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh switch (op->create_disposition) {
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh case FILE_SUPERSEDE:
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh case FILE_OVERWRITE_IF:
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh case FILE_OVERWRITE:
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh smb_ofile_set_write_time_pending(of);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh set_times = B_TRUE;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh break;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh default:
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh break;
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh }
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh if (set_times)
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh rc = smb_node_setattr(sr, node, sr->user_cr, of, &attr);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh return (rc);
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh}
037cac007b685e7ea79f6ef7e8e62bfd342a4d56joyce mcintosh
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States * This function is used to delete a newly created object (file or
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States * directory) if an error occurs after creation of the object.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic void
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United Statessmb_delete_new_object(smb_request_t *sr)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smb_arg_open_t *op = &sr->sr_open;
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States smb_fqi_t *fqi = &(op->fqi);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States uint32_t flags = 0;
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States if (SMB_TREE_IS_CASEINSENSITIVE(sr))
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States flags |= SMB_IGNORE_CASE;
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States if (SMB_TREE_SUPPORTS_CATIA(sr))
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States flags |= SMB_CATIA;
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States if (op->create_options & FILE_DIRECTORY_FILE)
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States (void) smb_fsop_rmdir(sr, sr->user_cr, fqi->fq_dnode,
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States fqi->fq_last_comp, flags);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States else
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States (void) smb_fsop_remove(sr, sr->user_cr, fqi->fq_dnode,
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States fqi->fq_last_comp, flags);
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States}