diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-19 21:33:50 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-19 21:33:50 +0900 |
commit | 89fed7a08bc0dc499ecbdd90f519fc4de94c06e3 (patch) | |
tree | d6562366bf311b4b4f96ae5c988232b6aa75c443 /src/namestore | |
parent | da036970cd6b71908052eee17dc1b50f31e6b310 (diff) | |
download | gnunet-89fed7a08bc0dc499ecbdd90f519fc4de94c06e3.tar.gz gnunet-89fed7a08bc0dc499ecbdd90f519fc4de94c06e3.zip |
NAMESTORE: Start parser for DNS zonefiles
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/Makefile.am | 8 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore-zonefile.c | 201 |
2 files changed, 208 insertions, 1 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index da563a9e8..8abe6560f 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -85,6 +85,7 @@ libexec_PROGRAMS = \ | |||
85 | bin_PROGRAMS = \ | 85 | bin_PROGRAMS = \ |
86 | gnunet-namestore \ | 86 | gnunet-namestore \ |
87 | gnunet-namestore-dbtool \ | 87 | gnunet-namestore-dbtool \ |
88 | gnunet-namestore-zonefile \ | ||
88 | gnunet-zoneimport | 89 | gnunet-zoneimport |
89 | 90 | ||
90 | libexec_PROGRAMS += \ | 91 | libexec_PROGRAMS += \ |
@@ -127,7 +128,12 @@ libgnunetnamestore_la_LDFLAGS = \ | |||
127 | $(GN_LIB_LDFLAGS) \ | 128 | $(GN_LIB_LDFLAGS) \ |
128 | -version-info 0:1:0 | 129 | -version-info 0:1:0 |
129 | 130 | ||
130 | 131 | gnunet_namestore_zonefile_SOURCES = \ | |
132 | gnunet-namestore-zonefile.c | ||
133 | gnunet_namestore_zonefile_LDADD = \ | ||
134 | libgnunetnamestore.la \ | ||
135 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
136 | $(GN_LIBINTL) | ||
131 | 137 | ||
132 | gnunet_zoneimport_SOURCES = \ | 138 | gnunet_zoneimport_SOURCES = \ |
133 | gnunet-zoneimport.c | 139 | gnunet-zoneimport.c |
diff --git a/src/namestore/gnunet-namestore-zonefile.c b/src/namestore/gnunet-namestore-zonefile.c new file mode 100644 index 000000000..645498257 --- /dev/null +++ b/src/namestore/gnunet-namestore-zonefile.c | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2012, 2013, 2014, 2019, 2022 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 | */ | ||
20 | /** | ||
21 | * @file gnunet-namestore-dbtool.c | ||
22 | * @brief command line tool to manipulate the database backends for the namestore | ||
23 | * @author Martin Schanzenbach | ||
24 | * | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include <gnunet_util_lib.h> | ||
28 | #include <gnunet_namestore_plugin.h> | ||
29 | |||
30 | /** | ||
31 | * Return code | ||
32 | */ | ||
33 | static int ret = 0; | ||
34 | |||
35 | /** | ||
36 | * Task run on shutdown. Cleans up everything. | ||
37 | * | ||
38 | * @param cls unused | ||
39 | */ | ||
40 | static void | ||
41 | do_shutdown (void *cls) | ||
42 | { | ||
43 | (void) cls; | ||
44 | } | ||
45 | /** | ||
46 | * Main function that will be run. | ||
47 | * | ||
48 | * @param cls closure | ||
49 | * @param args remaining command-line arguments | ||
50 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
51 | * @param cfg configuration | ||
52 | */ | ||
53 | static void | ||
54 | run (void *cls, | ||
55 | char *const *args, | ||
56 | const char *cfgfile, | ||
57 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
58 | { | ||
59 | char buf[5000]; /* buffer to hold entire line (adjust MAXC as needed) */ | ||
60 | char *next; | ||
61 | char *token; | ||
62 | char origin[255]; | ||
63 | char lastname[255]; | ||
64 | int origin_line = 0; | ||
65 | |||
66 | /* use filename provided as 1st argument (stdin by default) */ | ||
67 | int i = 0; | ||
68 | while (fgets (buf, 5000, stdin)) /* read each line of input */ | ||
69 | { | ||
70 | origin_line = 0; | ||
71 | /* Find space */ | ||
72 | next = strchr (buf, ' '); | ||
73 | if (NULL == next) | ||
74 | { | ||
75 | fprintf (stderr, "End?\n"); | ||
76 | break; | ||
77 | } | ||
78 | next[0] = '\0'; | ||
79 | next++; | ||
80 | if (0 == (strcmp (buf, "$ORIGIN"))) | ||
81 | origin_line = 1; | ||
82 | else if (0 == (strcmp (buf, "$TTL"))) | ||
83 | continue; // FIXME | ||
84 | else | ||
85 | { | ||
86 | if (0 == strlen (buf)) // Inherit name from before | ||
87 | { | ||
88 | printf ("Old name: %s\n", lastname); | ||
89 | } | ||
90 | else if (buf[strlen (buf) - 1] != '.') // no fqdn | ||
91 | { | ||
92 | printf ("New name: %s\n", buf); | ||
93 | strcpy (lastname, buf); | ||
94 | } | ||
95 | else if (0 == strcmp (buf, origin)) | ||
96 | { | ||
97 | printf ("New name: @\n"); | ||
98 | strcpy (lastname, "@"); | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | if (strlen (buf) < strlen (origin)) | ||
103 | { | ||
104 | fprintf (stderr, "Wrong origin: %s (expected %s)\n", buf, origin); | ||
105 | break; // FIXME error? | ||
106 | } | ||
107 | if (0 != strcmp (buf + (strlen (buf) - strlen (origin)), origin)) | ||
108 | { | ||
109 | fprintf (stderr, "Wrong origin: %s (expected %s)\n", buf, origin); | ||
110 | break; | ||
111 | } | ||
112 | buf[strlen (buf) - strlen (origin) - 1] = '\0'; | ||
113 | printf ("New name: %s\n", buf); | ||
114 | strcpy (lastname, buf); | ||
115 | } | ||
116 | } | ||
117 | while (*next == ' ') | ||
118 | next++; | ||
119 | token = next; | ||
120 | |||
121 | if (origin_line) | ||
122 | { | ||
123 | next = strchr (token, ';'); | ||
124 | if (NULL != next) | ||
125 | next[0] = '\0'; | ||
126 | next = strchr (token, ' '); | ||
127 | if (NULL != next) | ||
128 | next[0] = '\0'; | ||
129 | strcpy (origin, token); | ||
130 | printf ("Origin is: %s\n", origin); | ||
131 | continue; | ||
132 | } | ||
133 | next = strchr (token, ' '); | ||
134 | if (NULL == next) | ||
135 | { | ||
136 | fprintf (stderr, "Error, last token: %s\n", token); | ||
137 | break; | ||
138 | } | ||
139 | next[0] = '\0'; | ||
140 | next++; | ||
141 | printf ("class is: %s\n", token); | ||
142 | while (*next == ' ') | ||
143 | next++; | ||
144 | token = next; | ||
145 | next = strchr (token, ' '); | ||
146 | if (NULL == next) | ||
147 | { | ||
148 | fprintf (stderr, "Error\n"); | ||
149 | break; | ||
150 | } | ||
151 | next[0] = '\0'; | ||
152 | next++; | ||
153 | printf ("type is: %s\n", token); | ||
154 | while (*next == ' ') | ||
155 | next++; | ||
156 | token = next; | ||
157 | next = strchr (token, ';'); | ||
158 | if (NULL != next) | ||
159 | next[0] = '\0'; | ||
160 | printf ("data is: %s\n\n", token); | ||
161 | } | ||
162 | |||
163 | GNUNET_SCHEDULER_shutdown (); | ||
164 | } | ||
165 | |||
166 | |||
167 | /** | ||
168 | * The main function for gnunet-namestore-dbtool. | ||
169 | * | ||
170 | * @param argc number of arguments from the command line | ||
171 | * @param argv command line arguments | ||
172 | * @return 0 ok, 1 on error | ||
173 | */ | ||
174 | int | ||
175 | main (int argc, char *const *argv) | ||
176 | { | ||
177 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
178 | GNUNET_GETOPT_OPTION_END | ||
179 | }; | ||
180 | int lret; | ||
181 | |||
182 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
183 | return 2; | ||
184 | |||
185 | GNUNET_log_setup ("gnunet-namestore-dbtool", "WARNING", NULL); | ||
186 | if (GNUNET_OK != | ||
187 | (lret = GNUNET_PROGRAM_run (argc, | ||
188 | argv, | ||
189 | "gnunet-namestore-dbtool", | ||
190 | _ ( | ||
191 | "GNUnet namestore database manipulation tool"), | ||
192 | options, | ||
193 | &run, | ||
194 | NULL))) | ||
195 | { | ||
196 | GNUNET_free_nz ((void *) argv); | ||
197 | return lret; | ||
198 | } | ||
199 | GNUNET_free_nz ((void *) argv); | ||
200 | return ret; | ||
201 | } | ||