diff options
Diffstat (limited to 'src/gns/nss/nss_gns.c')
-rw-r--r-- | src/gns/nss/nss_gns.c | 193 |
1 files changed, 97 insertions, 96 deletions
diff --git a/src/gns/nss/nss_gns.c b/src/gns/nss/nss_gns.c index 43fc030b9..beae4d15e 100644 --- a/src/gns/nss/nss_gns.c +++ b/src/gns/nss/nss_gns.c | |||
@@ -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 | /** |
@@ -55,13 +55,13 @@ | |||
55 | * @return a nss_status code | 55 | * @return a nss_status code |
56 | */ | 56 | */ |
57 | enum nss_status | 57 | enum nss_status |
58 | _nss_gns_gethostbyname2_r(const char *name, | 58 | _nss_gns_gethostbyname2_r (const char *name, |
59 | int af, | 59 | int af, |
60 | struct hostent *result, | 60 | struct hostent *result, |
61 | char *buffer, | 61 | char *buffer, |
62 | size_t buflen, | 62 | size_t buflen, |
63 | int *errnop, | 63 | int *errnop, |
64 | int *h_errnop) | 64 | int *h_errnop) |
65 | { | 65 | { |
66 | struct userdata u; | 66 | struct userdata u; |
67 | enum nss_status status = NSS_STATUS_UNAVAIL; | 67 | enum nss_status status = NSS_STATUS_UNAVAIL; |
@@ -86,97 +86,98 @@ _nss_gns_gethostbyname2_r(const char *name, | |||
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) : |
97 | sizeof(ipv6_address_t); | ||
97 | if (buflen < | 98 | if (buflen < |
98 | sizeof(char*) + /* alias names */ | 99 | sizeof(char*) /* alias names */ |
99 | strlen(name) + 1) | 100 | + strlen (name) + 1) |
100 | { /* official name */ | 101 | { /* official name */ |
101 | *errnop = ERANGE; | 102 | *errnop = ERANGE; |
102 | *h_errnop = NO_RECOVERY; | 103 | *h_errnop = NO_RECOVERY; |
103 | status = NSS_STATUS_TRYAGAIN; | 104 | status = NSS_STATUS_TRYAGAIN; |
104 | 105 | ||
105 | goto finish; | 106 | goto finish; |
106 | } | 107 | } |
107 | u.count = 0; | 108 | u.count = 0; |
108 | u.data_len = 0; | 109 | u.data_len = 0; |
109 | i = gns_resolve_name(af, | 110 | i = gns_resolve_name (af, |
110 | name, | 111 | name, |
111 | &u); | 112 | &u); |
112 | if (-1 == i) | 113 | if (-1 == i) |
113 | { | 114 | { |
114 | *errnop = errno; | 115 | *errnop = errno; |
115 | status = NSS_STATUS_UNAVAIL; | 116 | status = NSS_STATUS_UNAVAIL; |
116 | *h_errnop = NO_RECOVERY; | 117 | *h_errnop = NO_RECOVERY; |
117 | goto finish; | 118 | goto finish; |
118 | } | 119 | } |
119 | if (-2 == i) | 120 | if (-2 == i) |
120 | { | 121 | { |
121 | *errnop = ENOENT; | 122 | *errnop = ENOENT; |
122 | *h_errnop = NO_RECOVERY; | 123 | *h_errnop = NO_RECOVERY; |
123 | status = NSS_STATUS_UNAVAIL; | 124 | status = NSS_STATUS_UNAVAIL; |
124 | goto finish; | 125 | goto finish; |
125 | } | 126 | } |
126 | if (-3 == i) | 127 | if (-3 == i) |
127 | { | 128 | { |
128 | *errnop = ETIMEDOUT; | 129 | *errnop = ETIMEDOUT; |
129 | *h_errnop = HOST_NOT_FOUND; | 130 | *h_errnop = HOST_NOT_FOUND; |
130 | status = NSS_STATUS_NOTFOUND; | 131 | status = NSS_STATUS_NOTFOUND; |
131 | goto finish; | 132 | goto finish; |
132 | } | 133 | } |
133 | if (0 == u.count) | 134 | if (0 == u.count) |
134 | { | 135 | { |
135 | *errnop = 0; /* success */ | 136 | *errnop = 0; /* success */ |
136 | *h_errnop = NO_DATA; /* success */ | 137 | *h_errnop = NO_DATA; /* success */ |
137 | status = NSS_STATUS_NOTFOUND; | 138 | status = NSS_STATUS_NOTFOUND; |
138 | goto finish; | 139 | goto finish; |
139 | } | 140 | } |
140 | /* Alias names */ | 141 | /* Alias names */ |
141 | *((char**)buffer) = NULL; | 142 | *((char**) buffer) = NULL; |
142 | result->h_aliases = (char**)buffer; | 143 | result->h_aliases = (char**) buffer; |
143 | idx = sizeof(char*); | 144 | idx = sizeof(char*); |
144 | 145 | ||
145 | /* Official name */ | 146 | /* Official name */ |
146 | strcpy(buffer + idx, | 147 | strcpy (buffer + idx, |
147 | name); | 148 | name); |
148 | result->h_name = buffer + idx; | 149 | result->h_name = buffer + idx; |
149 | idx += strlen(name) + 1; | 150 | idx += strlen (name) + 1; |
150 | 151 | ||
151 | ALIGN(idx); | 152 | ALIGN (idx); |
152 | 153 | ||
153 | result->h_addrtype = af; | 154 | result->h_addrtype = af; |
154 | result->h_length = address_length; | 155 | result->h_length = address_length; |
155 | 156 | ||
156 | /* Check if there's enough space for the addresses */ | 157 | /* Check if there's enough space for the addresses */ |
157 | if (buflen < idx + u.data_len + sizeof(char*) * (u.count + 1)) | 158 | if (buflen < idx + u.data_len + sizeof(char*) * (u.count + 1)) |
158 | { | 159 | { |
159 | *errnop = ERANGE; | 160 | *errnop = ERANGE; |
160 | *h_errnop = NO_RECOVERY; | 161 | *h_errnop = NO_RECOVERY; |
161 | status = NSS_STATUS_TRYAGAIN; | 162 | status = NSS_STATUS_TRYAGAIN; |
162 | goto finish; | 163 | goto finish; |
163 | } | 164 | } |
164 | /* Addresses */ | 165 | /* Addresses */ |
165 | astart = idx; | 166 | astart = idx; |
166 | l = u.count * address_length; | 167 | l = u.count * address_length; |
167 | if (0 != l) | 168 | if (0 != l) |
168 | memcpy(buffer + astart, | 169 | memcpy (buffer + astart, |
169 | &u.data, | 170 | &u.data, |
170 | l); | 171 | l); |
171 | /* address_length is a multiple of 32bits, so idx is still aligned | 172 | /* address_length is a multiple of 32bits, so idx is still aligned |
172 | * correctly */ | 173 | * correctly */ |
173 | idx += l; | 174 | idx += l; |
174 | 175 | ||
175 | /* Address array address_length is always a multiple of 32bits */ | 176 | /* Address array address_length is always a multiple of 32bits */ |
176 | for (i = 0; i < u.count; i++) | 177 | for (i = 0; i < u.count; i++) |
177 | ((char**)(buffer + idx))[i] = buffer + astart + address_length * i; | 178 | ((char**) (buffer + idx))[i] = buffer + astart + address_length * i; |
178 | ((char**)(buffer + idx))[i] = NULL; | 179 | ((char**) (buffer + idx))[i] = NULL; |
179 | result->h_addr_list = (char**)(buffer + idx); | 180 | result->h_addr_list = (char**) (buffer + idx); |
180 | 181 | ||
181 | status = NSS_STATUS_SUCCESS; | 182 | status = NSS_STATUS_SUCCESS; |
182 | 183 | ||
@@ -197,20 +198,20 @@ finish: | |||
197 | * @return a nss_status code | 198 | * @return a nss_status code |
198 | */ | 199 | */ |
199 | enum nss_status | 200 | enum nss_status |
200 | _nss_gns_gethostbyname_r(const char *name, | 201 | _nss_gns_gethostbyname_r (const char *name, |
201 | struct hostent *result, | 202 | struct hostent *result, |
202 | char *buffer, | 203 | char *buffer, |
203 | size_t buflen, | 204 | size_t buflen, |
204 | int *errnop, | 205 | int *errnop, |
205 | int *h_errnop) | 206 | int *h_errnop) |
206 | { | 207 | { |
207 | return _nss_gns_gethostbyname2_r(name, | 208 | return _nss_gns_gethostbyname2_r (name, |
208 | AF_UNSPEC, | 209 | AF_UNSPEC, |
209 | result, | 210 | result, |
210 | buffer, | 211 | buffer, |
211 | buflen, | 212 | buflen, |
212 | errnop, | 213 | errnop, |
213 | h_errnop); | 214 | h_errnop); |
214 | } | 215 | } |
215 | 216 | ||
216 | 217 | ||
@@ -229,21 +230,21 @@ _nss_gns_gethostbyname_r(const char *name, | |||
229 | * @return NSS_STATUS_UNAVAIL | 230 | * @return NSS_STATUS_UNAVAIL |
230 | */ | 231 | */ |
231 | enum nss_status | 232 | enum nss_status |
232 | _nss_gns_gethostbyaddr_r(const void* addr, | 233 | _nss_gns_gethostbyaddr_r (const void*addr, |
233 | int len, | 234 | int len, |
234 | int af, | 235 | int af, |
235 | struct hostent *result, | 236 | struct hostent *result, |
236 | char *buffer, | 237 | char *buffer, |
237 | size_t buflen, | 238 | size_t buflen, |
238 | int *errnop, | 239 | int *errnop, |
239 | int *h_errnop) | 240 | int *h_errnop) |
240 | { | 241 | { |
241 | (void)addr; | 242 | (void) addr; |
242 | (void)len; | 243 | (void) len; |
243 | (void)af; | 244 | (void) af; |
244 | (void)result; | 245 | (void) result; |
245 | (void)buffer; | 246 | (void) buffer; |
246 | (void)buflen; | 247 | (void) buflen; |
247 | *errnop = EINVAL; | 248 | *errnop = EINVAL; |
248 | *h_errnop = NO_RECOVERY; | 249 | *h_errnop = NO_RECOVERY; |
249 | /* NOTE we allow to leak this into DNS so no NOTFOUND */ | 250 | /* NOTE we allow to leak this into DNS so no NOTFOUND */ |