From rea-fbsd@codelabs.ru  Tue Nov  4 13:16:26 2008
Return-Path: <rea-fbsd@codelabs.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 4AFDD1065674
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  4 Nov 2008 13:16:26 +0000 (UTC)
	(envelope-from rea-fbsd@codelabs.ru)
Received: from 0.mx.codelabs.ru (0.mx.codelabs.ru [144.206.177.45])
	by mx1.freebsd.org (Postfix) with ESMTP id EB8D58FC12
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  4 Nov 2008 13:16:25 +0000 (UTC)
	(envelope-from rea-fbsd@codelabs.ru)
Received: from amnesiac.at.no.dns (dns.ccsem.infn.it [192.135.15.3])
	by 0.mx.codelabs.ru with esmtps (TLSv1:CAMELLIA256-SHA:256)
	id 1KxLlg-000D6f-JW for FreeBSD-gnats-submit@freebsd.org; Tue, 04 Nov 2008 16:16:24 +0300
Received: by shadow.localdomain (Postfix, from userid 1001)
	id EC8E717112; Tue,  4 Nov 2008 16:16:23 +0300 (MSK)
Message-Id: <20081104131623.EC8E717112@amnesiac.at.no.dns>
Date: Tue,  4 Nov 2008 16:16:23 +0300 (MSK)
From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Reply-To: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] activate readline(3) support in wpa_cli
X-Send-Pr-Version: 3.113
X-GNATS-Notify: sam@freebsd.org

>Number:         128582
>Category:       bin
>Synopsis:       [patch] wpa_cli(8): activate readline(3) support
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 04 13:20:00 UTC 2008
>Closed-Date:    
>Last-Modified:  Sat Jan 17 04:20:00 UTC 2009
>Originator:     Eygene Ryabinkin
>Release:        FreeBSD 7.1-PRERELEASE amd64
>Organization:
Code Labs
>Environment:

System: FreeBSD XXX 7.1-PRERELEASE FreeBSD 7.1-PRERELEASE #13: Mon Nov 3 13:26:45 MSK 2008 root@XXX:/usr/obj/usr/src/sys/XXX amd64

>Description:

Currently wpa_cli(8) has no compiled-in readline support, although it
has this functionality inside the source code.  It is very useful to
have command history, command editing and autocompletion in the
interactive mode.

>How-To-Repeat:

Spawn wpa_cli and try to push the arrow buttons.  They will produce the
usual "garbage" instead of making the utility to crawl through the
command history.

>Fix:

The following patch activates readline support.

--- patch-wpa_cli-readline-support begins here ---
From 360b30819549c7fb422de2995ba4eb3a8a68c81e Mon Sep 17 00:00:00 2001
From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Date: Tue, 4 Nov 2008 16:00:51 +0300

The support is present since wpa_cli.c, rev. 1.1, but it was not turned
on.  Since it is rather useful to have readline/history support for the
interactive mode, I am enabling this functionality.

Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
---
 usr.sbin/wpa/wpa_cli/Makefile |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/usr.sbin/wpa/wpa_cli/Makefile b/usr.sbin/wpa/wpa_cli/Makefile
index 75c3c02..477ba3c 100644
--- a/usr.sbin/wpa/wpa_cli/Makefile
+++ b/usr.sbin/wpa/wpa_cli/Makefile
@@ -10,5 +10,9 @@ MAN=	wpa_cli.8
 
 CFLAGS+= -DCONFIG_CTRL_IFACE
 CFLAGS+= -DCONFIG_CTRL_IFACE_UNIX
+CFLAGS+= -DCONFIG_READLINE
+
+DPADD+= ${LIBREADLINE}
+LDADD+= -lreadline
 
 .include <bsd.prog.mk>
-- 
1.6.0.3
--- patch-wpa_cli-readline-support ends here ---
>Release-Note:
>Audit-Trail:

