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
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;