From: Jeremy Allison Date: Fri, 3 Oct 2008 21:56:30 +0000 (-0700) Subject: Correctly fix smbclient to terminate on eof from server. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4dc2eb7f42bad6812d21bf4577e2901b04a5ca83;p=thirdparty%2Fsamba.git Correctly fix smbclient to terminate on eof from server. Jeremy. --- diff --git a/source/client/client.c b/source/client/client.c index d794f8fe53d..dc5e0f5359d 100644 --- a/source/client/client.c +++ b/source/client/client.c @@ -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; diff --git a/source/lib/readline.c b/source/lib/readline.c index 254f55c86a1..fd57799b578 100644 --- a/source/lib/readline.c +++ b/source/lib/readline.c @@ -45,6 +45,16 @@ # 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; } /****************************************************************************