On 03/08/2012 05:42 AM, Nuno Dias wrote:
  Hi,

  This is a solution for one machine, I have several machines with
different ports, I can create several dumptypes one for each machine,
but I think this is complicate the configuration ...

  Why amanda force port 22 and do not uses the default?

You are right, this is what the attached patch do.

Jean-Louis

Thanks
Nuno

On Wed, 2012-03-07 at 13:15 -0500, Jean-Louis Martineau wrote:
Add a client-port in the dumptype:
    client-port 50000

Jean-Louis

On 03/07/2012 12:34 PM, Nuno Dias wrote:
   Hi,

   In version 3.1.3 of amanda I used .ssh/config with a configuration like
this

Host machine_name
        Port 50000

   To do backups of a machine through a tunnel ssh.
   But with version 3.3.0 this is not working anymore, what I can see in
the logs is this

/usr/bin/ssh SSH_OPTIONS -l amanda -p 22 -i /var/lib/amanda/.ssh/id_rsa
machine_name /usr/lib64/amanda/amandad -auth=ssh

   Because the port is specified (-p 22) the port in .ssh/config it's not
used.

   This is a feature? or can I change this?

Thanks
Nuno

diff --git a/common-src/ssh-security.c b/common-src/ssh-security.c
index a6b11be..6e3d49b 100644
--- a/common-src/ssh-security.c
+++ b/common-src/ssh-security.c
@@ -114,7 +114,7 @@ ssh_connect(
     int result;
     struct sec_handle *rh;
     char *amandad_path=NULL, *client_username=NULL, *ssh_keys=NULL;
-    char *client_port = "22";
+    char *client_port = NULL;
 
     assert(fn != NULL);
     assert(hostname != NULL);
@@ -303,6 +303,10 @@ runssh(
     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));
@@ -317,18 +321,31 @@ runssh(
     if(!xclient_username || strlen(xclient_username) <= 1)
 	xclient_username = CLIENT_LOGIN;
     if(!xclient_port || strlen(xclient_port) <= 1)
-	xclient_port = "22";
+	xclient_port = NULL;
 
-    if(!ssh_keys || strlen(ssh_keys) <= 1) {
-	g_debug("exec: %s %s %s %s %s %s %s %s %s",
-		SSH, "SSH_OPTIONS", "-l", xclient_username, "-p", client_port,
-	        rc->hostname, xamandad_path, "-auth=ssh");
+    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);
     }
-    else {
-	g_debug("exec: %s %s %s %s %s %s %s %s %s %s %s",
-		SSH, "SSH_OPTIONS", "-l", xclient_username, "-p", client_port,
-	        "-i", xssh_keys, rc->hostname, xamandad_path, "-auth=ssh");
+    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:
@@ -356,15 +373,8 @@ runssh(
 
     safe_fd(-1, 0);
 
-    if(!ssh_keys || strlen(ssh_keys) <= 1) {
-	execlp(SSH, SSH, SSH_OPTIONS, "-l", xclient_username, "-p", client_port,
-	       rc->hostname, xamandad_path, "-auth=ssh", (char *)NULL);
-    }
-    else {
-	execlp(SSH, SSH, SSH_OPTIONS, "-l", xclient_username, "-p", client_port,
-	       "-i", xssh_keys, rc->hostname, xamandad_path, "-auth=ssh",
-	       (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 */

Reply via email to