Use Android reserved namespace for control interface

On Android, use a special reserved namespace for the UNIX domain
socket.
This commit is contained in:
Dmitry Shmidt 2011-02-27 18:19:17 +02:00 committed by Jouni Malinen
parent 1480633f96
commit b3f3865e0e
2 changed files with 52 additions and 0 deletions

View File

@ -20,6 +20,11 @@
#include <sys/un.h> #include <sys/un.h>
#endif /* CONFIG_CTRL_IFACE_UNIX */ #endif /* CONFIG_CTRL_IFACE_UNIX */
#ifdef ANDROID
#include <cutils/sockets.h>
#include "private/android_filesystem_config.h"
#endif /* ANDROID */
#include "wpa_ctrl.h" #include "wpa_ctrl.h"
#include "common.h" #include "common.h"
@ -105,6 +110,31 @@ try_again:
return NULL; return NULL;
} }
#ifdef ANDROID
chmod(ctrl->local.sun_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
chown(ctrl->local.sun_path, AID_SYSTEM, AID_WIFI);
/*
* If the ctrl_path isn't an absolute pathname, assume that
* it's the name of a socket in the Android reserved namespace.
* Otherwise, it's a normal UNIX domain socket appearing in the
* filesystem.
*/
if (ctrl_path != NULL && *ctrl_path != '/') {
char buf[21];
os_snprintf(buf, sizeof(buf), "wpa_%s", ctrl_path);
if (socket_local_client_connect(
ctrl->s, buf,
ANDROID_SOCKET_NAMESPACE_RESERVED,
SOCK_DGRAM) < 0) {
close(ctrl->s);
unlink(ctrl->local.sun_path);
os_free(ctrl);
return NULL;
}
return ctrl;
}
#endif /* ANDROID */
ctrl->dest.sun_family = AF_UNIX; ctrl->dest.sun_family = AF_UNIX;
res = os_strlcpy(ctrl->dest.sun_path, ctrl_path, res = os_strlcpy(ctrl->dest.sun_path, ctrl_path,
sizeof(ctrl->dest.sun_path)); sizeof(ctrl->dest.sun_path));

View File

@ -17,6 +17,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <grp.h> #include <grp.h>
#include <stddef.h> #include <stddef.h>
#ifdef ANDROID
#include <cutils/sockets.h>
#endif /* ANDROID */
#include "utils/common.h" #include "utils/common.h"
#include "utils/eloop.h" #include "utils/eloop.h"
@ -276,6 +279,13 @@ wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
buf = os_strdup(wpa_s->conf->ctrl_interface); buf = os_strdup(wpa_s->conf->ctrl_interface);
if (buf == NULL) if (buf == NULL)
goto fail; goto fail;
#ifdef ANDROID
os_snprintf(addr.sun_path, sizeof(addr.sun_path), "wpa_%s",
wpa_s->conf->ctrl_interface);
priv->sock = android_get_control_socket(addr.sun_path);
if (priv->sock >= 0)
goto havesock;
#endif /* ANDROID */
if (os_strncmp(buf, "DIR=", 4) == 0) { if (os_strncmp(buf, "DIR=", 4) == 0) {
dir = buf + 4; dir = buf + 4;
gid_str = os_strstr(dir, " GROUP="); gid_str = os_strstr(dir, " GROUP=");
@ -398,6 +408,9 @@ wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
} }
os_free(fname); os_free(fname);
#ifdef ANDROID
havesock:
#endif /* ANDROID */
eloop_register_read_sock(priv->sock, wpa_supplicant_ctrl_iface_receive, eloop_register_read_sock(priv->sock, wpa_supplicant_ctrl_iface_receive,
wpa_s, priv); wpa_s, priv);
wpa_msg_register_cb(wpa_supplicant_ctrl_iface_msg_cb); wpa_msg_register_cb(wpa_supplicant_ctrl_iface_msg_cb);
@ -637,6 +650,12 @@ wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
if (global->params.ctrl_interface == NULL) if (global->params.ctrl_interface == NULL)
return priv; return priv;
#ifdef ANDROID
priv->sock = android_get_control_socket(global->params.ctrl_interface);
if (priv->sock >= 0)
goto havesock;
#endif /* ANDROID */
wpa_printf(MSG_DEBUG, "Global control interface '%s'", wpa_printf(MSG_DEBUG, "Global control interface '%s'",
global->params.ctrl_interface); global->params.ctrl_interface);
@ -685,6 +704,9 @@ wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
} }
} }
#ifdef ANDROID
havesock:
#endif /* ANDROID */
eloop_register_read_sock(priv->sock, eloop_register_read_sock(priv->sock,
wpa_supplicant_global_ctrl_iface_receive, wpa_supplicant_global_ctrl_iface_receive,
global, NULL); global, NULL);