From: Dave Hart Date: Mon, 19 Oct 2009 17:23:04 +0000 (+0000) Subject: [Bug 1343] ntpd/ntp_io.c close_fd() does not compile on Solaris 7. X-Git-Tag: NTP_4_2_5P236_RC~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ff2ced558afe1da145f88f083cf2743b7823431;p=thirdparty%2Fntp.git [Bug 1343] ntpd/ntp_io.c close_fd() does not compile on Solaris 7. Also includes similar fix to sntp/crypto.c identified on same machine. bk: 4adca078XA_VEptIuwuTbB4noDVp9g --- diff --git a/ChangeLog b/ChangeLog index 9a62b14a6..d7940447b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* [Bug 1343] ntpd/ntp_io.c close_fd() does not compile on Solaris 7. (4.2.5p235-RC) 2009/10/18 Released by Harlan Stenn * [Bug 1343] lib/isc build breaks on systems without IPv6 headers. (4.2.5p234-RC) 2009/10/16 Released by Harlan Stenn diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 1f439f22a..8f0c220a4 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -416,8 +416,6 @@ move_fd( SOCKET fd ) { - NTP_REQUIRE((int)fd >= 0); - #if !defined(SYS_WINNT) && defined(F_DUPFD) #ifndef FD_CHUNK #define FD_CHUNK 10 @@ -449,6 +447,8 @@ move_fd( static SOCKET socket_boundary = -1; SOCKET newfd; + NTP_REQUIRE((int)fd >= 0); + /* * check whether boundary has be set up * already @@ -488,6 +488,8 @@ move_fd( socket_boundary); #endif } while (socket_boundary > 0); +#else + NTP_REQUIRE((int)fd >= 0); #endif /* !defined(SYS_WINNT) && defined(F_DUPFD) */ return fd; } diff --git a/sntp/crypto.c b/sntp/crypto.c index 9f2096844..d3dcf33ac 100644 --- a/sntp/crypto.c +++ b/sntp/crypto.c @@ -26,36 +26,37 @@ int key_cnt = 0; * authentic) or else 0 (not authentic). */ int -auth_md5 ( - char *pkt_data, - int mac_size, - struct key *cmp_key - ) +auth_md5( + char *pkt_data, + int mac_size, + struct key *cmp_key + ) { register int a; char digest[16]; MD5_CTX ctx; + char *digest_data; - if(cmp_key->type != 'M') + if (cmp_key->type != 'M') return -1; MD5Init(&ctx); - char *digest_data = (char *) emalloc(sizeof(char) * (LEN_PKT_NOMAC + cmp_key->key_len)); + digest_data = emalloc(sizeof(char) * (LEN_PKT_NOMAC + cmp_key->key_len)); - for(a=0; akey_len; a++) + for (a = 0; a < cmp_key->key_len; a++) digest_data[LEN_PKT_NOMAC + a] = cmp_key->key_seq[a]; - MD5Update(&ctx, (unsigned char *)digest_data, LEN_PKT_NOMAC + cmp_key->key_len); - MD5Final((unsigned char *)digest, &ctx); + MD5Update(&ctx, (u_char *)digest_data, LEN_PKT_NOMAC + cmp_key->key_len); + MD5Final((u_char *)digest, &ctx); free(digest_data); - for(a=0; a<16; a++) - if(digest[a] != pkt_data[LEN_PKT_MAC + a]) + for (a = 0; a < 16; a++) + if (digest[a] != pkt_data[LEN_PKT_MAC + a]) return 0; return 1; @@ -66,20 +67,19 @@ auth_md5 ( * number of keys it read */ int -auth_init ( - const char *keyfile, - struct key **keys - ) +auth_init( + const char *keyfile, + struct key **keys + ) { FILE *keyf = fopen(keyfile, "r"); struct key *prev = NULL; - register int a, line_limit; int scan_cnt, line_cnt = 0; char kbuf[96]; - if(keyf == NULL) { - if(ENABLED_OPT(NORMALVERBOSE)) + if (keyf == NULL) { + if (ENABLED_OPT(NORMALVERBOSE)) printf("sntp auth_init: Couldn't open key file %s for reading!\n", keyfile); return -1; @@ -87,29 +87,28 @@ auth_init ( line_cnt = 0; - if(feof(keyf)) { - if(ENABLED_OPT(NORMALVERBOSE)) + if (feof(keyf)) { + if (ENABLED_OPT(NORMALVERBOSE)) printf("sntp auth_init: Key file %s is empty!\n", keyfile); fclose(keyf); return -1; } - - while(!feof(keyf)) { - struct key *act = (struct key *) emalloc(sizeof(struct key)); + while (!feof(keyf)) { + struct key *act = emalloc(sizeof(struct key)); line_limit = 0; fgets(kbuf, sizeof(kbuf), keyf); - for(a=0; akey_id, &act->type, act->key_seq)) == 3) { + if ((scan_cnt = sscanf(kbuf, "%i %c %16s", &act->key_id, &act->type, act->key_seq)) == 3) { act->key_len = strlen(act->key_seq); act->next = NULL; @@ -132,8 +131,7 @@ auth_init ( #ifdef DEBUG printf("sntp auth_init: key_id %i type %c with key %s\n", act->key_id, act->type, act->key_seq); #endif - } - else { + } else { #ifdef DEBUG printf("sntp auth_init: scanf read %i items, doesn't look good, skipping line %i.\n", scan_cnt, line_cnt); #endif @@ -150,11 +148,14 @@ auth_init ( STDLINE printf("sntp auth_init: Read %i keys from file %s:\n", line_cnt, keyfile); - struct key *kptr = *keys; - for(a=0; akey_id, - kptr->type, kptr->key_seq, kptr->key_len); - kptr = kptr->next; + { + struct key *kptr = *keys; + + for (a = 0; a < key_cnt; a++) { + printf("key_id %i type %c with key %s (key length: %i)\n", + kptr->key_id, kptr->type, kptr->key_seq, kptr->key_len); + kptr = kptr->next; + } } STDLINE #endif @@ -169,19 +170,19 @@ auth_init ( * address of the key. If no matching key is found the pointer is not touched. */ void -get_key ( - int key_id, - struct key **d_key - ) +get_key( + int key_id, + struct key **d_key + ) { register int a; struct key *itr_key = key_ptr; - if(key_cnt == 0) + if (key_cnt == 0) return; - for(a=0; akey_id == key_id) { + for (a = 0; a < key_cnt && itr_key != NULL; a++) { + if (itr_key->key_id == key_id) { *d_key = itr_key; return; }