diff options
| author | 2013-12-10 19:13:49 +0100 | |
|---|---|---|
| committer | 2013-12-10 19:13:49 +0100 | |
| commit | ed73eddb895909f8c80fedab0d8753af15e6f394 (patch) | |
| tree | f96d8a5dfbd22cb775b10aef5699c4682f8d0444 /src/main.c | |
| parent | a648e0b133a4e372544c1ddfe2e45084e2b2c50a (diff) | |
| download | usbmuxd-ed73eddb895909f8c80fedab0d8753af15e6f394.tar.gz usbmuxd-ed73eddb895909f8c80fedab0d8753af15e6f394.tar.bz2 | |
main: make sure the non-privileged user has proper access to the config dir
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 30 |
1 files changed, 21 insertions, 9 deletions
| @@ -535,12 +535,26 @@ int main(int argc, char *argv[]) | |||
| 535 | 535 | ||
| 536 | #ifdef HAVE_LIBIMOBILEDEVICE | 536 | #ifdef HAVE_LIBIMOBILEDEVICE |
| 537 | const char* userprefdir = userpref_get_config_dir(); | 537 | const char* userprefdir = userpref_get_config_dir(); |
| 538 | |||
| 539 | struct stat fst; | 538 | struct stat fst; |
| 540 | int userprefdir_created = 0; | 539 | memset(&fst, '\0', sizeof(struct stat)); |
| 541 | if (stat(userprefdir, &fst) < 0) { | 540 | if (stat(userprefdir, &fst) < 0) { |
| 542 | mkdir(userprefdir, 0775); | 541 | if (mkdir(userprefdir, 0775) < 0) { |
| 543 | userprefdir_created = 1; | 542 | usbmuxd_log(LL_FATAL, "Failed to create required directory '%s': %s\n", userprefdir, strerror(errno)); |
| 543 | res = -1; | ||
| 544 | goto terminate; | ||
| 545 | } | ||
| 546 | if (stat(userprefdir, &fst) < 0) { | ||
| 547 | usbmuxd_log(LL_FATAL, "stat() failed after creating directory '%s': %s\n", userprefdir, strerror(errno)); | ||
| 548 | res = -1; | ||
| 549 | goto terminate; | ||
| 550 | } | ||
| 551 | } | ||
| 552 | |||
| 553 | // make sure permission bits are set correctly | ||
| 554 | if (fst.st_mode != 02775) { | ||
| 555 | if (chmod(userprefdir, 02775) < 0) { | ||
| 556 | usbmuxd_log(LL_WARNING, "chmod(%s, 02775) failed: %s", userprefdir, strerror(errno)); | ||
| 557 | } | ||
| 544 | } | 558 | } |
| 545 | #endif | 559 | #endif |
| 546 | 560 | ||
| @@ -562,12 +576,10 @@ int main(int argc, char *argv[]) | |||
| 562 | usbmuxd_log(LL_INFO, "Not dropping privileges to root"); | 576 | usbmuxd_log(LL_INFO, "Not dropping privileges to root"); |
| 563 | } else { | 577 | } else { |
| 564 | #ifdef HAVE_LIBIMOBILEDEVICE | 578 | #ifdef HAVE_LIBIMOBILEDEVICE |
| 565 | if (userprefdir_created) { | 579 | /* make sure the non-privileged user has proper access to the config directory */ |
| 580 | if ((fst.st_uid != pw->pw_uid) || (fst.st_gid != pw->pw_gid)) { | ||
| 566 | if (chown(userprefdir, pw->pw_uid, pw->pw_gid) < 0) { | 581 | if (chown(userprefdir, pw->pw_uid, pw->pw_gid) < 0) { |
| 567 | usbmuxd_log(LL_WARNING, "chown(%s, %d, %d) failed", userprefdir, pw->pw_uid, pw->pw_gid); | 582 | usbmuxd_log(LL_WARNING, "chown(%s, %d, %d) failed: %s", userprefdir, pw->pw_uid, pw->pw_gid, strerror(errno)); |
| 568 | } | ||
| 569 | if (chmod(userprefdir, 02775) < 0) { | ||
| 570 | usbmuxd_log(LL_WARNING, "chmod %s failed", userprefdir); | ||
| 571 | } | 583 | } |
| 572 | } | 584 | } |
| 573 | #endif | 585 | #endif |
