From: Harlan Stenn Date: Mon, 20 Mar 2000 07:15:36 +0000 (-0000) Subject: Many files: X-Git-Tag: NTP_4_0_99_J~58 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=da2257f8aa348a7cb452ba1eb16f04cdb524733e;p=thirdparty%2Fntp.git Many files: * ntpd/ntp_resolver.c (findhostaddr): hstrerror isn't always available. * configure.in: Look for hstrerror. * util/ntp_genkeys.c (main): Use snprintf, not sprintf. * ntpd/ntp_crypto.c: Use gethostname, not uname * util/ntp_genkeys.c: Ditto From: Dave Mills bk: 38d5d018dyJBwMhjK6NtXy7SJ_Tr7w --- diff --git a/ChangeLog b/ChangeLog index b56d65a5c6..41e66ac355 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2000-03-20 Harlan Stenn + + * ntpd/ntp_resolver.c (findhostaddr): hstrerror isn't always available. + + * configure.in: Look for hstrerror. + + * util/ntp_genkeys.c (main): Use snprintf, not sprintf. + + * ntpd/ntp_crypto.c: Use gethostname, not uname + * util/ntp_genkeys.c: Ditto + From: Dave Mills + 2000-03-19 Harlan Stenn * ntpd/ntp_proto.c (receive): Rename ntp_res_send() to diff --git a/config.h.in b/config.h.in index 8dad8e80bb..d42bd69f4f 100644 --- a/config.h.in +++ b/config.h.in @@ -492,6 +492,9 @@ /* Define if you have the `getuid' function. */ #undef HAVE_GETUID +/* Define if you have the `hstrerror' function. */ +#undef HAVE_HSTRERROR + /* Define if you have the header file. */ #undef HAVE_IEEEFP_H diff --git a/configure b/configure index 7efdb1fd01..3002d77070 100755 --- a/configure +++ b/configure @@ -5655,7 +5655,7 @@ done ;; esac -for ac_func in K_open kvm_open memcpy memmove memset +for ac_func in hstrerror K_open kvm_open memcpy memmove memset do ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` echo $ac_n "checking for $ac_func... $ac_c" 1>&6 diff --git a/configure.in b/configure.in index 7596d099f7..081408eef5 100644 --- a/configure.in +++ b/configure.in @@ -560,7 +560,7 @@ case "$target" in *) AC_CHECK_FUNCS(getuid) ;; esac -AC_CHECK_FUNCS(K_open kvm_open memcpy memmove memset) +AC_CHECK_FUNCS(hstrerror K_open kvm_open memcpy memmove memset) case "$target" in *-*-sco3.2v5.0.*) # Just stubs. Idiots. diff --git a/ntpd/ntp_crypto.c b/ntpd/ntp_crypto.c index ee3f8a9939..63c3f793e8 100644 --- a/ntpd/ntp_crypto.c +++ b/ntpd/ntp_crypto.c @@ -9,7 +9,6 @@ #include #include #include -#include #include "ntpd.h" #include "ntp_stdlib.h" @@ -894,7 +893,7 @@ void crypto_setup(void) { FILE *str; - struct utsname utsnamebuf; + u_char hostname[MAXFILENAME]; u_char filename[MAXFILENAME]; /* @@ -910,9 +909,9 @@ crypto_setup(void) * host is the DNS name of this machine. */ if (public_key_file == NULL) { - uname(&utsnamebuf); + gethostname(&hostname, MAXFILENAME); snprintf(filename, sizeof filename, "ntpkey_%s", - utsnamebuf.nodename); + hostname); public_key_file = emalloc(strlen(filename) + 1); strcpy(public_key_file, filename); } diff --git a/ntpd/ntp_resolver.c b/ntpd/ntp_resolver.c index 7b201884a3..15466b72bb 100644 --- a/ntpd/ntp_resolver.c +++ b/ntpd/ntp_resolver.c @@ -551,12 +551,36 @@ findhostaddr( #ifdef DEBUG if (debug > 2) { struct in_addr si; + char *hes; +#ifndef HAVE_HSTRERROR + char hnum[20]; + + switch (h_errno) { + case HOST_NOT_FOUND: + hes = "Authoritive Answer Host not found"; + break; + case TRY_AGAIN: + hes = "Non-Authoritative Host not found, or SERVERFAIL"; + break; + case NO_RECOVERY: + hes = "Non recoverable errors, FORMERR, REFUSED, NOTIMP"; + break; + case NO_DATA: + hes = "Valid name, no data record of requested type"; + break; + default: + snprintf(hnum, sizeof hnum, "%d", h_errno); + hes = hnum; + break; + } +#else + hes = hstrerror(h_errno); +#endif - si.s_addr = de->de_peeraddr; + si.s_addr = entry->de_peeraddr; msyslog(LOG_DEBUG, "findhostaddr: Failed resolution on <%s>/%s: %s", - de->de_hostname, inet_ntoa(si), - hstrerror(h_errno)); + entry->de_hostname, inet_ntoa(si), hes); } #endif } diff --git a/util/ntp_genkeys.c b/util/ntp_genkeys.c index 1b025cb119..ca20e7d0c1 100644 --- a/util/ntp_genkeys.c +++ b/util/ntp_genkeys.c @@ -5,7 +5,6 @@ #include #include #include -#include #include "ntpd.h" #include "ntp_stdlib.h" #include "ntp_string.h" @@ -94,8 +93,8 @@ main( u_char encoded_key[MAXKEYLEN]; /* encoded PEM string buffer */ u_int modulus; /* modulus length */ struct timeval tv; /* initialization vector */ - struct utsname utsnamebuf; /* uname argument structure */ - u_char sysname[128]; /* DNS host name */ + u_char hostname[256]; /* DNS host name */ + u_char filename[256]; /* public key file name */ u_char md5key[17]; /* generated MD5 key */ FILE *str; /* file handle */ int rval; /* return value */ @@ -106,7 +105,7 @@ main( * Generate the file "ntp.keys" containing 16 random MD5 keys in * the format expected at daemon run time. */ - uname(&utsnamebuf); + gethostname(&hostname, sizeof hostname); printf("Generating MD5 keys...\n"); str = fopen("ntp.keys", "w"); if (str == NULL) { @@ -116,7 +115,7 @@ main( gettimeofday(&tv, 0); srandom((u_int)tv.tv_sec); fprintf(str, "# MD5/DES key file generated by %s\n# %s", - utsnamebuf.nodename, ctime(&tv.tv_sec)); + hostname, ctime(&tv.tv_sec)); for (i = 1; i <= 16; i++) { for (j = 0; j < 16; j++) { while (1) { @@ -164,7 +163,7 @@ main( len = sizeof(rsaref_private) - sizeof(rsaref_private.bits); modulus = (u_int32)rsaref_private.bits; fprintf(str, "# RSA private key file generated by %s\n# %s", - utsnamebuf.nodename, ctime(&tv.tv_sec)); + hostname, ctime(&tv.tv_sec)); R_EncodePEMBlock(encoded_key, &temp, (u_char *)&rsaref_private.modulus, len); encoded_key[temp] = '\0'; @@ -175,8 +174,8 @@ main( * Generate the file "ntpkey_host" containing the RSA public key * in printable ASCII format. */ - sprintf(sysname, "ntpkey_%s", utsnamebuf.nodename); - str = fopen(sysname, "w"); + snprintf(filename, sizeof filename, "ntpkey_%s", hostname); + str = fopen(filename, "w"); if (str == NULL) { perror("RSA public key file"); return (-1); @@ -184,7 +183,7 @@ main( len = sizeof(rsaref_public) - sizeof(rsaref_public.bits); modulus = (u_int32)rsaref_public.bits; fprintf(str, "# RSA public key file generated by %s\n# %s", - utsnamebuf.nodename, ctime(&tv.tv_sec)); + hostname, ctime(&tv.tv_sec)); R_EncodePEMBlock(encoded_key, &temp, (u_char *)&rsaref_public.modulus, len); encoded_key[temp] = '\0'; @@ -224,7 +223,7 @@ main( } fprintf(str, "# Diffie-Hellman parameter file generated by %s\n# %s", - utsnamebuf.nodename, ctime(&tv.tv_sec)); + hostname, ctime(&tv.tv_sec)); R_EncodePEMBlock(encoded_key, &temp, (u_char *)dh_params.prime, dh_params.primeLen); encoded_key[temp] = '\0';