GNUnet 0.21.0
gns_tld_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013, 2016, 2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_constants.h"
29#include "gnunet_arm_service.h"
31#include "gnunet_protocols.h"
32#include "gnunet_dht_service.h"
33#include "gns.h"
34#include "gns_api.h"
35
36
37#define LOG(kind, ...) GNUNET_log_from (kind, "gns-tld-api", __VA_ARGS__)
38
39
44{
49
54
58 char *name;
59
64
69
74
80
85
89 uint32_t type;
90
95};
96
97
105static const char *
106get_tld (const char *name)
107{
108 const char *tld;
109
110 tld = strrchr (name, (unsigned char) '.');
111 if (NULL == tld)
112 tld = name;
113 else
114 tld++; /* skip the '.' */
115 return tld;
116}
117
118
125static void
126eat_tld (char *name, const char *tld)
127{
128 GNUNET_assert (0 < strlen (name));
129 if ((NULL == tld) || (strlen (name) == strlen (tld)))
130 {
132 }
133 else
134 {
135 GNUNET_assert (strlen (tld) < strlen (name));
136 name[strlen (name) - strlen (tld) - 1] = '\0';
137 }
138}
139
140
148static void
150 uint32_t rd_count,
151 const struct GNUNET_GNSRECORD_Data *rd)
152{
153 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
154
155 ltr->lr = NULL;
158}
159
160
167static void
169 const struct GNUNET_CRYPTO_PublicKey *pkey)
170{
171 ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle,
172 ltr->name,
173 pkey,
174 ltr->type,
175 ltr->options,
177 ltr);
178}
179
180
190static void
192 const struct GNUNET_CRYPTO_PrivateKey *priv,
193 const char *ego_name)
194{
195 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
197
198 ltr->id_co = NULL;
199 if (NULL == priv)
200 {
201 /* no matching ego found */
202 ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_NO, 0, NULL);
203 return;
204 }
205 /* Final case: TLD matches one of our egos */
206 if (0 == strcmp (ltr->name, ego_name))
207 {
208 /* name matches ego name perfectly, only "@" remains */
209 strcpy (ltr->name, GNUNET_GNS_EMPTY_LABEL_AT);
210 }
211 else
212 {
213 GNUNET_assert (strlen (ego_name) < strlen (ltr->name));
214 ltr->name[strlen (ltr->name) - strlen (ego_name) - 1] = '\0';
215 }
216 /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */
217 if (NULL == strchr (ltr->name, (unsigned char) '.'))
219 else
223}
224
225
241 const char *name,
242 uint32_t type,
245 void *proc_cls)
246{
248 const char *tld;
249 char *dot_tld;
250 char *zonestr;
252
254 ltr->gns_handle = handle;
255 ltr->name = GNUNET_strdup (name);
256 ltr->type = type;
257 ltr->options = options;
258 ltr->lookup_proc = proc;
259 ltr->lookup_proc_cls = proc_cls;
260 /* start with trivial case: TLD is zkey */
261 tld = get_tld (ltr->name);
262 if (GNUNET_OK ==
264 {
266 "`%s' seems to be a valid zone key\n", tld);
267 eat_tld (ltr->name, tld);
269 return ltr;
270 }
271
272 /* second case: domain is mapped in our configuration file */
273 for (const char *domain = name; NULL != domain;
274 domain = strchr (domain, (unsigned char) '.'))
275 {
276 if ('.' == domain[0])
277 domain++;
278 GNUNET_asprintf (&dot_tld, ".%s", domain);
280 "gns",
281 dot_tld,
282 &zonestr))
283 {
284 if (GNUNET_OK !=
286 &pkey))
287 {
290 "gns",
291 dot_tld,
292 _ ("Expected a base32-encoded public zone key\n"));
293 GNUNET_free (zonestr);
294 GNUNET_free (dot_tld);
295 GNUNET_free (ltr->name);
296 GNUNET_free (ltr);
297 return NULL;
298 }
299 eat_tld (ltr->name, &dot_tld[1]);
300 GNUNET_free (zonestr);
301 GNUNET_free (dot_tld);
303 return ltr;
304 }
305 GNUNET_free (dot_tld);
306 }
308 "`%s' should be a valid ego\n", ltr->name);
309 ltr->id_co =
311 ltr->name,
313 ltr);
314 if (NULL == ltr->id_co)
315 {
316 GNUNET_free (ltr->name);
317 GNUNET_free (ltr);
318 return NULL;
319 }
320 return ltr;
321}
322
323
330void *
332{
333 void *ret = ltr->lookup_proc_cls;
334
335 if (NULL != ltr->id_co)
336 {
338 ltr->id_co = NULL;
339 }
340 if (NULL != ltr->lr)
341 {
343 ltr->lr = NULL;
344 }
346 GNUNET_free (ltr->name);
347 GNUNET_free (ltr);
348 return ret;
349}
350
351
352/* end of gns_tld_api.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
IPC messages between GNS API and GNS service.
shared data structures of libgnunetgns
static void lookup_with_public_key(struct GNUNET_GNS_LookupWithTldRequest *ltr, const struct GNUNET_CRYPTO_PublicKey *pkey)
Perform the actual resolution, starting with the zone identified by the given public key.
Definition: gns_tld_api.c:168
static const char * get_tld(const char *name)
Obtain the TLD of the given name.
Definition: gns_tld_api.c:106
#define LOG(kind,...)
Definition: gns_tld_api.c:37
static void identity_zone_cb(void *cls, const struct GNUNET_CRYPTO_PrivateKey *priv, const char *ego_name)
Method called to with the ego we are to use for the lookup, when the ego is determined by a name.
Definition: gns_tld_api.c:191
static void process_lookup_result(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called with the result of a GNS lookup.
Definition: gns_tld_api.c:149
static void eat_tld(char *name, const char *tld)
Eat the "TLD" (last bit) of the given name.
Definition: gns_tld_api.c:126
static int ret
Final status code.
Definition: gnunet-arm.c:94
char * ego_name
static char * pkey
Public key of the zone to look in, in ASCII.
static char * name
Name (label) of the records to list.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
API to the DHT service.
Identity service; implements identity management for GNUnet.
Constants for network protocols.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
struct GNUNET_GNS_LookupRequest * GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_CRYPTO_PublicKey *zone, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS.
Definition: gns_api.c:421
void(* GNUNET_GNS_LookupResultProcessor2)(void *cls, int gns_tld, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Iterator called on obtained result for a GNS lookup where "not GNS" is a valid answer.
struct GNUNET_GNS_LookupWithTldRequest * GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, const char *name, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor2 proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS, determining the zone using the TLD of the given ...
Definition: gns_tld_api.c:240
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
Definition: gns_tld_api.c:331
void * GNUNET_GNS_lookup_cancel(struct GNUNET_GNS_LookupRequest *lr)
Cancel pending lookup request.
Definition: gns_api.c:313
GNUNET_GNS_LocalOptions
Options for the GNS lookup.
@ GNUNET_GNS_LO_NO_DHT
Never look in the DHT, keep request to local cache.
@ GNUNET_GNS_LO_LOCAL_MASTER
For the rightmost label, only look in the cache (it is our local namestore), for the others,...
#define GNUNET_GNS_EMPTY_LABEL_AT
String we use to indicate an empty label (top-level entry in the zone).
struct GNUNET_IDENTITY_EgoSuffixLookup * GNUNET_IDENTITY_ego_lookup_by_suffix(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *suffix, GNUNET_IDENTITY_EgoSuffixCallback cb, void *cb_cls)
Obtain the ego with the maximum suffix match between the ego's name and the given domain name suffix.
void GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(struct GNUNET_IDENTITY_EgoSuffixLookup *el)
Abort ego suffix lookup attempt.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: crypto_pkey.c:602
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_public_key_from_string(const char *str, struct GNUNET_CRYPTO_PublicKey *key)
Parses a (Base32) string representation of the public key.
Definition: crypto_pkey.c:571
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Connection to the GNS service.
Definition: gns_api.h:36
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: gns_api.h:40
Handle to a lookup request.
Definition: gns_api.c:48
Handle to a lookup request.
Definition: gns_tld_api.c:44
enum GNUNET_GNS_LocalOptions options
Lookup options.
Definition: gns_tld_api.c:94
GNUNET_GNS_LookupResultProcessor2 lookup_proc
processor to call on lookup result
Definition: gns_tld_api.c:53
uint32_t type
Desired result record type.
Definition: gns_tld_api.c:89
char * name
Domain name we are resolving.
Definition: gns_tld_api.c:58
void * lookup_proc_cls
lookup_proc closure
Definition: gns_tld_api.c:63
struct GNUNET_GNS_LookupRequest * lr
Underlying GNS lookup.
Definition: gns_tld_api.c:68
char * longest_match
Name of the longest matching ego found so far.
Definition: gns_tld_api.c:79
struct GNUNET_GNS_Handle * gns_handle
handle to gns
Definition: gns_tld_api.c:48
struct GNUNET_IDENTITY_EgoSuffixLookup * id_co
Lookup an ego with the identity service.
Definition: gns_tld_api.c:73
struct GNUNET_IDENTITY_Ego * longest_match_ego
Ego corresponding to longest_match.
Definition: gns_tld_api.c:84
Handle for an ego.
Definition: identity.h:37
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition: vpn_api.c:39