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; }