[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH]: don't hardcode default port 22 for ssh protocol



Hi,
attached patch removes the hardcoded port 22 when going through ssh, ssh
uses it by default. This makes it easier to override this via
.ssh/config on a per host basis instead of having to add this to the
connection URI explicitly.

While at that I cleaned up some free vs. VIR_FREE usage and replaced
pointer intializations with 0 by NULL.
Cheers,
 -- Guido

P.S.: this originated from Debian Bug #513605
>From 8947ce3926829f0c30935c9a4acfc28dde9c621a Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx sigxcpu org>
Date: Fri, 30 Jan 2009 20:23:29 +0100
Subject: [PATCH] don't hardcode ssh port to 22

---
 src/remote_internal.c |   44 +++++++++++++++++++++-----------------------
 1 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/src/remote_internal.c b/src/remote_internal.c
index f8740af..c792fcc 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -370,8 +370,8 @@ doRemoteOpen (virConnectPtr conn,
     /* Local variables which we will initialise. These can
      * get freed in the failed: path.
      */
-    char *name = 0, *command = 0, *sockname = 0, *netcat = 0, *username = 0;
-    char *port = 0, *authtype = 0;
+    char *name = NULL, *command = NULL, *sockname = NULL, *netcat = NULL;
+    char *port = NULL, *authtype = NULL, *username = NULL;
     int no_verify = 0, no_tty = 0;
     char **cmd_argv = NULL;
 
@@ -387,11 +387,8 @@ doRemoteOpen (virConnectPtr conn,
     } else if (transport == trans_tcp) {
         port = strdup (LIBVIRTD_TCP_PORT);
         if (!port) goto out_of_memory;
-    } else if (transport == trans_ssh) {
-        port = strdup ("22");
-        if (!port) goto out_of_memory;
     } else
-        port = NULL;           /* Port not used for unix, ext. */
+        port = NULL; /* Port not used for unix, ext., default for ssh */
 
 
     priv->hostname = strdup (conn->uri && conn->uri->server ?
@@ -673,24 +670,27 @@ doRemoteOpen (virConnectPtr conn,
     }
 
     case trans_ssh: {
-        int j, nr_args = 8;
+        int j, nr_args = 6;
 
         if (username) nr_args += 2; /* For -l username */
         if (no_tty) nr_args += 5;   /* For -T -o BatchMode=yes -e none */
+        if (port) nr_args += 2;     /* For -p port */
 
         command = command ? command : strdup ("ssh");
         if (command == NULL)
             goto out_of_memory;
 
         // Generate the final command argv[] array.
-        //   ssh -p $port [-l $username] $hostname $netcat -U $sockname [NULL]
+        //   ssh [-p $port] [-l $username] $hostname $netcat -U $sockname [NULL]
         if (VIR_ALLOC_N(cmd_argv, nr_args) < 0)
             goto out_of_memory;
 
         j = 0;
         cmd_argv[j++] = strdup (command);
-        cmd_argv[j++] = strdup ("-p");
-        cmd_argv[j++] = strdup (port);
+        if (port) {
+            cmd_argv[j++] = strdup ("-p");
+            cmd_argv[j++] = strdup (port);
+        }
         if (username) {
             cmd_argv[j++] = strdup ("-l");
             cmd_argv[j++] = strdup (username);
@@ -843,20 +843,20 @@ doRemoteOpen (virConnectPtr conn,
 
  cleanup:
     /* Free up the URL and strings. */
-    free (name);
-    free (command);
-    free (sockname);
-    free (authtype);
-    free (netcat);
-    free (username);
-    free (port);
+    VIR_FREE(name);
+    VIR_FREE(command);
+    VIR_FREE(sockname);
+    VIR_FREE(authtype);
+    VIR_FREE(netcat);
+    VIR_FREE(username);
+    VIR_FREE(port);
     if (cmd_argv) {
         char **cmd_argv_ptr = cmd_argv;
         while (*cmd_argv_ptr) {
-            free (*cmd_argv_ptr);
+            VIR_FREE(*cmd_argv_ptr);
             cmd_argv_ptr++;
         }
-        free (cmd_argv);
+        VIR_FREE(cmd_argv);
     }
 
     return retcode;
@@ -884,10 +884,8 @@ doRemoteOpen (virConnectPtr conn,
 #endif
     }
 
-    if (priv->hostname) {
-        free (priv->hostname);
-        priv->hostname = NULL;
-    }
+    if (priv->hostname)
+        VIR_FREE(priv->hostname);
 
     goto cleanup;
 }
-- 
1.6.0.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]