static NTSTATUS cmd_pathfunc(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) { int ret = -1; if (argc != 2) { printf("Usage: %s <path>\n", argv[0]); return NT_STATUS_OK; } if (strcmp("rmdir", argv[0]) == 0 ) { ret = SMB_VFS_RMDIR(vfs->conn, argv[1]); } else if (strcmp("unlink", argv[0]) == 0 ) { ret = SMB_VFS_UNLINK(vfs->conn, argv[1]); } else if (strcmp("chdir", argv[0]) == 0 ) { ret = SMB_VFS_CHDIR(vfs->conn, argv[1]); } else { printf("%s: error=%d (invalid function name!)\n", argv[0], errno); return NT_STATUS_UNSUCCESSFUL; } if (ret == -1) { printf("%s: error=%d (%s)\n", argv[0], errno, strerror(errno)); return NT_STATUS_UNSUCCESSFUL; } printf("%s: ok\n", argv[0]); return NT_STATUS_OK; }
static int acl_common_remove_object(vfs_handle_struct *handle, const char *path, bool is_directory) { connection_struct *conn = handle->conn; struct file_id id; files_struct *fsp = NULL; int ret = 0; char *parent_dir = NULL; const char *final_component = NULL; struct smb_filename local_fname; int saved_errno = 0; if (!parent_dirname(talloc_tos(), path, &parent_dir, &final_component)) { saved_errno = ENOMEM; goto out; } DEBUG(10,("acl_common_remove_object: removing %s %s/%s\n", is_directory ? "directory" : "file", parent_dir, final_component )); /* cd into the parent dir to pin it. */ ret = SMB_VFS_CHDIR(conn, parent_dir); if (ret == -1) { saved_errno = errno; goto out; } ZERO_STRUCT(local_fname); local_fname.base_name = CONST_DISCARD(char *,final_component); /* Must use lstat here. */ ret = SMB_VFS_LSTAT(conn, &local_fname); if (ret == -1) { saved_errno = errno; goto out; } /* Ensure we have this file open with DELETE access. */ id = vfs_file_id_from_sbuf(conn, &local_fname.st); for (fsp = file_find_di_first(id); fsp; file_find_di_next(fsp)) { if (fsp->access_mask & DELETE_ACCESS && fsp->delete_on_close) { /* We did open this for delete, * allow the delete as root. */ break; } } if (!fsp) { DEBUG(10,("acl_common_remove_object: %s %s/%s " "not an open file\n", is_directory ? "directory" : "file", parent_dir, final_component )); saved_errno = EACCES; goto out; } become_root(); if (is_directory) { ret = SMB_VFS_NEXT_RMDIR(handle, final_component); } else { ret = SMB_VFS_NEXT_UNLINK(handle, &local_fname); } unbecome_root(); if (ret == -1) { saved_errno = errno; } out: TALLOC_FREE(parent_dir); vfs_ChDir(conn, conn->connectpath); if (saved_errno) { errno = saved_errno; } return ret; }