Bug 160295

Summary: [patch] ypserv(8): ypserv -P [bin/109494] breaks tcp
Product: Base System Reporter: Dylan Simon <dylan>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me Keywords: patch
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
yp_main.c.diff none

Description Dylan Simon 2011-08-29 20:30:15 UTC
The -P argument to ypserv breaks NIS over TCP.  After starting
ypserv -P 666 I see:

tcp4       0      0 *.666                  *.*                    CLOSED

From the code ( http://svnweb.freebsd.org/base/stable/7/usr.sbin/ypserv/yp_main.c?r1=172506&r2=177753 )
the problem is rather obvious: the sock variable is used for both the
udp and tcp sockets, and so while transp = svcudp_create(sock); works
fine (after losing the tcp socket), transp = svctcp_create(sock, 0, 0);
doesn't work at all on the already open udp socket.

Here are the relevant calls.  Notice fd 4 is never touched again:
socket(PF_INET,SOCK_STREAM,0)                    = 4 (0x4)
bind(4,{ AF_INET 0.0.0.0:666 },16)               = 0 (0x0)
socket(PF_INET,SOCK_DGRAM,0)                     = 5 (0x5)
bind(5,{ AF_INET 0.0.0.0:666 },16)               = 0 (0x0)
getsockopt(0x5,0x0,0x13,0x7fffffffe4ec,0x7fffffffe4e0,0x7fffffffe340) = 0 (0x0)
setsockopt(0x5,0x0,0x13,0x7fffffffe4e8,0x4,0x7fffffffe458) = 0 (0x0)
bind(5,{ AF_INET 0.0.0.0:0 },16)                 ERR#22 'Invalid argument'
setsockopt(0x5,0x0,0x13,0x7fffffffe4ec,0x4,0x7fffffffe458) = 0 (0x0)
listen(0x5,0x80,0x13,0x8007dd42c,0xffffff80ec8b4d40,0x7fffffffe458) ERR#45 'Operation not supported'
getsockopt(0x5,0x0,0x13,0x7fffffffe4ec,0x7fffffffe4e0,0x800a00728) = 0 (0x0)
setsockopt(0x5,0x0,0x13,0x7fffffffe4e8,0x4,0x7fffffffe458) = 0 (0x0)
bind(5,{ AF_INET 0.0.0.0:0 },16)                 ERR#22 'Invalid argument'
setsockopt(0x5,0x0,0x13,0x7fffffffe4ec,0x4,0x7fffffffe458) = 0 (0x0)
listen(0x5,0x80,0x13,0x8007dd42c,0xffffff80ec8b4d40,0x7fffffffe458) ERR#45 'Operation not supported'

Fix: 

Use a different variable for each socket.
How-To-Repeat: Run ypserv -P <port>
Perform TCP NIS request from client
Comment 1 Dylan Simon 2011-08-30 17:15:19 UTC
Attached is a patch that seems to work.  However, there seems to be another
bug using ypserv -d where it exits ypproc_all_2_svc at the end even though it
hasn't forked (PR #10970 collateral?), so I can't test completely.  (I'm
trying to get automount maps in linux to pull from FreeBSD NIS, which still
isn't working.)
Comment 2 Dylan Simon 2012-08-21 03:10:38 UTC
Someone has done a rewrite to this exact section of code without fixing this
bug.  This bug completely breaks NIS over TCP which completely disables many
(non-freebsd) clients.  It is serious and blatantly obvious how the code is
broken.  It has been a year.  Please somebody fix it.
Comment 3 Hiroki Sato freebsd_committer freebsd_triage 2012-08-21 03:41:22 UTC
Responsible Changed
From-To: freebsd-bugs->hrs

I'll take this.
Comment 4 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:11 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 5 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:39:19 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>