1
0
mirror of https://github.com/samba-team/samba.git synced 2025-09-17 05:44:20 +03:00

clitar: add error return to tar_create_skip_path()

In preparation for propagation of memory allocation errors from
tar_path_in_list() and friends.

Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
David Disseldorp
2014-02-20 19:47:45 +01:00
committed by Andrew Bartlett
parent 385f0c9ea0
commit 4d9e1b68b7

View File

@@ -204,9 +204,10 @@ static void tar_dump(struct tar *t);
static bool tar_extract_skip_path(struct tar *t, struct archive_entry *entry); static bool tar_extract_skip_path(struct tar *t, struct archive_entry *entry);
static TALLOC_CTX *tar_reset_mem_context(struct tar *t); static TALLOC_CTX *tar_reset_mem_context(struct tar *t);
static void tar_free_mem_context(struct tar *t); static void tar_free_mem_context(struct tar *t);
static bool tar_create_skip_path(struct tar *t, static NTSTATUS tar_create_skip_path(struct tar *t,
const char *fullpath, const char *fullpath,
const struct file_info *finfo); const struct file_info *finfo,
bool *_skip);
static bool tar_path_in_list(struct tar *t, static bool tar_path_in_list(struct tar *t,
const char *path, const char *path,
@@ -857,9 +858,10 @@ static NTSTATUS get_file_callback(struct cli_state *cli,
const char *dir) const char *dir)
{ {
TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL)); TALLOC_CTX *ctx = PANIC_IF_NULL(talloc_new(NULL));
NTSTATUS err = NT_STATUS_OK; NTSTATUS status = NT_STATUS_OK;
char *remote_name; char *remote_name;
const char *initial_dir = client_get_cur_dir(); const char *initial_dir = client_get_cur_dir();
bool skip = false;
int rc; int rc;
remote_name = PANIC_IF_NULL(talloc_asprintf(ctx, "%s%s", remote_name = PANIC_IF_NULL(talloc_asprintf(ctx, "%s%s",
@@ -869,9 +871,14 @@ static NTSTATUS get_file_callback(struct cli_state *cli,
goto out; goto out;
} }
rc = tar_create_skip_path(&tar_ctx, remote_name, finfo); status = tar_create_skip_path(&tar_ctx, remote_name, finfo, &skip);
if (rc != 0) { if (!NT_STATUS_IS_OK(status)) {
goto out;
}
if (skip) {
DBG(5, ("--- %s\n", remote_name)); DBG(5, ("--- %s\n", remote_name));
status = NT_STATUS_OK;
goto out; goto out;
} }
@@ -887,7 +894,7 @@ static NTSTATUS get_file_callback(struct cli_state *cli,
rc = tar_get_file(&tar_ctx, remote_name, finfo); rc = tar_get_file(&tar_ctx, remote_name, finfo);
if (rc != 0) { if (rc != 0) {
err = NT_STATUS_UNSUCCESSFUL; status = NT_STATUS_UNSUCCESSFUL;
goto out; goto out;
} }
@@ -897,14 +904,14 @@ static NTSTATUS get_file_callback(struct cli_state *cli,
} else { } else {
rc = tar_get_file(&tar_ctx, remote_name, finfo); rc = tar_get_file(&tar_ctx, remote_name, finfo);
if (rc != 0) { if (rc != 0) {
err = NT_STATUS_UNSUCCESSFUL; status = NT_STATUS_UNSUCCESSFUL;
goto out; goto out;
} }
} }
out: out:
talloc_free(ctx); talloc_free(ctx);
return err; return status;
} }
/** /**
@@ -1338,18 +1345,19 @@ static bool tar_extract_skip_path(struct tar *t,
} }
/** /**
* tar_create_skip_path - return true if @fullpath shoud be skipped * tar_create_skip_path - check if @fullpath shoud be skipped
* @fullpath: full remote path of the current file * @fullpath: full remote path of the current file
* @finfo: remote file attributes * @finfo: remote file attributes
* @_skip: returned skip not
* *
* Skip predicate for tar creation (server to archive) only. * Skip predicate for tar creation (server to archive) only.
*/ */
static bool tar_create_skip_path(struct tar *t, static NTSTATUS tar_create_skip_path(struct tar *t,
const char *fullpath, const char *fullpath,
const struct file_info *finfo) const struct file_info *finfo,
bool *_skip)
{ {
/* syntaxic sugar */ /* syntaxic sugar */
const bool skip = true;
const mode_t mode = finfo->mode; const mode_t mode = finfo->mode;
const bool isdir = mode & FILE_ATTRIBUTE_DIRECTORY; const bool isdir = mode & FILE_ATTRIBUTE_DIRECTORY;
const bool exclude = t->mode.selection == TAR_EXCLUDE; const bool exclude = t->mode.selection == TAR_EXCLUDE;
@@ -1359,17 +1367,20 @@ static bool tar_create_skip_path(struct tar *t,
/* 1. if we dont want X and we have X, skip */ /* 1. if we dont want X and we have X, skip */
if (!t->mode.system && (mode & FILE_ATTRIBUTE_SYSTEM)) { if (!t->mode.system && (mode & FILE_ATTRIBUTE_SYSTEM)) {
return skip; *_skip = true;
return NT_STATUS_OK;
} }
if (!t->mode.hidden && (mode & FILE_ATTRIBUTE_HIDDEN)) { if (!t->mode.hidden && (mode & FILE_ATTRIBUTE_HIDDEN)) {
return skip; *_skip = true;
return NT_STATUS_OK;
} }
/* 2. if we only want archive and it's not, skip */ /* 2. if we only want archive and it's not, skip */
if (t->mode.incremental && !(mode & FILE_ATTRIBUTE_ARCHIVE)) { if (t->mode.incremental && !(mode & FILE_ATTRIBUTE_ARCHIVE)) {
return skip; *_skip = true;
return NT_STATUS_OK;
} }
} }
@@ -1380,14 +1391,16 @@ static bool tar_create_skip_path(struct tar *t,
* point, no need to check * point, no need to check
*/ */
if (!exclude) { if (!exclude) {
return !skip; *_skip = false;
return NT_STATUS_OK;
} }
/* we are now in exclude mode */ /* we are now in exclude mode */
/* no matter the selection, no list => include everything */ /* no matter the selection, no list => include everything */
if (t->path_list_size <= 0) { if (t->path_list_size <= 0) {
return !skip; *_skip = false;
return NT_STATUS_OK;
} }
if (t->mode.regex) { if (t->mode.regex) {
@@ -1395,8 +1408,9 @@ static bool tar_create_skip_path(struct tar *t,
} else { } else {
in = tar_path_in_list(t, fullpath, isdir && !exclude); in = tar_path_in_list(t, fullpath, isdir && !exclude);
} }
*_skip = in;
return in ? skip : !skip; return NT_STATUS_OK;
} }
/** /**