From patchwork Tue Apr 29 20:41:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Shmidt X-Patchwork-Id: 343988 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 618CD140083 for ; Wed, 30 Apr 2014 06:44:23 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 1D62C9D351; Tue, 29 Apr 2014 16:44:20 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eaCoGjp5qtAz; Tue, 29 Apr 2014 16:44:19 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 4ACBB17C046; Tue, 29 Apr 2014 16:44:14 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id EA37917C046 for ; Tue, 29 Apr 2014 16:44:12 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wwbNwZWWTBzo for ; Tue, 29 Apr 2014 16:44:06 -0400 (EDT) Received: from mail-ie0-f202.google.com (mail-ie0-f202.google.com [209.85.223.202]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 2D46F17C043 for ; Tue, 29 Apr 2014 16:44:06 -0400 (EDT) Received: by mail-ie0-f202.google.com with SMTP id lx4so172784iec.1 for ; Tue, 29 Apr 2014 13:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:date:subject:to:message-id; bh=u1E0eL1AXZnBx9Jy71TBK/cKTgcH2TYBSsV9DEaujW4=; b=SugI7Zm/1fDtW66U3jRVsPNmGx+ys5/v61/piYCVxOM44p/JntiW5PAjbyud3WmQ2W ntvfJ4CNdwLb7zyx5RXbcpvcEjFd2vDnLTJYzJbLQyOQfFHebi1mjchtHTgikA3v5H7R dsXbmKPuTqeblqkDqJtn17ZwcirG8NGBeu7lusBT2+IYSoVwIc2gVaJlQZ1ZEr4VBc5h BgtzWk1F5kSoGgettMXY+CaI4fmGq0Fp1Va6pCmL5mqy+P9aCq5iqSgbGE9YE8X7b48f jg1D+k3hRyxO/OAfGdx0nKAXOWypHCXH4kLx6GMaITGwoecFH076uqXd9xql7Z0hJk/q yIMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:subject:to:message-id; bh=u1E0eL1AXZnBx9Jy71TBK/cKTgcH2TYBSsV9DEaujW4=; b=BWVdxnTjvyKQ97+yDn95+JwfkjkxZdc9DHZOwlFOSnJ6xkXbM2MWOCe+9JbfI26JcV bABCqAd47VyLRRvdxM1c2BZih5NAngwu6L/PvBIOtzOjTFiKNSGndW2O1JPra2nrBN0f C3QkCXU1ni2bR76Gn4d7WPacXq5K2JoWRK8vWL/9gbEkYI51mUg4kInkFgHCFhrNejKn MLAyEAfwJtNOAknKryc7hnNxadVUbLUeb/xlfIHh+arVxlcPqJfWOAT+YCJdp931/COo 5EvGS+DjjNWQLAtM7vENO/bqiQrEriT/3zsps7gUStYX/IK4D6+H7F2penKQ8x0KQiKi Qn4g== X-Gm-Message-State: ALoCoQnVbpgQf6C982aNbPMFQPYSfZglP+w8dpSfbJQ2aYq9XiKK8S+7S7AY2Md/AWgj1l1JeRctJHoinrnMGn56+Vfrz7DDuCWwYklE9r5ioC9rbIVi5r2l95HxuAU5gSmSGWk3oDtpot1plQo1h39z5s6hh68obQKvZAaH3TzFHLJhz11XnS1L67+M9BHXqFlNk/Gn6s3i2tx74t0lvneVmU7Tfa6ibvmPLfoyKxYVVqDigxY2SSQ= X-Received: by 10.182.128.234 with SMTP id nr10mr129823obb.0.1398804243380; Tue, 29 Apr 2014 13:44:03 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id y50si2709251yhk.4.2014.04.29.13.44.03 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Apr 2014 13:44:03 -0700 (PDT) Received: from ushik.mtv.corp.google.com (ushik.mtv.corp.google.com [172.18.120.113]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 2648531C1F4 for ; Tue, 29 Apr 2014 13:44:03 -0700 (PDT) Received: by ushik.mtv.corp.google.com (Postfix, from userid 57417) id B335113F9B0; Tue, 29 Apr 2014 13:44:02 -0700 (PDT) From: Dmitry Shmidt Date: Tue, 29 Apr 2014 13:41:47 -0700 Subject: [PATCH] Add 'dup_network ' command To: hostap@lists.shmoo.com Message-Id: <20140429204402.B335113F9B0@ushik.mtv.corp.google.com> X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com This command allows to copy network variable from one network to another Change-Id: Ide1d672e21e0864a524f7cce1066a0c9be7b4c28 Signed-off-by: Dmitry Shmidt --- wpa_supplicant/ctrl_iface.c | 117 ++++++++++++++++++++++++++++++++++---------- wpa_supplicant/wpa_cli.c | 22 +++++++++ 2 files changed, 113 insertions(+), 26 deletions(-) diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index b8b6d95..767485d 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -2495,6 +2495,39 @@ static int wpa_supplicant_ctrl_iface_remove_network( } +static int wpa_supplicant_ctrl_iface_update_network( + struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, + char *name, char *value) +{ + if (wpa_config_set(ssid, name, value, 0) < 0) { + wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " + "variable '%s'", name); + return -1; + } + + if (os_strcmp(name, "bssid") != 0 && + os_strcmp(name, "priority") != 0) + wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); + + if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) { + /* + * Invalidate the EAP session cache if anything in the current + * or previously used configuration changes. + */ + eapol_sm_invalidate_cached_session(wpa_s->eapol); + } + + if ((os_strcmp(name, "psk") == 0 && + value[0] == '"' && ssid->ssid_len) || + (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) + wpa_config_update_psk(ssid); + else if (os_strcmp(name, "priority") == 0) + wpa_config_update_prio_list(wpa_s->conf); + + return 0; +} + + static int wpa_supplicant_ctrl_iface_set_network( struct wpa_supplicant *wpa_s, char *cmd) { @@ -2526,32 +2559,8 @@ static int wpa_supplicant_ctrl_iface_set_network( return -1; } - if (wpa_config_set(ssid, name, value, 0) < 0) { - wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " - "variable '%s'", name); - return -1; - } - - if (os_strcmp(name, "bssid") != 0 && - os_strcmp(name, "priority") != 0) - wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); - - if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) { - /* - * Invalidate the EAP session cache if anything in the current - * or previously used configuration changes. - */ - eapol_sm_invalidate_cached_session(wpa_s->eapol); - } - - if ((os_strcmp(name, "psk") == 0 && - value[0] == '"' && ssid->ssid_len) || - (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) - wpa_config_update_psk(ssid); - else if (os_strcmp(name, "priority") == 0) - wpa_config_update_prio_list(wpa_s->conf); - - return 0; + return wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name, + value); } @@ -2599,6 +2608,59 @@ static int wpa_supplicant_ctrl_iface_get_network( } +static int wpa_supplicant_ctrl_iface_dup_network( + struct wpa_supplicant *wpa_s, char *cmd) +{ + struct wpa_ssid *ssid_s, *ssid_d; + char *name, *id, *value; + int id_s, id_d, ret; + + /* cmd: " " */ + id = os_strchr(cmd, ' '); + if (id == NULL) + return -1; + *id++ = '\0'; + + name = os_strchr(id, ' '); + if (name == NULL) + return -1; + *name++ = '\0'; + + id_s = atoi(cmd); + id_d = atoi(id); + wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'", + id_s, id_d, name); + + ssid_s = wpa_config_get_network(wpa_s->conf, id_s); + if (ssid_s == NULL) { + wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " + "network id=%d", id_s); + return -1; + } + + ssid_d = wpa_config_get_network(wpa_s->conf, id_d); + if (ssid_d == NULL) { + wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " + "network id=%d", id_s); + return -1; + } + + value = wpa_config_get(ssid_s, name); + if (value == NULL) { + wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " + "variable '%s'", name); + return -1; + } + + ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name, + value); + + os_free(value); + + return ret; +} + + static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, char *buf, size_t buflen) { @@ -6450,6 +6512,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { reply_len = wpa_supplicant_ctrl_iface_get_network( wpa_s, buf + 12, reply, reply_size); + } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { + if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12)) + reply_len = -1; } else if (os_strcmp(buf, "LIST_CREDS") == 0) { reply_len = wpa_supplicant_ctrl_iface_list_creds( wpa_s, reply, reply_size); diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index 77c5295..759b8c9 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -1416,6 +1416,24 @@ static int wpa_cli_cmd_get_network(struct wpa_ctrl *ctrl, int argc, } +static int wpa_cli_cmd_dup_network(struct wpa_ctrl *ctrl, int argc, + char *argv[]) +{ + if (argc == 0) { + wpa_cli_show_network_variables(); + return 0; + } + + if (argc < 3) { + printf("Invalid DUP_NETWORK command: needs three arguments\n" + "(src netid, dest netid, and variable name)\n"); + return -1; + } + + return wpa_cli_cmd(ctrl, "DUP_NETWORK", 3, argc, argv); +} + + static int wpa_cli_cmd_list_creds(struct wpa_ctrl *ctrl, int argc, char *argv[]) { @@ -2570,6 +2588,10 @@ static struct wpa_cli_cmd wpa_cli_commands[] = { { "get_network", wpa_cli_cmd_get_network, NULL, cli_cmd_flag_none, " = get network variables" }, + { "dup_network", wpa_cli_cmd_dup_network, NULL, + cli_cmd_flag_sensitive, + " = dup network variables" + " (shows\n list of variables when run without arguments)" }, { "list_creds", wpa_cli_cmd_list_creds, NULL, cli_cmd_flag_none, "= list configured credentials" },