Exemplo n.º 1
0
static NTSTATUS pvfs_search_next_smb2(struct ntvfs_module_context *ntvfs,
				      struct ntvfs_request *req, const struct smb2_find *io, 
				      void *search_private, 
				      bool (*callback)(void *, const union smb_search_data *))
{
	struct pvfs_state *pvfs = talloc_get_type(ntvfs->private_data,
				  struct pvfs_state);
	struct pvfs_search_state *search;
	unsigned int reply_count;
	uint16_t max_count;
	NTSTATUS status;
	struct pvfs_file *f;

	f = pvfs_find_fd(pvfs, req, io->in.file.ntvfs);
	if (!f) {
		return NT_STATUS_FILE_CLOSED;
	}

	/* its only valid for directories */
	if (f->handle->fd != -1) {
		return NT_STATUS_INVALID_PARAMETER;
	}

	/* if there's no search started on the dir handle, it's like a search_first */
	search = f->search;
	if (!search) {
		return pvfs_search_first_smb2(ntvfs, req, io, search_private, callback);
	}

	if (io->in.continue_flags & SMB2_CONTINUE_FLAG_RESTART) {
		search->current_index = 0;
	}

	if (io->in.continue_flags & SMB2_CONTINUE_FLAG_SINGLE) {
		max_count = 1;
	} else {
		max_count = UINT16_MAX;
	}

	status = pvfs_search_fill(pvfs, req, max_count, search, io->data_level,
				  &reply_count, search_private, callback);
	NT_STATUS_NOT_OK_RETURN(status);

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

	return NT_STATUS_OK;
}
Exemplo n.º 2
0
/*
  query info on a open file
*/
NTSTATUS pvfs_qfileinfo(struct ntvfs_module_context *ntvfs,
		        struct ntvfs_request *req, union smb_fileinfo *info)
{
	struct pvfs_state *pvfs = talloc_get_type(ntvfs->private_data,
				  struct pvfs_state);
	struct pvfs_file *f;
	struct pvfs_file_handle *h;
	NTSTATUS status;
	uint32_t access_needed;

	f = pvfs_find_fd(pvfs, req, info->generic.in.file.ntvfs);
	if (!f) {
		return NT_STATUS_INVALID_HANDLE;
	}
	h = f->handle;

	access_needed = pvfs_fileinfo_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;
	}
	
	status = pvfs_map_fileinfo(pvfs, req, h->name, info, h->fd);

	/* a qfileinfo can fill in a bit more info than a qpathinfo -
	   now modify the levels that need to be fixed up */
	switch (info->generic.level) {
	case RAW_FILEINFO_STANDARD_INFO:
	case RAW_FILEINFO_STANDARD_INFORMATION:
		if (pvfs_delete_on_close_set(pvfs, h)) {
			info->standard_info.out.delete_pending = 1;
			info->standard_info.out.nlink--;
		}
		break;

	case RAW_FILEINFO_ALL_INFO:
	case RAW_FILEINFO_ALL_INFORMATION:
		if (pvfs_delete_on_close_set(pvfs, h)) {
			info->all_info.out.delete_pending = 1;
			info->all_info.out.nlink--;
		}
		break;

	case RAW_FILEINFO_POSITION_INFORMATION:
		info->position_information.out.position = h->position;
		break;

	case RAW_FILEINFO_ACCESS_INFORMATION:
		info->access_information.out.access_flags = f->access_mask;
		break;

	case RAW_FILEINFO_MODE_INFORMATION:
		info->mode_information.out.mode = h->mode;
		break;

	case RAW_FILEINFO_SMB2_ALL_INFORMATION:
		if (pvfs_delete_on_close_set(pvfs, h)) {
			info->all_info2.out.delete_pending = 1;
			info->all_info2.out.nlink--;
		}
		info->all_info2.out.position	= h->position;
		info->all_info2.out.access_mask	= f->access_mask;
		info->all_info2.out.mode	= h->mode;
		break;

	default:
		break;
	}
	
	return status;
}
Exemplo n.º 3
0
static NTSTATUS pvfs_search_first_smb2(struct ntvfs_module_context *ntvfs,
				       struct ntvfs_request *req, const struct smb2_find *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 max_count;
	const char *pattern;
	NTSTATUS status;
	struct pvfs_filename *name;
	struct pvfs_file *f;

	f = pvfs_find_fd(pvfs, req, io->in.file.ntvfs);
	if (!f) {
		return NT_STATUS_FILE_CLOSED;
	}

	/* its only valid for directories */
	if (f->handle->fd != -1) {
		return NT_STATUS_INVALID_PARAMETER;
	}

	if (!(f->access_mask & SEC_DIR_LIST)) {
		return NT_STATUS_ACCESS_DENIED;
	}

	if (f->search) {
		talloc_free(f->search);
		f->search = NULL;
	}

	if (strequal(io->in.pattern, "")) {
		return NT_STATUS_OBJECT_NAME_INVALID;
	}
	if (strchr_m(io->in.pattern, '\\')) {
		return NT_STATUS_OBJECT_NAME_INVALID;
	}
	if (strchr_m(io->in.pattern, '/')) {
		return NT_STATUS_OBJECT_NAME_INVALID;
	}

	if (strequal("", f->handle->name->original_name)) {
		pattern = talloc_asprintf(req, "%s", io->in.pattern);
		NT_STATUS_HAVE_NO_MEMORY(pattern);
	} else {
		pattern = talloc_asprintf(req, "%s\\%s",
					  f->handle->name->original_name,
					  io->in.pattern);
		NT_STATUS_HAVE_NO_MEMORY(pattern);
	}

	/* resolve the cifs name to a posix name */
	status = pvfs_resolve_name(pvfs, req, pattern, PVFS_RESOLVE_WILDCARD, &name);
	NT_STATUS_NOT_OK_RETURN(status);

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

	/* 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);
	NT_STATUS_HAVE_NO_MEMORY(search);

	/* do the actual directory listing */
	status = pvfs_list_start(pvfs, name, search, &dir);
	NT_STATUS_NOT_OK_RETURN(status);

	search->pvfs		= pvfs;
	search->handle		= INVALID_SEARCH_HANDLE;
	search->dir		= dir;
	search->current_index	= 0;
	search->search_attrib	= 0x0000FFFF;
	search->must_attrib	= 0;
	search->last_used	= 0;
	search->num_ea_names	= 0;
	search->ea_names	= NULL;
	search->te		= NULL;

	if (io->in.continue_flags & SMB2_CONTINUE_FLAG_SINGLE) {
		max_count = 1;
	} else {
		max_count = UINT16_MAX;
	}

	status = pvfs_search_fill(pvfs, req, max_count, search, io->data_level,
				  &reply_count, search_private, callback);
	NT_STATUS_NOT_OK_RETURN(status);

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

	f->search = talloc_steal(f, search);

	return NT_STATUS_OK;
}
Exemplo n.º 4
0
/*
  read from a file
*/
NTSTATUS pvfs_read(struct ntvfs_module_context *ntvfs,
		   struct ntvfs_request *req, union smb_read *rd)
{
	struct pvfs_state *pvfs = talloc_get_type(ntvfs->private_data,
				  struct pvfs_state);
	ssize_t ret;
	struct pvfs_file *f;
	NTSTATUS status;
	uint32_t maxcnt;
	uint32_t mask;

