/*
* Local functions
*/
-static int runssh(struct tcp_conn *, const char *, const char *, const char *);
+static int runssh(struct tcp_conn *, const char *, const char *, const char *,
+ const char *);
/*
* ssh version of a security handle allocator. Logically sets
int result;
struct sec_handle *rh;
char *amandad_path=NULL, *client_username=NULL, *ssh_keys=NULL;
+ char *client_port = NULL;
assert(fn != NULL);
assert(hostname != NULL);
* XXX need to eventually limit number of outgoing connections here.
*/
if(conf_fn) {
+ char *port_str;
amandad_path = conf_fn("amandad_path", datap);
client_username = conf_fn("client_username", datap);
ssh_keys = conf_fn("ssh_keys", datap);
+ port_str = conf_fn("client_port", datap);
+ if (port_str && strlen(port_str) >= 1) {
+ client_port = port_str;
+ }
}
if(rh->rc->read == -1) {
- if (runssh(rh->rs->rc, amandad_path, client_username, ssh_keys) < 0) {
+ if (runssh(rh->rs->rc, amandad_path, client_username, ssh_keys,
+ client_port) < 0) {
security_seterror(&rh->sech, _("can't connect to %s: %s"),
hostname, rh->rs->rc->errmsg);
goto error;
struct tcp_conn * rc,
const char * amandad_path,
const char * client_username,
- const char * ssh_keys)
+ const char * ssh_keys,
+ const char * client_port)
{
int rpipe[2], wpipe[2];
char *xamandad_path = (char *)amandad_path;
char *xclient_username = (char *)client_username;
char *xssh_keys = (char *)ssh_keys;
+ char *xclient_port = (char *)client_port;
+ GPtrArray *myargs;
+ gchar *ssh_options[100] = {SSH_OPTIONS, NULL};
+ gchar **ssh_option;
+ gchar *cmd;
memset(rpipe, -1, SIZEOF(rpipe));
memset(wpipe, -1, SIZEOF(wpipe));
return (-1);
}
+ if(!xamandad_path || strlen(xamandad_path) <= 1)
+ xamandad_path = vstralloc(amlibexecdir, "/", "amandad", NULL);
+ if(!xclient_username || strlen(xclient_username) <= 1)
+ xclient_username = CLIENT_LOGIN;
+ if(!xclient_port || strlen(xclient_port) <= 1)
+ xclient_port = NULL;
+
+ myargs = g_ptr_array_sized_new(20);
+ g_ptr_array_add(myargs, SSH);
+ for (ssh_option = ssh_options; *ssh_option != NULL; ssh_option++) {
+ g_ptr_array_add(myargs, *ssh_option);
+ }
+ g_ptr_array_add(myargs, "-l");
+ g_ptr_array_add(myargs, xclient_username);
+ if (xclient_port) {
+ g_ptr_array_add(myargs, "-p");
+ g_ptr_array_add(myargs, xclient_port);
+ }
+ if (ssh_keys && strlen(ssh_keys) > 1) {
+ g_ptr_array_add(myargs, "-i");
+ g_ptr_array_add(myargs, xssh_keys);
+ }
+ g_ptr_array_add(myargs, rc->hostname);
+ g_ptr_array_add(myargs, xamandad_path);
+ g_ptr_array_add(myargs, "-auth=ssh");
+ g_ptr_array_add(myargs, NULL);
+
+ cmd = g_strjoinv(" ", (gchar **)myargs->pdata);
+ g_debug("exec: %s", cmd);
+ g_free(cmd);
+
switch (rc->pid = fork()) {
case -1:
rc->errmsg = newvstrallocf(rc->errmsg, _("fork: %s"), strerror(errno));
safe_fd(-1, 0);
- if(!xamandad_path || strlen(xamandad_path) <= 1)
- xamandad_path = vstralloc(amlibexecdir, "/", "amandad", NULL);
- if(!xclient_username || strlen(xclient_username) <= 1)
- xclient_username = CLIENT_LOGIN;
- if(!ssh_keys || strlen(ssh_keys) <= 1) {
- execlp(SSH, SSH, SSH_OPTIONS, "-l", xclient_username,
- rc->hostname, xamandad_path, "-auth=ssh", "amdump", "amindexd",
- "amidxtaped", (char *)NULL);
- }
- else {
- execlp(SSH, SSH, SSH_OPTIONS, "-l", xclient_username,
- "-i", xssh_keys, rc->hostname, xamandad_path, "-auth=ssh",
- "amdump", "amindexd", "amidxtaped", (char *)NULL);
- }
+ execvp(SSH, (gchar **)myargs->pdata);
+
error("error: couldn't exec %s: %s", SSH, strerror(errno));
/* should never go here, shut up compiler warning */