smb_set_fileinfo.c revision 5496c1178a1a48006226450b13c2df195831794c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
/*
*
* SMB_INFO_STANDARD
* SMB_INFO_SET_EAS
* SMB_SET_FILE_BASIC_INFO
* SMB_SET_FILE_DISPOSITION_INFO
* SMB_SET_FILE_END_OF_FILE_INFO
* SMB_SET_FILE_ALLOCATION_INFO
*
* Handled Passthrough levels:
* SMB_FILE_BASIC_INFORMATION
* SMB_FILE_RENAME_INFORMATION
* SMB_FILE_LINK_INFORMATION
* SMB_FILE_DISPOSITION_INFORMATION
* SMB_FILE_END_OF_FILE_INFORMATION
* SMB_FILE_ALLOCATION_INFORMATION
*
* Internal levels representing non trans2 requests
* SMB_SET_INFORMATION
* SMB_SET_INFORMATION2
*/
/*
* Setting timestamps:
* The behaviour when the time field is set to -1 is not documented
* but is generally treated like 0, meaning that that server file
* system assigned value need not be changed.
*
* Setting attributes - FILE_ATTRIBUTE_NORMAL:
* SMB_SET_INFORMATION -
* - if the specified attributes have ONLY FILE_ATTRIBUTE_NORMAL set
* do NOT change the file's attributes.
* SMB_SET_BASIC_INFO -
* - if the specified attributes have ONLY FILE_ATTRIBUTE_NORMAL set
* clear (0) the file's attributes.
* - if the specified attributes are 0 do NOT change the file's
* attributes.
*/
#include <smbsrv/smb_kproto.h>
#include <smbsrv/smb_fsops.h>
typedef struct smb_setinfo {
/*
* These functions all return 0 (success) or -1 (error).
* They set error details in the sr when appropriate.
*/
/*
* smb_com_trans2_set_file_information
*/
{
return (SDRC_ERROR);
return (SDRC_ERROR);
return (SDRC_SUCCESS);
}
/*
* smb_com_trans2_set_path_information
*/
{
return (SDRC_ERROR);
}
return (SDRC_ERROR);
return (SDRC_ERROR);
return (SDRC_SUCCESS);
}
/*
* smb_com_set_information (aka setattr)
*/
{
return (SDRC_SUCCESS);
}
void
{
}
{
return (SDRC_ERROR);
}
return (SDRC_ERROR);
return (SDRC_ERROR);
if (smbsr_encode_empty_result(sr) != 0)
return (SDRC_ERROR);
return (SDRC_SUCCESS);
}
/*
* smb_com_set_information2 (aka setattre)
*/
{
return (SDRC_SUCCESS);
}
void
{
}
{
return (SDRC_ERROR);
return (SDRC_ERROR);
if (smbsr_encode_empty_result(sr) != 0)
return (SDRC_ERROR);
return (SDRC_SUCCESS);
}
/*
* smb_set_by_fid
*
* Common code for setting file information by open file id.
* Use the id to identify the node object and invoke smb_set_fileinfo
* for that node.
*
* Setting attributes on a named pipe by id is handled by simply
* returning success.
*/
static int
{
int rc;
if (SMB_TREE_IS_READONLY(sr)) {
return (-1);
}
return (0);
return (-1);
}
return (0);
}
return (rc);
}
/*
* smb_set_by_path
*
* Common code for setting file information by file name.
* Use the file name to identify the node object and invoke
* smb_set_fileinfo for that node.
*
* Path should be set in sr->arg.dirop.fqi.fq_path prior to
* calling smb_set_by_path.
*
* Setting attributes on a named pipe by name is an error and
* is handled in the calling functions so that they can return
* the appropriate error status code (which differs by caller).
*/
static int
{
int rc;
char *name;
if (SMB_TREE_IS_READONLY(sr)) {
return (-1);
}
return (-1);
if (rc == 0) {
}
if (rc != 0) {
} else {
}
return (-1);
}
return (rc);
}
/*
* smb_set_fileinfo
*
* For compatibility with windows servers, SMB_FILE_LINK_INFORMATION
* is handled by returning NT_STATUS_NOT_SUPPORTED.
*/
static int
{
switch (sinfo->si_infolev) {
case SMB_SET_INFORMATION:
case SMB_SET_INFORMATION2:
case SMB_INFO_STANDARD:
case SMB_INFO_SET_EAS:
/* EAs not supported */
return (0);
case SMB_SET_FILE_BASIC_INFO:
return (-1);
default:
break;
}
return (-1);
}
/*
* smb_set_information
*
* It is not valid to set FILE_ATTRIBUTE_DIRECTORY if the
* target is not a directory.
*
* For compatibility with Windows Servers, if the specified
* attributes have ONLY FILE_ATTRIBUTE_NORMAL set do NOT change
* the file's attributes.
*/
static int
{
int rc;
return (-1);
if ((attributes & FILE_ATTRIBUTE_DIRECTORY) &&
(!smb_node_is_dir(node))) {
return (-1);
}
if (attributes != FILE_ATTRIBUTE_NORMAL) {
}
}
if (rc != 0) {
return (-1);
}
return (0);
}
/*
* smb_set_information2
*/
static int
{
int rc;
return (-1);
}
}
}
if (rc != 0) {
return (-1);
}
return (0);
}
/*
* smb_set_standard_info
*
*/
static int
{
int rc;
return (-1);
}
}
}
}
if (rc != 0) {
return (-1);
}
return (0);
}
/*
* smb_set_basic_info
*
*
* It is not valid to set FILE_ATTRIBUTE_DIRECTORY if the
* target is not a directory.
*
* For compatibility with windows servers:
* - if the specified attributes have ONLY FILE_ATTRIBUTE_NORMAL set
* clear (0) the file's attributes.
* - if the specified attributes are 0 do NOT change the file's attributes.
*/
static int
{
int rc;
return (-1);
}
if ((attributes & FILE_ATTRIBUTE_DIRECTORY) &&
(!smb_node_is_dir(node))) {
return (-1);
}
}
}
}
}
if (attributes != 0) {
}
if (rc != 0) {
return (-1);
}
return (0);
}
/*
* smb_set_eof_info
*/
static int
{
int rc;
return (-1);
if (smb_node_is_dir(node)) {
return (-1);
}
/* If opened by path, break exclusive oplock */
if (rc != 0) {
return (-1);
}
return (0);
}
/*
* smb_set_alloc_info
*/
static int
{
int rc;
return (-1);
if (smb_node_is_dir(node)) {
return (-1);
}
/* If opened by path, break exclusive oplock */
if (rc != 0) {
return (-1);
}
return (0);
}
/*
* smb_set_disposition_info
*
* File should have been opened with DELETE access otherwise
* the operation is not permitted.
*
* NOTE: The node should be marked delete-on-close upon the receipt
* of the Trans2SetFileInfo(SetDispositionInfo) if mark_delete is set.
* It is different than both SmbNtCreateAndX and SmbNtTransact, which
* set delete-on-close on the ofile and defer setting the flag on the
* node until the file is closed.
*
* Observation of Windows 2000 indicates the following:
*
* 1) If a file is not opened with delete-on-close create options and
* the delete-on-close is set via Trans2SetFileInfo(SetDispositionInfo)
* using that open file handle, any subsequent open requests will fail
* with DELETE_PENDING.
*
* 2) If a file is opened with delete-on-close create options and the
* client attempts to unset delete-on-close via Trans2SetFileInfo
* (SetDispositionInfo) prior to the file close, any subsequent open
* requests will still fail with DELETE_PENDING after the file is closed.
*
* 3) If a file is opened with delete-on-close create options and that
* file handle (not the last open handle and the only file handle
* with delete-on-close set) is closed. Any subsequent open requests
* will fail with DELETE_PENDING. Unsetting delete-on-close via
* Trans2SetFileInfo(SetDispositionInfo) at this time will unset the
* node delete-on-close flag, which will result in the file not being
* removed even after the last file handle is closed.
*/
static int
{
unsigned char mark_delete;
int doserr;
return (-1);
return (-1);
}
if (mark_delete) {
if (SMB_TREE_SUPPORTS_CATIA(sr))
if (status != NT_STATUS_SUCCESS) {
switch (status) {
case NT_STATUS_CANNOT_DELETE:
break;
break;
default:
break;
}
return (-1);
}
} else {
}
return (0);
}
/*
* smb_set_rename_info
*
* Explicitly specified parameter validation rules:
* - If rootdir is not NULL respond with NT_STATUS_INVALID_PARAMETER.
* - If the filename contains a separator character respond with
* NT_STATUS_INVALID_PARAMETER.
*
* Oplock break:
* Some Windows servers break BATCH oplocks prior to the rename.
* W2K3 does not. We behave as W2K3; we do not send an oplock break.
*/
static int
{
int rc;
char *fname;
if (rc == 0) {
}
if (rc != 0)
return (-1);
return (-1);
}
return (-1);
}
return ((rc == 0) ? 0 : -1);
}