diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/gns/nss | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/gns/nss')
-rw-r--r-- | src/gns/nss/nss_gns.c | 192 | ||||
-rw-r--r-- | src/gns/nss/nss_gns_query.c | 140 | ||||
-rw-r--r-- | src/gns/nss/nss_gns_query.h | 11 |
3 files changed, 170 insertions, 173 deletions
diff --git a/src/gns/nss/nss_gns.c b/src/gns/nss/nss_gns.c index d76eac845..43fc030b9 100644 --- a/src/gns/nss/nss_gns.c +++ b/src/gns/nss/nss_gns.c | |||
@@ -17,7 +17,7 @@ | |||
17 | along with nss-mdns; if not, write to the Free Software | 17 | along with nss-mdns; if not, write to the Free Software |
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 | USA. | 19 | USA. |
20 | ***/ | 20 | ***/ |
21 | 21 | ||
22 | #include <gnunet_config.h> | 22 | #include <gnunet_config.h> |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
@@ -37,9 +37,9 @@ | |||
37 | 37 | ||
38 | /** macro to align idx to 32bit boundary */ | 38 | /** macro to align idx to 32bit boundary */ |
39 | #define ALIGN(idx) do { \ | 39 | #define ALIGN(idx) do { \ |
40 | if (idx % sizeof(void*)) \ | 40 | if (idx % sizeof(void*)) \ |
41 | idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \ | 41 | idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \ |
42 | } while(0) | 42 | } while (0) |
43 | 43 | ||
44 | 44 | ||
45 | /** | 45 | /** |
@@ -75,7 +75,7 @@ _nss_gns_gethostbyname2_r(const char *name, | |||
75 | #ifdef NSS_IPV6_ONLY | 75 | #ifdef NSS_IPV6_ONLY |
76 | af = AF_INET6; | 76 | af = AF_INET6; |
77 | #else | 77 | #else |
78 | af = AF_INET; | 78 | af = AF_INET; |
79 | #endif | 79 | #endif |
80 | 80 | ||
81 | #ifdef NSS_IPV4_ONLY | 81 | #ifdef NSS_IPV4_ONLY |
@@ -83,70 +83,70 @@ _nss_gns_gethostbyname2_r(const char *name, | |||
83 | #elif NSS_IPV6_ONLY | 83 | #elif NSS_IPV6_ONLY |
84 | if (af != AF_INET6) | 84 | if (af != AF_INET6) |
85 | #else | 85 | #else |
86 | if ( (af != AF_INET) && | 86 | if ((af != AF_INET) && |
87 | (af != AF_INET6) ) | 87 | (af != AF_INET6)) |
88 | #endif | 88 | #endif |
89 | { | 89 | { |
90 | *errnop = EINVAL; | 90 | *errnop = EINVAL; |
91 | *h_errnop = NO_RECOVERY; | 91 | *h_errnop = NO_RECOVERY; |
92 | 92 | ||
93 | goto finish; | 93 | goto finish; |
94 | } | 94 | } |
95 | 95 | ||
96 | address_length = (af == AF_INET) ? sizeof(ipv4_address_t) : sizeof(ipv6_address_t); | 96 | address_length = (af == AF_INET) ? sizeof(ipv4_address_t) : sizeof(ipv6_address_t); |
97 | if (buflen < | 97 | if (buflen < |
98 | sizeof(char*) + /* alias names */ | 98 | sizeof(char*) + /* alias names */ |
99 | strlen (name) + 1) | 99 | strlen(name) + 1) |
100 | { /* official name */ | 100 | { /* official name */ |
101 | *errnop = ERANGE; | 101 | *errnop = ERANGE; |
102 | *h_errnop = NO_RECOVERY; | 102 | *h_errnop = NO_RECOVERY; |
103 | status = NSS_STATUS_TRYAGAIN; | 103 | status = NSS_STATUS_TRYAGAIN; |
104 | 104 | ||
105 | goto finish; | 105 | goto finish; |
106 | } | 106 | } |
107 | u.count = 0; | 107 | u.count = 0; |
108 | u.data_len = 0; | 108 | u.data_len = 0; |
109 | i = gns_resolve_name (af, | 109 | i = gns_resolve_name(af, |
110 | name, | 110 | name, |
111 | &u); | 111 | &u); |
112 | if (-1 == i) | 112 | if (-1 == i) |
113 | { | 113 | { |
114 | *errnop = errno; | 114 | *errnop = errno; |
115 | status = NSS_STATUS_UNAVAIL; | 115 | status = NSS_STATUS_UNAVAIL; |
116 | *h_errnop = NO_RECOVERY; | 116 | *h_errnop = NO_RECOVERY; |
117 | goto finish; | 117 | goto finish; |
118 | } | 118 | } |
119 | if (-2 == i) | 119 | if (-2 == i) |
120 | { | 120 | { |
121 | *errnop = ENOENT; | 121 | *errnop = ENOENT; |
122 | *h_errnop = NO_RECOVERY; | 122 | *h_errnop = NO_RECOVERY; |
123 | status = NSS_STATUS_UNAVAIL; | 123 | status = NSS_STATUS_UNAVAIL; |
124 | goto finish; | 124 | goto finish; |
125 | } | 125 | } |
126 | if (-3 == i) | 126 | if (-3 == i) |
127 | { | 127 | { |
128 | *errnop = ETIMEDOUT; | 128 | *errnop = ETIMEDOUT; |
129 | *h_errnop = HOST_NOT_FOUND; | 129 | *h_errnop = HOST_NOT_FOUND; |
130 | status = NSS_STATUS_NOTFOUND; | 130 | status = NSS_STATUS_NOTFOUND; |
131 | goto finish; | 131 | goto finish; |
132 | } | 132 | } |
133 | if (0 == u.count) | 133 | if (0 == u.count) |
134 | { | 134 | { |
135 | *errnop = 0; /* success */ | 135 | *errnop = 0; /* success */ |
136 | *h_errnop = NO_DATA; /* success */ | 136 | *h_errnop = NO_DATA; /* success */ |
137 | status = NSS_STATUS_NOTFOUND; | 137 | status = NSS_STATUS_NOTFOUND; |
138 | goto finish; | 138 | goto finish; |
139 | } | 139 | } |
140 | /* Alias names */ | 140 | /* Alias names */ |
141 | *((char**) buffer) = NULL; | 141 | *((char**)buffer) = NULL; |
142 | result->h_aliases = (char**) buffer; | 142 | result->h_aliases = (char**)buffer; |
143 | idx = sizeof(char*); | 143 | idx = sizeof(char*); |
144 | 144 | ||
145 | /* Official name */ | 145 | /* Official name */ |
146 | strcpy (buffer+idx, | 146 | strcpy(buffer + idx, |
147 | name); | 147 | name); |
148 | result->h_name = buffer+idx; | 148 | result->h_name = buffer + idx; |
149 | idx += strlen (name)+1; | 149 | idx += strlen(name) + 1; |
150 | 150 | ||
151 | ALIGN(idx); | 151 | ALIGN(idx); |
152 | 152 | ||
@@ -154,29 +154,29 @@ _nss_gns_gethostbyname2_r(const char *name, | |||
154 | result->h_length = address_length; | 154 | result->h_length = address_length; |
155 | 155 | ||
156 | /* Check if there's enough space for the addresses */ | 156 | /* Check if there's enough space for the addresses */ |
157 | if (buflen < idx+u.data_len+sizeof(char*)*(u.count+1)) | 157 | if (buflen < idx + u.data_len + sizeof(char*) * (u.count + 1)) |
158 | { | 158 | { |
159 | *errnop = ERANGE; | 159 | *errnop = ERANGE; |
160 | *h_errnop = NO_RECOVERY; | 160 | *h_errnop = NO_RECOVERY; |
161 | status = NSS_STATUS_TRYAGAIN; | 161 | status = NSS_STATUS_TRYAGAIN; |
162 | goto finish; | 162 | goto finish; |
163 | } | 163 | } |
164 | /* Addresses */ | 164 | /* Addresses */ |
165 | astart = idx; | 165 | astart = idx; |
166 | l = u.count*address_length; | 166 | l = u.count * address_length; |
167 | if (0 != l) | 167 | if (0 != l) |
168 | memcpy (buffer+astart, | 168 | memcpy(buffer + astart, |
169 | &u.data, | 169 | &u.data, |
170 | l); | 170 | l); |
171 | /* address_length is a multiple of 32bits, so idx is still aligned | 171 | /* address_length is a multiple of 32bits, so idx is still aligned |
172 | * correctly */ | 172 | * correctly */ |
173 | idx += l; | 173 | idx += l; |
174 | 174 | ||
175 | /* Address array address_length is always a multiple of 32bits */ | 175 | /* Address array address_length is always a multiple of 32bits */ |
176 | for (i = 0; i < u.count; i++) | 176 | for (i = 0; i < u.count; i++) |
177 | ((char**) (buffer+idx))[i] = buffer+astart+address_length*i; | 177 | ((char**)(buffer + idx))[i] = buffer + astart + address_length * i; |
178 | ((char**) (buffer+idx))[i] = NULL; | 178 | ((char**)(buffer + idx))[i] = NULL; |
179 | result->h_addr_list = (char**) (buffer+idx); | 179 | result->h_addr_list = (char**)(buffer + idx); |
180 | 180 | ||
181 | status = NSS_STATUS_SUCCESS; | 181 | status = NSS_STATUS_SUCCESS; |
182 | 182 | ||
@@ -197,20 +197,20 @@ finish: | |||
197 | * @return a nss_status code | 197 | * @return a nss_status code |
198 | */ | 198 | */ |
199 | enum nss_status | 199 | enum nss_status |
200 | _nss_gns_gethostbyname_r (const char *name, | 200 | _nss_gns_gethostbyname_r(const char *name, |
201 | struct hostent *result, | 201 | struct hostent *result, |
202 | char *buffer, | 202 | char *buffer, |
203 | size_t buflen, | 203 | size_t buflen, |
204 | int *errnop, | 204 | int *errnop, |
205 | int *h_errnop) | 205 | int *h_errnop) |
206 | { | 206 | { |
207 | return _nss_gns_gethostbyname2_r (name, | 207 | return _nss_gns_gethostbyname2_r(name, |
208 | AF_UNSPEC, | 208 | AF_UNSPEC, |
209 | result, | 209 | result, |
210 | buffer, | 210 | buffer, |
211 | buflen, | 211 | buflen, |
212 | errnop, | 212 | errnop, |
213 | h_errnop); | 213 | h_errnop); |
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
@@ -229,21 +229,21 @@ _nss_gns_gethostbyname_r (const char *name, | |||
229 | * @return NSS_STATUS_UNAVAIL | 229 | * @return NSS_STATUS_UNAVAIL |
230 | */ | 230 | */ |
231 | enum nss_status | 231 | enum nss_status |
232 | _nss_gns_gethostbyaddr_r (const void* addr, | 232 | _nss_gns_gethostbyaddr_r(const void* addr, |
233 | int len, | 233 | int len, |
234 | int af, | 234 | int af, |
235 | struct hostent *result, | 235 | struct hostent *result, |
236 | char *buffer, | 236 | char *buffer, |
237 | size_t buflen, | 237 | size_t buflen, |
238 | int *errnop, | 238 | int *errnop, |
239 | int *h_errnop) | 239 | int *h_errnop) |
240 | { | 240 | { |
241 | (void) addr; | 241 | (void)addr; |
242 | (void) len; | 242 | (void)len; |
243 | (void) af; | 243 | (void)af; |
244 | (void) result; | 244 | (void)result; |
245 | (void) buffer; | 245 | (void)buffer; |
246 | (void) buflen; | 246 | (void)buflen; |
247 | *errnop = EINVAL; | 247 | *errnop = EINVAL; |
248 | *h_errnop = NO_RECOVERY; | 248 | *h_errnop = NO_RECOVERY; |
249 | /* NOTE we allow to leak this into DNS so no NOTFOUND */ | 249 | /* NOTE we allow to leak this into DNS so no NOTFOUND */ |
diff --git a/src/gns/nss/nss_gns_query.c b/src/gns/nss/nss_gns_query.c index 253bb0f02..8af618618 100644 --- a/src/gns/nss/nss_gns_query.c +++ b/src/gns/nss/nss_gns_query.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | #include <string.h> | 20 | #include <string.h> |
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
@@ -33,12 +33,12 @@ | |||
33 | #define TIMEOUT "5s" | 33 | #define TIMEOUT "5s" |
34 | 34 | ||
35 | static void | 35 | static void |
36 | kwait (pid_t chld) | 36 | kwait(pid_t chld) |
37 | { | 37 | { |
38 | int ret; | 38 | int ret; |
39 | 39 | ||
40 | kill (chld, SIGKILL); | 40 | kill(chld, SIGKILL); |
41 | waitpid (chld, &ret, 0); | 41 | waitpid(chld, &ret, 0); |
42 | } | 42 | } |
43 | 43 | ||
44 | 44 | ||
@@ -55,7 +55,7 @@ kwait (pid_t chld) | |||
55 | * else 0 | 55 | * else 0 |
56 | */ | 56 | */ |
57 | int | 57 | int |
58 | gns_resolve_name (int af, const char *name, struct userdata *u) | 58 | gns_resolve_name(int af, const char *name, struct userdata *u) |
59 | { | 59 | { |
60 | FILE *p; | 60 | FILE *p; |
61 | char line[128]; | 61 | char line[128]; |
@@ -63,85 +63,85 @@ gns_resolve_name (int af, const char *name, struct userdata *u) | |||
63 | int out[2]; | 63 | int out[2]; |
64 | pid_t pid; | 64 | pid_t pid; |
65 | 65 | ||
66 | if (0 != pipe (out)) | 66 | if (0 != pipe(out)) |
67 | return -1; | 67 | return -1; |
68 | pid = fork (); | 68 | pid = fork(); |
69 | if (-1 == pid) | 69 | if (-1 == pid) |
70 | return -1; | 70 | return -1; |
71 | if (0 == pid) | 71 | if (0 == pid) |
72 | { | 72 | { |
73 | char *argv[] = {"gnunet-gns", | 73 | char *argv[] = { "gnunet-gns", |
74 | "-r", | 74 | "-r", |
75 | "-t", | 75 | "-t", |
76 | (AF_INET6 == af) ? "AAAA" : "A", | 76 | (AF_INET6 == af) ? "AAAA" : "A", |
77 | "-u", | 77 | "-u", |
78 | (char *) name, | 78 | (char *)name, |
79 | "-T", | 79 | "-T", |
80 | TIMEOUT, | 80 | TIMEOUT, |
81 | NULL}; | 81 | NULL }; |
82 | 82 | ||
83 | (void) close (STDOUT_FILENO); | 83 | (void)close(STDOUT_FILENO); |
84 | if ((0 != close (out[0])) || | 84 | if ((0 != close(out[0])) || |
85 | (STDOUT_FILENO != dup2 (out[1], STDOUT_FILENO))) | 85 | (STDOUT_FILENO != dup2(out[1], STDOUT_FILENO))) |
86 | _exit (1); | 86 | _exit(1); |
87 | (void) execvp ("gnunet-gns", argv); | 87 | (void)execvp("gnunet-gns", argv); |
88 | _exit (1); | 88 | _exit(1); |
89 | } | 89 | } |
90 | (void) close (out[1]); | 90 | (void)close(out[1]); |
91 | p = fdopen (out[0], "r"); | 91 | p = fdopen(out[0], "r"); |
92 | if (NULL == p) | 92 | if (NULL == p) |
93 | { | ||
94 | kwait (pid); | ||
95 | return -1; | ||
96 | } | ||
97 | while (NULL != fgets (line, sizeof (line), p)) | ||
98 | { | ||
99 | if (u->count >= MAX_ENTRIES) | ||
100 | break; | ||
101 | if (line[strlen (line) - 1] == '\n') | ||
102 | { | 93 | { |
103 | line[strlen (line) - 1] = '\0'; | 94 | kwait(pid); |
104 | if (AF_INET == af) | 95 | return -1; |
105 | { | 96 | } |
106 | if (inet_pton (af, line, &u->data.ipv4[u->count])) | 97 | while (NULL != fgets(line, sizeof(line), p)) |
107 | { | 98 | { |
108 | u->count++; | 99 | if (u->count >= MAX_ENTRIES) |
109 | u->data_len += sizeof (ipv4_address_t); | 100 | break; |
110 | } | 101 | if (line[strlen(line) - 1] == '\n') |
111 | else | ||
112 | { | ||
113 | (void) fclose (p); | ||
114 | kwait (pid); | ||
115 | errno = EINVAL; | ||
116 | return -1; | ||
117 | } | ||
118 | } | ||
119 | else if (AF_INET6 == af) | ||
120 | { | ||
121 | if (inet_pton (af, line, &u->data.ipv6[u->count])) | ||
122 | { | ||
123 | u->count++; | ||
124 | u->data_len += sizeof (ipv6_address_t); | ||
125 | } | ||
126 | else | ||
127 | { | 102 | { |
128 | (void) fclose (p); | 103 | line[strlen(line) - 1] = '\0'; |
129 | kwait (pid); | 104 | if (AF_INET == af) |
130 | errno = EINVAL; | 105 | { |
131 | return -1; | 106 | if (inet_pton(af, line, &u->data.ipv4[u->count])) |
107 | { | ||
108 | u->count++; | ||
109 | u->data_len += sizeof(ipv4_address_t); | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | (void)fclose(p); | ||
114 | kwait(pid); | ||
115 | errno = EINVAL; | ||
116 | return -1; | ||
117 | } | ||
118 | } | ||
119 | else if (AF_INET6 == af) | ||
120 | { | ||
121 | if (inet_pton(af, line, &u->data.ipv6[u->count])) | ||
122 | { | ||
123 | u->count++; | ||
124 | u->data_len += sizeof(ipv6_address_t); | ||
125 | } | ||
126 | else | ||
127 | { | ||
128 | (void)fclose(p); | ||
129 | kwait(pid); | ||
130 | errno = EINVAL; | ||
131 | return -1; | ||
132 | } | ||
133 | } | ||
132 | } | 134 | } |
133 | } | ||
134 | } | 135 | } |
135 | } | 136 | (void)fclose(p); |
136 | (void) fclose (p); | 137 | waitpid(pid, &ret, 0); |
137 | waitpid (pid, &ret, 0); | 138 | if (!WIFEXITED(ret)) |
138 | if (! WIFEXITED (ret)) | ||
139 | return -1; | 139 | return -1; |
140 | if (4 == WEXITSTATUS (ret)) | 140 | if (4 == WEXITSTATUS(ret)) |
141 | return -2; /* not for GNS */ | 141 | return -2; /* not for GNS */ |
142 | if (3 == ret) | 142 | if (3 == ret) |
143 | return -3; /* timeout -> not found */ | 143 | return -3; /* timeout -> not found */ |
144 | if ((2 == WEXITSTATUS (ret)) || (1 == WEXITSTATUS (ret))) | 144 | if ((2 == WEXITSTATUS(ret)) || (1 == WEXITSTATUS(ret))) |
145 | return -2; /* launch failure -> service unavailable */ | 145 | return -2; /* launch failure -> service unavailable */ |
146 | return 0; | 146 | return 0; |
147 | } | 147 | } |
diff --git a/src/gns/nss/nss_gns_query.h b/src/gns/nss/nss_gns_query.h index 30ba76fd9..1901dd6c4 100644 --- a/src/gns/nss/nss_gns_query.h +++ b/src/gns/nss/nss_gns_query.h | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | #ifndef NSS_GNS_QUERY_H | 20 | #ifndef NSS_GNS_QUERY_H |
21 | #define NSS_GNS_QUERY_H | 21 | #define NSS_GNS_QUERY_H |
22 | 22 | ||
@@ -28,20 +28,17 @@ | |||
28 | /* Maximum number of entries to return */ | 28 | /* Maximum number of entries to return */ |
29 | #define MAX_ENTRIES 16 | 29 | #define MAX_ENTRIES 16 |
30 | 30 | ||
31 | typedef struct | 31 | typedef struct { |
32 | { | ||
33 | uint32_t address; | 32 | uint32_t address; |
34 | } ipv4_address_t; | 33 | } ipv4_address_t; |
35 | 34 | ||
36 | 35 | ||
37 | typedef struct | 36 | typedef struct { |
38 | { | ||
39 | uint8_t address[16]; | 37 | uint8_t address[16]; |
40 | } ipv6_address_t; | 38 | } ipv6_address_t; |
41 | 39 | ||
42 | 40 | ||
43 | struct userdata | 41 | struct userdata { |
44 | { | ||
45 | int count; | 42 | int count; |
46 | int data_len; /* only valid when doing reverse lookup */ | 43 | int data_len; /* only valid when doing reverse lookup */ |
47 | union { | 44 | union { |