Tweaks to fix issues with building the lib and client under Windows. Added .fwknop...
authorDamien Stuart <dstuart@dstuart.org>
Mon, 19 Nov 2012 04:59:10 +0000 (23:59 -0500)
committerDamien Stuart <dstuart@dstuart.org>
Mon, 19 Nov 2012 13:43:14 +0000 (08:43 -0500)
12 files changed:
client/fwknop.c
client/http_resolve_host.c
client/utils.c
client/utils.h
common/common.h
configure.ac
fwknop.spec
lib/Makefile.am
lib/fko_decode.c
lib/fko_message.h
lib/fko_user.c
win32/libfko.vcproj

index fbe1e4a..9a18ddd 100644 (file)
@@ -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) {
index e2a61f8..bdde3f2 100644 (file)
@@ -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);
         }
     }
index d5b9180..53b49d6 100644 (file)
@@ -28,6 +28,7 @@
  *
  *****************************************************************************
 */
+#include "common.h"
 #include "fwknop_common.h"
 #include "utils.h"
 
index c951314..a6f051a 100644 (file)
 #ifndef UTILS_H
 #define UTILS_H
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
-
 #if HAVE_CONFIG_H
   #include "config.h"
 #endif
index 4daa3b8..f064240 100644 (file)
   #include <unistd.h>
 #endif
 
+#ifdef HAVE_SYS_STAT_H
+  #include <sys/stat.h>
+#endif
+
 #if HAVE_NETINET_IN_H
   #include <netinet/in.h>
 #endif
   #include <time.h>
 #endif
 
+/* Some hoops for accommodating Windows
+*/
 #ifdef WIN32
+  #include <io.h>
   #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 <signal.h>
index 4336bb4..cb31015 100644 (file)
@@ -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
 
index ba82878..88b2c8d 100644 (file)
@@ -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.
 
index 2e30c08..03a43c1 100644 (file)
@@ -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
index f60fa1b..f94a67b 100644 (file)
@@ -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);
 
index 8c57252..fbe25c2 100644 (file)
 #ifndef FKO_MESSAGE_H
 #define FKO_MESSAGE_H 1
 
-#if PLATFORM_OPENBSD
-  #include <sys/types.h>
-  #include <netinet/in.h>
-#else
-  #if HAVE_SYS_SOCKET_H
-    #include <sys/socket.h>
-  #endif
-#endif
-#include <arpa/inet.h>
+#include "common.h"
+#include "netinet_common.h"
 
 #define MAX_PROTO_STR_LEN   4  /* tcp, udp, icmp for now */
 #define MAX_PORT_STR_LEN    5
index 00deb84..c2d6a8b 100644 (file)
@@ -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);
index 6bd9fd5..1eb779b 100644 (file)
@@ -42,7 +42,7 @@
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
                                EnableIntrinsicFunctions="false"\r
-                               AdditionalIncludeDirectories=".;..\lib;..\client"\r
+                               AdditionalIncludeDirectories=".;..\common;..\lib;..\client"\r
                                PreprocessorDefinitions="DLL_EXPORTS;WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS"\r
                                MinimalRebuild="true"\r
                                ExceptionHandling="0"\r
                                Name="VCCLCompilerTool"\r
                                Optimization="2"\r
                                EnableIntrinsicFunctions="false"\r
-                               AdditionalIncludeDirectories=".;..\lib;..\client"\r
+                               AdditionalIncludeDirectories=".;..\common;..\lib;..\client"\r
                                PreprocessorDefinitions="DLL_EXPORTS;WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS"\r
                                RuntimeLibrary="2"\r
                                EnableFunctionLevelLinking="true"\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
                                EnableIntrinsicFunctions="false"\r
-                               AdditionalIncludeDirectories=".;..\lib;..\client"\r
+                               AdditionalIncludeDirectories=".;..\common;..\lib;..\client"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS"\r
                                MinimalRebuild="true"\r
                                ExceptionHandling="0"\r
                                Name="VCCLCompilerTool"\r
                                Optimization="2"\r
                                EnableIntrinsicFunctions="false"\r
-                               AdditionalIncludeDirectories=".;..\lib;..\client"\r
+                               AdditionalIncludeDirectories=".;..\common;..\lib;..\client"\r
                                PreprocessorDefinitions="WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS"\r
                                RuntimeLibrary="2"\r
                                EnableFunctionLevelLinking="true"\r
                                Name="VCCLCompilerTool"\r
                                Optimization="2"\r
                                EnableIntrinsicFunctions="false"\r
-                               AdditionalIncludeDirectories=".;..\lib;..\client"\r
+                               AdditionalIncludeDirectories=".;..\common;..\lib;..\client"\r
                                PreprocessorDefinitions="WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS"\r
                                RuntimeLibrary="0"\r
                                EnableFunctionLevelLinking="true"\r