Esempio n. 1
0
gboolean
Resources_list(Matahari *matahari, const char *standard, const char *provider,
               DBusGMethodInvocation *context)
{
    GError* error = NULL;
    int i = 0;
    gchar **list;
    GList *agents = NULL;

    if (!check_authorization(RESOURCES_INTERFACE_NAME ".list",
                             &error, context)) {
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        return FALSE;
    }

    if (strlen(standard) == 0)
        standard = "ocf";
    if (strlen(provider) == 0)
        provider = "heartbeat";

    // Get list of agents
    agents = resources_list_agents(standard, provider);

    // Convert GList to (char **)
    list = g_new(char *, g_list_length(agents) + 1);
    for (; agents != NULL; agents = agents->next)
        list[i++] = strdup(agents->data);
    list[i] = NULL; // Sentinel

    dbus_g_method_return(context, list);
    g_strfreev(list);
    g_list_free_full(agents, free);
    return TRUE;
}
Esempio n. 2
0
gboolean
Services_list(Matahari *matahari, DBusGMethodInvocation *context)
{
    GError* error = NULL;
    int i = 0;
    GList *services;
    char **list;

    if (!check_authorization(SERVICES_BUS_NAME ".list", &error, context)) {
        dbus_g_method_return_error(context, error);
        return FALSE;
    }

    // Get list of services
    services = services_list();

    // Convert GList to (char **)
    list = g_new(char *, g_list_length(services) + 1);
    for (; services != NULL; services = services->next)
        list[i++] = strdup(services->data);
    list[i] = NULL; // Sentinel

    dbus_g_method_return(context, list);
    g_strfreev(list);
    g_list_free(services);
    return TRUE;
}
gboolean
Host_list_power_profiles(Matahari* matahari, DBusGMethodInvocation *context)
{
    GError *error = NULL;
    GList *list, *plist;
    char **profiles;
    int i = 0;

    if (!check_authorization(HOST_BUS_NAME ".list_power_profiles", &error, context)) {
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        return FALSE;
    }
    // Get the list of profiles
    list = mh_host_list_power_profiles();

    // Convert GList * with profiles to array (char **)
    profiles = g_new(char *, g_list_length(list) + 1);
    for (plist = g_list_first(list);
         plist;
         plist = g_list_next(plist)) {
        profiles[i++] = plist->data;
    }
    profiles[i] = NULL; // Sentinel

    dbus_g_method_return(context, profiles);
    g_list_free_full(list, free);
    g_free(profiles);
    return TRUE;
}
Esempio n. 4
0
gboolean
Resources_list_providers(Matahari *matahari, const char *standard,
                         DBusGMethodInvocation *context)
{
    GError* error = NULL;
    gchar **list;
    int i = 0;
    GList *providers;

    if (!check_authorization(RESOURCES_INTERFACE_NAME ".list_providers",
                             &error, context)) {
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        return FALSE;
    }

    // Get list of providers
    providers = resources_list_providers(standard);

    // Convert GList to (char **)
    list = g_new(char *, g_list_length(providers) + 1);
    for (; providers != NULL; providers = providers->next)
        list[i++] = strdup(providers->data);
    list[i] = NULL; // Sentinel

    dbus_g_method_return(context, list);
    g_strfreev(list);
    g_list_free_full(providers, free);
    return TRUE;
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
    DBusConnection *conn;
    struct sigaction sa;

    conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
    if (!conn) {
        fprintf(stderr, "Can't get on system bus");
        return 1;
    }

    check_authorization(conn);

    memset(&sa, 0, sizeof(sa));
    sa.sa_flags   = SA_NOCLDSTOP;
    sa.sa_handler = sig_term;
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGINT,  &sa, NULL);

#if 0
    while (!__io_terminate) {
        if (dbus_connection_read_write_dispatch(conn, 500) == FALSE)
            break;
    }
