~ubuntu-branches/ubuntu/natty/dbus/natty-201012211412

« back to all changes in this revision

Viewing changes to bus/bus.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-08-09 16:09:57 UTC
  • mfrom: (1.3.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100809160957-3xh1a1tnhxebs159
Tags: 1.2.24-3ubuntu1
* Resync on Debian
* Remaining Ubuntu Changes:
  - Install into / rather than /usr.
  - debian/control: Depend on ConsoleKit for "at_console" policy stanza.
  - debian/dbus.postinst: Do not restart dbus on upgrades, since it breaks
    too many applications. Instead, trigger a "reboot required" notification.
  - debian/dbus.postinst: Create /var/run/dbus in postinst to handle system
    being rebooted before package is configured.  LP: #275229.
  - Add debian/dbus.upstart and bump debhelper b-dep to ensure that it is
    properly installed.
  - 20_system_conf_limit.patch: Increase max_match_rules_per_connection for
    the system bus to 5000 (LP #454093)
  - 81-session.conf-timeout.patch: Raise the service startup timeout from 25
    to 60 seconds. It may be too short on the live CD with slow machines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "dir-watch.h"
34
34
#include <dbus/dbus-list.h>
35
35
#include <dbus/dbus-hash.h>
 
36
#include <dbus/dbus-credentials.h>
36
37
#include <dbus/dbus-internals.h>
37
38
 
38
39
struct BusContext
45
46
  char *address;
46
47
  char *pidfile;
47
48
  char *user;
 
49
  char *log_prefix;
48
50
  DBusLoop *loop;
49
51
  DBusList *servers;
50
52
  BusConnections *connections;
264
266
                                BusConfigParser *parser,
265
267
                                DBusError       *error)
266
268
{
 
269
  DBusString log_prefix;
267
270
  DBusList *link;
268
271
  DBusList **addresses;
269
272
  const char *user, *pidfile;
289
292
      DBusStat stbuf;
290
293
      
291
294
      _dbus_string_init_const (&u, pidfile);
292
 
      
 
295
 
293
296
      if (_dbus_stat (&u, &stbuf, NULL))
294
 
        {
295
 
          dbus_set_error (error, DBUS_ERROR_FAILED,
296
 
                          "The pid file \"%s\" exists, if the message bus is not running, remove this file",
297
 
                          pidfile);
298
 
          goto failed;
299
 
        }
 
297
        {
 
298
          dbus_set_error (error, DBUS_ERROR_FAILED,
 
299
                                  "The pid file \"%s\" exists, if the message bus is not running, remove this file",
 
300
                          pidfile);
 
301
              goto failed;
 
302
        }
300
303
    }
301
 
  
 
304
 
302
305
  /* keep around the pid filename so we can delete it later */
303
306
  context->pidfile = _dbus_strdup (pidfile);
304
307
 
 
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)
 
311
    goto oom;
 
312
 
 
313
  user = bus_config_parser_get_user (parser);
 
314
  if (user != NULL)
 
315
    {
 
316
      context->user = _dbus_strdup (user);
 
317
      if (context->user == NULL)
 
318
        goto oom;
 
319
    }
 
320
 
 
321
  /* Set up the prefix for syslog messages */
 
322
  if (!_dbus_string_init (&log_prefix))
 
323
    goto oom;
 
324
  if (context->type && !strcmp (context->type, "system"))
 
325
    {
 
326
      if (!_dbus_string_append (&log_prefix, "[system] "))
 
327
        goto oom;
 
328
    }
 
329
  else if (context->type && !strcmp (context->type, "session"))
 
330
    {
 
331
      DBusCredentials *credentials;
 
332
 
 
333
      credentials = _dbus_credentials_new_from_current_process ();
 
334
      if (!credentials)
 
335
        goto oom;
 
336
      if (!_dbus_string_append (&log_prefix, "[session "))
 
337
        goto oom;
 
338
      if (!_dbus_credentials_to_string_append (credentials, &log_prefix))
 
339
        goto oom;
 
340
      if (!_dbus_string_append (&log_prefix, "] "))
 
341
        goto oom;
 
342
      _dbus_credentials_unref (credentials);
 
343
    }
 
344
  if (!_dbus_string_steal_data (&log_prefix, &context->log_prefix))
 
345
    goto oom;
 
346
  _dbus_string_free (&log_prefix);
 
347
 
305
348
  /* Build an array of auth mechanisms */
306
 
  
 
349
 
307
350
  auth_mechanisms_list = bus_config_parser_get_mechanisms (parser);
308
351
  len = _dbus_list_get_length (auth_mechanisms_list);
309
352
 
313
356
 
314
357
      auth_mechanisms = dbus_new0 (char*, len + 1);