	if (rd->generic.level != RAW_READ_READX) {
		return ntvfs_map_read(ntvfs, req, rd);
	}

	f = pvfs_find_fd(pvfs, req, rd->readx.in.file.ntvfs);
	if (!f) {
		return NT_STATUS_INVALID_HANDLE;
	}

	if (f->handle->fd == -1) {
		return NT_STATUS_INVALID_DEVICE_REQUEST;
	}

	mask = SEC_FILE_READ_DATA;
	if (rd->readx.in.read_for_execute) {
		mask |= SEC_FILE_EXECUTE;
	}
	if (!(f->access_mask & mask)) {
		return NT_STATUS_ACCESS_DENIED;
	}

	maxcnt = rd->readx.in.maxcnt;
	if (maxcnt > 2*UINT16_MAX && req->ctx->protocol < PROTOCOL_SMB2) {
		DEBUG(3,(__location__ ": Invalid SMB maxcnt 0x%x\n", maxcnt));
		return NT_STATUS_INVALID_PARAMETER;
	}

	status = pvfs_check_lock(pvfs, f, req->smbpid, 
				 rd->readx.in.offset,
				 maxcnt,
				 READ_LOCK);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	if (f->handle->name->stream_name) {
		ret = pvfs_stream_read(pvfs, f->handle, 
				       rd->readx.out.data, maxcnt, rd->readx.in.offset);
	} else {
#if HAVE_LINUX_AIO
		/* possibly try an aio read */
		if ((req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC) &&
		    (pvfs->flags & PVFS_FLAG_LINUX_AIO)) {
			status = pvfs_aio_pread(req, rd, f, maxcnt);
			if (NT_STATUS_IS_OK(status)) {
				return NT_STATUS_OK;
			}
		}
#endif
		ret = pread(f->handle->fd, 
			    rd->readx.out.data, 
			    maxcnt,
			    rd->readx.in.offset);
	}
	if (ret == -1) {
		return pvfs_map_errno(pvfs, errno);
	}

	/* only SMB2 honors mincnt */
	if (req->ctx->protocol == PROTOCOL_SMB2) {
		if (rd->readx.in.mincnt > ret ||
		    (ret == 0 && maxcnt > 0)) {
			return NT_STATUS_END_OF_FILE;
		}
	}

	f->handle->position = f->handle->seek_offset = rd->readx.in.offset + ret;

	rd->readx.out.nread = ret;
	rd->readx.out.remaining = 0xFFFF;
	rd->readx.out.compaction_mode = 0; 

	return NT_STATUS_OK;
}