diff -urN honeyd-0.5/WIN32-Code/config.h honeyd-0.5-win32/WIN32-Code/config.h --- honeyd-0.5/WIN32-Code/config.h Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Code/config.h Fri Mar 14 00:19:42 2003 @@ -0,0 +1,266 @@ +/* config.h. Generated automatically by configure. */ +/* config.h.in. Generated automatically from configure.in by autoheader. */ +/* Define if the addr_cmp in libdnet is broken */ +/* #undef HAVE_BROKEN_DNET */ + +/* Define to `unsigned int' if doesn't define. */ +/* #undef u_int */ + +/* Define to `unsigned long long' if doesn't define. */ +/* #undef u_int64_t */ + +/* Define to `unsigned int' if doesn't define. */ +/* #undef u_int32_t */ + +/* Define to `unsigned short' if doesn't define. */ +/* #undef u_int16_t */ + +/* Define to `unsigned char' if doesn't define. */ +/* #undef u_int8_t */ + +/* Define if timeradd is defined in */ +#define HAVE_TIMERADD 1 +#ifndef HAVE_TIMERADD +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) +#endif /* !HAVE_TIMERADD */ + +/* Define if isblank is defined in */ +#define HAVE_ISBLANK 1 +#ifndef HAVE_ISBLANK +#define isblank(x) ((x) == ' ' || (x) == '\t') +#endif + +/* Define if your system defines struct sockaddr_storage */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define if you have the `daemon' function. */ +/* #undef HAVE_DAEMON */ + +/* Define if you don't have `vprintf' but do have `_doprnt.' */ +/* #undef HAVE_DOPRNT */ + +/* Define if you have the `dup2' function. */ +/* #undef HAVE_DUP2 */ + +/* Define if you have the `err' function. */ +#define HAVE_ERR 1 + +/* Define if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define if you have the `freeaddrinfo' function. */ +#define HAVE_FREEADDRINFO 1 + +/* Define if you have the `getaddrinfo' function. */ +#define HAVE_GETADDRINFO 1 + +/* Define if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define if you have the `isblank' function. */ +#define HAVE_ISBLANK 1 + +/* Define if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define if you have the header file. */ +#define HAVE_PATHS_H 1 + +/* Define if you have the `setgroups' function. */ +/* #undef HAVE_SETGROUPS */ + +/* Define if you have the header file. */ +/* #undef HAVE_STDINT_H */ + +/* Define if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define if you have the `strcasecmp' function. */ +#define HAVE_STRCASECMP 1 + +/* Define if you have the `strchr' function. */ +#define HAVE_STRCHR 1 + +/* Define if you have the `strdup' function. */ +#define HAVE_STRDUP 1 + +/* Define if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define if you have the `strlcpy' function. */ +/* #undef HAVE_STRLCPY */ + +/* Define if you have the `strncasecmp' function. */ +#define HAVE_STRNCASECMP 1 + +/* Define if you have the `strsep' function. */ +/* #undef HAVE_STRSEP */ + +/* Define if you have the `strspn' function. */ +#define HAVE_STRSPN 1 + +/* Define if you have the `strtoul' function. */ +#define HAVE_STRTOUL 1 + +/* Define if you have the header file. */ +#define HAVE_SYSLOG_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_IOCCOM_H */ + +/* Define if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_PARAM_H */ + +/* Define if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define if you have the header file. */ +#define HAVE_SYSLOG_H 1 + +/* Define if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define if you have that is POSIX.1 compatible. */ +#define HAVE_SYS_WAIT_H 1 + +/* Define if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define if you have the `vprintf' function. */ +#define HAVE_VPRINTF 1 + +/* Name of package */ +#define PACKAGE "honeyd" + +/* Define as the return type of signal handlers (`int' or `void'). */ +#define RETSIGTYPE void + +/* Define if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Version number of package */ +#define VERSION "0.4a" + +/* Define if `lex' declares `yytext' as a `char *' by default, not a `char[]'. + */ +#define YYTEXT_POINTER 1 + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `int' if doesn't define. */ +/* #undef gid_t */ + +/* Define to `int' if does not define. */ +/* #undef pid_t */ + +/* Define to `unsigned' if does not define. */ +/* #undef size_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef u_int */ + +/* Define to `unsigned short' if does not define. */ +/* #undef u_int16_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef u_int32_t */ + +/* Define to `unsigned long long' if does not define. */ +/* #undef u_int64_t */ + +/* Define to `unsigned char' if does not define. */ +/* #undef u_int8_t */ + +/* Define to `int' if doesn't define. */ +/* #undef uid_t */ + +/* Prototypes for missing functions */ +#ifdef WIN32 +#include +#endif + +#ifndef HAVE_STRLCPY +size_t strlcpy(char *, const char *, size_t); +#endif + +#ifndef HAVE_STRSEP +char *strsep(char **, const char *); +#endif + +#ifndef HAVE_DAEMON +int daemon(int, int); +#endif + +#ifdef WIN32 +#include +#define uid_t int +#define gid_t int +#define pid_t int +#define SHUT_WR SD_SEND +#define snprintf _snprintf +#define strcasecmp stricmp +#define strncasecmp strnicmp +#define __FUNCTION__ "honeyd-win32" +#define __func__ __FUNCTION__ +#define UINT_MAX 0xFFFFU/0xFFFFFFFFUL +#define read _read +#define write _write +#define socklen_t uint32_t +#define ssize_t long +#define setegid +#define setgid +#define seteuid +#define setuid + +static __inline int isblank(int c) { if(c == ' ' || c == '\t') return 1; return 0; } +size_t strlcat(char *, const char *, size_t); + +#endif diff -urN honeyd-0.5/WIN32-Code/getopt.c honeyd-0.5-win32/WIN32-Code/getopt.c --- honeyd-0.5/WIN32-Code/getopt.c Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Code/getopt.c Fri Dec 1 08:37:14 2000 @@ -0,0 +1,106 @@ +#include /* for EOF */ +#include /* for strchr() */ + +#include "getopt.h" + +/* static (global) variables that are specified as exported by getopt() */ +char *optarg = NULL; /* pointer to the start of the option argument */ +int optind = 1; /* number of the next argv[] to be evaluated */ +int opterr = 1; /* non-zero if a question mark should be returned + when a non-valid option character is detected */ + +int getopt(int argc, char *argv[], char *opstring) +{ + static char *pIndexPosition = NULL; /* place inside current argv string */ + char *pArgString = NULL; /* where to start from next */ + char *pOptString; /* the string in our program */ + + + if (pIndexPosition != NULL) { + /* we last left off inside an argv string */ + if (*(++pIndexPosition)) { + /* there is more to come in the most recent argv */ + pArgString = pIndexPosition; + } + } + + if (pArgString == NULL) { + /* we didn't leave off in the middle of an argv string */ + if (optind >= argc) { + /* more command-line arguments than the argument count */ + pIndexPosition = NULL; /* not in the middle of anything */ + return EOF; /* used up all command-line arguments */ + } + + /*--------------------------------------------------------------------- + * If the next argv[] is not an option, there can be no more options. + *-------------------------------------------------------------------*/ + pArgString = argv[optind++]; /* set this to the next argument ptr */ + + if (('/' != *pArgString) && /* doesn't start with a slash or a dash? */ + ('-' != *pArgString)) { + --optind; /* point to current arg once we're done */ + optarg = NULL; /* no argument follows the option */ + pIndexPosition = NULL; /* not in the middle of anything */ + return EOF; /* used up all the command-line flags */ + } + + /* check for special end-of-flags markers */ + if ((strcmp(pArgString, "-") == 0) || + (strcmp(pArgString, "--") == 0)) { + optarg = NULL; /* no argument follows the option */ + pIndexPosition = NULL; /* not in the middle of anything */ + return EOF; /* encountered the special flag */ + } + + pArgString++; /* look past the / or - */ + } + + if (':' == *pArgString) { /* is it a colon? */ + /*--------------------------------------------------------------------- + * Rare case: if opterr is non-zero, return a question mark; + * otherwise, just return the colon we're on. + *-------------------------------------------------------------------*/ + return (opterr ? (int)'?' : (int)':'); + } + else if ((pOptString = strchr(opstring, *pArgString)) == 0) { + /*--------------------------------------------------------------------- + * The letter on the command-line wasn't any good. + *-------------------------------------------------------------------*/ + optarg = NULL; /* no argument follows the option */ + pIndexPosition = NULL; /* not in the middle of anything */ + return (opterr ? (int)'?' : (int)*pArgString); + } + else { + /*--------------------------------------------------------------------- + * The letter on the command-line matches one we expect to see + *-------------------------------------------------------------------*/ + if (':' == _next_char(pOptString)) { /* is the next letter a colon? */ + /* It is a colon. Look for an argument string. */ + if ('\0' != _next_char(pArgString)) { /* argument in this argv? */ + optarg = &pArgString[1]; /* Yes, it is */ + } + else { + /*------------------------------------------------------------- + * The argument string must be in the next argv. + * But, what if there is none (bad input from the user)? + * In that case, return the letter, and optarg as NULL. + *-----------------------------------------------------------*/ + if (optind < argc) + optarg = argv[optind++]; + else { + optarg = NULL; + return (opterr ? (int)'?' : (int)*pArgString); + } + } + + pIndexPosition = NULL; /* not in the middle of anything */ + } + else { + /* it's not a colon, so just return the letter */ + optarg = NULL; /* no argument follows the option */ + pIndexPosition = pArgString; /* point to the letter we're on */ + } + return (int)*pArgString; /* return the letter that matched */ + } +} diff -urN honeyd-0.5/WIN32-Code/getopt.h honeyd-0.5-win32/WIN32-Code/getopt.h --- honeyd-0.5/WIN32-Code/getopt.h Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Code/getopt.h Fri Dec 1 08:37:14 2000 @@ -0,0 +1,8 @@ + +#define _next_char(string) (char)(*(string+1)) + +extern char * optarg; +extern int optind; + +int getopt(int, char**, char*); + diff -urN honeyd-0.5/WIN32-Code/misc.c honeyd-0.5-win32/WIN32-Code/misc.c --- honeyd-0.5/WIN32-Code/misc.c Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Code/misc.c Fri Mar 14 17:21:28 2003 @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include + +/**************************************************************************** + * + * Function: gettimeofday(struct timeval *, struct timezone *) + * + * Purpose: Get current time of day. + * + * Arguments: tv => Place to store the curent time of day. + * tz => Ignored. + * + * Returns: 0 => Success. + * + ****************************************************************************/ + +int gettimeofday(struct timeval *tv, struct timezone *tz) { + struct _timeb tb; + + if(tv == NULL) + return -1; + + _ftime(&tb); + tv->tv_sec = tb.time; + tv->tv_usec = ((int) tb.millitm) * 1000; + return 0; +} + +int setenv(const char *name, const char *value, int overwrite) +{ + char buf[1024]; + memset(buf, 0, sizeof(buf)); + _snprintf(buf, sizeof(buf) - 1, "%s=%s", name, value); + return _putenv(buf); +} + +/**************************************************************************** + * + * Function: init_winsock(void) + * + * Purpose: Initialize winsock. + * + * Arguments: None. + * + * Returns: 0 => Initilization failed. + * 1 => Initilization succeeded. + * + ****************************************************************************/ + +int init_winsock(void) { + WORD wVersionRequested = MAKEWORD(1, 1); + WSADATA wsaData; + + if (WSAStartup(wVersionRequested, &wsaData)) { + return 0; + } + + if (LOBYTE(wsaData.wVersion) < 1 || HIBYTE(wsaData.wVersion) < 1) { + WSACleanup(); + return 0; + } + + return 1; +} diff -urN honeyd-0.5/WIN32-Code/misc.h honeyd-0.5-win32/WIN32-Code/misc.h --- honeyd-0.5/WIN32-Code/misc.h Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Code/misc.h Sun Mar 9 21:25:10 2003 @@ -0,0 +1,8 @@ +#ifndef MISC_H +#define MISC_H + +int gettimeofday(struct timeval *,struct timezone *); +int setenv(const char *name, const char *value, int overwrite); +int init_winsock(void); + +#endif diff -urN honeyd-0.5/WIN32-Code/strlcat.c honeyd-0.5-win32/WIN32-Code/strlcat.c --- honeyd-0.5/WIN32-Code/strlcat.c Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Code/strlcat.c Mon Nov 19 16:27:10 2001 @@ -0,0 +1,73 @@ +/* $OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff -urN honeyd-0.5/WIN32-Code/sys/time.h honeyd-0.5-win32/WIN32-Code/sys/time.h --- honeyd-0.5/WIN32-Code/sys/time.h Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Code/sys/time.h Mon Jan 27 23:00:58 2003 @@ -0,0 +1,155 @@ +/* $OpenBSD: time.h,v 1.11 2000/10/10 13:36:48 itojun Exp $ */ +/* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)time.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ + +#include + +/* + * Structure defined by POSIX.1b to be like a timeval. + */ +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; + +#define TIMEVAL_TO_TIMESPEC(tv, ts) { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ +} +#define TIMESPEC_TO_TIMEVAL(tv, ts) { \ + (tv)->tv_sec = (ts)->tv_sec; \ + (tv)->tv_usec = (ts)->tv_nsec / 1000; \ +} + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; +#define DST_NONE 0 /* not on dst */ +#define DST_USA 1 /* USA style dst */ +#define DST_AUST 2 /* Australian style dst */ +#define DST_WET 3 /* Western European dst */ +#define DST_MET 4 /* Middle European dst */ +#define DST_EET 5 /* Eastern European dst */ +#define DST_CAN 6 /* Canada */ + +/* Operations on timevals. */ +#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) + +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) + +/* Operations on timespecs. */ +#define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0 +#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) +#define timespeccmp(tsp, usp, cmp) \ + (((tsp)->tv_sec == (usp)->tv_sec) ? \ + ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ + ((tsp)->tv_sec cmp (usp)->tv_sec)) +#define timespecadd(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ + if ((vsp)->tv_nsec >= 1000000000L) { \ + (vsp)->tv_sec++; \ + (vsp)->tv_nsec -= 1000000000L; \ + } \ + } while (0) +#define timespecsub(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ + } \ + } while (0) + +/* + * Names of the interval timers, and structure + * defining a timer setting. + */ +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 + +struct itimerval { + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ +}; + +/* + * Getkerninfo clock information structure + */ +struct clockinfo { + int hz; /* clock frequency */ + int tick; /* micro-seconds per hz tick */ + int tickadj; /* clock skew rate for adjtime() */ + int stathz; /* statistics clock frequency */ + int profhz; /* profiling clock frequency */ +}; + +#define CLOCK_REALTIME 0 +#define CLOCK_VIRTUAL 1 +#define CLOCK_PROF 2 + +#define TIMER_RELTIME 0x0 /* relative timer */ +#define TIMER_ABSTIME 0x1 /* absolute timer */ + +/* --- stuff got cut here - niels --- */ + +#endif /* !_SYS_TIME_H_ */ diff -urN honeyd-0.5/WIN32-Code/syslog.c honeyd-0.5-win32/WIN32-Code/syslog.c --- honeyd-0.5/WIN32-Code/syslog.c Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Code/syslog.c Fri Mar 14 19:13:10 2003 @@ -0,0 +1,111 @@ +/* -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/ + . Copyright (c) 2003 Michael Davis + . All rights reserved. + . + . Redistribution and use in source and binary forms, with or without + . modification, are permitted provided that the following conditions + . are met: + . + . 1. Redistributions of source code must retain the above copyright + . notice, this list of conditions and the following disclaimer. + . + . 2. Redistributions in binary form must reproduce the above copyright + . notice, this list of conditions and the following disclaimer in the + . documentation and/or other materials provided with the distribution. + . + . 3. The name of author may not be used to endorse or promote products + . derived from this software without specific prior written permission. + . + . THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + . INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + . AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + . THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + . EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + . PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + . OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + . WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + . OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + . ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + . -\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\ */ + +#include +#include +#include +#include "syslog.h" + +#define TBUF_LEN 2048 +#define FMT_LEN 1024 +#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID + +static int LogFile = -1; /* fd for log */ +static int opened; /* have done openlog() */ +static int LogStat = 0; /* status bits, set by openlog() */ +static char *LogTag = NULL; /* string to tag the entry with */ +static int LogFacility = LOG_USER; /* default facility code */ +static int LogMask = 0xff; /* mask of priorities to be logged */ +extern int debug; +void syslog(int pri, char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vsyslog(pri, fmt, ap); + va_end(ap); +} + +void vsyslog(int pri, char *fmt, va_list ap){ + char ch, *p, *t; + int tbuf_left, fmt_left, prlen, saved_errno; + char tbuf[TBUF_LEN], fmt_cpy[FMT_LEN]; + + p = tbuf; + tbuf_left = TBUF_LEN; + + saved_errno = errno; + + /* + * We wouldn't need this mess if printf handled %m, or if + * strerror() had been invented before syslog(). + */ + for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) { + if (ch == '%' && fmt[1] == 'm') { + ++fmt; + prlen = _snprintf(t, fmt_left, "%s", + strerror(saved_errno)); + if (prlen >= fmt_left) + prlen = fmt_left - 1; + t += prlen; + fmt_left -= prlen; + } else { + if (fmt_left > 1) { + *t++ = ch; + fmt_left--; + } + } + } + *t = '\0'; + + _vsnprintf(p, tbuf_left, fmt_cpy, ap); + + /* Get connected, output the message to the local logger. */ + if(opened) + if(debug) + printf("%s\n", p); + + return; +} + +void openlog(char *ident, int logstat, int logfac){ + + if(ident != NULL){ + LogTag = ident; + LogStat = logstat; + if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) + LogFacility = logfac; + } + opened = 1; +} + +void closelog() +{ + opened = 0; +} diff -urN honeyd-0.5/WIN32-Code/syslog.h honeyd-0.5-win32/WIN32-Code/syslog.h --- honeyd-0.5/WIN32-Code/syslog.h Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Code/syslog.h Sun Mar 9 19:03:12 2003 @@ -0,0 +1,240 @@ +/* -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/ + . Copyright (c) 2003 Michael Davis + . All rights reserved. + . + . Redistribution and use in source and binary forms, with or without + . modification, are permitted provided that the following conditions + . are met: + . + . 1. Redistributions of source code must retain the above copyright + . notice, this list of conditions and the following disclaimer. + . + . 2. Redistributions in binary form must reproduce the above copyright + . notice, this list of conditions and the following disclaimer in the + . documentation and/or other materials provided with the distribution. + . + . 3. The name of author may not be used to endorse or promote products + . derived from this software without specific prior written permission. + . + . THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + . INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + . AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + . THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + . EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + . PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + . OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + . WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + . OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + . ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + . -\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\ */ + +/* $OpenBSD: syslog.h,v 1.5 1998/02/10 18:41:57 deraadt Exp $ */ +/* $NetBSD: syslog.h,v 1.14 1996/04/03 20:46:44 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)syslog.h 8.1 (Berkeley) 6/2/93 + */ + +#define _PATH_LOG "/dev/log" + +/* + * priorities/facilities are encoded into a single 32-bit quantity, where the + * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility + * (0-big number). Both the priorities and the facilities map roughly + * one-to-one to strings in the syslogd(8) source code. This mapping is + * included in this file. + * + * priorities (these are ordered) + */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) +#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) + +#ifdef SYSLOG_NAMES +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ + /* mark "facility" */ +#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) +typedef struct _code { + char *c_name; + int c_val; +} CODE; + +CODE prioritynames[] = { + { "alert", LOG_ALERT }, + { "crit", LOG_CRIT }, + { "debug", LOG_DEBUG }, + { "emerg", LOG_EMERG }, + { "err", LOG_ERR }, + { "error", LOG_ERR }, /* DEPRECATED */ + { "info", LOG_INFO }, + { "none", INTERNAL_NOPRI }, /* INTERNAL */ + { "notice", LOG_NOTICE }, + { "panic", LOG_EMERG }, /* DEPRECATED */ + { "warn", LOG_WARNING }, /* DEPRECATED */ + { "warning", LOG_WARNING }, + { NULL, -1 }, +}; +#endif + +/* facility codes */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* security/authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ +#define LOG_FTP (11<<3) /* ftp daemon */ + + /* other codes through 15 reserved for system use */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +#ifdef SYSLOG_NAMES +CODE facilitynames[] = { + { "auth", LOG_AUTH }, + { "authpriv", LOG_AUTHPRIV }, + { "cron", LOG_CRON }, + { "daemon", LOG_DAEMON }, + { "ftp", LOG_FTP }, + { "kern", LOG_KERN }, + { "lpr", LOG_LPR }, + { "mail", LOG_MAIL }, + { "mark", INTERNAL_MARK }, /* INTERNAL */ + { "news", LOG_NEWS }, + { "security", LOG_AUTH }, /* DEPRECATED */ + { "syslog", LOG_SYSLOG }, + { "user", LOG_USER }, + { "uucp", LOG_UUCP }, + { "local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, + { NULL, -1 }, +}; +#endif + +#ifdef _KERNEL +#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */ +#endif + +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +/* + * Option flags for openlog. + * + * LOG_ODELAY no longer does anything. + * LOG_NDELAY is the inverse of what it used to be. + */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ + +#ifndef _KERNEL + +/* + * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd in two + * places ( and ), so if we include one + * of them here we may collide with the utility's includes. It's unreasonable + * for utilities to have to include one of them to include syslog.h, so we get + * _BSD_VA_LIST_ from and use it. + */ +#ifndef WIN32 +#include +#include +#endif + +#ifdef WIN32 +void syslog(int, char *, ...); +void vsyslog(int, char *, va_list); +void openlog(char *, int, int); +void closelog(void); +unsigned long resolve_host(char *); +#else +__BEGIN_DECLS +void closelog __P((void)); +void openlog __P((const char *, int, int)); +int setlogmask __P((int)); +void syslog __P((int, const char *, ...)) + __attribute__((__format__(__printf__,2,3))); +void vsyslog __P((int, const char *, _BSD_VA_LIST_)); +__END_DECLS +#endif + +#else /* !_KERNEL */ + +void logpri __P((int)); +void log __P((int, const char *, ...)) + __kprintf_attribute__((__format__(__kprintf__,2,3))); +int addlog __P((const char *, ...)) + __kprintf_attribute__((__format__(__kprintf__,1,2))); +void logwakeup __P((void)); + +#endif /* !_KERNEL */ diff -urN honeyd-0.5/WIN32-Prj/honeyd.dsp honeyd-0.5-win32/WIN32-Prj/honeyd.dsp --- honeyd-0.5/WIN32-Prj/honeyd.dsp Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Prj/honeyd.dsp Fri Mar 14 19:12:08 2003 @@ -0,0 +1,263 @@ +# Microsoft Developer Studio Project File - Name="honeyd" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=honeyd - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "honeyd.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "honeyd.mak" CFG="honeyd - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "honeyd - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "honeyd - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "honeyd - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "..\\" /I "..\WIN32-Code" /I "..\compat" /I "..\..\libevent-0.6" /I "..\..\libdnet-1.5\WIN32-include" /I "..\..\libdnet-1.5\include" /I "..\..\Wpdpack\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "HAVE_CONFIG_H" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 ws2_32.lib ..\..\libevent-0.6\WIN32-Prj\Release\libevent.lib ..\..\WPdpack\Lib\wpcap.lib ..\..\\libdnet-1.5\WIN32-Prj\Release\libdnet.lib Advapi32.lib Iphlpapi.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "honeyd - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\\" /I "..\WIN32-Code" /I "..\compat" /I "..\..\libevent-0.6" /I "..\..\libdnet-1.5\WIN32-include" /I "..\..\libdnet-1.5\include" /I "..\..\Wpdpack\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "HAVE_CONFIG_H" /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 ws2_32.lib ..\..\libevent-0.6\WIN32-Prj\Debug\libevent.lib ..\..\WPdpack\Lib\wpcap.lib ..\..\\libdnet-1.5\WIN32-Prj\Debug\libdnet.lib Advapi32.lib Iphlpapi.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "honeyd - Win32 Release" +# Name "honeyd - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\atomicio.c +# End Source File +# Begin Source File + +SOURCE=..\command.c +# End Source File +# Begin Source File + +SOURCE=..\config.c +# End Source File +# Begin Source File + +SOURCE=..\err.c +# End Source File +# Begin Source File + +SOURCE=..\fdpass.c +# End Source File +# Begin Source File + +SOURCE="..\WIN32-Code\getopt.c" +# End Source File +# Begin Source File + +SOURCE=..\honeyd.c +# End Source File +# Begin Source File + +SOURCE=..\ipfrag.c +# End Source File +# Begin Source File + +SOURCE=..\lex.c + +!IF "$(CFG)" == "honeyd - Win32 Release" + +!ELSEIF "$(CFG)" == "honeyd - Win32 Debug" + +# ADD CPP /D "i386" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\lex.l +# End Source File +# Begin Source File + +SOURCE=..\log.c +# End Source File +# Begin Source File + +SOURCE="..\WIN32-Code\misc.c" +# End Source File +# Begin Source File + +SOURCE=..\parse.c +# End Source File +# Begin Source File + +SOURCE=..\personality.c +# End Source File +# Begin Source File + +SOURCE=..\router.c +# End Source File +# Begin Source File + +SOURCE="..\WIN32-Code\strlcat.c" +# End Source File +# Begin Source File + +SOURCE=..\strlcpy.c +# End Source File +# Begin Source File + +SOURCE=..\strsep.c +# End Source File +# Begin Source File + +SOURCE=..\subsystem.c +# End Source File +# Begin Source File + +SOURCE=..\subsystem.h +# End Source File +# Begin Source File + +SOURCE="..\WIN32-Code\syslog.c" +# End Source File +# Begin Source File + +SOURCE=..\tcp.c +# End Source File +# Begin Source File + +SOURCE=..\udp.c +# End Source File +# Begin Source File + +SOURCE=..\util.c +# End Source File +# Begin Source File + +SOURCE=..\xprobe_assoc.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE="..\WIN32-Code\config.h" +# End Source File +# Begin Source File + +SOURCE=..\fdpass.h +# End Source File +# Begin Source File + +SOURCE="..\WIN32-Code\getopt.h" +# End Source File +# Begin Source File + +SOURCE=..\honeyd.h +# End Source File +# Begin Source File + +SOURCE=..\ipfrag.h +# End Source File +# Begin Source File + +SOURCE="..\WIN32-Code\misc.h" +# End Source File +# Begin Source File + +SOURCE=..\parse.h +# End Source File +# Begin Source File + +SOURCE=..\personality.h +# End Source File +# Begin Source File + +SOURCE="..\WIN32-Code\res_config.h" +# End Source File +# Begin Source File + +SOURCE=..\router.h +# End Source File +# Begin Source File + +SOURCE="..\WIN32-Code\syslog.h" +# End Source File +# Begin Source File + +SOURCE=..\tcp.h +# End Source File +# Begin Source File + +SOURCE=..\udp.h +# End Source File +# Begin Source File + +SOURCE=..\xprobe_assoc.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff -urN honeyd-0.5/WIN32-Prj/honeyd.dsw honeyd-0.5-win32/WIN32-Prj/honeyd.dsw --- honeyd-0.5/WIN32-Prj/honeyd.dsw Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32-Prj/honeyd.dsw Mon Jan 27 22:31:40 2003 @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "honeyd"=".\honeyd.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff -urN honeyd-0.5/WIN32_README.txt honeyd-0.5-win32/WIN32_README.txt --- honeyd-0.5/WIN32_README.txt Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/WIN32_README.txt Fri Mar 14 18:11:42 2003 @@ -0,0 +1,71 @@ +Honeyd - (c) 2002 Niels Provos +Honeyd-WIN32 - (c) 2003 Michael A. Davis + +About Honeyd-WIN32 +------------------ + +Honeyd-win32 has all the capabilities of the UNIX version of honeyd with the exception of subsystems. Scripts, proxies, etc are all 100% supported. + +Installation: +------------- + + 1. Download and install WinPCAP from http://winpcap.polito.it/. + + !!! NOTE: Honeyd-win32 has ONLY been test with WinPCAP Version 3.0 Beta. Other versions may or may not work. !!! + + 2. Follow the WinPCAP instructions and install the WinPCAP driver. + + 3. Execute honeyd just like the Unix version. + +FAQ: +---- + Q: Does this version of honeyd contain the newest patches for version 0.5? + + A: Yes. + + Q: What directory does honeyd look for its configuration files in? + + A: Whatever the current working directory is when you execute honeyd. + + Q: Can I use the scripts that come with honeyd? + + A: Yes! You need to install cygwin and make sure that the cygwin binary directory is in your System's PATH Variable. + + Q: When will subsystems be supported? + + A: Probably not for a while, if ever. I do not know of a win32 way to emulate the LD_PRELOAD functionality in UNIX without a hook server and driver which is a PITA. + +Known Bugs: +----------- + 1. When specifying a subsystem within a config file you will receive a parse error. + 2. If you have two identical Ethernet Adapters(as in Vendor and Model number: i.e. 2 3c905C cards) you will NOT be able to select the second interface to listen on. This is a problem with libdnet that Dug Song and I are fixing. + +Documentation: +-------------- + +Please refer to honeyd.html + +How to Compile honeyd-win32: +---------------------------- + + 1. You need the following libraries: libevent-win32(http://www.secuirtyprofiling.com), libdnet-msvc(http://www.secuirtyprofiling.com), and winpcap Developer Pack(ttp://winpcap.polito.it/) and the Microsoft Platform SDK. + 2. You shoould extract all three of these libraries into a common directory. here is how the layout should look: + + \CommonDirectory + \libdnet-1.5 + \libevent-0.6 + \wpdpack + \honeyd-0.5 + + 3. Load the honeyd.dsw project into MS VC++ 6. NOTE: There is curently no support for MS VC.NET. + 4. Verify that the Platform SDK has been added to your Directory search path. Go to Tools->Options->Directories. If the path where you installed the MS Platform SDK is not listed then add it to the "Include Files" search and "Library Files" search list. + 5. Click Build then click Build honeyd.exe. + +Acknowledgments: +---------------- + +The following people have helped with suggestions, ideas or code: + + Brett Oliphant + Dug Song + Lance Spitzner diff -urN honeyd-0.5/atomicio.c honeyd-0.5-win32/atomicio.c --- honeyd-0.5/atomicio.c Wed Feb 12 21:06:53 2003 +++ honeyd-0.5-win32/atomicio.c Thu Mar 13 16:10:46 2003 @@ -25,7 +25,9 @@ */ #include +#ifndef WIN32 #include +#endif #include #ifdef HAVE_CONFIG_H diff -urN honeyd-0.5/command.c honeyd-0.5-win32/command.c --- honeyd-0.5/command.c Sat Feb 15 14:31:49 2003 +++ honeyd-0.5-win32/command.c Fri Mar 14 19:06:00 2003 @@ -29,18 +29,53 @@ */ #include -#include #ifdef HAVE_CONFIG_H #include "config.h" #endif +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef WIN32 +#include "misc.h" +#include +#include +#include +#include +#include +#include +struct sockinet { + u_char si_len; + u_char si_family; + u_short si_port; +}; + +struct addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + char *ai_canonname; + struct sockaddr *ai_addr; + struct addrinfo *ai_next; +}; + +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 +#define NI_NUMERICHOST 0x00000002 +#define NI_NUMERICSERV 0x00000008 +#else +#include #include +#include +#include +#include +#endif #include #include #include -#include -#include #include #include @@ -49,7 +84,6 @@ #include #include #include -#include #include #include @@ -73,19 +107,41 @@ void cmd_trigger_read(struct command *cmd, int size) { - if (cmd->pfd == -1 || !cmd->fdconnected) +#ifdef WIN32 + /* Specify a quick timeout becuse we do no want libevent to wait INFINITE. */ + struct timeval tv = {0,1}; +#endif + if (cmd->pfd == INVALID_SOCKET || !cmd->fdconnected) return; if (size) +#ifdef WIN32 + if(!cmd->IsProxyCmd) + event_add(&cmd->pread, &tv); + else + event_add(&cmd->pread, NULL); +#else event_add(&cmd->pread, NULL); +#endif } void cmd_trigger_write(struct command *cmd, int size) { - if (cmd->pfd == -1 || !cmd->fdconnected) +#ifdef WIN32 + /* Specify a quick timeout becuse we do no want libevent to wait INFINITE. */ + struct timeval tv = {0,1}; +#endif + if (cmd->pfd == INVALID_SOCKET || !cmd->fdconnected) return; if (size) +#ifdef WIN32 + if(!cmd->IsProxyCmd) + event_add(&cmd->pwrite, &tv); + else event_add(&cmd->pwrite, NULL); +#else + event_add(&cmd->pwrite, NULL); +#endif } void @@ -93,24 +149,68 @@ { event_del(&cmd->pread); event_del(&cmd->pwrite); +#ifdef WIN32 + if(cmd->IsProxyCmd) { + WSAEventSelect(cmd->pfd, cmd->pread.ev_fd, 0); + WSAEventSelect(cmd->pfd, cmd->pwrite.ev_fd, 0); + WSACloseEvent(cmd->pread.ev_fd); + WSACloseEvent(cmd->pwrite.ev_fd); + + close(cmd->pfd); + cmd->pfd = INVALID_SOCKET; + } else { + CloseHandle((HANDLE)cmd->pfd); + cmd->pfd = INVALID_SOCKET; + CloseHandle((HANDLE)cmd->pwritefd); + cmd->pwritefd = INVALID_SOCKET; + } +#else close(cmd->pfd); - cmd->pfd = -1; + cmd->pfd = INVALID_SOCKET; +#endif - if (cmd->perrfd != -1) { + if (cmd->perrfd != INVALID_SOCKET) { event_del(&cmd->peread); close(cmd->perrfd); - cmd->perrfd = -1; + cmd->perrfd = INVALID_SOCKET; } } +#ifdef WIN32 + +#endif + void cmd_ready_fd(struct command *cmd, struct callback *cb, void *con) { +#ifdef WIN32 + if(cmd->IsProxyCmd) { + if((cmd->pread.ev_fd = WSACreateEvent()) == NULL) + return; + if((cmd->pwrite.ev_fd = WSACreateEvent()) == NULL) + return; + + /* + XXX: Creating two events which are read/write may cause issues + but in all my testing it works fine. + */ + if(WSAEventSelect(cmd->pfd, cmd->pread.ev_fd, FD_READ|FD_WRITE|FD_CLOSE) == SOCKET_ERROR) + errx(1, "WSAEventSelect: %d", WSAGetLastError()); + if(WSAEventSelect(cmd->pfd, cmd->pwrite.ev_fd, FD_READ|FD_WRITE|FD_CLOSE) == SOCKET_ERROR) + errx(1, "WSAEventSelect: %d", WSAGetLastError()); + event_set(&cmd->pread, (int)cmd->pread.ev_fd, EV_READ, cb->cb_read, con); + event_set(&cmd->pwrite, (int)cmd->pwrite.ev_fd, EV_WRITE, cb->cb_write, con); + } else { + event_set(&cmd->pread, cmd->pfd, EV_READ, cb->cb_read, con); + event_set(&cmd->pwrite, cmd->pwritefd, EV_WRITE, cb->cb_write, con); + } +#else event_set(&cmd->pread, cmd->pfd, EV_READ, cb->cb_read, con); event_set(&cmd->pwrite, cmd->pfd, EV_WRITE, cb->cb_write, con); +#endif cmd->fdconnected = 1; - if (cmd->perrfd != -1) + if (cmd->perrfd != INVALID_SOCKET) event_set(&cmd->peread, cmd->perrfd, EV_READ, cb->cb_eread, con); } @@ -119,18 +219,50 @@ cmd_proxy_getinfo(char *address, int type, short port) { struct addrinfo ai, *aitop; +#ifdef WIN32 + struct hostent *host_entry; + struct sockaddr_in *sin; +#else char strport[NI_MAXSERV]; +#endif memset(&ai, 0, sizeof (ai)); ai.ai_family = AF_INET; ai.ai_socktype = type; ai.ai_flags = 0; +#ifdef WIN32 + aitop = (struct addrinfo *)malloc(sizeof(struct addrinfo)); + if(!aitop) { + warn("malloc"); + return (NULL); + } + aitop->ai_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr)); + if(!aitop->ai_addr) { + warn("malloc"); + return (NULL); + } + aitop->ai_addrlen = sizeof(struct sockaddr); + sin = (struct sockaddr_in *)aitop->ai_addr; + sin->sin_port = htons(port); + + host_entry = gethostbyname(address); + + if(host_entry == NULL) { + warn("gethostbyname"); + return (NULL); + } + + memcpy(&sin->sin_addr, host_entry->h_addr_list[0], host_entry->h_length); + + sin->sin_family = host_entry->h_addrtype; + sin->sin_port = htons(port); +#else snprintf(strport, sizeof (strport), "%d", port); if (getaddrinfo(address, strport, &ai, &aitop) != 0) { warn("getaddrinfo"); return (NULL); } - +#endif return (aitop); } @@ -143,40 +275,55 @@ struct callback *cb; struct timeval tv = {10, 0}; int fd; - +#ifdef WIN32 + struct hostent *pHost = NULL; + + cmd->IsProxyCmd = 1; +#endif if (hdr->type == SOCK_STREAM) cb = &cb_tcp; else cb = &cb_udp; fd = socket(AF_INET, hdr->type, 0); - if (fd == -1) { + if (fd == INVALID_SOCKET) { warn("socket"); return (-1); } - +#ifndef WIN32 if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) warn("fcntl(O_NONBLOCK)"); if (fcntl(fd, F_SETFD, 1) == -1) warn("fcntl(F_SETFD)"); - +#endif cmd->pfd = fd; if (connect(fd, ai->ai_addr, ai->ai_addrlen) == 0) { (*cb->cb_connect)(fd, EV_WRITE, con); return (0); } +#ifndef WIN32 if (errno != EINPROGRESS) { warn("connect"); cmd->pfd = -1; close(fd); return (-1); } +#endif event_set(&cmd->pwrite, fd, EV_WRITE, cb->cb_connect, con); event_add(&cmd->pwrite, &tv); +#ifdef WIN32 + pHost = gethostbyaddr(ai->ai_addr->sa_data, ai->ai_addrlen,AF_INET); + if(pHost) + host = pHost->h_name; + else + host = inet_ntoa(((struct sockaddr_in *)ai->ai_addr)->sin_addr); + + snprintf(port, sizeof(strport), "%d", ntohs(((const struct sockinet *)ai->ai_addr)->si_port)); +#else if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop, sizeof(ntop), strport, sizeof(strport), NI_NUMERICHOST|NI_NUMERICSERV) != 0) { @@ -184,6 +331,7 @@ host = ""; port = ""; } +#endif syslog(LOG_INFO, "Connection established: %s -> proxy to %s:%s", honeyd_contoa(hdr), host, port); @@ -222,6 +370,7 @@ int cmd_setpriv(struct template *tmpl) { +#ifndef WIN32 uid_t uid = 32767; gid_t gid = 32767; struct rlimit rl; @@ -244,7 +393,7 @@ rl.rlim_cur = rl.rlim_max = 24; if (setrlimit(RLIMIT_NOFILE, &rl) == -1) err(1, "setrlimit"); - +#endif return (0); } @@ -253,8 +402,176 @@ char *execcmd, char **argv, void *con) { extern int honeyd_nchildren; - int pair[2], perr[2]; struct callback *cb; +#ifdef WIN32 + int pid; + SECURITY_ATTRIBUTES saAttr; + BOOL fSuccess; + DWORD dwMode; + HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup, + hChildStdoutRd, hChildStdoutWr, hChildStdoutRdDup, + hChildStderrRd, hChildStderrWr, hChildStderrRdDup, + hSaveStdin, hSaveStdout, hSaveStderr; + + // Set the bInheritHandle flag so pipe handles are inherited. + + saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); + saAttr.bInheritHandle = TRUE; + saAttr.lpSecurityDescriptor = NULL; + + // The steps for redirecting child process's STDOUT: + // 1. Save current STDOUT, to be restored later. + // 2. Create anonymous pipe to be STDOUT for child process. + // 3. Set STDOUT of the parent process to be write handle to + // the pipe, so it is inherited by the child process. + // 4. Create a noninheritable duplicate of the read handle and + // close the inheritable read handle. + + // Save the handle to the current STDOUT. + + hSaveStdout = GetStdHandle(STD_OUTPUT_HANDLE); + + // Create a pipe for the child process's STDOUT. + + if (!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) + warn("Stdout pipe creation failed\n"); + + // Set a write handle to the pipe to be STDOUT. + + if (!SetStdHandle(STD_OUTPUT_HANDLE, hChildStdoutWr)) + warn("Redirecting STDOUT failed"); + + // Create noninheritable read handle and close the inheritable read + // handle. + + fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd, + GetCurrentProcess(), &hChildStdoutRdDup , 0, + FALSE, + DUPLICATE_SAME_ACCESS); + if( !fSuccess ) + warn("DuplicateHandle failed"); + CloseHandle(hChildStdoutRd); + + // Save the handle to the current STDERR. + + hSaveStderr = GetStdHandle(STD_ERROR_HANDLE); + + // Create a pipe for the child process's STDERR. + + if (!CreatePipe(&hChildStderrRd, &hChildStderrWr, &saAttr, 0)) + warn("Stderr pipe creation failed\n"); + + // Set a write handle to the pipe to be STDERR. + + if (! SetStdHandle(STD_ERROR_HANDLE, hChildStderrWr)) + warn("Redirecting STDERR failed"); + + // Create noninheritable read handle and close the inheritable read + // handle. + + fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStderrRd, + GetCurrentProcess(), &hChildStderrRdDup , 0, + FALSE, + DUPLICATE_SAME_ACCESS); + if(!fSuccess ) + warn("DuplicateHandle failed"); + + CloseHandle(hChildStderrRd); + + // The steps for redirecting child process's STDIN: + // 1. Save current STDIN, to be restored later. + // 2. Create anonymous pipe to be STDIN for child process. + // 3. Set STDIN of the parent to be the read handle to the + // pipe, so it is inherited by the child process. + // 4. Create a noninheritable duplicate of the write handle, + // and close the inheritable write handle. + + // Save the handle to the current STDIN. + + hSaveStdin = GetStdHandle(STD_INPUT_HANDLE); + + // Create a pipe for the child process's STDIN. + + if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) + warn("Stdin pipe creation failed\n"); + + // Set a read handle to the pipe to be STDIN. + + if (! SetStdHandle(STD_INPUT_HANDLE, hChildStdinRd)) + warn("Redirecting Stdin failed"); + + // Duplicate the write handle to the pipe so it is not inherited. + + fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr, + GetCurrentProcess(), &hChildStdinWrDup, 0, + FALSE, // not inherited + DUPLICATE_SAME_ACCESS); + if (! fSuccess) + warn("DuplicateHandle failed"); + + CloseHandle(hChildStdinWr); + + // Set our Pipes to Asynchronous mode. + dwMode = PIPE_NOWAIT; + SetNamedPipeHandleState( + hChildStdoutRdDup, // pipe handle + &dwMode, // new pipe mode + NULL, // don't set maximum bytes + NULL); // don't set maximum time + SetNamedPipeHandleState( + hChildStdinWrDup, // pipe handle + &dwMode, // new pipe mode + NULL, // don't set maximum bytes + NULL); + SetNamedPipeHandleState( + hChildStderrRdDup, // pipe handle + &dwMode, // new pipe mode + NULL, // don't set maximum bytes + NULL); + + // Place the handles in out command struct. + cmd->pfd = (int)hChildStdoutRdDup; + cmd->pwritefd = (int)hChildStdinWrDup; + cmd->perrfd = (int)hChildStderrRdDup; + + // Create our Environment. + cmd_environment(tmpl, hdr); + + // Spawn process + pid = spawnvp(P_NOWAIT, execcmd, argv); + if(!pid) { + warn("Could not spawn process"); + return (-1); + } + + // To give our cmd some time to initialize. Recommended by MSDN. + Sleep(1); + + // After process creation, restore the saved STDIN, STDOUT, and STDERR. + if (!SetStdHandle(STD_INPUT_HANDLE, hSaveStdin)) + warn("Re-redirecting Stdin failed\n"); + + if (!SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout)) + warn("Re-redirecting Stdout failed\n"); + + if (!SetStdHandle(STD_ERROR_HANDLE, hSaveStderr)) + warn("Re-redirecting Stderr failed\n"); + + if (hdr->type == SOCK_STREAM) + cb = &cb_tcp; + else + cb = &cb_udp; + + cmd_ready_fd(cmd, cb, con); + + event_add(&cmd->pread, NULL); + event_add(&cmd->peread, NULL); + + honeyd_nchildren++; + + return (0); +#else + int pair[2], perr[2]; sigset_t sigmask; if (socketpair(AF_UNIX, hdr->type, 0, pair) == -1) @@ -349,6 +666,7 @@ close(pair[0]); close(pair[1]); cmd->pfd = -1; +#endif return (-1); } @@ -357,6 +675,9 @@ cmd_subsystem(struct template *tmpl, struct subsystem *sub, char *execcmd, char **argv) { +#ifdef WIN32 + return (-1); +#else extern int honeyd_nchildren; struct command *cmd = &sub->cmd; extern struct callback subsystem_cb; @@ -440,12 +761,16 @@ cmd->pfd = -1; return (-1); +#endif } int cmd_subsystem_connect(struct tuple *hdr, struct command *cmd, struct port *port, void *con) { +#ifdef WIN32 + return (-1); +#else struct callback *cb; struct subsystem *sub = port->sub; struct sockaddr_in si; @@ -488,12 +813,16 @@ honeyd_contoa(hdr), sub->cmdstring); return (0); +#endif } int cmd_subsystem_localconnect(struct tuple *hdr, struct command *cmd, struct port *port, void *con) { +#ifdef WIN32 + return (-1); +#else struct callback *cb; struct subsystem *sub = port->sub; struct sockaddr_in si; @@ -559,4 +888,5 @@ sub->cmdstring, honeyd_contoa(hdr)); return (0); +#endif } diff -urN honeyd-0.5/compat/sys/queue.h honeyd-0.5-win32/compat/sys/queue.h --- honeyd-0.5/compat/sys/queue.h Thu Apr 11 11:41:07 2002 +++ honeyd-0.5-win32/compat/sys/queue.h Fri Feb 21 20:59:12 2003 @@ -96,11 +96,13 @@ #define SLIST_HEAD_INITIALIZER(head) \ { NULL } - + +#ifndef WIN32 #define SLIST_ENTRY(type) \ struct { \ struct type *sle_next; /* next element */ \ } +#endif /* * Singly-linked List access methods. diff -urN honeyd-0.5/config.c honeyd-0.5-win32/config.c --- honeyd-0.5/config.c Sat Feb 15 14:53:30 2003 +++ honeyd-0.5-win32/config.c Thu Mar 13 19:50:24 2003 @@ -29,25 +29,30 @@ */ #include +#include "config.h" + +#ifdef WIN32 +#include +#else #include +#include +#include +#include +#endif -#include "config.h" #ifdef HAVE_SYS_TIME_H #include #endif -#include #include #include #include -#include #include #include #include #include #include -#include #include #undef timeout_pending @@ -173,7 +178,13 @@ if (port->action.action != NULL) free (port->action.action); if (port->action.aitop != NULL) +#ifdef WIN32 + { + free(port->action.aitop); + } +#else freeaddrinfo(port->action.aitop); +#endif free(port); } diff -urN honeyd-0.5/fdpass.c honeyd-0.5-win32/fdpass.c --- honeyd-0.5/fdpass.c Thu Feb 13 10:58:39 2003 +++ honeyd-0.5-win32/fdpass.c Thu Mar 13 19:47:14 2003 @@ -23,15 +23,17 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #ifdef HAVE_CONFIG_H #include "config.h" #endif +#ifndef WIN32 +#include #include #include +#endif #include #include @@ -87,6 +89,9 @@ #else errx(1, "%s: subsystems not supported due to lack of fd passing", __func__); +#ifdef WIN32 + return 0; +#endif #endif return (0); @@ -151,5 +156,8 @@ #else errx(1, "%s: subsystems not supported due to lack of fd passing", __func__); +#ifdef WIN32 + return 0; +#endif #endif } diff -urN honeyd-0.5/honeyd.c honeyd-0.5-win32/honeyd.c --- honeyd-0.5/honeyd.c Sat Feb 15 16:07:48 2003 +++ honeyd-0.5-win32/honeyd.c Fri Mar 14 19:07:32 2003 @@ -28,7 +28,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #ifdef HAVE_CONFIG_H @@ -41,11 +40,18 @@ #ifdef HAVE_SYS_IOCCOM_H #include #endif +#ifdef WIN32 +#include "getopt.h" +#include "misc.h" +#else +#include #include #include +#include +#include +#endif #include #include -#include #include #include @@ -60,7 +66,6 @@ #ifdef HAVE_TIME_H #include #endif -#include #include #undef timeout_pending @@ -122,12 +127,20 @@ int honeyd_dopoll; int honeyd_ttl; struct tcp_con honeyd_tmp; +#ifdef WIN32 +int debug; +#endif void usage(void) { fprintf(stderr, +#ifdef WIN32 + "WIN32 Port By Michael A. Davis (mdavis@securityprofiling.com, www.securityprofiling.com)\n" + "Usage: honeyd [-dPW] [-l logfile] [-i interface] [-p personalities]\n" +#else "Usage: honeyd [-dP] [-l logfile] [-i interface] [-p personalities]\n" +#endif "\t[-x xprobe] [-a assoc] [-f config] [net ...]\n"); exit(1); } @@ -146,8 +159,12 @@ hdr->type = SOCK_STREAM; hdr->local = local; con->rcv_flags = tcp->th_flags; - con->cmd.pfd = -1; - con->cmd.perrfd = -1; + con->cmd.pfd = INVALID_SOCKET; + con->cmd.perrfd = INVALID_SOCKET; +#ifdef WIN32 + con->cmd.pwritefd = INVALID_SOCKET; + con->cmd.IsProxyCmd = 0; +#endif } void @@ -164,9 +181,12 @@ hdr->type = SOCK_DGRAM; hdr->local = local; con->softerrors = 0; - con->cmd.pfd = -1; - con->cmd.perrfd = -1; - + con->cmd.pfd = INVALID_SOCKET; + con->cmd.perrfd = INVALID_SOCKET; +#ifdef WIN32 + con->cmd.pwritefd = INVALID_SOCKET; + con->cmd.IsProxyCmd = 0; +#endif TAILQ_INIT(&con->incoming); } @@ -316,7 +336,12 @@ honeyd_init(char *dev, int naddresses, char **addresses) { struct bpf_program fcode; +#ifndef WIN32 struct rlimit rl; +#else + pcap_if_t *alldevs, *d; + int adapter, i; +#endif char filter[1024], ebuf[PCAP_ERRBUF_SIZE], *dst; intf_t *intf; int options, time; @@ -330,6 +355,7 @@ memset(&honeyd_tmp, 0, sizeof(honeyd_tmp)); +#ifndef WIN32 /* Raising file descriptor limits */ if (getrlimit(RLIMIT_NOFILE, &rl) == -1) err(1, "getrlimit"); @@ -343,6 +369,8 @@ if (setrlimit(RLIMIT_NPROC, &rl) == -1) err(1, "setrlimit"); #endif +#endif + if ((honeyd_ip = ip_open()) == NULL) err(1, "ip_open"); @@ -352,13 +380,32 @@ if ((intf = intf_open()) == NULL) err(1, "intf_open"); +#ifdef WIN32 + if (pcap_findalldevs(&alldevs, ebuf) == -1) + errx(1, "pcap_findalldevs: %s", ebuf); + + if (dev == NULL) + d = alldevs; + else { + adapter = atoi(dev); + for(i=1, d=alldevs; adapter && i <= adapter && d; i++, d=d->next); + + if (d == NULL) + errx(1, "Unable to find adapter %d", adapter); + } + dev = d->name; + honeyd_ifent.intf_len = sizeof(honeyd_ifent); + strlcpy(honeyd_ifent.intf_name, alldevs->description, sizeof(honeyd_ifent.intf_name)); + +#else if (dev == NULL) { if ((dev = pcap_lookupdev(ebuf)) == NULL) errx(1, "pcap_lookupdev: %s", ebuf); } honeyd_ifent.intf_len = sizeof(honeyd_ifent); strlcpy(honeyd_ifent.intf_name, dev, sizeof(honeyd_ifent.intf_name)); - +#endif + if (intf_get(intf, &honeyd_ifent) < 0) err(1, "intf_get"); @@ -429,7 +476,9 @@ syslog(LOG_WARNING, "calloc: %m"); return (NULL); } - +#ifdef WIN32 + con->cmd.IsProxyCmd = 0; +#endif honeyd_nconnects++; honeyd_settcp(con, ip, tcp, local); timeout_set(&con->timeout, honeyd_tcp_timeout, con); @@ -663,7 +712,13 @@ if ((ai = cmd_proxy_getinfo(name, hdr->type, nport)) == NULL) return (-1); res = cmd_proxy_connect(hdr, cmd, ai, arg); +#ifdef WIN32 + if(ai->ai_addr) + free(ai->ai_addr); + free(ai); +#else freeaddrinfo(ai); +#endif } else res = cmd_proxy_connect(hdr, cmd, ai, arg); @@ -776,13 +831,22 @@ goto out; return; } +#ifdef WIN32 + argv[0] = "C:\\winnt\\system32\\cmd.exe"; + argv[1] = "/c"; + argv[2] = line; + argv[3] = NULL; + if (cmd_fork(hdr, cmd, tmpl, "C:\\winnt\\system32\\cmd.exe", argv, con) == -1) { +#else argv[0] = "/bin/sh"; argv[1] = "-c"; argv[2] = line; argv[3] = NULL; if (cmd_fork(hdr, cmd, tmpl, "/bin/sh", argv, con) == -1) { +#endif + syslog(LOG_WARNING, "malloc %s: %m", honeyd_contoa(hdr)); goto err; } @@ -873,7 +937,7 @@ void tcp_senddata(struct tcp_con *con, uint8_t flags) { - int space, sent; + unsigned int space, sent; int needretrans = 0; do { @@ -1271,7 +1335,7 @@ } \ tcp_drain_payload(con, acked); \ acked += ackinc; \ - if (con->cmd_pfd == -1 && con->plen <= TCP_MAX_SEND) \ + if (con->cmd_pfd == INVALID_SOCKET && con->plen <= TCP_MAX_SEND) \ con->sentfin = 1; \ } else if (con->sentfin) { \ if (th_ack == con->snd_una + 1) { \ @@ -1594,7 +1658,7 @@ udp = (struct udp_hdr *)(pkt + (ip->ip_hl << 2)); data = (u_char *)(pkt + (ip->ip_hl*4) + UDP_HDR_LEN); dlen = ntohs(ip->ip_len) - (ip->ip_hl << 2) - UDP_HDR_LEN; - if (dlen != (ntohs(udp->uh_ulen) - UDP_HDR_LEN)) + if ((u_short)dlen != (ntohs(udp->uh_ulen) - UDP_HDR_LEN)) return; portnum = ntohs(udp->uh_dport); @@ -1918,7 +1982,7 @@ int delay = 0; u_short iplen; - if (pkthdr->caplen < honeyd_dloff + IP_HDR_LEN) + if (pkthdr->caplen < (unsigned int)(honeyd_dloff + IP_HDR_LEN)) return; ip = (struct ip_hdr *)(pkt + honeyd_dloff); @@ -2036,6 +2100,7 @@ void child_handler(int sig) { +#ifndef WIN32 int s = errno; if (signal(SIGCHLD, child_handler) == SIG_ERR) { @@ -2047,6 +2112,7 @@ while (waitpid(-1, NULL, WNOHANG) > 0) honeyd_nchildren--; errno = s; +#endif } int @@ -2069,14 +2135,43 @@ char *xprobe = PATH_HONEYDDATA "/xprobe2.conf"; char *assoc = PATH_HONEYDDATA "/nmap.assoc"; char *logfile = NULL; +#ifndef WIN32 int c, debug; +#endif FILE *fp; +#ifdef WIN32 + int c; + char ebuf[PCAP_ERRBUF_SIZE]; + pcap_if_t *alldevs, *d; + int i; +#endif dev = NULL; debug = 0; - + +#ifdef WIN32 + while ((c = getopt(argc, argv, "WVPdi:p:x:a:f:l:h?")) != -1) { +#else while ((c = getopt(argc, argv, "VPdi:p:x:a:f:l:h?")) != -1) { +#endif switch (c) { +#ifdef WIN32 + case 'W': + if (pcap_findalldevs(&alldevs, ebuf) == -1) + errx(1, "pcap_findalldevs: %s", ebuf); + + printf("\nInterface\tDevice\t\tDescription\n-------------------------------------------\n"); + for(i = 1, d=alldevs;d;d=d->next, i++) { + printf("%d %s",i, d->name); + + if (d->description) + printf("\t%s",d->description); + + printf("\n"); + } + exit(1); + break; +#endif /* WIN32 */ case 'V': printf("Honeyd Version %s\n", VERSION); exit(0); @@ -2115,6 +2210,9 @@ if ((honeyd_rand = rand_open()) == NULL) err(1, "rand_open"); +#ifdef WIN32 + init_winsock(); +#endif /* Initalize libevent but without kqueue because of bpf */ setenv("EVENT_NOKQUEUE", "yes", 0); event_init(); @@ -2163,6 +2261,7 @@ if ((fp = fopen(PIDFILE, "w")) == NULL) err(1, "fopen"); +#ifndef WIN32 if (!debug) { setlogmask(LOG_UPTO(LOG_INFO)); @@ -2172,6 +2271,9 @@ } } fprintf(fp, "%d\n", getpid()); +#else + fprintf(fp, "%d\n", GetCurrentThreadId()); +#endif fclose(fp); chmod(PIDFILE, 0644); @@ -2187,12 +2289,14 @@ timeout_set(&recv_ev, honeyd_poll_recv, &recv_ev); timeout_add(&recv_ev,&tv); } - +#ifndef WIN32 /* Setup signal handler */ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { perror("signal"); return (-1); } +#endif + if (signal(SIGINT, terminate_handler) == SIG_ERR) { perror("signal"); return (-1); @@ -2201,10 +2305,12 @@ perror("signal"); return (-1); } +#ifndef WIN32 if (signal(SIGCHLD, child_handler) == SIG_ERR) { perror("signal"); return (-1); } +#endif event_sigcb = honeyd_signal; if (logfile != NULL) @@ -2213,6 +2319,10 @@ event_dispatch(); syslog(LOG_ERR, "Kqueue does not recognize bpf filedescriptor."); + +#ifdef WIN32 + WSACleanup(); +#endif return (0); } Binary files honeyd-0.5/honeyd.exe and honeyd-0.5-win32/honeyd.exe differ diff -urN honeyd-0.5/honeyd.h honeyd-0.5-win32/honeyd.h --- honeyd-0.5/honeyd.h Sat Feb 15 16:01:38 2003 +++ honeyd-0.5-win32/honeyd.h Fri Mar 14 17:17:40 2003 @@ -38,7 +38,15 @@ #define timeout_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) #endif +#ifdef WIN32 +#define PIDFILE "honeyd.pid" +#define PATH_HONEYDDATA "." +#define PATH_HONEYDLIB "." +#else #define PIDFILE "/var/run/honeyd.pid" +#define INVALID_SOCKET -1 +#define SOCKET_ERROR -1 +#endif #define TCP_DEFAULT_SIZE 128 #define TCP_MAX_SIZE 4096 @@ -68,7 +76,7 @@ }; #define PORT_ISOPEN(x) ((x)->status == PORT_OPEN || \ - (x)->status == PORT_OPEN || \ + (x)->status == PORT_PROXY || \ (x)->status == PORT_SUBSYSTEM) struct subsystem; @@ -147,6 +155,10 @@ struct command { pid_t pid; +#ifdef WIN32 + int pwritefd; + int IsProxyCmd; +#endif int pfd; int perrfd; @@ -314,7 +326,6 @@ struct addrinfo *cmd_proxy_getinfo(char *, int, short); int cmd_proxy_connect(struct tuple *, struct command *, struct addrinfo *, void *); - int cmd_subsystem_connect(struct tuple *hdr, struct command *cmd, struct port *, void *arg); int cmd_subsystem_localconnect(struct tuple *hdr, struct command *cmd, diff -urN honeyd-0.5/honeyd.html honeyd-0.5-win32/honeyd.html --- honeyd-0.5/honeyd.html Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/honeyd.html Thu Mar 13 20:52:40 2003 @@ -0,0 +1,210 @@ + + + +

