FROMLIST: D-Bus: share 'remove all networks' with CLI

The D-Bus implementation of RemoveAllNetworks differs wildly from the
CLI implementation. Let's share the implementations.

This resolves use-after-free bugs I noticed, where we continue to use
the 'wpa_s->current_ssid' wpa_ssid object after freeing it, because we
didn't bother to disconnect from (and set to NULL) current_ssid before
freeing it.

Signed-off-by: Brian Norris <briannorris@chromium.org>
(am from https://patchwork.ozlabs.org/patch/1348134/)
(also found at https://marc.info/?i=20200820020935.954467-2-briannorris@chromium.org)

BUG=b:164231396
TEST=`tast run -var network.HostapHwsim.runArgs=dbus_remove_connected
     localhost:9222 network.HostapHwsim.full` (requires additional dbus-
     test support) -- especially with ASAN enabled
TEST=`gdbus call -y -d fi.w1.wpa_supplicant1 -o
     /fi/w1/wpa_supplicant1/Interfaces/0 -m
     fi.w1.wpa_supplicant1.Interface.RemoveAllNetworks` -- especially
     with ASAN enabled

Change-Id: I1508d2837e7677371015b852d16c4a4d83b7d367
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/hostap/+/2368059
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Matthew Wang <matthewmwang@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Commit-Queue: Brian Norris <briannorris@chromium.org>
(cherry picked from commit 240cb8214397fc9e08b27af29c98cf2685f6e7a4)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/hostap/+/2372733
Reviewed-by: Brian Norris <briannorris@chromium.org>
4 files changed