#endif

    dbus_connection_unref(conn);

    return 0;
}
gboolean
Host_reboot(Matahari* matahari, DBusGMethodInvocation *context)
{
    GError* error = NULL;
    if (!check_authorization(HOST_BUS_NAME ".reboot", &error, context)) {
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        return FALSE;
    }
    mh_host_reboot();
    dbus_g_method_return(context, TRUE);
    return TRUE;
}
gboolean
Host_get_uuid(Matahari* matahari, const char *lifetime, DBusGMethodInvocation *context)
{
    GError* error = NULL;
    const char *uuid = NULL;
    if (!check_authorization(HOST_BUS_NAME ".get_uuid", &error, context)) {
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        return FALSE;
    }
    uuid = mh_host_get_uuid(lifetime);
    dbus_g_method_return(context, uuid);
    return TRUE;
}
Esempio n. 8
0
gboolean
Resources_invoke(Matahari *matahari, const char *name, const char *standard,
                 const char *provider, const char *agent, const char *action,
                 unsigned int interval, GHashTable *parameters,
                 unsigned int timeout, unsigned int expected_rc,
                 const char *userdata_in, DBusGMethodInvocation *context)
{
    GError* error = NULL;
    svc_action_t *op = NULL;
    GList *standards;
    struct invoke_cb_data *data;

    if (!check_authorization(RESOURCES_INTERFACE_NAME ".invoke",
                             &error, context)) {
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        return FALSE;
    }

    // Check if standard is valid
    standards = resources_list_standards();

    if (g_list_find_custom(standards, standard, (GCompareFunc) strcasecmp) == NULL) {
        mh_err("%s is not a known resource standard", standard);
        error = g_error_new(MATAHARI_ERROR, MH_RES_NOT_IMPLEMENTED,
                            "%s is not a known resource standard", standard);
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        g_list_free_full(standards, free);
        return FALSE;
    }
    g_list_free_full(standards, free);

    op = resources_action_create(name, standard, provider, agent, action,
                                 0, timeout, g_hash_table_ref(parameters));
    op->expected_rc = expected_rc;

    if (!(data = malloc(1 * sizeof(struct invoke_cb_data)))) {
        services_action_free(op);
        return FALSE;
    }

    data->context = context;
    data->userdata = strdup(userdata_in);
    op->cb_data = data;

    services_action_async(op, invoke_cb);
    return FALSE;
}
Esempio n. 9
0
gboolean
Services_describe(Matahari *matahari, const char *name,
                  DBusGMethodInvocation *context)
{
    GError* error = NULL;
    if (!check_authorization(SERVICES_BUS_NAME ".describe", &error, context)) {
        dbus_g_method_return_error(context, error);
        return FALSE;
    }
    // TODO: Implement when implemented in backend
    error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
                        "Action describe is not implemented yet!");
    dbus_g_method_return_error(context, error);
    return TRUE;
}
Esempio n. 10
0
gboolean
Services_cancel(Matahari *matahari, const char *name, const char *action,
                unsigned int interval, DBusGMethodInvocation *context)
{
    GError* error = NULL;
    int res;

    if (!check_authorization(SERVICES_BUS_NAME ".cancel", &error, context)) {
        dbus_g_method_return_error(context, error);
        return FALSE;
    }
    res = services_action_cancel(name, action, interval);
    dbus_g_method_return(context);
    return res;
}
Esempio n. 11
0
gboolean
Resources_cancel(Matahari *matahari, const char *name, const char *action,
                 unsigned int interval, unsigned int timeout,
                 DBusGMethodInvocation *context)
{
    GError* error = NULL;
    if (!check_authorization(RESOURCES_INTERFACE_NAME ".cancel",
                             &error, context)) {
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        return FALSE;
    }

    services_action_cancel(name, action, 0);
    dbus_g_method_return(context);
    return TRUE;
}
Esempio n. 12
0
gboolean
Services_disable(Matahari *matahari, const char *name,
                 DBusGMethodInvocation *context)
{
    GError* error = NULL;
    svc_action_t *op;
    gboolean res;

    if (!check_authorization(SERVICES_BUS_NAME ".disable", &error, context)) {
        dbus_g_method_return_error(context, error);
        return FALSE;
    }
    op = services_action_create(name, "disable", 0, TIMEOUT_MS);
    res = services_action_sync(op);
    services_action_free(op);
    dbus_g_method_return(context, res);
    return res;
}
Esempio n. 13
0
gboolean
Resources_fail(Matahari *matahari, const char *name, unsigned int rc,
                         DBusGMethodInvocation *context)
{
    GError* error = NULL;
    if (!check_authorization(RESOURCES_INTERFACE_NAME ".fail",
                             &error, context)) {
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        return FALSE;
    }
    // TODO: Implement when implemented in backend
    error = g_error_new(MATAHARI_ERROR, MH_RES_NOT_IMPLEMENTED,
                        "%s", mh_result_to_str(MH_RES_NOT_IMPLEMENTED));
    dbus_g_method_return_error(context, error);
    g_error_free(error);
    return TRUE;
}
Esempio n. 14
0
gboolean
Services_status(Matahari *matahari, const char *name, unsigned int interval,
                unsigned int timeout, DBusGMethodInvocation *context)
{
    GError* error = NULL;
    svc_action_t *op;
    int rc;

    if (!check_authorization(SERVICES_BUS_NAME ".status", &error, context)) {
        dbus_g_method_return_error(context, error);
        return FALSE;
    }
    op = services_action_create(name, "status", interval, timeout);
    services_action_sync(op);
    rc = op->rc;
    services_action_free(op);
    dbus_g_method_return(context, rc);
    return TRUE;
}
gboolean
Host_set_power_profile(Matahari* matahari, const char *profile, DBusGMethodInvocation *context)
{
    GError *error = NULL;
    enum mh_result res;

    if (!check_authorization(HOST_BUS_NAME ".set_power_profile", &error, context)) {
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        return FALSE;
    }
    res = mh_host_set_power_profile(profile);
    if (res != MH_RES_SUCCESS) {
        error = g_error_new(MATAHARI_ERROR, res, mh_result_to_str(res));
        dbus_g_method_return_error(context, error);
        g_error_free(error);
        return FALSE;
    }

    dbus_g_method_return(context, 0);
    return TRUE;
}
Esempio n. 16
0
/**
 * perform SIP message sanity check
 * @param _msg - SIP message structure
 * @param msg_checks - bitmask of sanity tests to perform over message
 * @param uri_checks - bitmask of sanity tests to perform over uri
 * @return -1 on error, 0 on tests failure, 1 on success
 */
