Ejemplo n.º 1
0
static dbus_bool_t
get_parameters_for_service (BusDesktopFile *desktop_file,
                            const char     *service_name,
                            char          **exec,
                            char          **user,
                            DBusError      *error)
{
    char *exec_tmp;
    char *user_tmp;

    exec_tmp = NULL;
    user_tmp = NULL;

    /* check the name of the service */
    if (!check_service_name (desktop_file, service_name, error))
        goto failed;

    /* get the complete path of the executable */
    if (!bus_desktop_file_get_string (desktop_file,
                                      DBUS_SERVICE_SECTION,
                                      DBUS_SERVICE_EXEC,
                                      &exec_tmp,
                                      error))
    {
        _DBUS_ASSERT_ERROR_IS_SET (error);
        goto failed;
    }

    /* get the user that should run this service - user is compulsary for system activation */
    if (!bus_desktop_file_get_string (desktop_file,
                                      DBUS_SERVICE_SECTION,
                                      DBUS_SERVICE_USER,
                                      &user_tmp,
                                      error))
    {
        _DBUS_ASSERT_ERROR_IS_SET (error);
        goto failed;
    }

    /* only assign if all the checks passed */
    *exec = exec_tmp;
    *user = user_tmp;
    return TRUE;

failed:
    dbus_free (exec_tmp);
    dbus_free (user_tmp);
    return FALSE;
}
Ejemplo n.º 2
0
static dbus_bool_t
check_service_name (BusDesktopFile *desktop_file,
                    const char     *service_name,
                    DBusError      *error)
{
  char *name_tmp;
  dbus_bool_t retval;

  retval = FALSE;

  /* try to get Name */
  if (!bus_desktop_file_get_string (desktop_file,
                                    DBUS_SERVICE_SECTION,
                                    DBUS_SERVICE_NAME,
                                    &name_tmp,
                                    error))
    goto failed;

  /* verify that the name is the same as the file service name */
  if (strcmp (service_name, name_tmp) != 0)
    {
      dbus_set_error (error, DBUS_ERROR_SPAWN_FILE_INVALID,
                      "Service '%s' does not match expected value", name_tmp);
      goto failed_free;
    }

  retval = TRUE;

failed_free:
  /* we don't return the name, so free it here */
  dbus_free (name_tmp);
failed:
  return retval;
}
Ejemplo n.º 3
0
static dbus_bool_t
get_parameters_for_service (BusDesktopFile *desktop_file,
                            const char     *service_name,
                            char          **exec,
                            char          **user,
                            char          **alias,
                            DBusError      *error)
{
  char *exec_tmp;
  char *user_tmp;
  char *alias_tmp;

  exec_tmp = NULL;
  user_tmp = NULL;
  alias_tmp = NULL;

  /* check the name of the service */
  if (!check_service_name (desktop_file, service_name, error))
    goto failed;

  /* look up if the service is an alias to another service */
  if (bus_desktop_file_get_string (desktop_file,
                                   DBUS_SERVICE_SECTION,
                                   DBUS_SERVICE_ALIAS,
                                   &alias_tmp,
                                   error))
    {
      /* TODO: Should we check for Exec and User field in the file and
               warn / error if they are set? They don't make sense when
               a service is an alias to another service, and may be
               misleading. */
      /*
      if (bus_desktop_file_has_string (desktop_file,
                                       DBUS_SERVICE_SECTION,
                                       DBUS_SERVICE_EXEC)))
        {
          dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED,
                          "You can't set Alias and Exec together");
          goto failed;
        }
      if (bus_desktop_file_has_string (desktop_file,
                                       DBUS_SERVICE_SECTION,
                                       DBUS_SERVICE_USER)))
        {
          dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED,
                          "You can't set Alias and User together");
          goto failed;
        }
        */

      *alias = alias_tmp;
      return TRUE;
    }
  else
    {
      /* TODO: Notify of OOM errors, or you'll see confusing error messages. */
      dbus_error_free (error);
    }

  /* get the complete path of the executable */
  if (!bus_desktop_file_get_string (desktop_file,
                                    DBUS_SERVICE_SECTION,
                                    DBUS_SERVICE_EXEC,
                                    &exec_tmp,
                                    error))
    {
      _DBUS_ASSERT_ERROR_IS_SET (error);
      goto failed;
    }

  /* get the user that should run this service - user is compulsary for system activation */
  if (!bus_desktop_file_get_string (desktop_file,
                                    DBUS_SERVICE_SECTION,
                                    DBUS_SERVICE_USER,
                                    &user_tmp,
                                    error))
    {
      _DBUS_ASSERT_ERROR_IS_SET (error);
      goto failed;
    }

  /* only assign if all the checks passed */
  *exec = exec_tmp;
  *user = user_tmp;
  return TRUE;

failed:
  dbus_free (exec_tmp);
  dbus_free (user_tmp);
  dbus_free (alias_tmp);
  return FALSE;
}