summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2013-09-19 07:45:02 +0200
committerGravatar Nikias Bassen2013-09-19 07:45:02 +0200
commitf631e8e055dfcdae440631902ed8a38eb5109cb8 (patch)
treeeeac77f6fef5eea8399160dc2ca1cb001ecfc338 /src/main.c
parent23bcddf12b520f613451705e3f85c38c40333a90 (diff)
downloadusbmuxd-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.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 32c6a2b..1804c30 100644
--- a/src/main.c
+++ b/src/main.c
@@ -49,6 +49,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
49 49
50static const char *socket_path = "/var/run/usbmuxd"; 50static const char *socket_path = "/var/run/usbmuxd";
51static const char *lockfile = "/var/run/usbmuxd.pid"; 51static const char *lockfile = "/var/run/usbmuxd.pid";
52static const char *userprefdir = "/var/lib/lockdown";
52 53
53int should_exit; 54int should_exit;
54int should_discover; 55int 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;