Style & build warning fix 81/69681/1
authorSangyoon Jang <s89.jang@samsung.com>
Mon, 16 May 2016 10:14:13 +0000 (19:14 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Mon, 16 May 2016 10:14:13 +0000 (19:14 +0900)
- use nullptr instead of NULL
- one variable per one line
- return false when setuid failed

Change-Id: I8f23d9c52da418110cb41cc7f11e4b186fff2ff2
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/common/shared_dirs.cc
src/common/step/security/step_privilege_compatibility.cc
src/common/tzip_interface.cc
src/common/utils/subprocess.cc

index ff142e4..396e35f 100644 (file)
@@ -231,11 +231,12 @@ bool CreateDirectories(const bf::path& app_dir, const std::string& pkgid,
 }
 
 bf::path GetDirectoryPathForStorage(uid_t user, std::string apps_prefix) {
-  struct passwd pwd, *pwd_result;
+  struct passwd pwd;
+  struct passwd *pwd_result;
   char buf[1024] = {0, };
 
   int ret = getpwuid_r(user, &pwd, buf, sizeof(buf), &pwd_result);
-  if (ret != 0 || pwd_result == NULL)
+  if (ret != 0 || pwd_result == nullptr)
     return {};
 
   bf::path apps_rw;
@@ -249,14 +250,16 @@ bool CreateUserDirectories(uid_t user, const std::string& pkgid,
     const std::string& apps_prefix, const bool set_permissions) {
   char buf[1024] = {0, };
 
-  struct passwd pwd, *pwd_result;
+  struct passwd pwd;
+  struct passwd *pwd_result;
   int ret = getpwuid_r(user, &pwd, buf, sizeof(buf), &pwd_result);
-  if (ret != 0 || pwd_result == NULL) {
+  if (ret != 0 || pwd_result == nullptr) {
     LOG(WARNING) << "Failed to get user for home directory: " << user;
     return false;
   }
 
-  struct group gr, *gr_result;
+  struct group gr;
+  struct group *gr_result;
   ret = getgrgid_r(pwd.pw_gid, &gr, buf, sizeof(buf), &gr_result);
   if (ret != 0
       || strcmp(gr.gr_name, tzplatform_getenv(TZ_SYS_USER_GROUP)) != 0)
@@ -299,16 +302,18 @@ bool DeletePerUserDirectories(const std::string& pkgid) {
       return false;
     const bf::path& home_path = iter->path();
     std::string user = home_path.filename().string();
-    struct passwd pwd, *pwd_result;
+    struct passwd pwd;
+    struct passwd *pwd_result;
     int ret = getpwnam_r(user.c_str(), &pwd, buf, sizeof(buf), &pwd_result);
-    if (ret != 0 || pwd_result == NULL) {
+    if (ret != 0 || pwd_result == nullptr) {
       LOG(WARNING) << "Failed to get user for home directory: " << user;
       continue;
     }
 
-    struct group gr, *gr_result;
+    struct group gr;
+    struct group *gr_result;
     ret = getgrgid_r(pwd.pw_gid, &gr, buf, sizeof(buf), &gr_result);
-    if (ret != 0 || gr_result == NULL ||
+    if (ret != 0 || gr_result == nullptr ||
         strcmp(gr.gr_name, tzplatform_getenv(TZ_SYS_USER_GROUP)) != 0)
       continue;
 
@@ -390,12 +395,14 @@ bool PerformInternalDirectoryCreationForAllUsers(const std::string& pkgid,
     const bf::path& home_path = iter->path();
     std::string user = home_path.filename().string();
 
-    struct passwd pwd, *pwd_result;
+    struct passwd pwd;
+    struct passwd *pwd_result;
     int ret = getpwnam_r(user.c_str(), &pwd, buf, sizeof(buf), &pwd_result);
-    if (ret != 0 || pwd_result == NULL)
+    if (ret != 0 || pwd_result == nullptr)
       continue;
 
-    struct group gr, *gr_result;
+    struct group gr;
+    struct group *gr_result;
     ret = getgrgid_r(pwd.pw_gid, &gr, buf, sizeof(buf), &gr_result);
     if (ret != 0 ||
         strcmp(gr.gr_name, tzplatform_getenv(TZ_SYS_USER_GROUP)) != 0)
@@ -427,12 +434,14 @@ bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid,
     const bf::path& home_path = iter->path();
     std::string user = home_path.filename().string();
 
-    struct passwd pwd, *pwd_result;
+    struct passwd pwd;
+    struct passwd *pwd_result;
     int ret = getpwnam_r(user.c_str(), &pwd, buf, sizeof(buf), &pwd_result);
-    if (ret != 0 || pwd_result == NULL)
+    if (ret != 0 || pwd_result == nullptr)
       continue;
 
-    struct group gr, *gr_result;
+    struct group gr;
+    struct group *gr_result;
     ret = getgrgid_r(pwd.pw_gid, &gr, buf, sizeof(buf), &gr_result);
     if (ret != 0 ||
         strcmp(gr.gr_name, tzplatform_getenv(TZ_SYS_USER_GROUP)) != 0)
@@ -455,7 +464,7 @@ bool SetPackageDirectorySmackRulesForUser(uid_t uid,
   struct passwd pwd;
   struct passwd *pwd_result;
   int ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result);
-  if (ret != 0 || pwd_result == NULL) {
+  if (ret != 0 || pwd_result == nullptr) {
     LOG(WARNING) << "Failed to get user for home directory: " << uid;
     return false;
   }
@@ -483,9 +492,10 @@ bool SetPackageDirectorySmackRulesForAllUsers(const std::string& pkg_id,
     const bf::path& home_path = iter->path();
     std::string user = home_path.filename().string();
 
-    struct passwd pwd, *pwd_result;
+    struct passwd pwd;
+    struct passwd*pwd_result;
     int ret = getpwnam_r(user.c_str(), &pwd, buf, sizeof(buf), &pwd_result);
-    if (ret != 0 || pwd_result == NULL) {
+    if (ret != 0 || pwd_result == nullptr) {
       LOG(WARNING) << "Failed to get user for home directory: " << user;
       return false;
     }
index 97a34a4..0a192a0 100644 (file)
@@ -49,7 +49,7 @@ bool TranslatePrivilegesForCompatibility(manifest_x* m) {
   // set pkgmgr new list
   g_list_free_full(m->privileges, free);
   m->privileges = nullptr;
-  for (GList* l = mapped_privilege_list; l != NULL; l = l->next) {
+  for (GList* l = mapped_privilege_list; l != nullptr; l = l->next) {
     m->privileges = g_list_append(m->privileges,
                                   strdup(reinterpret_cast<char*>(l->data)));
   }
index 2c58549..32e2aa3 100644 (file)
@@ -83,7 +83,7 @@ class TzipInterface::Pimpl {
   }
 
   bool UnmountZip() {
-    DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+    DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, nullptr);
     if (!conn) {
       return false;
     }
index 6f4cc25..a20ee5f 100644 (file)
@@ -34,8 +34,12 @@ bool Subprocess::RunWithArgs(const std::vector<std::string>& args) {
       argv[i] = args[i - 1].c_str();
     }
     argv[args.size() + 1] = nullptr;
-    if (uid_ != -1)
-      setuid(uid_);
+    if (uid_ != -1) {
+      if (setuid(uid_)) {
+        LOG(ERROR) << "Failed to setuid";
+        return false;
+      }
+    }
     execvp(argv[0], const_cast<char* const*>(argv.get()));
     LOG(ERROR) << "Failed to execv";
     return false;