315
358
      if (auth_mechanisms == NULL)
316
 
        {
317
 
          BUS_SET_OOM (error);
318
 
          goto failed;
319
 
        }
320
 
      
 
359
        goto oom;
 
360
 
321
361
      i = 0;
322
362
      link = _dbus_list_get_first_link (auth_mechanisms_list);
323
363
      while (link != NULL)
324
364
        {
325
365
          auth_mechanisms[i] = _dbus_strdup (link->data);
326
366
          if (auth_mechanisms[i] == NULL)
327
 
            {
328
 
              BUS_SET_OOM (error);
329
 
              goto failed;
330
 
            }
 
367
            goto oom;
331
368
          link = _dbus_list_get_next_link (auth_mechanisms_list, link);
332
369
        }
333
370
    }
358
395
        }
359
396
 
360
397
      if (!_dbus_list_append (&context->servers, server))
361
 
        {
362
 
          BUS_SET_OOM (error);
363
 
          goto failed;
364
 
        }          
365
 
      
 
398
        goto oom;
 
399
 
366
400
      link = _dbus_list_get_next_link (addresses, link);
367
401
    }
368
402
 
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)
372
 
    {
373
 
      BUS_SET_OOM (error);
374
 
      goto failed;
375
 
    }
376
 
 
377
 
  user = bus_config_parser_get_user (parser);
378
 
  if (user != NULL)
379
 
    {
380
 
      context->user = _dbus_strdup (user);
381
 
      if (context->user == NULL)
382
 
        {
383
 
          BUS_SET_OOM (error);
384
 
          goto failed;
385
 
        }
386
 
    }
387
 
 
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);
391
 
  
 
406
 
392
407
  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
393
408
  retval = TRUE;
394
409
 
395
410
 failed:
396
411
  dbus_free_string_array (auth_mechanisms);
397
412
  return retval;
 
413
 
 
414
 oom:
 
415
  BUS_SET_OOM (error);
 
416
  dbus_free_string_array (auth_mechanisms);
 
417
  return FALSE;
398
418
}
399
419
 
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);
435
455
 
 
456
  if (context->policy)
 
457
    bus_policy_unref (context->policy);
436
458
  context->policy = bus_config_parser_steal_policy (parser);
437
459
  _dbus_assert (context->policy != NULL);
438
460
 
496
518
      dbus_free(context->servicehelper);
497
519
      context->servicehelper = s;
498
520
    }
499
 
  
 
521
 
500
522
  /* Create activation subsystem */
501
 
  new_activation = bus_activation_new (context, &full_address,
502
 
                                       dirs, error);
503
 
  if (new_activation == NULL)
 
523
  if (context->activation)
 
524
    {
 
525
      if (!bus_activation_reload (context->activation, &full_address, dirs, error))
 
526
        goto failed;
 
527
    }
 
528
  else
 
529
    {
 
530
      context->activation = bus_activation_new (context, &full_address, dirs, error);
 
531
    }
 
532
 
 
533
  if (context->activation == NULL)
504
534
    {
505
535
      _DBUS_ASSERT_ERROR_IS_SET (error);
506
536
      goto failed;
507
537
    }
508
538
 
509
 
  if (is_reload)
510
 
    bus_activation_unref (context->activation);
511
 
 
512
 
  context->activation = new_activation;
513
 
 
514
 
  /* Drop existing conf-dir watches (if applicable) */
515
 
 
516
 
  if (is_reload)
517
 
    bus_drop_all_directory_watches ();
518
 
 
519
539
  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
520
540
  retval = TRUE;
521
541
 
529
549
}
530
550
 
531
551
static dbus_bool_t
 
552
list_concat_new (DBusList **a,
 
553
                 DBusList **b,
 
554
                 DBusList **result)
 
555
{
 
556
  DBusList *link;
 
557
 
 
558
  *result = NULL;
 
559
 
 
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))
 
562
    {
 
563
      if (!_dbus_list_append (result, link->data))
 
564
        goto oom;
 
565
    }
 
566
  for (link = _dbus_list_get_first_link (b); link; link = _dbus_list_get_next_link (b, link))
 
567
    {
 
568
      if (!_dbus_list_append (result, link->data))
 
569
        goto oom;
 
570
    }
 
571
 
 
572
  return TRUE;
 
573
oom:
 
574
  _dbus_list_clear (result);
 
575
  return FALSE;
 
576
}
 
577
 
 
578
static dbus_bool_t
532
579
process_config_postinit (BusContext      *context,
533
580
                         BusConfigParser *parser,
534
581
                         DBusError       *error)
