示例#1
0
/*
 * Apparently returning TRUE means "stay connected, keep doing stuff".
 * Returning FALSE means "we're all done, close the connection"
 */
gboolean
crmd_ipc_msg_callback(IPC_Channel * client, gpointer user_data)
{
    int lpc = 0;
    xmlNode *msg = NULL;
    crmd_client_t *curr_client = (crmd_client_t *) user_data;
    gboolean stay_connected = TRUE;

    crm_trace("Invoked: %s", curr_client->table_key);

    while (IPC_ISRCONN(client)) {
        if (client->ops->is_message_pending(client) == 0) {
            break;
        }

        msg = xmlfromIPC(client, MAX_IPC_DELAY);
        if (msg == NULL) {
            break;
        }
#if ENABLE_ACL
        determine_request_user(&curr_client->user, client, msg, F_CRM_USER);
#endif

        lpc++;
        crm_trace("Processing msg from %s", curr_client->table_key);
        crm_log_xml_trace(msg, "CRMd[inbound]");

        if (crmd_authorize_message(msg, curr_client)) {
            route_message(C_IPC_MESSAGE, msg);
        }

        free_xml(msg);
        msg = NULL;

        if (client->ch_status != IPC_CONNECT) {
            break;
        }
    }

    crm_trace("Processed %d messages", lpc);

    if (client->ch_status != IPC_CONNECT) {
        stay_connected = FALSE;
        process_client_disconnect(curr_client);
    }

    trigger_fsa(fsa_source);
    return stay_connected;
}
示例#2
0
gboolean
crmd_authorize_message(xmlNode * client_msg, crmd_client_t * curr_client)
{
    /* check the best case first */
    const char *sys_from = crm_element_value(client_msg, F_CRM_SYS_FROM);
    char *uuid = NULL;
    char *client_name = NULL;
    char *major_version = NULL;
    char *minor_version = NULL;
    const char *filtered_from;
    gpointer table_key = NULL;
    gboolean auth_result = FALSE;
    struct crm_subsystem_s *the_subsystem = NULL;
    gboolean can_reply = FALSE; /* no-one has registered with this id */

    xmlNode *xml = NULL;
    const char *op = crm_element_value(client_msg, F_CRM_TASK);

    if (safe_str_neq(CRM_OP_HELLO, op)) {

        if (sys_from == NULL) {
            crm_warn("Message [%s] was had no value for %s... discarding",
                     crm_element_value(client_msg, XML_ATTR_REFERENCE), F_CRM_SYS_FROM);
            return FALSE;
        }

        filtered_from = sys_from;

        /* The CIB can have two names on the DC */
        if (strcasecmp(sys_from, CRM_SYSTEM_DCIB) == 0)
            filtered_from = CRM_SYSTEM_CIB;

        if (g_hash_table_lookup(ipc_clients, filtered_from) != NULL) {
            can_reply = TRUE;   /* reply can be routed */
        }

        crm_debug_2("Message reply can%s be routed from %s.", can_reply ? "" : " not", sys_from);

        if (can_reply == FALSE) {
            crm_warn("Message [%s] not authorized",
                     crm_element_value(client_msg, XML_ATTR_REFERENCE));
        }

        return can_reply;
    }

    crm_debug_3("received client join msg");
    crm_log_xml(LOG_MSG, "join", client_msg);
    xml = get_message_xml(client_msg, F_CRM_DATA);
    auth_result = process_hello_message(xml, &uuid, &client_name, &major_version, &minor_version);

    if (auth_result == TRUE) {
        if (client_name == NULL || uuid == NULL) {
            crm_err("Bad client details (client_name=%s, uuid=%s)",
                    crm_str(client_name), crm_str(uuid));
            auth_result = FALSE;
        }
    }

    if (auth_result == TRUE) {
        /* check version */
        int mav = atoi(major_version);
        int miv = atoi(minor_version);

        crm_debug_3("Checking client version number");
        if (mav < 0 || miv < 0) {
            crm_err("Client version (%d:%d) is not acceptable", mav, miv);
            auth_result = FALSE;
        }
        crm_free(major_version);
        crm_free(minor_version);
    }

    if (safe_str_eq(CRM_SYSTEM_PENGINE, client_name)) {
        the_subsystem = pe_subsystem;

    } else if (safe_str_eq(CRM_SYSTEM_TENGINE, client_name)) {
        the_subsystem = te_subsystem;
    }

    /* TODO: Is this code required anymore?? */
    if (auth_result == TRUE && the_subsystem != NULL) {
        /* if we already have one of those clients
         * only applies to te, pe etc.  not admin clients
         */
        crm_err("Checking if %s is required/already connected", client_name);

        table_key = (gpointer) crm_strdup(client_name);

        if (is_set(fsa_input_register, the_subsystem->flag_connected)) {
            auth_result = FALSE;
            crm_free(table_key);
            table_key = NULL;
            crm_warn("Bit\t%.16llx set in %.16llx",
                     the_subsystem->flag_connected, fsa_input_register);
            crm_err("Client %s is already connected", client_name);

        } else if (FALSE == is_set(fsa_input_register, the_subsystem->flag_required)) {
            crm_warn("Bit\t%.16llx not set in %.16llx",
                     the_subsystem->flag_connected, fsa_input_register);
            crm_warn("Client %s joined but we dont need it", client_name);
            stop_subsystem(the_subsystem, TRUE);

        } else {
            the_subsystem->ipc = curr_client->client_channel;
            set_bit_inplace(fsa_input_register, the_subsystem->flag_connected);
        }

    } else {
        table_key = (gpointer) generate_hash_key(client_name, uuid);
    }

    if (auth_result == TRUE) {
        crm_debug_2("Accepted client %s", crm_str(table_key));

        curr_client->table_key = table_key;
        curr_client->sub_sys = crm_strdup(client_name);
        curr_client->uuid = crm_strdup(uuid);

        g_hash_table_insert(ipc_clients, table_key, curr_client->client_channel);

        send_hello_message(curr_client->client_channel, "n/a", CRM_SYSTEM_CRMD, "0", "1");

        crm_debug_3("Updated client list with %s", crm_str(table_key));

        crm_debug_3("Triggering FSA: %s", __FUNCTION__);
        mainloop_set_trigger(fsa_source);

        if (the_subsystem != NULL) {
            CRM_CHECK(the_subsystem->client == NULL,
                      process_client_disconnect(the_subsystem->client));
            the_subsystem->client = curr_client;
        }

    } else {
        crm_free(table_key);
        crm_warn("Rejected client logon request");
        curr_client->client_channel->ch_status = IPC_DISC_PENDING;
    }

    if (uuid != NULL)
        crm_free(uuid);
    if (minor_version != NULL)
        crm_free(minor_version);
    if (major_version != NULL)
        crm_free(major_version);
    if (client_name != NULL)
        crm_free(client_name);

    /* hello messages should never be processed further */
    return FALSE;
}