Updates and revisions to accommodate a Windows build.

git-svn-id: file:///home/mbr/svn/fwknop/trunk@88 510a4753-2344-4c79-9c09-4d669213fbeb
This commit is contained in:
Damien Stuart
2009-05-24 16:46:33 +00:00
parent ee78a35cfd
commit 4192eb8876
25 changed files with 2577 additions and 170 deletions

View File

@@ -23,13 +23,22 @@
*/
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#ifdef WIN32
#include <sys/timeb.h>
#include <time.h>
#include <stdlib.h>
#else
#include <sys/time.h>
#endif
#include "cipher_funcs.h"
#include "digest.h"
#ifndef RAND_FILE
#define RAND_FILE "/dev/urandom"
#ifndef WIN32
#ifndef RAND_FILE
#define RAND_FILE "/dev/urandom"
#endif
#endif
/* Get random data.
@@ -37,9 +46,23 @@
void
get_random_data(unsigned char *data, size_t len)
{
FILE *rfd;
uint32_t i;
#ifdef WIN32
int rnum;
struct _timeb tb;
_ftime_s(&tb);
srand((uint32_t)(tb.time*1000)+tb.millitm);
for(i=0; i<len; i++)
{
rnum = rand();
*(data+i) = rnum % 0xff;
}
#else
FILE *rfd;
struct timeval tv;
int i;
/* Attempt to read seed data from /dev/urandom. If that does not
* work, then fall back to a time-based method (less secure, but
@@ -62,6 +85,8 @@ get_random_data(unsigned char *data, size_t len)
fread(data, len, 1, rfd);
fclose(rfd);
}
#endif
}

126
fko/fko.h
View File

@@ -26,6 +26,24 @@
#ifndef FKO_H
#define FKO_H 1
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WIN32
#ifdef DLL_EXPORTS
#define DLL_API __declspec(dllexport)
#else
#ifdef DLL_IMPORTS
#define DLL_API __declspec(dllimport)
#else
#define DLL_API
#endif
#endif
#else
#define DLL_API
#endif
/* General params
*/
#define FKO_PROTOCOL_VERSION "1.9.12" /* The fwknop protocol version */
@@ -155,77 +173,81 @@ enum {
/* General api calls
*/
int fko_new(fko_ctx_t *ctx);
int fko_new_with_data(fko_ctx_t *ctx, char *enc_msg, char *dec_key);
void fko_destroy(fko_ctx_t ctx);
int fko_spa_data_final(fko_ctx_t ctx, char *enc_key);
DLL_API int fko_new(fko_ctx_t *ctx);
DLL_API int fko_new_with_data(fko_ctx_t *ctx, char *enc_msg, char *dec_key);
DLL_API void fko_destroy(fko_ctx_t ctx);
DLL_API int fko_spa_data_final(fko_ctx_t ctx, char *enc_key);
/* Set context data functions
*/
int fko_set_rand_value(fko_ctx_t ctx, const char *val);
int fko_set_username(fko_ctx_t ctx, const char *spoof_user);
int fko_set_timestamp(fko_ctx_t ctx, int offset);
int fko_set_spa_message_type(fko_ctx_t ctx, short msg_type);
int fko_set_spa_message(fko_ctx_t ctx, const char *msg_string);
int fko_set_spa_nat_access(fko_ctx_t ctx, const char *nat_access);
int fko_set_spa_server_auth(fko_ctx_t ctx, const char *server_auth);
int fko_set_spa_client_timeout(fko_ctx_t ctx, int timeout);
int fko_set_spa_digest_type(fko_ctx_t ctx, short digest_type);
int fko_set_spa_digest(fko_ctx_t ctx);
int fko_set_spa_encryption_type(fko_ctx_t ctx, short encrypt_type);
int fko_set_spa_data(fko_ctx_t ctx, char *enc_msg);
DLL_API int fko_set_rand_value(fko_ctx_t ctx, const char *val);
DLL_API int fko_set_username(fko_ctx_t ctx, const char *spoof_user);
DLL_API int fko_set_timestamp(fko_ctx_t ctx, int offset);
DLL_API int fko_set_spa_message_type(fko_ctx_t ctx, short msg_type);
DLL_API int fko_set_spa_message(fko_ctx_t ctx, const char *msg_string);
DLL_API int fko_set_spa_nat_access(fko_ctx_t ctx, const char *nat_access);
DLL_API int fko_set_spa_server_auth(fko_ctx_t ctx, const char *server_auth);
DLL_API int fko_set_spa_client_timeout(fko_ctx_t ctx, int timeout);
DLL_API int fko_set_spa_digest_type(fko_ctx_t ctx, short digest_type);
DLL_API int fko_set_spa_digest(fko_ctx_t ctx);
DLL_API int fko_set_spa_encryption_type(fko_ctx_t ctx, short encrypt_type);
DLL_API int fko_set_spa_data(fko_ctx_t ctx, char *enc_msg);
/* Data processing and misc utility functions
*/
const char* fko_errstr(int err_code);
DLL_API const char* fko_errstr(int err_code);
int fko_encode_spa_data(fko_ctx_t ctx);
int fko_decode_spa_data(fko_ctx_t ctx);
int fko_encrypt_spa_data(fko_ctx_t ctx, char *enc_key);
int fko_decrypt_spa_data(fko_ctx_t ctx, char *dec_key);
DLL_API int fko_encode_spa_data(fko_ctx_t ctx);
DLL_API int fko_decode_spa_data(fko_ctx_t ctx);
DLL_API int fko_encrypt_spa_data(fko_ctx_t ctx, char *enc_key);
DLL_API int fko_decrypt_spa_data(fko_ctx_t ctx, char *dec_key);
int fko_get_encoded_data(fko_ctx_t ctx, char **enc_data);
DLL_API int fko_get_encoded_data(fko_ctx_t ctx, char **enc_data);
/* Get context data functions
*/
int fko_get_rand_value(fko_ctx_t ctx, char **rand_val);
int fko_get_username(fko_ctx_t ctx, char **username);
int fko_get_timestamp(fko_ctx_t ctx, unsigned int *ts);
int fko_get_spa_message_type(fko_ctx_t ctx, short *spa_msg);
int fko_get_spa_message(fko_ctx_t ctx, char **spa_message);
int fko_get_spa_nat_access(fko_ctx_t ctx, char **nat_access);
int fko_get_spa_server_auth(fko_ctx_t ctx, char **server_auth);
int fko_get_spa_client_timeout(fko_ctx_t ctx, int *client_timeout);
int fko_get_spa_digest_type(fko_ctx_t ctx, short *spa_digest_type);
int fko_get_spa_digest(fko_ctx_t ctx, char **spa_digest);
int fko_get_spa_encryption_type(fko_ctx_t ctx, short *spa_enc_type);
int fko_get_spa_data(fko_ctx_t ctx, char **spa_data);
DLL_API int fko_get_rand_value(fko_ctx_t ctx, char **rand_val);
DLL_API int fko_get_username(fko_ctx_t ctx, char **username);
DLL_API int fko_get_timestamp(fko_ctx_t ctx, time_t *ts);
DLL_API int fko_get_spa_message_type(fko_ctx_t ctx, short *spa_msg);
DLL_API int fko_get_spa_message(fko_ctx_t ctx, char **spa_message);
DLL_API int fko_get_spa_nat_access(fko_ctx_t ctx, char **nat_access);
DLL_API int fko_get_spa_server_auth(fko_ctx_t ctx, char **server_auth);
DLL_API int fko_get_spa_client_timeout(fko_ctx_t ctx, int *client_timeout);
DLL_API int fko_get_spa_digest_type(fko_ctx_t ctx, short *spa_digest_type);
DLL_API int fko_get_spa_digest(fko_ctx_t ctx, char **spa_digest);
DLL_API int fko_get_spa_encryption_type(fko_ctx_t ctx, short *spa_enc_type);
DLL_API int fko_get_spa_data(fko_ctx_t ctx, char **spa_data);
int fko_get_version(fko_ctx_t ctx, char **version);
DLL_API int fko_get_version(fko_ctx_t ctx, char **version);
/* GPG-related functions */
int fko_set_gpg_recipient(fko_ctx_t ctx, const char *recip);
int fko_get_gpg_recipient(fko_ctx_t ctx, char **recip);
int fko_set_gpg_signer(fko_ctx_t ctx, const char *signer);
int fko_get_gpg_signer(fko_ctx_t ctx, char **signer);
int fko_set_gpg_home_dir(fko_ctx_t ctx, const char *gpg_home_dir);
int fko_get_gpg_home_dir(fko_ctx_t ctx, char **gpg_home_dir);
DLL_API int fko_set_gpg_recipient(fko_ctx_t ctx, const char *recip);
DLL_API int fko_get_gpg_recipient(fko_ctx_t ctx, char **recip);
DLL_API int fko_set_gpg_signer(fko_ctx_t ctx, const char *signer);
DLL_API int fko_get_gpg_signer(fko_ctx_t ctx, char **signer);
DLL_API int fko_set_gpg_home_dir(fko_ctx_t ctx, const char *gpg_home_dir);
DLL_API int fko_get_gpg_home_dir(fko_ctx_t ctx, char **gpg_home_dir);
const char* fko_gpg_errorstr(fko_ctx_t ctx);
DLL_API const char* fko_gpg_errorstr(fko_ctx_t ctx);
int fko_set_gpg_signature_verify(fko_ctx_t ctx, unsigned char val);
int fko_get_gpg_signature_verify(fko_ctx_t ctx, unsigned char *val);
int fko_set_gpg_ignore_verify_error(fko_ctx_t ctx, unsigned char val);
int fko_get_gpg_ignore_verify_error(fko_ctx_t ctx, unsigned char *val);
DLL_API int fko_set_gpg_signature_verify(fko_ctx_t ctx, unsigned char val);
DLL_API int fko_get_gpg_signature_verify(fko_ctx_t ctx, unsigned char *val);
DLL_API int fko_set_gpg_ignore_verify_error(fko_ctx_t ctx, unsigned char val);
DLL_API int fko_get_gpg_ignore_verify_error(fko_ctx_t ctx, unsigned char *val);
int fko_get_gpg_signature_id(fko_ctx_t ctx, char **sig_id);
int fko_get_gpg_signature_fpr(fko_ctx_t ctx, char **sig_fpr);
int fko_get_gpg_signature_summary(fko_ctx_t ctx, int *sigsum);
int fko_get_gpg_signature_status(fko_ctx_t ctx, int *sigstat);
DLL_API int fko_get_gpg_signature_id(fko_ctx_t ctx, char **sig_id);
DLL_API int fko_get_gpg_signature_fpr(fko_ctx_t ctx, char **sig_fpr);
DLL_API int fko_get_gpg_signature_summary(fko_ctx_t ctx, int *sigsum);
DLL_API int fko_get_gpg_signature_status(fko_ctx_t ctx, int *sigstat);
int fko_gpg_signature_id_match(fko_ctx_t ctx, const char *id, unsigned char *result);
int fko_gpg_signature_fpr_match(fko_ctx_t ctx, const char *fpr, unsigned char *result);
DLL_API int fko_gpg_signature_id_match(fko_ctx_t ctx, const char *id, unsigned char *result);
DLL_API int fko_gpg_signature_fpr_match(fko_ctx_t ctx, const char *fpr, unsigned char *result);
#ifdef __cplusplus
}
#endif
#endif /* FKO_H */