535
582
{
536
583
  DBusHashTable *service_context_table;
 
584
  DBusList *watched_dirs = NULL;
537
585
 
538
586
  service_context_table = bus_config_parser_steal_service_context_table (parser);
539
587
  if (!bus_registry_set_service_context_table (context->registry,
545
593
 
546
594
  _dbus_hash_table_unref (service_context_table);
547
595
 
548
 
  /* Watch all conf directories */
549
 
  _dbus_list_foreach (bus_config_parser_get_conf_dirs (parser),
550
 
                      (DBusForeachFunction) bus_watch_directory,
551
 
                      context);
 
596
  /* We need to monitor both the configuration directories and directories
 
597
   * containing .service files.
 
598
   */
 
599
  if (!list_concat_new (bus_config_parser_get_conf_dirs (parser),
 
600
                        bus_config_parser_get_service_dirs (parser),
 
601
                        &watched_dirs))
 
602
    {
 
603
      BUS_SET_OOM (error);
 
604
      return FALSE;
 
605
    }
 
606
 
 
607
  bus_set_watched_dirs (context, &watched_dirs);
 
608
 
 
609
  _dbus_list_clear (&watched_dirs);
552
610
 
553
611
  return TRUE;
554
612
}
560
618
                 DBusPipe         *print_pid_pipe,
561
619
                 DBusError        *error)
562
620
{
 
621
  DBusString log_prefix;
563
622
  BusContext *context;
564
623
  BusConfigParser *parser;
565
624
 
583
642
  context->refcount = 1;
584
643
 
585
644
  _dbus_generate_uuid (&context->uuid);
586
 
  
 
645
 
587
646
  if (!_dbus_string_copy_data (config_file, &context->config_file))
588
647
    {
589
648
      BUS_SET_OOM (error);
744
803
 
745
804
  if (!bus_selinux_full_init ())
746
805
    {
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");
748
807
    }
749
 
  
 
808
 
750
809
  if (!process_config_postinit (context, parser, error))
751
810
    {
752
811
      _DBUS_ASSERT_ERROR_IS_SET (error);
831
890
    }
832
891
  ret = TRUE;
833
892
 
834
 
  bus_context_log_info (context, "Reloaded configuration");
835
 
 failed:  
 
893
  bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Reloaded configuration");
 
894
 failed:
836
895
  if (!ret)
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);
840
899
  return ret;
944
1003
          bus_matchmaker_unref (context->matchmaker);
945
1004
          context->matchmaker = NULL;
946
1005
        }
947
 
      
 
1006
 
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);
1116
1176
}
1117
1177
 
1118
1178
void
1119
 
bus_context_log_info (BusContext *context, const char *msg, ...)
1120
 
{
1121
 
  va_list args;
1122
 
 
1123
 
  va_start (args, msg);
1124
 
  
1125
 
  if (context->syslog)
1126
 
    _dbus_log_info (msg, args);
1127
 
 
1128
 
  va_end (args);
1129
 
}
 
1179
bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (3, 4);
1130
1180
 
1131
1181
void
1132
 
bus_context_log_security (BusContext *context, const char *msg, ...)
 
1182
bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...)
1133
1183
{
1134
1184
  va_list args;
1135
1185
 
 
1186
  if (!context->syslog)
 
1187
    return;
 
1188
 
1136
1189
  va_start (args, msg);
1137
 
  
1138
 
  if (context->syslog)
1139
 
    _dbus_log_security (msg, args);
1140
 
 
 
1190
 
 
1191
  if (context->log_prefix)
 
1192
    {
 
1193
      DBusString full_msg;
 
1194
 
 
1195
      if (!_dbus_string_init (&full_msg))
 
1196
        goto out;
 
1197
      if (!_dbus_string_append (&full_msg, context->log_prefix))
 
1198
        goto oom_out;
 
1199
      if (!_dbus_string_append_printf_valist (&full_msg, msg, args))
 
1200
        goto oom_out;
 
1201
 
 
1202
      _dbus_system_log (severity, "%s", _dbus_string_get_const_data (&full_msg));
 
1203
    oom_out:
 
1204
      _dbus_string_free (&full_msg);
 
1205
    }
 
1206
  else
 
1207
    _dbus_system_logv (severity, msg, args);
 
1208
 
 
1209
out:
1141
1210
  va_end (args);
1142
1211
}
1143
1212
 
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,
1385
1454
                                  toggles,
1386
1455
                                  dbus_message_type_to_string (dbus_message_get_type (message)),
1387
1456
                                  sender_name ? sender_name : "(unset)",
1400
1469
    }
1401
1470
 
1402
1471
  if (log)
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))",
1406
1475
                              toggles,
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,
1449
1518
                                  toggles,
1450
1519
                                  dbus_message_type_to_string (dbus_message_get_type (message)),
1451
1520
                                  sender_name ? sender_name : "(unset)",