-/* $OpenBSD: ypbind.c,v 1.74 2020/12/29 19:48:49 benno Exp $ */
+/* $OpenBSD: ypbind.c,v 1.75 2022/07/15 16:59:49 deraadt Exp $ */
/*
* Copyright (c) 1992, 1993, 1996, 1997, 1998 Theo de Raadt <deraadt@openbsd.org>
rpc_received(char *dom, struct sockaddr_in *raddrp, int force)
{
struct _dom_binding *ypdb;
- struct iovec iov[2];
+ struct iovec iov[3];
struct ypbind_resp ybr;
char path[PATH_MAX];
+ u_short ypserv_tcp, ypserv_udp;
int fd;
if (strchr(dom, '/'))
return;
}
+ /* syncronously ask for the matching ypserv TCP port number */
+ ypserv_udp = raddrp->sin_port;
+ ypserv_tcp = pmap_getport(raddrp, YPPROG,
+ YPVERS, IPPROTO_TCP);
+ if (ypserv_tcp == 0) {
+ clnt_pcreateerror("pmap_getport");
+ return;
+ }
+ if (ypserv_tcp >= IPPORT_RESERVED || ypserv_tcp == 20)
+ return;
+ ypserv_tcp = htons(ypserv_tcp);
+
memcpy(&ypdb->dom_server_addr, raddrp, sizeof ypdb->dom_server_addr);
/* recheck binding in 60 seconds */
ypdb->dom_check_t = time(NULL) + 60;
iov[0].iov_len = sizeof udptransp->xp_port;
iov[1].iov_base = (caddr_t)&ybr;
iov[1].iov_len = sizeof ybr;
+ iov[2].iov_base = (caddr_t)&ypserv_tcp;
+ iov[2].iov_len = sizeof ypserv_tcp;
memset(&ybr, 0, sizeof ybr);
ybr.ypbind_status = YPBIND_SUCC_VAL;
&raddrp->sin_addr,
sizeof(ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr));
memmove(&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port,
- &raddrp->sin_port,
+ &ypserv_udp,
sizeof(ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port));
- if (writev(ypdb->dom_lockfd, iov, 2) != iov[0].iov_len + iov[1].iov_len) {
+ if (writev(ypdb->dom_lockfd, iov, sizeof(iov)/sizeof(iov[0])) !=
+ iov[0].iov_len + iov[1].iov_len + iov[2].iov_len) {
perror("write");
close(ypdb->dom_lockfd);
unlink(path);