summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2015-01-26 23:29:18 +0100
committerEthan Chen <intervigil@gmail.com>2015-01-27 14:41:51 -0800
commit7558b9dda2fba785cdf30a3e352909f82d2c9a7d (patch)
tree8c4ac0b397b2180afe8d236858895ac44fd5ad9e
parent7f517d761b99078960fbd9333127c735805db88d (diff)
downloadandroid_hardware_samsung-7558b9dda2fba785cdf30a3e352909f82d2c9a7d.tar.gz
android_hardware_samsung-7558b9dda2fba785cdf30a3e352909f82d2c9a7d.tar.bz2
android_hardware_samsung-7558b9dda2fba785cdf30a3e352909f82d2c9a7d.zip
macloader: Use fchown() to change owner of the cidfile.
Change-Id: Ia99c0ae414366d91b6d0112f50b00630749ea570 Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--macloader/macloader.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/macloader/macloader.c b/macloader/macloader.c
index 89b657d..a9c0d5b 100644
--- a/macloader/macloader.c
+++ b/macloader/macloader.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <pwd.h>
#include <cutils/log.h>
@@ -118,6 +119,9 @@ int main() {
}
if (type != NONE) {
+ struct passwd *pwd;
+ int fd;
+
/* open cid file */
cidfile = fopen(CID_PATH, "w");
if(cidfile == 0) {
@@ -172,20 +176,28 @@ int main() {
fd = fileno(cidfile);
amode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
ret = fchmod(fd, amode);
- fclose(cidfile);
if (ret != 0) {
+ fclose(cidfile);
ALOGE("Can't set permissions on %s - %s\n",
CID_PATH, strerror(errno));
return 1;
}
- char* chown_cmd = (char*) malloc(strlen("chown system ") + strlen(CID_PATH) + 1);
- char* chgrp_cmd = (char*) malloc(strlen("chgrp system ") + strlen(CID_PATH) + 1);
- sprintf(chown_cmd, "chown system %s", CID_PATH);
- sprintf(chgrp_cmd, "chgrp system %s", CID_PATH);
- system(chown_cmd);
- system(chgrp_cmd);
+ pwd = getpwnam("system");
+ if (pwd == NULL) {
+ fclose(cidfile);
+ ALOGE("Failed to find 'system' user - %s\n",
+ strerror(errno));
+ return 1;
+ }
+ ret = fchown(fd, pwd->pw_uid, pwd->pw_gid);
+ fclose(cidfile);
+ if (ret != 0) {
+ ALOGE("Failed to change owner of %s - %s\n",
+ CID_PATH, strerror(errno));
+ return 1;
+ }
} else {
/* delete cid file if no specific type */
ALOGD("Deleting file %s\n", CID_PATH);