291
294
_dbus_string_init_const (&u, pidfile);
293
296
if (_dbus_stat (&u, &stbuf, NULL))
295
dbus_set_error (error, DBUS_ERROR_FAILED,
296
"The pid file \"%s\" exists, if the message bus is not running, remove this file",
298
dbus_set_error (error, DBUS_ERROR_FAILED,
299
"The pid file \"%s\" exists, if the message bus is not running, remove this file",
302
305
/* keep around the pid filename so we can delete it later */
303
306
context->pidfile = _dbus_strdup (pidfile);
308
/* note that type may be NULL */
309
context->type = _dbus_strdup (bus_config_parser_get_type (parser));
310
if (bus_config_parser_get_type (parser) != NULL && context->type == NULL)
313
user = bus_config_parser_get_user (parser);
316
context->user = _dbus_strdup (user);
317
if (context->user == NULL)
321
/* Set up the prefix for syslog messages */
322
if (!_dbus_string_init (&log_prefix))
324
if (context->type && !strcmp (context->type, "system"))
326
if (!_dbus_string_append (&log_prefix, "[system] "))
329
else if (context->type && !strcmp (context->type, "session"))
331
DBusCredentials *credentials;
333
credentials = _dbus_credentials_new_from_current_process ();
336
if (!_dbus_string_append (&log_prefix, "[session "))
338
if (!_dbus_credentials_to_string_append (credentials, &log_prefix))
340
if (!_dbus_string_append (&log_prefix, "] "))
342
_dbus_credentials_unref (credentials);
344
if (!_dbus_string_steal_data (&log_prefix, &context->log_prefix))
346
_dbus_string_free (&log_prefix);
305
348
/* Build an array of auth mechanisms */
307
350
auth_mechanisms_list = bus_config_parser_get_mechanisms (parser);
308
351
len = _dbus_list_get_length (auth_mechanisms_list);
314
357
auth_mechanisms = dbus_new0 (char*, len + 1);
315
358
if (auth_mechanisms == NULL)
322
362
link = _dbus_list_get_first_link (auth_mechanisms_list);
323
363
while (link != NULL)
325
365
auth_mechanisms[i] = _dbus_strdup (link->data);
326
366
if (auth_mechanisms[i] == NULL)
331
368
link = _dbus_list_get_next_link (auth_mechanisms_list, link);
360
397
if (!_dbus_list_append (&context->servers, server))
366
400
link = _dbus_list_get_next_link (addresses, link);
369
/* note that type may be NULL */
370
context->type = _dbus_strdup (bus_config_parser_get_type (parser));
371
if (bus_config_parser_get_type (parser) != NULL && context->type == NULL)
377
user = bus_config_parser_get_user (parser);
380
context->user = _dbus_strdup (user);
381
if (context->user == NULL)
388
403
context->fork = bus_config_parser_get_fork (parser);
389
404
context->syslog = bus_config_parser_get_syslog (parser);
390
405
context->keep_umask = bus_config_parser_get_keep_umask (parser);
392
407
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
396
411
dbus_free_string_array (auth_mechanisms);
416
dbus_free_string_array (auth_mechanisms);
400
420
/* This code gets executed every time the config files
433
453
/* get our limits and timeout lengths */
434
454
bus_config_parser_get_limits (parser, &context->limits);
457
bus_policy_unref (context->policy);
436
458
context->policy = bus_config_parser_steal_policy (parser);
437
459
_dbus_assert (context->policy != NULL);
496
518
dbus_free(context->servicehelper);
497
519
context->servicehelper = s;
500
522
/* Create activation subsystem */
501
new_activation = bus_activation_new (context, &full_address,
503
if (new_activation == NULL)
523
if (context->activation)
525
if (!bus_activation_reload (context->activation, &full_address, dirs, error))
530
context->activation = bus_activation_new (context, &full_address, dirs, error);
533
if (context->activation == NULL)
505
535
_DBUS_ASSERT_ERROR_IS_SET (error);
510
bus_activation_unref (context->activation);
512
context->activation = new_activation;
514
/* Drop existing conf-dir watches (if applicable) */
517
bus_drop_all_directory_watches ();
519
539
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
531
551
static dbus_bool_t
552
list_concat_new (DBusList **a,
560
link = _dbus_list_get_first_link (a);
561
for (link = _dbus_list_get_first_link (a); link; link = _dbus_list_get_next_link (a, link))
563
if (!_dbus_list_append (result, link->data))
566
for (link = _dbus_list_get_first_link (b); link; link = _dbus_list_get_next_link (b, link))
568
if (!_dbus_list_append (result, link->data))
574
_dbus_list_clear (result);
532
579
process_config_postinit (BusContext *context,
533
580
BusConfigParser *parser,
534
581
DBusError *error)
536
583
DBusHashTable *service_context_table;
584
DBusList *watched_dirs = NULL;
538
586
service_context_table = bus_config_parser_steal_service_context_table (parser);
539
587
if (!bus_registry_set_service_context_table (context->registry,
546
594
_dbus_hash_table_unref (service_context_table);
548
/* Watch all conf directories */
549
_dbus_list_foreach (bus_config_parser_get_conf_dirs (parser),
550
(DBusForeachFunction) bus_watch_directory,
596
/* We need to monitor both the configuration directories and directories
597
* containing .service files.
599
if (!list_concat_new (bus_config_parser_get_conf_dirs (parser),
600
bus_config_parser_get_service_dirs (parser),
607
bus_set_watched_dirs (context, &watched_dirs);
609
_dbus_list_clear (&watched_dirs);
745
804
if (!bus_selinux_full_init ())
747
_dbus_warn ("SELinux initialization failed\n");
806
bus_context_log (context, DBUS_SYSTEM_LOG_FATAL, "SELinux enabled but AVC initialization failed; check system log\n");
750
809
if (!process_config_postinit (context, parser, error))
752
811
_DBUS_ASSERT_ERROR_IS_SET (error);
834
bus_context_log_info (context, "Reloaded configuration");
893
bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Reloaded configuration");
837
bus_context_log_info (context, "Unable to reload configuration: %s", error->message);
896
bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Unable to reload configuration: %s", error->message);
838
897
if (parser != NULL)
839
898
bus_config_parser_unref (parser);
944
1003
bus_matchmaker_unref (context->matchmaker);
945
1004
context->matchmaker = NULL;
948
1007
dbus_free (context->config_file);
1008
dbus_free (context->log_prefix);
949
1009
dbus_free (context->type);
950
1010
dbus_free (context->address);
951
1011
dbus_free (context->user);
1119
bus_context_log_info (BusContext *context, const char *msg, ...)
1123
va_start (args, msg);
1125
if (context->syslog)
1126
_dbus_log_info (msg, args);
1179
bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (3, 4);
1132
bus_context_log_security (BusContext *context, const char *msg, ...)
1182
bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...)
1186
if (!context->syslog)
1136
1189
va_start (args, msg);
1138
if (context->syslog)
1139
_dbus_log_security (msg, args);
1191
if (context->log_prefix)
1193
DBusString full_msg;
1195
if (!_dbus_string_init (&full_msg))
1197
if (!_dbus_string_append (&full_msg, context->log_prefix))
1199
if (!_dbus_string_append_printf_valist (&full_msg, msg, args))
1202
_dbus_system_log (severity, "%s", _dbus_string_get_const_data (&full_msg));
1204
_dbus_string_free (&full_msg);
1207
_dbus_system_logv (severity, msg, args);
1380
1449
dest ? dest : DBUS_SERVICE_DBUS,
1381
1450
proposed_recipient_loginfo);
1382
1451
/* Needs to be duplicated to avoid calling malloc and having to handle OOM */
1383
if (addressed_recipient == proposed_recipient)
1384
bus_context_log_security (context, msg,
1452
if (addressed_recipient == proposed_recipient)
1453
bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, msg,
1386
1455
dbus_message_type_to_string (dbus_message_get_type (message)),
1387
1456
sender_name ? sender_name : "(unset)",
1403
bus_context_log_security (context,
1472
bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY,
1404
1473
"Would reject message, %d matched rules; "
1405
1474
"type=\"%s\", sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" requested_reply=%d destination=\"%s\" (%s))",
1444
1513
dest ? dest : DBUS_SERVICE_DBUS,
1445
1514
proposed_recipient_loginfo);
1446
1515
/* Needs to be duplicated to avoid calling malloc and having to handle OOM */
1447
if (addressed_recipient == proposed_recipient)
1448
bus_context_log_security (context, msg,
1516
if (addressed_recipient == proposed_recipient)
1517
bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, msg,
1450
1519
dbus_message_type_to_string (dbus_message_get_type (message)),
1451
1520
sender_name ? sender_name : "(unset)",