[daemon-fix] Fixed sending daemon match rules for kdbus broadcasts
[platform/upstream/dbus.git] / bus / activation-helper-bin.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* activation-helper-bin.c  Setuid helper for launching programs as a custom
3  *                          user. This file is security sensitive.
4  *
5  * Copyright (C) 2007 Red Hat, Inc.
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
27 #include "utils.h"
28 #include "activation-helper.h"
29 #include "activation-exit-codes.h"
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 static int
36 convert_error_to_exit_code (DBusError *error)
37 {
38   if (dbus_error_has_name (error, DBUS_ERROR_NO_MEMORY))
39     return BUS_SPAWN_EXIT_CODE_NO_MEMORY;
40
41   if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_CONFIG_INVALID))
42     return BUS_SPAWN_EXIT_CODE_CONFIG_INVALID;
43
44   if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_SETUP_FAILED))
45     return BUS_SPAWN_EXIT_CODE_SETUP_FAILED;
46
47   if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_SERVICE_INVALID))
48     return BUS_SPAWN_EXIT_CODE_SERVICE_NOT_FOUND;
49
50   if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID))
51     return BUS_SPAWN_EXIT_CODE_PERMISSIONS_INVALID;
52
53   if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_FILE_INVALID))
54     return BUS_SPAWN_EXIT_CODE_FILE_INVALID;
55
56   if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_EXEC_FAILED))
57     return BUS_SPAWN_EXIT_CODE_EXEC_FAILED;
58
59   if (dbus_error_has_name (error, DBUS_ERROR_INVALID_ARGS))
60     return BUS_SPAWN_EXIT_CODE_INVALID_ARGS;
61
62   if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_CHILD_SIGNALED))
63     return BUS_SPAWN_EXIT_CODE_CHILD_SIGNALED;
64   
65   /* should we assert? */
66   fprintf(stderr, "%s: %s\n", error->name, error->message);
67   
68   return BUS_SPAWN_EXIT_CODE_SETUP_FAILED;
69 }
70
71 int
72 main (int argc, char **argv)
73 {
74   DBusError error;
75   int retval;
76
77   /* default is all okay */
78   retval = 0;
79
80   /* have we used a help option or not specified the correct arguments? */
81   if (argc != 2 ||
82       strcmp (argv[1], "--help") == 0 ||
83       strcmp (argv[1], "-h") == 0 ||
84       strcmp (argv[1], "-?") == 0)
85     {
86         fprintf (stderr, "dbus-daemon-activation-helper service.to.activate\n");
87         exit (0);
88     }
89
90   dbus_error_init (&error);
91   if (!run_launch_helper (argv[1], &error))
92     {
93       /* convert error to an exit code */
94       retval = convert_error_to_exit_code (&error);
95       dbus_error_free (&error);
96     }
97
98   return retval;
99 }
100