masqmail

changeset 200:116b0269c934

reworked resolvtest; let it build; refactored in lookup.c the resolvtest helper and code test tool was available in the code but did not get built I moved it to resolvtest.c and included it into the build process the define RESOLV_TEST was removed
author meillo@marmaro.de
date Fri, 16 Jul 2010 12:53:07 +0200
parents a8855df82650
children 138e66e1a61f
files src/Makefile.am src/Makefile.in src/lookup.c src/lookup.h src/resolvtest.c
diffstat 5 files changed, 131 insertions(+), 60 deletions(-) [+]
line diff
     1.1 --- a/src/Makefile.am	Fri Jul 16 12:39:14 2010 +0200
     1.2 +++ b/src/Makefile.am	Fri Jul 16 12:53:07 2010 +0200
     1.3 @@ -4,7 +4,7 @@
     1.4  
     1.5  sbin_PROGRAMS=masqmail
     1.6  bin_PROGRAMS=mservdetect
     1.7 -noinst_PROGRAMS=smtpsend readtest
     1.8 +noinst_PROGRAMS=smtpsend readtest resolvtest
     1.9  
    1.10  masqmail_SOURCES=\
    1.11  	dotlock.h\
    1.12 @@ -76,7 +76,12 @@
    1.13  	readsock.h\
    1.14  	readtest.c
    1.15  
    1.16 +resolvtest_SOURCES=\
    1.17 +	resolvtest.c\
    1.18 +	lookup.c
    1.19 +
    1.20  masqmail_LDADD=@RESOLV_LIBS@ @GLIB_LIBS@ @LOCKFILE_LIBS@ @MD5_LIBS@ @BASE64_LIBS@ @IDENT_LIBS@
    1.21  smtpsend_LDADD=@RESOLV_LIBS@ @GLIB_LIBS@ @MD5_LIBS@ @BASE64_LIBS@
    1.22  mservdetect_LDADD=@GLIB_LIBS@
    1.23  readtest_LDADD=@GLIB_LIBS@
    1.24 +resolvtest_LDADD=@RESOLV_LIBS@ @GLIB_LIBS@ @IDENT_LIBS@
     2.1 --- a/src/Makefile.in	Fri Jul 16 12:39:14 2010 +0200
     2.2 +++ b/src/Makefile.in	Fri Jul 16 12:53:07 2010 +0200
     2.3 @@ -34,7 +34,8 @@
     2.4  POST_UNINSTALL = :
     2.5  sbin_PROGRAMS = masqmail$(EXEEXT)
     2.6  bin_PROGRAMS = mservdetect$(EXEEXT)
     2.7 -noinst_PROGRAMS = smtpsend$(EXEEXT) readtest$(EXEEXT)
     2.8 +noinst_PROGRAMS = smtpsend$(EXEEXT) readtest$(EXEEXT) \
     2.9 +	resolvtest$(EXEEXT)
    2.10  subdir = src
    2.11  DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
    2.12  ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
    2.13 @@ -67,6 +68,9 @@
    2.14  am_readtest_OBJECTS = readsock.$(OBJEXT) readtest.$(OBJEXT)
    2.15  readtest_OBJECTS = $(am_readtest_OBJECTS)
    2.16  readtest_DEPENDENCIES =
    2.17 +am_resolvtest_OBJECTS = resolvtest.$(OBJEXT) lookup.$(OBJEXT)
    2.18 +resolvtest_OBJECTS = $(am_resolvtest_OBJECTS)
    2.19 +resolvtest_DEPENDENCIES =
    2.20  am_smtpsend_OBJECTS = smtpsend.$(OBJEXT) accept.$(OBJEXT) \
    2.21  	address.$(OBJEXT) child.$(OBJEXT) connect.$(OBJEXT) \
    2.22  	header.$(OBJEXT) interface.$(OBJEXT) lookup.$(OBJEXT) \
    2.23 @@ -83,9 +87,9 @@
    2.24  CCLD = $(CC)
    2.25  LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
    2.26  SOURCES = $(masqmail_SOURCES) $(mservdetect_SOURCES) \
    2.27 -	$(readtest_SOURCES) $(smtpsend_SOURCES)
    2.28 +	$(readtest_SOURCES) $(resolvtest_SOURCES) $(smtpsend_SOURCES)
    2.29  DIST_SOURCES = $(masqmail_SOURCES) $(mservdetect_SOURCES) \
    2.30 -	$(readtest_SOURCES) $(smtpsend_SOURCES)
    2.31 +	$(readtest_SOURCES) $(resolvtest_SOURCES) $(smtpsend_SOURCES)
    2.32  RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
    2.33  	html-recursive info-recursive install-data-recursive \
    2.34  	install-dvi-recursive install-exec-recursive \
    2.35 @@ -303,10 +307,15 @@
    2.36  	readsock.h\
    2.37  	readtest.c
    2.38  
    2.39 +resolvtest_SOURCES = \
    2.40 +	resolvtest.c\
    2.41 +	lookup.c
    2.42 +
    2.43  masqmail_LDADD = @RESOLV_LIBS@ @GLIB_LIBS@ @LOCKFILE_LIBS@ @MD5_LIBS@ @BASE64_LIBS@ @IDENT_LIBS@
    2.44  smtpsend_LDADD = @RESOLV_LIBS@ @GLIB_LIBS@ @MD5_LIBS@ @BASE64_LIBS@
    2.45  mservdetect_LDADD = @GLIB_LIBS@
    2.46  readtest_LDADD = @GLIB_LIBS@
    2.47 +resolvtest_LDADD = @RESOLV_LIBS@ @GLIB_LIBS@ @IDENT_LIBS@
    2.48  all: all-recursive
    2.49  
    2.50  .SUFFIXES:
    2.51 @@ -427,6 +436,9 @@
    2.52  readtest$(EXEEXT): $(readtest_OBJECTS) $(readtest_DEPENDENCIES) 
    2.53  	@rm -f readtest$(EXEEXT)
    2.54  	$(LINK) $(readtest_OBJECTS) $(readtest_LDADD) $(LIBS)
    2.55 +resolvtest$(EXEEXT): $(resolvtest_OBJECTS) $(resolvtest_DEPENDENCIES) 
    2.56 +	@rm -f resolvtest$(EXEEXT)
    2.57 +	$(LINK) $(resolvtest_OBJECTS) $(resolvtest_LDADD) $(LIBS)
    2.58  smtpsend$(EXEEXT): $(smtpsend_OBJECTS) $(smtpsend_DEPENDENCIES) 
    2.59  	@rm -f smtpsend$(EXEEXT)
    2.60  	$(LINK) $(smtpsend_OBJECTS) $(smtpsend_LDADD) $(LIBS)
    2.61 @@ -463,6 +475,7 @@
    2.62  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/queue.Po@am__quote@
    2.63  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readsock.Po@am__quote@
    2.64  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readtest.Po@am__quote@
    2.65 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resolvtest.Po@am__quote@
    2.66  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rewrite.Po@am__quote@
    2.67  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/route.Po@am__quote@
    2.68  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smtp_in.Po@am__quote@
     3.1 --- a/src/lookup.c	Fri Jul 16 12:39:14 2010 +0200
     3.2 +++ b/src/lookup.c	Fri Jul 16 12:53:07 2010 +0200
     3.3 @@ -22,11 +22,6 @@
     3.4  
     3.5  #include "masqmail.h"
     3.6  
     3.7 -#ifdef RESOLV_TEST
     3.8 -#undef DEBUG
     3.9 -#define DEBUG(x) if(x > 0)
    3.10 -#define debugf g_print
    3.11 -#endif
    3.12  
    3.13  #ifdef ENABLE_RESOLVER
    3.14  
    3.15 @@ -198,35 +193,39 @@
    3.16  }
    3.17  */
    3.18  
    3.19 -static int
    3.20 +int
    3.21  dns_look_ip(gchar * domain, guint32 * ip)
    3.22  {
    3.23  	gchar *n = domain;
    3.24  
    3.25  	while (TRUE) {
    3.26 -		if (dns_resolve(n, T_A, FALSE) == 0) {
    3.27 -			dns_next();
    3.28 -			if (rr_type == T_A) {
    3.29 -				if (rr_dlen < 4)
    3.30 -					return -1;  /* soft */
    3.31 -				*ip = *(guint32 *) (resp_pos);
    3.32 +		if (dns_resolve(n, T_A, FALSE) != 0) {
    3.33 +			return -1;
    3.34 +		}
    3.35  
    3.36 -				DEBUG(5) debugf("DNS: dns_look_ip(): ip = %s\n", inet_ntoa(*(struct in_addr *) ip));
    3.37 +		dns_next();
    3.38 +		if (rr_type == T_A) {
    3.39 +			if (rr_dlen < 4) {
    3.40 +				return -1;  /* soft */
    3.41 +			}
    3.42 +			*ip = *(guint32 *) (resp_pos);
    3.43  
    3.44 -				resp_pos += rr_dlen;
    3.45 -				return 0;
    3.46 -			} else if (rr_type == T_CNAME) {
    3.47 -				if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0)
    3.48 -					return -1;
    3.49 +			DEBUG(5) debugf("DNS: dns_look_ip(): ip = %s\n", inet_ntoa(*(struct in_addr *) ip));
    3.50  
    3.51 -				DEBUG(5) debugf("DNS: (CNAME) dns_look_ip(): name = %s\n", name);
    3.52 +			resp_pos += rr_dlen;
    3.53 +			return 0;
    3.54 +		} else if (rr_type == T_CNAME) {
    3.55 +			if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0) {
    3.56 +				return -1;
    3.57 +			}
    3.58  
    3.59 -				resp_pos += rr_dlen;
    3.60 -				n = name;
    3.61 -			} else
    3.62 -				return -1;
    3.63 -		} else
    3.64 +			DEBUG(5) debugf("DNS: (CNAME) dns_look_ip(): name = %s\n", name);
    3.65 +
    3.66 +			resp_pos += rr_dlen;
    3.67 +			n = name;
    3.68 +		} else {
    3.69  			return -1;
    3.70 +		}
    3.71  	}
    3.72  }
    3.73  
    3.74 @@ -333,35 +332,3 @@
    3.75  	}
    3.76  	return list;
    3.77  }
    3.78 -
    3.79 -#ifdef RESOLV_TEST
    3.80 -int
    3.81 -main(int argc, char *argv[])
    3.82 -{
    3.83 -	GList *addr_list = NULL, *node;
    3.84 -
    3.85 -	g_print("starting res_init()\n");
    3.86 -	g_print("retrans = %d, retry = %d\n", _res.retrans, _res.retry);
    3.87 -	if (res_init() == 0) {
    3.88 -		addr_list = resolve_dns_a(NULL, argv[1]);
    3.89 -		g_print("A:\n");
    3.90 -		foreach(addr_list, node) {
    3.91 -			mxip_addr *p_mxip = (mxip_addr *) (node->data);
    3.92 -			printf("name = %s\n IP = %s\n", p_mxip->name, inet_ntoa(*(struct in_addr *) &(p_mxip->ip)));
    3.93 -		}
    3.94 -		addr_list = resolve_dns_mx(NULL, argv[1]);
    3.95 -		g_print("MX:\n");
    3.96 -		foreach(addr_list, node) {
    3.97 -			mxip_addr *p_mxip = (mxip_addr *) (node->data);
    3.98 -			printf("name = %s\n IP = %s pref = %d\n", p_mxip->name,
    3.99 -			       inet_ntoa(*(struct in_addr *) &(p_mxip->ip)), p_mxip->pref);
   3.100 -		}
   3.101 -		{
   3.102 -			guint32 ip;
   3.103 -			dns_look_ip(argv[1], &ip);
   3.104 -			printf("dns_look_ip: %s\n", inet_ntoa(*((struct in_addr *) (&ip))));
   3.105 -		}
   3.106 -	} else
   3.107 -		printf("res_init() failed.\n");
   3.108 -}
   3.109 -#endif
     4.1 --- a/src/lookup.h	Fri Jul 16 12:39:14 2010 +0200
     4.2 +++ b/src/lookup.h	Fri Jul 16 12:53:07 2010 +0200
     4.3 @@ -30,3 +30,4 @@
     4.4  GList *resolve_dns_a(GList * list, gchar * domain);
     4.5  GList *resolve_dns_mx(GList * list, gchar * domain);
     4.6  GList *resolve_byname(GList * list, gchar * domain);
     4.7 +int dns_look_ip(gchar * domain, guint32 * ip);
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/resolvtest.c	Fri Jul 16 12:53:07 2010 +0200
     5.3 @@ -0,0 +1,85 @@
     5.4 +/* MasqMail Copyright (C) Oliver Kurth,
     5.5 +/* Copyright (C) 2010 markus schnalke <meillo@marmaro.de>
     5.6 + *
     5.7 + * This program is free software; you can redistribute it and/or modify
     5.8 + * it under the terms of the GNU General Public License as published by
     5.9 + * the Free Software Foundation; either version 2 of the License, or
    5.10 + * (at your option) any later version.
    5.11 + *
    5.12 + * This program is distributed in the hope that it will be useful,
    5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.15 + * GNU General Public License for more details.
    5.16 + *
    5.17 + * You should have received a copy of the GNU General Public License
    5.18 + * along with this program; if not, write to the Free Software
    5.19 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    5.20 + */
    5.21 +
    5.22 +
    5.23 +#include <sys/types.h>
    5.24 +#include <netinet/in.h>
    5.25 +#include <arpa/nameser.h>
    5.26 +#include <resolv.h>
    5.27 +
    5.28 +#include "masqmail.h"
    5.29 +
    5.30 +
    5.31 +masqmail_conf conf;
    5.32 +
    5.33 +
    5.34 +void
    5.35 +debugf(const char *fmt, ...)
    5.36 +{
    5.37 +	va_list args;
    5.38 +	va_start(args, fmt);
    5.39 +
    5.40 +	vfprintf(stdout, fmt, args);
    5.41 +
    5.42 +	va_end(args);
    5.43 +
    5.44 +}
    5.45 +
    5.46 +
    5.47 +int
    5.48 +main(int argc, char *argv[])
    5.49 +{
    5.50 +	GList *addr_list = NULL, *node;
    5.51 +
    5.52 +	conf.debug_level = -1;  /* no debug messages */
    5.53 +
    5.54 +	if (argc != 2) {
    5.55 +		fprintf(stderr, "usage: resolvtest HOSTNAME\n");
    5.56 +		return 1;
    5.57 +	}
    5.58 +
    5.59 +	if (res_init() != 0) {
    5.60 +		printf("res_init() failed.\n");
    5.61 +		return 1;
    5.62 +	}
    5.63 +
    5.64 +	printf("A:\n");
    5.65 +	addr_list = resolve_dns_a(NULL, argv[1]);
    5.66 +	foreach(addr_list, node) {
    5.67 +		mxip_addr *p_mxip = (mxip_addr *) (node->data);
    5.68 +		printf("%s  \t%s\n", p_mxip->name, inet_ntoa(*(struct in_addr *) &(p_mxip->ip)));
    5.69 +	}
    5.70 +
    5.71 +	printf("\nMX:\n");
    5.72 +	addr_list = resolve_dns_mx(NULL, argv[1]);
    5.73 +	foreach(addr_list, node) {
    5.74 +		mxip_addr *p_mxip = (mxip_addr *) (node->data);
    5.75 +		printf("%s  \t%s  %d\n", p_mxip->name,
    5.76 +		       inet_ntoa(*(struct in_addr *) &(p_mxip->ip)), p_mxip->pref);
    5.77 +	}
    5.78 +
    5.79 +	printf("\nIP resolved directly (assumed FQDN, no default domain added):\n");
    5.80 +	{
    5.81 +		guint32 ip;
    5.82 +		if (dns_look_ip(argv[1], &ip) >= 0) {
    5.83 +			printf("%s\n", inet_ntoa(*((struct in_addr *) (&ip))));
    5.84 +		}
    5.85 +	}
    5.86 +
    5.87 +	return 0;
    5.88 +}