annotate src/lookup.c @ 91:3e7136221104

correct masqmail path in rmail script; remove docs on uninstall on install the correct path to the masqmail executable gets inserted into the rmail script now. now documentation, examples, and the templates are removed on uninstall. Empty directories are the only thing that may remain if one installs masqmail into an unusual path.
author meillo@marmaro.de
date Mon, 21 Jun 2010 09:40:16 +0200
parents f671821d8222
children 116b0269c934
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
1 /* MasqMail Copyright (C) Oliver Kurth,
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
2 *
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
3 * This program is free software; you can redistribute it and/or modify
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
4 * it under the terms of the GNU General Public License as published by
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
5 * the Free Software Foundation; either version 2 of the License, or
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
6 * (at your option) any later version.
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
7 *
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
11 * GNU General Public License for more details.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
12 *
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
13 * You should have received a copy of the GNU General Public License
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
14 * along with this program; if not, write to the Free Software
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
16 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
17
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
18 #include <sys/types.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
19 #include <netinet/in.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
20 #include <arpa/nameser.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
21 #include <resolv.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
22
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
23 #include "masqmail.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
24
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
25 #ifdef RESOLV_TEST
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
26 #undef DEBUG
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
27 #define DEBUG(x) if(x > 0)
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
28 #define debugf g_print
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
29 #endif
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
30
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
31 #ifdef ENABLE_RESOLVER
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
32
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
33 static union {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
34 HEADER hdr;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
35 unsigned char buf[PACKETSZ];
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
36 } response;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
37 static unsigned char *resp_end;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
38 static unsigned char *resp_pos;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
39
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
40 static int num_answers;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
41 static char name[MAX_DNSNAME];
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
42
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
43 unsigned short rr_type;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
44 unsigned short rr_dlen;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
45
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
46 static unsigned short
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
47 getshort(unsigned char *c)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
48 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
49 unsigned short u;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
50 u = c[0];
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
51 return (u << 8) + c[1];
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
52 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
53
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
54 static int
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
55 dns_resolve(char *domain, int type, gboolean do_search)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
56 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
57 int n;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
58 int i;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
59
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
60 int resp_len;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
61 /*errno = 0; */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
62
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
63 /*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
64 if (!stralloc_copy(&glue,domain)) return DNS_MEM;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
65 if (!stralloc_0(&glue)) return DNS_MEM;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
66 */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
67
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
68 // resp_len = res_query(domain, C_IN, type, response.buf, sizeof(response));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
69 DEBUG(5) debugf("DNS: before res_search()\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
70 if (do_search)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
71 resp_len = res_search(domain, C_IN, type, response.buf, sizeof(response));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
72 else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
73 resp_len = res_query(domain, C_IN, type, response.buf, sizeof(response));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
74 DEBUG(5) debugf("DBG: after res_search()\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
75
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
76 if (resp_len <= 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
77 /*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
78 if (errno == ECONNREFUSED) return DNS_SOFT;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
79 if (h_errno == TRY_AGAIN) return DNS_SOFT;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
80 return DNS_HARD;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
81 */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
82 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
83 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
84 if (resp_len >= sizeof(response))
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
85 resp_len = sizeof(response);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
86
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
87 resp_end = response.buf + resp_len;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
88 resp_pos = response.buf + sizeof(HEADER);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
89 n = ntohs(response.hdr.qdcount);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
90
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
91 while (n-- > 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
92 i = dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
93 if (i < 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
94 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
95 DEBUG(5) debugf("DBG: resolve name = %s\n", name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
96 resp_pos += i;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
97 i = resp_end - resp_pos;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
98 if (i < QFIXEDSZ)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
99 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
100 resp_pos += QFIXEDSZ;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
101 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
102 num_answers = ntohs(response.hdr.ancount);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
103
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
104 return 0;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
105 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
106
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
107 static int
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
108 dns_next()
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
109 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
110 int i;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
111
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
112 if (num_answers <= 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
113 return 2;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
114 num_answers--;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
115
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
116 if (resp_pos == resp_end)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
117 return -1; /* soft */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
118
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
119 i = dn_expand(response.buf, resp_end, resp_pos, name, 256);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
120 if (i < 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
121 return -1; /* soft */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
122 resp_pos += i;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
123
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
124 i = resp_end - resp_pos;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
125 if (i < 4 + 3 * 2)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
126 return -1; /* soft */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
127
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
128 rr_type = getshort(resp_pos);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
129 rr_dlen = getshort(resp_pos + 8);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
130 resp_pos += 10;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
131
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
132 return 0;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
133 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
134
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
135 static int
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
136 dns_getip(guint32 * ip)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
137 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
138 int ret;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
139
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
140 if ((ret = dns_next()))
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
141 return ret;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
142
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
143 if (rr_type == T_A) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
144 if (rr_dlen < 4)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
145 return -1; /* soft */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
146 *ip = *(guint32 *) (resp_pos);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
147 DEBUG(5) debugf("DNS: dns_getip(): ip = %s\n", inet_ntoa(*(struct in_addr *) ip));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
148 resp_pos += rr_dlen;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
149
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
150 return 1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
151 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
152 resp_pos += rr_dlen;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
153 return 0;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
154 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
155
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
156 static int
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
157 dns_getmx(int *pref)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
158 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
159 int ret;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
160
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
161 if ((ret = dns_next()))
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
162 return ret;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
163
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
164 if (rr_type == T_MX) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
165 if (rr_dlen < 3)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
166 return -1; /* soft */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
167
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
168 *pref = (resp_pos[0] << 8) + resp_pos[1];
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
169 if (dn_expand(response.buf, resp_end, resp_pos + 2, name, MAX_DNSNAME) < 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
170 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
171
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
172 resp_pos += rr_dlen;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
173
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
174 return 1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
175 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
176 resp_pos += rr_dlen;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
177 return 0;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
178 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
179
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
180 /*
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
181 static int
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
182 dns_getname(int type)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
183 {
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
184 int ret;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
185
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
186 if((ret = dns_next())) return ret;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
187
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
188 if (rr_type == type){
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
189 if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0)
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
190 return -1;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
191
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
192 resp_pos += rr_dlen;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
193
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
194 return 1;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
195 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
196 resp_pos += rr_dlen;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
197 return 0;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
198 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
199 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
200
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
201 static int
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
202 dns_look_ip(gchar * domain, guint32 * ip)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
203 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
204 gchar *n = domain;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
205
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
206 while (TRUE) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
207 if (dns_resolve(n, T_A, FALSE) == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
208 dns_next();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
209 if (rr_type == T_A) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
210 if (rr_dlen < 4)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
211 return -1; /* soft */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
212 *ip = *(guint32 *) (resp_pos);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
213
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
214 DEBUG(5) debugf("DNS: dns_look_ip(): ip = %s\n", inet_ntoa(*(struct in_addr *) ip));
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
215
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
216 resp_pos += rr_dlen;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
217 return 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
218 } else if (rr_type == T_CNAME) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
219 if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
220 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
221
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
222 DEBUG(5) debugf("DNS: (CNAME) dns_look_ip(): name = %s\n", name);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
223
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
224 resp_pos += rr_dlen;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
225 n = name;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
226 } else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
227 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
228 } else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
229 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
230 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
231 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
232
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
233 GList*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
234 resolve_dns_a(GList * list, gchar * domain)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
235 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
236 int ret;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
237
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
238 DEBUG(5) debugf("DNS: resolve_dns_a entered\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
239
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
240 if (dns_resolve(domain, T_A, TRUE) == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
241 mxip_addr mxip;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
242 while ((ret = dns_getip(&(mxip.ip))) != 2) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
243 if (ret == 1) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
244 mxip.name = g_strdup(name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
245 mxip.pref = 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
246 list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
247 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
248 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
249 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
250 return list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
251 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
252
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
253 static gint
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
254 _mx_sort_func(gconstpointer aa, gconstpointer bb)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
255 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
256 const mxip_addr *a = (mxip_addr *) aa;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
257 const mxip_addr *b = (mxip_addr *) bb;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
258
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
259 if (a->pref == b->pref)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
260 return a->ip - b->ip;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
261 else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
262 return a->pref - b->pref;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
263 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
264
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
265 GList*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
266 resolve_dns_mx(GList * list, gchar * domain)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
267 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
268 GList *node;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
269 int ret;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
270 int cnt = 0;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
271
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
272 DEBUG(5) debugf("DNS: resolve_dns_mx entered\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
273
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
274 if (dns_resolve(domain, T_MX, TRUE) == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
275 GList *node_next;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
276 mxip_addr mxip;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
277 while ((ret = dns_getmx(&(mxip.pref))) != 2) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
278 if (ret == 1) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
279 mxip.name = g_strdup(name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
280 mxip.ip = rand();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
281 list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
282 cnt++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
283 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
284 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
285
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
286 DEBUG(5) debugf("DNS: found %d mx records\n", cnt);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
287
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
288 /* to randomize sequences with equal pref values,
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
289 we temporarily 'misused' the ip field and
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
290 put a random number in it as a secondary sort key.
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
291 */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
292 list = g_list_sort(list, _mx_sort_func);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
293
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
294 /* CNAME resolving has to be added as well. */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
295
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
296 for (node = g_list_first(list); node != NULL; node = node_next) {
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
297
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
298 mxip_addr *p_mxip = (mxip_addr *) (node->data);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
299 node_next = g_list_next(node);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
300
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
301 if (dns_look_ip(p_mxip->name, &(p_mxip->ip)) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
302 DEBUG(1) debugf("DNS: could not resolve target of mx %s\n", p_mxip->name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
303 list = g_list_remove_link(list, node);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
304 g_free(node->data);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
305 g_list_free_1(node);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
306 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
307 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
308 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
309 return list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
310 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
311
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
312 #endif
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
313
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
314 /* now something completely different... */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
315
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
316 GList*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
317 resolve_byname(GList * list, gchar * domain)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
318 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
319 struct hostent *hent;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
320
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
321 DEBUG(5) debugf("DNS: resolve_byname entered\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
322
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
323 if ((hent = gethostbyname(domain))) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
324 char *haddr;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
325 int i = 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
326 while ((haddr = hent->h_addr_list[i++])) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
327 mxip_addr mxip;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
328 mxip.ip = *(guint32 *) (haddr);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
329 mxip.pref = 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
330 mxip.name = g_strdup(hent->h_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
331 list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
332 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
333 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
334 return list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
335 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
336
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
337 #ifdef RESOLV_TEST
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
338 int
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
339 main(int argc, char *argv[])
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
340 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
341 GList *addr_list = NULL, *node;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
342
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
343 g_print("starting res_init()\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
344 g_print("retrans = %d, retry = %d\n", _res.retrans, _res.retry);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
345 if (res_init() == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
346 addr_list = resolve_dns_a(NULL, argv[1]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
347 g_print("A:\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
348 foreach(addr_list, node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
349 mxip_addr *p_mxip = (mxip_addr *) (node->data);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
350 printf("name = %s\n IP = %s\n", p_mxip->name, inet_ntoa(*(struct in_addr *) &(p_mxip->ip)));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
351 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
352 addr_list = resolve_dns_mx(NULL, argv[1]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
353 g_print("MX:\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
354 foreach(addr_list, node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
355 mxip_addr *p_mxip = (mxip_addr *) (node->data);
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
356 printf("name = %s\n IP = %s pref = %d\n", p_mxip->name,
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
357 inet_ntoa(*(struct in_addr *) &(p_mxip->ip)), p_mxip->pref);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
358 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
359 {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
360 guint32 ip;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
361 dns_look_ip(argv[1], &ip);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
362 printf("dns_look_ip: %s\n", inet_ntoa(*((struct in_addr *) (&ip))));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
363 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
364 } else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
365 printf("res_init() failed.\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
366 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
367 #endif