diff options
| author | 2013-09-19 07:45:02 +0200 | |
|---|---|---|
| committer | 2013-09-19 07:45:02 +0200 | |
| commit | f631e8e055dfcdae440631902ed8a38eb5109cb8 (patch) | |
| tree | eeac77f6fef5eea8399160dc2ca1cb001ecfc338 /src/main.c | |
| parent | 23bcddf12b520f613451705e3f85c38c40333a90 (diff) | |
| download | usbmuxd-f631e8e055dfcdae440631902ed8a38eb5109cb8.tar.gz usbmuxd-f631e8e055dfcdae440631902ed8a38eb5109cb8.tar.bz2 | |
added preflight worker implementation to handle initial device pairing
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 20 |
1 files changed, 17 insertions, 3 deletions
| @@ -49,6 +49,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||
| 49 | 49 | ||
| 50 | static const char *socket_path = "/var/run/usbmuxd"; | 50 | static const char *socket_path = "/var/run/usbmuxd"; |
| 51 | static const char *lockfile = "/var/run/usbmuxd.pid"; | 51 | static const char *lockfile = "/var/run/usbmuxd.pid"; |
| 52 | static const char *userprefdir = "/var/lib/lockdown"; | ||
| 52 | 53 | ||
| 53 | int should_exit; | 54 | int should_exit; |
| 54 | int should_discover; | 55 | int should_discover; |
| @@ -285,9 +286,6 @@ static int daemonize(void) | |||
| 285 | close(pfd[0]); | 286 | close(pfd[0]); |
| 286 | report_to_parent = 1; | 287 | report_to_parent = 1; |
| 287 | 288 | ||
| 288 | // Change the file mode mask | ||
| 289 | umask(0); | ||
| 290 | |||
| 291 | // Create a new SID for the child process | 289 | // Create a new SID for the child process |
| 292 | sid = setsid(); | 290 | sid = setsid(); |
| 293 | if (sid < 0) { | 291 | if (sid < 0) { |
| @@ -531,6 +529,13 @@ int main(int argc, char *argv[]) | |||
| 531 | if(listenfd < 0) | 529 | if(listenfd < 0) |
| 532 | goto terminate; | 530 | goto terminate; |
| 533 | 531 | ||
| 532 | struct stat fst; | ||
| 533 | int userprefdir_created = 0; | ||
| 534 | if (stat(userprefdir, &fst) < 0) { | ||
| 535 | mkdir(userprefdir, 0775); | ||
| 536 | userprefdir_created = 1; | ||
| 537 | } | ||
| 538 | |||
| 534 | // drop elevated privileges | 539 | // drop elevated privileges |
| 535 | if (drop_privileges && (getuid() == 0 || geteuid() == 0)) { | 540 | if (drop_privileges && (getuid() == 0 || geteuid() == 0)) { |
| 536 | struct passwd *pw; | 541 | struct passwd *pw; |
| @@ -548,6 +553,15 @@ int main(int argc, char *argv[]) | |||
| 548 | if (pw->pw_uid == 0) { | 553 | if (pw->pw_uid == 0) { |
| 549 | usbmuxd_log(LL_INFO, "Not dropping privileges to root"); | 554 | usbmuxd_log(LL_INFO, "Not dropping privileges to root"); |
| 550 | } else { | 555 | } else { |
| 556 | if (userprefdir_created) { | ||
| 557 | if (chown(userprefdir, pw->pw_uid, pw->pw_gid) < 0) { | ||
| 558 | usbmuxd_log(LL_WARNING, "chown(%s, %d, %d) failed", userprefdir, pw->pw_uid, pw->pw_gid); | ||
| 559 | } | ||
| 560 | if (chmod(userprefdir, 02775) < 0) { | ||
| 561 | usbmuxd_log(LL_WARNING, "chmod %s failed", userprefdir); | ||
| 562 | } | ||
| 563 | } | ||
| 564 | |||
| 551 | if ((res = initgroups(drop_user, pw->pw_gid)) < 0) { | 565 | if ((res = initgroups(drop_user, pw->pw_gid)) < 0) { |
| 552 | usbmuxd_log(LL_FATAL, "Failed to drop privileges (cannot set supplementary groups)"); | 566 | usbmuxd_log(LL_FATAL, "Failed to drop privileges (cannot set supplementary groups)"); |
| 553 | goto terminate; | 567 | goto terminate; |
