summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt McCutchen <matt@mattmccutchen.net>2008-11-10 08:55:27 -0500
committerColin Walters <walters@verbum.org>2009-01-06 19:57:34 -0500
commit545e43870e9c01779cab1176cbbae27158a98fb4 (patch)
treee254496c2de0caf3eeab226a19ce4ed2b1e8aebe
parent2304473d97a69341de118680f45f9c832756f4b2 (diff)
Bug 18446: Keep umask for session bus
Signed-off-by: Colin Walters <walters@verbum.org>
-rw-r--r--bus/bus.c5
-rw-r--r--bus/config-parser-common.c8
-rw-r--r--bus/config-parser-common.h3
-rw-r--r--bus/config-parser.c32
-rw-r--r--bus/config-parser.h1
-rw-r--r--bus/dbus-daemon.1.in7
-rw-r--r--bus/session.conf.in4
-rw-r--r--dbus/dbus-sysdeps-util-unix.c13
-rw-r--r--dbus/dbus-sysdeps-util-win.c4
-rw-r--r--dbus/dbus-sysdeps.h3
-rw-r--r--doc/busconfig.dtd2
11 files changed, 72 insertions, 10 deletions
diff --git a/bus/bus.c b/bus/bus.c
index e38d4a23..f5b6e7ec 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -55,6 +55,7 @@ struct BusContext
BusLimits limits;
unsigned int fork : 1;
unsigned int syslog : 1;
+ unsigned int keep_umask : 1;
};
static dbus_int32_t server_data_slot = -1;
@@ -386,6 +387,7 @@ process_config_first_time_only (BusContext *context,
context->fork = bus_config_parser_get_fork (parser);
context->syslog = bus_config_parser_get_syslog (parser);
+ context->keep_umask = bus_config_parser_get_keep_umask (parser);
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
retval = TRUE;
@@ -710,7 +712,8 @@ bus_context_new (const DBusString *config_file,
if (!_dbus_become_daemon (context->pidfile ? &u : NULL,
print_pid_pipe,
- error))
+ error,
+ context->keep_umask))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
goto failed;
diff --git a/bus/config-parser-common.c b/bus/config-parser-common.c
index ce590861..88e099ac 100644
--- a/bus/config-parser-common.c
+++ b/bus/config-parser-common.c
@@ -118,6 +118,10 @@ bus_config_parser_element_name_to_type (const char *name)
{
return ELEMENT_SYSLOG;
}
+ else if (strcmp (name, "keep_umask") == 0)
+ {
+ return ELEMENT_KEEP_UMASK;
+ }
return ELEMENT_NONE;
}
@@ -168,7 +172,9 @@ bus_config_parser_element_type_to_name (ElementType type)
return "associate";
case ELEMENT_SYSLOG:
return "syslog";
- }
+ case ELEMENT_KEEP_UMASK:
+ return "keep_umask";
+ }
_dbus_assert_not_reached ("bad element type");
diff --git a/bus/config-parser-common.h b/bus/config-parser-common.h
index 4ecaa8d8..ae40d089 100644
--- a/bus/config-parser-common.h
+++ b/bus/config-parser-common.h
@@ -48,7 +48,8 @@ typedef enum
ELEMENT_ASSOCIATE,
ELEMENT_STANDARD_SESSION_SERVICEDIRS,
ELEMENT_STANDARD_SYSTEM_SERVICEDIRS,
- ELEMENT_SYSLOG
+ ELEMENT_SYSLOG,
+ ELEMENT_KEEP_UMASK
} ElementType;
ElementType bus_config_parser_element_name_to_type (const char *element_name);
diff --git a/bus/config-parser.c b/bus/config-parser.c
index a8de3ff3..38ce8a1d 100644
--- a/bus/config-parser.c
+++ b/bus/config-parser.c
@@ -112,6 +112,7 @@ struct BusConfigParser
unsigned int fork : 1; /**< TRUE to fork into daemon mode */
unsigned int syslog : 1; /**< TRUE to enable syslog */
+ unsigned int keep_umask : 1; /**< TRUE to keep original umask when forking */
unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */
};
@@ -308,6 +309,9 @@ merge_included (BusConfigParser *parser,
if (included->fork)
parser->fork = TRUE;
+ if (included->keep_umask)
+ parser->keep_umask = TRUE;
+
if (included->pidfile != NULL)
{
dbus_free (parser->pidfile);
@@ -710,11 +714,26 @@ start_busconfig_child (BusConfigParser *parser,
BUS_SET_OOM (error);
return FALSE;
}
-
+
parser->syslog = TRUE;
return TRUE;
}
+ else if (element_type == ELEMENT_KEEP_UMASK)
+ {
+ if (!check_no_attributes (parser, "keep_umask", attribute_names, attribute_values, error))
+ return FALSE;
+
+ if (push_element (parser, ELEMENT_KEEP_UMASK) == NULL)
+ {
+ BUS_SET_OOM (error);
+ return FALSE;
+ }
+
+ parser->keep_umask = TRUE;
+
+ return TRUE;
+ }
else if (element_type == ELEMENT_PIDFILE)
{
if (!check_no_attributes (parser, "pidfile", attribute_names, attribute_values, error))
@@ -1970,6 +1989,7 @@ bus_config_parser_end_element (BusConfigParser *parser,
case ELEMENT_DENY:
case ELEMENT_FORK:
case ELEMENT_SYSLOG:
+ case ELEMENT_KEEP_UMASK:
case ELEMENT_SELINUX:
case ELEMENT_ASSOCIATE:
case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
@@ -2256,6 +2276,7 @@ bus_config_parser_content (BusConfigParser *parser,
case ELEMENT_DENY:
case ELEMENT_FORK:
case ELEMENT_SYSLOG:
+ case ELEMENT_KEEP_UMASK:
case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
case ELEMENT_SELINUX:
@@ -2584,6 +2605,12 @@ bus_config_parser_get_syslog (BusConfigParser *parser)
return parser->syslog;
}
+dbus_bool_t
+bus_config_parser_get_keep_umask (BusConfigParser *parser)
+{
+ return parser->keep_umask;
+}
+
const char *
bus_config_parser_get_pidfile (BusConfigParser *parser)
{
@@ -2977,6 +3004,9 @@ config_parsers_equal (const BusConfigParser *a,
if (! bools_equal (a->fork, b->fork))
return FALSE;
+ if (! bools_equal (a->keep_umask, b->keep_umask))
+ return FALSE;
+
if (! bools_equal (a->is_toplevel, b->is_toplevel))
return FALSE;
diff --git a/bus/config-parser.h b/bus/config-parser.h
index b951d1d2..bb3a30f4 100644
--- a/bus/config-parser.h
+++ b/bus/config-parser.h
@@ -67,6 +67,7 @@ DBusList** bus_config_parser_get_mechanisms (BusConfigParser *parser);
dbus_bool_t bus_config_parser_get_fork (BusConfigParser *parser);
dbus_bool_t bus_config_parser_get_allow_anonymous (BusConfigParser *parser);
dbus_bool_t bus_config_parser_get_syslog (BusConfigParser *parser);
+dbus_bool_t bus_config_parser_get_keep_umask (BusConfigParser *parser);
const char* bus_config_parser_get_pidfile (BusConfigParser *parser);
const char* bus_config_parser_get_servicehelper (BusConfigParser *parser);
DBusList** bus_config_parser_get_service_dirs (BusConfigParser *parser);
diff --git a/bus/dbus-daemon.1.in b/bus/dbus-daemon.1.in
index 81439343..8342600e 100644
--- a/bus/dbus-daemon.1.in
+++ b/bus/dbus-daemon.1.in
@@ -214,6 +214,13 @@ into the background, etc.). This is generally used
rather than the \-\-fork command line option.
.TP
+.I "<keep_umask>"
+
+.PP
+If present, the bus daemon keeps its original umask when forking.
+This may be useful to avoid affecting the behavior of child processes.
+
+.TP
.I "<listen>"
.PP
diff --git a/bus/session.conf.in b/bus/session.conf.in
index b2dee5b3..794eb8da 100644
--- a/bus/session.conf.in
+++ b/bus/session.conf.in
@@ -8,6 +8,10 @@
<!-- Our well-known bus type, don't change this -->
<type>session</type>
+ <!-- If we fork, keep the user's original umask to avoid affecting
+ the behavior of child processes. -->
+ <keep_umask/>
+
<listen>unix:tmpdir=@DBUS_SESSION_SOCKET_DIR@</listen>
<standard_session_servicedirs />
diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c
index be7bc968..03928044 100644
--- a/dbus/dbus-sysdeps-util-unix.c
+++ b/dbus/dbus-sysdeps-util-unix.c
@@ -70,12 +70,14 @@
* @param pidfile #NULL, or pidfile to create
* @param print_pid_pipe pipe to print daemon's pid to, or -1 for none
* @param error return location for errors
+ * @param keep_umask #TRUE to keep the original umask
* @returns #FALSE on failure
*/
dbus_bool_t
_dbus_become_daemon (const DBusString *pidfile,
DBusPipe *print_pid_pipe,
- DBusError *error)
+ DBusError *error,
+ dbus_bool_t keep_umask)
{
const char *s;
pid_t child_pid;
@@ -122,9 +124,12 @@ _dbus_become_daemon (const DBusString *pidfile,
_dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
}
- /* Get a predictable umask */
- _dbus_verbose ("setting umask\n");
- umask (022);
+ if (!keep_umask)
+ {
+ /* Get a predictable umask */
+ _dbus_verbose ("setting umask\n");
+ umask (022);
+ }
_dbus_verbose ("calling setsid()\n");
if (setsid () == -1)
diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c
index 8608ad0e..6358531b 100644
--- a/dbus/dbus-sysdeps-util-win.c
+++ b/dbus/dbus-sysdeps-util-win.c
@@ -70,12 +70,14 @@ errno_t strcpy_s(char *dest, size_t size, char *src)
* @param pidfile #NULL, or pidfile to create
* @param print_pid_fd file descriptor to print daemon's pid to, or -1 for none
* @param error return location for errors
+ * @param keep_umask #TRUE to keep the original umask
* @returns #FALSE on failure
*/
dbus_bool_t
_dbus_become_daemon (const DBusString *pidfile,
DBusPipe *print_pid_pipe,
- DBusError *error)
+ DBusError *error,
+ dbus_bool_t keep_umask)
{
return TRUE;
}
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index 2662b270..b766f3f9 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -400,7 +400,8 @@ void _dbus_print_backtrace (void);
dbus_bool_t _dbus_become_daemon (const DBusString *pidfile,
DBusPipe *print_pid_pipe,
- DBusError *error);
+ DBusError *error,
+ dbus_bool_t keep_umask);
dbus_bool_t _dbus_verify_daemon_user (const char *user);
dbus_bool_t _dbus_change_to_daemon_user (const char *user,
diff --git a/doc/busconfig.dtd b/doc/busconfig.dtd
index 84593fe0..0cc519b4 100644
--- a/doc/busconfig.dtd
+++ b/doc/busconfig.dtd
@@ -1,6 +1,7 @@
<!ELEMENT busconfig (user |
type |
fork |
+ keep_umask |
listen |
pidfile |
includedir |
@@ -21,6 +22,7 @@
<!ELEMENT type (#PCDATA)>
<!ELEMENT pidfile (#PCDATA)>
<!ELEMENT fork EMPTY>
+<!ELEMENT keep_umask EMPTY>
<!ELEMENT include (#PCDATA)>
<!ATTLIST include