Correctly fix smbclient to terminate on eof from server.
authorJeremy Allison <jra@samba.org>
Fri, 3 Oct 2008 21:56:30 +0000 (14:56 -0700)
committerMichael Adam <obnox@samba.org>
Fri, 24 Oct 2008 13:43:14 +0000 (15:43 +0200)
Jeremy.
(cherry picked from commit 4dc2eb7f42bad6812d21bf4577e2901b04a5ca83)
(cherry picked from commit 28fa519a80bfcd30737a51ad157d134322c1fed9)

source/client/client.c
source/lib/readline.c

index d794f8fe53d42fb9cbdc0f879879a23174306e2c..dc5e0f5359d87be2c859493f7da635269ff41afd 100644 (file)
@@ -4342,6 +4342,8 @@ cleanup:
        }
 }
 
+static bool finished;
+
 /****************************************************************************
  Make sure we swallow keepalives during idle time.
 ****************************************************************************/
@@ -4388,6 +4390,8 @@ static void readline_callback(void)
                        DEBUG(0, ("Read from server failed, maybe it closed "
                                  "the connection\n"));
 
+                       finished = true;
+                       smb_readline_done();
                        if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
                                set_smb_read_error(&cli->smb_rw_error,
                                                   SMB_READ_EOF);
@@ -4416,7 +4420,12 @@ static void readline_callback(void)
        {
                unsigned char garbage[16];
                memset(garbage, 0xf0, sizeof(garbage));
-               cli_echo(cli, 1, garbage, sizeof(garbage));
+               if (!cli_echo(cli, 1, garbage, sizeof(garbage))) {
+                       DEBUG(0, ("SMBecho failed. Maybe server has closed "
+                                 "the connection\n"));
+                       smb_readline_done();
+                       finished = true;
+               }
        }
 }
 
@@ -4428,7 +4437,7 @@ static int process_stdin(void)
 {
        int rc = 0;
 
-       while (1) {
+       while (!finished) {
                TALLOC_CTX *frame = talloc_stackframe();
                char *tok = NULL;
                char *the_prompt = NULL;
index 254f55c86a14f8dce32e062994cb166970a7684f..fd57799b578ba8e58bb117882bcec10a1d4fabc8 100644 (file)
 #  define RL_COMPLETION_CAST
 #endif /* HAVE_NEW_LIBREADLINE */
 
+static bool smb_rl_done;
+
+void smb_readline_done(void)
+{
+       smb_rl_done = true;
+#if HAVE_LIBREADLINE
+       rl_done = 1;
+#endif
+}
+
 /****************************************************************************
  Display the prompt and wait for input. Call callback() regularly
 ****************************************************************************/
@@ -69,7 +79,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
                return NULL;
        }
 
-       while (1) {
+       while (!smb_rl_done) {
                timeout.tv_sec = 5;
                timeout.tv_usec = 0;
 
@@ -87,6 +97,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
                        callback();
                }
        }
+       return NULL;
 }
 
 /****************************************************************************