diff options
author | Andre Heider <a.heider@gmail.com> | 2022-11-13 21:11:06 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-12-15 20:11:12 +0100 |
commit | dd4e1ffeacfde2499da67d523f548dead52e04c7 (patch) | |
tree | a9d09fdbc2f72f8f6e14f1e86982ba1aa3bec81e /iwinfo_nl80211.c | |
parent | d6381634c28bfdc9701352146a82a4e8c35f4eff (diff) | |
download | iwinfo-dd4e1ffeacfde2499da67d523f548dead52e04c7.tar.gz |
nl80211: fix wpa supplicant ctrl socket permissions
No data at all can currently be read from the control socket.
Set up the permission exactly like hostapd's wpa_cli utility to fix it.
Among other this fixes a mesh's encryption being shown as "None".
Signed-off-by: Andre Heider <a.heider@gmail.com>
Diffstat (limited to 'iwinfo_nl80211.c')
-rw-r--r-- | iwinfo_nl80211.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index f852ed1..aceef18 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -938,6 +938,18 @@ static int nl80211_wpactl_connect(const char *ifname, struct sockaddr_un *local) sprintf(remote.sun_path, "/var/run/wpa_supplicant-%s/%s", ifname, ifname); + /* Set client socket file permissions so that bind() creates the client + * socket with these permissions and there is no need to try to change + * them with chmod() after bind() which would have potential issues with + * race conditions. These permissions are needed to make sure the server + * side (wpa_supplicant or hostapd) can reply to the control interface + * messages. + * + * The lchown() calls below after bind() are also part of the needed + * operations to allow the response to go through. Those are using the + * no-deference-symlinks version to avoid races. */ + fchmod(sock, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + if (fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC) < 0) { close(sock); @@ -966,6 +978,10 @@ static int nl80211_wpactl_connect(const char *ifname, struct sockaddr_un *local) return -1; } + /* Set group even if we do not have privileges to change owner */ + lchown(local->sun_path, -1, 101); + lchown(local->sun_path, 101, 101); + return sock; } |