int sanity_check(struct sip_msg* _msg, int msg_checks, int uri_checks)
{
	int ret;

	ret = SANITY_CHECK_PASSED;
	if (SANITY_RURI_SIP_VERSION & msg_checks &&
			(ret = check_ruri_sip_version(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_RURI_SCHEME & msg_checks &&
			(ret = check_ruri_scheme(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_REQUIRED_HEADERS & msg_checks &&
			(ret = check_required_headers(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_VIA_SIP_VERSION & msg_checks &&
			(ret = check_via_sip_version(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_VIA_PROTOCOL & msg_checks &&
			(ret = check_via_protocol(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_CSEQ_METHOD & msg_checks &&
			(ret = check_cseq_method(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_CSEQ_VALUE & msg_checks &&
			(ret = check_cseq_value(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_CL & msg_checks &&
			(ret = check_cl(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_EXPIRES_VALUE & msg_checks &&
			(ret = check_expires_value(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_PROXY_REQUIRE & msg_checks &&
			(ret = check_proxy_require(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_PARSE_URIS & msg_checks &&
			(ret = check_parse_uris(_msg, uri_checks)) != SANITY_CHECK_PASSED) {
		goto done;
	}

	if (SANITY_CHECK_DIGEST & msg_checks &&
			(ret = check_digest(_msg, uri_checks)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_CHECK_AUTHORIZATION & msg_checks &&
			(ret = check_authorization(_msg, uri_checks)) != SANITY_CHECK_PASSED) {
		goto done;
	}
	if (SANITY_CHECK_DUPTAGS & msg_checks &&
			(ret = check_duptags(_msg)) != SANITY_CHECK_PASSED) {
		goto done;
	}

done:
	return ret;
}