186d7f5d3SJohn Marino /* CVS rsh client stuff.
286d7f5d3SJohn Marino
386d7f5d3SJohn Marino This program is free software; you can redistribute it and/or modify
486d7f5d3SJohn Marino it under the terms of the GNU General Public License as published by
586d7f5d3SJohn Marino the Free Software Foundation; either version 2, or (at your option)
686d7f5d3SJohn Marino any later version.
786d7f5d3SJohn Marino
886d7f5d3SJohn Marino This program is distributed in the hope that it will be useful,
986d7f5d3SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
1086d7f5d3SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1186d7f5d3SJohn Marino GNU General Public License for more details. */
1286d7f5d3SJohn Marino
1386d7f5d3SJohn Marino #include <config.h>
1486d7f5d3SJohn Marino
1586d7f5d3SJohn Marino #include "cvs.h"
1686d7f5d3SJohn Marino #include "buffer.h"
1786d7f5d3SJohn Marino
1886d7f5d3SJohn Marino #ifdef CLIENT_SUPPORT
1986d7f5d3SJohn Marino
2086d7f5d3SJohn Marino #include "rsh-client.h"
2186d7f5d3SJohn Marino
2286d7f5d3SJohn Marino #ifndef NO_EXT_METHOD
2386d7f5d3SJohn Marino
2486d7f5d3SJohn Marino /* Contact the server by starting it with rsh. */
2586d7f5d3SJohn Marino
2686d7f5d3SJohn Marino /* Right now, we have two different definitions for this function,
2786d7f5d3SJohn Marino depending on whether we start the rsh server using popenRW or not.
2886d7f5d3SJohn Marino This isn't ideal, and the best thing would probably be to change
2986d7f5d3SJohn Marino the OS/2 port to be more like the regular Unix client (i.e., by
3086d7f5d3SJohn Marino implementing piped_child)... but I'm doing something else at the
3186d7f5d3SJohn Marino moment, and wish to make only one change at a time. -Karl */
3286d7f5d3SJohn Marino
3386d7f5d3SJohn Marino # ifdef START_RSH_WITH_POPEN_RW
3486d7f5d3SJohn Marino
3586d7f5d3SJohn Marino
3686d7f5d3SJohn Marino
3786d7f5d3SJohn Marino /* This is actually a crock -- it's OS/2-specific, for no one else
3886d7f5d3SJohn Marino uses it. If I get time, I want to make piped_child and all the
3986d7f5d3SJohn Marino other stuff in os2/run.c work right. In the meantime, this gets us
4086d7f5d3SJohn Marino up and running, and that's most important. */
4186d7f5d3SJohn Marino void
start_rsh_server(cvsroot_t * root,struct buffer ** to_server_p,struct buffer ** from_server_p)4286d7f5d3SJohn Marino start_rsh_server (cvsroot_t *root, struct buffer **to_server_p,
4386d7f5d3SJohn Marino struct buffer **from_server_p)
4486d7f5d3SJohn Marino {
4586d7f5d3SJohn Marino int pipes[2];
4686d7f5d3SJohn Marino int child_pid;
4786d7f5d3SJohn Marino
4886d7f5d3SJohn Marino /* If you're working through firewalls, you can set the
4986d7f5d3SJohn Marino CVS_RSH environment variable to a script which uses rsh to
5086d7f5d3SJohn Marino invoke another rsh on a proxy machine. */
5186d7f5d3SJohn Marino char *cvs_rsh = (root->cvs_rsh != NULL
5286d7f5d3SJohn Marino ? root->cvs_rsh : getenv ("CVS_RSH"));
5386d7f5d3SJohn Marino char *cvs_server = (root->cvs_server != NULL
5486d7f5d3SJohn Marino ? root->cvs_server : getenv ("CVS_SERVER"));
5586d7f5d3SJohn Marino int i = 0;
5686d7f5d3SJohn Marino /* This needs to fit "rsh", "-b", "-l", "USER", "host",
5786d7f5d3SJohn Marino "cmd (w/ args)", and NULL. We leave some room to grow. */
5886d7f5d3SJohn Marino char *rsh_argv[10];
5986d7f5d3SJohn Marino
6086d7f5d3SJohn Marino if (!cvs_rsh)
6186d7f5d3SJohn Marino /* People sometimes suggest or assume that this should default
6286d7f5d3SJohn Marino to "remsh" on systems like HPUX in which that is the
6386d7f5d3SJohn Marino system-supplied name for the rsh program. However, that
6486d7f5d3SJohn Marino causes various problems (keep in mind that systems such as
6586d7f5d3SJohn Marino HPUX might have non-system-supplied versions of "rsh", like
6686d7f5d3SJohn Marino a Kerberized one, which one might want to use). If we
6786d7f5d3SJohn Marino based the name on what is found in the PATH of the person
6886d7f5d3SJohn Marino who runs configure, that would make it harder to
6986d7f5d3SJohn Marino consistently produce the same result in the face of
7086d7f5d3SJohn Marino different people producing binary distributions. If we
7186d7f5d3SJohn Marino based it on "remsh" always being the default for HPUX
7286d7f5d3SJohn Marino (e.g. based on uname), that might be slightly better but
7386d7f5d3SJohn Marino would require us to keep track of what the defaults are for
7486d7f5d3SJohn Marino each system type, and probably would cope poorly if the
7586d7f5d3SJohn Marino existence of remsh or rsh varies from OS version to OS
7686d7f5d3SJohn Marino version. Therefore, it seems best to have the default
7786d7f5d3SJohn Marino remain "rsh", and tell HPUX users to specify remsh, for
7886d7f5d3SJohn Marino example in CVS_RSH or other such mechanisms to be devised,
7986d7f5d3SJohn Marino if that is what they want (the manual already tells them
8086d7f5d3SJohn Marino that). */
8186d7f5d3SJohn Marino cvs_rsh = RSH_DFLT;
8286d7f5d3SJohn Marino if (!cvs_server)
8386d7f5d3SJohn Marino cvs_server = "cvs";
8486d7f5d3SJohn Marino
8586d7f5d3SJohn Marino /* The command line starts out with rsh. */
8686d7f5d3SJohn Marino rsh_argv[i++] = cvs_rsh;
8786d7f5d3SJohn Marino
8886d7f5d3SJohn Marino # ifdef RSH_NEEDS_BINARY_FLAG
8986d7f5d3SJohn Marino /* "-b" for binary, under OS/2. */
9086d7f5d3SJohn Marino rsh_argv[i++] = "-b";
9186d7f5d3SJohn Marino # endif /* RSH_NEEDS_BINARY_FLAG */
9286d7f5d3SJohn Marino
9386d7f5d3SJohn Marino /* Then we strcat more things on the end one by one. */
9486d7f5d3SJohn Marino if (root->username != NULL)
9586d7f5d3SJohn Marino {
9686d7f5d3SJohn Marino rsh_argv[i++] = "-l";
9786d7f5d3SJohn Marino rsh_argv[i++] = root->username;
9886d7f5d3SJohn Marino }
9986d7f5d3SJohn Marino
10086d7f5d3SJohn Marino rsh_argv[i++] = root->hostname;
10186d7f5d3SJohn Marino rsh_argv[i++] = cvs_server;
10286d7f5d3SJohn Marino rsh_argv[i++] = "server";
10386d7f5d3SJohn Marino
10486d7f5d3SJohn Marino /* Mark the end of the arg list. */
10586d7f5d3SJohn Marino rsh_argv[i] = NULL;
10686d7f5d3SJohn Marino
10786d7f5d3SJohn Marino if (trace)
10886d7f5d3SJohn Marino {
10986d7f5d3SJohn Marino fprintf (stderr, " -> Starting server: ");
11086d7f5d3SJohn Marino for (i = 0; rsh_argv[i]; i++)
11186d7f5d3SJohn Marino fprintf (stderr, "%s ", rsh_argv[i]);
11286d7f5d3SJohn Marino putc ('\n', stderr);
11386d7f5d3SJohn Marino }
11486d7f5d3SJohn Marino
11586d7f5d3SJohn Marino /* Do the deed. */
11686d7f5d3SJohn Marino child_pid = popenRW (rsh_argv, pipes);
11786d7f5d3SJohn Marino if (child_pid < 0)
11886d7f5d3SJohn Marino error (1, errno, "cannot start server via rsh");
11986d7f5d3SJohn Marino
12086d7f5d3SJohn Marino /* Give caller the file descriptors in a form it can deal with. */
12186d7f5d3SJohn Marino make_bufs_from_fds (pipes[0], pipes[1], child_pid, to_server_p,
12286d7f5d3SJohn Marino from_server_p, 0);
12386d7f5d3SJohn Marino }
12486d7f5d3SJohn Marino
12586d7f5d3SJohn Marino # else /* ! START_RSH_WITH_POPEN_RW */
12686d7f5d3SJohn Marino
12786d7f5d3SJohn Marino void
start_rsh_server(cvsroot_t * root,struct buffer ** to_server_p,struct buffer ** from_server_p)12886d7f5d3SJohn Marino start_rsh_server (cvsroot_t *root, struct buffer **to_server_p,
12986d7f5d3SJohn Marino struct buffer **from_server_p)
13086d7f5d3SJohn Marino {
13186d7f5d3SJohn Marino /* If you're working through firewalls, you can set the
13286d7f5d3SJohn Marino CVS_RSH environment variable to a script which uses rsh to
13386d7f5d3SJohn Marino invoke another rsh on a proxy machine. */
13486d7f5d3SJohn Marino char *cvs_rsh = (root->cvs_rsh != NULL
13586d7f5d3SJohn Marino ? root->cvs_rsh : getenv ("CVS_RSH"));
13686d7f5d3SJohn Marino char *cvs_server = (root->cvs_server != NULL
13786d7f5d3SJohn Marino ? root->cvs_server : getenv ("CVS_SERVER"));
13886d7f5d3SJohn Marino char *command;
13986d7f5d3SJohn Marino int tofd, fromfd;
14086d7f5d3SJohn Marino int child_pid;
14186d7f5d3SJohn Marino
14286d7f5d3SJohn Marino if (!cvs_rsh)
14386d7f5d3SJohn Marino cvs_rsh = RSH_DFLT;
14486d7f5d3SJohn Marino if (!cvs_server)
14586d7f5d3SJohn Marino cvs_server = "cvs";
14686d7f5d3SJohn Marino
14786d7f5d3SJohn Marino /* Pass the command to rsh as a single string. This shouldn't
14886d7f5d3SJohn Marino * affect most rsh servers at all, and will pacify some buggy
14986d7f5d3SJohn Marino * versions of rsh that grab switches out of the middle of the
15086d7f5d3SJohn Marino * command (they're calling the GNU getopt routines incorrectly).
15186d7f5d3SJohn Marino *
15286d7f5d3SJohn Marino * If you are running a very old (Nov 3, 1994, before 1.5)
15386d7f5d3SJohn Marino * version of the server, you need to make sure that your .bashrc
15486d7f5d3SJohn Marino * on the server machine does not set CVSROOT to something
15586d7f5d3SJohn Marino * containing a colon (or better yet, upgrade the server).
15686d7f5d3SJohn Marino */
15786d7f5d3SJohn Marino command = Xasprintf ("%s server", cvs_server);
15886d7f5d3SJohn Marino
15986d7f5d3SJohn Marino {
16086d7f5d3SJohn Marino char *argv[10];
16186d7f5d3SJohn Marino char **p = argv;
16286d7f5d3SJohn Marino
16386d7f5d3SJohn Marino *p++ = cvs_rsh;
16486d7f5d3SJohn Marino
16586d7f5d3SJohn Marino /* If the login names differ between client and server
16686d7f5d3SJohn Marino * pass it on to rsh.
16786d7f5d3SJohn Marino */
16886d7f5d3SJohn Marino if (root->username != NULL)
16986d7f5d3SJohn Marino {
17086d7f5d3SJohn Marino *p++ = "-l";
17186d7f5d3SJohn Marino *p++ = root->username;
17286d7f5d3SJohn Marino }
17386d7f5d3SJohn Marino
17486d7f5d3SJohn Marino *p++ = root->hostname;
17586d7f5d3SJohn Marino *p++ = command;
17686d7f5d3SJohn Marino *p++ = NULL;
17786d7f5d3SJohn Marino
17886d7f5d3SJohn Marino if (trace)
17986d7f5d3SJohn Marino {
18086d7f5d3SJohn Marino int i;
18186d7f5d3SJohn Marino
18286d7f5d3SJohn Marino fprintf (stderr, " -> Starting server: ");
18386d7f5d3SJohn Marino for (i = 0; argv[i]; i++)
18486d7f5d3SJohn Marino fprintf (stderr, "%s ", argv[i]);
18586d7f5d3SJohn Marino putc ('\n', stderr);
18686d7f5d3SJohn Marino }
18786d7f5d3SJohn Marino child_pid = piped_child (argv, &tofd, &fromfd, true);
18886d7f5d3SJohn Marino
18986d7f5d3SJohn Marino if (child_pid < 0)
19086d7f5d3SJohn Marino error (1, errno, "cannot start server via rsh");
19186d7f5d3SJohn Marino }
19286d7f5d3SJohn Marino free (command);
19386d7f5d3SJohn Marino
19486d7f5d3SJohn Marino make_bufs_from_fds (tofd, fromfd, child_pid, root, to_server_p,
19586d7f5d3SJohn Marino from_server_p, 0);
19686d7f5d3SJohn Marino }
19786d7f5d3SJohn Marino
19886d7f5d3SJohn Marino # endif /* START_RSH_WITH_POPEN_RW */
19986d7f5d3SJohn Marino
20086d7f5d3SJohn Marino #endif /* NO_EXT_METHOD */
20186d7f5d3SJohn Marino
20286d7f5d3SJohn Marino #endif /* CLIENT_SUPPORT */
203