~ubuntu-branches/ubuntu/maverick/dbus/maverick-security

« back to all changes in this revision

Viewing changes to dbus/dbus-server-unix.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-27 13:06:32 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20100927130632-bqs145trvchd2lmf
Tags: 1.4.0-0ubuntu1
* New upstream release
 - Fixes https://bugs.freedesktop.org/show_bug.cgi?id=17754 Race condition in protected_change_timeout
 - Requested by various upstream KDE developers http://lists.kde.org/?t=128514970000004&r=1&w=2

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright (C) 2002, 2003, 2004  Red Hat Inc.
5
5
 *
6
6
 * Licensed under the Academic Free License version 2.1
7
 
 * 
 
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
10
10
 * the Free Software Foundation; either version 2 of the License, or
14
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
16
 * GNU General Public License for more details.
17
 
 * 
 
17
 *
18
18
 * You should have received a copy of the GNU General Public License
19
19
 * along with this program; if not, write to the Free Software
20
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
21
 *
22
22
 */
23
23
 
 
24
#include <config.h>
24
25
#include "dbus-internals.h"
25
26
#include "dbus-server-unix.h"
26
27
#include "dbus-server-socket.h"
41
42
 * Tries to interpret the address entry in a platform-specific
42
43
 * way, creating a platform-specific server type if appropriate.
43
44
 * Sets error if the result is not OK.
44
 
 * 
 
45
 *
45
46
 * @param entry an address entry
46
47
 * @param server_p location to store a new DBusServer, or #NULL on failure.
47
48
 * @param error location to store rationale for failure on bad address
48
49
 * @returns the outcome
49
 
 * 
 
50
 *
50
51
 */
51
52
DBusServerListenResult
52
53
_dbus_server_listen_platform_specific (DBusAddressEntry *entry,
56
57
  const char *method;
57
58
 
58
59
  *server_p = NULL;
59
 
  
 
60
 
60
61
  method = dbus_address_entry_get_method (entry);
61
62
 
62
63
  if (strcmp (method, "unix") == 0)
64
65
      const char *path = dbus_address_entry_get_value (entry, "path");
65
66
      const char *tmpdir = dbus_address_entry_get_value (entry, "tmpdir");
66
67
      const char *abstract = dbus_address_entry_get_value (entry, "abstract");
67
 
          
 
68
 
68
69
      if (path == NULL && tmpdir == NULL && abstract == NULL)
69
70
        {
70
71
          _dbus_set_bad_address(error, "unix",
86
87
        {
87
88
          DBusString full_path;
88
89
          DBusString filename;
89
 
              
 
90
 
90
91
          if (!_dbus_string_init (&full_path))
91
92
            {
92
93
              dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
93
94
              return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
94
95
            }
95
 
                  
 
96
 
96
97
          if (!_dbus_string_init (&filename))
97
98
            {
98
99
              _dbus_string_free (&full_path);
99
100
              dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
100
101
              return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
101
102
            }
102
 
              
 
103
 
103
104
          if (!_dbus_string_append (&filename,
104
105
                                    "dbus-") ||
105
106
              !_dbus_generate_random_ascii (&filename, 10) ||
111
112
              dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
112
113
              return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
113
114
            }
114
 
              
 
115
 
115
116
          /* Always use abstract namespace if possible with tmpdir */
116
 
              
 
117
 
117
118
          *server_p =
118
119
            _dbus_server_new_for_domain_socket (_dbus_string_get_const_data (&full_path),
119
120
#ifdef HAVE_ABSTRACT_SOCKETS
145
146
          return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
146
147
        }
147
148
    }
 
149
  else if (strcmp (method, "systemd") == 0)
 
150
    {
 
151
      int n, *fds;
 
152
      DBusString address;
 
153
 
 
154
      n = _dbus_listen_systemd_sockets (&fds, error);
 
155
      if (n < 0)
 
156
        {
 
157
          _DBUS_ASSERT_ERROR_IS_SET (error);
 
158
          return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
 
159
        }
 
160
 
 
161
      _dbus_string_init_const (&address, "systemd:");
 
162
 
 
163
      *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL);
 
164
      if (*server_p == NULL)
 
165
        {
 
166
          int i;
 
167
 
 
168
          for (i = 0; i < n; i++)
 
169
            {
 
170
              _dbus_close_socket (fds[i], NULL);
 
171
            }
 
172
          dbus_free (fds);
 
173
 
 
174
          dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
 
175
          return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
 
176
        }
 
177
 
 
178
      dbus_free (fds);
 
179
 
 
180
      return DBUS_SERVER_LISTEN_OK;
 
181
    }
148
182
  else
149
183
    {
150
184
      /* If we don't handle the method, we return NULL with the
173
207
  DBusString address;
174
208
  char *path_copy;
175
209
  DBusString path_str;
176
 
  
 
210
 
177
211
  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
178
212
 
179
213
  if (!_dbus_string_init (&address))
199
233
      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
200
234
      goto failed_0;
201
235
    }
202
 
  
 
236
 
203
237
  listen_fd = _dbus_listen_unix_socket (path, abstract, error);
204
 
  _dbus_fd_set_close_on_exec (listen_fd);
205
 
  
 
238
 
206
239
  if (listen_fd < 0)
207
240
    {
208
241
      _DBUS_ASSERT_ERROR_IS_SET (error);
209
242
      goto failed_1;
210
243
    }
211
 
  
212
 
  server = _dbus_server_new_for_socket (&listen_fd, 1, &address);
 
244
 
 
245
  server = _dbus_server_new_for_socket (&listen_fd, 1, &address, 0);
213
246
  if (server == NULL)
214
247
    {
215
248
      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
217
250
    }
218
251
 
219
252
  _dbus_server_socket_own_filename(server, path_copy);
220
 
  
 
253
 
221
254
  _dbus_string_free (&address);
222
 
  
 
255
 
223
256
  return server;
224
257
 
225
258
 failed_2:
233
266
}
234
267
 
235
268
/** @} */
236