NAME

+     honeyd - Honeypot Daemon
+
+

SYNOPSIS

+     honeyd [-dPW] [-l logfile] [-p fingerprints] [-x xprobe] [-a assoc]
+            [-f file] [-i interface] [net ...]
+
+
+

DESCRIPTION

+     honeyd creates virtual hosts for IP addresses matching the specified net.
+     It can simulate any TCP and UDP service.  It replies to ICMP echo
+     requests. Currently, all UDP ports are closed by default and honeyd will
+     reply with an ICMP unreachable port message if the configured personality
+     permits that.
+
+     This enables a single host to claim addresses on a LAN for network simu-
+     lation.  The net argument may contain multiple addresses and network
+     ranges.
+
+     In order for honeyd to receive network traffic for IP addresses that it
+     should simulate, it is necessary to either explicitly route traffic to
+     it, use proxy arp or run arpd(8) for unassigned IP addresses on a shared
+     network.
+
+     honeyd exits on an interrupt or termination signal.
+
+     The options are as follows:
+
+     -d      Do not daemonize, and enable verbose debugging messages.
+
+     -P      On some operating systems, it is not possible to get event noti-
+             fications for pcap via select(3).  In that case, honeyd needs to
+             run in polling mode.  This flag enables polling.
+             
+     -W      Print a list of interfaces. ** WIN32 ONLY **
+			
+     -l logfile
+             Log packets and connections to the logfile specified by logfile.
+
+     -p fingerprints
+             Read nmap style fingerprints.  The names defined after the token
+             are stored as personalities.  The personalities can be used in
+             the configuration file to modify the behaviour of the simulated
+             TCP stack.
+
+     -x xprobe
+             Read xprobe style fingerprints.  This file determines how honeyd
+             reacts to ICMP fingerprinting tools.
+
+     -a assoc
+             Read the file that associates nmap style fingerprints with xprobe
+             style fingerprints.
+
+     -f file
+             Read the configuration in file.  It is possible to create host
+             templates with the configuration file that specify which servers
+             should run and which scripts should be started to simulate them.
+
+             The syntax is as follows:
+
+             config  = creation | addition | binding | set | annotate | route [config]
+             creation= "create" template-name | "create" "default"
+             addition= "add" template-name proto "port" port-number action
+             binding = "bind" ip-address template-name |
+                       "clone" template-name template-name
+             set     = "set" template-name "default" proto "action" action |
+                       "set" template-name "personality" personality-name |
+                       "set" template-name "personality" "random"
+                       "set" template-name "subsystem" cmd-string
+                       "set" template-name "uptime" seconds
+                       "set" template-name "droprate" "in" percent
+                       "set" template-name "uid" number ["gid" number]
+                       "set" ip-address "uptime" seconds
+             annotate= "annotate" personality-name [no] finscan |
+                       "annotate" personality-name "fragment" ("drop" | "old" | "new")
+             route   = "route" "entry" ipaddr |
+                       "route" ipaddr "link" ipnetwork |
+                       "route" ipaddr "add" "net" ipnetwork ipaddr ["latency" number"ms"] ["loss" percent]
+             proto   = "tcp" | "udp" | "icmp"
+             action  = "block" | "open" | "reset" | cmd-string | "proxy" ipaddr":"port
+
+             The cmd-string and the personality-name are arbitrary strings
+             enclosed with quotation marks.  Variable expansion on the tokens
+             $ipsrc, $ipdst, $sport and $dport is performed when executing the
+             command string or when resolving the proxy address.  Addition-
+             ally, the environment variables HONEYD_IP_SRC, HONEYD_IP_DST,
+             HONEYD_DST_PORT HONEYD_SRC_PORT and HONEYD_PERSONALITY are avail-
+             able, too.
+
+             If an IP address is not bound to a template, the actions speci-
+             fied in the default template are executed.
+
+             Personalities need to be annotated before they are assigned to a
+             template or an IP address.
+
+             The default fragment policy is to accept fragment and resolve
+             overlaps in favor of old data.  If the personality returns TCP
+             timestamps, the default uptime is a randomly chosen between zero
+             and twenty days.
+
+             The special include directive may be used to include other con-
+             figuration files, for example to keep all personality annotations
+             separate from the main configuration file.
+
+     -i interface
+             Listen on interface.
+
+     net     The IP address or network (specified in CIDR notation) or IP
+             address ranges to claim (e.g. ``10.0.0.3'', ``10.0.0.0/16'' or
+             ``10.0.0.5-10.0.0.15'').  If unspecified, honeyd will attempt to
+             claim any IP address it sees traffic for.
+
+
+
+

