~ubuntu-branches/ubuntu/maverick/dbus/maverick-proposed

« back to all changes in this revision

Viewing changes to bus/selinux.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:
22
22
 */
23
23
#include <dbus/dbus-internals.h>
24
24
#include <dbus/dbus-string.h>
 
25
#include <dbus/dbus-userdb.h>
25
26
#include "selinux.h"
26
27
#include "services.h"
27
28
#include "policy.h"
28
29
#include "utils.h"
29
30
#include "config-parser.h"
30
31
 
 
32
#ifdef HAVE_ERRNO_H
 
33
#include <errno.h>
 
34
#endif
31
35
#ifdef HAVE_SELINUX
32
36
#include <sys/types.h>
33
37
#include <unistd.h>
34
 
#ifdef HAVE_ERRNO_H
35
 
#include <errno.h>
36
 
#endif
37
38
#include <limits.h>
38
39
#include <pthread.h>
39
40
#include <syslog.h>
44
45
#include <signal.h>
45
46
#include <stdarg.h>
46
47
#include <stdio.h>
 
48
#include <grp.h>
 
49
#endif /* HAVE_SELINUX */
47
50
#ifdef HAVE_LIBAUDIT
 
51
#include <cap-ng.h>
48
52
#include <libaudit.h>
49
53
#endif /* HAVE_LIBAUDIT */
50
 
#endif /* HAVE_SELINUX */
51
54
 
52
55
#define BUS_SID_FROM_SELINUX(sid)  ((BusSELinuxID*) (sid))
53
56
#define SELINUX_SID_FROM_BUS(sid)  ((security_id_t) (sid))
143
146
#ifdef HAVE_LIBAUDIT
144
147
  if (audit_fd >= 0)
145
148
  {
146
 
    char buf[PATH_MAX*2];
 
149
    capng_get_caps_process();
 
150
    if (capng_have_capability(CAPNG_EFFECTIVE, CAP_AUDIT_WRITE))
 
151
    {
 
152
      char buf[PATH_MAX*2];
147
153
    
148
 
    /* FIXME: need to change this to show real user */
149
 
    vsnprintf(buf, sizeof(buf), fmt, ap);
150
 
    audit_log_user_avc_message(audit_fd, AUDIT_USER_AVC, buf, NULL, NULL,
 
154
      /* FIXME: need to change this to show real user */
 
155
      vsnprintf(buf, sizeof(buf), fmt, ap);
 
156
      audit_log_user_avc_message(audit_fd, AUDIT_USER_AVC, buf, NULL, NULL,
151
157
                               NULL, getuid());
152
 
    return;
 
158
      return;
 
159
    }
153
160
  }
154
161
#endif /* HAVE_LIBAUDIT */
155
162
  
1010
1017
#endif /* HAVE_SELINUX */
1011
1018
}
1012
1019
 
 
1020
/* The !HAVE_LIBAUDIT case lives in dbus-sysdeps-util-unix.c */
 
1021
#ifdef HAVE_LIBAUDIT
 
1022
/**
 
1023
 * Changes the user and group the bus is running as.
 
1024
 *
 
1025
 * @param user the user to become
 
1026
 * @param error return location for errors
 
1027
 * @returns #FALSE on failure
 
1028
 */
 
1029
dbus_bool_t
 
1030
_dbus_change_to_daemon_user  (const char    *user,
 
1031
                              DBusError     *error)
 
1032
{
 
1033
  dbus_uid_t uid;
 
1034
  dbus_gid_t gid;
 
1035
  DBusString u;
 
1036
 
 
1037
  _dbus_string_init_const (&u, user);
 
1038
 
 
1039
  if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
 
1040
    {
 
1041
      dbus_set_error (error, DBUS_ERROR_FAILED,
 
1042
                      "User '%s' does not appear to exist?",
 
1043
                      user);
 
1044
      return FALSE;
 
1045
    }
 
1046
 
 
1047
  /* If we were root */
 
1048
  if (_dbus_geteuid () == 0)
 
1049
    {
 
1050
      int rc;
 
1051
 
 
1052
      capng_clear (CAPNG_SELECT_BOTH);
 
1053
      capng_update (CAPNG_ADD, CAPNG_EFFECTIVE | CAPNG_PERMITTED,
 
1054
                    CAP_AUDIT_WRITE);
 
1055
      rc = capng_change_id (uid, gid, 0);
 
1056
      if (rc)
 
1057
        {
 
1058
          switch (rc) {
 
1059
            default:
 
1060
              dbus_set_error (error, DBUS_ERROR_FAILED,
 
1061
                              "Failed to drop capabilities: %s\n",
 
1062
                              _dbus_strerror (errno));
 
1063
              break;
 
1064
            case -4:
 
1065
              dbus_set_error (error, _dbus_error_from_errno (errno),
 
1066
                              "Failed to set GID to %lu: %s", gid,
 
1067
                              _dbus_strerror (errno));
 
1068
              break;
 
1069
            case -5:
 
1070
              _dbus_warn ("Failed to drop supplementary groups: %s\n",
 
1071
                          _dbus_strerror (errno));
 
1072
              break;
 
1073
            case -6:
 
1074
              dbus_set_error (error, _dbus_error_from_errno (errno),
 
1075
                              "Failed to set UID to %lu: %s", uid,
 
1076
                              _dbus_strerror (errno));
 
1077
              break;
 
1078
            case -7:
 
1079
              dbus_set_error (error, _dbus_error_from_errno (errno),
 
1080
                              "Failed to unset keep-capabilities: %s\n",
 
1081
                              _dbus_strerror (errno));
 
1082
              break;
 
1083
          }
 
1084
          return FALSE;
 
1085
        }
 
1086
    }
 
1087
 
 
1088
 return TRUE;
 
1089
}
 
1090
#endif
 
1091