View | Details | Raw Unified | Return to bug 53188
Collapse All | Expand All

(-)a/cldap_ping.c (-1 / +1 lines)
Lines 279-285 int netlogon_get_client_site(char *netlogon_response, size_t netlogon_size, char Link Here
279
	for (int i=0; i < 8; i++) {
279
	for (int i=0; i < 8; i++) {
280
		// iterate over DnsForestName, DnsDomainName, NetbiosDomainName, NetbiosComputerName, UserName, DcSiteName
280
		// iterate over DnsForestName, DnsDomainName, NetbiosDomainName, NetbiosComputerName, UserName, DcSiteName
281
		// to finally get to our desired ClientSiteName field
281
		// to finally get to our desired ClientSiteName field
282
		if (read_dns_string(netlogon_response, netlogon_size, sitename, MAXCDNAME, &offset) < 0) {
282
		if (read_dns_string(netlogon_response, netlogon_size, sitename, MAXLABEL, &offset) < 0) {
283
			return CLDAP_PING_PARSE_ERROR_NETLOGON;
283
			return CLDAP_PING_PARSE_ERROR_NETLOGON;
284
		}
284
		}
285
	}
285
	}
(-)a/cldap_ping.h (-1 / +1 lines)
Lines 8-14 Link Here
8
8
9
// returns CLDAP_PING_TRYNEXT if you should use another dc
9
// returns CLDAP_PING_TRYNEXT if you should use another dc
10
// any other error code < 0 is a fatal error
10
// any other error code < 0 is a fatal error
11
// site_name must be of MAXCDNAME size!
11
// site_name must be of MAXLABEL size!
12
int cldap_ping(char *domain, sa_family_t family, void *addr, char *site_name);
12
int cldap_ping(char *domain, sa_family_t family, void *addr, char *site_name);
13
13
14
#endif /* _CLDAP_PING_H_ */
14
#endif /* _CLDAP_PING_H_ */
(-)a/mount.cifs.c (-11 / +17 lines)
Lines 186-191 struct parsed_mount_info { Link Here
186
	char username[MAX_USERNAME_SIZE + 1];
186
	char username[MAX_USERNAME_SIZE + 1];
187
	char password[MOUNT_PASSWD_SIZE + 1];
187
	char password[MOUNT_PASSWD_SIZE + 1];
188
	char addrlist[MAX_ADDR_LIST_LEN];
188
	char addrlist[MAX_ADDR_LIST_LEN];
189
	char hostlist[MAX_HOST_LIST_LEN];
189
	unsigned int got_user:1;
190
	unsigned int got_user:1;
190
	unsigned int got_password:1;
191
	unsigned int got_password:1;
191
	unsigned int fakemnt:1;
192
	unsigned int fakemnt:1;
Lines 1845-1850 assemble_mountinfo(struct parsed_mount_info *parsed_info, Link Here
1845
{
1846
{
1846
	int rc;
1847
	int rc;
1847
	char *newopts = NULL;
1848
	char *newopts = NULL;
1849
	char *hostlist;
1848
1850
1849
	rc = drop_capabilities(0);
1851
	rc = drop_capabilities(0);
1850
	if (rc)
1852
	if (rc)
Lines 1889-1896 assemble_mountinfo(struct parsed_mount_info *parsed_info, Link Here
1889
	if (rc)
1891
	if (rc)
1890
		goto assemble_exit;
1892
		goto assemble_exit;
1891
1893
1894
	parsed_info->hostlist[0] = '\0';
1892
	if (parsed_info->addrlist[0] == '\0') {
1895
	if (parsed_info->addrlist[0] == '\0') {
1893
		rc = resolve_host(parsed_info->host, parsed_info->addrlist);
1896
		hostlist = parsed_info->is_krb5 ? parsed_info->hostlist : NULL;
1897
		rc = resolve_host_with_names(parsed_info->host, parsed_info->addrlist, hostlist);
1894
		if (rc == 0 && parsed_info->verboseflag)
1898
		if (rc == 0 && parsed_info->verboseflag)
1895
			fprintf(stderr, "Host \"%s\" resolved to the following IP addresses: %s\n", parsed_info->host, parsed_info->addrlist);
1899
			fprintf(stderr, "Host \"%s\" resolved to the following IP addresses: %s\n", parsed_info->host, parsed_info->addrlist);
1896
	}
1900
	}
Lines 2047-2052 int main(int argc, char **argv) Link Here
2047
	char *options = NULL;
2051
	char *options = NULL;
2048
	char *orig_dev = NULL;
2052
	char *orig_dev = NULL;
2049
	char *currentaddress, *nextaddress;
2053
	char *currentaddress, *nextaddress;
2054
	char *currenthost, *nexthost;
2050
	char *value = NULL;
2055
	char *value = NULL;
2051
	char *ep = NULL;
2056
	char *ep = NULL;
2052
	int rc = 0;
2057
	int rc = 0;
Lines 2205-2216 assemble_retry: Link Here
2205
	}
2210
	}
2206
2211
2207
	currentaddress = parsed_info->addrlist;
2212
	currentaddress = parsed_info->addrlist;
2208
	nextaddress = strchr(currentaddress, ',');
2213
	nextaddress = NULL;
2209
	if (nextaddress)
2214
	currenthost = parsed_info->hostlist;
2210
		*nextaddress++ = '\0';
2215
	nexthost = NULL;
2211
2216
2212
mount_retry:
2217
mount_retry:
2213
	options[0] = '\0';
2218
	options[0] = '\0';
2219
	iterlist(&currentaddress, &nextaddress);
2220
	iterlist(&currenthost, &nexthost);
2214
	if (!currentaddress) {
2221
	if (!currentaddress) {
2215
		fprintf(stderr, "Unable to find suitable address.\n");
2222
		fprintf(stderr, "Unable to find suitable address.\n");
2216
		rc = parsed_info->nofail ? 0 : EX_FAIL;
2223
		rc = parsed_info->nofail ? 0 : EX_FAIL;
Lines 2234-2242 mount_retry: Link Here
2234
		strlcat(options, parsed_info->prefix, options_size);
2241
		strlcat(options, parsed_info->prefix, options_size);
2235
	}
2242
	}
2236
2243
2237
	if (sloppy)
2244
	if (sloppy || currenthost)
2238
		strlcat(options, ",sloppy", options_size);
2245
		strlcat(options, ",sloppy", options_size);
2239
2246
2247
	if (currenthost) {
2248
		strlcat(options, ",hostname=", options_size);
2249
		strlcat(options, currenthost, options_size);
2250
	}
2251
2240
	if (parsed_info->verboseflag)
2252
	if (parsed_info->verboseflag)
2241
		fprintf(stderr, "%s kernel mount options: %s",
2253
		fprintf(stderr, "%s kernel mount options: %s",
2242
			thisprogram, options);
2254
			thisprogram, options);
Lines 2273-2284 mount_retry: Link Here
2273
				fprintf(stderr, "mount error(%d): could not connect to %s",
2285
				fprintf(stderr, "mount error(%d): could not connect to %s",
2274
					errno, currentaddress);
2286
					errno, currentaddress);
2275
			}
2287
			}
2276
			currentaddress = nextaddress;
2277
			if (currentaddress) {
2278
				nextaddress = strchr(currentaddress, ',');
2279
				if (nextaddress)
2280
					*nextaddress++ = '\0';
2281
			}
2282
			goto mount_retry;
2288
			goto mount_retry;
2283
		case ENODEV:
2289
		case ENODEV:
2284
			fprintf(stderr,
2290
			fprintf(stderr,
(-)a/resolve_host.c (-7 / +36 lines)
Lines 37-43 Link Here
37
/*
37
/*
38
 * resolve hostname to comma-separated list of address(es)
38
 * resolve hostname to comma-separated list of address(es)
39
 */
39
 */
40
int resolve_host(const char *host, char *addrstr) {
40
int resolve_host_with_names(const char *host, char *addrstr, char *hoststr) {
41
	int rc;
41
	int rc;
42
	/* 10 for max width of decimal scopeid */
42
	/* 10 for max width of decimal scopeid */
43
	char tmpbuf[NI_MAXHOST + 1 + 10 + 1];
43
	char tmpbuf[NI_MAXHOST + 1 + 10 + 1];
Lines 114-120 int resolve_host(const char *host, char *addrstr) { Link Here
114
114
115
115
116
	// Is this a DFS domain where we need to do a cldap ping to find the closest node?
116
	// Is this a DFS domain where we need to do a cldap ping to find the closest node?
117
	if (count_v4 > 1 || count_v6 > 1) {
117
	if (count_v4 > 1 || count_v6 > 1 || hoststr) {
118
		int res;
118
		int res;
119
		ns_msg global_domain_handle;
119
		ns_msg global_domain_handle;
120
		unsigned char global_domain_lookup[4096];
120
		unsigned char global_domain_lookup[4096];
Lines 122-127 int resolve_host(const char *host, char *addrstr) { Link Here
122
		unsigned char site_domain_lookup[4096];
122
		unsigned char site_domain_lookup[4096];
123
		char dname[MAXCDNAME];
123
		char dname[MAXCDNAME];
124
		int srv_cnt;
124
		int srv_cnt;
125
		int number_addresses = 0;
126
		const char *hostname;
125
127
126
		res = res_init();
128
		res = res_init();
127
		if (res != 0)
129
		if (res != 0)
Lines 144-150 int resolve_host(const char *host, char *addrstr) { Link Here
144
146
145
		// No or just one DC we are done
147
		// No or just one DC we are done
146
		if (srv_cnt < 2)
148
		if (srv_cnt < 2)
147
			goto resolve_host_out;
149
			goto resolve_host_global;
148
150
149
		char site_name[MAXCDNAME];
151
		char site_name[MAXCDNAME];
150
		// We assume that AD always sends the ip addresses in the addtional data block
152
		// We assume that AD always sends the ip addresses in the addtional data block
Lines 199-205 int resolve_host(const char *host, char *addrstr) { Link Here
199
		if (res < 0)
201
		if (res < 0)
200
			goto resolve_host_out;
202
			goto resolve_host_out;
201
203
202
		int number_addresses = 0;
203
		for (int i = 0; i < ns_msg_count(site_domain_handle, ns_s_ar); i++) {
204
		for (int i = 0; i < ns_msg_count(site_domain_handle, ns_s_ar); i++) {
204
			if (i > MAX_ADDRESSES)
205
			if (i > MAX_ADDRESSES)
205
				break;
206
				break;
Lines 213-218 int resolve_host(const char *host, char *addrstr) { Link Here
213
				case ns_t_aaaa:
214
				case ns_t_aaaa:
214
					if (ns_rr_rdlen(rr) != NS_IN6ADDRSZ)
215
					if (ns_rr_rdlen(rr) != NS_IN6ADDRSZ)
215
						continue;
216
						continue;
217
					hostname = ns_rr_name(rr);
216
					ipaddr = inet_ntop(AF_INET6, ns_rr_rdata(rr), tmpbuf,
218
					ipaddr = inet_ntop(AF_INET6, ns_rr_rdata(rr), tmpbuf,
217
									   sizeof(tmpbuf));
219
									   sizeof(tmpbuf));
218
					if (!ipaddr) {
220
					if (!ipaddr) {
Lines 223-228 int resolve_host(const char *host, char *addrstr) { Link Here
223
				case ns_t_a:
225
				case ns_t_a:
224
					if (ns_rr_rdlen(rr) != NS_INADDRSZ)
226
					if (ns_rr_rdlen(rr) != NS_INADDRSZ)
225
						continue;
227
						continue;
228
					hostname = ns_rr_name(rr);
226
					ipaddr = inet_ntop(AF_INET, ns_rr_rdata(rr), tmpbuf,
229
					ipaddr = inet_ntop(AF_INET, ns_rr_rdata(rr), tmpbuf,
227
									   sizeof(tmpbuf));
230
									   sizeof(tmpbuf));
228
					if (!ipaddr) {
231
					if (!ipaddr) {
Lines 236-249 int resolve_host(const char *host, char *addrstr) { Link Here
236
239
237
			number_addresses++;
240
			number_addresses++;
238
241
239
			if (i == 0)
242
			if (i == 0) {
240
				*addrstr = '\0';
243
				*addrstr = '\0';
241
			else
244
				if (hoststr)
245
					*hoststr = '\0';
246
			} else {
242
				strlcat(addrstr, ",", MAX_ADDR_LIST_LEN);
247
				strlcat(addrstr, ",", MAX_ADDR_LIST_LEN);
248
				if (hoststr)
249
					strlcat(hoststr, ",", MAX_ADDR_LIST_LEN);
250
			}
243
251
244
			strlcat(addrstr, tmpbuf, MAX_ADDR_LIST_LEN);
252
			strlcat(addrstr, tmpbuf, MAX_ADDR_LIST_LEN);
253
			if (hoststr)
254
				strlcat(hoststr, hostname, MAX_HOST_LIST_LEN);
245
		}
255
		}
246
256
257
resolve_host_global:
247
		// Preferred site ips is now the first entry in addrstr, fill up with other sites till MAX_ADDRESS
258
		// Preferred site ips is now the first entry in addrstr, fill up with other sites till MAX_ADDRESS
248
		for (int i = 0; i < ns_msg_count(global_domain_handle, ns_s_ar); i++) {
259
		for (int i = 0; i < ns_msg_count(global_domain_handle, ns_s_ar); i++) {
249
			if (number_addresses > MAX_ADDRESSES)
260
			if (number_addresses > MAX_ADDRESSES)
Lines 258-263 int resolve_host(const char *host, char *addrstr) { Link Here
258
				case ns_t_aaaa:
269
				case ns_t_aaaa:
259
					if (ns_rr_rdlen(rr) != NS_IN6ADDRSZ)
270
					if (ns_rr_rdlen(rr) != NS_IN6ADDRSZ)
260
						continue;
271
						continue;
272
					hostname = ns_rr_name(rr);
261
					ipaddr = inet_ntop(AF_INET6, ns_rr_rdata(rr), tmpbuf,
273
					ipaddr = inet_ntop(AF_INET6, ns_rr_rdata(rr), tmpbuf,
262
									   sizeof(tmpbuf));
274
									   sizeof(tmpbuf));
263
					if (!ipaddr) {
275
					if (!ipaddr) {
Lines 268-273 int resolve_host(const char *host, char *addrstr) { Link Here
268
				case ns_t_a:
280
				case ns_t_a:
269
					if (ns_rr_rdlen(rr) != NS_INADDRSZ)
281
					if (ns_rr_rdlen(rr) != NS_INADDRSZ)
270
						continue;
282
						continue;
283
					hostname = ns_rr_name(rr);
271
					ipaddr = inet_ntop(AF_INET, ns_rr_rdata(rr), tmpbuf,
284
					ipaddr = inet_ntop(AF_INET, ns_rr_rdata(rr), tmpbuf,
272
									   sizeof(tmpbuf));
285
									   sizeof(tmpbuf));
273
					if (!ipaddr) {
286
					if (!ipaddr) {
Lines 279-284 int resolve_host(const char *host, char *addrstr) { Link Here
279
					continue;
292
					continue;
280
			}
293
			}
281
294
295
			if (number_addresses == 0) {
296
				*addrstr = '\0';
297
				if (hoststr)
298
					*hoststr = '\0';
299
			}
300
282
			char *found = strstr(addrstr, tmpbuf);
301
			char *found = strstr(addrstr, tmpbuf);
283
302
284
			if (found) {
303
			if (found) {
Lines 292-300 int resolve_host(const char *host, char *addrstr) { Link Here
292
				}
311
				}
293
			}
312
			}
294
313
314
			if (number_addresses > 0) {
315
				strlcat(addrstr, ",", MAX_ADDR_LIST_LEN);
316
				if (hoststr)
317
					strlcat(hoststr, ",", MAX_HOST_LIST_LEN);
318
			}
295
			number_addresses++;
319
			number_addresses++;
296
			strlcat(addrstr, ",", MAX_ADDR_LIST_LEN);
297
			strlcat(addrstr, tmpbuf, MAX_ADDR_LIST_LEN);
320
			strlcat(addrstr, tmpbuf, MAX_ADDR_LIST_LEN);
321
			if (hoststr)
322
				strlcat(hoststr, hostname, MAX_HOST_LIST_LEN);
298
		}
323
		}
299
	}
324
	}
300
325
Lines 302-304 resolve_host_out: Link Here
302
	freeaddrinfo(addrlist);
327
	freeaddrinfo(addrlist);
303
	return rc;
328
	return rc;
304
}
329
}
330
331
int resolve_host(const char *host, char *addrstr) {
332
	return resolve_host_with_names(host, addrstr, NULL);
333
}
(-)a/resolve_host.h (+5 lines)
Lines 22-27 Link Here
22
#define _RESOLVE_HOST_H_
22
#define _RESOLVE_HOST_H_
23
23
24
#include <arpa/inet.h>
24
#include <arpa/inet.h>
25
#include <resolv.h>
25
26
26
/* currently maximum length of IPv6 address string */
27
/* currently maximum length of IPv6 address string */
27
#define MAX_ADDRESS_LEN INET6_ADDRSTRLEN
28
#define MAX_ADDRESS_LEN INET6_ADDRSTRLEN
Lines 31-36 Link Here
31
/* limit list of addresses to MAX_ADDRESSES max-size addrs */
32
/* limit list of addresses to MAX_ADDRESSES max-size addrs */
32
#define MAX_ADDR_LIST_LEN ((MAX_ADDRESS_LEN + 1) * MAX_ADDRESSES)
33
#define MAX_ADDR_LIST_LEN ((MAX_ADDRESS_LEN + 1) * MAX_ADDRESSES)
33
34
35
/* limit list of hostnames to MAX_ADDRESSES max-size names */
36
#define MAX_HOST_LIST_LEN ((MAXCDNAME + 1) * MAX_ADDRESSES)
37
38
extern int resolve_host_with_names(const char *host, char *addrstr, char *hoststr);
34
extern int resolve_host(const char *host, char *addrstr);
39
extern int resolve_host(const char *host, char *addrstr);
35
40
36
#endif /* _RESOLVE_HOST_H_ */
41
#endif /* _RESOLVE_HOST_H_ */
(-)a/util.c (+14 lines)
Lines 83-85 getusername(uid_t uid) Link Here
83
	return username;
83
	return username;
84
}
84
}
85
85
86
int
87
iterlist(char **curr, char **next) {
88
    if (!*curr || *curr[0] == '\0' || *curr == *next) {
89
        *curr = *next = NULL;
90
        return 0;
91
    }
92
    *curr = *next ? *next : *curr;
93
    *next = strchr(*curr, ',');
94
    if (*next)
95
        *(*next)++ = '\0';
96
    else
97
        *next = *curr;
98
    return 1;
99
}
(-)a/util.h (+1 lines)
Lines 29-33 extern size_t strlcpy(char *d, const char *s, size_t bufsize); Link Here
29
extern size_t strlcat(char *d, const char *s, size_t bufsize);
29
extern size_t strlcat(char *d, const char *s, size_t bufsize);
30
30
31
extern char *getusername(uid_t uid);
31
extern char *getusername(uid_t uid);
32
extern int iterlist(char **curr, char **next);
32
#endif /* _LIBUTIL_H */
33
#endif /* _LIBUTIL_H */
33
34

Return to bug 53188