Exemple #1
0
/*
  create a directory
*/
NTSTATUS pvfs_mkdir(struct ntvfs_module_context *ntvfs,
		    struct ntvfs_request *req, union smb_mkdir *md)
{
	struct pvfs_state *pvfs = talloc_get_type(ntvfs->private_data,
				  struct pvfs_state);
	NTSTATUS status;
	struct pvfs_filename *name;
	mode_t mode;

	if (md->generic.level == RAW_MKDIR_T2MKDIR) {
		return pvfs_t2mkdir(pvfs, req, md);
	}

	if (md->generic.level != RAW_MKDIR_MKDIR) {
		return NT_STATUS_INVALID_LEVEL;
	}

	/* resolve the cifs name to a posix name */
	status = pvfs_resolve_name(pvfs, req, md->mkdir.in.path, 0, &name);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	if (name->exists) {
		return NT_STATUS_OBJECT_NAME_COLLISION;
	}

	status = pvfs_access_check_parent(pvfs, req, name, SEC_DIR_ADD_FILE);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	mode = pvfs_fileperms(pvfs, FILE_ATTRIBUTE_DIRECTORY);

	if (pvfs_sys_mkdir(pvfs, name->full_name, mode, name->allow_override) == -1) {
		return pvfs_map_errno(pvfs, errno);
	}

	pvfs_xattr_unlink_hook(pvfs, name->full_name);

	/* setup an inherited acl from the parent */
	status = pvfs_acl_inherit(pvfs, req, name, -1);
	if (!NT_STATUS_IS_OK(status)) {
		pvfs_sys_rmdir(pvfs, name->full_name, name->allow_override);
		return status;
	}

	notify_trigger(pvfs->notify_context, 
		       NOTIFY_ACTION_ADDED, 
		       FILE_NOTIFY_CHANGE_DIR_NAME,
		       name->full_name);

	return NT_STATUS_OK;
}
Exemple #2
0
/* 
   list files in a directory matching a wildcard pattern
*/
static NTSTATUS pvfs_search_first_trans2(struct ntvfs_module_context *ntvfs,
					 struct ntvfs_request *req, union smb_search_first *io, 
					 void *search_private, 
					 bool (*callback)(void *, const union smb_search_data *))
{
	struct pvfs_dir *dir;
	struct pvfs_state *pvfs = talloc_get_type(ntvfs->private_data,
				  struct pvfs_state);
	struct pvfs_search_state *search;
	unsigned int reply_count;
	uint16_t search_attrib, max_count;
	const char *pattern;
	NTSTATUS status;
	struct pvfs_filename *name;
	int id;

	search_attrib = io->t2ffirst.in.search_attrib;
	pattern       = io->t2ffirst.in.pattern;
	max_count     = io->t2ffirst.in.max_count;

	/* resolve the cifs name to a posix name */
	status = pvfs_resolve_name(pvfs, req, pattern, PVFS_RESOLVE_WILDCARD, &name);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	if (!name->has_wildcard && !name->exists) {
		return NT_STATUS_NO_SUCH_FILE;
	}

	status = pvfs_access_check_parent(pvfs, req, name, SEC_DIR_TRAVERSE | SEC_DIR_LIST);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	/* we initially make search a child of the request, then if we
	   need to keep it long term we steal it for the private
	   structure */
	search = talloc(req, struct pvfs_search_state);
	if (!search) {
		return NT_STATUS_NO_MEMORY;
	}

	/* do the actual directory listing */
	status = pvfs_list_start(pvfs, name, search, &dir);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	id = idr_get_new(pvfs->search.idtree, search, MAX_SEARCH_HANDLES);
	if (id == -1) {
		return NT_STATUS_INSUFFICIENT_RESOURCES;
	}

	search->pvfs = pvfs;
	search->handle = id;
	search->dir = dir;
	search->current_index = 0;
	search->search_attrib = search_attrib;
	search->must_attrib = 0;
	search->last_used = 0;
	search->num_ea_names = io->t2ffirst.in.num_names;
	search->ea_names = io->t2ffirst.in.ea_names;
	search->te = NULL;

	DLIST_ADD(pvfs->search.list, search);
	talloc_set_destructor(search, pvfs_search_destructor);

	status = pvfs_search_fill(pvfs, req, max_count, search, io->generic.data_level,
				  &reply_count, search_private, callback);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	/* not matching any entries is an error */
	if (reply_count == 0) {
		return NT_STATUS_NO_SUCH_FILE;
	}

	io->t2ffirst.out.count = reply_count;
	io->t2ffirst.out.handle = search->handle;
	io->t2ffirst.out.end_of_search = pvfs_list_eos(dir, search->current_index) ? 1 : 0;

	/* work out if we are going to keep the search state
	   and allow for a search continue */
	if ((io->t2ffirst.in.flags & FLAG_TRANS2_FIND_CLOSE) ||
	    ((io->t2ffirst.in.flags & FLAG_TRANS2_FIND_CLOSE_IF_END) && 
	     io->t2ffirst.out.end_of_search)) {
		talloc_free(search);
	} else {
		talloc_steal(pvfs, search);
	}

	return NT_STATUS_OK;
}
Exemple #3
0
/* 
   list files in a directory matching a wildcard pattern - old SMBsearch interface
*/
static NTSTATUS pvfs_search_first_old(struct ntvfs_module_context *ntvfs,
				      struct ntvfs_request *req, union smb_search_first *io, 
				      void *search_private, 
				      bool (*callback)(void *, const union smb_search_data *))
{
	struct pvfs_dir *dir;
	struct pvfs_state *pvfs = talloc_get_type(ntvfs->private_data,
				  struct pvfs_state);
	struct pvfs_search_state *search;
	unsigned int reply_count;
	uint16_t search_attrib;
	const char *pattern;
	NTSTATUS status;
	struct pvfs_filename *name;
	int id;

	search_attrib = io->search_first.in.search_attrib;
	pattern       = io->search_first.in.pattern;

	/* resolve the cifs name to a posix name */
	status = pvfs_resolve_name(pvfs, req, pattern, PVFS_RESOLVE_WILDCARD, &name);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	if (!name->has_wildcard && !name->exists) {
		return STATUS_NO_MORE_FILES;
	}

	status = pvfs_access_check_parent(pvfs, req, name, SEC_DIR_TRAVERSE | SEC_DIR_LIST);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	/* we initially make search a child of the request, then if we
	   need to keep it long term we steal it for the private
	   structure */
	search = talloc(req, struct pvfs_search_state);
	if (!search) {
		return NT_STATUS_NO_MEMORY;
	}

	/* do the actual directory listing */
	status = pvfs_list_start(pvfs, name, search, &dir);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	/* we need to give a handle back to the client so it
	   can continue a search */
	id = idr_get_new(pvfs->search.idtree, search, MAX_OLD_SEARCHES);
	if (id == -1) {
		pvfs_search_cleanup(pvfs);
		id = idr_get_new(pvfs->search.idtree, search, MAX_OLD_SEARCHES);
	}
	if (id == -1) {
		return NT_STATUS_INSUFFICIENT_RESOURCES;
	}

	search->pvfs = pvfs;
	search->handle = id;
	search->dir = dir;
	search->current_index = 0;
	search->search_attrib = search_attrib & 0xFF;
	search->must_attrib = (search_attrib>>8) & 0xFF;
	search->last_used = time(NULL);
	search->te = NULL;

	DLIST_ADD(pvfs->search.list, search);

	talloc_set_destructor(search, pvfs_search_destructor);

	status = pvfs_search_fill(pvfs, req, io->search_first.in.max_count, search, io->generic.data_level,
				  &reply_count, search_private, callback);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	io->search_first.out.count = reply_count;

	/* not matching any entries is an error */
	if (reply_count == 0) {
		return STATUS_NO_MORE_FILES;
	}

	talloc_steal(pvfs, search);

	return NT_STATUS_OK;
}
Exemple #4
0
/*
  create a directory with EAs
*/
static NTSTATUS pvfs_t2mkdir(struct pvfs_state *pvfs,
			     struct ntvfs_request *req, union smb_mkdir *md)
{
	NTSTATUS status;
	struct pvfs_filename *name;
	mode_t mode;

