diff --git a/client/fwknop.c b/client/fwknop.c index fbe1e4a9..9a18dddd 100644 --- a/client/fwknop.c +++ b/client/fwknop.c @@ -532,11 +532,14 @@ get_save_file(char *args_save_file) char *homedir = NULL; int rv = 0; +#ifdef WIN32 + homedir = getenv("USERPROFILE"); +#else homedir = getenv("HOME"); - +#endif if (homedir != NULL) { - snprintf(args_save_file, MAX_PATH_LEN, "%s%s%s", - homedir, "/", ".fwknop.run"); + snprintf(args_save_file, MAX_PATH_LEN, "%s%c%s", + homedir, PATH_SEP, ".fwknop.run"); rv = 1; } @@ -552,14 +555,6 @@ show_last_command(void) char args_str[MAX_LINE_LEN] = ""; FILE *args_file_ptr = NULL; -#ifdef WIN32 - /* Not sure what the right thing is here on Win32, just exit - * for now. - */ - fprintf(stderr, "--show-last not implemented on Win32 yet."); - exit(EXIT_FAILURE); -#endif - if (get_save_file(args_save_file)) { verify_file_perms_ownership(args_save_file); if ((args_file_ptr = fopen(args_save_file, "r")) == NULL) { @@ -594,14 +589,6 @@ run_last_args(fko_cli_options_t *options) char arg_tmp[MAX_LINE_LEN] = {0}; char *argv_new[MAX_CMDLINE_ARGS]; /* should be way more than enough */ - -#ifdef WIN32 - /* Not sure what the right thing is here on Win32, just return - * for now. - */ - return; -#endif - if (get_save_file(args_save_file)) { verify_file_perms_ownership(args_save_file); @@ -664,13 +651,6 @@ save_args(int argc, char **argv) char args_str[MAX_LINE_LEN] = ""; int i = 0, args_str_len = 0, args_file_fd = -1; -#ifdef WIN32 - /* Not sure what the right thing is here on Win32, just return - * for now. - */ - return; -#endif - if (get_save_file(args_save_file)) { args_file_fd = open(args_save_file, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR); if (args_file_fd == -1) { diff --git a/client/http_resolve_host.c b/client/http_resolve_host.c index e2a61f8b..bdde3f2d 100644 --- a/client/http_resolve_host.c +++ b/client/http_resolve_host.c @@ -329,7 +329,9 @@ resolve_ip_http(fko_cli_options_t *options) */ strlcpy(url.host, HTTP_BACKUP_RESOLVE_HOST, MAX_URL_HOST_LEN); +#ifndef WIN32 sleep(2); +#endif res = try_url(&url, options); } } diff --git a/client/utils.c b/client/utils.c index d5b91807..53b49d66 100644 --- a/client/utils.c +++ b/client/utils.c @@ -28,6 +28,7 @@ * ***************************************************************************** */ +#include "common.h" #include "fwknop_common.h" #include "utils.h" diff --git a/client/utils.h b/client/utils.h index c951314e..a6f051ab 100644 --- a/client/utils.h +++ b/client/utils.h @@ -31,13 +31,6 @@ #ifndef UTILS_H #define UTILS_H -#include -#include -#include -#include -#include -#include - #if HAVE_CONFIG_H #include "config.h" #endif diff --git a/common/common.h b/common/common.h index 4daa3b8b..f064240a 100644 --- a/common/common.h +++ b/common/common.h @@ -58,6 +58,10 @@ #include #endif +#ifdef HAVE_SYS_STAT_H + #include +#endif + #if HAVE_NETINET_IN_H #include #endif @@ -70,11 +74,24 @@ #include #endif +/* Some hoops for accommodating Windows +*/ #ifdef WIN32 + #include #define strcasecmp _stricmp #define strncasecmp _strnicmp #define snprintf _snprintf #define unlink _unlink + #define open _open + #define close _close + #define write _write + #define O_WRONLY _O_WRONLY + #define O_RDONLY _O_RDONLY + #define O_RDWR _O_RDWR + #define O_CREAT _O_CREAT + #define O_EXCL _O_EXCL + #define S_IRUSR _S_IREAD + #define S_IWUSR _S_IWRITE #define PATH_SEP '\\' #else #include diff --git a/configure.ac b/configure.ac index 4336bb4b..cb31015f 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ AC_CONFIG_AUX_DIR(config) AC_CANONICAL_TARGET -AM_INIT_AUTOMAKE([tar-ustar -Wall -Werror foreign]) +AM_INIT_AUTOMAKE([tar-ustar -Wall foreign]) dnl AM_MAINTAINER_MODE diff --git a/fwknop.spec b/fwknop.spec index ba82878e..88b2c8d7 100644 --- a/fwknop.spec +++ b/fwknop.spec @@ -14,7 +14,7 @@ Name: fwknop Version: 2.0.4 -Epoch: 1 +Epoch: 1 Release: 1%{?dist} Summary: Firewall Knock Operator client. An implementation of Single Packet Authorization. diff --git a/lib/Makefile.am b/lib/Makefile.am index 2e30c087..03a43c18 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -12,8 +12,8 @@ libfko_source_files = \ libfko_la_SOURCES = $(libfko_source_files) -libfko_la_LDFLAGS = -version-info 0:3:0 $(GPGME_LIBS) +libfko_la_LDFLAGS = -version-info 0:4:0 $(GPGME_LIBS) -AM_CPPFLAGS = $(GPGME_CFLAGS) +AM_CPPFLAGS = $(GPGME_CFLAGS) -I $(top_srcdir)/common include_HEADERS = fko.h fko_limits.h fko_message.h diff --git a/lib/fko_decode.c b/lib/fko_decode.c index f60fa1b9..f94a67b6 100644 --- a/lib/fko_decode.c +++ b/lib/fko_decode.c @@ -54,7 +54,7 @@ fko_decode_spa_data(fko_ctx_t ctx) /* Make sure there are no non-ascii printable chars */ - for (i=0; i < strnlen(ctx->encoded_msg, MAX_SPA_ENCODED_MSG_SIZE); i++) + for (i=0; i < (int)strnlen(ctx->encoded_msg, MAX_SPA_ENCODED_MSG_SIZE); i++) if(isprint(ctx->encoded_msg[i]) == 0) return(FKO_ERROR_INVALID_DATA); diff --git a/lib/fko_message.h b/lib/fko_message.h index 8c57252d..fbe25c2a 100644 --- a/lib/fko_message.h +++ b/lib/fko_message.h @@ -32,15 +32,8 @@ #ifndef FKO_MESSAGE_H #define FKO_MESSAGE_H 1 -#if PLATFORM_OPENBSD - #include - #include -#else - #if HAVE_SYS_SOCKET_H - #include - #endif -#endif -#include +#include "common.h" +#include "netinet_common.h" #define MAX_PROTO_STR_LEN 4 /* tcp, udp, icmp for now */ #define MAX_PORT_STR_LEN 5 diff --git a/lib/fko_user.c b/lib/fko_user.c index 00deb848..c2d6a8b7 100644 --- a/lib/fko_user.c +++ b/lib/fko_user.c @@ -72,13 +72,16 @@ fko_set_username(fko_ctx_t ctx, const char *spoof_user) #else username = getlogin(); #endif - /* if we still didn't get a username, fall back + /* if we still didn't get a username, continue falling back */ - if((username = getenv("USER")) == NULL) - { - username = strdup("NO_USER"); - if(username == NULL) - return(FKO_ERROR_MEMORY_ALLOCATION); + if(username == NULL) + { + if((username = getenv("USER")) == NULL) + { + username = strdup("NO_USER"); + if(username == NULL) + return(FKO_ERROR_MEMORY_ALLOCATION); + } } } } @@ -135,7 +138,7 @@ validate_username(const char *username) if(isalnum(username[0]) == 0) return(FKO_ERROR_INVALID_DATA); - for (i=1; i < strnlen(username, MAX_SPA_USERNAME_SIZE); i++) + for (i=1; i < (int)strnlen(username, MAX_SPA_USERNAME_SIZE); i++) if((isalnum(username[i]) == 0) && username[i] != '-' && username[i] != '_') return(FKO_ERROR_INVALID_DATA); diff --git a/win32/libfko.vcproj b/win32/libfko.vcproj index 6bd9fd5c..1eb779bb 100644 --- a/win32/libfko.vcproj +++ b/win32/libfko.vcproj @@ -42,7 +42,7 @@ Name="VCCLCompilerTool" Optimization="0" EnableIntrinsicFunctions="false" - AdditionalIncludeDirectories=".;..\lib;..\client" + AdditionalIncludeDirectories=".;..\common;..\lib;..\client" PreprocessorDefinitions="DLL_EXPORTS;WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS" MinimalRebuild="true" ExceptionHandling="0" @@ -117,7 +117,7 @@ Name="VCCLCompilerTool" Optimization="2" EnableIntrinsicFunctions="false" - AdditionalIncludeDirectories=".;..\lib;..\client" + AdditionalIncludeDirectories=".;..\common;..\lib;..\client" PreprocessorDefinitions="DLL_EXPORTS;WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS" RuntimeLibrary="2" EnableFunctionLevelLinking="true" @@ -185,7 +185,7 @@ Name="VCCLCompilerTool" Optimization="0" EnableIntrinsicFunctions="false" - AdditionalIncludeDirectories=".;..\lib;..\client" + AdditionalIncludeDirectories=".;..\common;..\lib;..\client" PreprocessorDefinitions="WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS" MinimalRebuild="true" ExceptionHandling="0" @@ -251,7 +251,7 @@ Name="VCCLCompilerTool" Optimization="2" EnableIntrinsicFunctions="false" - AdditionalIncludeDirectories=".;..\lib;..\client" + AdditionalIncludeDirectories=".;..\common;..\lib;..\client" PreprocessorDefinitions="WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS" RuntimeLibrary="2" EnableFunctionLevelLinking="true" @@ -314,7 +314,7 @@ Name="VCCLCompilerTool" Optimization="2" EnableIntrinsicFunctions="false" - AdditionalIncludeDirectories=".;..\lib;..\client" + AdditionalIncludeDirectories=".;..\common;..\lib;..\client" PreprocessorDefinitions="WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS" RuntimeLibrary="0" EnableFunctionLevelLinking="true"