D-Bus  1.12.20
dbus-sysdeps-util-unix.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-sysdeps-util-unix.c Would be in dbus-sysdeps-unix.c, but not used in libdbus
3  *
4  * Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
5  * Copyright (C) 2003 CodeFactory AB
6  *
7  * Licensed under the Academic Free License version 2.1
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #include <config.h>
26 #include "dbus-sysdeps.h"
27 #include "dbus-sysdeps-unix.h"
28 #include "dbus-internals.h"
29 #include "dbus-list.h"
30 #include "dbus-pipe.h"
31 #include "dbus-protocol.h"
32 #include "dbus-string.h"
33 #define DBUS_USERDB_INCLUDES_PRIVATE 1
34 #include "dbus-userdb.h"
35 #include "dbus-test.h"
36 
37 #include <sys/types.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <signal.h>
41 #include <unistd.h>
42 #include <stdio.h>
43 #include <errno.h>
44 #include <fcntl.h>
45 #include <sys/stat.h>
46 #ifdef HAVE_SYS_RESOURCE_H
47 #include <sys/resource.h>
48 #endif
49 #include <grp.h>
50 #include <sys/socket.h>
51 #include <dirent.h>
52 #include <sys/un.h>
53 
54 #ifdef HAVE_SYS_SYSLIMITS_H
55 #include <sys/syslimits.h>
56 #endif
57 
58 #ifdef HAVE_SYSTEMD
59 #include <systemd/sd-daemon.h>
60 #endif
61 
62 #ifdef HAVE_PDPLINUX
63 #include <sys/capability.h>
64 #endif
65 
66 #ifndef O_BINARY
67 #define O_BINARY 0
68 #endif
69 
87  DBusPipe *print_pid_pipe,
88  DBusError *error,
89  dbus_bool_t keep_umask)
90 {
91  const char *s;
92  pid_t child_pid;
93  DBusEnsureStandardFdsFlags flags;
94 
95  _dbus_verbose ("Becoming a daemon...\n");
96 
97  _dbus_verbose ("chdir to /\n");
98  if (chdir ("/") < 0)
99  {
101  "Could not chdir() to root directory");
102  return FALSE;
103  }
104 
105  _dbus_verbose ("forking...\n");
106  switch ((child_pid = fork ()))
107  {
108  case -1:
109  _dbus_verbose ("fork failed\n");
110  dbus_set_error (error, _dbus_error_from_errno (errno),
111  "Failed to fork daemon: %s", _dbus_strerror (errno));
112  return FALSE;
113  break;
114 
115  case 0:
116  _dbus_verbose ("in child, closing std file descriptors\n");
117 
118  flags = DBUS_FORCE_STDIN_NULL | DBUS_FORCE_STDOUT_NULL;
119  s = _dbus_getenv ("DBUS_DEBUG_OUTPUT");
120 
121  if (s == NULL || *s == '\0')
122  flags |= DBUS_FORCE_STDERR_NULL;
123  else
124  _dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
125 
126  if (!_dbus_ensure_standard_fds (flags, &s))
127  {
128  _dbus_warn ("%s: %s", s, _dbus_strerror (errno));
129  _exit (1);
130  }
131 
132  if (!keep_umask)
133  {
134  /* Get a predictable umask */
135  _dbus_verbose ("setting umask\n");
136  umask (022);
137  }
138 
139  _dbus_verbose ("calling setsid()\n");
140  if (setsid () == -1)
141  _dbus_assert_not_reached ("setsid() failed");
142 
143  break;
144 
145  default:
146  if (!_dbus_write_pid_to_file_and_pipe (pidfile, print_pid_pipe,
147  child_pid, error))
148  {
149  _dbus_verbose ("pid file or pipe write failed: %s\n",
150  error->message);
151  kill (child_pid, SIGTERM);
152  return FALSE;
153  }
154 
155  _dbus_verbose ("parent exiting\n");
156  _exit (0);
157  break;
158  }
159 
160  return TRUE;
161 }
162 
163 
172 static dbus_bool_t
173 _dbus_write_pid_file (const DBusString *filename,
174  unsigned long pid,
175  DBusError *error)
176 {
177  const char *cfilename;
178  int fd;
179  FILE *f;
180 
181  cfilename = _dbus_string_get_const_data (filename);
182 
183  fd = open (cfilename, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644);
184 
185  if (fd < 0)
186  {
187  dbus_set_error (error, _dbus_error_from_errno (errno),
188  "Failed to open \"%s\": %s", cfilename,
189  _dbus_strerror (errno));
190  return FALSE;
191  }
192 
193  if ((f = fdopen (fd, "w")) == NULL)
194  {
195  dbus_set_error (error, _dbus_error_from_errno (errno),
196  "Failed to fdopen fd %d: %s", fd, _dbus_strerror (errno));
197  _dbus_close (fd, NULL);
198  return FALSE;
199  }
200 
201  if (fprintf (f, "%lu\n", pid) < 0)
202  {
203  dbus_set_error (error, _dbus_error_from_errno (errno),
204  "Failed to write to \"%s\": %s", cfilename,
205  _dbus_strerror (errno));
206 
207  fclose (f);
208  return FALSE;
209  }
210 
211  if (fclose (f) == EOF)
212  {
213  dbus_set_error (error, _dbus_error_from_errno (errno),
214  "Failed to close \"%s\": %s", cfilename,
215  _dbus_strerror (errno));
216  return FALSE;
217  }
218 
219  return TRUE;
220 }
221 
235  DBusPipe *print_pid_pipe,
236  dbus_pid_t pid_to_write,
237  DBusError *error)
238 {
239  if (pidfile)
240  {
241  _dbus_verbose ("writing pid file %s\n", _dbus_string_get_const_data (pidfile));
242  if (!_dbus_write_pid_file (pidfile,
243  pid_to_write,
244  error))
245  {
246  _dbus_verbose ("pid file write failed\n");
247  _DBUS_ASSERT_ERROR_IS_SET(error);
248  return FALSE;
249  }
250  }
251  else
252  {
253  _dbus_verbose ("No pid file requested\n");
254  }
255 
256  if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
257  {
258  DBusString pid;
259  int bytes;
260 
261  _dbus_verbose ("writing our pid to pipe %d\n",
262  print_pid_pipe->fd);
263 
264  if (!_dbus_string_init (&pid))
265  {
266  _DBUS_SET_OOM (error);
267  return FALSE;
268  }
269 
270  if (!_dbus_string_append_int (&pid, pid_to_write) ||
271  !_dbus_string_append (&pid, "\n"))
272  {
273  _dbus_string_free (&pid);
274  _DBUS_SET_OOM (error);
275  return FALSE;
276  }
277 
278  bytes = _dbus_string_get_length (&pid);
279  if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
280  {
281  /* _dbus_pipe_write sets error only on failure, not short write */
282  if (error != NULL && !dbus_error_is_set(error))
283  {
285  "Printing message bus PID: did not write enough bytes\n");
286  }
287  _dbus_string_free (&pid);
288  return FALSE;
289  }
290 
291  _dbus_string_free (&pid);
292  }
293  else
294  {
295  _dbus_verbose ("No pid pipe to write to\n");
296  }
297 
298  return TRUE;
299 }
300 
308 _dbus_verify_daemon_user (const char *user)
309 {
310  DBusString u;
311 
312  _dbus_string_init_const (&u, user);
313 
315 }
316 
317 
318 /* The HAVE_LIBAUDIT case lives in selinux.c */
319 #ifndef HAVE_LIBAUDIT
320 
328 _dbus_change_to_daemon_user (const char *user,
329  DBusError *error)
330 {
331  dbus_uid_t uid;
332  dbus_gid_t gid;
333  DBusString u;
334 
335  _dbus_string_init_const (&u, user);
336 
337  if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
338  {
340  "User '%s' does not appear to exist?",
341  user);
342  return FALSE;
343  }
344 
345  /* setgroups() only works if we are a privileged process,
346  * so we don't return error on failure; the only possible
347  * failure is that we don't have perms to do it.
348  *
349  * not sure this is right, maybe if setuid()
350  * is going to work then setgroups() should also work.
351  */
352  if (setgroups (0, NULL) < 0)
353  _dbus_warn ("Failed to drop supplementary groups: %s",
354  _dbus_strerror (errno));
355 
356  /* Set GID first, or the setuid may remove our permission
357  * to change the GID
358  */
359  if (setgid (gid) < 0)
360  {
361  dbus_set_error (error, _dbus_error_from_errno (errno),
362  "Failed to set GID to %lu: %s", gid,
363  _dbus_strerror (errno));
364  return FALSE;
365  }
366 
367  if (setuid (uid) < 0)
368  {
369  dbus_set_error (error, _dbus_error_from_errno (errno),
370  "Failed to set UID to %lu: %s", uid,
371  _dbus_strerror (errno));
372  return FALSE;
373  }
374 
375 #ifdef HAVE_PDPLINUX
376  if (uid == 0){
377  /* Add special capabilities to read /proc for process name detection
378  * when Not enabled HAVE_LIBAUDIT and started by root.
379  */
380  cap_t capsproc=NULL;
381  cap_value_t cap_val=0;
382  capsproc=cap_get_proc();
383 
384  // Set all caps from CAP_INHERITABLE but needed only CAP_SYS_ADMIN CAP_DAC_OVERRIDE CAP_SYS_PTRACE
385  // Set all CAP_INHERITABLE caps (which setted by systemd daemon) to CAP_EFFECTIVE
386 
387  while (cap_val<=CAP_LAST_CAP){
388  cap_flag_value_t val;
389 
390  if (0==cap_get_flag(capsproc,
391  cap_val,
392  CAP_INHERITABLE,
393  &val)){
394  cap_set_flag(capsproc, CAP_EFFECTIVE, 1, &cap_val, val);
395  }
396 
397  cap_val++;
398  }
399 
400  cap_set_proc(capsproc);
401 
402  if (capsproc) cap_free(capsproc);
403  }
404 #endif
405 
406  return TRUE;
407 }
408 #endif /* !HAVE_LIBAUDIT */
409 
410 #ifdef HAVE_SETRLIMIT
411 
412 /* We assume that if we have setrlimit, we also have getrlimit and
413  * struct rlimit.
414  */
415 
416 struct DBusRLimit {
417  struct rlimit lim;
418 };
419 
420 DBusRLimit *
421 _dbus_rlimit_save_fd_limit (DBusError *error)
422 {
423  DBusRLimit *self;
424 
425  self = dbus_new0 (DBusRLimit, 1);
426 
427  if (self == NULL)
428  {
429  _DBUS_SET_OOM (error);
430  return NULL;
431  }
432 
433  if (getrlimit (RLIMIT_NOFILE, &self->lim) < 0)
434  {
435  dbus_set_error (error, _dbus_error_from_errno (errno),
436  "Failed to get fd limit: %s", _dbus_strerror (errno));
437  dbus_free (self);
438  return NULL;
439  }
440 
441  return self;
442 }
443 
444 /* Enough fds that we shouldn't run out, even if several uids work
445  * together to carry out a denial-of-service attack. This happens to be
446  * the same number that systemd < 234 would normally use. */
447 #define ENOUGH_FDS 65536
448 
450 _dbus_rlimit_raise_fd_limit (DBusError *error)
451 {
452  struct rlimit old, lim;
453 
454  if (getrlimit (RLIMIT_NOFILE, &lim) < 0)
455  {
456  dbus_set_error (error, _dbus_error_from_errno (errno),
457  "Failed to get fd limit: %s", _dbus_strerror (errno));
458  return FALSE;
459  }
460 
461  old = lim;
462 
463  if (getuid () == 0)
464  {
465  /* We are privileged, so raise the soft limit to at least
466  * ENOUGH_FDS, and the hard limit to at least the desired soft
467  * limit. This assumes we can exercise CAP_SYS_RESOURCE on Linux,
468  * or other OSs' equivalents. */
469  if (lim.rlim_cur != RLIM_INFINITY &&
470  lim.rlim_cur < ENOUGH_FDS)
471  lim.rlim_cur = ENOUGH_FDS;
472 
473  if (lim.rlim_max != RLIM_INFINITY &&
474  lim.rlim_max < lim.rlim_cur)
475  lim.rlim_max = lim.rlim_cur;
476  }
477 
478  /* Raise the soft limit to match the hard limit, which we can do even
479  * if we are unprivileged. In particular, systemd >= 240 will normally
480  * set rlim_cur to 1024 and rlim_max to 512*1024, recent Debian
481  * versions end up setting rlim_cur to 1024 and rlim_max to 1024*1024,
482  * and older and non-systemd Linux systems would typically set rlim_cur
483  * to 1024 and rlim_max to 4096. */
484  if (lim.rlim_max == RLIM_INFINITY || lim.rlim_cur < lim.rlim_max)
485  lim.rlim_cur = lim.rlim_max;
486 
487  /* Early-return if there is nothing to do. */
488  if (lim.rlim_max == old.rlim_max &&
489  lim.rlim_cur == old.rlim_cur)
490  return TRUE;
491 
492  if (setrlimit (RLIMIT_NOFILE, &lim) < 0)
493  {
494  dbus_set_error (error, _dbus_error_from_errno (errno),
495  "Failed to set fd limit to %lu: %s",
496  (unsigned long) lim.rlim_cur,
497  _dbus_strerror (errno));
498  return FALSE;
499  }
500 
501  return TRUE;
502 }
503 
505 _dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
506  DBusError *error)
507 {
508  if (setrlimit (RLIMIT_NOFILE, &saved->lim) < 0)
509  {
510  dbus_set_error (error, _dbus_error_from_errno (errno),
511  "Failed to restore old fd limit: %s",
512  _dbus_strerror (errno));
513  return FALSE;
514  }
515 
516  return TRUE;
517 }
518 
519 #else /* !HAVE_SETRLIMIT */
520 
521 static void
522 fd_limit_not_supported (DBusError *error)
523 {
525  "cannot change fd limit on this platform");
526 }
527 
528 DBusRLimit *
529 _dbus_rlimit_save_fd_limit (DBusError *error)
530 {
531  fd_limit_not_supported (error);
532  return NULL;
533 }
534 
536 _dbus_rlimit_raise_fd_limit (DBusError *error)
537 {
538  fd_limit_not_supported (error);
539  return FALSE;
540 }
541 
543 _dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
544  DBusError *error)
545 {
546  fd_limit_not_supported (error);
547  return FALSE;
548 }
549 
550 #endif
551 
552 void
553 _dbus_rlimit_free (DBusRLimit *lim)
554 {
555  dbus_free (lim);
556 }
557 
563 void
565  DBusSignalHandler handler)
566 {
567  struct sigaction act;
568  sigset_t empty_mask;
569 
570  sigemptyset (&empty_mask);
571  act.sa_handler = handler;
572  act.sa_mask = empty_mask;
573  act.sa_flags = 0;
574  sigaction (sig, &act, NULL);
575 }
576 
583 _dbus_file_exists (const char *file)
584 {
585  return (access (file, F_OK) == 0);
586 }
587 
595 _dbus_user_at_console (const char *username,
596  DBusError *error)
597 {
598 #ifdef DBUS_CONSOLE_AUTH_DIR
599  DBusString u, f;
600  dbus_bool_t result;
601 
602  result = FALSE;
603  if (!_dbus_string_init (&f))
604  {
605  _DBUS_SET_OOM (error);
606  return FALSE;
607  }
608 
609  if (!_dbus_string_append (&f, DBUS_CONSOLE_AUTH_DIR))
610  {
611  _DBUS_SET_OOM (error);
612  goto out;
613  }
614 
615  _dbus_string_init_const (&u, username);
616 
617  if (!_dbus_concat_dir_and_file (&f, &u))
618  {
619  _DBUS_SET_OOM (error);
620  goto out;
621  }
622 
623  result = _dbus_file_exists (_dbus_string_get_const_data (&f));
624 
625  out:
626  _dbus_string_free (&f);
627 
628  return result;
629 #else
630  return FALSE;
631 #endif
632 }
633 
634 
643 {
644  if (_dbus_string_get_length (filename) > 0)
645  return _dbus_string_get_byte (filename, 0) == '/';
646  else
647  return FALSE;
648 }
649 
659 _dbus_stat (const DBusString *filename,
660  DBusStat *statbuf,
661  DBusError *error)
662 {
663  const char *filename_c;
664  struct stat sb;
665 
666  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
667 
668  filename_c = _dbus_string_get_const_data (filename);
669 
670  if (stat (filename_c, &sb) < 0)
671  {
672  dbus_set_error (error, _dbus_error_from_errno (errno),
673  "%s", _dbus_strerror (errno));
674  return FALSE;
675  }
676 
677  statbuf->mode = sb.st_mode;
678  statbuf->nlink = sb.st_nlink;
679  statbuf->uid = sb.st_uid;
680  statbuf->gid = sb.st_gid;
681  statbuf->size = sb.st_size;
682  statbuf->atime = sb.st_atime;
683  statbuf->mtime = sb.st_mtime;
684  statbuf->ctime = sb.st_ctime;
685 
686  return TRUE;
687 }
688 
689 
694 {
695  DIR *d;
697 };
698 
708  DBusError *error)
709 {
710  DIR *d;
711  DBusDirIter *iter;
712  const char *filename_c;
713 
714  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
715 
716  filename_c = _dbus_string_get_const_data (filename);
717 
718  d = opendir (filename_c);
719  if (d == NULL)
720  {
721  dbus_set_error (error, _dbus_error_from_errno (errno),
722  "Failed to read directory \"%s\": %s",
723  filename_c,
724  _dbus_strerror (errno));
725  return NULL;
726  }
727  iter = dbus_new0 (DBusDirIter, 1);
728  if (iter == NULL)
729  {
730  closedir (d);
732  "Could not allocate memory for directory iterator");
733  return NULL;
734  }
735 
736  iter->d = d;
737 
738  return iter;
739 }
740 
756  DBusString *filename,
757  DBusError *error)
758 {
759  struct dirent *ent;
760  int err;
761 
762  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
763 
764  again:
765  errno = 0;
766  ent = readdir (iter->d);
767 
768  if (!ent)
769  {
770  err = errno;
771 
772  if (err != 0)
773  dbus_set_error (error,
775  "%s", _dbus_strerror (err));
776 
777  return FALSE;
778  }
779  else if (ent->d_name[0] == '.' &&
780  (ent->d_name[1] == '\0' ||
781  (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
782  goto again;
783  else
784  {
785  _dbus_string_set_length (filename, 0);
786  if (!_dbus_string_append (filename, ent->d_name))
787  {
789  "No memory to read directory entry");
790  return FALSE;
791  }
792  else
793  {
794  return TRUE;
795  }
796  }
797 }
798 
802 void
804 {
805  closedir (iter->d);
806  dbus_free (iter);
807 }
808 
809 static dbus_bool_t
810 fill_user_info_from_group (struct group *g,
811  DBusGroupInfo *info,
812  DBusError *error)
813 {
814  _dbus_assert (g->gr_name != NULL);
815 
816  info->gid = g->gr_gid;
817  info->groupname = _dbus_strdup (g->gr_name);
818 
819  /* info->members = dbus_strdupv (g->gr_mem) */
820 
821  if (info->groupname == NULL)
822  {
824  return FALSE;
825  }
826 
827  return TRUE;
828 }
829 
830 static dbus_bool_t
831 fill_group_info (DBusGroupInfo *info,
832  dbus_gid_t gid,
833  const DBusString *groupname,
834  DBusError *error)
835 {
836  const char *group_c_str;
837 
838  _dbus_assert (groupname != NULL || gid != DBUS_GID_UNSET);
839  _dbus_assert (groupname == NULL || gid == DBUS_GID_UNSET);
840 
841  if (groupname)
842  group_c_str = _dbus_string_get_const_data (groupname);
843  else
844  group_c_str = NULL;
845 
846  /* For now assuming that the getgrnam() and getgrgid() flavors
847  * always correspond to the pwnam flavors, if not we have
848  * to add more configure checks.
849  */
850 
851 #if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R)
852  {
853  struct group *g;
854  int result;
855  size_t buflen;
856  char *buf;
857  struct group g_str;
858  dbus_bool_t b;
859 
860  /* retrieve maximum needed size for buf */
861  buflen = sysconf (_SC_GETGR_R_SIZE_MAX);
862 
863  /* sysconf actually returns a long, but everything else expects size_t,
864  * so just recast here.
865  * https://bugs.freedesktop.org/show_bug.cgi?id=17061
866  */
867  if ((long) buflen <= 0)
868  buflen = 1024;
869 
870  result = -1;
871  while (1)
872  {
873  buf = dbus_malloc (buflen);
874  if (buf == NULL)
875  {
877  return FALSE;
878  }
879 
880  g = NULL;
881 #ifdef HAVE_POSIX_GETPWNAM_R
882  if (group_c_str)
883  result = getgrnam_r (group_c_str, &g_str, buf, buflen,
884  &g);
885  else
886  result = getgrgid_r (gid, &g_str, buf, buflen,
887  &g);
888 #else
889  g = getgrnam_r (group_c_str, &g_str, buf, buflen);
890  result = 0;
891 #endif /* !HAVE_POSIX_GETPWNAM_R */
892  /* Try a bigger buffer if ERANGE was returned:
893  https://bugs.freedesktop.org/show_bug.cgi?id=16727
894  */
895  if (result == ERANGE && buflen < 512 * 1024)
896  {
897  dbus_free (buf);
898  buflen *= 2;
899  }
900  else
901  {
902  break;
903  }
904  }
905 
906  if (result == 0 && g == &g_str)
907  {
908  b = fill_user_info_from_group (g, info, error);
909  dbus_free (buf);
910  return b;
911  }
912  else
913  {
914  dbus_set_error (error, _dbus_error_from_errno (errno),
915  "Group %s unknown or failed to look it up\n",
916  group_c_str ? group_c_str : "???");
917  dbus_free (buf);
918  return FALSE;
919  }
920  }
921 #else /* ! HAVE_GETPWNAM_R */
922  {
923  /* I guess we're screwed on thread safety here */
924  struct group *g;
925 
926  g = getgrnam (group_c_str);
927 
928  if (g != NULL)
929  {
930  return fill_user_info_from_group (g, info, error);
931  }
932  else
933  {
934  dbus_set_error (error, _dbus_error_from_errno (errno),
935  "Group %s unknown or failed to look it up\n",
936  group_c_str ? group_c_str : "???");
937  return FALSE;
938  }
939  }
940 #endif /* ! HAVE_GETPWNAM_R */
941 }
942 
954  const DBusString *groupname,
955  DBusError *error)
956 {
957  return fill_group_info (info, DBUS_GID_UNSET,
958  groupname, error);
959 
960 }
961 
973  dbus_gid_t gid,
974  DBusError *error)
975 {
976  return fill_group_info (info, gid, NULL, error);
977 }
978 
989  dbus_uid_t *uid_p)
990 {
991  return _dbus_get_user_id (username, uid_p);
992 
993 }
994 
1005  dbus_gid_t *gid_p)
1006 {
1007  return _dbus_get_group_id (groupname, gid_p);
1008 }
1009 
1022  dbus_gid_t **group_ids,
1023  int *n_group_ids)
1024 {
1025  return _dbus_groups_from_uid (uid, group_ids, n_group_ids);
1026 }
1027 
1039  DBusError *error)
1040 {
1041  return _dbus_is_console_user (uid, error);
1042 
1043 }
1044 
1054 {
1055  return uid == _dbus_geteuid ();
1056 }
1057 
1066 _dbus_windows_user_is_process_owner (const char *windows_sid)
1067 {
1068  return FALSE;
1069 }
1070  /* End of DBusInternalsUtils functions */
1072 
1086  DBusString *dirname)
1087 {
1088  int sep;
1089 
1090  _dbus_assert (filename != dirname);
1091  _dbus_assert (filename != NULL);
1092  _dbus_assert (dirname != NULL);
1093 
1094  /* Ignore any separators on the end */
1095  sep = _dbus_string_get_length (filename);
1096  if (sep == 0)
1097  return _dbus_string_append (dirname, "."); /* empty string passed in */
1098 
1099  while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1100  --sep;
1101 
1102  _dbus_assert (sep >= 0);
1103 
1104  if (sep == 0)
1105  return _dbus_string_append (dirname, "/");
1106 
1107  /* Now find the previous separator */
1108  _dbus_string_find_byte_backward (filename, sep, '/', &sep);
1109  if (sep < 0)
1110  return _dbus_string_append (dirname, ".");
1111 
1112  /* skip multiple separators */
1113  while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1114  --sep;
1115 
1116  _dbus_assert (sep >= 0);
1117 
1118  if (sep == 0 &&
1119  _dbus_string_get_byte (filename, 0) == '/')
1120  return _dbus_string_append (dirname, "/");
1121  else
1122  return _dbus_string_copy_len (filename, 0, sep - 0,
1123  dirname, _dbus_string_get_length (dirname));
1124 } /* DBusString stuff */
1126 
1127 static void
1128 string_squash_nonprintable (DBusString *str)
1129 {
1130  unsigned char *buf;
1131  int i, len;
1132 
1133  buf = _dbus_string_get_udata (str);
1134  len = _dbus_string_get_length (str);
1135 
1136  for (i = 0; i < len; i++)
1137  {
1138  unsigned char c = (unsigned char) buf[i];
1139  if (c == '\0')
1140  buf[i] = ' ';
1141  else if (c < 0x20 || c > 127)
1142  buf[i] = '?';
1143  }
1144 }
1145 
1160 dbus_bool_t
1161 _dbus_command_for_pid (unsigned long pid,
1162  DBusString *str,
1163  int max_len,
1164  DBusError *error)
1165 {
1166  /* This is all Linux-specific for now */
1167  DBusString path;
1168  DBusString cmdline;
1169  int fd;
1170 
1171  if (!_dbus_string_init (&path))
1172  {
1173  _DBUS_SET_OOM (error);
1174  return FALSE;
1175  }
1176 
1177  if (!_dbus_string_init (&cmdline))
1178  {
1179  _DBUS_SET_OOM (error);
1180  _dbus_string_free (&path);
1181  return FALSE;
1182  }
1183 
1184  if (!_dbus_string_append_printf (&path, "/proc/%ld/cmdline", pid))
1185  goto oom;
1186 
1187  fd = open (_dbus_string_get_const_data (&path), O_RDONLY);
1188  if (fd < 0)
1189  {
1190  dbus_set_error (error,
1191  _dbus_error_from_errno (errno),
1192  "Failed to open \"%s\": %s",
1193  _dbus_string_get_const_data (&path),
1194  _dbus_strerror (errno));
1195  goto fail;
1196  }
1197 
1198  if (!_dbus_read (fd, &cmdline, max_len))
1199  {
1200  dbus_set_error (error,
1201  _dbus_error_from_errno (errno),
1202  "Failed to read from \"%s\": %s",
1203  _dbus_string_get_const_data (&path),
1204  _dbus_strerror (errno));
1205  _dbus_close (fd, NULL);
1206  goto fail;
1207  }
1208 
1209  if (!_dbus_close (fd, error))
1210  goto fail;
1211 
1212  string_squash_nonprintable (&cmdline);
1213 
1214  if (!_dbus_string_copy (&cmdline, 0, str, _dbus_string_get_length (str)))
1215  goto oom;
1216 
1217  _dbus_string_free (&cmdline);
1218  _dbus_string_free (&path);
1219  return TRUE;
1220 oom:
1221  _DBUS_SET_OOM (error);
1222 fail:
1223  _dbus_string_free (&cmdline);
1224  _dbus_string_free (&path);
1225  return FALSE;
1226 }
1227 
1238 {
1239  return TRUE;
1240 }
1241 
1242 static dbus_bool_t
1243 ensure_owned_directory (const char *label,
1244  const DBusString *string,
1245  dbus_bool_t create,
1246  DBusError *error)
1247 {
1248  const char *dir = _dbus_string_get_const_data (string);
1249  struct stat buf;
1250 
1251  if (create && !_dbus_ensure_directory (string, error))
1252  return FALSE;
1253 
1254  /*
1255  * The stat()-based checks in this function are to protect against
1256  * mistakes, not malice. We are working in a directory that is meant
1257  * to be trusted; but if a user has used `su` or similar to escalate
1258  * their privileges without correctly clearing the environment, the
1259  * XDG_RUNTIME_DIR in the environment might still be the user's
1260  * and not root's. We don't want to write root-owned files into that
1261  * directory, so just warn and don't provide support for transient
1262  * services in that case.
1263  *
1264  * In particular, we use stat() and not lstat() so that if we later
1265  * decide to use a different directory name for transient services,
1266  * we can drop in a compatibility symlink without breaking older
1267  * libdbus.
1268  */
1269 
1270  if (stat (dir, &buf) != 0)
1271  {
1272  int saved_errno = errno;
1273 
1274  dbus_set_error (error, _dbus_error_from_errno (saved_errno),
1275  "%s \"%s\" not available: %s", label, dir,
1276  _dbus_strerror (saved_errno));
1277  return FALSE;
1278  }
1279 
1280  if (!S_ISDIR (buf.st_mode))
1281  {
1282  dbus_set_error (error, DBUS_ERROR_FAILED, "%s \"%s\" is not a directory",
1283  label, dir);
1284  return FALSE;
1285  }
1286 
1287  if (buf.st_uid != geteuid ())
1288  {
1290  "%s \"%s\" is owned by uid %ld, not our uid %ld",
1291  label, dir, (long) buf.st_uid, (long) geteuid ());
1292  return FALSE;
1293  }
1294 
1295  /* This is just because we have the stat() results already, so we might
1296  * as well check opportunistically. */
1297  if ((S_IWOTH | S_IWGRP) & buf.st_mode)
1298  {
1300  "%s \"%s\" can be written by others (mode 0%o)",
1301  label, dir, buf.st_mode);
1302  return FALSE;
1303  }
1304 
1305  return TRUE;
1306 }
1307 
1308 #define DBUS_UNIX_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
1309 #define DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
1310 
1320  DBusError *error)
1321 {
1322  const char *xdg_runtime_dir;
1323  DBusString services;
1324  DBusString dbus1;
1325  DBusString xrd;
1326  dbus_bool_t ret = FALSE;
1327  char *data = NULL;
1328 
1329  if (!_dbus_string_init (&dbus1))
1330  {
1331  _DBUS_SET_OOM (error);
1332  return FALSE;
1333  }
1334 
1335  if (!_dbus_string_init (&services))
1336  {
1337  _dbus_string_free (&dbus1);
1338  _DBUS_SET_OOM (error);
1339  return FALSE;
1340  }
1341 
1342  if (!_dbus_string_init (&xrd))
1343  {
1344  _dbus_string_free (&dbus1);
1345  _dbus_string_free (&services);
1346  _DBUS_SET_OOM (error);
1347  return FALSE;
1348  }
1349 
1350  xdg_runtime_dir = _dbus_getenv ("XDG_RUNTIME_DIR");
1351 
1352  /* Not an error, we just can't have transient session services */
1353  if (xdg_runtime_dir == NULL)
1354  {
1355  _dbus_verbose ("XDG_RUNTIME_DIR is unset: transient session services "
1356  "not available here\n");
1357  ret = TRUE;
1358  goto out;
1359  }
1360 
1361  if (!_dbus_string_append (&xrd, xdg_runtime_dir) ||
1362  !_dbus_string_append_printf (&dbus1, "%s/dbus-1",
1363  xdg_runtime_dir) ||
1364  !_dbus_string_append_printf (&services, "%s/dbus-1/services",
1365  xdg_runtime_dir))
1366  {
1367  _DBUS_SET_OOM (error);
1368  goto out;
1369  }
1370 
1371  if (!ensure_owned_directory ("XDG_RUNTIME_DIR", &xrd, FALSE, error) ||
1372  !ensure_owned_directory ("XDG_RUNTIME_DIR subdirectory", &dbus1, TRUE,
1373  error) ||
1374  !ensure_owned_directory ("XDG_RUNTIME_DIR subdirectory", &services,
1375  TRUE, error))
1376  goto out;
1377 
1378  if (!_dbus_string_steal_data (&services, &data) ||
1379  !_dbus_list_append (dirs, data))
1380  {
1381  _DBUS_SET_OOM (error);
1382  goto out;
1383  }
1384 
1385  _dbus_verbose ("Transient service directory is %s\n", data);
1386  /* Ownership was transferred to @dirs */
1387  data = NULL;
1388  ret = TRUE;
1389 
1390 out:
1391  _dbus_string_free (&dbus1);
1392  _dbus_string_free (&services);
1393  _dbus_string_free (&xrd);
1394  dbus_free (data);
1395  return ret;
1396 }
1397 
1417 {
1418  const char *xdg_data_home;
1419  const char *xdg_data_dirs;
1420  DBusString servicedir_path;
1421 
1422  if (!_dbus_string_init (&servicedir_path))
1423  return FALSE;
1424 
1425  xdg_data_home = _dbus_getenv ("XDG_DATA_HOME");
1426  xdg_data_dirs = _dbus_getenv ("XDG_DATA_DIRS");
1427 
1428  if (xdg_data_home != NULL)
1429  {
1430  if (!_dbus_string_append (&servicedir_path, xdg_data_home))
1431  goto oom;
1432  }
1433  else
1434  {
1435  const DBusString *homedir;
1436  DBusString local_share;
1437 
1438  if (!_dbus_homedir_from_current_process (&homedir))
1439  goto oom;
1440 
1441  if (!_dbus_string_append (&servicedir_path, _dbus_string_get_const_data (homedir)))
1442  goto oom;
1443 
1444  _dbus_string_init_const (&local_share, "/.local/share");
1445  if (!_dbus_concat_dir_and_file (&servicedir_path, &local_share))
1446  goto oom;
1447  }
1448 
1449  if (!_dbus_string_append (&servicedir_path, ":"))
1450  goto oom;
1451 
1452  if (xdg_data_dirs != NULL)
1453  {
1454  if (!_dbus_string_append (&servicedir_path, xdg_data_dirs))
1455  goto oom;
1456 
1457  if (!_dbus_string_append (&servicedir_path, ":"))
1458  goto oom;
1459  }
1460  else
1461  {
1462  if (!_dbus_string_append (&servicedir_path, "/usr/local/share:/usr/share:"))
1463  goto oom;
1464  }
1465 
1466  /*
1467  * add configured datadir to defaults
1468  * this may be the same as an xdg dir
1469  * however the config parser should take
1470  * care of duplicates
1471  */
1472  if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR))
1473  goto oom;
1474 
1475  if (!_dbus_split_paths_and_append (&servicedir_path,
1476  DBUS_UNIX_STANDARD_SESSION_SERVICEDIR,
1477  dirs))
1478  goto oom;
1479 
1480  _dbus_string_free (&servicedir_path);
1481  return TRUE;
1482 
1483  oom:
1484  _dbus_string_free (&servicedir_path);
1485  return FALSE;
1486 }
1487 
1488 
1509 {
1510  /*
1511  * DBUS_DATADIR may be the same as one of the standard directories. However,
1512  * the config parser should take care of the duplicates.
1513  *
1514  * Also, append /lib as counterpart of /usr/share on the root
1515  * directory (the root directory does not know /share), in order to
1516  * facilitate early boot system bus activation where /usr might not
1517  * be available.
1518  */
1519  static const char standard_search_path[] =
1520  "/usr/local/share:"
1521  "/usr/share:"
1522  DBUS_DATADIR ":"
1523  "/lib";
1524  DBusString servicedir_path;
1525 
1526  _dbus_string_init_const (&servicedir_path, standard_search_path);
1527 
1528  return _dbus_split_paths_and_append (&servicedir_path,
1529  DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR,
1530  dirs);
1531 }
1532 
1543 {
1544  _dbus_assert (_dbus_string_get_length (str) == 0);
1545 
1546  return _dbus_string_append (str, DBUS_SYSTEM_CONFIG_FILE);
1547 }
1548 
1557 {
1558  _dbus_assert (_dbus_string_get_length (str) == 0);
1559 
1560  return _dbus_string_append (str, DBUS_SESSION_CONFIG_FILE);
1561 }
1562 
1563 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
1564 
1565 /*
1566  * Set uid to a machine-readable authentication identity (numeric Unix
1567  * uid or ConvertSidToStringSid-style Windows SID) that is likely to exist,
1568  * and differs from the identity of the current process.
1569  *
1570  * @param uid Populated with a machine-readable authentication identity
1571  * on success
1572  * @returns #FALSE if no memory
1573  */
1575 _dbus_test_append_different_uid (DBusString *uid)
1576 {
1577  if (geteuid () == 0)
1578  return _dbus_string_append (uid, "65534");
1579  else
1580  return _dbus_string_append (uid, "0");
1581 }
1582 
1583 /*
1584  * Set uid to a human-readable authentication identity (login name)
1585  * that is likely to exist, and differs from the identity of the current
1586  * process. This function currently only exists on Unix platforms.
1587  *
1588  * @param uid Populated with a machine-readable authentication identity
1589  * on success
1590  * @returns #FALSE if no memory
1591  */
1593 _dbus_test_append_different_username (DBusString *username)
1594 {
1595  if (geteuid () == 0)
1596  return _dbus_string_append (username, "nobody");
1597  else
1598  return _dbus_string_append (username, "root");
1599 }
1600 
1601 #endif
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
Definition: dbus-string.c:935
dbus_bool_t _dbus_split_paths_and_append(DBusString *dirs, const char *suffix, DBusList **dir_list)
Split paths into a list of char strings.
Definition: dbus-sysdeps.c:228
const char * message
public error message field
Definition: dbus-errors.h:51
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t _dbus_become_daemon(const DBusString *pidfile, DBusPipe *print_pid_pipe, DBusError *error, dbus_bool_t keep_umask)
Does the chdir, fork, setsid, etc.
dbus_bool_t _dbus_unix_user_is_at_console(dbus_uid_t uid, DBusError *error)
Checks to see if the UNIX user ID is at the console.
dbus_bool_t _dbus_group_info_fill_gid(DBusGroupInfo *info, dbus_gid_t gid, DBusError *error)
Initializes the given DBusGroupInfo struct with information about the given group ID...
dbus_bool_t _dbus_string_get_dirname(const DBusString *filename, DBusString *dirname)
Get the directory name from a complete filename.
dbus_bool_t _dbus_ensure_directory(const DBusString *filename, DBusError *error)
Creates a directory; succeeds if the directory is created or already existed.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition: dbus-memory.c:702
dbus_bool_t _dbus_path_is_absolute(const DBusString *filename)
Checks whether the filename is an absolute path.
Portable struct with stat() results.
Definition: dbus-sysdeps.h:533
dbus_bool_t _dbus_ensure_standard_fds(DBusEnsureStandardFdsFlags flags, const char **error_str_p)
Ensure that the standard file descriptors stdin, stdout and stderr are open, by opening /dev/null if ...
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn&#39;t supported (like ENOSYS on UNIX).
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_string_append_int(DBusString *str, long value)
Appends an integer to a DBusString.
Definition: dbus-sysdeps.c:356
dbus_bool_t _dbus_groups_from_uid(dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids)
Gets all groups corresponding to the given UID.
dbus_bool_t _dbus_parse_unix_group_from_config(const DBusString *groupname, dbus_gid_t *gid_p)
Parse a UNIX group from the bus config file.
void _dbus_directory_close(DBusDirIter *iter)
Closes a directory iteration.
dbus_bool_t _dbus_is_console_user(dbus_uid_t uid, DBusError *error)
Checks to see if the UID sent in is the console user.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_directory_get_next_file(DBusDirIter *iter, DBusString *filename, DBusError *error)
Get next file in the directory.
unsigned long atime
Access time.
Definition: dbus-sysdeps.h:540
dbus_bool_t _dbus_get_standard_session_servicedirs(DBusList **dirs)
Returns the standard directories for a session bus to look for service activation files...
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
DBusDirIter * _dbus_directory_open(const DBusString *filename, DBusError *error)
Open a directory to iterate over.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:175
dbus_bool_t _dbus_command_for_pid(unsigned long pid, DBusString *str, int max_len, DBusError *error)
Get a printable string describing the command used to execute the process with pid.
dbus_bool_t _dbus_get_system_config_file(DBusString *str)
Get the absolute path of the system.conf file (there is no system bus on Windows so this can just ret...
dbus_bool_t _dbus_string_copy(const DBusString *source, int start, DBusString *dest, int insert_at)
Like _dbus_string_move(), but does not delete the section of the source string that&#39;s copied to the d...
Definition: dbus-string.c:1283
char * groupname
Group name.
const char * _dbus_error_from_errno(int error_number)
Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.
Definition: dbus-sysdeps.c:592
Internals of directory iterator.
unsigned long mode
File mode.
Definition: dbus-sysdeps.h:535
unsigned long dbus_pid_t
A process ID.
Definition: dbus-sysdeps.h:132
dbus_bool_t _dbus_get_user_id_and_primary_group(const DBusString *username, dbus_uid_t *uid_p, dbus_gid_t *gid_p)
Gets user ID and primary group given username.
dbus_bool_t _dbus_change_to_daemon_user(const char *user, DBusError *error)
Changes the user and group the bus is running as.
DIR * d
The DIR* from opendir()
void * dbus_malloc(size_t bytes)
Allocates the given number of bytes, as with standard malloc().
Definition: dbus-memory.c:462
dbus_gid_t gid
Group owning file.
Definition: dbus-sysdeps.h:538
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition: dbus-memory.h:58
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:190
dbus_bool_t _dbus_get_session_config_file(DBusString *str)
Get the absolute path of the session.conf file.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
Definition: dbus-list.c:270
int _dbus_read(int fd, DBusString *buffer, int count)
Thin wrapper around the read() system call that appends the data it reads to the DBusString buffer...
dbus_bool_t _dbus_string_append_printf(DBusString *str, const char *format,...)
Appends a printf-style formatted string to the DBusString.
Definition: dbus-string.c:1114
dbus_bool_t _dbus_group_info_fill(DBusGroupInfo *info, const DBusString *groupname, DBusError *error)
Initializes the given DBusGroupInfo struct with information about the given group name...
dbus_bool_t _dbus_get_group_id(const DBusString *groupname, dbus_gid_t *gid)
Gets group ID given groupname.
Object representing an exception.
Definition: dbus-errors.h:48
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition: dbus-errors.c:354
dbus_bool_t _dbus_unix_groups_from_uid(dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids)
Gets all groups corresponding to the given UNIX user ID.
unsigned long ctime
Creation time.
Definition: dbus-sysdeps.h:542
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
Definition: dbus-string.c:259
#define DBUS_GID_UNSET
an invalid GID used to represent an uninitialized dbus_gid_t field
Definition: dbus-sysdeps.h:143
dbus_uid_t _dbus_geteuid(void)
Gets our effective UID.
dbus_bool_t _dbus_file_exists(const char *file)
Checks if a file exists.
#define TRUE
Expands to "1".
unsigned long nlink
Number of hard links.
Definition: dbus-sysdeps.h:536
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
dbus_bool_t _dbus_write_pid_to_file_and_pipe(const DBusString *pidfile, DBusPipe *print_pid_pipe, dbus_pid_t pid_to_write, DBusError *error)
Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a pipe (if non-NULL).
dbus_uid_t uid
User owning file.
Definition: dbus-sysdeps.h:537
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
dbus_bool_t _dbus_verify_daemon_user(const char *user)
Verify that after the fork we can successfully change to this user.
dbus_bool_t _dbus_string_find_byte_backward(const DBusString *str, int start, unsigned char byte, int *found)
Find the given byte scanning backward from the given start.
dbus_bool_t _dbus_homedir_from_current_process(const DBusString **homedir)
Gets homedir of user owning current process.
Definition: dbus-userdb.c:447
Information about a UNIX group.
dbus_bool_t _dbus_stat(const DBusString *filename, DBusStat *statbuf, DBusError *error)
stat() wrapper.
dbus_bool_t _dbus_get_user_id(const DBusString *username, dbus_uid_t *uid)
Gets user ID given username.
void _dbus_set_signal_handler(int sig, DBusSignalHandler handler)
Installs a UNIX signal handler.
A node in a linked list.
Definition: dbus-list.h:34
dbus_bool_t _dbus_unix_user_is_process_owner(dbus_uid_t uid)
Checks to see if the UNIX user ID matches the UID of the process.
dbus_bool_t _dbus_replace_install_prefix(DBusString *path)
Replace the DBUS_PREFIX in the given path, in-place, by the current D-Bus installation directory...
dbus_bool_t _dbus_user_at_console(const char *username, DBusError *error)
Checks if user is at the console.
dbus_bool_t _dbus_windows_user_is_process_owner(const char *windows_sid)
Checks to see if the Windows user SID matches the owner of the process.
dbus_bool_t _dbus_set_up_transient_session_servicedirs(DBusList **dirs, DBusError *error)
Returns the standard directories for a session bus to look for transient service activation files...
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
dbus_bool_t _dbus_close(int fd, DBusError *error)
Closes a file descriptor.
#define FALSE
Expands to "0".
unsigned long mtime
Modify time.
Definition: dbus-sysdeps.h:541
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
Definition: dbus-string.c:802
dbus_bool_t _dbus_string_copy_len(const DBusString *source, int start, int len, DBusString *dest, int insert_at)
Like _dbus_string_copy(), but can copy a segment from the middle of the source string.
Definition: dbus-string.c:1375
dbus_bool_t _dbus_string_steal_data(DBusString *str, char **data_return)
Like _dbus_string_get_data(), but removes the gotten data from the original string.
Definition: dbus-string.c:641
dbus_gid_t gid
GID.
void(* DBusSignalHandler)(int sig)
A UNIX signal handler.
unsigned long dbus_gid_t
A group ID.
Definition: dbus-sysdeps.h:136
unsigned long size
Size of file.
Definition: dbus-sysdeps.h:539
dbus_bool_t _dbus_parse_unix_user_from_config(const DBusString *username, dbus_uid_t *uid_p)
Parse a UNIX user from the bus config file.
char * _dbus_strdup(const char *str)
Duplicates a string.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:187
unsigned long dbus_uid_t
A user ID.
Definition: dbus-sysdeps.h:134
dbus_bool_t _dbus_get_standard_system_servicedirs(DBusList **dirs)
Returns the standard directories for a system bus to look for service activation files.
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition: dbus-errors.c:329