diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-01 09:12:04 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-01 09:12:04 +0000 |
commit | 953498a3688a11381e9e3e7af26b7fa3dd533571 (patch) | |
tree | 5b9197c11975c5a77bea6fdb2bd08be4a5b28244 /src | |
parent | 76cf6a96f1c43ef4b2740b8f34fc1f2ee82b1fa8 (diff) | |
download | gnunet-953498a3688a11381e9e3e7af26b7fa3dd533571.tar.gz gnunet-953498a3688a11381e9e3e7af26b7fa3dd533571.zip |
-comments
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/nss/nss_gns.c | 53 | ||||
-rw-r--r-- | src/gns/nss/nss_gns_query.c | 10 | ||||
-rw-r--r-- | src/gns/nss/nss_gns_query.h | 17 |
3 files changed, 78 insertions, 2 deletions
diff --git a/src/gns/nss/nss_gns.c b/src/gns/nss/nss_gns.c index 8aace9c04..3bb45a153 100644 --- a/src/gns/nss/nss_gns.c +++ b/src/gns/nss/nss_gns.c | |||
@@ -34,11 +34,20 @@ | |||
34 | 34 | ||
35 | #include <arpa/inet.h> | 35 | #include <arpa/inet.h> |
36 | 36 | ||
37 | /** macro to align idx to 32bit boundary */ | ||
37 | #define ALIGN(idx) do { \ | 38 | #define ALIGN(idx) do { \ |
38 | if (idx % sizeof(void*)) \ | 39 | if (idx % sizeof(void*)) \ |
39 | idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \ | 40 | idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \ |
40 | } while(0) | 41 | } while(0) |
41 | 42 | ||
43 | |||
44 | /** | ||
45 | * function to check if name ends with a specific suffix | ||
46 | * | ||
47 | * @param name the name to check | ||
48 | * @param suffix the suffix to check for | ||
49 | * @return 1 if true | ||
50 | */ | ||
42 | static int ends_with(const char *name, const char* suffix) { | 51 | static int ends_with(const char *name, const char* suffix) { |
43 | size_t ln, ls; | 52 | size_t ln, ls; |
44 | assert(name); | 53 | assert(name); |
@@ -50,10 +59,29 @@ static int ends_with(const char *name, const char* suffix) { | |||
50 | return strcasecmp(name+ln-ls, suffix) == 0; | 59 | return strcasecmp(name+ln-ls, suffix) == 0; |
51 | } | 60 | } |
52 | 61 | ||
62 | |||
63 | /** | ||
64 | * Check if name is inside .gnunet or .zkey TLD | ||
65 | * | ||
66 | * @param name name to check | ||
67 | * @return 1 if true | ||
68 | */ | ||
53 | static int verify_name_allowed(const char *name) { | 69 | static int verify_name_allowed(const char *name) { |
54 | return ends_with(name, ".gnunet") || ends_with(name, ".zkey"); | 70 | return ends_with(name, ".gnunet") || ends_with(name, ".zkey"); |
55 | } | 71 | } |
56 | 72 | ||
73 | /** | ||
74 | * The gethostbyname hook executed by nsswitch | ||
75 | * | ||
76 | * @param name the name to resolve | ||
77 | * @param af the address family to resolve | ||
78 | * @param result the result hostent | ||
79 | * @param buffer the result buffer | ||
80 | * @param buflen length of the buffer | ||
81 | * @param errnop idk | ||
82 | * @param h_errnop idk | ||
83 | * @return a nss_status code | ||
84 | */ | ||
57 | enum nss_status _nss_gns_gethostbyname2_r( | 85 | enum nss_status _nss_gns_gethostbyname2_r( |
58 | const char *name, | 86 | const char *name, |
59 | int af, | 87 | int af, |
@@ -166,6 +194,17 @@ finish: | |||
166 | return status; | 194 | return status; |
167 | } | 195 | } |
168 | 196 | ||
197 | /** | ||
198 | * The gethostbyname hook executed by nsswitch | ||
199 | * | ||
200 | * @param name the name to resolve | ||
201 | * @param result the result hostent | ||
202 | * @param buffer the result buffer | ||
203 | * @param buflen length of the buffer | ||
204 | * @param errnop idk | ||
205 | * @param h_errnop idk | ||
206 | * @return a nss_status code | ||
207 | */ | ||
169 | enum nss_status _nss_gns_gethostbyname_r ( | 208 | enum nss_status _nss_gns_gethostbyname_r ( |
170 | const char *name, | 209 | const char *name, |
171 | struct hostent *result, | 210 | struct hostent *result, |
@@ -184,6 +223,20 @@ enum nss_status _nss_gns_gethostbyname_r ( | |||
184 | h_errnop); | 223 | h_errnop); |
185 | } | 224 | } |
186 | 225 | ||
226 | /** | ||
227 | * The gethostbyaddr hook executed by nsswitch | ||
228 | * We can't do this so we always return NSS_STATUS_UNAVAIL | ||
229 | * | ||
230 | * @param addr the address to resolve | ||
231 | * @param len the length of the address | ||
232 | * @param af the address family of the address | ||
233 | * @param result the result hostent | ||
234 | * @param buffer the result buffer | ||
235 | * @param buflen length of the buffer | ||
236 | * @param errnop idk | ||
237 | * @param h_errnop idk | ||
238 | * @return NSS_STATUS_UNAVAIL | ||
239 | */ | ||
187 | enum nss_status _nss_gns_gethostbyaddr_r( | 240 | enum nss_status _nss_gns_gethostbyaddr_r( |
188 | const void* addr, | 241 | const void* addr, |
189 | int len, | 242 | int len, |
diff --git a/src/gns/nss/nss_gns_query.c b/src/gns/nss/nss_gns_query.c index ba9fa1496..ab88d22cb 100644 --- a/src/gns/nss/nss_gns_query.c +++ b/src/gns/nss/nss_gns_query.c | |||
@@ -4,6 +4,16 @@ | |||
4 | #include "nss_gns_query.h" | 4 | #include "nss_gns_query.h" |
5 | #include <arpa/inet.h> | 5 | #include <arpa/inet.h> |
6 | 6 | ||
7 | |||
8 | /** | ||
9 | * Wrapper function that uses gnunet-gns cli tool to resolve | ||
10 | * an IPv4/6 address. | ||
11 | * | ||
12 | * @param af address family | ||
13 | * @param name the name to resolve | ||
14 | * @param u the userdata (result struct) | ||
15 | * @return -1 on error else 0 | ||
16 | */ | ||
7 | int gns_resolve_name(int af, const char *name, struct userdata *u) | 17 | int gns_resolve_name(int af, const char *name, struct userdata *u) |
8 | { | 18 | { |
9 | FILE *p; | 19 | FILE *p; |
diff --git a/src/gns/nss/nss_gns_query.h b/src/gns/nss/nss_gns_query.h index ab8b6cb43..0b4dae5e7 100644 --- a/src/gns/nss/nss_gns_query.h +++ b/src/gns/nss/nss_gns_query.h | |||
@@ -1,5 +1,9 @@ | |||
1 | #ifndef fooqueryhfoo | 1 | #ifndef NSS_GNS_QUERY_H |
2 | #define fooqueryhfoo | 2 | #define NSS_GNS_QUERY_H |
3 | |||
4 | /** | ||
5 | * Parts taken from nss-mdns. Original license statement follows | ||
6 | */ | ||
3 | 7 | ||
4 | /* $Id$ */ | 8 | /* $Id$ */ |
5 | 9 | ||
@@ -46,6 +50,15 @@ struct userdata { | |||
46 | } data; | 50 | } data; |
47 | }; | 51 | }; |
48 | 52 | ||
53 | /** | ||
54 | * Wrapper function that uses gnunet-gns cli tool to resolve | ||
55 | * an IPv4/6 address. | ||
56 | * | ||
57 | * @param af address family | ||
58 | * @param name the name to resolve | ||
59 | * @param u the userdata (result struct) | ||
60 | * @return -1 on error else 0 | ||
61 | */ | ||
49 | int gns_resolve_name(int af, | 62 | int gns_resolve_name(int af, |
50 | const char *name, | 63 | const char *name, |
51 | struct userdata *userdata); | 64 | struct userdata *userdata); |