smbclient: Slightly simplify do_mget()
authorVolker Lendecke <vl@samba.org>
Mon, 28 Sep 2020 12:21:24 +0000 (14:21 +0200)
committerKarolin Seeger <kseeger@samba.org>
Thu, 26 Nov 2020 08:17:15 +0000 (08:17 +0000)
Put the prompt query into a separate if-statement, move the "quest"
variable closer to its use

Bug: https://bugzilla.samba.org/show_bug.cgi?id=14517
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 71bc4d4b8d94458ac2e40d659f06110d434fd5c9)

source3/client/client.c

index 5bed37fc2a2ccd2744811eeba3cd5b287d58725e..5901419f427136b6f74e4b0b6d90fa9a03ccecf2 100644 (file)
@@ -1203,7 +1203,6 @@ static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
        TALLOC_CTX *ctx = talloc_tos();
        NTSTATUS status = NT_STATUS_OK;
        char *rname = NULL;
-       char *quest = NULL;
        char *saved_curdir = NULL;
        char *mget_mask = NULL;
        char *new_cd = NULL;
@@ -1215,23 +1214,24 @@ static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
        if (strequal(finfo->name,".") || strequal(finfo->name,".."))
                return NT_STATUS_OK;
 
-       if (finfo->attr & FILE_ATTRIBUTE_DIRECTORY) {
-               if (asprintf(&quest,
-                        "Get directory %s? ",finfo->name) < 0) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-       } else {
-               if (asprintf(&quest,
-                        "Get file %s? ",finfo->name) < 0) {
+       if (prompt) {
+               const char *object = (finfo->attr & FILE_ATTRIBUTE_DIRECTORY) ?
+                       "directory" : "file";
+               char *quest = NULL;
+               bool ok;
+
+               quest = talloc_asprintf(
+                       ctx, "Get %s %s? ", object, finfo->name);
+               if (quest == NULL) {
                        return NT_STATUS_NO_MEMORY;
                }
-       }
 
-       if (prompt && !yesno(quest)) {
-               SAFE_FREE(quest);
-               return NT_STATUS_OK;
+               ok = yesno(quest);
+               TALLOC_FREE(quest);
+               if (!ok) {
+                       return NT_STATUS_OK;
+               }
        }
-       SAFE_FREE(quest);
 
        if (!(finfo->attr & FILE_ATTRIBUTE_DIRECTORY)) {
                rname = talloc_asprintf(ctx,