diff options
author | Colin Cross <ccross@android.com> | 2018-09-06 21:59:37 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-09-06 21:59:37 -0700 |
commit | 260b4dd50a4e670d74c6916ae3d8d564e09b7f90 (patch) | |
tree | 9146cee49839ada00ebc2aee46e237e41e8397ad | |
parent | b7d5cdad5f876ce8f9556cde1714c6cb84b06604 (diff) | |
parent | b12f48bf47d8365f0848fc72245f3726e8481ebc (diff) |
Use getpwnam and getgrnam in libwifi_hal am: bddd3ef5c1 am: a1df98147e
am: b12f48bf47
Change-Id: I148977dba7f19dbcacdcedcb3a33bb90adbfd5ac
-rw-r--r-- | libwifi_hal/driver_tool.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/libwifi_hal/driver_tool.cpp b/libwifi_hal/driver_tool.cpp index d4d0c1f99..405254824 100644 --- a/libwifi_hal/driver_tool.cpp +++ b/libwifi_hal/driver_tool.cpp @@ -14,10 +14,13 @@ * limitations under the License. */ +#include <grp.h> +#include <pwd.h> +#include <sys/types.h> + #include "wifi_hal/driver_tool.h" #include <android-base/logging.h> -#include <private/android_filesystem_config.h> #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; |