Added more source files. Split out libfwknop functions to a static lib. Misc updates.
git-svn-id: file:///home/mbr/svn/fwknop/trunk@5 510a4753-2344-4c79-9c09-4d669213fbeb
This commit is contained in:
@@ -24,10 +24,7 @@
|
||||
############################################################################
|
||||
#
|
||||
CC = gcc
|
||||
|
||||
# Specify pcap library (typically pcap or pcap_ring).
|
||||
#
|
||||
PCAP_LIB = -lpcap
|
||||
AR = ar
|
||||
|
||||
# Base CFLAGS
|
||||
# For Full debugging (for extreme verbose output at runtime), add
|
||||
@@ -42,31 +39,53 @@ BASE_CFLAGS = -Wall -fno-strict-aliasing
|
||||
#CFLAGS = -O2 $(BASE_CFLAGS)
|
||||
#
|
||||
## For debugging symbols if you plan to use a debugger
|
||||
#
|
||||
CFLAGS = -g -O0 $(BASE_CFLAGS)
|
||||
|
||||
LDFLAGS =
|
||||
|
||||
LIBS = #$(PCAP_LIB) -lm -lz
|
||||
|
||||
PROG = fko_test
|
||||
PROG = fwknop
|
||||
SRC = fwknop.c
|
||||
|
||||
SRCS = fko_test.c \
|
||||
spa_random_number.c \
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
TPROG = fko_test
|
||||
TSRC = fko_test.c
|
||||
|
||||
TOBJ = $(TSRC:.c=.o)
|
||||
|
||||
LIBFWK = libfwknop.a
|
||||
LIBSRCS = spa_random_number.c \
|
||||
spa_user.c \
|
||||
spa_timestamp.c \
|
||||
spa_version.c \
|
||||
spa_message_type.c \
|
||||
strlcat.c \
|
||||
strlcpy.c
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
LIBOBJS = $(LIBSRCS:.c=.o)
|
||||
|
||||
# Group all the source files for make depend.
|
||||
#
|
||||
ALLSRCS = $(LIBSRCS) $(SRC) $(TSRC)
|
||||
|
||||
###########################################################################
|
||||
# Targets
|
||||
#
|
||||
all: $(PROG)
|
||||
all: $(PROG) $(TPROG)
|
||||
|
||||
$(PROG): $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||
$(PROG): $(OBJ) $(LIBFWK)
|
||||
$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBFWK) $(LIBS)
|
||||
|
||||
$(TPROG): $(TOBJ) $(LIBFWK)
|
||||
$(CC) $(LDFLAGS) -o $@ $(TOBJ) $(LIBFWK) $(LIBS)
|
||||
|
||||
lib: $(LIBFWK)
|
||||
|
||||
$(LIBFWK): $(LIBOBJS)
|
||||
$(AR) rcs $@ $(LIBOBJS)
|
||||
|
||||
# Force a normal rebuild.
|
||||
#
|
||||
@@ -76,18 +95,18 @@ strip: $(PROG)
|
||||
strip $(PROG)
|
||||
|
||||
clean:
|
||||
rm -f $(PROG) $(OBJS)
|
||||
rm -f $(PROG) $(TPROG) *.o *.a *.so
|
||||
|
||||
realclean:
|
||||
rm -f $(PROG) $(OBJS) core *.bak *.tmp *[-~]
|
||||
realclean: clean
|
||||
rm -f core *.bak *.tmp *[-~]
|
||||
|
||||
# Generate the dependencies for the sources in this current directory
|
||||
# while ignoring warnings. Note: If you don't have makedepend in your PATH,
|
||||
# you will simple get a warning and noting will happen.
|
||||
#
|
||||
depend:
|
||||
@`which makedepend 2>/dev/null` -Y -- $(CFLAGS) -- $(SRCS) 2> /dev/null \
|
||||
&& echo "makedepend -Y -- $(CFLAGS) -- $(SRCS) 2> /dev/null" \
|
||||
@`which makedepend 2>/dev/null` -Y -- $(CFLAGS) -- $(ALLSRCS) 2> /dev/null \
|
||||
&& echo "makedepend -Y -- $(CFLAGS) -- $(ALLSRCS) 2> /dev/null" \
|
||||
|| echo " - makedepend not found. Aborting..."
|
||||
|
||||
|
||||
@@ -96,7 +115,10 @@ depend:
|
||||
#
|
||||
# DO NOT DELETE
|
||||
|
||||
fko_test.o: fwknop.h
|
||||
spa_random_number.o: fwknop.h
|
||||
spa_user.o: fwknop.h
|
||||
spa_timestamp.o: fwknop.h
|
||||
spa_version.o: fwknop.h
|
||||
spa_message_type.o: fwknop.h
|
||||
fwknop.o: fwknop.h
|
||||
fko_test.o: fwknop.h
|
||||
|
||||
@@ -1,30 +1,37 @@
|
||||
This is the top-level directory for the C version of fwknop.
|
||||
|
||||
Additionl information and details can be found on the fwknop-c site at
|
||||
http://devmetrix.org/trac/fwknop-c.
|
||||
|
||||
libfwnop source files:
|
||||
======================
|
||||
These will be compiled into libfwknop.a (static for now).
|
||||
|
||||
spa_random_number.c
|
||||
Usage: "char* spa_random_number(char* rand_val);"
|
||||
spa_random_number.c - Generate a string of 16 random hex digits.
|
||||
spa_user.c - Get or spoof the current user.
|
||||
spa_timestamp.c - Get the current timestamp with optional offset.
|
||||
spa_version.c - Get the fwknop-client version number.
|
||||
spa_message_type.c -
|
||||
spa_message.c -
|
||||
spa_nat_access.c -
|
||||
spa_server_auth.c -
|
||||
spa_client_timeout.c -
|
||||
spa_digest.c -
|
||||
-more to come-
|
||||
|
||||
Where 'rand_val' must be a char array of at least 17 bytes.
|
||||
Returns a pointer to the provided char array.
|
||||
Executables:
|
||||
============
|
||||
|
||||
spa_user.c
|
||||
fwknop - Soon to be the fwknop client. At present, it just
|
||||
dumps some internal data for functional verification
|
||||
during development.
|
||||
|
||||
spa_timestamp.c
|
||||
fko_test - A temp program for testing libfwknop functions during
|
||||
during development. This will go away once we have
|
||||
a fair amount of progress in developing the client
|
||||
(and maybe the server).
|
||||
|
||||
spa_version.c
|
||||
-more to come-
|
||||
|
||||
spa_message_type.c
|
||||
|
||||
spa_message.c
|
||||
|
||||
spa_nat_access.c
|
||||
|
||||
spa_server_auth.c
|
||||
|
||||
spa_client_timeout.c
|
||||
|
||||
spa_digest.c
|
||||
|
||||
Someday, I'll put something meaningful here... --DSS
|
||||
###EOF###
|
||||
|
||||
+17
@@ -59,6 +59,23 @@ int main(int argc, char **argv)
|
||||
spa_timestamp(&sm, -600);
|
||||
printf("SPA_TIMESTAMP (-600): %u\n", sm.timestamp);
|
||||
|
||||
/*********************************************************************
|
||||
* Get the version of fwknop.
|
||||
*/
|
||||
printf(" SPA_Version: %s\n", spa_version(&sm));
|
||||
|
||||
/*********************************************************************
|
||||
* Set and get the message type. set ACCESS, COMMAND, NAT, Then
|
||||
* invalid
|
||||
*/
|
||||
spa_message_type(&sm, SPA_ACCESS_MSG);
|
||||
printf(" SPA Message Type: %u\n", sm.message_type);
|
||||
spa_message_type(&sm, SPA_COMMAND_MSG);
|
||||
printf("SPA CMD Message Type: %u\n", sm.message_type);
|
||||
spa_message_type(&sm, SPA_LOCAL_NAT_ACCESS_MSG);
|
||||
printf("SPA NAT Message Type: %u\n", sm.message_type);
|
||||
spa_message_type(&sm, 100);
|
||||
printf("SPA bad Message Type: %u\n", sm.message_type);
|
||||
|
||||
|
||||
return(0);
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/* $Id$
|
||||
*****************************************************************************
|
||||
*
|
||||
* File: fwknop.c
|
||||
*
|
||||
* Author: Damien S. Stuart
|
||||
*
|
||||
* Purpose: fwknop client program.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
#include "fwknop.h"
|
||||
|
||||
/* Local prototypes
|
||||
*/
|
||||
void init_spa_message(spa_message_t *sm);
|
||||
void dump_spa_message_data(spa_message_t *sm);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
spa_message_t sm;
|
||||
|
||||
init_spa_message(&sm);
|
||||
|
||||
/* Timestamp */
|
||||
spa_timestamp(&sm, 0);
|
||||
|
||||
dump_spa_message_data(&sm);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Initialize the spa_message data struct, and set some default/preliminary
|
||||
* values.
|
||||
*/
|
||||
void init_spa_message(spa_message_t *sm)
|
||||
{
|
||||
/* Zero our SPA message struct.
|
||||
*/
|
||||
memset(sm, 0x0, sizeof(spa_message_t));
|
||||
|
||||
/* Initialize default values.
|
||||
*/
|
||||
sm->digest_type = DEFAULT_DIGEST;
|
||||
sm->enc_pcap_port = DEFAULT_PORT;
|
||||
sm->message_type = DEFAULT_MSG_TYPE;
|
||||
sm->client_timeout = DEFAULT_CLIENT_TIMEOUT;
|
||||
|
||||
/* Go ahead and and setup the random and user fields.
|
||||
*/
|
||||
spa_random_number(sm);
|
||||
spa_user(sm, NULL);
|
||||
|
||||
/* Version is static, so we add it here as well.
|
||||
*/
|
||||
spa_version(sm);
|
||||
}
|
||||
|
||||
/* Pretty print the data in the spa_message data struct.
|
||||
*/
|
||||
void dump_spa_message_data(spa_message_t *sm)
|
||||
{
|
||||
printf(
|
||||
"\nCurrent SPA Message Data:\n\n"
|
||||
" Random Val: %s\n"
|
||||
" User: %s\n"
|
||||
" Timestamp: %u\n"
|
||||
" Version: %s\n"
|
||||
" Message Type: %u\n"
|
||||
" Message String: %s\n"
|
||||
" Nat Access: %s\n"
|
||||
" Server Auth: %s\n"
|
||||
" Client Timeout: %u\n"
|
||||
" Digest: %s\n"
|
||||
"\n"
|
||||
" Digest Type: %u\n"
|
||||
" Port: %u\n"
|
||||
"\n",
|
||||
sm->rand_val,
|
||||
sm->user,
|
||||
sm->timestamp,
|
||||
sm->version,
|
||||
sm->message_type,
|
||||
sm->message,
|
||||
sm->nat_access,
|
||||
sm->server_auth,
|
||||
sm->client_timeout,
|
||||
sm->digest,
|
||||
sm->digest_type,
|
||||
sm->enc_pcap_port
|
||||
);
|
||||
}
|
||||
|
||||
/***EOF***/
|
||||
@@ -37,21 +37,21 @@
|
||||
|
||||
/* General params
|
||||
*/
|
||||
#define FWKNOP_VERSION "1.9.10-pre1" /* The fwknop client version # */
|
||||
#define VERSION_LENGTH 11 /* Length of the version string */
|
||||
#define FWKNOP_VERSION "1.9.9" /* The fwknop client version # */
|
||||
#define VERSION_LENGTH 11 /* Length of the version string */
|
||||
|
||||
#define MIN_PORT 10000
|
||||
#define MAX_PORT 65535
|
||||
#define MIN_PORT 10000
|
||||
#define MAX_PORT 65535
|
||||
|
||||
#define ENC_KEYSIZE 16 /* RIJNDAEL Key Size */
|
||||
#define ENC_KEYSIZE 16 /* RIJNDAEL Key Size */
|
||||
|
||||
/* For random string generation.
|
||||
*/
|
||||
#define RAND_VAL_SIZE 16
|
||||
#define RAND_FILE "/dev/urandom"
|
||||
#define RAND_MASK 0xFFFF
|
||||
#define RAND_VAL_SIZE 16
|
||||
#define RAND_FILE "/dev/urandom"
|
||||
#define RAND_MASK 0xFFFF
|
||||
|
||||
#define TIMESTAMP_SIZE 10
|
||||
#define TIMESTAMP_SIZE 10
|
||||
|
||||
#define MAX_USER_SIZE 32
|
||||
#define MAX_MESSAGE_SIZE 128
|
||||
@@ -62,29 +62,32 @@
|
||||
/* SPA Message types...
|
||||
*/
|
||||
enum {
|
||||
SPA_COMMAND_MODE,
|
||||
SPA_ACCESS_MODE,
|
||||
SPA_NAT_ACCESS_MODE,
|
||||
SPA_CLIENT_TIMEOUT_ACCESS_MODE,
|
||||
SPA_CLIENT_TIMEOUT_NAT_ACCESS_MODE,
|
||||
SPA_LOCAL_NAT_ACCESS_MODE,
|
||||
SPA_CLIENT_TIMEOUT_LOCAL_NAT_ACCESS_MODE
|
||||
SPA_COMMAND_MSG = 0,
|
||||
SPA_ACCESS_MSG,
|
||||
SPA_NAT_ACCESS_MSG,
|
||||
SPA_CLIENT_TIMEOUT_ACCESS_MSG,
|
||||
SPA_CLIENT_TIMEOUT_NAT_ACCESS_MSG,
|
||||
SPA_LOCAL_NAT_ACCESS_MSG,
|
||||
SPA_CLIENT_TIMEOUT_LOCAL_NAT_ACCESS_MSG,
|
||||
LAST_MSG_TYPE /* Always leave this as the last one */
|
||||
};
|
||||
|
||||
/* Digest types...
|
||||
*/
|
||||
enum {
|
||||
MD5_DIGEST,
|
||||
MD5_DIGEST = 0,
|
||||
SHA1_DIGEST,
|
||||
SHA256_DIGEST
|
||||
};
|
||||
|
||||
/* General Defaults
|
||||
*/
|
||||
#define DEFAULT_USER "root"
|
||||
#define DEFAULT_PORT 62201
|
||||
#define DEFAULT_DIGEST SHA256_DIGEST
|
||||
#define KNOCK_INTERVAL 60
|
||||
#define DEFAULT_USER "root"
|
||||
#define DEFAULT_PORT 62201
|
||||
#define DEFAULT_DIGEST SHA256_DIGEST
|
||||
#define DEFAULT_MSG_TYPE SPA_ACCESS_MSG
|
||||
#define DEFAULT_CLIENT_TIMEOUT 0
|
||||
#define KNOCK_INTERVAL 60
|
||||
|
||||
/* The pieces we need to make a SPA packet.
|
||||
*/
|
||||
@@ -109,7 +112,7 @@ char* spa_random_number(spa_message_t *sm);
|
||||
char* spa_user(spa_message_t *sm, char *spoof_user);
|
||||
unsigned int spa_timestamp(spa_message_t *sm, int offset);
|
||||
char* spa_version(spa_message_t *sm);
|
||||
unsigned short spa_message_type(spa_message_t *sm);
|
||||
int spa_message_type(spa_message_t *sm, unsigned short msg_type);
|
||||
char* spa_message(spa_message_t *sm);
|
||||
char* spa_nat_access(spa_message_t *sm);
|
||||
char* spa_server_auth(spa_message_t *sm);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/* $Id$
|
||||
*****************************************************************************
|
||||
*
|
||||
* File: spa_message_type.c
|
||||
*
|
||||
* Author: Damien S. Stuart
|
||||
*
|
||||
* Purpose: Set the current fwknop message type.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
#include "fwknop.h"
|
||||
|
||||
int spa_message_type(spa_message_t *sm, unsigned short msg_type)
|
||||
{
|
||||
if(msg_type >= LAST_MSG_TYPE)
|
||||
{
|
||||
fprintf(stderr, "*Invlaid fwknop message type: %u.\n", msg_type);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
sm->message_type = msg_type;
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/***EOF***/
|
||||
+1
-1
@@ -55,7 +55,7 @@ char* spa_user(spa_message_t *sm, char *spoof_user)
|
||||
*/
|
||||
if(res < 1)
|
||||
if((strlcpy(sm->user, getenv("LOGNAME"), MAX_USER_SIZE)) < 1)
|
||||
if((strlcpy(sm->user, getenv("USER"), MAX_USER_SIZE)) < 1);
|
||||
if((strlcpy(sm->user, getenv("USER"), MAX_USER_SIZE)) < 1)
|
||||
strlcpy(sm->user, DEFAULT_USER, strlen(DEFAULT_USER) + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* $Id$
|
||||
*****************************************************************************
|
||||
*
|
||||
* File: spa_version.c
|
||||
*
|
||||
* Author: Damien S. Stuart
|
||||
*
|
||||
* Purpose: Get the current fwknop version.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
#include "fwknop.h"
|
||||
|
||||
char* spa_version(spa_message_t *sm)
|
||||
{
|
||||
strlcpy(sm->version, FWKNOP_VERSION, strlen(FWKNOP_VERSION) + 1);
|
||||
return(sm->version);
|
||||
}
|
||||
|
||||
/***EOF***/
|
||||
Reference in New Issue
Block a user