Fix rpc_init so it isn't confused by ssh
authorneilbrown <neilbrown>
Mon, 12 Dec 2005 03:55:53 +0000 (03:55 +0000)
committerneilbrown <neilbrown>
Mon, 12 Dec 2005 03:55:53 +0000 (03:55 +0000)
ChangeLog
support/nfs/rpcmisc.c

index 3d8aca2..1557e90 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-12-12 Usha Ketineni <ketineni@us.ibm.com>, NeilBrown <neilb@suse.de>
+       *support/nfs/rpcmisc.c(rpc_init): is stdin is a socket, but
+       is already connected (as e.g. from ssh), don't assume we
+       were started by inetd.
+
 2005-11-03 Steve Dickson <SteveD@redhat.com> NeilBrown <neilb@suse.de>
        *utils/idmapd/idmaps.c:
        
index ca63c81..1c02364 100644 (file)
@@ -53,12 +53,19 @@ rpc_init(char *name, int prog, int vers, void (*dispatch)(), int defport)
        if (getsockname(0, (struct sockaddr *) &saddr, &asize) == 0
            && saddr.sin_family == AF_INET) {
                int ssize = sizeof (int);
-               _rpcfdtype = 0;
+               int fdtype = 0;
                if (getsockopt(0, SOL_SOCKET, SO_TYPE,
-                               (char *)&_rpcfdtype, &ssize) == -1)
+                               (char *)&fdtype, &ssize) == -1)
                        xlog(L_FATAL, "getsockopt failed: %s", strerror(errno));
-               _rpcpmstart = 1;
-       } else {
+               /* inetd passes a UDP socket or a listening TCP socket.
+                * listen will fail on a connected TCP socket(passed by rsh).
+                */
+               if (!(fdtype == SOCK_STREAM && listen(0,5) == -1)) {
+                       _rpcfdtype = fdtype;
+                       _rpcpmstart = 1;
+               }
+       }
+       if (!_rpcpmstart) {
                pmap_unset(prog, vers);
                sock = RPC_ANYSOCK;
        }