]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Bug fixes to compile Windows
authorDanny Mayer <mayer@ntp.org>
Thu, 21 Jan 2016 03:52:41 +0000 (03:52 +0000)
committerDanny Mayer <mayer@ntp.org>
Thu, 21 Jan 2016 03:52:41 +0000 (03:52 +0000)
bk: 56a05609p1KiWyK6PFiUSMgb1I8bYA

include/ntp_stdlib.h
include/ntp_worker.h
libntp/authkeys.c
libntp/is_ip_address.c
ntpd/ntp_io.c
ports/winnt/vs2008/libntp/libntp.vcproj
ports/winnt/vs2013/libntp/libntp.vcxproj

index 98ac69eb4697da37c1a6ecd93f1c5288a6209713..5a20a83fa618da5943db893e6f347670a8a7cd5d 100644 (file)
@@ -200,7 +200,7 @@ extern int  authnumfreekeys;
 extern keyid_t cache_keyid;            /* key identifier */
 extern int     cache_type;             /* key type */
 extern u_char *        cache_secret;           /* secret */
-extern u_short cache_secretsize;       /* secret octets */
+extern size_t  cache_secretsize;       /* secret octets */
 extern u_short cache_flags;            /* KEY_ bit flags */
 
 /* getopt.c */
index 7720b8c853700a06908c5dc0a8330e7183d4c23d..bc833795b5efab2b0d967aa1209377b3cd1324a2 100644 (file)
@@ -119,11 +119,11 @@ typedef struct blocking_child_tag {
        int                     resp_write_pipe;        /* child */
        int                     ispipe;
        void *                  resp_read_ctx;          /* child */
-       volatile u_int          resp_ready_seen;        /* signal/scan */
-       volatile u_int          resp_ready_done;        /* consumer/mainloop */
 #else
        sem_ref                 responses_pending;      /* signalling */
 #endif
+       volatile u_int          resp_ready_seen;        /* signal/scan */
+       volatile u_int          resp_ready_done;        /* consumer/mainloop */
        sema_type               sem_table[4];
        thread_type             thr_table[1];
 } blocking_child;
index 36fdd8b7c118ba2bdb63ec3f5b1c73dc8ad585ca..84398ad4f18c0ae924448225d269297d5e4b0f7f 100644 (file)
@@ -30,7 +30,7 @@ struct savekey {
        u_long          lifetime;       /* remaining lifetime */
        keyid_t         keyid;          /* key identifier */
        u_short         type;           /* OpenSSL digest NID */
-       u_short         secretsize;     /* secret octets */
+       size_t          secretsize;     /* secret octets */
        u_short         flags;          /* KEY_ flags that wave */
 };
 
@@ -51,12 +51,12 @@ symkey_alloc *      authallocs;
 #endif /* DEBUG */
 
 static u_short auth_log2(size_t);
-static void    auth_resize_hashtable(void);
-static void    allocsymkey(symkey **, keyid_t, u_short, u_short,
-                           u_long, u_short, u_char *, KeyAccT *);
-static void    freesymkey(symkey *, symkey **);
+static void            auth_resize_hashtable(void);
+static void            allocsymkey(keyid_t,    u_short,
+                                   u_short, u_long, size_t, u_char *, KeyAccT *);
+static void            freesymkey(symkey *, keyid_t);
 #ifdef DEBUG
-static void    free_auth_mem(void);
+static void            free_auth_mem(void);
 #endif
 
 symkey key_listhead;           /* list of all in-use keys */;
@@ -75,10 +75,10 @@ symkey **key_hash;
 
 u_long authkeynotfound;                /* keys not found */
 u_long authkeylookups;         /* calls to lookup keys */
-u_long authnumkeys;            /* number of active keys */
+u_long authnumkeys;                    /* number of active keys */
 u_long authkeyexpired;         /* key lifetime expirations */
 u_long authkeyuncached;                /* cache misses */
-u_long authnokey;              /* calls to encrypt with no key */
+u_long authnokey;                      /* calls to encrypt with no key */
 u_long authencryptions;                /* calls to encrypt */
 u_long authdecryptions;                /* calls to decrypt */
 
@@ -96,8 +96,8 @@ int authnumfreekeys;
  */
 keyid_t        cache_keyid;            /* key identifier */
 u_char *cache_secret;          /* secret */
-u_short        cache_secretsize;       /* secret length */
-int    cache_type;             /* OpenSSL digest NID */
+size_t cache_secretsize;       /* secret length */
+int    cache_type;                             /* OpenSSL digest NID */
 u_short cache_flags;           /* flags that wave */
 KeyAccT *cache_keyacclist;     /* key access list */
 
