From 4b0f0802eedb1451029aac319ff063182650ee07 Mon Sep 17 00:00:00 2001 From: "Damien S. Stuart" Date: Wed, 17 Jul 2013 22:46:24 -0400 Subject: [PATCH] Tweaks to unbreak the windows build: Renamed FD_SET macro to FD_SET_ALT to avoid conflict with the well-known FD_SET macro. Made the client read password from file descriptor a non-supported function on Windows. --- client/cmd_opts.h | 4 ++-- client/config_init.c | 10 +++++++++- client/getpasswd.c | 27 +++++++-------------------- common/common.h | 1 + lib/fko_common.h | 2 +- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/client/cmd_opts.h b/client/cmd_opts.h index e503b212..33d7529b 100644 --- a/client/cmd_opts.h +++ b/client/cmd_opts.h @@ -59,7 +59,7 @@ enum { KEY_HMAC_BASE64, KEY_HMAC, FD_SET_STDIN, - FD_SET, + FD_SET_ALT, /* Put GPG-related items below the following line */ GPG_ENCRYPTION = 0x200, GPG_RECIP_KEY, @@ -91,7 +91,7 @@ static struct option cmd_opts[] = {"destination", 1, NULL, 'D'}, {"save-args-file", 1, NULL, 'E'}, {"encryption-mode", 1, NULL, ENCRYPTION_MODE}, - {"fd", 1, NULL, FD_SET}, + {"fd", 1, NULL, FD_SET_ALT}, {"fw-timeout", 1, NULL, 'f'}, {"gpg-encryption", 0, NULL, 'g'}, {"gpg-recipient-key", 1, NULL, GPG_RECIP_KEY }, diff --git a/client/config_init.c b/client/config_init.c index 6d5988e3..a87fb869 100644 --- a/client/config_init.c +++ b/client/config_init.c @@ -37,6 +37,10 @@ #include #include +#ifdef WIN32 + #define STDIN_FILENO 0 +#endif + #define RC_PARAM_TEMPLATE "%-24s %s\n" /*!< Template to define param = val in a rc file */ #define RC_SECTION_DEFAULT "default" /*!< Name of the default section in fwknoprc */ #define RC_SECTION_TEMPLATE "[%s]\n" /*!< Template to define a section in a rc file */ @@ -2138,7 +2142,11 @@ config_init(fko_cli_options_t *options, int argc, char **argv) case FD_SET_STDIN: options->input_fd = STDIN_FILENO; break; - case FD_SET: + case FD_SET_ALT: +#ifdef WIN32 + log_msg(LOG_VERBOSITY_ERROR, "Read password from FD not supported on Windows"); + exit(EXIT_FAILURE); +#endif options->input_fd = strtol_wrapper(optarg, 0, -1, EXIT_UPON_ERR, &is_err); break; diff --git a/client/getpasswd.c b/client/getpasswd.c index 827bb309..75d30069 100644 --- a/client/getpasswd.c +++ b/client/getpasswd.c @@ -128,11 +128,15 @@ char* getpasswd(const char *prompt, int fd) { char *ptr; + FILE *fp; #ifndef WIN32 sigset_t sig, old_sig; struct termios ts, old_ts; - FILE *fp; +#else + /* Force stdin on windows. */ + fd = 0; +#endif /* If a valid file descriptor is supplied, we try to open a stream from it */ if (FD_IS_VALID(fd)) @@ -147,6 +151,7 @@ getpasswd(const char *prompt, int fd) } } +#ifndef WIN32 /* Otherwise we are going to open a new stream */ else { @@ -179,33 +184,15 @@ getpasswd(const char *prompt, int fd) #else _cputs(prompt); #endif - /* Read the password */ ptr = read_passwd_from_stream(fp); -#ifndef WIN32 - - /* If we used a new buffered stream */ - if (FD_IS_VALID(fd) == 0) - { - /* we can go ahead and echo out a newline. - */ - putc(PW_LF_CHAR, fp); - - /* Restore our tty state and signal handlers. - */ - tcsetattr(fileno(fp), TCSAFLUSH, &old_ts); - sigprocmask(SIG_BLOCK, &old_sig, NULL); - } - - fclose(fp); -#else +#ifdef WIN32 /* In Windows, it would be a CR-LF */ _putch(PW_CR_CHAR); _putch(PW_LF_CHAR); #endif - return (ptr); } diff --git a/common/common.h b/common/common.h index 31af6dad..6bb3504f 100644 --- a/common/common.h +++ b/common/common.h @@ -83,6 +83,7 @@ #define snprintf _snprintf #define unlink _unlink #define open _open + #define fdopen _fdopen #define close _close #define write _write #define O_WRONLY _O_WRONLY diff --git a/lib/fko_common.h b/lib/fko_common.h index 323f6c5e..ec37629f 100644 --- a/lib/fko_common.h +++ b/lib/fko_common.h @@ -116,7 +116,7 @@ #ifndef BYTEORDER #if defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) #define BYTEORDER 4321 - #elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) + #elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || defined(WIN32) #define BYTEORDER 1234 #endif #endif