From ae43c103319c1bc38528537769a0282cc2da0848 Mon Sep 17 00:00:00 2001 From: jbasney Date: Thu, 25 Apr 2002 14:27:44 +0000 Subject: [PATCH] modified to meet GPT relocatability requirements by replacing paths fixed at compile time with paths set at run-time based off of $GLOBUS_LOCATION --- openssh/Makefile.in | 29 +++++++------------ openssh/logintest.c | 1 + openssh/pathnames.c | 61 +++++++++++++++++++++++++++++++++++++++ openssh/pathnames.h | 42 +++++++++++++-------------- openssh/scp.c | 4 ++- openssh/session.c | 7 +++-- openssh/sftp.c | 4 ++- openssh/ssh-add.c | 1 + openssh/ssh-keygen.c | 1 + openssh/ssh-rand-helper.c | 7 ++--- openssh/ssh.c | 1 + openssh/sshd.c | 4 ++- 12 files changed, 112 insertions(+), 50 deletions(-) create mode 100644 openssh/pathnames.c diff --git a/openssh/Makefile.in b/openssh/Makefile.in index 0583cc7..8791ee5 100644 --- a/openssh/Makefile.in +++ b/openssh/Makefile.in @@ -8,7 +8,7 @@ libexecdir=@libexecdir@ datadir=@datadir@ mandir=@mandir@ mansubdir=@mansubdir@ -sysconfdir=@sysconfdir@ +sysconfdir=$$GLOBUS_LOCATION/etc/ssh piddir=@piddir@ srcdir=@srcdir@ top_srcdir=@top_srcdir@ @@ -19,13 +19,6 @@ SSH_PROGRAM=@bindir@/ssh ASKPASS_PROGRAM=$(libexecdir)/ssh-askpass SFTP_SERVER=$(libexecdir)/sftp-server -PATHS= -DSSHDIR=\"$(sysconfdir)\" \ - -D_PATH_SSH_PROGRAM=\"$(SSH_PROGRAM)\" \ - -D_PATH_SSH_ASKPASS_DEFAULT=\"$(ASKPASS_PROGRAM)\" \ - -D_PATH_SFTP_SERVER=\"$(SFTP_SERVER)\" \ - -D_PATH_SSH_PIDDIR=\"$(piddir)\" \ - -DSSH_RAND_HELPER=\"$(libexecdir)/ssh-rand-helper\" - CC=@CC@ LD=@LD@ CFLAGS=@CFLAGS@ @@ -50,7 +43,7 @@ INSTALL_SSH_RAND_HELPER=@INSTALL_SSH_RAND_HELPER@ TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-agent$(EXEEXT) scp$(EXEEXT) ssh-rand-helper${EXEEXT} $(SFTP_PROGS) -LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o compat.o compress.o crc32.o deattack.o dh.o dispatch.o fatal.o mac.o hostfile.o key.o kex.o kexdh.o kexgex.o log.o match.o misc.o mpaux.o nchan.o packet.o radix.o rijndael.o entropy.o readpass.o rsa.o scard.o ssh-dss.o ssh-rsa.o tildexpand.o ttymodes.o uidswap.o uuencode.o xmalloc.o kexgss.o gss-genr.o +LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o compat.o compress.o crc32.o deattack.o dh.o dispatch.o fatal.o mac.o hostfile.o key.o kex.o kexdh.o kexgex.o log.o match.o misc.o mpaux.o nchan.o packet.o pathnames.o radix.o rijndael.o entropy.o readpass.o rsa.o scard.o ssh-dss.o ssh-rsa.o tildexpand.o ttymodes.o uidswap.o uuencode.o xmalloc.o kexgss.o gss-genr.o SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o sshtty.o readconf.o clientloop.o @@ -64,17 +57,17 @@ CONFIGFILES=sshd_config.out ssh_config.out moduli.out CONFIGFILES_IN=sshd_config ssh_config moduli PATHSUBS = \ - -D/etc/ssh/ssh_config=$(sysconfdir)/ssh_config \ - -D/etc/ssh/ssh_known_hosts=$(sysconfdir)/ssh_known_hosts \ - -D/etc/ssh/sshd_config=$(sysconfdir)/sshd_config \ + -D/etc/ssh/ssh_config='$(sysconfdir)'/ssh_config \ + -D/etc/ssh/ssh_known_hosts='$(sysconfdir)'/ssh_known_hosts \ + -D/etc/ssh/sshd_config='$(sysconfdir)'/sshd_config \ -D/usr/libexec=$(libexecdir) \ - -D/etc/shosts.equiv=$(sysconfdir)/shosts.equiv \ - -D/etc/ssh/ssh_host_key=$(sysconfdir)/ssh_host_key \ - -D/etc/ssh/ssh_host_dsa_key=$(sysconfdir)/ssh_host_dsa_key \ - -D/etc/ssh/ssh_host_rsa_key=$(sysconfdir)/ssh_host_rsa_key \ + -D/etc/shosts.equiv='$(sysconfdir)'/shosts.equiv \ + -D/etc/ssh/ssh_host_key='$(sysconfdir)'/ssh_host_key \ + -D/etc/ssh/ssh_host_dsa_key='$(sysconfdir)'/ssh_host_dsa_key \ + -D/etc/ssh/ssh_host_rsa_key='$(sysconfdir)'/ssh_host_rsa_key \ -D/var/run/sshd.pid=$(piddir)/sshd.pid \ - -D/etc/ssh/moduli=$(sysconfdir)/moduli \ - -D/etc/ssh/sshrc=$(sysconfdir)/sshrc \ + -D/etc/ssh/moduli='$(sysconfdir)'/moduli \ + -D/etc/ssh/sshrc='$(sysconfdir)'/sshrc \ -D/usr/X11R6/bin/xauth=$(XAUTH_PATH) \ -D/usr/bin:/bin:/usr/sbin:/sbin=@user_path@ diff --git a/openssh/logintest.c b/openssh/logintest.c index aa3f5f4..1678d65 100644 --- a/openssh/logintest.c +++ b/openssh/logintest.c @@ -293,6 +293,7 @@ main(int argc, char *argv[]) printf("Platform-independent login recording test driver\n"); __progname = get_progname(argv[0]); + init_pathnames(); if (argc == 2) { if (strncmp(argv[1], "-i", 3) == 0) compile_opts_only = 1; diff --git a/openssh/pathnames.c b/openssh/pathnames.c new file mode 100644 index 0000000..071f127 --- /dev/null +++ b/openssh/pathnames.c @@ -0,0 +1,61 @@ +#include "includes.h" +#include "xmalloc.h" +#include "log.h" + +#define BINDIR "/bin" +#define LIBEXEC "/libexec" +#define SSHDIR "/etc/ssh" + +char *SSH_PRNG_COMMAND_FILE; +char *_PATH_SSH_SYSTEM_HOSTFILE; +char *_PATH_SSH_SYSTEM_HOSTFILE2; +char *_PATH_SERVER_CONFIG_FILE; +char *_PATH_HOST_CONFIG_FILE; +char *_PATH_HOST_KEY_FILE; +char *_PATH_HOST_DSA_KEY_FILE; +char *_PATH_HOST_RSA_KEY_FILE; +char *_PATH_DH_MODULI; +char *_PATH_DH_PRIMES; +char *_PATH_SSH_PROGRAM; +char *_PATH_SSH_SYSTEM_RC; +char *_PATH_SSH_HOSTS_EQUIV; +char *_PATH_SFTP_SERVER; + +static char * +compose(const char str1[], const char str2[], const char str3[]) +{ + int len; + char *result; + + len = strlen(str1) + strlen(str2) + strlen(str3) + 1; + result = xmalloc(len); + snprintf(result, len, "%s%s%s", str1, str2, str3); + + return result; +} + +void +init_pathnames() +{ + char *gl; + + gl = getenv("GLOBUS_LOCATION"); + if (gl == NULL) { + fatal("GLOBUS_LOCATION environment variable undefined."); + } + + SSH_PRNG_COMMAND_FILE = compose(gl, SSHDIR, "/ssh_prng_cmds"); + _PATH_SSH_SYSTEM_HOSTFILE = compose(gl, SSHDIR, "/ssh_known_hosts"); + _PATH_SSH_SYSTEM_HOSTFILE2 = compose(gl, SSHDIR, "/ssh_known_hosts2"); + _PATH_SERVER_CONFIG_FILE = compose(gl, SSHDIR, "/sshd_config"); + _PATH_HOST_CONFIG_FILE = compose(gl, SSHDIR, "/ssh_config"); + _PATH_HOST_KEY_FILE = compose(gl, SSHDIR, "/ssh_host_key"); + _PATH_HOST_DSA_KEY_FILE = compose(gl, SSHDIR, "/ssh_host_dsa_key"); + _PATH_HOST_RSA_KEY_FILE = compose(gl, SSHDIR, "/ssh_host_rsa_key"); + _PATH_DH_MODULI = compose(gl, SSHDIR, "/moduli"); + _PATH_DH_PRIMES = compose(gl, SSHDIR, "/primes"); + _PATH_SSH_PROGRAM = compose(gl, BINDIR, "/ssh"); + _PATH_SSH_SYSTEM_RC = compose(gl, SSHDIR, "/sshrc"); + _PATH_SSH_HOSTS_EQUIV = compose(gl, SSHDIR, "/shosts.equiv"); + _PATH_SFTP_SERVER = compose(gl, LIBEXEC, "/sftp-server"); +} diff --git a/openssh/pathnames.h b/openssh/pathnames.h index 002c313..4b8f267 100644 --- a/openssh/pathnames.h +++ b/openssh/pathnames.h @@ -12,11 +12,12 @@ * called by a name other than "ssh" or "Secure Shell". */ -#define ETCDIR "/etc" - -#ifndef SSHDIR -#define SSHDIR ETCDIR "/ssh" -#endif +/* + * Some of these pathnames are generated at run-time to meet GPT binary + * relocatability requirements. They are initialized by init_pathnames() + * in pathnames.c. + */ +void init_pathnames(); #ifndef _PATH_SSH_PIDDIR #define _PATH_SSH_PIDDIR "/var/run" @@ -26,26 +27,24 @@ * System-wide file containing host keys of known hosts. This file should be * world-readable. */ -#define _PATH_SSH_SYSTEM_HOSTFILE SSHDIR "/ssh_known_hosts" +extern char *_PATH_SSH_SYSTEM_HOSTFILE; /* backward compat for protocol 2 */ -#define _PATH_SSH_SYSTEM_HOSTFILE2 SSHDIR "/ssh_known_hosts2" +extern char *_PATH_SSH_SYSTEM_HOSTFILE2; /* * Of these, ssh_host_key must be readable only by root, whereas ssh_config * should be world-readable. */ -#define _PATH_SERVER_CONFIG_FILE SSHDIR "/sshd_config" -#define _PATH_HOST_CONFIG_FILE SSHDIR "/ssh_config" -#define _PATH_HOST_KEY_FILE SSHDIR "/ssh_host_key" -#define _PATH_HOST_DSA_KEY_FILE SSHDIR "/ssh_host_dsa_key" -#define _PATH_HOST_RSA_KEY_FILE SSHDIR "/ssh_host_rsa_key" -#define _PATH_DH_MODULI SSHDIR "/moduli" +extern char *_PATH_SERVER_CONFIG_FILE; +extern char *_PATH_HOST_CONFIG_FILE; +extern char *_PATH_HOST_KEY_FILE; +extern char *_PATH_HOST_DSA_KEY_FILE; +extern char *_PATH_HOST_RSA_KEY_FILE; +extern char *_PATH_DH_MODULI; /* Backwards compatibility */ -#define _PATH_DH_PRIMES SSHDIR "/primes" +extern char *_PATH_DH_PRIMES; -#ifndef _PATH_SSH_PROGRAM -#define _PATH_SSH_PROGRAM "/usr/bin/ssh" -#endif +extern char *_PATH_SSH_PROGRAM; /* * The process id of the daemon listening for connections is saved here to @@ -104,13 +103,13 @@ * use. xauth will be run if neither of these exists. */ #define _PATH_SSH_USER_RC ".ssh/rc" -#define _PATH_SSH_SYSTEM_RC SSHDIR "/sshrc" +extern char *_PATH_SSH_SYSTEM_RC; /* * Ssh-only version of /etc/hosts.equiv. Additionally, the daemon may use * ~/.rhosts and /etc/hosts.equiv if rhosts authentication is enabled. */ -#define _PATH_SSH_HOSTS_EQUIV SSHDIR "/shosts.equiv" +extern char *_PATH_SSH_HOSTS_EQUIV; #define _PATH_RHOSTS_EQUIV "/etc/hosts.equiv" /* @@ -136,9 +135,8 @@ #endif /* for sftp */ -#ifndef _PATH_SFTP_SERVER -#define _PATH_SFTP_SERVER "/usr/libexec/sftp-server" -#endif +extern char *_PATH_SFTP_SERVER; + #ifndef _PATH_LS #define _PATH_LS "ls" #endif diff --git a/openssh/scp.c b/openssh/scp.c index 83e7769..4c9b87c 100644 --- a/openssh/scp.c +++ b/openssh/scp.c @@ -131,7 +131,7 @@ int verbose_mode = 0; int showprogress = 1; /* This is the program to execute for the secured connection. ("ssh" or -S) */ -char *ssh_program = _PATH_SSH_PROGRAM; +char *ssh_program; /* * This function executes the given command as the specified user on the @@ -233,6 +233,8 @@ main(argc, argv) extern int optind; __progname = get_progname(argv[0]); + init_pathnames(); + ssh_program = _PATH_SSH_PROGRAM; args.list = NULL; addargs(&args, "ssh"); /* overwritten with ssh_program */ diff --git a/openssh/session.c b/openssh/session.c index efed43b..28fbb50 100644 --- a/openssh/session.c +++ b/openssh/session.c @@ -1062,10 +1062,11 @@ do_rc_files(Session *s, const char *shell) fprintf(stderr, "Could not run %s\n", _PATH_SSH_USER_RC); } else if (stat(_PATH_SSH_SYSTEM_RC, &st) >= 0) { + snprintf(cmd, sizeof cmd, "%s %s", _PATH_BSHELL, + _PATH_SSH_SYSTEM_RC); if (debug_flag) - fprintf(stderr, "Running %s %s\n", _PATH_BSHELL, - _PATH_SSH_SYSTEM_RC); - f = popen(_PATH_BSHELL " " _PATH_SSH_SYSTEM_RC, "w"); + fprintf(stderr, "Running %s\n", cmd); + f = popen(cmd, "w"); if (f) { if (do_xauth) fprintf(f, "%s %s\n", s->auth_proto, diff --git a/openssh/sftp.c b/openssh/sftp.c index 045e076..b067c03 100644 --- a/openssh/sftp.c +++ b/openssh/sftp.c @@ -110,13 +110,15 @@ main(int argc, char **argv) char *host, *userhost, *cp, *file2; int debug_level = 0, sshver = 2; char *file1 = NULL, *sftp_server = NULL; - char *ssh_program = _PATH_SSH_PROGRAM, *sftp_direct = NULL; + char *ssh_program = NULL, *sftp_direct = NULL; LogLevel ll = SYSLOG_LEVEL_INFO; arglist args; extern int optind; extern char *optarg; __progname = get_progname(argv[0]); + init_pathnames(); + ssh_program = _PATH_SSH_PROGRAM; args.list = NULL; addargs(&args, "ssh"); /* overwritten with ssh_program */ addargs(&args, "-oFallBackToRsh no"); diff --git a/openssh/ssh-add.c b/openssh/ssh-add.c index b057a08..b2c50d2 100644 --- a/openssh/ssh-add.c +++ b/openssh/ssh-add.c @@ -260,6 +260,7 @@ main(int argc, char **argv) int i, ch, deleting = 0, ret = 0; __progname = get_progname(argv[0]); + init_pathnames(); init_rng(); seed_rng(); diff --git a/openssh/ssh-keygen.c b/openssh/ssh-keygen.c index 6aff4a4..c6442d4 100644 --- a/openssh/ssh-keygen.c +++ b/openssh/ssh-keygen.c @@ -851,6 +851,7 @@ main(int ac, char **av) extern char *optarg; __progname = get_progname(av[0]); + init_pathnames(); SSLeay_add_all_algorithms(); diff --git a/openssh/ssh-rand-helper.c b/openssh/ssh-rand-helper.c index 28ea659..3fe0a23 100644 --- a/openssh/ssh-rand-helper.c +++ b/openssh/ssh-rand-helper.c @@ -58,10 +58,8 @@ RCSID("$Id$"); # define SSH_PRNG_SEED_FILE _PATH_SSH_USER_DIR"/prng_seed" #endif -/* Path to PRNG commands list */ -#ifndef SSH_PRNG_COMMAND_FILE -# define SSH_PRNG_COMMAND_FILE SSHDIR "/ssh_prng_cmds" -#endif +/* Path to PRNG commands list (from pathnames.c) */ +extern char *SSH_PRNG_COMMAND_FILE; #ifdef HAVE___PROGNAME @@ -754,6 +752,7 @@ main(int argc, char **argv) int ret; __progname = get_progname(argv[0]); + init_pathnames(); /* XXX: need some debugging mode */ log_init(argv[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1); diff --git a/openssh/ssh.c b/openssh/ssh.c index 117a093..ac824a3 100644 --- a/openssh/ssh.c +++ b/openssh/ssh.c @@ -260,6 +260,7 @@ main(int ac, char **av) extern char *optarg; __progname = get_progname(av[0]); + init_pathnames(); init_rng(); /* diff --git a/openssh/sshd.c b/openssh/sshd.c index c35a17f..cb700a0 100644 --- a/openssh/sshd.c +++ b/openssh/sshd.c @@ -103,7 +103,7 @@ char *__progname; ServerOptions options; /* Name of the server configuration file. */ -char *config_file_name = _PATH_SERVER_CONFIG_FILE; +char *config_file_name; /* * Flag indicating whether IPv4 or IPv6. This can be set on the command line. @@ -607,6 +607,8 @@ main(int ac, char **av) int ret, key_used = 0; __progname = get_progname(av[0]); + init_pathnames(); + config_file_name = _PATH_SERVER_CONFIG_FILE; init_rng(); /* Save argv. */ -- 2.45.2