smb_common_open.c revision 8c10a8659ac31335ed870a1711c0182623f72fd6
1N/A * The contents of this file are subject to the terms of the 1N/A * Common Development and Distribution License (the "License"). 1N/A * You may not use this file except in compliance with the License. 1N/A * See the License for the specific language governing permissions 1N/A * and limitations under the License. 1N/A * When distributing Covered Code, include this CDDL HEADER in each 1N/A * If applicable, add the following below this CDDL HEADER, with the 1N/A * fields enclosed by brackets "[]" replaced with your own identifying 1N/A * information: Portions Copyright [yyyy] [name of copyright owner] 1N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 1N/A * Use is subject to license terms. 1N/A#
pragma ident "%Z%%M% %I% %E% SMI" 1N/A * This module provides the common open functionality to the various 1N/A * open and create SMB interface functions. 1N/A * This macro is used to delete a newly created object 1N/A * if any error happens after creation of object. 1N/A * smb_access_generic_to_file 1N/A * Search MSDN for IoCreateFile to see following mapping. 1N/A * GENERIC_READ STANDARD_RIGHTS_READ, FILE_READ_DATA, 1N/A * FILE_READ_ATTRIBUTES and FILE_READ_EA 1N/A * GENERIC_WRITE STANDARD_RIGHTS_WRITE, FILE_WRITE_DATA, 1N/A * FILE_WRITE_ATTRIBUTES, FILE_WRITE_EA, and FILE_APPEND_DATA 1N/A * GENERIC_EXECUTE STANDARD_RIGHTS_EXECUTE, SYNCHRONIZE, and FILE_EXECUTE. * This function converts open modes used by Open and Open AndX * commands to desired access bits used by NT Create AndX command. * smb_denymode_to_sharemode * This function converts deny modes used by Open and Open AndX * commands to share access bits used by NT Create AndX command. * smb_ofun_to_crdisposition * This function converts open function values used by Open and Open AndX * commands to create disposition values used by NT Create AndX command. * Retry opens to avoid spurious sharing violations, due to timing * issues between closes and opens. The client that already has the * file open may be in the process of closing it. * Notes on write-through behaviour. It looks like pre-LM0.12 versions * of the protocol specify the write-through mode when a file is opened, * (SmbOpen, SmbOpenAndX) so the write calls (SmbWrite, SmbWriteAndClose, * SmbWriteAndUnlock) don't need to contain a write-through flag. * With LM0.12, the open calls (SmbCreateAndX, SmbNtTransactCreate) * don't indicate which write-through mode to use. Instead the write * calls (SmbWriteAndX, SmbWriteRaw) specify the mode on a per call * We don't care which open call was used to get us here, we just need * to ensure that the write-through mode flag is copied from the open * parameters to the node. We test the omode write-through flag in all * This function will return NT status codes but it also raises errors, * in which case it won't return to the caller. Be careful how you * The following rules apply when processing a file open request: * - Oplocks must be broken prior to share checking to prevent open * starvation due to batch oplocks. Checking share reservations first * could potentially result in unnecessary open failures due to * - Share checks must take place prior to access checks for correct * Windows semantics and to prevent unnecessary NFS delegation recalls. * - Oplocks must be acquired after open to ensure the correct * synchronization with NFS delegation and FEM installation. * The object being created or opened is a directory, * and the Disposition parameter must be one of * FILE_CREATE, FILE_OPEN, or FILE_OPEN_IF /* This must be NULL at this point */ * No further processing for IPC, we need to either * raise an exception or return success here. * Some clients pass null file names; NT interprets this as "\". * If the access mask has only DELETE set (ignore * FILE_READ_ATTRIBUTES), then assume that this * is a request to delete the link (if a link) * and do not follow links. Otherwise, follow * the link to the target. * The uniq_fid is a CIFS-server-wide unique identifier for an ofile * which is used to uniquely identify open instances for the * VFS share reservation mechanism (accessed via smb_fsop_shrlock()). * Reject this request if the target is a directory * and the client has specified that it must not be * a directory (required by Lotus Notes). * Directories cannot be opened * with the above commands * No more open should be accepted when "Delete on close" * Specified file already exists so the operation should fail. * Windows seems to check read-only access before file * If file is being replaced, * we should remove existing streams * FILE_OPEN or FILE_OPEN_IF. /* Last component was not found. */ * lock the parent dir node in case another create * request to the same parent directory comes in. * A problem with setting the readonly bit at * create time is that this bit will prevent * writes to the file from the same fid (which * The solution is to set the bit at close time. * Meanwhile, to prevent racing opens from being * able to write to the file, set share reservations * to prevent write and delete access. * smb_ofile_open() will copy node to of->node. Hence * the hold on node (i.e. op->fqi.last_snode) will be "transferred" * smb_fsop_unshrlock() and smb_fsop_close() * are called from smb_ofile_close() }
else {
/* VDIR or VLNK */ * Propagate the write-through mode from the open params * to the node: see the notes in the function header. * Clients may set the DOS readonly bit on create but they * expect subsequent write operations on the open fid to * succeed. Thus the DOS readonly bit is not set until * the file is closed. The NODE_CREATED_READONLY flag * will act as the indicator to set the DOS readonly bit on * If we reach here, it means that file already exists * and if create disposition is one of: FILE_SUPERSEDE, * FILE_OVERWRITE_IF, or FILE_OVERWRITE it * means that client wants to overwrite (or truncate) * the existing file. So we should overwrite the dos * attributes of destination file with the dos attributes * Set up the file type in open_param for the response * smb_validate_object_name * Very basic file name validation. Directory validation is handed off * to smb_validate_dirname. For filenames, we check for names of the * form "AAAn:". Names that contain three characters, a single digit * and a colon (:) are reserved as DOS device names, i.e. "COM1:". * Returns NT status codes. * Basename with backslashes. * smb_preset_delete_on_close * Set the DeleteOnClose flag on the smb file. When the file is closed, * the flag will be transferred to the smb node, which will commit the * delete operation and inhibit subsequent open requests. * When DeleteOnClose is set on an smb_node, the common open code will * reject subsequent open requests for the file. Observation of Windows * 2000 indicates that subsequent opens should be allowed (assuming * there would be no sharing violation) until the file is closed using * the fid on which the DeleteOnClose was requested.