/* return info on a pathname */ NTSTATUS pvfs_qpathinfo(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_filename *name; NTSTATUS status; /* resolve the cifs name to a posix name */ status = pvfs_resolve_name(pvfs, req, info->generic.in.file.path, PVFS_RESOLVE_STREAMS, &name); if (!NT_STATUS_IS_OK(status)) { return status; } if (!name->stream_exists) { return NT_STATUS_OBJECT_NAME_NOT_FOUND; } status = pvfs_can_stat(pvfs, req, name); if (!NT_STATUS_IS_OK(status)) { return status; } status = pvfs_access_check_simple(pvfs, req, name, pvfs_fileinfo_access(info)); if (!NT_STATUS_IS_OK(status)) { return status; } status = pvfs_map_fileinfo(pvfs, req, name, info, -1); return status; }
/* 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; }
/* remove a directory */ NTSTATUS pvfs_rmdir(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, struct smb_rmdir *rd) { struct pvfs_state *pvfs = talloc_get_type(ntvfs->private_data, struct pvfs_state); NTSTATUS status; struct pvfs_filename *name; /* resolve the cifs name to a posix name */ status = pvfs_resolve_name(pvfs, req, rd->in.path, 0, &name); if (!NT_STATUS_IS_OK(status)) { return status; } if (!name->exists) { return NT_STATUS_OBJECT_NAME_NOT_FOUND; } status = pvfs_access_check_simple(pvfs, req, name, SEC_STD_DELETE); if (!NT_STATUS_IS_OK(status)) { return status; } status = pvfs_xattr_unlink_hook(pvfs, name->full_name); if (!NT_STATUS_IS_OK(status)) { return status; } if (pvfs_sys_rmdir(pvfs, name->full_name, name->allow_override) == -1) { /* some olders systems don't return ENOTEMPTY to rmdir() */ if (errno == EEXIST) { return NT_STATUS_DIRECTORY_NOT_EMPTY; } return pvfs_map_errno(pvfs, errno); } notify_trigger(pvfs->notify_context, NOTIFY_ACTION_REMOVED, FILE_NOTIFY_CHANGE_DIR_NAME, name->full_name); return NT_STATUS_OK; }
/* check if a directory exists */ static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_chkpath *cp) { struct pvfs_state *pvfs = ntvfs->private_data; struct pvfs_filename *name; NTSTATUS status; /* resolve the cifs name to a posix name */ status = pvfs_resolve_name(pvfs, req, cp->chkpath.in.path, 0, &name); NT_STATUS_NOT_OK_RETURN(status); if (!name->exists) { return NT_STATUS_OBJECT_NAME_NOT_FOUND; } if (!S_ISDIR(name->st.st_mode)) { return NT_STATUS_NOT_A_DIRECTORY; } return NT_STATUS_OK; }
/* delete a file - the dirtype specifies the file types to include in the search. The name can contain CIFS wildcards, but rarely does (except with OS/2 clients) */ NTSTATUS pvfs_unlink(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_unlink *unl) { struct pvfs_state *pvfs = talloc_get_type(ntvfs->private_data, struct pvfs_state); struct pvfs_dir *dir; NTSTATUS status; uint32_t total_deleted=0; struct pvfs_filename *name; const char *fname; off_t ofs; /* resolve the cifs name to a posix name */ status = pvfs_resolve_name(pvfs, req, unl->unlink.in.pattern, PVFS_RESOLVE_WILDCARD | PVFS_RESOLVE_STREAMS | PVFS_RESOLVE_NO_OPENDB, &name); if (!NT_STATUS_IS_OK(status)) { return status; } if (!name->exists && !name->has_wildcard) { return NT_STATUS_OBJECT_NAME_NOT_FOUND; } if (name->exists && (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)) { return NT_STATUS_FILE_IS_A_DIRECTORY; } if (!name->has_wildcard) { return pvfs_unlink_one(pvfs, req, unl, name); } /* * disable async requests in the wildcard case * untill we have proper tests for this */ req->async_states->state &= ~NTVFS_ASYNC_STATE_MAY_ASYNC; /* get list of matching files */ status = pvfs_list_start(pvfs, name, req, &dir); if (!NT_STATUS_IS_OK(status)) { return status; } status = NT_STATUS_NO_SUCH_FILE; talloc_free(name); ofs = 0; while ((fname = pvfs_list_next(dir, &ofs))) { /* this seems to be a special case */ if ((unl->unlink.in.attrib & FILE_ATTRIBUTE_DIRECTORY) && (ISDOT(fname) || ISDOTDOT(fname))) { return NT_STATUS_OBJECT_NAME_INVALID; } /* get a pvfs_filename object */ status = pvfs_resolve_partial(pvfs, req, pvfs_list_unix_path(dir), fname, PVFS_RESOLVE_NO_OPENDB, &name); if (!NT_STATUS_IS_OK(status)) { return status; } status = pvfs_unlink_one(pvfs, req, unl, name); if (NT_STATUS_IS_OK(status)) { total_deleted++; } talloc_free(name); } if (total_deleted > 0) { status = NT_STATUS_OK; } return status; }
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; }
/* 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; }
/* 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; }
/* 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; }
/* open a directory */ static NTSTATUS pvfs_open_directory(struct pvfs_state *pvfs, struct ntvfs_request *req, struct pvfs_filename *name, union smb_open *io) { struct pvfs_file *f; struct ntvfs_handle *h; NTSTATUS status; uint32_t create_action; uint32_t access_mask = io->generic.in.access_mask; struct odb_lock *lck; BOOL del_on_close; uint32_t create_options; uint32_t share_access; create_options = io->generic.in.create_options; share_access = io->generic.in.share_access; if (name->stream_name) { return NT_STATUS_NOT_A_DIRECTORY; } /* if the client says it must be a directory, and it isn't, then fail */ if (name->exists && !(name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)) { return NT_STATUS_NOT_A_DIRECTORY; } switch (io->generic.in.open_disposition) { case NTCREATEX_DISP_OPEN_IF: break; case NTCREATEX_DISP_OPEN: if (!name->exists) { return NT_STATUS_OBJECT_NAME_NOT_FOUND; } break; case NTCREATEX_DISP_CREATE: if (name->exists) { return NT_STATUS_OBJECT_NAME_COLLISION; } break; case NTCREATEX_DISP_OVERWRITE_IF: case NTCREATEX_DISP_OVERWRITE: case NTCREATEX_DISP_SUPERSEDE: default: return NT_STATUS_INVALID_PARAMETER; } status = ntvfs_handle_new(pvfs->ntvfs, req, &h); NT_STATUS_NOT_OK_RETURN(status); f = talloc(h, struct pvfs_file); if (f == NULL) { return NT_STATUS_NO_MEMORY; } f->handle = talloc(f, struct pvfs_file_handle); if (f->handle == NULL) { return NT_STATUS_NO_MEMORY; } if (name->exists) { /* check the security descriptor */ status = pvfs_access_check(pvfs, req, name, &access_mask); } else { status = pvfs_access_check_create(pvfs, req, name, &access_mask); } if (!NT_STATUS_IS_OK(status)) { return status; } f->ntvfs = h; f->pvfs = pvfs; f->pending_list = NULL; f->lock_count = 0; f->share_access = io->generic.in.share_access; f->impersonation = io->generic.in.impersonation; f->access_mask = access_mask; f->brl_handle = NULL; f->notify_buffer = NULL; f->search = NULL; f->handle->pvfs = pvfs; f->handle->name = talloc_steal(f->handle, name); f->handle->fd = -1; f->handle->odb_locking_key = data_blob(NULL, 0); f->handle->create_options = io->generic.in.create_options; f->handle->seek_offset = 0; f->handle->position = 0; f->handle->mode = 0; f->handle->sticky_write_time = False; if ((create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) && pvfs_directory_empty(pvfs, f->handle->name)) { del_on_close = True; } else { del_on_close = False; } if (name->exists) { /* form the lock context used for opendb locking */ status = pvfs_locking_key(name, f->handle, &f->handle->odb_locking_key); if (!NT_STATUS_IS_OK(status)) { return status; } /* get a lock on this file before the actual open */ lck = odb_lock(req, pvfs->odb_context, &f->handle->odb_locking_key); if (lck == NULL) { DEBUG(0,("pvfs_open: failed to lock file '%s' in opendb\n", name->full_name)); /* we were supposed to do a blocking lock, so something is badly wrong! */ return NT_STATUS_INTERNAL_DB_CORRUPTION; } /* see if we are allowed to open at the same time as existing opens */ status = odb_open_file(lck, f->handle, f->handle->name->stream_id, share_access, access_mask, del_on_close, name->full_name, OPLOCK_NONE, NULL); if (!NT_STATUS_IS_OK(status)) { talloc_free(lck); return status; } f->handle->have_opendb_entry = True; } DLIST_ADD(pvfs->files.list, f); /* setup destructors to avoid leaks on abnormal termination */ talloc_set_destructor(f->handle, pvfs_dir_handle_destructor); talloc_set_destructor(f, pvfs_dir_fnum_destructor); if (!name->exists) { uint32_t attrib = io->generic.in.file_attr | FILE_ATTRIBUTE_DIRECTORY; mode_t mode = pvfs_fileperms(pvfs, attrib); if (mkdir(name->full_name, mode) == -1) { return pvfs_map_errno(pvfs,errno); } pvfs_xattr_unlink_hook(pvfs, name->full_name); status = pvfs_resolve_name(pvfs, req, io->ntcreatex.in.fname, 0, &name); if (!NT_STATUS_IS_OK(status)) { goto cleanup_delete; } status = pvfs_open_setup_eas_acl(pvfs, req, name, -1, f, io); if (!NT_STATUS_IS_OK(status)) { goto cleanup_delete; } /* form the lock context used for opendb locking */ status = pvfs_locking_key(name, f->handle, &f->handle->odb_locking_key); if (!NT_STATUS_IS_OK(status)) { return status; } lck = odb_lock(req, pvfs->odb_context, &f->handle->odb_locking_key); if (lck == NULL) { DEBUG(0,("pvfs_open: failed to lock file '%s' in opendb\n", name->full_name)); /* we were supposed to do a blocking lock, so something is badly wrong! */ return NT_STATUS_INTERNAL_DB_CORRUPTION; } status = odb_open_file(lck, f->handle, f->handle->name->stream_id, share_access, access_mask, del_on_close, name->full_name, OPLOCK_NONE, NULL); if (!NT_STATUS_IS_OK(status)) { goto cleanup_delete; } f->handle->have_opendb_entry = True; create_action = NTCREATEX_ACTION_CREATED; notify_trigger(pvfs->notify_context, NOTIFY_ACTION_ADDED, FILE_NOTIFY_CHANGE_DIR_NAME, name->full_name); } else { create_action = NTCREATEX_ACTION_EXISTED; } if (!name->exists) { return NT_STATUS_OBJECT_NAME_NOT_FOUND; } /* the open succeeded, keep this handle permanently */ status = ntvfs_handle_set_backend_data(h, pvfs->ntvfs, f); if (!NT_STATUS_IS_OK(status)) { goto cleanup_delete; } io->generic.out.oplock_level = OPLOCK_NONE; io->generic.out.file.ntvfs = h; io->generic.out.create_action = create_action; io->generic.out.create_time = name->dos.create_time; io->generic.out.access_time = name->dos.access_time; io->generic.out.write_time = name->dos.write_time; io->generic.out.change_time = name->dos.change_time; io->generic.out.attrib = name->dos.attrib; io->generic.out.alloc_size = name->dos.alloc_size; io->generic.out.size = name->st.st_size; io->generic.out.file_type = FILE_TYPE_DISK; io->generic.out.ipc_state = 0; io->generic.out.is_directory = 1; return NT_STATUS_OK; cleanup_delete: rmdir(name->full_name); return status; }
/* 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; }