MCPcopy Index your code
hub / github.com/RsyncProject/rsync / match_hostname

Function match_hostname

access.c:31–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29extern const char undetermined_hostname[];
30
31static int match_hostname(const char **host_ptr, const char *addr, const char *tok)
32{
33 struct hostent *hp;
34 unsigned int i;
35 const char *host = *host_ptr;
36
37 if (!host || !*host)
38 return 0;
39
40#ifdef HAVE_INNETGR
41 if (*tok == '@' && tok[1])
42 return innetgr(tok + 1, host, NULL, NULL);
43#endif
44
45 /* First check if the reverse-DNS-determined hostname matches. */
46 if (iwildmatch(tok, host))
47 return 1;
48
49 if (!allow_forward_dns)
50 return 0;
51
52 /* Fail quietly if tok is an address or wildcarded entry, not a simple hostname. */
53 if (!tok[strspn(tok, ".0123456789")] || tok[strcspn(tok, ":/*?[")])
54 return 0;
55
56 /* Now try forward-DNS on the token (config-specified hostname) and see if the IP matches. */
57 if (!(hp = gethostbyname(tok)))
58 return 0;
59
60 for (i = 0; hp->h_addr_list[i] != NULL; i++) {
61 if (strcmp(addr, inet_ntoa(*(struct in_addr*)(hp->h_addr_list[i]))) == 0) {
62 /* If reverse lookups are off, we'll use the conf-specified
63 * hostname in preference to UNDETERMINED. */
64 if (host == undetermined_hostname)
65 *host_ptr = strdup(tok);
66 return 1;
67 }
68 }
69
70 return 0;
71}
72
73static int match_binary(const char *b1, const char *b2, const char *mask, int addrlen)
74{

Callers 1

access_matchFunction · 0.85

Calls 1

iwildmatchFunction · 0.85

Tested by

no test coverage detected