@@ -139,7 +139,7 @@ free_auth_mem(void)
        symkey_alloc *  next_alloc;
 
        while (NULL != (sk = HEAD_DLIST(key_listhead, llink))) {
-               freesymkey(sk, &key_hash[KEYHASH(sk->keyid)]);
+               freesymkey(sk, sk->keyid);
        }
        free(key_hash);
        key_hash = NULL;
@@ -288,17 +288,20 @@ auth_resize_hashtable(void)
  */
 static void
 allocsymkey(
-       symkey **       bucket,
        keyid_t         id,
        u_short         flags,
        u_short         type,
        u_long          lifetime,
-       u_short         secretsize,
+       size_t          secretsize,
        u_char *        secret,
        KeyAccT *       ka
        )
 {
        symkey *        sk;
+       symkey **       bucket;
+
+       bucket = &key_hash[KEYHASH(id)];
+
 
        if (authnumfreekeys < 1)
                auth_moremem(-1);
@@ -324,10 +327,11 @@ allocsymkey(
 static void
 freesymkey(
        symkey *        sk,
-       symkey **       bucket
+       keyid_t         id
        )
 {
-       symkey *        unlinked;
+symkey **      bucket = &key_hash[KEYHASH(id)];
+symkey *       unlinked;
 
        if (sk->secret != NULL) {
                memset(sk->secret, '\0', sk->secretsize);
@@ -378,12 +382,10 @@ auth_havekey(
                return TRUE;
        }
 
-       for (sk = key_hash[KEYHASH(id)]; sk != NULL; sk = sk->hlink) {
-               if (id == sk->keyid) {
-                       return TRUE;
-               }
+       sk = auth_findkey(id);
+       if (sk != NULL && id == sk->keyid) {
+               return TRUE;
        }
-
        return FALSE;
 }
 
@@ -410,13 +412,11 @@ authhavekey(
         * a key or key type. In this case consider the key missing.
         */
        authkeyuncached++;
-       for (sk = key_hash[KEYHASH(id)]; sk != NULL; sk = sk->hlink) {
-               if (id == sk->keyid) {
-                       if (0 == sk->type) {
-                               authkeynotfound++;
-                               return FALSE;
-                       }
-                       break;
+       sk = auth_findkey(id);
+       if (sk != NULL && id == sk->keyid) {
+               if (sk->type == 0) {
+                       authkeynotfound++;
+                       return FALSE;
                }
        }
 
@@ -456,7 +456,6 @@ authtrust(
        u_long          trust
        )
 {
-       symkey **       bucket;
        symkey *        sk;
        u_long          lifetime;
 
@@ -464,12 +463,9 @@ authtrust(
         * Search bin for key; if it does not exist and is untrusted,
         * forget it.
         */
-       bucket = &key_hash[KEYHASH(id)];
-       for (sk = *bucket; sk != NULL; sk = sk->hlink) {
-               if (id == sk->keyid)
-                       break;
-       }
-       if (!trust && NULL == sk)
+
+       sk = auth_findkey(id);
+       if (!trust && sk == NULL)
                return;
 
        /*
@@ -498,7 +494,7 @@ authtrust(
                }
 
                /* No longer trusted, return it to the free list. */
-               freesymkey(sk, bucket);
+               freesymkey(sk, id);
                return;
        }
 
@@ -511,7 +507,7 @@ authtrust(
        } else {
                lifetime = 0;
        }
-       allocsymkey(bucket, id, KEY_TRUSTED, 0, lifetime, 0, NULL, NULL);
+       allocsymkey(id, KEY_TRUSTED, 0, lifetime, 0, NULL, NULL);
 }
 
 
@@ -520,22 +516,17 @@ authtrust(
  */
 int
 authistrusted(
-       keyid_t         keyno
+       keyid_t         id
        )
 {
        symkey *        sk;
-       symkey **       bucket;
 
-       if (keyno == cache_keyid)
+       if (id == cache_keyid)
                return !!(KEY_TRUSTED & cache_flags);
 
        authkeyuncached++;
-       bucket = &key_hash[KEYHASH(keyno)];
-       for (sk = *bucket; sk != NULL; sk = sk->hlink) {
-               if (keyno == sk->keyid)
-                       break;
-       }
-       if (NULL == sk || !(KEY_TRUSTED & sk->flags)) {
+       sk = auth_findkey(id);
+       if (sk == NULL || !(KEY_TRUSTED & sk->flags)) {
                authkeynotfound++;
                return FALSE;
        }
@@ -553,7 +544,6 @@ authistrusted(
        )
 {
        symkey *        sk;
-       symkey **       bucket;
        KeyAccT *       kal;
        KeyAccT *       k;
 
@@ -561,12 +551,9 @@ authistrusted(
                kal = cache_keyacclist;
        else {
                authkeyuncached++;
-               bucket = &key_hash[KEYHASH(keyno)];
-               for (sk = *bucket; sk != NULL; sk = sk->hlink) {
-                       if (keyno == sk->keyid)
-                               break;
-               }
-               if (NULL == sk || !(KEY_TRUSTED & sk->flags)) {
+
+       sk = auth_findkey(keyno);
+       if (NULL == sk || !(KEY_TRUSTED & sk->flags)) {
                        INSIST(!"authistrustedip: keyid not found/trusted!");
                        return FALSE;
                }
@@ -574,7 +561,7 @@ authistrusted(
        }
 
        if (NULL == kal)
-               return TRUE;
+       return TRUE;
 
        for (k = kal; k; k = k->next) {
                if (SOCK_EQ(&k->addr, sau))
@@ -584,7 +571,6 @@ authistrusted(
        return FALSE;
 }
 
-
 /* Note: There are two locations below where 'strncpy()' is used. While
  * this function is a hazard by itself, it's essential that it is used
  * here. Bug 1243 involved that the secret was filled with NUL bytes
@@ -601,63 +587,58 @@ MD5auth_setkey(
        keyid_t keyno,
        int     keytype,
        const u_char *key,
-       size_t  len,
+       size_t secretsize,
        KeyAccT *ka
        )
 {
        symkey *        sk;
-       symkey **       bucket;
        u_char *        secret;
-       size_t          secretsize;
        
        DEBUG_ENSURE(keytype <= USHRT_MAX);
-       DEBUG_ENSURE(len < 4 * 1024);
+       DEBUG_ENSURE(secretsize < 4 * 1024);
        /*
         * See if we already have the key.  If so just stick in the
         * new value.
         */
-       bucket = &key_hash[KEYHASH(keyno)];
-       for (sk = *bucket; sk != NULL; sk = sk->hlink) {
-               if (keyno == sk->keyid) {
+       sk = auth_findkey(keyno);
+       if (sk != NULL && keyno == sk->keyid) {
                        /* TALOS-CAN-0054: make sure we have a new buffer! */
-                       if (NULL != sk->secret) {
-                               memset(sk->secret, 0, sk->secretsize);
-                               free(sk->secret);
-                       }
-                       sk->secret = emalloc(len);
-                       sk->type = (u_short)keytype;
-                       secretsize = len;
-                       sk->secretsize = (u_short)secretsize;
-                       sk->keyacclist = ka;
+               if (NULL != sk->secret) {
+                       memset(sk->secret, 0, sk->secretsize);
+                       free(sk->secret);
+               }
+               sk->secret = emalloc(secretsize + 1);
+               sk->type = (u_short)keytype;
+               sk->secretsize = secretsize;
+               sk->keyacclist = ka;
+#
 #ifndef DISABLE_BUG1243_FIX
-                       memcpy(sk->secret, key, secretsize);
+               memcpy(sk->secret, key, secretsize);
 #else
                        /* >MUST< use 'strncpy()' here! See above! */
                        strncpy((char *)sk->secret, (const char *)key,
                                secretsize);
 #endif
-                       if (cache_keyid == keyno) {
-                               cache_flags = 0;
-                               cache_keyid = 0;
+               if (cache_keyid == keyno) {
+                       cache_flags = 0;
+                       cache_keyid = 0;
                                cache_keyacclist = NULL;
-                       }
-                       return;
                }
+               return;
        }
 
        /*
         * Need to allocate new structure.  Do it.
         */
-       secretsize = len;
-       secret = emalloc(secretsize);
+       secret = emalloc(secretsize + 1);
 #ifndef DISABLE_BUG1243_FIX
        memcpy(secret, key, secretsize);
 #else
        /* >MUST< use 'strncpy()' here! See above! */
        strncpy((char *)secret, (const char *)key, secretsize);
 #endif
-       allocsymkey(bucket, keyno, 0, (u_short)keytype, 0,
-                   (u_short)secretsize, secret, ka);
+       allocsymkey(keyno, 0, (u_short)keytype, 0,
+                   secretsize, secret, ka);
 #ifdef DEBUG
        if (debug >= 4) {
                size_t  j;
@@ -700,7 +681,7 @@ auth_delkeys(void)
                        sk->secretsize = 0;
                        sk->lifetime = 0;
                } else {
-                       freesymkey(sk, &key_hash[KEYHASH(sk->keyid)]);
+                       freesymkey(sk, sk->keyid);
                }
        ITER_DLIST_END()
 }
@@ -716,7 +697,7 @@ auth_agekeys(void)
 
        ITER_DLIST_BEGIN(key_listhead, sk, llink, symkey)
                if (sk->lifetime > 0 && current_time > sk->lifetime) {
-                       freesymkey(sk, &key_hash[KEYHASH(sk->keyid)]);
+                       freesymkey(sk, sk->keyid);
                        authkeyexpired++;
                }
        ITER_DLIST_END()
index 1f2137645f71c39e9ed0fe43a2e86a6f7da6ee57..d36984ca00b681bd4ec3ea97965ff0a760ed994f 100644 (file)
@@ -7,53 +7,13 @@
 # include <config.h>
 #endif
 
-#if 0
-#include <stdio.h>
-#include <signal.h>
-#ifdef HAVE_FNMATCH_H
-# include <fnmatch.h>
-# if !defined(FNM_CASEFOLD) && defined(FNM_IGNORECASE)
-#  define FNM_CASEFOLD FNM_IGNORECASE
-# endif
-#endif
-#ifdef HAVE_SYS_PARAM_H
-# include <sys/param.h>
-#endif
-#ifdef HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-#endif
-#ifdef HAVE_SYS_SOCKIO_H       /* UXPV: SIOC* #defines (Frank Vance <fvance@waii.com>) */
-# include <sys/sockio.h>
-#endif
-#ifdef HAVE_SYS_UIO_H
-# include <sys/uio.h>
-#endif
-#endif
-
 #include "ntp_assert.h"
 #include "ntp_stdlib.h"
 #include "safecast.h"
 
-#if 0
-#include "ntp_machine.h"
-#include "ntpd.h"
-#include "ntp_io.h"
-#include "iosignal.h"
-#include "ntp_lists.h"
-#include "ntp_refclock.h"
-#include "ntp_worker.h"
-#include "ntp_request.h"
-#include "timevalops.h"
-#include "timespecops.h"
-#include "ntpd-opts.h"
-#endif
-
 /* Don't include ISC's version of IPv6 variables and structures */
 #define ISC_IPV6_H 1
-#include <isc/mem.h>
-#include <isc/interfaceiter.h>
 #include <isc/netaddr.h>
-#include <isc/result.h>
 #include <isc/sockaddr.h>
 
 
index ee52b1a5c38979b27eccd48c19b90ac6f224bbfb..c84a7de3747f7f20ca6dbefb74c440e16235a305 100644 (file)
@@ -3141,7 +3141,8 @@ sendpkt(
 }
 
 
-#if !defined(HAVE_IO_COMPLETION_PORT) && !defined(HAVE_SIGNALED_IO)
+#if !defined(HAVE_IO_COMPLETION_PORT)
+#if !defined(HAVE_SIGNALED_IO)
 /*
  * fdbits - generate ascii representation of fd_set (FAU debug support)
  * HFDF format - highest fd first.
@@ -3789,7 +3790,7 @@ input_handler_scan(
                        lfptoms(&ts_e, 6));
 #endif /* DEBUG_TIMING */
 }
-
+#endif /* !HAVE_IO_COMPLETION_PORT */
 
 /*
  * find an interface suitable for the src address
index 191cdfcf76f9d96405b29dd52b5fc8e5ec86cccb..3dbc7f5e81157a357b664cfda0c131dd9340f1bc 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
        ProjectType="Visual C++"
-       Version="9,00"
+       Version="9.00"
        Name="libntp"
        ProjectGUID="{400FBFCB-462E-40D0-B06B-3B74E3FFFD00}"
        TargetFrameworkVersion="0"
                                RelativePath="..\..\..\..\libntp\iosignal.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\..\..\libntp\is_ip_address.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\..\..\lib\isc\lib.c"
                                >
index 158e9f1f24703a923800e8139ab5bb7d9594540b..e06f1457552bed6d04917450bffec9bfc7da773e 100644 (file)
     <ClCompile Include="..\..\..\..\libntp\humandate.c" />
     <ClCompile Include="..\..\..\..\libntp\icom.c" />
     <ClCompile Include="..\..\..\..\libntp\iosignal.c" />
+    <ClCompile Include="..\..\..\..\libntp\is_ip_address.c" />
     <ClCompile Include="..\..\..\..\libntp\lib_strbuf.c" />
     <ClCompile Include="..\..\..\..\libntp\machines.c" />
     <ClCompile Include="..\..\..\..\libntp\mktime.c" />