summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-09-06 11:53:17 -0700
committerColin Cross <ccross@android.com>2018-09-06 15:55:28 -0700
commitbddd3ef5c1ab6e21e0e3e49fb2b410c9dabe5edc (patch)
tree9f285c76b408fde93771f4fa198e7486df5a1327
parent9666cb415d7d44a86cfb0b7ec1df6e6317fe3259 (diff)
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
-rw-r--r--libwifi_hal/driver_tool.cpp29
1 files 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 <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;