	/* resolve the cifs name to a posix name */
	status = pvfs_resolve_name(pvfs, req, md->t2mkdir.in.path, 0, &name);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	if (name->exists) {
		return NT_STATUS_OBJECT_NAME_COLLISION;
	}

	status = pvfs_access_check_parent(pvfs, req, name, SEC_DIR_ADD_FILE);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	mode = pvfs_fileperms(pvfs, FILE_ATTRIBUTE_DIRECTORY);

	if (pvfs_sys_mkdir(pvfs, name->full_name, mode, name->allow_override) == -1) {
		return pvfs_map_errno(pvfs, errno);
	}

	pvfs_xattr_unlink_hook(pvfs, name->full_name);

	status = pvfs_resolve_name(pvfs, req, md->t2mkdir.in.path, 0, &name);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}
	if (!name->exists ||
	    !(name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)) {
		return NT_STATUS_INTERNAL_ERROR;
	}

	/* setup an inherited acl from the parent */
	status = pvfs_acl_inherit(pvfs, req, name, -1);
	if (!NT_STATUS_IS_OK(status)) {
		pvfs_sys_rmdir(pvfs, name->full_name, name->allow_override);
		return status;
	}

	/* setup any EAs that were asked for */
	status = pvfs_setfileinfo_ea_set(pvfs, name, -1, 
					 md->t2mkdir.in.num_eas,
					 md->t2mkdir.in.eas);
	if (!NT_STATUS_IS_OK(status)) {
		pvfs_sys_rmdir(pvfs, name->full_name, name->allow_override);
		return status;
	}

	notify_trigger(pvfs->notify_context, 
		       NOTIFY_ACTION_ADDED, 
		       FILE_NOTIFY_CHANGE_DIR_NAME,
		       name->full_name);

	return NT_STATUS_OK;
}
/*
  rename_information level
*/
static NTSTATUS pvfs_setfileinfo_rename(struct pvfs_state *pvfs, 
					struct ntvfs_request *req, 
					struct pvfs_filename *name,
					int fd,
					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;
	}

	/* handle stream renames specially */
	if (name->stream_name) {
		return pvfs_setfileinfo_rename_stream(pvfs, req, name, fd, 
						      odb_locking_key, info);
	}

	/* 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, req, 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;
}