updated on Thu Jan 19 16:10:29 UTC 2012
[aur-mirror.git] / rp-l2tp / dns.patch
blob08ddc8a4dd8c226a9579f685b970ad40566f41e8
1 diff -aur rp-l2tp-0.4.orig/handlers/cmd.c rp-l2tp-0.4.new/handlers/cmd.c
2 --- rp-l2tp-0.4.orig/handlers/cmd.c 2004-07-01 18:58:56.000000000 +0400
3 +++ rp-l2tp-0.4.new/handlers/cmd.c 2007-03-12 01:48:25.000000000 +0300
4 @@ -340,7 +340,7 @@
5 return;
7 memcpy(&haddr.sin_addr, he->h_addr, sizeof(haddr.sin_addr));
8 - p = l2tp_peer_find(&haddr, NULL);
9 + p = l2tp_peer_find(&haddr, NULL, peer);
10 if (!p) {
11 cmd_reply(es, fd, "ERR Unknown peer");
12 return;
13 diff -aur rp-l2tp-0.4.orig/l2tp.h rp-l2tp-0.4.new/l2tp.h
14 --- rp-l2tp-0.4.orig/l2tp.h 2004-07-01 18:58:55.000000000 +0400
15 +++ rp-l2tp-0.4.new/l2tp.h 2007-03-12 03:23:14.000000000 +0300
16 @@ -78,6 +78,8 @@
17 int mask_bits; /* Peer's netmask in number of bits */
18 char hostname[MAX_HOSTNAME]; /* My hostname as presented to this peer. */
19 size_t hostname_len; /* Length of my hostname */
20 + char peer[MAX_HOSTNAME]; /* Peer's name. */
21 + size_t peer_len; /* Length of name */
22 char peername[MAX_HOSTNAME]; /* Peer's hostname. */
23 size_t peername_len; /* Length of hostname */
24 char secret[MAX_SECRET_LEN]; /* Secret for this peer */
25 @@ -453,7 +455,7 @@
27 /* peer.c */
28 void l2tp_peer_init(void);
29 -l2tp_peer *l2tp_peer_find(struct sockaddr_in *addr, char const *hostname);
30 +l2tp_peer *l2tp_peer_find(struct sockaddr_in *addr, char const *hostname, char const *peernametosearch);
31 l2tp_peer *l2tp_peer_insert(struct sockaddr_in *addr);
33 /* debug.c */
34 diff -aur rp-l2tp-0.4.orig/peer.c rp-l2tp-0.4.new/peer.c
35 --- rp-l2tp-0.4.orig/peer.c 2004-07-01 18:58:55.000000000 +0400
36 +++ rp-l2tp-0.4.new/peer.c 2007-03-12 03:27:17.000000000 +0300
37 @@ -18,6 +18,8 @@
39 #include "l2tp.h"
40 #include <stddef.h>
41 +#include <netdb.h>
42 +#include <errno.h>
43 #include <string.h>
45 static hash_table all_peers;
46 @@ -36,6 +38,7 @@
47 static int handle_secret_option(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
48 static int handle_hostname_option(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
49 static int handle_peername_option(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
50 +static int handle_peer_option(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
51 static int set_lac_handler(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
52 static int handle_lac_option(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
53 static int set_lns_handler(EventSelector *es, l2tp_opt_descriptor *desc, char const *value);
54 @@ -44,7 +47,7 @@
55 /* Peer options */
56 static l2tp_opt_descriptor peer_opts[] = {
57 /* name type addr */
58 - { "peer", OPT_TYPE_IPADDR, &prototype.addr.sin_addr.s_addr},
59 + { "peer", OPT_TYPE_CALLFUNC, (void *) handle_peer_option},
60 { "mask", OPT_TYPE_INT, &prototype.mask_bits},
61 { "secret", OPT_TYPE_CALLFUNC, (void *) handle_secret_option},
62 { "hostname", OPT_TYPE_CALLFUNC, (void *) handle_hostname_option},
63 @@ -114,6 +117,36 @@
66 /**********************************************************************
67 +* %FUNCTION: handle_peer_option
68 +* %ARGUMENTS:
69 +* es -- event selector
70 +* desc -- descriptor
71 +* value -- the peer
72 +* %RETURNS:
73 +* 0
74 +* %DESCRIPTION:
75 +* Copies peer to prototype
76 +***********************************************************************/
77 +static int
78 +handle_peer_option(EventSelector *es,
79 + l2tp_opt_descriptor *desc,
80 + char const *value)
82 + struct hostent *he;
83 + strncpy(prototype.peer, value, MAX_HOSTNAME);
84 + prototype.peer[MAX_HOSTNAME-1] = 0;
85 + prototype.peer_len = strlen(prototype.peer);
86 + he = gethostbyname(value);
87 + if (!he) {
88 + l2tp_set_errmsg("Could not resolve %s as IP address: %s",
89 + value, strerror(errno));
90 + return -1;
91 + }
92 + memcpy(&prototype.addr.sin_addr.s_addr, he->h_addr, sizeof(he->h_addr));
93 + return 0;
96 +/**********************************************************************
97 * %FUNCTION: handle_hostname_option
98 * %ARGUMENTS:
99 * es -- event selector
100 @@ -270,6 +303,8 @@
101 peer->mask_bits = prototype.mask_bits;
102 memcpy(&peer->hostname,&prototype.hostname, sizeof(prototype.hostname));
103 peer->hostname_len = prototype.hostname_len;
104 + memcpy(&peer->peer,&prototype.peer, sizeof(prototype.peer));
105 + peer->peer_len = prototype.peer_len;
106 memcpy(&peer->peername,&prototype.peername, sizeof(prototype.peername));
107 peer->peername_len = prototype.peername_len;
108 memcpy(&peer->secret, &prototype.secret, MAX_SECRET_LEN);
109 @@ -351,7 +386,7 @@
110 * Searches peer hash table for specified peer.
111 ***********************************************************************/
112 l2tp_peer *
113 -l2tp_peer_find(struct sockaddr_in *addr, char const *peername)
114 +l2tp_peer_find(struct sockaddr_in *addr, char const *peername, const char *peernametosearch)
116 void *cursor;
117 l2tp_peer *peer = NULL;
118 @@ -371,8 +406,9 @@
119 addr1_str, addr2_str,
120 candidate->mask_bits));
122 - if ((candidate->addr.sin_addr.s_addr & mask) ==
123 - (addr->sin_addr.s_addr & mask)
124 + if (((candidate->addr.sin_addr.s_addr & mask) ==
125 + (addr->sin_addr.s_addr & mask)
126 + || (peernametosearch && candidate->peer[0] && !strcmp(peernametosearch,candidate->peer)))
127 && (!peername ||
128 !(candidate->peername[0]) ||
129 !strcmp(peername,candidate->peername))) {
130 diff -aur rp-l2tp-0.4.orig/tunnel.c rp-l2tp-0.4.new/tunnel.c
131 --- rp-l2tp-0.4.orig/tunnel.c 2004-07-01 18:58:56.000000000 +0400
132 +++ rp-l2tp-0.4.new/tunnel.c 2007-03-12 01:50:07.000000000 +0300
133 @@ -1348,7 +1348,7 @@
134 l2tp_debug_tunnel_to_str(tunnel), tunnel->peer_hostname));
136 /* Find peer */
137 - tunnel->peer = l2tp_peer_find(&tunnel->peer_addr, tunnel->peer_hostname);
138 + tunnel->peer = l2tp_peer_find(&tunnel->peer_addr, tunnel->peer_hostname, NULL);
140 /* Get assigned tunnel ID */
141 val = l2tp_dgram_search_avp(dgram, tunnel, &mandatory, &hidden, &len,