From bddd3ef5c1ab6e21e0e3e49fb2b410c9dabe5edc Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 6 Sep 2018 11:53:17 -0700 Subject: Use getpwnam and getgrnam in libwifi_hal libwifi_hal is a vendor module, but it was accidentally getting the core version of the libcutils headers which included private/android_filesystem_config.h. Change it to using getpwnam("wifi") and getgrnam("wifi") instead of AID_WIFI. Test: m checkbuild Bug: 63135587 Bug: 114238698 Change-Id: I28f20fd9f4868c0d1e25fda64f477f6d551cc1dd --- libwifi_hal/driver_tool.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/libwifi_hal/driver_tool.cpp b/libwifi_hal/driver_tool.cpp index 3089ee0a4..0b393d782 100644 --- a/libwifi_hal/driver_tool.cpp +++ b/libwifi_hal/driver_tool.cpp @@ -14,10 +14,13 @@ * limitations under the License. */ +#include +#include +#include + #include "wifi_hal/driver_tool.h" #include -#include #include "hardware_legacy/wifi.h" @@ -35,7 +38,29 @@ bool DriverTool::TakeOwnershipOfFirmwareReload() { return true; // HAL doesn't think we need to load firmware for any mode. } - if (chown(WIFI_DRIVER_FW_PATH_PARAM, AID_WIFI, AID_WIFI) != 0) { + errno = 0; + struct passwd *pwd = getpwnam("wifi"); + if (pwd == nullptr) { + if (errno == 0) { + PLOG(ERROR) << "No user 'wifi' found"; + } else { + PLOG(ERROR) << "Error getting uid for wifi: " << strerror(errno); + } + return false; + } + + errno = 0; + struct group *grp = getgrnam("wifi"); + if (grp == nullptr) { + if (errno == 0) { + PLOG(ERROR) << "No group 'wifi' found"; + } else { + PLOG(ERROR) << "Error getting gid for wifi: " << strerror(errno); + } + return false; + } + + if (chown(WIFI_DRIVER_FW_PATH_PARAM, pwd->pw_uid, grp->gr_gid) != 0) { PLOG(ERROR) << "Error changing ownership of '" << WIFI_DRIVER_FW_PATH_PARAM << "' to wifi:wifi"; return false; -- cgit v1.2.3