Do

SSH .ssh/config parsing assumes one host per line

Bug #328968 reported by Mattias Eriksson
4
Affects Status Importance Assigned to Milestone
Do
Fix Released
Undecided
Chris S.

Bug Description

The code on SSHHosts.cs
  Regex r = new Regex ("^\\s*Host\\s+([^ ]+)\\s*$");

                string s;
                while ((s = reader.ReadLine ()) != null) {
                    Match m = r.Match (s);
                    if (m.Groups.Count == 2) {
                        items.Add (new HostItem (m.Groups [1].ToString ()));
                    }
                }

seems to assume one host per Host line in .ssh/config. However this is not true a hostline may look like
Host foo foo.domain.com another.domain.com

So I suggest to match ^\sHost (.+)$
Then split $1 on space and add that. I don't have time to learn how to do this right now since I'm not familiar with mono.

Related branches

Revision history for this message
Alex Launi (alexlauni) wrote : Re: [Bug 328968] [NEW] SSH .ssh/config parsing assumes one host per line

How does it determine which host to connect to?

--
--Alex Launi

Revision history for this message
Mattias Eriksson (snaggen) wrote :

Well this is the code that fetches all the possible hosts to list. Then you just selects the host in the gui as with other kinds of selections.

Revision history for this message
Sylvain Firmery (nimhs) wrote :

Hi all,

Here is a patch of SSHHosts.cs to parse more than one host per line :

                                Regex r = new Regex ("^\\s*Host\\s+(.+)\\s*$");

                                string s;
                                while ((s = reader.ReadLine ()) != null) {
                                        Match m = r.Match (s);
                                        if (m.Groups.Count == 2) {
                                                string line = m.Groups[1].ToString();
                                                string[] hosts = line.Split(new string[] { " " }, StringSplitOptions.None);
                                                foreach (string host in hosts) {
                                                        items.Add (new HostItem (host));
                                                }
                                        }
                                }

Revision history for this message
David Siegel (djsiegel-deactivatedaccount) wrote : Re: [Bug 328968] Re: SSH .ssh/config parsing assumes one host per line

Please propose a branch for merging on Launchpad. It makes our job much
easier that copying and formatting your inline code snippet.

Revision history for this message
Chris S. (cszikszoy) wrote :

This was fixed in lp:do-plugins/trunk r 591

Changed in do:
assignee: nobody → Chris S. (cszikszoy)
status: New → Fix Committed
Robert Dyer (psybers)
Changed in do:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.