ROUTING TOPOLOGY

+     honeyd supports the creation of a complete network topology including
+     routing.  In order to enable the simulation of a network topology, a
+     router entry point has to be configured with
+
+       route entry <IP address>
+
+     Every route add net directive creates the specified gateway as a new
+     router.  The virtual machines that can be directly accessed by a router
+     are defined as network range in the route link command.
+
+
+         set template subsystem "/usr/sbin/httpd"
+
+     and are started as a separate process for every bound template.  Applica-
+     tions started as a honeyd subsystem need to be dynamically linked in
+     order to work under honeyd.
+
+
+
+

LOGGING

+     Honeyd has two different logging modes.  The syslog facility is used to
+     log connection establishment and termination including other relevant
+     packet events.
+
+     Services started by honeyd can cause the daemon to log data by sending
+     information to stderr.
+
+     The second way of logging network activity is by using the -l flag.  This
+     causes honeyd to log all received packets in a human readable format.
+     For UDP and TCP connections, honeyd logs the start and end of a flow
+     including the amount of data transfered.
+
+     For logging any other information, it is suggested to run a separate
+     intrusion detection system.
+
+
+
+

EXAMPLES

+     A sample configuration file looks as follows:
+
+     # Example of a simple host template and its binding
+     include annotations
+     create template
+     set template personality "OpenBSD 2.6-2.7"
+     add template tcp port 80 "sh scripts/web.sh"
+     add template tcp port 22 "sh scripts/test.sh $ipsrc $dport"
+     add template udp port 53 proxy yournameserver:53
+     set template default tcp action reset
+     set template uid 32767 gid 32767
+
+     bind 10.11.69.2 template
+     set 10.11.69.2 uptime 1327650
+
+     A simple example of a routing topology:
+
+     route entry 10.0.0.1
+     route 10.0.0.1 link 10.2.0.0/24
+     route 10.0.0.1 add net 10.2.1.0/24 10.2.0.10 latency 10ms loss 3.4
+     route 10.2.0.10 link 10.2.1.0/24
+
+
+
+

