-int lookup_name(int fd, const struct sockaddr_storage *ss,
- socklen_t ss_len,
- char *name_buf, size_t name_buf_len,
- char *port_buf, size_t port_buf_len)
-{
- int name_err;
-
- /* reverse lookup */
- name_err = getnameinfo((struct sockaddr *) ss, ss_len,
- name_buf, name_buf_len,
- port_buf, port_buf_len,
- NI_NAMEREQD | NI_NUMERICSERV);
- if (name_err != 0) {
- strcpy(name_buf, default_name);
- rprintf(FERROR, RSYNC_NAME ": name lookup failed for %s: %s\n",
- client_addr(fd),
- gai_strerror(name_err));
- return name_err;
- }
-
- return 0;
-}
-
-
-
-/* Do a forward lookup on name_buf and make sure it corresponds to ss
- * -- otherwise we may be being spoofed. If we suspect we are, then
- * we don't abort the connection but just emit a warning. */
-int check_name(int fd,
- const struct sockaddr_storage *ss,
- socklen_t ss_len,
- char *name_buf,
- const char *port_buf)
-{
- struct addrinfo hints, *res, *res0;
- int error;
- int ss_family = get_sockaddr_family(ss);
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_flags = ss_family;
- hints.ai_socktype = SOCK_STREAM;
- error = getaddrinfo(name_buf, port_buf, &hints, &res0);
- if (error) {
- rprintf(FERROR,
- RSYNC_NAME ": forward name lookup for %s:%s failed: %s\n",
- name_buf, port_buf,
- gai_strerror(error));
- strcpy(name_buf, default_name);
- return error;
- }
-
-
- /* We expect that one of the results will be the same as ss. */
- for (res = res0; res; res = res->ai_next) {
- if (res->ai_family != ss_family) {
- rprintf(FERROR,
- "check_name: response family %d != %d\n",
- res->ai_family, ss_family);
- continue;
- }
- if (res->ai_addrlen != ss_len) {
- rprintf(FERROR,
- "check_name: addrlen %d != %d\n",
- res->ai_addrlen, ss_len);
- continue;
- }
- if (memcmp(res->ai_addr, ss, res->ai_addrlen) == 0) {
- rprintf(FERROR,
- "check_name: %d bytes of address identical\n",
- res->ai_addrlen);
- break;
- } else{
- rprintf(FERROR,
- "check_name: %d bytes of address NOT identical\n",
- res->ai_addrlen);
- }
- }
-
- if (!res0) {
- /* We hit the end of the list without finding an
- * address that was the same as ss. */
- rprintf(FERROR, RSYNC_NAME
- ": no known address for \"%s\": "
- "spoofed address?\n",
- name_buf);
- strcpy(name_buf, default_name);
- }
- if (res == NULL) {
- /* We hit the end of the list without finding an
- * address that was the same as ss. */
- rprintf(FERROR, RSYNC_NAME
- ": %s is not a known address for \"%s\": "
- "spoofed address?\n",
- client_addr(fd),
- name_buf);
- strcpy(name_buf, default_name);
- }
-
- freeaddrinfo(res0);
- return 0;
-}
-
-
-/*******************************************************************
-this is like socketpair but uses tcp. It is used by the Samba
-regression test code
-The function guarantees that nobody else can attach to the socket,
-or if they do that this function fails and the socket gets closed
-returns 0 on success, -1 on failure
-the resulting file descriptors are symmetrical
- ******************************************************************/