Bug 51133

Summary: RSH environmental variable not described in rcmd(3)
Product: Documentation Reporter: David Magda <dmagda+fbugs>
Component: Books & ArticlesAssignee: Murray Stokely <murray>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description David Magda 2003-04-18 18:40:07 UTC
A while back rcmd(3) was changed so that if a program was defined 
in the RSH environmental variable, it would be used when the rcmd(3) 
library function was called.

Fix: 

Create a ENVIRONMENT section (.Sh ENVIRONMENT) in the rcmd(3) man 
page (and any others that are affected by RSH) stating what RSH does.

Mentioning this functionality in the DESCRIPTION may not be a bad
idea either. OpenBSD's rcmd(3) man page does this:

http://www.openbsd.org/cgi-bin/man.cgi?query=rcmdsh&sektion=3

NetBSD uses the RCMD_CMD variable:

http://netbsd.gw.com/cgi-bin/man-cgi?rcmd+3+NetBSD-current
How-To-Repeat: 
man 3 rcmd
search for RSH: you won't find it
Comment 1 Murray Stokely freebsd_committer freebsd_triage 2003-05-04 22:45:59 UTC
State Changed
From-To: open->analyzed

Yes we should update these man pages.  Is there any chance the 
submitter can give us a patch to update the pages?  If not, I will 
work on this. 



Comment 2 Murray Stokely freebsd_committer freebsd_triage 2003-05-04 22:45:59 UTC
Responsible Changed
From-To: freebsd-doc->murray

Yes we should update these man pages.  Is there any chance the 
submitter can give us a patch to update the pages?  If not, I will 
work on this.
Comment 3 David Magda 2003-07-28 02:17:17 UTC
This is the message of the text that I sent to murray@ in response to
his comment on the PR. I'm putting it in the PR so that if others
want to act on it they can since no progress has been made:

On Sun, May 04, 2003 at 02:46:50PM -0700, Murray Stokely wrote:
> Yes we should update these man pages.  Is there any chance the
> submitter can give us a patch to update the pages?  If not, I will
> work on this.

Don't know anything about groff (?) formatting so here's the text
and I'll let someone who knows it get the details right.

In the DESCRIPTION section, insert the following after the first
sentence in first paragraph:

        If the calling process is not setuid, the RSH environment
        variable is set, and inport is ``shell/tcp'', rcmdsh(3) is
        called instead with the value of RSH. Alternately, if the
        user is not the superuser, rcmd() will invoke rcmdsh(3) to
        run the command via rsh(1). While rcmd() can handle IPv4
        cases only, the rcmd_af() function can handle other cases as
        well.

Then start a new paragraph. Continue of with the rest of the text of
the man page.
This will basically make FreeBSD's man page match OpenBSD's 
rcmd(3) [1].


Next, create an ENVIRONMENT section and add the following text:

      RSH    When using the rcmd() function, this variable is used as
             the program to run instead of rsh(1).

This part is taken from NetBSD's rcmd(3) [2]: the main change is that
Net has a program rcmd(1) so that users could call rcmd(3) without
having to be the super-user, and Net uses the variable RCMD_CMD.


The above ENVIRONMENT section should also be added to dump(8) and
restore(8) since they will run $RSH if it is defined. I sent an email
suggesting so to docs@ but haven't received a reply and nothing's
been committed to CVS. Doing a quick find/grep, rdist(1) also uses
rcmd(3) so would probably be effective by $RSH.


Also, just curious. Why does OpenBSD have the following code in
rcmd.c [3]:

        if (!issetugid() && (p = getenv("RSH")) && *p) {
                struct servent *sp = getservbyname("shell", "tcp");

While FreeBSD has the following [4]:

      if (!issetugid() && (p = getenv("RSH"))) {
                 struct servent *sp = getservbyname("shell", "tcp");

The difference being the "&& *p".

This difference was introduced by the OpenBSD (by millet) in their
rev. 1.37 [5] with the commit message of "Make sure $RSH is not the
empty string."

How beneficial would it be if this was added to FreeBSD's code?

[1] http://www.openbsd.org/cgi-bin/man.cgi?query=rcmd
[2] http://netbsd.gw.com/cgi-bin/man-cgi?rcmd+3
[3] http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/net/rcmd.c?rev=1.45
[4] http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/net/rcmd.c?rev=1.38
[5] http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/net/rcmd.c.diff?r1=1.36&r2=1.37
Comment 4 Murray Stokely freebsd_committer freebsd_triage 2008-12-15 00:26:25 UTC
State Changed
From-To: analyzed->patched

Committed to -CURRENT.  This is the reminder to MFC to 7.x/6.x-STABLE.
Comment 5 Isabell Long freebsd_committer freebsd_triage 2012-07-21 18:18:16 UTC
State Changed
From-To: patched->closed

Close.  Committed several years ago.