From: Sam Leffler <sam@freebsd.org>
To: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/128582: [patch] activate readline(3) support in wpa_cli
Date: Tue, 04 Nov 2008 11:37:22 -0800

 readline support in wpa_cli is not enabled by default because it bloats 
 the system with very little gain.  It is trivial to have a local 
 configuration that adds it w/o touching the source code but once added 
 in the way proposed it is not possible to disable it w/o modification.
 
 I believe the original PR was submitted by brix@.  I recently asked him 
 to review it and decide whether he wanted to commit the change; 
 otherwise close the PR.
 
     Sam
 

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: Sam Leffler <sam@freebsd.org>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/128582: [patch] activate readline(3) support in wpa_cli
Date: Wed, 5 Nov 2008 20:58:53 +0300

 --i0/AhcQY5QxfSsSZ
 Content-Type: multipart/mixed; boundary="NzB8fVQJ5HfG6fxh"
 Content-Disposition: inline
 
 
 --NzB8fVQJ5HfG6fxh
 Content-Type: text/plain; charset=koi8-r
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Sam, good day.
 
 Tue, Nov 04, 2008 at 11:37:22AM -0800, Sam Leffler wrote:
 > readline support in wpa_cli is not enabled by default because it bloats=
 =20
 > the system with very little gain.  It is trivial to have a local=20
 > configuration that adds it w/o touching the source code but once added=20
 > in the way proposed it is not possible to disable it w/o modification.
 
 OK, no problems: what about the attached patch?
 
 > I believe the original PR was submitted by brix@.  I recently asked him=
 =20
 > to review it and decide whether he wanted to commit the change;=20
 > otherwise close the PR.
 
 Yes, it is bin/116606.  I had spotted from that patch that ncurses is
 needed too and had explicitely added it to my patch.  The main
 difference between my and Henrik patches is that I am defining
 additional knob WPA_CLI_WITH_READLINE that enables the realine support
 (but only when MK_GNU_SUPPORT is defined too).  So, by-default the
 support won't be included and people will be able to turn it on
 without resorting the the make trickery.  And I had also described
 this in the manual page.
 
 As a bonus, I had written proper support for the history command
 validation for the potentially sensitive commands that shouldn't be
 written to the disk.  The original version was faulty and incomplete.
 The patch is attached too.  May be it should go upstream, I'll try to
 submit it there too.
 --=20
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual  =20
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook=20
     {_.-``-'         {_/            #
 
 --NzB8fVQJ5HfG6fxh
 Content-Type: text/plain; charset=koi8-r
 Content-Disposition: attachment; filename=patch-wpa_cli-readline-support
 Content-Transfer-Encoding: quoted-printable
 
 =46rom dfcf8eb229255ff0d28e7afc4bfd49cf3afb573f Mon Sep 17 00:00:00 2001
 =46rom: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 Date: Tue, 4 Nov 2008 16:00:51 +0300
 Subject: [PATCH] WPA supplicant: activate support for readline and history =
 browsing
 
 The support is present since wpa_cli.c, rev. 1.1, but it was not turned
 on.  Since it is rather useful to have readline/history support for the
 interactive mode, I am enabling this functionality, but it is done
 conditionally.  Sam Leffler told me [1] that it will be the system bloat
 when there will be unconditional support for readline(3).  So, one
 should set the macro WPA_CLI_WITH_READLINE=3D"yes" to enable this.
 
 readline(3) support won't be enabled when GNU support is globally
 disabled.
 
 [1] http://www.freebsd.org/cgi/query-pr.cgi?pr=3D128582
 
 Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 ---
  usr.sbin/wpa/wpa_cli/Makefile  |   10 ++++++++++
  usr.sbin/wpa/wpa_cli/wpa_cli.8 |   25 ++++++++++++++++++++++++-
  2 files changed, 34 insertions(+), 1 deletions(-)
 
 diff --git a/usr.sbin/wpa/wpa_cli/Makefile b/usr.sbin/wpa/wpa_cli/Makefile
 index 75c3c02..4531598 100644
 --- a/usr.sbin/wpa/wpa_cli/Makefile
 +++ b/usr.sbin/wpa/wpa_cli/Makefile
 @@ -11,4 +11,14 @@ MAN=3D	wpa_cli.8
  CFLAGS+=3D -DCONFIG_CTRL_IFACE
  CFLAGS+=3D -DCONFIG_CTRL_IFACE_UNIX
 =20
 +.include <bsd.own.mk>
 +
 +.if ${MK_GNU_SUPPORT} =3D=3D "no"
 +# Do nothing, we don't want readline(3) support: GNU support it disabled
 +.elif defined(WPA_CLI_WITH_READLINE) && ${WPA_CLI_WITH_READLINE} =3D=3D "y=
 es"
 +CFLAGS+=3D -DCONFIG_READLINE
 +DPADD+=3D ${LIBREADLINE} ${LIBNCURSES}
 +LDADD+=3D -lreadline -lncurses
 +.endif
 +
  .include <bsd.prog.mk>
 diff --git a/usr.sbin/wpa/wpa_cli/wpa_cli.8 b/usr.sbin/wpa/wpa_cli/wpa_cli.8
 index e9a22ee..3ed857c 100644
 --- a/usr.sbin/wpa/wpa_cli/wpa_cli.8
 +++ b/usr.sbin/wpa/wpa_cli/wpa_cli.8
 @@ -202,9 +202,32 @@ to terminate.
  Exit
  .Nm .
  .El
 +.Sh IMPLEMENTATION DETAILS
 +.Pp
 +One can enable
 +.Xr readline 3
 +support for the
 +.Nm
 +by setting the macro=20
 +.Dv WPA_CLI_WITH_READLINE
 +to
 +.Qq yes
 +either on the compile time, in the
 +.Pa /etc/make.conf
 +or
 +.Pa /etc/src.conf .
 +This option will be effective only when GNU tools support is enabled:
 +the macro
 +.Dv WITHOUT_GNU_SUPPORT
 +should be unset.
 +.Xr readline 3
 +support will add history browsing, command editing and command completion
 +for the interactive operation mode.
  .Sh SEE ALSO
  .Xr wpa_supplicant.conf 5 ,
 -.Xr wpa_supplicant 8
 +.Xr wpa_supplicant 8 ,
 +.Xr src.conf 5 ,
 +.Xr make.conf 5
  .Sh HISTORY
  The
  .Nm
 --=20
 1.6.0.3
 
 
 --NzB8fVQJ5HfG6fxh
 Content-Type: text/plain; charset=koi8-r
 Content-Disposition: attachment; filename=patch-wpa_cli-properly-clean-history
 Content-Transfer-Encoding: quoted-printable
 
 =46rom fbd42c715af5d894a48b45db3abf12ac8eaf36b0 Mon Sep 17 00:00:00 2001
 =46rom: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 Date: Wed, 5 Nov 2008 20:29:56 +0300
 Subject: [PATCH] WPA CLI tool: properly clean history before writing it to =
 the disk
 
 First of all, the history had not been written to the disk, since almost
 all commands were cleaned up due to the error in the history cleaning:
 the return value of the last os_strncasecmp() call was not compared to
 zero, but was rather used as is.  So the condition was almost always
 true and most commands were removed from the history.
 
 The second problem was that the evaluation of the potentially sensitive
 commands was started at the entry number 1, instead of very first entry.
 
 I had added flags to the every command description: just now the only
 meaningful flag tells that this command has sensitive arguments and it
 shouldn't be written to the disk.  I rewrote the logics for the search
 for the sensitive commands: special procedure is now loops over all
 commands and tries to see if command has sensitive data.  And I had
 rewritten the command checking loop to properly check all commands.
 
 Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 ---
  contrib/wpa_supplicant/wpa_cli.c |  124 ++++++++++++++++++++++------------=
 ----
  1 files changed, 72 insertions(+), 52 deletions(-)
 
 diff --git a/contrib/wpa_supplicant/wpa_cli.c b/contrib/wpa_supplicant/wpa_=
 cli.c
 index 7176c95..f3e90ef 100644
 --- a/contrib/wpa_supplicant/wpa_cli.c
 +++ b/contrib/wpa_supplicant/wpa_cli.c
 @@ -973,57 +973,81 @@ static int wpa_cli_cmd_interface_remove(struct wpa_ct=
 rl *ctrl, int argc,
  	return wpa_ctrl_command(ctrl, cmd);
  }
 =20
 +enum wpa_cli_cmd_flags {
 +	cli_cmd_flag_none		=3D 0x00,
 +	cli_cmd_flag_sensitive		=3D 0x01
 +};
 =20
  struct wpa_cli_cmd {
  	const char *cmd;
  	int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
 +	enum wpa_cli_cmd_flags flags;
  };
 =20
  static struct wpa_cli_cmd wpa_cli_commands[] =3D {
 -	{ "status", wpa_cli_cmd_status },
 -	{ "ping", wpa_cli_cmd_ping },
 -	{ "mib", wpa_cli_cmd_mib },
 -	{ "help", wpa_cli_cmd_help },
 -	{ "interface", wpa_cli_cmd_interface },
 -	{ "level", wpa_cli_cmd_level },
 -	{ "license", wpa_cli_cmd_license },
 -	{ "quit", wpa_cli_cmd_quit },
 -	{ "set", wpa_cli_cmd_set },
 -	{ "logon", wpa_cli_cmd_logon },
 -	{ "logoff", wpa_cli_cmd_logoff },
 -	{ "pmksa", wpa_cli_cmd_pmksa },
 -	{ "reassociate", wpa_cli_cmd_reassociate },
 -	{ "preauthenticate", wpa_cli_cmd_preauthenticate },
 -	{ "identity", wpa_cli_cmd_identity },
 -	{ "password", wpa_cli_cmd_password },
 -	{ "new_password", wpa_cli_cmd_new_password },
 -	{ "pin", wpa_cli_cmd_pin },
 -	{ "otp", wpa_cli_cmd_otp },
 -	{ "passphrase", wpa_cli_cmd_passphrase },
 -	{ "bssid", wpa_cli_cmd_bssid },
 -	{ "list_networks", wpa_cli_cmd_list_networks },
 -	{ "select_network", wpa_cli_cmd_select_network },
 -	{ "enable_network", wpa_cli_cmd_enable_network },
 -	{ "disable_network", wpa_cli_cmd_disable_network },
 -	{ "add_network", wpa_cli_cmd_add_network },
 -	{ "remove_network", wpa_cli_cmd_remove_network },
 -	{ "set_network", wpa_cli_cmd_set_network },
 -	{ "get_network", wpa_cli_cmd_get_network },
 -	{ "save_config", wpa_cli_cmd_save_config },
 -	{ "disconnect", wpa_cli_cmd_disconnect },
 -	{ "reconnect", wpa_cli_cmd_reconnect },
 -	{ "scan", wpa_cli_cmd_scan },
 -	{ "scan_results", wpa_cli_cmd_scan_results },
 -	{ "get_capability", wpa_cli_cmd_get_capability },
 -	{ "reconfigure", wpa_cli_cmd_reconfigure },
 -	{ "terminate", wpa_cli_cmd_terminate },
 -	{ "interface_add", wpa_cli_cmd_interface_add },
 -	{ "interface_remove", wpa_cli_cmd_interface_remove },
 -	{ "ap_scan", wpa_cli_cmd_ap_scan },
 -	{ "stkstart", wpa_cli_cmd_stkstart },
 -	{ NULL, NULL }
 +	{ "status", wpa_cli_cmd_status, cli_cmd_flag_none },
 +	{ "ping", wpa_cli_cmd_ping, cli_cmd_flag_none },
 +	{ "mib", wpa_cli_cmd_mib, cli_cmd_flag_none },
 +	{ "help", wpa_cli_cmd_help, cli_cmd_flag_none },
 +	{ "interface", wpa_cli_cmd_interface, cli_cmd_flag_none },
 +	{ "level", wpa_cli_cmd_level, cli_cmd_flag_none },
 +	{ "license", wpa_cli_cmd_license, cli_cmd_flag_none },
 +	{ "quit", wpa_cli_cmd_quit, cli_cmd_flag_none },
 +	{ "set", wpa_cli_cmd_set, cli_cmd_flag_none },
 +	{ "logon", wpa_cli_cmd_logon, cli_cmd_flag_none },
 +	{ "logoff", wpa_cli_cmd_logoff, cli_cmd_flag_none },
 +	{ "pmksa", wpa_cli_cmd_pmksa, cli_cmd_flag_none },
 +	{ "reassociate", wpa_cli_cmd_reassociate, cli_cmd_flag_none },
 +	{ "preauthenticate", wpa_cli_cmd_preauthenticate, cli_cmd_flag_none },
 +	{ "identity", wpa_cli_cmd_identity, cli_cmd_flag_none },
 +	{ "password", wpa_cli_cmd_password, cli_cmd_flag_sensitive },
 +	{ "new_password", wpa_cli_cmd_new_password, cli_cmd_flag_sensitive },
 +	{ "pin", wpa_cli_cmd_pin, cli_cmd_flag_sensitive },
 +	{ "otp", wpa_cli_cmd_otp, cli_cmd_flag_sensitive },
 +	{ "passphrase", wpa_cli_cmd_passphrase, cli_cmd_flag_sensitive },
 +	{ "bssid", wpa_cli_cmd_bssid, cli_cmd_flag_none },
 +	{ "list_networks", wpa_cli_cmd_list_networks, cli_cmd_flag_none },
 +	{ "select_network", wpa_cli_cmd_select_network, cli_cmd_flag_none },
 +	{ "enable_network", wpa_cli_cmd_enable_network, cli_cmd_flag_none },
 +	{ "disable_network", wpa_cli_cmd_disable_network, cli_cmd_flag_none },
 +	{ "add_network", wpa_cli_cmd_add_network, cli_cmd_flag_none },
 +	{ "remove_network", wpa_cli_cmd_remove_network, cli_cmd_flag_none },
 +	{ "set_network", wpa_cli_cmd_set_network, cli_cmd_flag_none },
 +	{ "get_network", wpa_cli_cmd_get_network, cli_cmd_flag_none },
 +	{ "save_config", wpa_cli_cmd_save_config, cli_cmd_flag_none },
 +	{ "disconnect", wpa_cli_cmd_disconnect, cli_cmd_flag_none },
 +	{ "reconnect", wpa_cli_cmd_reconnect, cli_cmd_flag_none },
 +	{ "scan", wpa_cli_cmd_scan, cli_cmd_flag_none },
 +	{ "scan_results", wpa_cli_cmd_scan_results, cli_cmd_flag_none },
 +	{ "get_capability", wpa_cli_cmd_get_capability, cli_cmd_flag_none },
 +	{ "reconfigure", wpa_cli_cmd_reconfigure, cli_cmd_flag_none },
 +	{ "terminate", wpa_cli_cmd_terminate, cli_cmd_flag_none },
 +	{ "interface_add", wpa_cli_cmd_interface_add, cli_cmd_flag_none },
 +	{ "interface_remove", wpa_cli_cmd_interface_remove, cli_cmd_flag_none },
 +	{ "ap_scan", wpa_cli_cmd_ap_scan, cli_cmd_flag_none },
 +	{ "stkstart", wpa_cli_cmd_stkstart, cli_cmd_flag_none },
 +	{ NULL, NULL, cli_cmd_flag_none }
  };
 =20
 +static int _cmd_has_sensitive_data(const char *cmd)
 +{
 +	const char *c, *delim;
 +	int n;
 +	size_t len;
 +
 +	delim =3D strpbrk(cmd, " \t");
 +	if (delim)
 +		len =3D delim - cmd;
 +	else
 +		len =3D strlen(cmd);
 +
 +	for (n =3D 0; c =3D wpa_cli_commands[n].cmd; n++) {
 +		if (os_strncasecmp(cmd, c, len) =3D=3D 0 && len =3D=3D strlen(c))
 +			return (wpa_cli_commands[n].flags &
 +			    cli_cmd_flag_sensitive);
 +	}
 +	return 0;
 +}
 =20
  static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
  {
 @@ -1349,24 +1373,20 @@ static void wpa_cli_interactive(void)
  		 * passwords. */
  		HIST_ENTRY *h;
  		history_set_pos(0);
 -		h =3D next_history();
 -		while (h) {
 +		while (h =3D current_history()) {
  			char *p =3D h->line;
  			while (*p =3D=3D ' ' || *p =3D=3D '\t')
  				p++;
 -			if (os_strncasecmp(p, "pa", 2) =3D=3D 0 ||
 -			    os_strncasecmp(p, "o", 1) =3D=3D 0 ||
 -			    os_strncasecmp(p, "n", 1)) {
 +			if (_cmd_has_sensitive_data(p)) {
  				h =3D remove_history(where_history());
  				if (h) {
  					os_free(h->line);
  					os_free(h->data);
  					os_free(h);
 -				}
 -				h =3D current_history();
 -			} else {
 -				h =3D next_history();
 -			}
 +				} else
 +					next_history();
 +			} else
 +				next_history();
  		}
  		write_history(hfile);
  		os_free(hfile);
 --=20
 1.6.0.3
 
 
 --NzB8fVQJ5HfG6fxh--
 
 --i0/AhcQY5QxfSsSZ
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.9 (FreeBSD)
 
 iEYEARECAAYFAkkR3t0ACgkQthUKNsbL7YijtgCfcGVUtEI5SQbGLjj0lWkmtQD4
 fhkAnRToWxLfVDpF8FDgXQiekkxUpb7U
 =dpiq
 -----END PGP SIGNATURE-----
 
 --i0/AhcQY5QxfSsSZ--

From: Sam Leffler <sam@freebsd.org>
To: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/128582: [patch] activate readline(3) support in wpa_cli
Date: Thu, 06 Nov 2008 14:45:09 -0800

 Eygene Ryabinkin wrote:
 > Sam, good day.
 > 
 > Tue, Nov 04, 2008 at 11:37:22AM -0800, Sam Leffler wrote:
 >> readline support in wpa_cli is not enabled by default because it bloats 
 >> the system with very little gain.  It is trivial to have a local 
 >> configuration that adds it w/o touching the source code but once added 
 >> in the way proposed it is not possible to disable it w/o modification.
 > 
 > OK, no problems: what about the attached patch?
 > 
 >> I believe the original PR was submitted by brix@.  I recently asked him 
 >> to review it and decide whether he wanted to commit the change; 
 >> otherwise close the PR.
 > 
 > Yes, it is bin/116606.  I had spotted from that patch that ncurses is
 > needed too and had explicitely added it to my patch.  The main
 > difference between my and Henrik patches is that I am defining
 > additional knob WPA_CLI_WITH_READLINE that enables the realine support
 > (but only when MK_GNU_SUPPORT is defined too).  So, by-default the
 > support won't be included and people will be able to turn it on
 > without resorting the the make trickery.  And I had also described
 > this in the manual page.
 > 
 > As a bonus, I had written proper support for the history command
 > validation for the potentially sensitive commands that shouldn't be
 > written to the disk.  The original version was faulty and incomplete.
 > The patch is attached too.  May be it should go upstream, I'll try to
 > submit it there too.
 > 
 
 So long as it can be disabled I'm fine with adding the support.  Thanks
 for following through on this.
 
 Yes, please do send your wpa_cli changes to Jouni (might want to check
 if they are already in later versions of the code).
 
 	Sam
 

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: Sam Leffler <sam@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: bin/128582: [patch] activate readline(3) support in wpa_cli
Date: Fri, 7 Nov 2008 11:15:46 +0300

 --Nq2Wo0NMKNjxTN9z
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Sam, good day.
 
 Thu, Nov 06, 2008 at 02:45:09PM -0800, Sam Leffler wrote:
 > So long as it can be disabled I'm fine with adding the support.  Thanks
 > for following through on this.
 
 OK, fine, thank you.
 
 > Yes, please do send your wpa_cli changes to Jouni (might want to check
 > if they are already in later versions of the code).
 
 Already sent yesterday.  No answer yet, but I think that it is just "too
 early".  I had glanced over the latest development branch and GIT repo
 for 0.6.x: the error is still here, at least it is in the tip of the
 hostap-full.git repository.
 
 Thanks again!
 --=20
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual  =20
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook=20
     {_.-``-'         {_/            #
 
 --Nq2Wo0NMKNjxTN9z
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.9 (FreeBSD)
 
 iEYEARECAAYFAkkT+TEACgkQthUKNsbL7YhK7QCfWc4rFm+PF4H7YrA273E9P6JQ
 Q8kAnA/49+FE2UkZxFR9SAa5lSb9x4v8
 =FRL9
 -----END PGP SIGNATURE-----
 
 --Nq2Wo0NMKNjxTN9z--

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: Sam Leffler <sam@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: bin/128582: [patch] activate readline(3) support in wpa_cli
Date: Tue, 6 Jan 2009 22:36:09 +0300

 Sam, good day.
 
 To update on the bug status.
 
 Fri, Nov 07, 2008 at 11:15:45AM +0300, Eygene Ryabinkin wrote:
 > > Yes, please do send your wpa_cli changes to Jouni (might want to check
 > > if they are already in later versions of the code).
 >
 > Already sent yesterday.  No answer yet, but I think that it is just "too
 > early".  I had glanced over the latest development branch and GIT repo
 > for 0.6.x: the error is still here, at least it is in the tip of the
 > hostap-full.git repository.
 
 The fixes were integrated to the 0.6.x series and are in 0.6.7,
   http://hostap.epitest.fi/gitweb/gitweb.cgi?p=hostap-06.git;a=shortlog
 
 I had asked Jouni if he is going to backport the fixes to 0.5.x.
 -- 
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook
     {_.-``-'         {_/            #

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: Sam Leffler <sam@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: bin/128582: [patch] activate readline(3) support in wpa_cli
Date: Sat, 17 Jan 2009 07:12:51 +0300

 --x+6KMIRAuhnl3hBn
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Sam, good day.
 
 Tue, Jan 06, 2009 at 10:36:08PM +0300, Eygene Ryabinkin wrote:
 > The fixes were integrated to the 0.6.x series and are in 0.6.7,
 >   http://hostap.epitest.fi/gitweb/gitweb.cgi?p=hostap-06.git;a=shortlog
 > 
 > I had asked Jouni if he is going to backport the fixes to 0.5.x.
 
 Jouni said that he isn't going to integrate the full fixes.  May be
 only small part will go to 5.x, may be nothing will be added.  Said
 that, I have full patches for 5.x and if you want them, they are
 attached to this message.  It is up to you to either integrate them
 somehow into the FreeBSD base or to close the PR without doing this.
 -- 
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook
     {_.-``-'         {_/            #
 
 --x+6KMIRAuhnl3hBn
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="0001-WPA-CLI-tool-properly-clean-history-before-writing.patch"
 Content-Transfer-Encoding: quoted-printable
 
 =46rom 675f3cf08143fdc04ee23a550c9846d8a1cc89d1 Mon Sep 17 00:00:00 2001
 =46rom: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 Date: Sat, 8 Nov 2008 14:13:50 +0300
 Subject: [PATCH] WPA CLI tool: properly clean history before writing it to =
 the disk
 
 First of all, the history had not been written to the disk, since almost
 all commands were cleaned up due to the error in the history cleaning:
 the return value of the last os_strncasecmp() call was not compared to
 zero, but was rather used as is.  So the condition was almost always
 true and most commands were removed from the history.
 
 The second problem was that the evaluation of the potentially sensitive
 commands was started at the entry number 1, instead of very first entry.
 
 I had added flags to the every command description: just now the only
 meaningful flag tells that this command has sensitive arguments and it
 shouldn't be written to the disk.  I rewrote the logics for the search
 for the sensitive commands: special procedure is now loops over all
 commands and tries to see if command has sensitive data.  And I had
 rewritten the command checking loop to properly check all commands.
 
 Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 ---
  wpa_supplicant/wpa_cli.c |  175 ++++++++++++++++++++++++++++++++----------=
 ----
  1 files changed, 121 insertions(+), 54 deletions(-)
 
 diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
 index 46ec736..e6d4608 100644
 --- a/wpa_supplicant/wpa_cli.c
 +++ b/wpa_supplicant/wpa_cli.c
 @@ -1041,59 +1041,130 @@ static int wpa_cli_cmd_interface_remove(struct wpa=
 _ctrl *ctrl, int argc,
  	return wpa_ctrl_command(ctrl, cmd);
  }
 =20
 +enum wpa_cli_cmd_flags {
 +	cli_cmd_flag_none		=3D 0x00,
 +	cli_cmd_flag_sensitive		=3D 0x01
 +};
 =20
  struct wpa_cli_cmd {
  	const char *cmd;
  	int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
 +	enum wpa_cli_cmd_flags flags;
  };
 =20
  static struct wpa_cli_cmd wpa_cli_commands[] =3D {
 -	{ "status", wpa_cli_cmd_status },
 -	{ "ping", wpa_cli_cmd_ping },
 -	{ "mib", wpa_cli_cmd_mib },
 -	{ "help", wpa_cli_cmd_help },
 -	{ "interface", wpa_cli_cmd_interface },
 -	{ "level", wpa_cli_cmd_level },
 -	{ "license", wpa_cli_cmd_license },
 -	{ "quit", wpa_cli_cmd_quit },
 -	{ "set", wpa_cli_cmd_set },
 -	{ "logon", wpa_cli_cmd_logon },
 -	{ "logoff", wpa_cli_cmd_logoff },
 -	{ "pmksa", wpa_cli_cmd_pmksa },
 -	{ "reassociate", wpa_cli_cmd_reassociate },
 -	{ "preauthenticate", wpa_cli_cmd_preauthenticate },
 -	{ "identity", wpa_cli_cmd_identity },
 -	{ "password", wpa_cli_cmd_password },
 -	{ "new_password", wpa_cli_cmd_new_password },
 -	{ "pin", wpa_cli_cmd_pin },
 -	{ "otp", wpa_cli_cmd_otp },
 -	{ "passphrase", wpa_cli_cmd_passphrase },
 -	{ "bssid", wpa_cli_cmd_bssid },
 -	{ "list_networks", wpa_cli_cmd_list_networks },
 -	{ "select_network", wpa_cli_cmd_select_network },
 -	{ "enable_network", wpa_cli_cmd_enable_network },
 -	{ "disable_network", wpa_cli_cmd_disable_network },
 -	{ "add_network", wpa_cli_cmd_add_network },
 -	{ "remove_network", wpa_cli_cmd_remove_network },
 -	{ "set_network", wpa_cli_cmd_set_network },
 -	{ "get_network", wpa_cli_cmd_get_network },
 -	{ "save_config", wpa_cli_cmd_save_config },
 -	{ "disconnect", wpa_cli_cmd_disconnect },
 -	{ "reconnect", wpa_cli_cmd_reconnect },
 -	{ "scan", wpa_cli_cmd_scan },
 -	{ "scan_results", wpa_cli_cmd_scan_results },
 -	{ "bss", wpa_cli_cmd_bss },
 -	{ "get_capability", wpa_cli_cmd_get_capability },
 -	{ "reconfigure", wpa_cli_cmd_reconfigure },
 -	{ "terminate", wpa_cli_cmd_terminate },
 -	{ "interface_add", wpa_cli_cmd_interface_add },
 -	{ "interface_remove", wpa_cli_cmd_interface_remove },
 -	{ "ap_scan", wpa_cli_cmd_ap_scan },
 -	{ "stkstart", wpa_cli_cmd_stkstart },
 -	{ "ft_ds", wpa_cli_cmd_ft_ds },
 -	{ NULL, NULL }
 +	{ "status", wpa_cli_cmd_status,
 +	  cli_cmd_flag_none },
 +	{ "ping", wpa_cli_cmd_ping,
 +	  cli_cmd_flag_none },
 +	{ "mib", wpa_cli_cmd_mib,
 +	  cli_cmd_flag_none },
 +	{ "help", wpa_cli_cmd_help,
 +	  cli_cmd_flag_none },
 +	{ "interface", wpa_cli_cmd_interface,
 +	  cli_cmd_flag_none },
 +	{ "level", wpa_cli_cmd_level,
 +	  cli_cmd_flag_none },
 +	{ "license", wpa_cli_cmd_license,
 +	  cli_cmd_flag_none },
 +	{ "quit", wpa_cli_cmd_quit,
 +	  cli_cmd_flag_none },
 +	{ "set", wpa_cli_cmd_set,
 +	  cli_cmd_flag_none },
 +	{ "logon", wpa_cli_cmd_logon,
 +	  cli_cmd_flag_none },
 +	{ "logoff", wpa_cli_cmd_logoff,
 +	  cli_cmd_flag_none },
 +	{ "pmksa", wpa_cli_cmd_pmksa,
 +	  cli_cmd_flag_none },
 +	{ "reassociate", wpa_cli_cmd_reassociate,
 +	  cli_cmd_flag_none },
 +	{ "preauthenticate", wpa_cli_cmd_preauthenticate,
 +	  cli_cmd_flag_none },
 +	{ "identity", wpa_cli_cmd_identity,
 +	  cli_cmd_flag_none },
 +	{ "password", wpa_cli_cmd_password,
 +	  cli_cmd_flag_sensitive },
 +	{ "new_password", wpa_cli_cmd_new_password,
 +	  cli_cmd_flag_sensitive },
 +	{ "pin", wpa_cli_cmd_pin,
 +	  cli_cmd_flag_sensitive },
 +	{ "otp", wpa_cli_cmd_otp,
 +	  cli_cmd_flag_sensitive },
 +	{ "passphrase", wpa_cli_cmd_passphrase,
 +	  cli_cmd_flag_sensitive },
 +	{ "bssid", wpa_cli_cmd_bssid,
 +	  cli_cmd_flag_none },
 +	{ "list_networks", wpa_cli_cmd_list_networks,
 +	  cli_cmd_flag_none },
 +	{ "select_network", wpa_cli_cmd_select_network,
 +	  cli_cmd_flag_none },
 +	{ "enable_network", wpa_cli_cmd_enable_network,
 +	  cli_cmd_flag_none },
 +	{ "disable_network", wpa_cli_cmd_disable_network,
 +	  cli_cmd_flag_none },
 +	{ "add_network", wpa_cli_cmd_add_network,
 +	  cli_cmd_flag_none },
 +	{ "remove_network", wpa_cli_cmd_remove_network,
 +	  cli_cmd_flag_none },
 +	{ "set_network", wpa_cli_cmd_set_network,
 +	  cli_cmd_flag_none },
 +	{ "get_network", wpa_cli_cmd_get_network,
 +	  cli_cmd_flag_none },
 +	{ "save_config", wpa_cli_cmd_save_config,
 +	  cli_cmd_flag_none },
 +	{ "disconnect", wpa_cli_cmd_disconnect,
 +	  cli_cmd_flag_none },
 +	{ "reconnect", wpa_cli_cmd_reconnect,
 +	  cli_cmd_flag_none },
 +	{ "scan", wpa_cli_cmd_scan,
 +	  cli_cmd_flag_none },
 +	{ "scan_results", wpa_cli_cmd_scan_results,
 +	  cli_cmd_flag_none },
 +	{ "bss", wpa_cli_cmd_bss,
 +	  cli_cmd_flag_none },
 +	{ "get_capability", wpa_cli_cmd_get_capability,
 +	  cli_cmd_flag_none },
 +	{ "reconfigure", wpa_cli_cmd_reconfigure,
 +	  cli_cmd_flag_none },
 +	{ "terminate", wpa_cli_cmd_terminate,
 +	  cli_cmd_flag_none },
 +	{ "interface_add", wpa_cli_cmd_interface_add,
 +	  cli_cmd_flag_none },
 +	{ "interface_remove", wpa_cli_cmd_interface_remove,
 +	  cli_cmd_flag_none },
 +	{ "ap_scan", wpa_cli_cmd_ap_scan,
 +	  cli_cmd_flag_none },
 +	{ "stkstart", wpa_cli_cmd_stkstart,
 +	  cli_cmd_flag_none },
 +	{ "ft_ds", wpa_cli_cmd_ft_ds,
 +	  cli_cmd_flag_none },
 +	{ NULL, NULL,
 +	  cli_cmd_flag_none }
  };
 =20
 +#ifdef CONFIG_READLINE	/* Currently, only readline-related code uses this =
 */
 +static int _cmd_has_sensitive_data(const char *cmd)
 +{
 +	const char *c, *delim;
 +	int n;
 +	size_t len;
 +
 +	delim =3D strpbrk(cmd, " \t");
 +	if (delim)
 +		len =3D delim - cmd;
 +	else
 +		len =3D os_strlen(cmd);
 +
 +	for (n =3D 0; (c =3D wpa_cli_commands[n].cmd); n++) {
 +		if (os_strncasecmp(cmd, c, len) =3D=3D 0 && len =3D=3D os_strlen(c))
 +			return (wpa_cli_commands[n].flags &
 +			    cli_cmd_flag_sensitive);
 +	}
 +	return 0;
 +}
 +#endif
 +
 =20
  static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
  {
 @@ -1430,24 +1501,20 @@ static void wpa_cli_interactive(void)
  		 * passwords. */
  		HIST_ENTRY *h;
  		history_set_pos(0);
 -		h =3D next_history();
 -		while (h) {
 +		while ((h =3D current_history())) {
  			char *p =3D h->line;
  			while (*p =3D=3D ' ' || *p =3D=3D '\t')
  				p++;
 -			if (os_strncasecmp(p, "pa", 2) =3D=3D 0 ||
 -			    os_strncasecmp(p, "o", 1) =3D=3D 0 ||
 -			    os_strncasecmp(p, "n", 1)) {
 +			if (_cmd_has_sensitive_data(p)) {
  				h =3D remove_history(where_history());
  				if (h) {
  					os_free(h->line);
  					os_free(h->data);
  					os_free(h);
 -				}
 -				h =3D current_history();
 -			} else {
 -				h =3D next_history();
 -			}
 +				} else
 +					next_history();
 +			} else
 +				next_history();
  		}
  		write_history(hfile);
  		os_free(hfile);
 --=20
 1.6.0.3
 
 
 --x+6KMIRAuhnl3hBn
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="0002-WPA-CLI-tool-embed-command-usage-into-the-wpa_cli_c.patch"
 Content-Transfer-Encoding: quoted-printable
 
 =46rom c319af1e6dd24d09ef19e5e9f381db2fd61341c6 Mon Sep 17 00:00:00 2001
 =46rom: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 Date: Sat, 8 Nov 2008 18:52:30 +0300
 Subject: [PATCH] WPA CLI tool: embed command usage into the wpa_cli_command=
 s array
 
 It is better to have command description around the command definitions:
 the chances for omitting usage, forgotting to change/delete them, etc
 are smaller then for the separate usage statement.
 
 Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 ---
  wpa_supplicant/wpa_cli.c |  235 +++++++++++++++++++++++++++---------------=
 ----
  1 files changed, 137 insertions(+), 98 deletions(-)
 
 diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
 index e6d4608..0830f7f 100644
 --- a/wpa_supplicant/wpa_cli.c
 +++ b/wpa_supplicant/wpa_cli.c
 @@ -14,6 +14,8 @@
 =20
  #include "includes.h"
 =20
 +#include <assert.h>
 +
  #ifdef CONFIG_CTRL_IFACE
 =20
  #ifdef CONFIG_CTRL_IFACE_UNIX
 @@ -86,55 +88,6 @@ static const char *wpa_cli_full_license =3D
  "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
  "\n";
 =20
 -static const char *commands_help =3D
 -"commands:\n"
 -"  status [verbose] =3D get current WPA/EAPOL/EAP status\n"
 -"  mib =3D get MIB variables (dot1x, dot11)\n"
 -"  help =3D show this usage help\n"
 -"  interface [ifname] =3D show interfaces/select interface\n"
 -"  level <debug level> =3D change debug level\n"
 -"  license =3D show full wpa_cli license\n"
 -"  logoff =3D IEEE 802.1X EAPOL state machine logoff\n"
 -"  logon =3D IEEE 802.1X EAPOL state machine logon\n"
 -"  set =3D set variables (shows list of variables when run without argumen=
 ts)\n"
 -"  pmksa =3D show PMKSA cache\n"
 -"  reassociate =3D force reassociation\n"
 -"  reconfigure =3D force wpa_supplicant to re-read its configuration file\=
 n"
 -"  preauthenticate <BSSID> =3D force preauthentication\n"
 -"  identity <network id> <identity> =3D configure identity for an SSID\n"
 -"  password <network id> <password> =3D configure password for an SSID\n"
 -"  new_password <network id> <password> =3D change password for an SSID\n"
 -"  pin <network id> <pin> =3D configure pin for an SSID\n"
 -"  otp <network id> <password> =3D configure one-time-password for an SSID=
 \n"
 -"  passphrase <network id> <passphrase> =3D configure private key passphra=
 se\n"
 -"    for an SSID\n"
 -"  bssid <network id> <BSSID> =3D set preferred BSSID for an SSID\n"
 -"  list_networks =3D list configured networks\n"
 -"  select_network <network id> =3D select a network (disable others)\n"
 -"  enable_network <network id> =3D enable a network\n"
 -"  disable_network <network id> =3D disable a network\n"
 -"  add_network =3D add a network\n"
 -"  remove_network <network id> =3D remove a network\n"
 -"  set_network <network id> <variable> <value> =3D set network variables "
 -"(shows\n"
 -"    list of variables when run without arguments)\n"
 -"  get_network <network id> <variable> =3D get network variables\n"
 -"  save_config =3D save the current configuration\n"
 -"  disconnect =3D disconnect and wait for reassociate/reconnect command be=
 fore\n "
 -"    connecting\n"
 -"  reconnect =3D like reassociate, but only takes effect if already "
 -"disconnected\n"
 -"  scan =3D request new BSS scan\n"
 -"  scan_results =3D get latest scan results\n"
 -"  bss <<idx> | <bssid>> =3D get detailed scan result info\n"
 -"  get_capability <eap/pairwise/group/key_mgmt/proto/auth_alg> =3D "
 -"get capabilies\n"
 -"  ap_scan <value> =3D set ap_scan parameter\n"
 -"  stkstart <addr> =3D request STK negotiation with <addr>\n"
 -"  ft_ds <addr> =3D request over-the-DS FT with <addr>\n"
 -"  terminate =3D terminate wpa_supplicant\n"
 -"  quit =3D exit wpa_cli\n";
 -
  static struct wpa_ctrl *ctrl_conn;
  static int wpa_cli_quit =3D 0;
  static int wpa_cli_attached =3D 0;
 @@ -146,9 +99,12 @@ static const char *pid_file =3D NULL;
  static const char *action_file =3D NULL;
 =20
 =20
 +static void _print_help(void);
 +
 +
  static void usage(void)
  {
 -	printf("wpa_cli [-p<path to ctrl sockets>] [-i<ifname>] [-hvB] "
 +	fputs("wpa_cli [-p<path to ctrl sockets>] [-i<ifname>] [-hvB] "
  	       "[-a<action file>] \\\n"
  	       "        [-P<pid file>] [-g<global ctrl>]  [command..]\n"
  	       "  -h =3D help (show this usage text)\n"
 @@ -158,9 +114,9 @@ static void usage(void)
  	       "       wpa_supplicant\n"
  	       "  -B =3D run a daemon in the background\n"
  	       "  default path: /var/run/wpa_supplicant\n"
 -	       "  default interface: first interface found in socket path\n"
 -	       "%s",
 -	       commands_help);
 +	       "  default interface: first interface found in socket path\n",
 +	       stdout);
 +	_print_help();
  }
 =20
 =20
 @@ -274,7 +230,7 @@ static int wpa_cli_cmd_pmksa(struct wpa_ctrl *ctrl, int=
  argc, char *argv[])
 =20
  static int wpa_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[])
  {
 -	printf("%s", commands_help);
 +	_print_help();
  	return 0;
  }
 =20
 @@ -1050,99 +1006,182 @@ struct wpa_cli_cmd {
  	const char *cmd;
  	int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
  	enum wpa_cli_cmd_flags flags;
 +	const char *usage;
  };
 =20
  static struct wpa_cli_cmd wpa_cli_commands[] =3D {
  	{ "status", wpa_cli_cmd_status,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "[verbose] =3D get current WPA/EAPOL/EAP status" },
  	{ "ping", wpa_cli_cmd_ping,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D pings wpa_supplicant" },
  	{ "mib", wpa_cli_cmd_mib,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D get MIB variables (dot1x, dot11)" },
  	{ "help", wpa_cli_cmd_help,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D show this usage help" },
  	{ "interface", wpa_cli_cmd_interface,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "[ifname] =3D show interfaces/select interface" },
  	{ "level", wpa_cli_cmd_level,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  " <debug level> =3D change debug level" },
  	{ "license", wpa_cli_cmd_license,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D show full wpa_cli license" },
  	{ "quit", wpa_cli_cmd_quit,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "exit wpa_cli" },
  	{ "set", wpa_cli_cmd_set,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D set variables (show list of variables when run without arguments" =
 },
  	{ "logon", wpa_cli_cmd_logon,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D IEEE 802.1X EAPOL state machine logon" },
  	{ "logoff", wpa_cli_cmd_logoff,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D IEEE 802.1X EAPOL state machine logoff" },
  	{ "pmksa", wpa_cli_cmd_pmksa,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D show PMKSA cache" },
  	{ "reassociate", wpa_cli_cmd_reassociate,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D force reassociation" },
  	{ "preauthenticate", wpa_cli_cmd_preauthenticate,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<BSSID> =3D forces preauthentication" },
  	{ "identity", wpa_cli_cmd_identity,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<network id> <identity> =3D configure identity for an SSID" },
  	{ "password", wpa_cli_cmd_password,
 -	  cli_cmd_flag_sensitive },
 +	  cli_cmd_flag_sensitive,
 +	  "<network id> <password> =3D configure password for an SSID" },
  	{ "new_password", wpa_cli_cmd_new_password,
 -	  cli_cmd_flag_sensitive },
 +	  cli_cmd_flag_sensitive,
 +	  "<network id> <password> =3D change password for an SSID" },
  	{ "pin", wpa_cli_cmd_pin,
 -	  cli_cmd_flag_sensitive },
 +	  cli_cmd_flag_sensitive,
 +	  "<network id> <pin> =3D configure pin for an SSID" },
  	{ "otp", wpa_cli_cmd_otp,
 -	  cli_cmd_flag_sensitive },
 +	  cli_cmd_flag_sensitive,
 +	  "<network id> <password> =3D configure one-time-password for an SSID" },
  	{ "passphrase", wpa_cli_cmd_passphrase,
 -	  cli_cmd_flag_sensitive },
 +	  cli_cmd_flag_sensitive,
 +	  "<network id> <passphrase> =3D configure private key passphrase\n"
 +	  "  for an SSID" },
  	{ "bssid", wpa_cli_cmd_bssid,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<network id> <BSSID> =3D set preferred BSSID for an SSID" },
  	{ "list_networks", wpa_cli_cmd_list_networks,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D list configured networks" },
  	{ "select_network", wpa_cli_cmd_select_network,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<network id> =3D select a network (disable others)" },
  	{ "enable_network", wpa_cli_cmd_enable_network,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<network id> =3D enable a network" },
  	{ "disable_network", wpa_cli_cmd_disable_network,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<network id> =3D disable a network" },
  	{ "add_network", wpa_cli_cmd_add_network,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D add a network" },
  	{ "remove_network", wpa_cli_cmd_remove_network,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<network id> =3D remove a network" },
  	{ "set_network", wpa_cli_cmd_set_network,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<network id> <variable> <value> =3D set network variables (shows\n"
 +	  "  list of variables when run without arguments)" },
  	{ "get_network", wpa_cli_cmd_get_network,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<network id> <variable> =3D get network variables" },
  	{ "save_config", wpa_cli_cmd_save_config,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D save the current configuration" },
  	{ "disconnect", wpa_cli_cmd_disconnect,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D disconnect and wait for reassociate/reconnect command before\n"
 +	  "  connecting" },
  	{ "reconnect", wpa_cli_cmd_reconnect,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D like reassociate, but only takes effect if already disonnected" },
  	{ "scan", wpa_cli_cmd_scan,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D request new BSS scan" },
  	{ "scan_results", wpa_cli_cmd_scan_results,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D get latest scan results" },
  	{ "bss", wpa_cli_cmd_bss,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<<idx> | <bssid>> =3D get detailed scan result info" },
  	{ "get_capability", wpa_cli_cmd_get_capability,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<eap/pairwise/group/key_mgmt/proto/auth_alg> =3D get capabilities" },
  	{ "reconfigure", wpa_cli_cmd_reconfigure,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D reconfigures wpa_supplicant" },
  	{ "terminate", wpa_cli_cmd_terminate,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "=3D terminate wpa_supplicant" },
  	{ "interface_add", wpa_cli_cmd_interface_add,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"
 +	  "  <bridge_name> =3D adds new interface, all parameters but <ifname>\n"
 +	  "  are optional" },
  	{ "interface_remove", wpa_cli_cmd_interface_remove,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<ifname> =3D removes the interface" },
  	{ "ap_scan", wpa_cli_cmd_ap_scan,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<value> =3D set ap_scan parameter" },
  	{ "stkstart", wpa_cli_cmd_stkstart,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<addr> =3D request STK negotiation with <addr>" },
  	{ "ft_ds", wpa_cli_cmd_ft_ds,
 -	  cli_cmd_flag_none },
 +	  cli_cmd_flag_none,
 +	  "<addr> =3D request over-the-DS FT with <addr>" },
  	{ NULL, NULL,
 -	  cli_cmd_flag_none }
 +	  cli_cmd_flag_none,
 +	  NULL }
  };
 =20
 +
 +/*
 + * Prints command usage, lines are padded with the specified string.
 + */
 +static void _print_cmd_help(struct wpa_cli_cmd *cmd, const char *pad)
 +{
 +	char c;
 +	size_t n;
 +	FILE *stream =3D stdout;
 +
 +	assert(cmd !=3D NULL);
 +	assert(pad !=3D NULL);
 +
 +	fprintf(stream, "%s%s ", pad, cmd->cmd);
 +	for (n =3D 0; (c=3Dcmd->usage[n]); n++) {
 +		(void)fputc((int)c, stream);
 +		if (c =3D=3D '\n')
 +			fputs(pad, stream);
 +	}
 +	fputc('\n', stream);
 +}
 +
 +
 +static void _print_help(void)
 +{
 +	int n;
 +
 +	fputs("commands:\n", stdout);
 +	for (n =3D 0; wpa_cli_commands[n].cmd; n++)
 +		_print_cmd_help(&wpa_cli_commands[n], "  ");
 +}
 +
 +
  #ifdef CONFIG_READLINE	/* Currently, only readline-related code uses this =
 */
  static int _cmd_has_sensitive_data(const char *cmd)
  {
 --=20
 1.6.0.3
 
 
 --x+6KMIRAuhnl3hBn--
>Unformatted:
