summaryrefslogtreecommitdiffstats
path: root/source3/client/clitar.c
diff options
context:
space:
mode:
authorDavid Disseldorp <ddiss@samba.org>2014-02-14 17:16:14 +0100
committerAndreas Schneider <asn@samba.org>2014-02-19 18:22:29 +0100
commit8dc6f0fb39647e37a444ac582b5b33e27b40b3dc (patch)
tree3469cdd8a5a29a0ec4282a89aab2787f4e537665 /source3/client/clitar.c
parent14c6e9b6b8c0f67a0cd85508c94413fb42ac20f7 (diff)
downloadsamba-8dc6f0fb39647e37a444ac582b5b33e27b40b3dc.tar.gz
samba-8dc6f0fb39647e37a444ac582b5b33e27b40b3dc.tar.xz
samba-8dc6f0fb39647e37a444ac582b5b33e27b40b3dc.zip
clitar: get tar context handle via helper function
Add and use tar_get_ctx() to get the tarmode context handle in client.c, rather than declaring an extern. Also, add checks for NULL context pointer arguments. Signed-off-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'source3/client/clitar.c')
-rw-r--r--source3/client/clitar.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/source3/client/clitar.c b/source3/client/clitar.c
index e0c9c94d335..37c31ac3d9e 100644
--- a/source3/client/clitar.c
+++ b/source3/client/clitar.c
@@ -24,8 +24,8 @@
* the context of the backup process.
*
* The current tar context can be accessed via the global variable
- * `tar_ctx`. It's not static but you should avoid accessing it
- * directly.
+ * `tar_ctx`. It's publicly exported as an opaque handle via
+ * tar_get_ctx().
*
* A tar context is first configured through tar_parse_args() which
* can be called from either the CLI (in client.c) or the interactive
@@ -232,6 +232,13 @@ static int max_token (const char *str);
static bool is_subpath(const char *sub, const char *full);
static int set_remote_attr(const char *filename, uint16 new_attr, int mode);
+/**
+ * tar_get_ctx - retrieve global tar context handle
+ */
+struct tar *tar_get_ctx()
+{
+ return &tar_ctx;
+}
/**
* cmd_block - interactive command to change tar blocksize
@@ -475,12 +482,17 @@ int cmd_setmode(void)
int tar_parse_args(struct tar* t, const char *flag,
const char **val, int valsize)
{
- TALLOC_CTX *ctx = tar_reset_mem_context(t);
+ TALLOC_CTX *ctx;
bool list = false;
-
/* index of next value to use */
int ival = 0;
+ if (t == NULL) {
+ DBG(0, ("Invalid tar context\n"));
+ return 1;
+ }
+
+ ctx = tar_reset_mem_context(t);
/*
* Reset back some options - could be from interactive version
* all other modes are left as they are
@@ -659,6 +671,11 @@ int tar_process(struct tar *t)
{
int rc = 0;
+ if (t == NULL) {
+ DBG(0, ("Invalid tar context\n"));
+ return 1;
+ }
+
switch(t->mode.operation) {
case TAR_EXTRACT:
rc = tar_extract(t);
@@ -1353,6 +1370,10 @@ static bool tar_create_skip_path(struct tar *t,
*/
bool tar_to_process (struct tar *t)
{
+ if (t == NULL) {
+ DBG(0, ("Invalid tar context\n"));
+ return false;
+ }
return t->to_process;
}
@@ -1683,13 +1704,6 @@ static char *path_base_name (const char *path)
#define NOT_IMPLEMENTED DEBUG(0, ("tar mode not compiled. build with --with-libarchive\n"))
-struct tar
-{
- int dummy;
-};
-
-struct tar tar_ctx;
-
int cmd_block(void)
{
NOT_IMPLEMENTED;
@@ -1732,4 +1746,9 @@ bool tar_to_process(struct tar *tar)
return false;
}
+struct tar *tar_get_ctx()
+{
+ return NULL;
+}
+
#endif