[PATCH] make cwm parse /etc/ssh/ssh_known_hosts (global known hosts) as well as user's known_hosts

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] make cwm parse /etc/ssh/ssh_known_hosts (global known hosts) as well as user's known_hosts

Franz Bettag
Dear OpenBSD folks,

appended you will find a patch allowing cwm to also parse the contents
of /etc/ssh/ssh_known_hosts and thus extend the ssh menu.

the diff was taken against the latest source on the github xenocara repo.

comments and/or feedback is much appreciated.

thanks for considering this. :)

best regards

Franz Bettag

diff --git app/cwm/calmwm.h app/cwm/calmwm.h
index 008c16e1..445dab9e 100644
--- app/cwm/calmwm.h
+++ app/cwm/calmwm.h
@@ -305,6 +305,7 @@ struct conf {
  int xrandr_event_base;
  char *conf_file;
  char *known_hosts;
+ char *global_known_hosts;
  char *wm_argv;
  int debug;
 };
diff --git app/cwm/conf.c app/cwm/conf.c
index c84be55b..62994b11 100644
--- app/cwm/conf.c
+++ app/cwm/conf.c
@@ -318,6 +318,7 @@ conf_init(struct conf *c)
  }
  xasprintf(&c->conf_file, "%s/%s", home, ".cwmrc");
  xasprintf(&c->known_hosts, "%s/%s", home, ".ssh/known_hosts");
+ xasprintf(&c->global_known_hosts, "/etc/ssh/ssh_known_hosts");
 }

 void
@@ -365,6 +366,7 @@ conf_clear(struct conf *c)

  free(c->conf_file);
  free(c->known_hosts);
+ free(c->global_known_hosts);
  free(c->font);
  free(c->wmname);
 }
diff --git app/cwm/cwm.1 app/cwm/cwm.1
index fc8f0ece..ddadea0e 100644
--- app/cwm/cwm.1
+++ app/cwm/cwm.1
@@ -146,6 +146,8 @@ Spawn
 dialog.
 This parses
 .Pa $HOME/.ssh/known_hosts
+and
+.Pa /etc/ssh/ssh_known_hosts
 to provide host auto-completion.
 .Xr ssh 1
 will be executed via the configured terminal emulator.
diff --git app/cwm/kbfunc.c app/cwm/kbfunc.c
index 48404874..6b4c05dc 100644
--- app/cwm/kbfunc.c
+++ app/cwm/kbfunc.c
@@ -670,6 +670,34 @@ kbfunc_menu_ssh(void *ctx, struct cargs *cargs)

  if ((fp = fopen(Conf.known_hosts, "r")) == NULL) {
  warn("%s: %s", __func__, Conf.known_hosts);
+ goto global;
+ }
+
+ lbuf = NULL;
+ len = 0;
+ while ((slen = getline(&lbuf, &len, fp)) != -1) {
+ buf = lbuf;
+ if (buf[slen - 1] == '\n')
+ buf[slen - 1] = '\0';
+
+ /* skip hashed hosts */
+ if (strncmp(buf, HASH_MARKER, strlen(HASH_MARKER)) == 0)
+ continue;
+ for (p = buf; *p != ',' && *p != ' ' && p != buf + slen; p++)
+ ;
+ /* ignore badness */
+ if (p - buf + 1 > sizeof(hostbuf))
+ continue;
+ (void)strlcpy(hostbuf, buf, p - buf + 1);
+ menuq_add(&menuq, NULL, "%s", hostbuf);
+ }
+ free(lbuf);
+ if (ferror(fp))
+ err(1, "%s", path);
+ (void)fclose(fp);
+global:
+ if ((fp = fopen(Conf.global_known_hosts, "r")) == NULL) {
+ warn("%s: %s", __func__, Conf.global_known_hosts);
  goto menu;
  }

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] make cwm parse /etc/ssh/ssh_known_hosts (global known hosts) as well as user's known_hosts

Solene Rapenne
On Wed, Feb 12, 2020 at 07:15:36PM +0100, Franz Bettag wrote:

> Dear OpenBSD folks,
>
> appended you will find a patch allowing cwm to also parse the contents
> of /etc/ssh/ssh_known_hosts and thus extend the ssh menu.
>
> the diff was taken against the latest source on the github xenocara repo.
>
> comments and/or feedback is much appreciated.
>
> thanks for considering this. :)
>
> best regards

seems people agreed to remove this feature 3 weeks ago but it's still
not committed.

https://marc.info/?l=openbsd-tech&m=157972423522573&w=2

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] make cwm parse /etc/ssh/ssh_known_hosts (global known hosts) as well as user's known_hosts

Okan Demirmen
On Wed 2020.02.12 at 22:03 +0100, Solene Rapenne wrote:

