summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2003-11-06 19:57:16 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2003-11-06 19:57:16 +0000
commita6bc25dcac9e81aafa0761e9ef4aaed2291abc89 (patch)
treebf9d458563efd32687cedb1b5e03e51c1e8f006e
parent942db004726ceea6bfa2eb6c71b9df7f609a65d2 (diff)
downloadgnutls-a6bc25dcac9e81aafa0761e9ef4aaed2291abc89.tar.gz
some changes to compile in mingw32.
-rw-r--r--configure.in11
-rw-r--r--lib/gnutls_buffers.c4
-rw-r--r--libextra/auth_srp_passwd.c10
-rw-r--r--libextra/gnutls_openpgp.c5
-rw-r--r--libgcrypt.m42
-rw-r--r--src/Makefile.am4
-rw-r--r--src/certtool.c4
-rw-r--r--src/cli-gaa.c4
-rw-r--r--src/cli.c44
-rw-r--r--src/crypt.c30
-rw-r--r--src/serv.c46
-rw-r--r--src/tests.c16
-rw-r--r--src/tests.h2
-rw-r--r--src/tls_test-gaa.c4
-rw-r--r--src/tls_test.c44
15 files changed, 177 insertions, 53 deletions
diff --git a/configure.in b/configure.in
index 9f8405c265..8ef47d2d36 100644
--- a/configure.in
+++ b/configure.in
@@ -49,6 +49,15 @@ AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)
+case "${target}" in
+ *-*-mingw32*)
+ SERV_LIBS="$SERV_LIBS -lwsock32"
+ ;;
+ *)
+ ;;
+esac
+
+
opt_dmalloc_mode=no
AC_MSG_CHECKING([whether in dmalloc mode])
AC_ARG_ENABLE(dmalloc-mode,
@@ -160,7 +169,7 @@ AC_HEADER_TIME
AC_CHECK_HEADERS(unistd.h strings.h stddef.h alloca.h)
AC_CHECK_HEADERS(sys/stat.h sys/types.h sys/socket.h)
AC_CHECK_HEADERS(errno.h sys/time.h time.h)
-AC_CHECK_FUNCS(memmove strnstr mmap gmtime_r,,)
+AC_CHECK_FUNCS(memmove strnstr mmap gmtime_r inet_ntop,,)
AC_FUNC_ALLOCA
diff --git a/lib/gnutls_buffers.c b/lib/gnutls_buffers.c
index 46b901ba13..6b1b5570fa 100644
--- a/lib/gnutls_buffers.c
+++ b/lib/gnutls_buffers.c
@@ -54,6 +54,10 @@
# include <errno.h>
#endif
+#ifdef _WIN32
+# include <winsock2.h>
+#endif
+
#ifndef EAGAIN
# define EAGAIN EWOULDBLOCK
#endif
diff --git a/libextra/auth_srp_passwd.c b/libextra/auth_srp_passwd.c
index 77a31aeed4..67cdaf1732 100644
--- a/libextra/auth_srp_passwd.c
+++ b/libextra/auth_srp_passwd.c
@@ -49,7 +49,7 @@ opaque *verifier;
size_t verifier_size;
int indx;
- p = rindex( str, ':'); /* we have index */
+ p = strrchr( str, ':'); /* we have index */
if (p==NULL) {
gnutls_assert();
return GNUTLS_E_SRP_PWD_PARSING_ERROR;
@@ -66,7 +66,7 @@ int indx;
}
/* now go for salt */
- p = rindex( str, ':'); /* we have salt */
+ p = strrchr( str, ':'); /* we have salt */
if (p==NULL) {
gnutls_assert();
return GNUTLS_E_SRP_PWD_PARSING_ERROR;
@@ -85,7 +85,7 @@ int indx;
}
/* now go for verifier */
- p = rindex( str, ':'); /* we have verifier */
+ p = strrchr( str, ':'); /* we have verifier */
if (p==NULL) {
_gnutls_free_datum(&entry->salt);
return GNUTLS_E_SRP_PWD_PARSING_ERROR;
@@ -131,7 +131,7 @@ int len;
opaque * tmp;
int ret;
- p = rindex( str, ':'); /* we have g */
+ p = strrchr( str, ':'); /* we have g */
if (p==NULL) {
gnutls_assert();
return GNUTLS_E_SRP_PWD_PARSING_ERROR;
@@ -154,7 +154,7 @@ int ret;
entry->g.size = ret;
/* now go for n - modulo */
- p = rindex( str, ':'); /* we have n */
+ p = strrchr( str, ':'); /* we have n */
if (p==NULL) {
_gnutls_free_datum( &entry->g);
gnutls_assert();
diff --git a/libextra/gnutls_openpgp.c b/libextra/gnutls_openpgp.c
index 61b47a43ae..c1e9ec5025 100644
--- a/libextra/gnutls_openpgp.c
+++ b/libextra/gnutls_openpgp.c
@@ -36,11 +36,6 @@
#include <opencdk.h>
#include <time.h>
#include <sys/stat.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <assert.h>
#define OPENPGP_NAME_SIZE 256
diff --git a/libgcrypt.m4 b/libgcrypt.m4
index b57b5b33c4..fa1c60d723 100644
--- a/libgcrypt.m4
+++ b/libgcrypt.m4
@@ -60,7 +60,7 @@ AC_DEFUN(AM_PATH_LIBGCRYPT,
fi
fi
fi
- if test $ok = yes; then
+ if test x$ok = xyes; then
LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --cflags`
LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --libs`
AC_MSG_RESULT(yes)
diff --git a/src/Makefile.am b/src/Makefile.am
index b8d2710e28..a964dc0d64 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,9 +13,9 @@ gnutls_serv_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la $(LIBGCRY
gnutls_srpcrypt_SOURCES = crypt-gaa.c crypt.c
gnutls_srpcrypt_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la $(LIBGCRYPT_LIBS) $(LIBOPENCDK_LIBS)
gnutls_cli_SOURCES = cli-gaa.c cli.c common.c
-gnutls_cli_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la $(LIBGCRYPT_LIBS) $(LIBOPENCDK_LIBS)
+gnutls_cli_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la $(LIBGCRYPT_LIBS) $(LIBOPENCDK_LIBS) $(SERV_LIBS)
gnutls_cli_debug_SOURCES = tls_test-gaa.c tls_test.c tests.c common.c
-gnutls_cli_debug_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la $(LIBGCRYPT_LIBS) $(LIBOPENCDK_LIBS)
+gnutls_cli_debug_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la $(LIBGCRYPT_LIBS) $(LIBOPENCDK_LIBS) $(SERV_LIBS)
noinst_PROGRAMS = retcodes
diff --git a/src/certtool.c b/src/certtool.c
index d2844f3926..4de05c0e1f 100644
--- a/src/certtool.c
+++ b/src/certtool.c
@@ -116,6 +116,10 @@ char input[128];
return atoi(input);
}
+#ifdef _WIN32
+# define getpass read_str
+#endif
+
static const char* read_str( const char* input_str)
{
static char input[128];
diff --git a/src/cli-gaa.c b/src/cli-gaa.c
index 6ace4e17d7..963d27496d 100644
--- a/src/cli-gaa.c
+++ b/src/cli-gaa.c
@@ -477,7 +477,7 @@ int gaa_getint(char *arg)
{
int tmp;
char a;
- if(sscanf(arg, "%d%c", &tmp, &a) != 1)
+ if(sscanf(arg, "%d%c", &tmp, &a) < 1)
{
printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
GAAERROR(-1);
@@ -503,7 +503,7 @@ float gaa_getfloat(char *arg)
{
float tmp;
char a;
- if(sscanf(arg, "%f%c", &tmp, &a) != 1)
+ if(sscanf(arg, "%f%c", &tmp, &a) < 1)
{
printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
GAAERROR(-1);
diff --git a/src/cli.c b/src/cli.c
index 1c266b9a79..5101c61503 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -24,17 +24,27 @@
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+
+#ifdef _WIN32
+# include <winsock.h>
+# include <io.h>
+# include <winbase.h>
+# define socklen_t int
+# define close closesocket
+#else
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# include <unistd.h>
+# include <netdb.h>
+# include <signal.h>
+#endif
+
#include <string.h>
-#include <unistd.h>
#include <gnutls/gnutls.h>
#include <gnutls/extra.h>
#include <gnutls/x509.h>
#include <sys/time.h>
-#include <signal.h>
-#include <netdb.h>
#include "common.h"
#include "cli-gaa.h"
@@ -264,6 +274,10 @@ int main(int argc, char **argv)
int user_term = 0;
struct hostent *server_host;
socket_st hd;
+#ifdef _WIN32
+ WORD wVersionRequested;
+ WSADATA wsaData;
+#endif
gaa_parser(argc, argv);
if (hostname == NULL) {
@@ -271,7 +285,16 @@ int main(int argc, char **argv)
exit(1);
}
+#ifdef _WIN32
+ wVersionRequested = MAKEWORD(1, 1);
+ if (WSAStartup(wVersionRequested, &wsaData) != 0) {
+ perror("WSA_STARTUP_ERROR");
+ }
+#endif
+
+#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
+#endif
init_global_tls_stuff();
@@ -293,12 +316,17 @@ int main(int argc, char **argv)
sa.sin_addr.s_addr = *((unsigned int *) server_host->h_addr);
+#ifdef HAVE_INET_NTOP
if (inet_ntop(AF_INET, &sa.sin_addr, buffer, MAX_BUF) == NULL) {
perror("inet_ntop()");
return(1);
}
-
fprintf(stderr, "Connecting to '%s:%d'...\n", buffer, port);
+#else /* use inet_ntoa */
+ fprintf(stderr, "Connecting to '%s:%d'...\n", inet_ntoa( ((struct sockaddr_in*)&sa)->sin_addr),
+ port);
+#endif
+
err = connect(sd, (SA *) & sa, sizeof(sa));
ERR(err, "connect");
@@ -377,7 +405,9 @@ int main(int argc, char **argv)
printf("\n- Simple Client Mode:\n\n");
+#ifndef _WIN32
signal (SIGALRM, &starttls_alarm);
+#endif
/* do not buffer */
setbuf(stdin, NULL);
diff --git a/src/crypt.c b/src/crypt.c
index 6e8283f6c3..4a017ca125 100644
--- a/src/crypt.c
+++ b/src/crypt.c
@@ -40,11 +40,14 @@ int main (int argc, char **argv)
#include <gnutls/gnutls.h>
#include <gnutls/extra.h>
#include <gcrypt.h> /* for randomize */
-#include <pwd.h>
+
#include <sys/types.h>
#include <sys/stat.h>
-#include <unistd.h>
+#ifndef _WIN32
+# include <pwd.h>
+# include <unistd.h>
+#endif
#define _MAX(x,y) (x>y?x:y)
@@ -229,7 +232,7 @@ char *pos;
/* copy salt, and null terminate after the ':' */
strcpy( _salt, salt);
- pos = index(_salt, ':');
+ pos = strchr(_salt, ':');
if (pos!=NULL) *pos = 0;
/* convert salt to binary. */
@@ -302,7 +305,7 @@ char *p;
}
/* accepts password file */
-static int find_index(char* username, char* file) {
+static int find_strchr(char* username, char* file) {
FILE * fd;
char *pos;
char line[5*1024];
@@ -323,7 +326,7 @@ unsigned int i;
}
if (strncmp(username, line, _MAX(i,strlen(username)) ) == 0) {
/* find the index */
- pos = rindex(line, ':');
+ pos = strrchr(line, ':');
pos++;
fclose(fd);
return atoi(pos);
@@ -346,7 +349,7 @@ int verify_passwd(char *conffile, char *tpasswd, char *username, char *passwd)
int iindex;
char *p, *pos;
- iindex = find_index( username, tpasswd);
+ iindex = find_strchr( username, tpasswd);
if (iindex==-1) {
fprintf(stderr, "Cannot find '%s' in %s\n", username, tpasswd);
return -1;
@@ -393,7 +396,7 @@ int verify_passwd(char *conffile, char *tpasswd, char *username, char *passwd)
if (strncmp(username, line, _MAX(i,strlen(username)) ) == 0) {
char* verifier_pos, *salt_pos;
- pos = index(line, ':');
+ pos = strchr(line, ':');
fclose(fd);
if (pos==NULL) {
fprintf(stderr, "Cannot parse conf file '%s'\n", conffile);
@@ -403,7 +406,7 @@ int verify_passwd(char *conffile, char *tpasswd, char *username, char *passwd)
verifier_pos = pos;
/* Move to the salt */
- pos = index(pos, ':');
+ pos = strchr(pos, ':');
if (pos==NULL) {
fprintf(stderr, "Cannot parse conf file '%s'\n", conffile);
return -1;
@@ -459,6 +462,7 @@ int main(int argc, char **argv)
info.passwd_conf = KPASSWD_CONF;
if (info.username == NULL) {
+#ifndef _WIN32
pwd = getpwuid(getuid());
if (pwd == NULL) {
@@ -467,6 +471,10 @@ int main(int argc, char **argv)
}
info.username = pwd->pw_name;
+#else
+ fprintf(stderr, "Please specify a user\n");
+ return -1;
+#endif
}
salt = 16;
@@ -614,7 +622,7 @@ int crypt_int(char *username, char *passwd, int salt_size,
p = fgets( line, sizeof(line)-1, fd2);
if (p==NULL) break;
- pp = index( line, ':');
+ pp = strchr( line, ':');
if (pp==NULL) continue;
if ( strncmp( p, username, _MAX(strlen(username), (unsigned int)(pp-p)) ) == 0 ) {
@@ -654,7 +662,7 @@ static int read_conf_values(gnutls_datum * g, gnutls_datum * n, char *str)
index = atoi(str);
- p = rindex(str, ':'); /* we have g */
+ p = strrchr(str, ':'); /* we have g */
if (p == NULL) {
return -1;
}
@@ -676,7 +684,7 @@ static int read_conf_values(gnutls_datum * g, gnutls_datum * n, char *str)
}
/* now go for n - modulo */
- p = rindex(str, ':'); /* we have n */
+ p = strrchr(str, ':'); /* we have n */
if (p == NULL) {
return -1;
}
diff --git a/src/serv.c b/src/serv.c
index 510dfd185a..14df1db4dd 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -27,15 +27,25 @@
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+
+#ifdef _WIN32
+# include <winsock.h>
+# include <io.h>
+# include <winbase.h>
+# define socklen_t int
+# define close closesocket
+#else
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# include <unistd.h>
+# include <signal.h>
+#endif
+
#include <string.h>
-#include <unistd.h>
#include <gnutls/gnutls.h>
#include <gnutls/extra.h>
#include "common.h"
-#include <signal.h>
#include "serv-gaa.h"
#include <sys/time.h>
#include <fcntl.h>
@@ -546,12 +556,23 @@ int main(int argc, char **argv)
char name[256];
int accept_fd;
struct sockaddr_in client_address;
+#ifdef _WIN32
+ WORD wVersionRequested;
+ WSADATA wsaData;
+#endif
+#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, SIG_IGN);
signal(SIGTERM, terminate);
if (signal(SIGINT, terminate) == SIG_IGN)
signal(SIGINT, SIG_IGN); /* e.g. background process */
+#else
+ wVersionRequested = MAKEWORD(1, 1);
+ if (WSAStartup(wVersionRequested, &wsaData) != 0) {
+ perror("WSA_STARTUP_ERROR");
+ }
+#endif
gaa_parser(argc, argv);
@@ -706,11 +727,13 @@ int main(int argc, char **argv)
/* flag which connections we are reading or writing to within the fd sets */
lloopstart(listener_list, j) {
+#ifndef _WIN32
val = fcntl(j->fd, F_GETFL, 0);
if ( (val == -1) || (fcntl(j->fd, F_SETFL, val | O_NONBLOCK) < 0) ) {
perror("fcntl()");
exit(1);
}
+#endif
if (j->http_state == HTTP_STATE_REQUEST) {
FD_SET(j->fd, &rd);
@@ -802,10 +825,16 @@ int main(int argc, char **argv)
printf("*** This is a resumed session\n");
if (quiet == 0) {
+#ifdef HAVE_INET_NTOP
printf("\n* connection from %s, port %d\n",
inet_ntop(AF_INET, &client_address.sin_addr,
topbuf, sizeof(topbuf)),
ntohs(client_address.sin_port));
+#else
+ printf("\n* connection from %s, port %d\n",
+ inet_ntoa(((struct sockaddr_in*)&client_address)->sin_addr),
+ ntohs(client_address.sin_port));
+#endif
print_info(j->tls_session, NULL);
}
j->handshake_ok = 1;
@@ -876,10 +905,17 @@ int main(int argc, char **argv)
&& quiet == 0)
printf("*** This is a resumed session\n");
if (quiet == 0) {
+#ifdef HAVE_INET_NTOP
printf("- connection from %s, port %d\n",
inet_ntop(AF_INET, &client_address.sin_addr,
topbuf, sizeof(topbuf)),
ntohs(client_address.sin_port));
+#else
+ printf("\n* connection from %s, port %d\n",
+ inet_ntoa(((struct sockaddr_in*)&client_address)->sin_addr),
+ ntohs(client_address.sin_port));
+#endif
+
print_info(j->tls_session, NULL);
}
j->handshake_ok = 1;
diff --git a/src/tests.c b/src/tests.c
index 7d5669f178..792fdd75a2 100644
--- a/src/tests.c
+++ b/src/tests.c
@@ -23,8 +23,13 @@
#include <gnutls/extra.h>
#include <gnutls/x509.h>
#include <tests.h>
-#include <unistd.h>
-#include <signal.h>
+
+#ifndef _WIN32
+# include <unistd.h>
+# include <signal.h>
+#endif
+
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <common.h>
@@ -254,7 +259,10 @@ int test_bye( gnutls_session session) {
int ret;
char data[20];
int old;
+
+#ifndef _WIN32
signal( SIGALRM, got_alarm);
+#endif
ADD_ALL_CIPHERS(session);
ADD_ALL_COMP(session);
@@ -270,14 +278,18 @@ int old;
ret = gnutls_bye( session, GNUTLS_SHUT_WR);
if (ret<0) return FAILED;
+#ifndef _WIN32
old = siginterrupt( SIGALRM, 1);
alarm(6);
+#endif
do {
ret = gnutls_record_recv( session, data, sizeof(data));
} while( ret > 0);
+#ifndef _WIN32
siginterrupt( SIGALRM, old);
+#endif
if (ret==0) return SUCCEED;
if (alrm == 0) return UNSURE;
diff --git a/src/tests.h b/src/tests.h
index b30b2cb5ed..df430b7412 100644
--- a/src/tests.h
+++ b/src/tests.h
@@ -1,5 +1,3 @@
-#include <stdio.h>
-
#define SUCCEED 1
#define FAILED 0
#define UNSURE -1
diff --git a/src/tls_test-gaa.c b/src/tls_test-gaa.c
index 297de3aab4..f6a1109bea 100644
--- a/src/tls_test-gaa.c
+++ b/src/tls_test-gaa.c
@@ -353,7 +353,7 @@ int gaa_getint(char *arg)
{
int tmp;
char a;
- if(sscanf(arg, "%d%c", &tmp, &a) != 1)
+ if(sscanf(arg, "%d%c", &tmp, &a) < 1)
{
printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
GAAERROR(-1);
@@ -379,7 +379,7 @@ float gaa_getfloat(char *arg)
{
float tmp;
char a;
- if(sscanf(arg, "%f%c", &tmp, &a) != 1)
+ if(sscanf(arg, "%f%c", &tmp, &a) < 1)
{
printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
GAAERROR(-1);
diff --git a/src/tls_test.c b/src/tls_test.c
index 7f3d558f3f..f287923a86 100644
--- a/src/tls_test.c
+++ b/src/tls_test.c
@@ -23,16 +23,26 @@
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+
+#ifdef _WIN32
+# include <winsock.h>
+# include <io.h>
+# include <winbase.h>
+# define socklen_t int
+# define close closesocket
+#else
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# include <unistd.h>
+# include <signal.h>
+# include <netdb.h>
+#endif
+
#include <string.h>
-#include <unistd.h>
#include <gnutls/gnutls.h>
#include <gnutls/extra.h>
#include <sys/time.h>
-#include <signal.h>
-#include <netdb.h>
#include <tests.h>
#include <tls_test-gaa.h>
@@ -124,6 +134,13 @@ static const TLS_TEST tls_tests[] = {
};
static int tt = 0;
+char* ip;
+
+#ifdef HAVE_INET_NTOP
+# define IP inet_ntop(AF_INET, &sa.sin_addr, buffer, MAX_BUF)
+#else
+# define IP inet_ntoa( ((struct sockaddr_in*)&sa)->sin_addr)
+#endif
#define CONNECT() \
sd = socket(AF_INET, SOCK_STREAM, 0); \
@@ -132,8 +149,8 @@ static int tt = 0;
sa.sin_family = AF_INET; \
sa.sin_port = htons(port); \
sa.sin_addr.s_addr = *((unsigned int *) server_host->h_addr); \
- inet_ntop(AF_INET, &sa.sin_addr, buffer, MAX_BUF); \
- if (tt++ == 0) printf("Connecting to '%s:%d'...\n", buffer, port); \
+ ip = IP; \
+ if (tt++ == 0) printf("Connecting to '%s:%d'...\n", ip, port); \
err = connect(sd, (SA *) & sa, sizeof(sa)); \
ERR(err, "connect")
@@ -149,10 +166,21 @@ int main(int argc, char **argv)
struct hostent *server_host;
int ssl3_ok = 0;
int tls1_ok = 0;
+#ifdef _WIN32
+ WORD wVersionRequested;
+ WSADATA wsaData;
+#endif
gaa_parser(argc, argv);
+#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
+#else
+ wVersionRequested = MAKEWORD(1, 1);
+ if (WSAStartup(wVersionRequested, &wsaData) != 0) {
+ perror("WSA_STARTUP_ERROR");
+ }
+#endif
if (gnutls_global_init() < 0) {
fprintf(stderr, "global state initialization error\n");