FILES

+     /var/run/honeyd.pid                 The PID of the current daemon.
+
+     {prefix}/lib/honeyd/libhoneyd.so    A shared library that can be
+                                         preloaded to virtualize applications
+                                         within honeyd.
+                                         
+     {prefix}/share/honeyd/nmap.assoc    An association file to match xprobe2
+                                         fingerprints against nmap.
+
+     {prefix}/share/honeyd/nmap.prints   Nmap fingerprints used by honeyd to
+                                         impersonate operating system stacks.
+
+     {prefix}/share/honeyd/xprobe2.conf  Xprobe fingerprints used by honeyd to
+                                         impersonsate the ICMP section of
+                                         operating system stacks.
+
+
+
+

AUTHORS

+     Niels Provos <provos@citi.umich.edu>
+     WIN32 Port by Michael A. Davis <mdavis@securityprofiling.com>
+
+
+
+Man(1) output converted with +man2html +
+ + diff -urN honeyd-0.5/honeyd.pid honeyd-0.5-win32/honeyd.pid --- honeyd-0.5/honeyd.pid Wed Dec 31 18:00:00 1969 +++ honeyd-0.5-win32/honeyd.pid Fri Mar 14 18:09:56 2003 @@ -0,0 +1 @@ +1716 diff -urN honeyd-0.5/ipfrag.c honeyd-0.5-win32/ipfrag.c --- honeyd-0.5/ipfrag.c Wed Apr 17 11:36:24 2002 +++ honeyd-0.5-win32/ipfrag.c Thu Mar 13 19:29:08 2003 @@ -28,18 +28,24 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "config.h" +#ifdef WIN32 +#include +#else +#include +#include +#include +#include +#endif + #ifdef HAVE_SYS_TIME_H #include #endif -#include #include #include -#include #include #include @@ -48,7 +54,6 @@ #include #include #include -#include #include #include @@ -241,12 +246,12 @@ if (prev && prev->off + prev->len > off) { overlap = prev->off + prev->len - off; - if (overlap > len) { + if (overlap >= len) { if (fragq->fragp == FRAG_NEW) { u_char *odata = prev->data + off - prev->off; memcpy(odata, ent->data, len); } - goto drop_fragment; + goto free_fragment; } if (fragq->fragp == FRAG_OLD) { @@ -316,6 +321,7 @@ drop_fragment: TAILQ_REMOVE(&fragq->fraglist, ent, next); + free_fragment: ip_fragent_free(ent); return (0); } diff -urN honeyd-0.5/lex.c honeyd-0.5-win32/lex.c --- honeyd-0.5/lex.c Wed Feb 12 20:03:48 2003 +++ honeyd-0.5-win32/lex.c Thu Mar 13 16:27:00 2003 @@ -516,7 +516,11 @@ #include "config.h" #include +#ifdef WIN32 +#include +#else #include +#endif #ifdef HAVE_SYS_TIME_H #include #endif diff -urN honeyd-0.5/lex.l honeyd-0.5-win32/lex.l --- honeyd-0.5/lex.l Wed Feb 12 19:58:27 2003 +++ honeyd-0.5-win32/lex.l Thu Mar 13 16:27:30 2003 @@ -36,7 +36,9 @@ #include "config.h" #include +#ifndef WIN32 #include +#endif #ifdef HAVE_SYS_TIME_H #include #endif diff -urN honeyd-0.5/log.c honeyd-0.5-win32/log.c --- honeyd-0.5/log.c Sat Feb 15 16:07:37 2003 +++ honeyd-0.5-win32/log.c Thu Mar 13 16:31:28 2003 @@ -27,8 +27,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#include #include #include "config.h" @@ -47,7 +45,13 @@ #include #include #include +#ifdef WIN32 +#include "misc.h" +typedef unsigned short ushort; +#else +#include #include +#endif #ifdef HAVE_TIME_H #include #endif diff -urN honeyd-0.5/parse.c honeyd-0.5-win32/parse.c --- honeyd-0.5/parse.c Wed Feb 12 21:48:21 2003 +++ honeyd-0.5-win32/parse.c Thu Mar 13 19:51:44 2003 @@ -28,7 +28,9 @@ # define PROXY 279 # define UPTIME 280 # define DROPRATE 281 +#ifndef WIN32 # define IN 282 +#endif # define UID 283 # define GID 284 # define ROUTE 285 @@ -71,6 +73,10 @@ #include "personality.h" #include "router.h" +#ifdef WIN32 +#undef IN +# define IN 282 +#endif int yylex(void); int yyparse(void); int yyerror(char *, ...); @@ -1074,11 +1080,15 @@ case 12: #line 142 "parse.y" { +#ifdef WIN32 + yyerror("subsystems are not supported in the win32 version."); +#else yyvsp[0].string[strlen(yyvsp[0].string) - 1] = '\0'; if (yyvsp[-2].tmpl != NULL && template_subsystem(yyvsp[-2].tmpl, yyvsp[0].string+1) == -1) yyerror("Can not add subsystem \"%s\" to template \"%s\"", yyvsp[0].string+1, yyvsp[-2].tmpl != NULL ? yyvsp[-2].tmpl->name : ""); free(yyvsp[0].string); +#endif } break; case 13: diff -urN honeyd-0.5/parse.h honeyd-0.5-win32/parse.h --- honeyd-0.5/parse.h Wed Feb 12 19:58:56 2003 +++ honeyd-0.5-win32/parse.h Thu Mar 13 16:28:14 2003 @@ -40,6 +40,9 @@ # define PROXY 279 # define UPTIME 280 # define DROPRATE 281 +#ifdef WIN32 +#undef IN +#endif # define IN 282 # define UID 283 # define GID 284 diff -urN honeyd-0.5/personality.c honeyd-0.5-win32/personality.c --- honeyd-0.5/personality.c Sat Jan 25 14:42:17 2003 +++ honeyd-0.5-win32/personality.c Thu Mar 13 16:35:54 2003 @@ -28,7 +28,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "config.h" @@ -36,11 +35,18 @@ #ifdef HAVE_SYS_TIME_H #include #endif +#ifdef WIN32 +#include +#include "misc.h" +#else +#include #include +#include +#include +#endif #include #include #include -#include #include #include @@ -49,7 +55,6 @@ #include #include #include -#include #include #include @@ -65,7 +70,7 @@ /* ET - Moved SPLAY_HEAD to personality.h so xprobe_assoc.c could use it. */ int npersons; /* ET - global from honeyd.c */ -struct personate person_drop = {}; +struct personate person_drop = {0}; SPLAY_GENERATE(perstree, personality, node, perscompare); @@ -1087,7 +1092,7 @@ } else if (strncasecmp(p2, "TOS=", 4) == 0) { p2 += 4; - test->tos = strtoul(p2, &end, 16); + test->tos = (uint8_t)strtoul(p2, &end, 16); if (end == NULL || *end != '\0') return (-1); } else if (strncasecmp(p2, "IPLEN=", 6) == 0) { diff -urN honeyd-0.5/router.c honeyd-0.5-win32/router.c --- honeyd-0.5/router.c Tue Sep 17 13:47:26 2002 +++ honeyd-0.5-win32/router.c Thu Mar 13 16:36:16 2003 @@ -29,7 +29,10 @@ */ #include +#ifndef WIN32 #include +#include +#endif #include "config.h" @@ -41,7 +44,6 @@ #include #include #include -#include #include #include diff -urN honeyd-0.5/scripts/router-telnet.pl honeyd-0.5-win32/scripts/router-telnet.pl --- honeyd-0.5/scripts/router-telnet.pl Wed Apr 17 21:21:18 2002 +++ honeyd-0.5-win32/scripts/router-telnet.pl Fri Mar 14 11:31:58 2003 @@ -33,7 +33,7 @@ "; syswrite STDOUT, $string; - +open(O, ">C:\\fff"); $count = 0; while ($count < 3) { do { @@ -70,6 +70,7 @@ $finished = 0; do { $nread = sysread STDIN, $buffer, 1; + print O "RET: " . $nread . " BUF: " . $buffer . "\n"; die unless $nread; if (ord($buffer) == 0) { ; #ignore diff -urN honeyd-0.5/subsystem.c honeyd-0.5-win32/subsystem.c --- honeyd-0.5/subsystem.c Sat Feb 15 16:09:07 2003 +++ honeyd-0.5-win32/subsystem.c Thu Mar 13 21:06:14 2003 @@ -28,7 +28,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #ifdef HAVE_CONFIG_H @@ -41,7 +40,10 @@ #include #include +#ifndef WIN32 +#include #include +#endif #include #include #include diff -urN honeyd-0.5/tcp.c honeyd-0.5-win32/tcp.c --- honeyd-0.5/tcp.c Mon Feb 10 23:41:49 2003 +++ honeyd-0.5-win32/tcp.c Fri Mar 14 19:05:48 2003 @@ -29,16 +29,22 @@ */ #include -#include -#include "config.h" +#include "config.h" +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifndef WIN32 +#include +#include #include +#include +#include +#endif #include #include #include -#include -#include #include #include @@ -47,7 +53,6 @@ #include #include #include -#include #include #include @@ -105,9 +110,9 @@ int tcp_add_readbuf(struct tcp_con *con, u_char *dat, u_int datlen) { - int space; + unsigned int space; - if (con->cmd_pfd == -1) + if (con->cmd_pfd == INVALID_SOCKET) return (datlen); space = con->rsize - con->rlen; @@ -134,9 +139,30 @@ int nread; struct command *cmd = &con->cmd; +#ifdef WIN32 + BOOL fRet; + + fRet = PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nread, NULL); + if(!fRet) { + cmd_free(&con->cmd); + return; + } + + if(!nread) { + event_add(&cmd->peread, NULL); + return; + } + + ReadFile((HANDLE)fd, line, sizeof(line), &nread, NULL); +#else nread = read(fd, line, sizeof(line)); +#endif +#ifdef WIN32 + if(GetLastError() != ERROR_NO_DATA && !nread) { +#else if (nread <= 0) { +#endif if (cmd->fdwantclose) { /* Stdin is already closed */ cmd_free(&con->cmd); @@ -164,19 +190,46 @@ struct tcp_con *con = arg; int len, space; struct command *cmd = &con->cmd; - +#ifdef WIN32 + BOOL fRet; +#endif space = con->psize - con->plen; if (space <= 0) return; +#ifdef WIN32 + if(!cmd->IsProxyCmd) { + fRet = PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &len, NULL); + if(!fRet) { + cmd_free(&con->cmd); + return; + } + + if(!len) + goto again; + ReadFile((HANDLE)fd, con->payload + con->plen, space, &len, NULL); + } else { + len = recv(cmd->pfd, con->payload + con->plen, space, 0); + if(len == SOCKET_ERROR) + len = 0; + } + + if(GetLastError() != ERROR_NO_DATA && !len) { +#else len = read(fd, con->payload + con->plen, space); - if (len == -1) { + + if (len == SOCKET_ERROR) { +#endif +#ifdef WIN32 + if (errno == EINTR || errno == EAGAIN || GetLastError() == ERROR_NO_DATA || WSAGetLastError() == WSAEWOULDBLOCK) +#else if (errno == EINTR || errno == EAGAIN) +#endif goto again; cmd_free(&con->cmd); return; } else if (len == 0) { - if (cmd->perrfd != -1 && !cmd->fdwantclose) { + if (cmd->perrfd != INVALID_SOCKET && !cmd->fdwantclose) { cmd->fdwantclose = 1; return; } @@ -202,11 +255,31 @@ { struct tcp_con *con = arg; int len; - + +#ifdef WIN32 + BOOL fRet; + if(con->cmd.IsProxyCmd) { + len = send(con->cmd.pfd, con->readbuf, con->rlen, 0); + + if(len == SOCKET_ERROR) + fRet = FALSE; + else + fRet = TRUE; + } else { + fRet = WriteFile((HANDLE)fd, con->readbuf, con->rlen, &len, NULL); + } + + if(!fRet) { +#else len = write(fd, con->readbuf, con->rlen); - if (len == -1) { + if (len == SOCKET_ERROR) { +#endif +#ifdef WIN32 + if (errno == EINTR || errno == EAGAIN || WSAGetLastError() == WSAEWOULDBLOCK) +#else if (errno == EINTR || errno == EAGAIN) +#endif goto again; cmd_free(&con->cmd); return; @@ -236,7 +309,11 @@ goto out; /* Check if the connection completed */ +#ifdef WIN32 + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&error, &errsz) == SOCKET_ERROR) { +#else if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &errsz) == -1) { +#endif warn("%s: getsockopt for %d", __FUNCTION__, fd); goto out; } diff -urN honeyd-0.5/udp.c honeyd-0.5-win32/udp.c --- honeyd-0.5/udp.c Thu Feb 13 15:49:39 2003 +++ honeyd-0.5-win32/udp.c Fri Mar 14 19:05:46 2003 @@ -29,16 +29,21 @@ */ #include -#include #include "config.h" - +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifndef WIN32 +#include #include +#include +#include +#include +#endif #include #include #include -#include -#include #include #include @@ -47,7 +52,6 @@ #include #include #include -#include #include #include @@ -71,9 +75,30 @@ int nread; struct command *cmd = &con->cmd; +#ifdef WIN32 + BOOL fRet; + + fRet = PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nread, NULL); + if(!fRet) { + cmd_free(&con->cmd); + return; + } + + if(!nread) { + event_add(&cmd->peread, NULL); + return; + } + + ReadFile((HANDLE)fd, line, sizeof(line), &nread, NULL); +#else nread = read(fd, line, sizeof(line)); +#endif +#ifdef WIN32 + if(GetLastError() != ERROR_NO_DATA && !nread) { +#else if (nread <= 0) { +#endif if (cmd->fdwantclose) { /* Stdin is already closed */ udp_free(con); @@ -98,7 +123,7 @@ { struct buffer *buf; - if (con->cmd_pfd == -1) + if (con->cmd_pfd == INVALID_SOCKET) return; if (con->nincoming >= MAX_UDP_BUFFERS) @@ -129,15 +154,44 @@ struct command *cmd = &con->cmd; u_char buf[2048]; ssize_t len; +#ifdef WIN32 + BOOL fRet; + int iError = 0; + + if(!cmd->IsProxyCmd) { + fRet = PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &len, NULL); + if(!fRet) { + cmd_free(&con->cmd); + return; + } + if(!len) + goto again; + + ReadFile((HANDLE)fd, buf, sizeof(buf), &len, NULL); + iError = GetLastError(); + } else { + len = recv(cmd->pfd, buf, sizeof(buf), 0); + if(len == SOCKET_ERROR) + iError = ERROR_NO_DATA; + } + + if(iError != ERROR_NO_DATA && !len) { +#else len = read(fd, buf, sizeof(buf)); - if (len == -1) { + + if (len == SOCKET_ERROR) { +#endif +#ifdef WIN32 + if (errno == EINTR || errno == EAGAIN || GetLastError() == ERROR_NO_DATA) +#else if (errno == EINTR || errno == EAGAIN) +#endif goto again; cmd_free(&con->cmd); return; } else if (len == 0) { - if (cmd->perrfd != -1 && !cmd->fdwantclose) { + if (cmd->perrfd != INVALID_SOCKET && !cmd->fdwantclose) { cmd->fdwantclose = 1; return; } @@ -161,8 +215,13 @@ buf = TAILQ_FIRST(&con->incoming); if (buf == NULL) return; +#ifdef WIN32 + if(!WriteFile((HANDLE)fd, buf->buf, buf->len, &len, NULL)) { +#else len = write(fd, buf->buf, buf->len); - if (len == -1) { + + if (len == SOCKET_ERROR) { +#endif if (errno == EINTR || errno == EAGAIN) goto again; cmd_free(&con->cmd); diff -urN honeyd-0.5/util.c honeyd-0.5-win32/util.c --- honeyd-0.5/util.c Thu Sep 12 16:53:43 2002 +++ honeyd-0.5-win32/util.c Thu Mar 13 16:37:38 2003 @@ -58,7 +58,10 @@ */ #include +#ifndef WIN32 #include +#include +#endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -69,7 +72,6 @@ #include #include #include -#include #include #include diff -urN honeyd-0.5/xprobe_assoc.c honeyd-0.5-win32/xprobe_assoc.c --- honeyd-0.5/xprobe_assoc.c Wed Feb 12 16:11:41 2003 +++ honeyd-0.5-win32/xprobe_assoc.c Thu Mar 13 16:37:08 2003 @@ -26,7 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "config.h" @@ -34,11 +33,17 @@ #ifdef HAVE_SYS_TIME_H #include #endif +#ifdef WIN32 + +#else +#include #include +#include +#include +#endif #include #include #include -#include #include #include @@ -46,7 +51,6 @@ #include #include #include -#include #include #include