]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
some changes to compile in mingw32.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 6 Nov 2003 19:57:16 +0000 (19:57 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 6 Nov 2003 19:57:16 +0000 (19:57 +0000)
15 files changed:
configure.in
lib/gnutls_buffers.c
libextra/auth_srp_passwd.c
libextra/gnutls_openpgp.c
libgcrypt.m4
src/Makefile.am
src/certtool.c
src/cli-gaa.c
src/cli.c
src/crypt.c
src/serv.c
src/tests.c
src/tests.h
src/tls_test-gaa.c
src/tls_test.c

index 9f8405c26560843b520244fd13b40d66c1d6f7b5..8ef47d2d366ba8f729869869084023bf8ef40d47 100644 (file)
@@ -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
 
 
index 46b901ba137a76aea99ff0dfb67334495c677642..6b1b5570fabe1ee38ae634826e5ea20f6fc56fa7 100644 (file)
 # include <errno.h>
 #endif
 
+#ifdef _WIN32
+# include <winsock2.h>
+#endif
+
 #ifndef EAGAIN
 # define EAGAIN EWOULDBLOCK
 #endif
index 77a31aeed41f4408f4194638338bc1a952d1d776..67cdaf17323be25f71687beca6cdae34db9fafc6 100644 (file)
@@ -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();
index 61b47a43ae432c4634fee22fd586eca814ce5f9b..c1e9ec502599bf259a037262c41e23585eb6d094 100644 (file)
 #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
 
index b57b5b33c4d692c98a45eab0765d82023610ec2b..fa1c60d72376157c076225cdceded6eeedb42ea8 100644 (file)
@@ -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)
index b8d2710e28a24f3406645520481c1f1d4dc2dd78..a964dc0d64a4c2f2c48822353018b99267381a6b 100644 (file)
@@ -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
index d2844f39268d39e988bd48d124793cf89e8821b3..4de05c0e1fd34f70f239f24e7a3afa365110e910 100644 (file)
@@ -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];
index 6ace4e17d79c746210f35aaf7c5033725d202695..963d27496d4d150c2d3872615e4359e8671df5ce 100644 (file)
@@ -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);
index 1c266b9a798fb3d356c008de23aa50ec9bb4b4b8..5101c61503320d0a90bf144dfd2d4aee99610f0e 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
 #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);
index 6e8283f6c3c31dd3e0a82cf69b8d894f85ebb00c..4a017ca1258740665a404660efbca535d5654126 100644 (file)
@@ -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;
        }
index 510dfd185a41520127f81322f9eac10811585329..14df1db4ddb14d0c7403d137f6edc5093f01bee2 100644 (file)
 #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;
index 7d5669f17897783771877c036b91350198ea9ddd..792fdd75a2ee33c019be1477df8038912d609ad4 100644 (file)
 #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;
index b30b2cb5eda21842c55fa1c815f28110af85e3e2..df430b7412c41392f1366198af6c3ad5cdd1f5a3 100644 (file)
@@ -1,5 +1,3 @@
-#include <stdio.h>
-
 #define SUCCEED 1
 #define FAILED 0
 #define UNSURE -1
index 297de3aab4668f247145c49c806d34689a2d0783..f6a1109bea0463e609c2ef65fe272f5698ebb6a3 100644 (file)
@@ -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);
index 7f3d558f3f9b3d2b1307c7be3a5e569c31067a3f..f287923a866a01be364c642e3fbf0422801a0959 100644 (file)
 #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");