> On Wed, Feb 12, 2020 at 07:15:36PM +0100, Franz Bettag wrote:
> > Dear OpenBSD folks,
> >
> > appended you will find a patch allowing cwm to also parse the contents
> > of /etc/ssh/ssh_known_hosts and thus extend the ssh menu.
> >
> > the diff was taken against the latest source on the github xenocara repo.
> >
> > comments and/or feedback is much appreciated.
> >
> > thanks for considering this. :)
> >
> > best regards
>
> seems people agreed to remove this feature 3 weeks ago but it's still
> not committed.
>
> https://marc.info/?l=openbsd-tech&m=157972423522573&w=2

There's a lot of private diapproval; one person gave an alternative
(thank you), which might be feasible in some way, but I'm still
unconvinced any of this belongs in a wm. At this point I don't care
enough - it is not getting in the way, but I object to giving it more
features; once this thing gets in the way, it's another story.

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] make cwm parse /etc/ssh/ssh_known_hosts (global known hosts) as well as user's known_hosts

Theo de Raadt-2
In reply to this post by Franz Bettag
I don't like this, and think it is dangerous coupling between systems.

If anything similar to browsers, window managers should not have access
to anything in the ~/.ssh directory. Or well, any other object they
don't actually need.




Franz Bettag <[hidden email]> wrote:

> Dear OpenBSD folks,
>
> appended you will find a patch allowing cwm to also parse the contents
> of /etc/ssh/ssh_known_hosts and thus extend the ssh menu.
>
> the diff was taken against the latest source on the github xenocara repo.
>
> comments and/or feedback is much appreciated.
>
> thanks for considering this. :)
>
> best regards
>
> Franz Bettag
>
> diff --git app/cwm/calmwm.h app/cwm/calmwm.h
> index 008c16e1..445dab9e 100644
> --- app/cwm/calmwm.h
> +++ app/cwm/calmwm.h
> @@ -305,6 +305,7 @@ struct conf {
> int xrandr_event_base;
> char *conf_file;
> char *known_hosts;
> + char *global_known_hosts;
> char *wm_argv;
> int debug;
> };
> diff --git app/cwm/conf.c app/cwm/conf.c
> index c84be55b..62994b11 100644
> --- app/cwm/conf.c
> +++ app/cwm/conf.c
> @@ -318,6 +318,7 @@ conf_init(struct conf *c)
> }
> xasprintf(&c->conf_file, "%s/%s", home, ".cwmrc");
> xasprintf(&c->known_hosts, "%s/%s", home, ".ssh/known_hosts");
> + xasprintf(&c->global_known_hosts, "/etc/ssh/ssh_known_hosts");
> }
>
> void
> @@ -365,6 +366,7 @@ conf_clear(struct conf *c)
>
> free(c->conf_file);
> free(c->known_hosts);
> + free(c->global_known_hosts);
> free(c->font);
> free(c->wmname);
> }
> diff --git app/cwm/cwm.1 app/cwm/cwm.1
> index fc8f0ece..ddadea0e 100644
> --- app/cwm/cwm.1
> +++ app/cwm/cwm.1
> @@ -146,6 +146,8 @@ Spawn
> dialog.
> This parses
> .Pa $HOME/.ssh/known_hosts
> +and
> +.Pa /etc/ssh/ssh_known_hosts
> to provide host auto-completion.
> .Xr ssh 1
> will be executed via the configured terminal emulator.
> diff --git app/cwm/kbfunc.c app/cwm/kbfunc.c
> index 48404874..6b4c05dc 100644
> --- app/cwm/kbfunc.c
> +++ app/cwm/kbfunc.c
> @@ -670,6 +670,34 @@ kbfunc_menu_ssh(void *ctx, struct cargs *cargs)
>
> if ((fp = fopen(Conf.known_hosts, "r")) == NULL) {
> warn("%s: %s", __func__, Conf.known_hosts);
> + goto global;
> + }
> +
> + lbuf = NULL;
> + len = 0;
> + while ((slen = getline(&lbuf, &len, fp)) != -1) {
> + buf = lbuf;
> + if (buf[slen - 1] == '\n')
> + buf[slen - 1] = '\0';
> +
> + /* skip hashed hosts */
> + if (strncmp(buf, HASH_MARKER, strlen(HASH_MARKER)) == 0)
> + continue;
> + for (p = buf; *p != ',' && *p != ' ' && p != buf + slen; p++)
> + ;
> + /* ignore badness */
> + if (p - buf + 1 > sizeof(hostbuf))
> + continue;
> + (void)strlcpy(hostbuf, buf, p - buf + 1);
> + menuq_add(&menuq, NULL, "%s", hostbuf);
> + }
> + free(lbuf);
> + if (ferror(fp))
> + err(1, "%s", path);
> + (void)fclose(fp);
> +global:
> + if ((fp = fopen(Conf.global_known_hosts, "r")) == NULL) {
> + warn("%s: %s", __func__, Conf.global_known_hosts);
> goto menu;
> }
>