⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pvfs_setfileinfo.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    Unix SMB/CIFS implementation.   POSIX NTVFS backend - setfileinfo   Copyright (C) Andrew Tridgell 2004   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 3 of the License, or   (at your option) any later version.      This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.      You should have received a copy of the GNU General Public License   along with this program.  If not, see <http://www.gnu.org/licenses/>.*/#include "includes.h"#include "vfs_posix.h"#include "system/time.h"#include "librpc/gen_ndr/xattr.h"/*  determine what access bits are needed for a call*/static uint32_t pvfs_setfileinfo_access(union smb_setfileinfo *info){	uint32_t needed;	switch (info->generic.level) {	case RAW_SFILEINFO_EA_SET:		needed = SEC_FILE_WRITE_EA;		break;	case RAW_SFILEINFO_DISPOSITION_INFO:	case RAW_SFILEINFO_DISPOSITION_INFORMATION:		needed = SEC_STD_DELETE;		break;	case RAW_SFILEINFO_END_OF_FILE_INFO:		needed = SEC_FILE_WRITE_DATA;		break;	case RAW_SFILEINFO_POSITION_INFORMATION:		needed = 0;		break;	case RAW_SFILEINFO_SEC_DESC:		needed = 0;		if (info->set_secdesc.in.secinfo_flags & (SECINFO_OWNER|SECINFO_GROUP)) {			needed |= SEC_STD_WRITE_OWNER;		}		if (info->set_secdesc.in.secinfo_flags & SECINFO_DACL) {			needed |= SEC_STD_WRITE_DAC;		}		if (info->set_secdesc.in.secinfo_flags & SECINFO_SACL) {			needed |= SEC_FLAG_SYSTEM_SECURITY;		}		break;	case RAW_SFILEINFO_RENAME_INFORMATION:	case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:		needed = SEC_STD_DELETE;		break;	default:		needed = SEC_FILE_WRITE_ATTRIBUTE;		break;	}	return needed;}/*  rename_information level*/static NTSTATUS pvfs_setfileinfo_rename(struct pvfs_state *pvfs, 					struct ntvfs_request *req, 					struct pvfs_filename *name,					DATA_BLOB *odb_locking_key,					union smb_setfileinfo *info){	NTSTATUS status;	struct pvfs_filename *name2;	char *new_name, *p;	struct odb_lock *lck = NULL;	/* renames are only allowed within a directory */	if (strchr_m(info->rename_information.in.new_name, '\\') &&	    (req->ctx->protocol != PROTOCOL_SMB2)) {		return NT_STATUS_NOT_SUPPORTED;	}	/* don't allow stream renames for now */	if (name->stream_name) {		return NT_STATUS_INVALID_PARAMETER;	}	/* w2k3 does not appear to allow relative rename. On SMB2, vista sends it sometimes,	   but I suspect it is just uninitialised memory */	if (info->rename_information.in.root_fid != 0 && 	    (req->ctx->protocol != PROTOCOL_SMB2)) {		return NT_STATUS_INVALID_PARAMETER;	}	/* construct the fully qualified windows name for the new file name */	if (req->ctx->protocol == PROTOCOL_SMB2) {		/* SMB2 sends the full path of the new name */		new_name = talloc_asprintf(req, "\\%s", info->rename_information.in.new_name);	} else {		new_name = talloc_strdup(req, name->original_name);		if (new_name == NULL) {			return NT_STATUS_NO_MEMORY;		}		p = strrchr_m(new_name, '\\');		if (p == NULL) {			return NT_STATUS_OBJECT_NAME_INVALID;		} else {			*p = 0;		}		new_name = talloc_asprintf(req, "%s\\%s", new_name,					   info->rename_information.in.new_name);	}	if (new_name == NULL) {		return NT_STATUS_NO_MEMORY;	}	/* resolve the new name */	status = pvfs_resolve_name(pvfs, name, new_name, 0, &name2);	if (!NT_STATUS_IS_OK(status)) {		return status;	}	/* if the destination exists, then check the rename is allowed */	if (name2->exists) {		if (strcmp(name2->full_name, name->full_name) == 0) {			/* rename to same name is null-op */			return NT_STATUS_OK;		}		if (!info->rename_information.in.overwrite) {			return NT_STATUS_OBJECT_NAME_COLLISION;		}		status = pvfs_can_delete(pvfs, req, name2, NULL);		if (NT_STATUS_EQUAL(status, NT_STATUS_DELETE_PENDING)) {			return NT_STATUS_ACCESS_DENIED;		}		if (NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {			return NT_STATUS_ACCESS_DENIED;		}		if (!NT_STATUS_IS_OK(status)) {			return status;		}	}	status = pvfs_access_check_parent(pvfs, req, name2, SEC_DIR_ADD_FILE);	if (!NT_STATUS_IS_OK(status)) {		return status;	}	lck = odb_lock(req, pvfs->odb_context, odb_locking_key);	if (lck == NULL) {		DEBUG(0,("Unable to lock opendb for can_stat\n"));		return NT_STATUS_INTERNAL_DB_CORRUPTION;	}	status = pvfs_do_rename(pvfs, lck, name, name2->full_name);	talloc_free(lck);	NT_STATUS_NOT_OK_RETURN(status);	if (NT_STATUS_IS_OK(status)) {		name->full_name = talloc_steal(name, name2->full_name);		name->original_name = talloc_steal(name, name2->original_name);	}	return NT_STATUS_OK;}/*  add a single DOS EA*/NTSTATUS pvfs_setfileinfo_ea_set(struct pvfs_state *pvfs, 				 struct pvfs_filename *name,				 int fd, uint16_t num_eas,				 struct ea_struct *eas){	struct xattr_DosEAs *ealist;	int i, j;	NTSTATUS status;	if (num_eas == 0) {		return NT_STATUS_OK;	}	if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE)) {		return NT_STATUS_NOT_SUPPORTED;	}	ealist = talloc(name, struct xattr_DosEAs);	/* load the current list */	status = pvfs_doseas_load(pvfs, name, fd, ealist);	if (!NT_STATUS_IS_OK(status)) {		return status;	}	for (j=0;j<num_eas;j++) {		struct ea_struct *ea = &eas[j];		/* see if its already there */		for (i=0;i<ealist->num_eas;i++) {			if (strcasecmp_m(ealist->eas[i].name, ea->name.s) == 0) {				ealist->eas[i].value = ea->value;				break;			}		}		if (i==ealist->num_eas) {			/* add it */			ealist->eas = talloc_realloc(ealist, ealist->eas, 						       struct xattr_EA, 						       ealist->num_eas+1);			if (ealist->eas == NULL) {				return NT_STATUS_NO_MEMORY;			}			ealist->eas[i].name = ea->name.s;			ealist->eas[i].value = ea->value;			ealist->num_eas++;		}	}		/* pull out any null EAs */	for (i=0;i<ealist->num_eas;i++) {		if (ealist->eas[i].value.length == 0) {			memmove(&ealist->eas[i],				&ealist->eas[i+1],				(ealist->num_eas-(i+1)) * sizeof(ealist->eas[i]));			ealist->num_eas--;			i--;		}	}	status = pvfs_doseas_save(pvfs, name, fd, ealist);	if (!NT_STATUS_IS_OK(status)) {		return status;	}	notify_trigger(pvfs->notify_context, 		       NOTIFY_ACTION_MODIFIED, 		       FILE_NOTIFY_CHANGE_EA,		       name->full_name);	name->dos.ea_size = 4;	for (i=0;i<ealist->num_eas;i++) {		name->dos.ea_size += 4 + strlen(ealist->eas[i].name)+1 + 			ealist->eas[i].value.length;	}	/* update the ea_size attrib */	return pvfs_dosattrib_save(pvfs, name, fd);}/*  set info on a open file*/NTSTATUS pvfs_setfileinfo(struct ntvfs_module_context *ntvfs,			  struct ntvfs_request *req, 			  union smb_setfileinfo *info){	struct pvfs_state *pvfs = ntvfs->private_data;	struct utimbuf unix_times;	struct pvfs_file *f;	struct pvfs_file_handle *h;	struct pvfs_filename newstats;	NTSTATUS status;	uint32_t access_needed;	uint32_t change_mask = 0;	f = pvfs_find_fd(pvfs, req, info->generic.in.file.ntvfs);	if (!f) {		return NT_STATUS_INVALID_HANDLE;	}	h = f->handle;	access_needed = pvfs_setfileinfo_access(info);	if ((f->access_mask & access_needed) != access_needed) {		return NT_STATUS_ACCESS_DENIED;	}	/* update the file information */	status = pvfs_resolve_name_handle(pvfs, h);	if (!NT_STATUS_IS_OK(status)) {		return status;	}	/* we take a copy of the current file stats, then update	   newstats in each of the elements below. At the end we	   compare, and make any changes needed */	newstats = *h->name;	switch (info->generic.level) {	case RAW_SFILEINFO_SETATTR:		if (!null_time(info->setattr.in.write_time)) {			unix_to_nt_time(&newstats.dos.write_time, info->setattr.in.write_time);		}		if (info->setattr.in.attrib != FILE_ATTRIBUTE_NORMAL) {			newstats.dos.attrib = info->setattr.in.attrib;		}  		break;	case RAW_SFILEINFO_SETATTRE:	case RAW_SFILEINFO_STANDARD:		if (!null_time(info->setattre.in.create_time)) {			unix_to_nt_time(&newstats.dos.create_time, info->setattre.in.create_time);		}		if (!null_time(info->setattre.in.access_time)) {			unix_to_nt_time(&newstats.dos.access_time, info->setattre.in.access_time);		}		if (!null_time(info->setattre.in.write_time)) {			unix_to_nt_time(&newstats.dos.write_time, info->setattre.in.write_time);		}  		break;	case RAW_SFILEINFO_EA_SET:		return pvfs_setfileinfo_ea_set(pvfs, h->name, h->fd, 					       info->ea_set.in.num_eas,					       info->ea_set.in.eas);	case RAW_SFILEINFO_BASIC_INFO:	case RAW_SFILEINFO_BASIC_INFORMATION:		if (!null_nttime(info->basic_info.in.create_time)) {			newstats.dos.create_time = info->basic_info.in.create_time;		}		if (!null_nttime(info->basic_info.in.access_time)) {			newstats.dos.access_time = info->basic_info.in.access_time;		}		if (!null_nttime(info->basic_info.in.write_time)) {			newstats.dos.write_time = info->basic_info.in.write_time;		}		if (!null_nttime(info->basic_info.in.change_time)) {			newstats.dos.change_time = info->basic_info.in.change_time;		}		if (info->basic_info.in.attrib != 0) {			newstats.dos.attrib = info->basic_info.in.attrib;		}  		break;	case RAW_SFILEINFO_DISPOSITION_INFO:	case RAW_SFILEINFO_DISPOSITION_INFORMATION:		return pvfs_set_delete_on_close(pvfs, req, f, 						info->disposition_info.in.delete_on_close);	case RAW_SFILEINFO_ALLOCATION_INFO:	case RAW_SFILEINFO_ALLOCATION_INFORMATION:		status = pvfs_break_level2_oplocks(f);		NT_STATUS_NOT_OK_RETURN(status);		newstats.dos.alloc_size = info->allocation_info.in.alloc_size;		if (newstats.dos.alloc_size < newstats.st.st_size) {			newstats.st.st_size = newstats.dos.alloc_size;		}		newstats.dos.alloc_size = pvfs_round_alloc_size(pvfs, 								newstats.dos.alloc_size);		break;	case RAW_SFILEINFO_END_OF_FILE_INFO:	case RAW_SFILEINFO_END_OF_FILE_INFORMATION:		status = pvfs_break_level2_oplocks(f);		NT_STATUS_NOT_OK_RETURN(status);		newstats.st.st_size = info->end_of_file_info.in.size;		break;	case RAW_SFILEINFO_POSITION_INFORMATION:		h->position = info->position_information.in.position;		break;	case RAW_SFILEINFO_MODE_INFORMATION:		/* this one is a puzzle */		if (info->mode_information.in.mode != 0 &&		    info->mode_information.in.mode != 2 &&		    info->mode_information.in.mode != 4 &&		    info->mode_information.in.mode != 6) {			return NT_STATUS_INVALID_PARAMETER;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -