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

Function client_name

clientname.c:100–156  ·  view source on GitHub ↗

* Return the DNS name of the client. * * The name is statically cached so that repeated lookups are quick, * so there is a limit of one lookup per customer. * * If anything goes wrong, including the name->addr->name check, then * we just use "UNKNOWN", so you can use that value in hosts allow * lines. * * After translation from sockaddr to name we do a forward lookup to * make sure nobod

Source from the content-addressed store, hash-verified

98 * make sure nobody is spoofing PTR records.
99 **/
100char *client_name(const char *ipaddr)
101{
102 static char name_buf[100];
103 char port_buf[100];
104 struct sockaddr_storage ss;
105 socklen_t ss_len;
106 struct addrinfo hint, *answer;
107 int err;
108
109 if (*name_buf)
110 return name_buf;
111
112 strlcpy(name_buf, default_name, sizeof name_buf);
113
114 if (strcmp(ipaddr, "0.0.0.0") == 0)
115 return name_buf;
116
117 memset(&ss, 0, sizeof ss);
118 memset(&hint, 0, sizeof hint);
119
120#ifdef AI_NUMERICHOST
121 hint.ai_flags = AI_NUMERICHOST;
122#endif
123 hint.ai_socktype = SOCK_STREAM;
124
125 if ((err = getaddrinfo(ipaddr, NULL, &hint, &answer)) != 0) {
126 rprintf(FLOG, "malformed address %s: %s\n", ipaddr, gai_strerror(err));
127 return name_buf;
128 }
129
130 switch (answer->ai_family) {
131 case AF_INET:
132 ss_len = sizeof (struct sockaddr_in);
133 memcpy(&ss, answer->ai_addr, ss_len);
134 break;
135#ifdef INET6
136 case AF_INET6:
137 ss_len = sizeof (struct sockaddr_in6);
138 memcpy(&ss, answer->ai_addr, ss_len);
139 break;
140#endif
141 default:
142 NOISY_DEATH("Unknown ai_family value");
143 }
144 freeaddrinfo(answer);
145
146 /* reverse lookup */
147 err = getnameinfo((struct sockaddr*)&ss, ss_len, name_buf, sizeof name_buf,
148 port_buf, sizeof port_buf, NI_NAMEREQD | NI_NUMERICSERV);
149 if (err) {
150 strlcpy(name_buf, default_name, sizeof name_buf);
151 rprintf(FLOG, "name lookup failed for %s: %s\n", ipaddr, gai_strerror(err));
152 } else
153 check_name(ipaddr, &ss, name_buf, sizeof name_buf);
154
155 return name_buf;
156}
157

Callers 3

log_formattedFunction · 0.85
rsync_moduleFunction · 0.85
start_daemonFunction · 0.85

Calls 7

strlcpyFunction · 0.85
getaddrinfoFunction · 0.85
gai_strerrorFunction · 0.85
freeaddrinfoFunction · 0.85
getnameinfoFunction · 0.85
check_nameFunction · 0.85
rprintfFunction · 0.70

Tested by

no test coverage detected