diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/gns_tld_api.c | 148 | ||||
-rw-r--r-- | src/util/dnsparser.c | 2 |
2 files changed, 63 insertions, 87 deletions
diff --git a/src/gns/gns_tld_api.c b/src/gns/gns_tld_api.c index 0dabac60e..e62bc437d 100644 --- a/src/gns/gns_tld_api.c +++ b/src/gns/gns_tld_api.c | |||
@@ -35,8 +35,7 @@ | |||
35 | #include "gns_api.h" | 35 | #include "gns_api.h" |
36 | 36 | ||
37 | 37 | ||
38 | #define LOG(kind,...) GNUNET_log_from (kind, "gns-tld-api",__VA_ARGS__) | 38 | #define LOG(kind, ...) GNUNET_log_from (kind, "gns-tld-api", __VA_ARGS__) |
39 | |||
40 | 39 | ||
41 | 40 | ||
42 | /** | 41 | /** |
@@ -110,8 +109,7 @@ get_tld (const char *name) | |||
110 | { | 109 | { |
111 | const char *tld; | 110 | const char *tld; |
112 | 111 | ||
113 | tld = strrchr (name, | 112 | tld = strrchr (name, (unsigned char) '.'); |
114 | (unsigned char) '.'); | ||
115 | if (NULL == tld) | 113 | if (NULL == tld) |
116 | tld = name; | 114 | tld = name; |
117 | else | 115 | else |
@@ -127,19 +125,18 @@ get_tld (const char *name) | |||
127 | * @param tld what to eat (can be more than just the tld) | 125 | * @param tld what to eat (can be more than just the tld) |
128 | */ | 126 | */ |
129 | static void | 127 | static void |
130 | eat_tld (char *name, | 128 | eat_tld (char *name, const char *tld) |
131 | const char *tld) | ||
132 | { | 129 | { |
133 | GNUNET_assert (0 < strlen (name)); | 130 | GNUNET_assert (0 < strlen (name)); |
134 | if (NULL == tld) | 131 | if ((NULL == tld) || |
132 | (strlen (name) == strlen (tld))) | ||
135 | { | 133 | { |
136 | strcpy (name, | 134 | strcpy (name, GNUNET_GNS_EMPTY_LABEL_AT); |
137 | GNUNET_GNS_EMPTY_LABEL_AT); | ||
138 | } | 135 | } |
139 | else | 136 | else |
140 | { | 137 | { |
141 | GNUNET_assert (strlen (tld) < strlen (name)); | 138 | GNUNET_assert (strlen (tld) < strlen (name)); |
142 | name[strlen(name) - strlen(tld) - 1] = '\0'; | 139 | name[strlen (name) - strlen (tld) - 1] = '\0'; |
143 | } | 140 | } |
144 | } | 141 | } |
145 | 142 | ||
@@ -154,15 +151,12 @@ eat_tld (char *name, | |||
154 | static void | 151 | static void |
155 | process_lookup_result (void *cls, | 152 | process_lookup_result (void *cls, |
156 | uint32_t rd_count, | 153 | uint32_t rd_count, |
157 | const struct GNUNET_GNSRECORD_Data *rd) | 154 | const struct GNUNET_GNSRECORD_Data *rd) |
158 | { | 155 | { |
159 | struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; | 156 | struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; |
160 | 157 | ||
161 | ltr->lr = NULL; | 158 | ltr->lr = NULL; |
162 | ltr->lookup_proc (ltr->lookup_proc_cls, | 159 | ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_YES, rd_count, rd); |
163 | GNUNET_YES, | ||
164 | rd_count, | ||
165 | rd); | ||
166 | GNUNET_GNS_lookup_with_tld_cancel (ltr); | 160 | GNUNET_GNS_lookup_with_tld_cancel (ltr); |
167 | } | 161 | } |
168 | 162 | ||
@@ -175,15 +169,15 @@ process_lookup_result (void *cls, | |||
175 | */ | 169 | */ |
176 | static void | 170 | static void |
177 | lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr, | 171 | lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr, |
178 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 172 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) |
179 | { | 173 | { |
180 | ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle, | 174 | ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle, |
181 | ltr->name, | 175 | ltr->name, |
182 | pkey, | 176 | pkey, |
183 | ltr->type, | 177 | ltr->type, |
184 | ltr->options, | 178 | ltr->options, |
185 | &process_lookup_result, | 179 | &process_lookup_result, |
186 | ltr); | 180 | ltr); |
187 | } | 181 | } |
188 | 182 | ||
189 | 183 | ||
@@ -211,57 +205,48 @@ identity_zone_cb (void *cls, | |||
211 | { | 205 | { |
212 | /* Final case: TLD matches one of our egos */ | 206 | /* Final case: TLD matches one of our egos */ |
213 | // FIXME: eat all of the match (not just TLD!) | 207 | // FIXME: eat all of the match (not just TLD!) |
214 | if (0 == strcmp (ltr->name, | 208 | if (0 == strcmp (ltr->name, ltr->longest_match)) |
215 | ltr->longest_match)) | ||
216 | { | 209 | { |
217 | /* name matches ego name perfectly, only "@" remains */ | 210 | /* name matches ego name perfectly, only "@" remains */ |
218 | strcpy (ltr->name, | 211 | strcpy (ltr->name, GNUNET_GNS_EMPTY_LABEL_AT); |
219 | GNUNET_GNS_EMPTY_LABEL_AT); | ||
220 | } | 212 | } |
221 | else | 213 | else |
222 | { | 214 | { |
223 | GNUNET_assert (strlen (ltr->longest_match) < strlen (ltr->name)); | 215 | GNUNET_assert (strlen (ltr->longest_match) < strlen (ltr->name)); |
224 | ltr->name[strlen(ltr->name) - strlen (ltr->longest_match) - 1] = '\0'; | 216 | ltr->name[strlen (ltr->name) - strlen (ltr->longest_match) - 1] = '\0'; |
225 | } | 217 | } |
226 | 218 | ||
227 | /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */ | 219 | /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */ |
228 | GNUNET_free (ltr->longest_match); | 220 | GNUNET_free (ltr->longest_match); |
229 | ltr->longest_match = NULL; | 221 | ltr->longest_match = NULL; |
230 | if (NULL == strchr (ltr->name, | 222 | if (NULL == strchr (ltr->name, (unsigned char) '.')) |
231 | (unsigned char) '.')) | ||
232 | ltr->options = GNUNET_GNS_LO_NO_DHT; | 223 | ltr->options = GNUNET_GNS_LO_NO_DHT; |
233 | else | 224 | else |
234 | ltr->options = GNUNET_GNS_LO_LOCAL_MASTER; | 225 | ltr->options = GNUNET_GNS_LO_LOCAL_MASTER; |
235 | 226 | ||
236 | GNUNET_IDENTITY_ego_get_public_key (ltr->longest_match_ego, | 227 | GNUNET_IDENTITY_ego_get_public_key (ltr->longest_match_ego, &pkey); |
237 | &pkey); | ||
238 | GNUNET_IDENTITY_disconnect (ltr->id_co); | 228 | GNUNET_IDENTITY_disconnect (ltr->id_co); |
239 | ltr->id_co = NULL; | 229 | ltr->id_co = NULL; |
240 | lookup_with_public_key (ltr, | 230 | lookup_with_public_key (ltr, &pkey); |
241 | &pkey); | ||
242 | } | 231 | } |
243 | else | 232 | else |
244 | { | 233 | { |
245 | /* no matching ego found */ | 234 | /* no matching ego found */ |
246 | GNUNET_IDENTITY_disconnect (ltr->id_co); | 235 | GNUNET_IDENTITY_disconnect (ltr->id_co); |
247 | ltr->id_co = NULL; | 236 | ltr->id_co = NULL; |
248 | ltr->lookup_proc (ltr->lookup_proc_cls, | 237 | ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_NO, 0, NULL); |
249 | GNUNET_NO, | ||
250 | 0, | ||
251 | NULL); | ||
252 | GNUNET_GNS_lookup_with_tld_cancel (ltr); | 238 | GNUNET_GNS_lookup_with_tld_cancel (ltr); |
253 | } | 239 | } |
254 | return; | 240 | return; |
255 | } | 241 | } |
256 | else if (NULL != name) | 242 | else if (NULL != name) |
257 | { | 243 | { |
258 | if ( (strlen (name) <= strlen (ltr->name)) && | 244 | if ((strlen (name) <= strlen (ltr->name)) && |
259 | (0 == strcmp (name, | 245 | (0 == strcmp (name, <r->name[strlen (ltr->name) - strlen (name)])) && |
260 | <r->name[strlen(ltr->name) - strlen (name)])) && | 246 | ((strlen (name) == strlen (ltr->name)) || |
261 | ( (strlen (name) == strlen (ltr->name)) || | 247 | ('.' == ltr->name[strlen (ltr->name) - strlen (name) - 1])) && |
262 | ('.' == ltr->name[strlen(ltr->name) - strlen (name) - 1]) ) && | 248 | ((NULL == ltr->longest_match) || |
263 | ( (NULL == ltr->longest_match) || | 249 | (strlen (name) > strlen (ltr->longest_match)))) |
264 | (strlen (name) > strlen (ltr->longest_match)) ) ) | ||
265 | { | 250 | { |
266 | /* found better match, update! */ | 251 | /* found better match, update! */ |
267 | GNUNET_free_non_null (ltr->longest_match); | 252 | GNUNET_free_non_null (ltr->longest_match); |
@@ -287,11 +272,11 @@ identity_zone_cb (void *cls, | |||
287 | */ | 272 | */ |
288 | struct GNUNET_GNS_LookupWithTldRequest * | 273 | struct GNUNET_GNS_LookupWithTldRequest * |
289 | GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | 274 | GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, |
290 | const char *name, | 275 | const char *name, |
291 | uint32_t type, | 276 | uint32_t type, |
292 | enum GNUNET_GNS_LocalOptions options, | 277 | enum GNUNET_GNS_LocalOptions options, |
293 | GNUNET_GNS_LookupResultProcessor2 proc, | 278 | GNUNET_GNS_LookupResultProcessor2 proc, |
294 | void *proc_cls) | 279 | void *proc_cls) |
295 | { | 280 | { |
296 | struct GNUNET_GNS_LookupWithTldRequest *ltr; | 281 | struct GNUNET_GNS_LookupWithTldRequest *ltr; |
297 | const char *tld; | 282 | const char *tld; |
@@ -309,63 +294,52 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | |||
309 | /* start with trivial case: TLD is zkey */ | 294 | /* start with trivial case: TLD is zkey */ |
310 | tld = get_tld (ltr->name); | 295 | tld = get_tld (ltr->name); |
311 | if (GNUNET_OK == | 296 | if (GNUNET_OK == |
312 | GNUNET_CRYPTO_ecdsa_public_key_from_string (tld, | 297 | GNUNET_CRYPTO_ecdsa_public_key_from_string (tld, strlen (tld), &pkey)) |
313 | strlen (tld), | ||
314 | &pkey)) | ||
315 | { | 298 | { |
316 | eat_tld (ltr->name, | 299 | eat_tld (ltr->name, tld); |
317 | tld); | 300 | lookup_with_public_key (ltr, &pkey); |
318 | lookup_with_public_key (ltr, | ||
319 | &pkey); | ||
320 | return ltr; | 301 | return ltr; |
321 | } | 302 | } |
322 | 303 | ||
323 | /* second case: domain is mapped in our configuration file */ | 304 | /* second case: domain is mapped in our configuration file */ |
324 | for (const char *domain = name; | 305 | for (const char *domain = name; NULL != domain; |
325 | NULL != domain; | 306 | domain = strchr (domain, (unsigned char) '.')) |
326 | domain = strchr (domain, | ||
327 | (unsigned char) '.')) | ||
328 | { | 307 | { |
329 | if ('.' == domain[0]) | 308 | if ('.' == domain[0]) |
330 | domain++; | 309 | domain++; |
331 | GNUNET_asprintf (&dot_tld, | 310 | GNUNET_asprintf (&dot_tld, ".%s", domain); |
332 | ".%s", | 311 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (handle->cfg, |
333 | domain); | 312 | "gns", |
334 | if (GNUNET_OK == | 313 | dot_tld, |
335 | GNUNET_CONFIGURATION_get_value_string (handle->cfg, | 314 | &zonestr)) |
336 | "gns", | ||
337 | dot_tld, | ||
338 | &zonestr)) | ||
339 | { | 315 | { |
340 | if (GNUNET_OK != | 316 | if (GNUNET_OK != |
341 | GNUNET_CRYPTO_ecdsa_public_key_from_string (zonestr, | 317 | GNUNET_CRYPTO_ecdsa_public_key_from_string (zonestr, |
342 | strlen (zonestr), | 318 | strlen (zonestr), |
343 | &pkey)) | 319 | &pkey)) |
344 | { | 320 | { |
345 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 321 | GNUNET_log_config_invalid ( |
346 | "gns", | 322 | GNUNET_ERROR_TYPE_ERROR, |
347 | dot_tld, | 323 | "gns", |
348 | _("Expected a base32-encoded public zone key\n")); | 324 | dot_tld, |
349 | GNUNET_free (zonestr); | 325 | _ ("Expected a base32-encoded public zone key\n")); |
350 | GNUNET_free (dot_tld); | 326 | GNUNET_free (zonestr); |
351 | GNUNET_free (ltr->name); | 327 | GNUNET_free (dot_tld); |
352 | GNUNET_free (ltr); | 328 | GNUNET_free (ltr->name); |
353 | return NULL; | 329 | GNUNET_free (ltr); |
330 | return NULL; | ||
354 | } | 331 | } |
355 | eat_tld (ltr->name, | 332 | eat_tld (ltr->name, &dot_tld[1]); |
356 | &dot_tld[1]); | ||
357 | GNUNET_free (zonestr); | 333 | GNUNET_free (zonestr); |
358 | GNUNET_free (dot_tld); | 334 | GNUNET_free (dot_tld); |
359 | lookup_with_public_key (ltr, | 335 | lookup_with_public_key (ltr, &pkey); |
360 | &pkey); | ||
361 | return ltr; | 336 | return ltr; |
362 | } | 337 | } |
363 | GNUNET_free (dot_tld); | 338 | GNUNET_free (dot_tld); |
364 | } | 339 | } |
365 | 340 | ||
366 | ltr->id_co = GNUNET_IDENTITY_connect (ltr->gns_handle->cfg, | 341 | ltr->id_co = |
367 | &identity_zone_cb, | 342 | GNUNET_IDENTITY_connect (ltr->gns_handle->cfg, &identity_zone_cb, ltr); |
368 | ltr); | ||
369 | if (NULL == ltr->id_co) | 343 | if (NULL == ltr->id_co) |
370 | { | 344 | { |
371 | GNUNET_free (ltr->name); | 345 | GNUNET_free (ltr->name); |
diff --git a/src/util/dnsparser.c b/src/util/dnsparser.c index 699f9d592..ec10e3ec3 100644 --- a/src/util/dnsparser.c +++ b/src/util/dnsparser.c | |||
@@ -60,6 +60,8 @@ GNUNET_DNSPARSER_check_label (const char *label) | |||
60 | 60 | ||
61 | if (NULL != strchr (label, '.')) | 61 | if (NULL != strchr (label, '.')) |
62 | return GNUNET_SYSERR; /* not a label! Did you mean GNUNET_DNSPARSER_check_name? */ | 62 | return GNUNET_SYSERR; /* not a label! Did you mean GNUNET_DNSPARSER_check_name? */ |
63 | if (0 == strcmp (label, "@")) /* '@' is reserved for the empty label, see #GNUNET_GNS_EMPTY_LABEL_AT */ | ||
64 | return GNUNET_SYSERR; | ||
63 | if (IDNA_SUCCESS != idna_to_ascii_8z (label, &output, IDNA_ALLOW_UNASSIGNED)) | 65 | if (IDNA_SUCCESS != idna_to_ascii_8z (label, &output, IDNA_ALLOW_UNASSIGNED)) |
64 | return GNUNET_SYSERR; | 66 | return GNUNET_SYSERR; |
65 | slen = strlen (output); | 67 | slen = strlen (output); |