View File

@@ -51,8 +51,15 @@
#define isdigit(c) (c >= 48 && c <= 57)
#endif
#if HAVE_STDINT_H
#include <stdint.h>
#ifdef WIN32
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
#define strdup _strdup
#else
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#endif
/* Work out endianess (sp?)
@@ -74,6 +81,17 @@
#endif
#endif
#ifdef WIN32
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#ifdef TIME_WITH_SYS_TIME
#include <time.h>
#endif
#endif
#endif
/* Convenient macros for wrapping sections in 'extern "C" {' constructs.
*/
#ifdef __cplusplus

View File

@@ -48,7 +48,7 @@ struct fko_context {
/* FKO SPA user-definable message data */
char *rand_val;
char *username;
unsigned int timestamp;
time_t timestamp;
short message_type;
char *message;
char *nat_access;

View File

@@ -103,7 +103,8 @@ _rijndael_encrypt(fko_ctx_t ctx, char *enc_key)
int
_rijndael_decrypt(fko_ctx_t ctx, char *dec_key, int b64_len)
{
char *tbuf, *ndx;
char *tbuf;
unsigned char *ndx;
unsigned char *cipher;
int cipher_len, pt_len, i, err = 0;
@@ -384,7 +385,7 @@ int
fko_decrypt_spa_data(fko_ctx_t ctx, char *dec_key)
{
int b64_len, res;
char *ndx;
//char *ndx;
/* First, make sure we have data to work with.
*/

View File

@@ -26,24 +26,33 @@
#include "fko_common.h"
#include "fko.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#ifdef TIME_WITH_SYS_TIME
#include <time.h>
#ifdef WIN32
#include <sys/timeb.h>
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#ifdef TIME_WITH_SYS_TIME
#include <time.h>
#endif
#endif
#endif
#define RAND_FILE "/dev/urandom"
#define RAND_FILE "/dev/urandom"
#endif
/* Set/Generate the SPA data random value string.
*/
int
fko_set_rand_value(fko_ctx_t ctx, const char *new_val)
{
#ifdef WIN32
struct _timeb tb;
#else
FILE *rfd;
struct timeval tv;
unsigned int seed;
char *tmp_buf;
#endif
unsigned long seed;
char *tmp_buf;
/* Context must be initialized.
*/
@@ -66,6 +75,10 @@ fko_set_rand_value(fko_ctx_t ctx, const char *new_val)
return(FKO_SUCCESS);
}
#ifdef WIN32
_ftime_s(&tb);
seed = ((tb.time * 1000) + tb.millitm) & 0xFFFFFFFF;
#else
/* Attempt to read seed data from /dev/urandom. If that does not
* work, then fall back to a time-based method (less secure, but
* probably more portable).
@@ -85,6 +98,7 @@ fko_set_rand_value(fko_ctx_t ctx, const char *new_val)
seed = tv.tv_usec;
}
#endif
srand(seed);
@@ -97,7 +111,7 @@ fko_set_rand_value(fko_ctx_t ctx, const char *new_val)
return(FKO_ERROR_MEMORY_ALLOCATION);
sprintf(ctx->rand_val, "%u", rand());
while(strlen(ctx->rand_val) < FKO_RAND_VAL_SIZE)
{
sprintf(tmp_buf, "%u", rand());

View File

@@ -26,19 +26,13 @@
#include "fko_common.h"
#include "fko.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#ifdef TIME_WITH_SYS_TIME
#include <time.h>
#endif
#endif
/* Set the timestamp.
*/
int
fko_set_timestamp(fko_ctx_t ctx, int offset)
{
unsigned int ts;
time_t ts;
/* Must be initialized
*/
@@ -60,7 +54,7 @@ fko_set_timestamp(fko_ctx_t ctx, int offset)
/* Return the current timestamp.
*/
int
fko_get_timestamp(fko_ctx_t ctx, unsigned int *timestamp)
fko_get_timestamp(fko_ctx_t ctx, time_t *timestamp)
{
/* Must be initialized
*/

View File

@@ -54,6 +54,8 @@ fko_set_username(fko_ctx_t ctx, const char *spoof_user)
/* cuserid will return the effective user (i.e. su or setuid).
*/
username = cuserid(NULL);
#elif WIN32
username = strdup("NO_USER");
#else
username = getlogin();
#endif

View File

@@ -53,7 +53,9 @@
}
#else
#define byteReverse(buf, len) /* Nothing */
#warning Undetermined or unsupported Byte Order... We will try LITTLE_ENDIAN
#ifndef WIN32
#warning Undetermined or unsupported Byte Order... We will try LITTLE_ENDIAN
#endif
#endif
/*

View File

@@ -30,6 +30,10 @@
#include "fko_common.h"
#ifdef WIN32
#define BYTEORDER 1234
#endif
/* Truncate to 32 bits -- should be a null op on 32-bit machines
*/
#ifndef TRUNC32

View File

@@ -123,7 +123,9 @@ sha1_transform(SHA_INFO *sha_info)
dp += 4;
W[i] = TRUNC32(T);
}
#warning Unknown byte order -- we will try LITTLE_ENDIAN
#ifndef WIN32
#warning Undetermined or unsupported Byte Order... We will try LITTLE_ENDIAN
#endif
#endif /* SWAP_DONE */
for (i = 16; i < 80; ++i) {

View File

@@ -127,7 +127,9 @@ sha256_transform(SHA_INFO *sha_info)
dp += 4;
W[i] = TRUNC32(T);
}
#warning Unknown byte order -- we will try LITTLE_ENDIAN
#ifndef WIN32
#warning Undetermined or unsupported Byte Order... We will try LITTLE_ENDIAN
#endif
#endif /* SWAP_DONE */
A = sha_info->digest[0];
@@ -195,7 +197,7 @@ sha256_update(SHA_INFO *sha_info, uint8_t *buffer, int count)
sha_info->count_hi++;
}
sha_info->count_lo = clo;
sha_info->count_hi += (uint8_t) count >> 29;
sha_info->count_hi += (uint32_t) count >> 29;
if (sha_info->local) {
i = SHA_BLOCKSIZE - sha_info->local;
if (i > count) {

View File

@@ -25,6 +25,9 @@
*/
#include "fwknop_common.h"
#include "config_init.h"
#include "getopt.h"
#include "spa_comm.h"
#include "utils.h"
/* Routine to extract the configuration value from a line in the config
* file.
@@ -39,7 +42,7 @@ get_char_val(const char *var_name, char *dest, char *lptr)
/* var_name is guaranteed to be NULL-terminated.
*/
for (i=0; i < strlen(var_name); i++)
for (i=0; i < (int)strlen(var_name); i++)
if (tmp_ptr[i] != var_name[i])
return 0;
@@ -147,7 +150,7 @@ parse_config_file(fko_cli_options_t *options, struct opts_track* ot)
static void
validate_options(fko_cli_options_t *options)
{
char *tmpc;
//char *tmpc;
/* Gotta have a Destination unless we are just testing or getting the
* the version.
@@ -183,7 +186,7 @@ void
config_init(fko_cli_options_t *options, int argc, char **argv)
{
int cmd_arg, index;
unsigned int tmpint;
//unsigned int tmpint;
struct opts_track ot;
@@ -198,8 +201,13 @@ config_init(fko_cli_options_t *options, int argc, char **argv)
options->proto = FKO_DEFAULT_PROTO;
options->port = FKO_DEFAULT_PORT;
#ifdef WIN32
while ((cmd_arg = getopt(argc, argv,
"A:a:D:G:S:Q:m:p:P:B:bghqdTvVn")) != -1) {
#else
while ((cmd_arg = getopt_long(argc, argv,
"A:a:D:G:S:Q:p:P:BbghqdTvVn", cmd_opts, &index)) != -1) {
#endif
switch(cmd_arg) {
case 'A':
strlcpy(options->access_str, optarg, MAX_LINE_LEN);
@@ -273,6 +281,7 @@ config_init(fko_cli_options_t *options, int argc, char **argv)
usage();
exit(0);
case FKO_DIGEST_NAME:
case 'm':
if(strncasecmp(optarg, "md5", 3) == 0)
options->digest_type = FKO_DIGEST_MD5;
else if(strncasecmp(optarg, "sha1", 4) == 0)
@@ -336,7 +345,9 @@ usage(void)
" -c, --config-file - Specify an alternate configuration file.\n"
" -A, --access - Provide a list of ports/protocols to open\n"
" on the server.\n"
" -a, --allow-ip - Specify IP address to allow within the SPA\n"
" -B, --save-packet - Save the generated packet data to the\n"
" specified file.\n"
" -a, --allow-ip - Specify IP address to allow within the SPA\n"
" packet.\n"
" -D, --destination - Specify the IP address of the fwknop server.\n"
" -p, --server-port - Set the destination port for outgoing SPA\n"
@@ -353,7 +364,7 @@ usage(void)
" -d, --debug - Set debug mode.\n"
" -v, --verbose - Set verbose mode.\n"
" -V, --version - Print version number.\n"
" --digest-type - Speciy the message digest algorithm to use.\n"
" -m, --digest-type - Speciy the message digest algorithm to use.\n"
" (md5, sha1, or sha256 (default)).\n"
" --gpg-encryption - Use GPG encyrption (default is Rijndael).\n"
" --gpg-recipient-key - Specify the recipient GPG key name or ID.\n"
@@ -363,6 +374,12 @@ usage(void)
"\n"
);
// --DSS TEMP
#ifdef WIN32
printf("NOTE: Long options and GPG encryption are not available\n");
printf(" under Windows yet.\n\n");
#endif
return;
}

View File

@@ -40,7 +40,7 @@ main(int argc, char **argv)
{
fko_ctx_t ctx, ctx2;
int res;
char *pw, *spa_data, *version;
char *spa_data, *version;
char access_buf[MAX_LINE_LEN];
fko_cli_options_t options;
@@ -69,8 +69,10 @@ main(int argc, char **argv)
/* If use-gpg-agent was not specified, then remove the GPG_AGENT_INFO
* ENV variable if it exists.
*/
#ifndef WIN32
if(!options.use_gpg_agent)
unsetenv("GPG_AGENT_INFO");
#endif
res = fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_GPG);
if(res != FKO_SUCCESS)
@@ -175,7 +177,7 @@ main(int argc, char **argv)
fko_set_spa_client_timeout(ctx, 120);
*/
/* Set a serer auth string.
/* Set a server auth string.
res = fko_set_spa_server_auth(ctx, "crypt,SomePW");
if(res != FKO_SUCCESS)
fprintf(stderr, "Error #%i from fko_set_spa_server_auth: %s\n", res, fko_errstr(res));
@@ -221,7 +223,6 @@ main(int argc, char **argv)
/* Now we create a new context based on data from the first one.
*/
res = fko_get_spa_data(ctx, &spa_data);
if(res != FKO_SUCCESS)
{
fprintf(stderr,
@@ -281,7 +282,6 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
*/
if(options.use_gpg)
{
@@ -298,8 +298,9 @@ main(int argc, char **argv)
}
}
}
*/
fko_set_gpg_signature_verify(ctx2, 0);
//fko_set_gpg_signature_verify(ctx2, 0);
//fko_set_gpg_ignore_verify_error(ctx2, 1);
res = fko_decrypt_spa_data(
@@ -319,35 +320,6 @@ fko_set_gpg_signature_verify(ctx2, 0);
exit(EXIT_FAILURE);
}
/* --DSS temp for test
*/
if(options.use_gpg)
{
int summ=-1, stat=-1;
char *fpr, *id;
res = fko_get_gpg_signature_fpr(ctx2, &fpr);
if(res == FKO_SUCCESS)
printf("++ SIG FPR: %s\n", fpr);
else
printf("++ SIG FPR ERROR %i: %s\n", res, fko_errstr(res));
res = fko_get_gpg_signature_id(ctx2, &id);
if(res == FKO_SUCCESS)
printf("++ SIG ID: %s\n", id);
else
printf("++ SIG ID ERROR %i: %s\n", res, fko_errstr(res));
res = fko_get_gpg_signature_status(ctx2, &stat);
if(res != FKO_SUCCESS)
printf("++ SIG Status ERROR %i: %s\n", res, fko_errstr(res));
res = fko_get_gpg_signature_summary(ctx2, &summ);
if(res != FKO_SUCCESS)
printf("++ SIG Summary ERROR %i: %s\n", res, fko_errstr(res));
printf("++ Status: %i, Summary: %i\n", stat, summ);
}
if (! options.quiet) {
printf("\nDump of the Decoded Data\n");
@@ -392,56 +364,70 @@ display_ctx(fko_ctx_t ctx)
{
char *rand_val, *username, *version, *spa_message, *nat_access,
*server_auth, *enc_data, *spa_digest, *spa_data;
unsigned int timestamp=0;
time_t timestamp=0;
short msg_type=-1, digest_type=-1;
int client_timeout=-1, res;
int client_timeout=-1;
/* Should be checking return values, but this is temp code. --DSS
*/
fko_get_rand_value(ctx, &rand_val);
//printf("RAND: '%s'\n", rand_val);
fko_get_username(ctx, &username);
//printf("USER: '%s'\n", username);
fko_get_timestamp(ctx, &timestamp);
//printf("TIME: '%lu'\n", timestamp);
fko_get_version(ctx, &version);
//printf("VER: '%s'\n", version);
fko_get_spa_message_type(ctx, &msg_type);
//printf("MTYP: '%i'\n", msg_type);
fko_get_spa_message(ctx, &spa_message);
//printf("MSG: '%s'\n", spa_message);
fko_get_spa_nat_access(ctx, &nat_access);
//printf("NAT: '%s'\n", nat_access);
fko_get_spa_server_auth(ctx, &server_auth);
//printf("AUTH: '%s'\n", server_auth);
fko_get_spa_client_timeout(ctx, &client_timeout);
//printf("CLTO: '%s'\n", client_timeout);
fko_get_spa_digest_type(ctx, &digest_type);
//printf("DTYP: '%i'\n", digest_type);
fko_get_encoded_data(ctx, &enc_data);
//printf("ENC: '%s'\n", enc_data);
fko_get_spa_digest(ctx, &spa_digest);
//printf("DIG: '%s'\n", spa_digest);
fko_get_spa_data(ctx, &spa_data);
//printf("SDAT: '%s'\n", spa_data);
printf(
"\nFKO Context Values:\n===================\n\n"
" Random Value: %s\n"
" Username: %s\n"
" Timestamp: %u\n"
" FKO Version: %s\n"
" Message Type: %i\n"
" Message String: %s\n"
" Nat Access: %s\n"
" Server Auth: %s\n"
" Client Timeout: %u\n"
" Digest Type: %u\n"
"\n Encoded Data: %s\n"
"\nSPA Data Digest: %s\n"
"\nFinal Packed/Encrypted/Encoded Data:\n\n%s\n\n"
,
rand_val == NULL ? "<NULL>" : rand_val,
username == NULL ? "<NULL>" : username,
timestamp,
version == NULL ? "<NULL>" : version,
msg_type,
spa_message == NULL ? "<NULL>" : spa_message,
nat_access == NULL ? "<NULL>" : nat_access,
server_auth == NULL ? "<NULL>" : server_auth,
client_timeout,
digest_type,
enc_data == NULL ? "<NULL>" : enc_data,
spa_digest == NULL ? "<NULL>" : spa_digest,
spa_data == NULL ? "<NULL>" : spa_data
);
//return;
printf("\nFKO Context Values:\n===================\n\n");
printf(" Random Value: %s\n", rand_val);
printf(" Username: %s\n", username);
printf(" Timestamp: %u\n", timestamp);
printf(" FKO Version: %s\n", version);
printf(" Message Type: %i\n", msg_type);
printf(" Message String: %s\n", spa_message);
printf(" Nat Access: %s\n", nat_access);
printf(" Server Auth: %s\n", server_auth);
printf(" Client Timeout: %u\n", client_timeout);
printf(" Digest Type: %u\n", digest_type);
printf("\n Encoded Data: %s\n", enc_data);
printf("\nSPA Data Digest: %s\n", spa_digest);
printf("\nFinal Packed/Encrypted/Encoded Data:\n\n%s\n\n", spa_data);
//,
//rand_val,// == NULL ? "<NULL>" : rand_val,
//username,// == NULL ? "<NULL>" : username,
//timestamp,
//version, // == NULL ? "<NULL>" : version,
//msg_type,
//spa_message // == NULL ? "<NULL>" : spa_message,
//nat_access == NULL ? "<NULL>" : nat_access,
//server_auth == NULL ? "<NULL>" : server_auth,
//client_timeout,
//digest_type,
//enc_data == NULL ? "<NULL>" : enc_data,
//spa_digest == NULL ? "<NULL>" : spa_digest,
//spa_data == NULL ? "<NULL>" : spa_data
//);
}

View File

@@ -50,7 +50,12 @@
#include <netinet/in.h>
#endif
#include <signal.h>
#ifdef WIN32
#define strncasecmp _strnicmp
#define snprintf _snprintf
#else
#include <signal.h>
#endif
#include "fko.h"

View File

@@ -25,7 +25,12 @@
*/
#include <stdio.h>
#include <signal.h>
#include <termios.h>
#ifdef WIN32
#include <conio.h>
#else
#include <termios.h>
#endif
#include "fwknop_common.h"
#include "getpasswd.h"
@@ -39,11 +44,13 @@ getpasswd(const char *prompt)
{
static char pwbuf[MAX_PASS_LEN + 1] = {0};
char *ptr;
sigset_t sig, old_sig;
struct termios ts, old_ts;
FILE *fp;
int c;
#ifndef WIN32
FILE *fp;
sigset_t sig, old_sig;
struct termios ts, old_ts;
if((fp = fopen(ctermid(NULL), "r+")) == NULL)
return(NULL);
@@ -66,33 +73,46 @@ getpasswd(const char *prompt)
tcsetattr(fileno(fp), TCSAFLUSH, &ts);
fputs(prompt, fp);
#endif
/* Read in the password.
*/
ptr = pwbuf;
while((c = getc(fp)) != EOF && c != '\n')
#ifdef WIN32
_cputs(prompt);
while((c = _getch()) != '\r')
#else
while((c = getc(fp)) != EOF && c != '\n')
#endif
if(ptr < &pwbuf[MAX_PASS_LEN])
*ptr++ = c;
/* Null terminate the password.
/* Null terminate the password.
*/
*ptr = 0;
#ifndef WIN32
/* we can go ahead and echo out a newline.
*/
putc('\n', fp);
/* Restore our tty state and signal handlers.
/* Restore our tty state and signal handlers.
*/
tcsetattr(fileno(fp), TCSAFLUSH, &old_ts);
sigprocmask(SIG_BLOCK, &old_sig, NULL);
fclose(fp);
#else
/* In Windows, it would be a CR-LF
*/
_putch('\r');
_putch('\n');
#endif
return(pwbuf);
}
/* Function for accepting password input from users
/* Function for accepting password input from from a file
*/
char*
getpasswd_file(const char *pw_file, const char *dst_ip_str)
@@ -108,7 +128,7 @@ getpasswd_file(const char *pw_file, const char *dst_ip_str)
if ((pwfile_ptr = fopen(pw_file, "r")) == NULL)
{
fprintf(stderr, "[*] Could not open config file: %s\n", pw_file);
exit(EXIT_FAILURE);
exit(1);
}
while ((fgets(conf_line_buf, MAX_LINE_LEN, pwfile_ptr)) != NULL)
@@ -163,7 +183,7 @@ getpasswd_file(const char *pw_file, const char *dst_ip_str)
if (pwbuf[0] == '\0') {
fprintf(stderr, "[*] Could not get password for IP: %s from: %s\n",
dst_ip_str, pw_file);
exit(EXIT_FAILURE);
exit(1);
}
return pwbuf;

View File

@@ -25,9 +25,6 @@
*****************************************************************************
*/
#include "spa_comm.h"
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
/* Send the SPA data via UDP packet.
*/
@@ -40,6 +37,17 @@ send_spa_packet_udp(fko_ctx_t ctx, struct sockaddr_in *saddr,
int res;
char *spa_data;
#ifdef WIN32
WSADATA wsa_data;
res = WSAStartup( MAKEWORD(1,1), &wsa_data );
if( res != 0 )
{
fprintf(stderr, "[*] Winsock initialization error %d\n", res );
exit(0);
}
#endif
/* create the socket
*/
sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -72,7 +80,7 @@ int
send_spa_packet_tcp(fko_ctx_t ctx, struct sockaddr_in *saddr,
struct sockaddr_in *daddr, fko_cli_options_t *options)
{
int rv;
int rv = -1;
return rv;
}
@@ -81,7 +89,7 @@ send_spa_packet_tcp(fko_ctx_t ctx, struct sockaddr_in *saddr,
int
send_spa_packet_icmp(fko_ctx_t ctx, fko_cli_options_t *options)
{
int rv;
int rv = -1;
return rv;
}

View File

@@ -28,6 +28,16 @@
#include "fwknop_common.h"
#ifdef WIN32
#include <winsock2.h>
#define unlink _unlink
#else
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#endif
/* Prototypes
*/
int send_spa_packet(fko_ctx_t ctx, fko_cli_options_t *options);

View File

@@ -31,4 +31,12 @@
*/
void hex_dump(unsigned char *data, int size);
#ifdef WIN32
/* Function prototypes we need for Windows
*/
size_t strlcat(char *dst, const char *src, size_t siz);
size_t strlcpy(char *dst, const char *src, size_t siz);
#endif
#endif /* UTILS_H */

202
win32/config.h Normal file
View File

@@ -0,0 +1,202 @@
/* $Id$
*****************************************************************************
*
* File: fko_common.h
*
* Author: Damien S. Stuart
*
* Purpose: Common header for libfko source files.
*
* Copyright (C) 2008 Damien Stuart (dstuart@dstuart.org)
*
* License (GNU Public License):
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*****************************************************************************
*/
#ifndef CONFIG_H
#define CONFIG_H 1
/* Define to 1 if you have the `bzero' function. */
#undef HAVE_BZERO
/* Define to 1 if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <endian.h> header file. */
#undef HAVE_ENDIAN_H
/* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define if you have libgpgme */
#undef HAVE_LIBGPGME
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#undef HAVE_MALLOC
/* Define to 1 if you have the `memmove' function. */
#define HAVE_MEMMOVE 1
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
and to 0 otherwise. */
#undef HAVE_REALLOC
/* Define to 1 if you have the `socket' function. */
#undef HAVE_SOCKET
/* Define to 1 if `stat' has the bug that it succeeds when given the
zero-length file name argument. */
#undef HAVE_STAT_EMPTY_STRING_BUG
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strchr' function. */
#define HAVE_STRCHR 1
/* Define to 1 if you have the `strcspn' function. */
#define HAVE_STRCSPN 1
/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the `strncasecmp' function. */
#define HAVE_STRNCASECMP 1
/* Define to 1 if you have the `strndup' function. */
#define HAVE_STRNDUP 1
/* Define to 1 if you have the `strrchr' function. */
#define HAVE_STRRCHR 1
/* Define to 1 if you have the `strspn' function. */
#define HAVE_STRSPN 1
/* Define to 1 if you have the <sys/byteorder.h> header file. */
#undef HAVE_SYS_BYTEORDER_H
/* Define to 1 if you have the <sys/endian.h> header file. */
#undef HAVE_SYS_ENDIAN_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <termios.h> header file. */
#undef HAVE_TERMIOS_H
/* Define to 1 if the system has the type `uint32_t'. */
#undef HAVE_UINT32_T
/* Define to 1 if the system has the type `uint8_t'. */
#undef HAVE_UINT8_T
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
slash. */
#undef LSTAT_FOLLOWS_SLASHED_SYMLINK
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
#undef NO_MINUS_C_MINUS_O
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of `unsigned int', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_INT
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Version number of package */
#define VERSION "0.61"
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define to rpl_malloc if the replacement function should be used. */
#undef malloc
/* Define to `long int' if <sys/types.h> does not define. */
#undef off_t
/* Define to rpl_realloc if the replacement function should be used. */
#undef realloc
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t
#endif /* CONFIG_H */

269
win32/fwknop-client.vcproj Normal file
View File

@@ -0,0 +1,269 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="fwknop-client"
ProjectGUID="{D8AFA02D-14BF-42F4-97DE-EF4924D046D6}"
RootNamespace="fwknopclient"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".;../fko;../src"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
ExceptionHandling="0"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
CompileAs="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies=" libfko.lib ws2_32.lib"
OutputFile="$(OutDir)\fwknop.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;C:\Documents and Settings\dstuart\My Documents\Visual Studio 2008\Projects\fwknop-c\win32\Debug&quot;"
DelayLoadDLLs=""
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories=".;../fko;../src"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
CompileAs="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies=" libfko.lib ws2_32.lib"
OutputFile="$(OutDir)\fwknop.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;C:\Documents and Settings\dstuart\My Documents\Visual Studio 2008\Projects\fwknop-c\win32\Release&quot;"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\src\config_init.c"
>
</File>
<File
RelativePath="..\src\fwknop.c"
>
</File>
<File
RelativePath=".\getopt.c"
>
</File>
<File
RelativePath="..\src\getpasswd.c"
>
</File>
<File
RelativePath="..\src\spa_comm.c"
>
</File>
<File
RelativePath="..\fko\strlcat.c"
>
</File>
<File
RelativePath="..\fko\strlcpy.c"
>
</File>
<File
RelativePath="..\src\utils.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\config.h"
>
</File>
<File
RelativePath="..\src\config_init.h"
>
</File>
<File
RelativePath="..\fko\fko.h"
>
</File>
<File
RelativePath="..\src\fwknop.h"
>
</File>
<File
RelativePath="..\src\fwknop_common.h"
>
</File>
<File
RelativePath=".\getopt.h"
>
</File>
<File
RelativePath="..\src\getpasswd.h"
>
</File>
<File
RelativePath="..\src\spa_comm.h"
>
</File>
<File
RelativePath="..\src\utils.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

1258
win32/getopt.c Normal file

File diff suppressed because it is too large Load Diff

185
win32/getopt.h Normal file
View File

@@ -0,0 +1,185 @@
/* getopt.h */
/* Declarations for getopt.
Copyright (C) 1989-1994, 1996-1999, 2001 Free Software
Foundation, Inc. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute
it and/or modify it under the terms of the GNU Lesser
General Public License as published by the Free Software
Foundation; either version 2.1 of the License, or
(at your option) any later version.
The GNU C Library is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General
Public License along with the GNU C Library; if not, write
to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA. */
#ifndef _GETOPT_H
#ifndef __need_getopt
# define _GETOPT_H 1
#endif
/* If __GNU_LIBRARY__ is not already defined, either we are being used
standalone, or this is the first header included in the source file.
If we are being used with glibc, we need to include <features.h>, but
that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
not defined, include <ctype.h>, which will pull in <features.h> for us
if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
doesn't flood the namespace with stuff the way some other headers do.) */
#if !defined __GNU_LIBRARY__
# include <ctype.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
extern char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern int optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
extern int opterr;
/* Set to an option character which was unrecognized. */
extern int optopt;
#ifndef __need_getopt
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct option
{
# if (defined __STDC__ && __STDC__) || defined __cplusplus
const char *name;
# else
char *name;
# endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};
/* Names for the values of the `has_arg' field of `struct option'. */
# define no_argument 0
# define required_argument 1
# define optional_argument 2
#endif /* need getopt */
/* Get definitions and prototypes for functions to process the
arguments in ARGV (ARGC of them, minus the program name) for
options given in OPTS.
Return the option character from OPTS just read. Return -1 when
there are no more options. For unrecognized options, or options
missing arguments, `optopt' is set to the option letter, and '?' is
returned.
The OPTS string is a list of characters which are recognized option
letters, optionally followed by colons, specifying that that letter
takes an argument, to be placed in `optarg'.
If a letter in OPTS is followed by two colons, its argument is
optional. This behavior is specific to the GNU `getopt'.
The argument `--' causes premature termination of argument
scanning, explicitly telling `getopt' that there are no more
options.
If OPTS begins with `--', then non-option arguments are treated as
arguments to the option '\0'. This behavior is specific to the GNU
`getopt'. */
#if (defined __STDC__ && __STDC__) || defined __cplusplus
# ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);
# else /* not __GNU_LIBRARY__ */
extern int getopt ();
# endif /* __GNU_LIBRARY__ */
# ifndef __need_getopt
extern int getopt_long (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind);
extern int getopt_long_only (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind);
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only);
# endif
#else /* not __STDC__ */
extern int getopt ();
# ifndef __need_getopt
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
# endif
#endif /* __STDC__ */
#ifdef __cplusplus
}
#endif
/* Make sure we later can get all the definitions and declarations. */
#undef __need_getopt
#endif /* getopt.h */

29
win32/libfko.sln Normal file
View File

@@ -0,0 +1,29 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libfko", "libfko.vcproj", "{133BC195-4877-481D-9F56-9F1BEBAD21F0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fwknop-client", "fwknop-client.vcproj", "{D8AFA02D-14BF-42F4-97DE-EF4924D046D6}"
ProjectSection(ProjectDependencies) = postProject
{133BC195-4877-481D-9F56-9F1BEBAD21F0} = {133BC195-4877-481D-9F56-9F1BEBAD21F0}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{133BC195-4877-481D-9F56-9F1BEBAD21F0}.Debug|Win32.ActiveCfg = Debug|Win32
{133BC195-4877-481D-9F56-9F1BEBAD21F0}.Debug|Win32.Build.0 = Debug|Win32
{133BC195-4877-481D-9F56-9F1BEBAD21F0}.Release|Win32.ActiveCfg = Release|Win32
{133BC195-4877-481D-9F56-9F1BEBAD21F0}.Release|Win32.Build.0 = Release|Win32
{D8AFA02D-14BF-42F4-97DE-EF4924D046D6}.Debug|Win32.ActiveCfg = Debug|Win32
{D8AFA02D-14BF-42F4-97DE-EF4924D046D6}.Debug|Win32.Build.0 = Debug|Win32
{D8AFA02D-14BF-42F4-97DE-EF4924D046D6}.Release|Win32.ActiveCfg = Release|Win32
{D8AFA02D-14BF-42F4-97DE-EF4924D046D6}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

324
win32/libfko.vcproj Normal file
View File

@@ -0,0 +1,324 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="libfko"
ProjectGUID="{133BC195-4877-481D-9F56-9F1BEBAD21F0}"
RootNamespace="libfko"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
EnableIntrinsicFunctions="false"
AdditionalIncludeDirectories=".;..\fko;..\src"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
ExceptionHandling="0"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
CompileAs="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="false"
AdditionalIncludeDirectories=".;..\fko;..\src"
PreprocessorDefinitions="WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
CompileAs="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\fko\base64.c"
>
</File>
<File
RelativePath="..\fko\cipher_funcs.c"
>
</File>
<File
RelativePath="..\fko\digest.c"
>
</File>
<File
RelativePath="..\fko\fko_client_timeout.c"
>
</File>
<File
RelativePath="..\fko\fko_decode.c"
>
</File>
<File
RelativePath="..\fko\fko_digest.c"
>
</File>
<File
RelativePath="..\fko\fko_encode.c"
>
</File>
<File
RelativePath="..\fko\fko_encryption.c"
>
</File>
<File
RelativePath="..\fko\fko_error.c"
>
</File>
<File
RelativePath="..\fko\fko_funcs.c"
>
</File>
<File
RelativePath="..\fko\fko_message.c"
>
</File>
<File
RelativePath="..\fko\fko_nat_access.c"
>
</File>
<File
RelativePath="..\fko\fko_rand_value.c"
>
</File>
<File
RelativePath="..\fko\fko_server_auth.c"
>
</File>
<File
RelativePath="..\fko\fko_timestamp.c"
>
</File>
<File
RelativePath="..\fko\fko_user.c"
>
</File>
<File
RelativePath="..\fko\gpgme_funcs.c"
>
</File>
<File
RelativePath="..\fko\md5.c"
>
</File>
<File
RelativePath="..\fko\rijndael.c"
>
</File>
<File
RelativePath="..\fko\sha1.c"
>
</File>
<File
RelativePath="..\fko\sha256.c"
>
</File>
<File
RelativePath="..\fko\strlcat.c"
>
</File>
<File
RelativePath="..\fko\strlcpy.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\fko\base64.h"
>
</File>
<File
RelativePath="..\fko\cipher_funcs.h"
>
</File>
<File
RelativePath=".\config.h"
>
</File>
<File
RelativePath="..\fko\digest.h"
>
</File>
<File
RelativePath="..\fko\fko.h"
>
</File>
<File
RelativePath="..\fko\fko_common.h"
>
</File>
<File
RelativePath="..\fko\fko_context.h"
>
</File>
<File
RelativePath="..\fko\fko_limits.h"
>
</File>
<File
RelativePath="..\fko\fko_state.h"
>
</File>
<File
RelativePath="..\fko\fko_util.h"
>
</File>
<File
RelativePath="..\fko\gpgme_funcs.h"
>
</File>
<File
RelativePath="..\fko\md5.h"
>
</File>
<File
RelativePath="..\fko\rijndael.h"
>
</File>
<File
RelativePath="..\fko\sha.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>