The branch, v3-2-test has been updated via f4c0961a16a84dcdfe6e2faafb75c76983e6d466 (commit) via 33ee0cfb190a883229d0824d7194898fd8966ceb (commit) via 46c12de07fe6f44bcf58ca9de276e7932384843d (commit) via 0cd1ed0424ce87f60070d43caffda41be6706d59 (commit) via d4ae42b1b2982dd786d6da16d7fa964d25fd3356 (commit) via 3e8f43e3cf97f10be4717978643ef3edca8650a5 (commit) from 0177158d85797e0d22c81d88175a77d4ad5ed711 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test - Log ----------------------------------------------------------------- commit f4c0961a16a84dcdfe6e2faafb75c76983e6d466 Author: Stefan Metzmacher <[EMAIL PROTECTED]> Date: Mon Oct 15 11:02:24 2007 +0200 fix the compilation of getpass.c and it's configure test metze commit 33ee0cfb190a883229d0824d7194898fd8966ceb Author: Jeremy Allison <[EMAIL PROTECTED]> Date: Fri Jun 16 23:07:42 2006 +0000 r16320: Ensure variable is not null before calling fclose. Klocwork #412. Jeremy. commit 46c12de07fe6f44bcf58ca9de276e7932384843d Author: Jeremy Allison <[EMAIL PROTECTED]> Date: Thu Jun 15 05:32:21 2006 +0000 r16245: Cope with string being zero len. Klocwork bug #410. Jeremy. commit 0cd1ed0424ce87f60070d43caffda41be6706d59 Author: jmcd <[EMAIL PROTECTED]> Date: Thu Oct 23 13:47:17 2003 +0000 Volker's fix for bug #668. Change the \n after the password prompt to go to tty instead of stdout. commit d4ae42b1b2982dd786d6da16d7fa964d25fd3356 Author: Stefan Metzmacher <[EMAIL PROTECTED]> Date: Fri Oct 5 16:20:38 2007 +0200 reapply: Allow ^C to interrupt smbpasswd if using our getpass. from Jeremy metze commit 3e8f43e3cf97f10be4717978643ef3edca8650a5 Author: Stefan Metzmacher <[EMAIL PROTECTED]> Date: Fri Oct 5 15:55:19 2007 +0200 reformat getpass() replacement code metze ----------------------------------------------------------------------- Summary of changes: source/lib/replace/getpass.c | 161 +++++++++++++++++++++++------------------ source/lib/replace/getpass.m4 | 5 +- 2 files changed, 91 insertions(+), 75 deletions(-) Changeset truncated at 500 lines: diff --git a/source/lib/replace/getpass.c b/source/lib/replace/getpass.c index f6a72ad..4b21849 100644 --- a/source/lib/replace/getpass.c +++ b/source/lib/replace/getpass.c @@ -49,8 +49,6 @@ typedef int sig_atomic_t; #define SIGNAL_CAST (RETSIGTYPE (*)(int)) #endif -#ifdef REPLACE_GETPASS - #ifdef SYSV_TERMIO /* SYSTEM V TERMIO HANDLING */ @@ -131,81 +129,102 @@ static void catch_signal(int signum,void (*handler)(int )) sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask,signum); sigaction(signum,&act,&oldact); - return oldact.sa_handler; #else /* !HAVE_SIGACTION */ /* FIXME: need to handle sigvec and systems with broken signal() */ - return signal(signum, handler); + signal(signum, handler); #endif } +static sig_atomic_t gotintr; +static int in_fd = -1; + +/*************************************************************** + Signal function to tell us were ^C'ed. +****************************************************************/ + +static void gotintr_sig(void) +{ + gotintr = 1; + if (in_fd != -1) + close(in_fd); /* Safe way to force a return. */ + in_fd = -1; +} + char *getsmbpass(const char *prompt) { - FILE *in, *out; - int echo_off; - static char buf[256]; - static size_t bufsize = sizeof(buf); - size_t nread; - - /* Catch problematic signals */ - catch_signal(SIGINT, SIGNAL_CAST SIG_IGN); - - /* Try to write to and read from the terminal if we can. - If we can't open the terminal, use stderr and stdin. */ - - in = fopen ("/dev/tty", "w+"); - if (in == NULL) - { - in = stdin; - out = stderr; - } - else - out = in; - - setvbuf(in, NULL, _IONBF, 0); - - /* Turn echoing off if it is on now. */ - - if (tcgetattr (fileno (in), &t) == 0) - { - if (ECHO_IS_ON(t)) - { - TURN_ECHO_OFF(t); - echo_off = tcsetattr (fileno (in), TCSAFLUSH, &t) == 0; - TURN_ECHO_ON(t); + FILE *in, *out; + int echo_off; + static char buf[256]; + static size_t bufsize = sizeof(buf); + size_t nread; + + /* Catch problematic signals */ + catch_signal(SIGINT, SIGNAL_CAST gotintr_sig); + + /* Try to write to and read from the terminal if we can. + If we can't open the terminal, use stderr and stdin. */ + + in = fopen ("/dev/tty", "w+"); + if (in == NULL) { + in = stdin; + out = stderr; + } else { + out = in; } - else - echo_off = 0; - } - else - echo_off = 0; - - /* Write the prompt. */ - fputs (prompt, out); - fflush (out); - - /* Read the password. */ - buf[0] = 0; - fgets(buf, bufsize, in); - nread = strlen(buf); - if (buf[nread - 1] == '\n') - buf[nread - 1] = '\0'; - - /* Restore echoing. */ - if (echo_off) - (void) tcsetattr (fileno (in), TCSANOW, &t); - - if (in != stdin) - /* We opened the terminal; now close it. */ - fclose (in); - - /* Catch problematic signals */ - catch_signal(SIGINT, SIGNAL_CAST SIG_DFL); - - printf("\n"); - return buf; -} -#else - void getsmbpasswd_dummy(void); - void getsmbpasswd_dummy(void) {;} -#endif + setvbuf(in, NULL, _IONBF, 0); + + /* Turn echoing off if it is on now. */ + + if (tcgetattr (fileno (in), &t) == 0) { + if (ECHO_IS_ON(t)) { + TURN_ECHO_OFF(t); + echo_off = tcsetattr (fileno (in), TCSAFLUSH, &t) == 0; + TURN_ECHO_ON(t); + } else { + echo_off = 0; + } + } else { + echo_off = 0; + } + + /* Write the prompt. */ + fputs(prompt, out); + fflush(out); + + /* Read the password. */ + buf[0] = 0; + if (!gotintr) { + in_fd = fileno(in); + fgets(buf, bufsize, in); + } + nread = strlen(buf); + if (nread) { + if (buf[nread - 1] == '\n') + buf[nread - 1] = '\0'; + } + + /* Restore echoing. */ + if (echo_off) { + if (gotintr && in_fd == -1) + in = fopen ("/dev/tty", "w+"); + if (in != NULL) + tcsetattr (fileno (in), TCSANOW, &t); + } + + fprintf(out, "\n"); + fflush(out); + + if (in && in != stdin) /* We opened the terminal; now close it. */ + fclose(in); + + /* Catch problematic signals */ + catch_signal(SIGINT, SIGNAL_CAST SIG_DFL); + + if (gotintr) { + printf("Interupted by signal.\n"); + fflush(stdout); + exit(1); + } + return buf; +} diff --git a/source/lib/replace/getpass.m4 b/source/lib/replace/getpass.m4 index 20d04a6..17dfdf7 100644 --- a/source/lib/replace/getpass.m4 +++ b/source/lib/replace/getpass.m4 @@ -3,11 +3,8 @@ SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS -I$libreplacedir/" AC_TRY_COMPILE([ #include "confdefs.h" -#define _LIBREPLACE_REPLACE_H -#define REPLACE_GETPASS 1 -#define main dont_declare_main +#define NO_CONFIG_H #include "$libreplacedir/getpass.c" -#undef main ],[],samba_cv_REPLACE_GETPASS=yes,samba_cv_REPLACE_GETPASS=no) CPPFLAGS="$SAVE_CPPFLAGS" ]) -- Samba Shared Repository