From f631e8e055dfcdae440631902ed8a38eb5109cb8 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 19 Sep 2013 07:45:02 +0200 Subject: added preflight worker implementation to handle initial device pairing --- src/main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/main.c') 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 static const char *socket_path = "/var/run/usbmuxd"; static const char *lockfile = "/var/run/usbmuxd.pid"; +static const char *userprefdir = "/var/lib/lockdown"; int should_exit; int should_discover; @@ -285,9 +286,6 @@ static int daemonize(void) close(pfd[0]); report_to_parent = 1; - // Change the file mode mask - umask(0); - // Create a new SID for the child process sid = setsid(); if (sid < 0) { @@ -531,6 +529,13 @@ int main(int argc, char *argv[]) if(listenfd < 0) goto terminate; + struct stat fst; + int userprefdir_created = 0; + if (stat(userprefdir, &fst) < 0) { + mkdir(userprefdir, 0775); + userprefdir_created = 1; + } + // drop elevated privileges if (drop_privileges && (getuid() == 0 || geteuid() == 0)) { struct passwd *pw; @@ -548,6 +553,15 @@ int main(int argc, char *argv[]) if (pw->pw_uid == 0) { usbmuxd_log(LL_INFO, "Not dropping privileges to root"); } else { + if (userprefdir_created) { + if (chown(userprefdir, pw->pw_uid, pw->pw_gid) < 0) { + usbmuxd_log(LL_WARNING, "chown(%s, %d, %d) failed", userprefdir, pw->pw_uid, pw->pw_gid); + } + if (chmod(userprefdir, 02775) < 0) { + usbmuxd_log(LL_WARNING, "chmod %s failed", userprefdir); + } + } + if ((res = initgroups(drop_user, pw->pw_gid)) < 0) { usbmuxd_log(LL_FATAL, "Failed to drop privileges (cannot set supplementary groups)"); goto terminate; -- cgit v1.1-32-gdbae