25 #include "dbus-internals.h" 26 #include "dbus-server-unix.h" 27 #include "dbus-server-socket.h" 28 #include "dbus-server-launchd.h" 29 #include "dbus-transport-unix.h" 30 #include "dbus-connection-internal.h" 31 #include "dbus-sysdeps-unix.h" 32 #include "dbus-string.h" 35 #include <parsec/pdp.h> 37 #include <parsec/parsec_cap.h> 39 int pdplinux_capability_set_socket_from_current_process(
const char *path,
int sockfd);
40 int pdplinux_capability_set_apply_socket(parsec_cap_t
set,
int sockfd);
63 DBusServerListenResult
74 if (strcmp (method,
"unix") == 0)
81 int mutually_exclusive_modes = 0;
83 mutually_exclusive_modes = (path !=
NULL) + (tmpdir !=
NULL) +
86 if (mutually_exclusive_modes < 1)
89 "path or tmpdir or abstract or runtime or dir",
91 return DBUS_SERVER_LISTEN_BAD_ADDRESS;
94 if (mutually_exclusive_modes > 1)
97 "cannot specify two of \"path\", \"tmpdir\", \"abstract\", \"runtime\" and \"dir\" at the same time");
98 return DBUS_SERVER_LISTEN_BAD_ADDRESS;
105 const char *runtimedir;
107 if (strcmp (runtime,
"yes") != 0)
110 "if given, the only value allowed for \"runtime\" is \"yes\"");
111 return DBUS_SERVER_LISTEN_BAD_ADDRESS;
116 if (runtimedir ==
NULL)
120 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
127 _DBUS_SET_OOM (error);
128 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
135 _DBUS_SET_OOM (error);
136 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
143 _dbus_string_get_const_data (&full_path),
148 else if (tmpdir !=
NULL || dir !=
NULL)
169 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
176 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
184 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
191 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
200 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
219 if (*server_p !=
NULL)
221 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
222 return DBUS_SERVER_LISTEN_OK;
226 _DBUS_ASSERT_ERROR_IS_SET(error);
227 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
230 else if (strcmp (method,
"systemd") == 0)
239 _DBUS_ASSERT_ERROR_IS_SET (error);
240 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
246 for (i = 0; i < n; i++)
256 _dbus_verbose(
"parsec privsock: process to set Special label: fds[i] = %d (%d of %d) address=%s (NSP)\n",
257 fds[i].fd, i, n, _dbus_string_get_const_data(&address));
258 pdplinux_capability_set_socket_from_current_process(_dbus_string_get_const_data(&address),fds[i].fd);
263 if (*server_p ==
NULL)
269 return DBUS_SERVER_LISTEN_OK;
272 _DBUS_SET_OOM (error);
274 for (i = 0; i < n; i++)
281 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
283 #ifdef DBUS_ENABLE_LAUNCHD 284 else if (strcmp (method,
"launchd") == 0)
287 if (launchd_env_var ==
NULL)
290 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
294 if (*server_p !=
NULL)
296 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
297 return DBUS_SERVER_LISTEN_OK;
301 _DBUS_ASSERT_ERROR_IS_SET(error);
302 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
311 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
312 return DBUS_SERVER_LISTEN_NOT_HANDLED;
335 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
361 if (path_copy ==
NULL)
370 if (listen_fd.fd < 0)
372 _DBUS_ASSERT_ERROR_IS_SET (error);
377 _dbus_verbose(
"parsec privsock: process to set Special label: path %s, fd=%d (NSP)\n",path,listen_fd.fd);
378 pdplinux_capability_set_socket_from_current_process(path,listen_fd.fd);
388 if (path_copy !=
NULL)
408 int pdplinux_capability_set_socket_from_current_process(
const char* path,
int sockfd){
413 parsec_caps_t capsproc;
416 memset(&capsproc,0,
sizeof(capsproc));
417 r=parsec_capget(0,&capsproc);
425 r=pdplinux_capability_set_apply_socket(capsproc.cap_effective,sockfd);
427 _dbus_verbose(
"parsec privsock: parsec_capget failed with %d\n",r);
430 _dbus_verbose(
"parsec privsock: _dbus_string_find cannot find system_bus_socket in path so skip set_apply_socket\n");
432 _dbus_verbose(
"parsec privsock: pdplinux_capability_set_apply_socket returned %d\n",r);
437 int pdplinux_capability_set_apply_socket(parsec_cap_t
set,
int sockfd){
441 unsigned int caps=
set;
442 _dbus_verbose(
"parsec privsock: Capability is %x\n",caps);
446 _dbus_verbose(
"parsec privsock: Error pdp_init %m\n");
451 if (
set & PARSEC_CAP_TO_MASK(PARSEC_CAP_PRIV_SOCK)){
453 PDP_TYPE_T type = PDPT_EHOLE;
455 _dbus_verbose(
"parsec privsock: Processing 'PARSEC_CAP_PRIV_SOCK' socket...\n");
457 pdpl=pdp_get_fd(sockfd);
460 pdpl_or_type(pdpl,type);
462 if ( pdp_set_fd(sockfd,pdpl)!=0 ){
464 _dbus_verbose(
"parsec privsock: Failed pdp_set_fd: %m\n");
467 _dbus_verbose(
"parsec privsock: Parsec privsock set successful\n");
473 _dbus_verbose(
"parsec privsock: Failed pdp_get_fd: %m\n");
477 _dbus_verbose(
"parsec privsock: Parsec privsock skipped because of no PARSEC_CAP_PRIV_SOCK\n");
483 _dbus_verbose(
"parsec privsock: Error pdp_release %m\n");
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
#define NULL
A null pointer, defined appropriately for C or C++.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
DBusServer * _dbus_server_new_for_launchd(const char *launchd_env_var, DBusError *error)
Creates a new server from launchd.
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn't supported (like ENOSYS on UNIX).
Internals of DBusServer object.
dbus_bool_t _dbus_append_address_from_socket(DBusSocket fd, DBusString *address, DBusError *error)
Read the address from the socket and append it to the string.
const char * dbus_address_entry_get_method(DBusAddressEntry *entry)
Returns the method string of an address entry.
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
DBusServerListenResult _dbus_server_listen_platform_specific(DBusAddressEntry *entry, DBusServer **server_p, DBusError *error)
Tries to interpret the address entry in a platform-specific way, creating a platform-specific server ...
dbus_bool_t _dbus_close_socket(DBusSocket fd, DBusError *error)
Closes a socket.
dbus_bool_t _dbus_string_find(const DBusString *str, int start, const char *substr, int *found)
Finds the given substring in the string, returning TRUE and filling in the byte index where the subst...
DBusServer * _dbus_server_new_for_socket(DBusSocket *fds, int n_fds, const DBusString *address, DBusNonceFile *noncefile, DBusError *error)
Creates a new server listening on the given file descriptor.
const char * dbus_address_entry_get_value(DBusAddressEntry *entry, const char *key)
Returns a value from a key of an entry.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
dbus_bool_t _dbus_generate_random_ascii(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII su...
void _dbus_server_socket_own_filename(DBusServer *server, char *filename)
This is a bad hack since it's really unix domain socket specific.
int _dbus_listen_systemd_sockets(DBusSocket **fds, DBusError *error)
Acquires one or more sockets passed in from systemd.
Internals of DBusAddressEntry.
void _dbus_set_bad_address(DBusError *error, const char *address_problem_type, const char *address_problem_field, const char *address_problem_other)
Sets DBUS_ERROR_BAD_ADDRESS.
Object representing an exception.
dbus_bool_t _dbus_address_append_escaped(DBusString *escaped, const DBusString *unescaped)
Appends an escaped version of one string to another string, using the D-Bus address escaping mechanis...
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
#define TRUE
Expands to "1".
DBusServer * _dbus_server_new_for_domain_socket(const char *path, dbus_bool_t abstract, DBusError *error)
Creates a new server listening on the given Unix domain socket.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define FALSE
Expands to "0".
char * _dbus_strdup(const char *str)
Duplicates a string.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
int _dbus_listen_unix_socket(const char *path, dbus_bool_t abstract, DBusError *error)
Creates a socket and binds it to the given path, then listens on the socket.