Beispiel #1
0
gboolean
do_init(void)
{
    GCHSource *src = NULL;

    crm_malloc0(admin_uuid, 11);
    if (admin_uuid != NULL) {
        snprintf(admin_uuid, 10, "%d", getpid());
        admin_uuid[10] = '\0';
    }

    src = init_client_ipc_comms(CRM_SYSTEM_CRMD, admin_msg_callback, NULL, &crmd_channel);

    if (DO_RESOURCE || DO_RESOURCE_LIST || DO_NODE_LIST) {
        return TRUE;

    } else if (crmd_channel != NULL) {
        send_hello_message(crmd_channel, admin_uuid, crm_system_name, "0", "1");

        set_IPC_Channel_dnotify(src, crmadmin_ipc_connection_destroy);

        return TRUE;
    }
    return FALSE;
}
Beispiel #2
0
static void channel_connecting(Channel * c) {
    struct channel_extra *ce = (struct channel_extra *)c->client_data;
    lua_State *L = ce->L;

    if(ce->connecting_cbrefp != NULL) {
        lua_rawgeti(L, LUA_REGISTRYINDEX, ce->connecting_cbrefp->ref);
        if(lua_pcall(L, 0, 0, 0) != 0) {
            fprintf(stderr, "%s\n", lua_tostring(L,1));
            exit(1);
        }
    }
    trace(LOG_LUA, "lua_channel_connecting %p", c);
    send_hello_message(c);
}
static void proxy_connecting(Channel * c) {
    Proxy * target = c->client_data;

    assert(c == target->c);
    assert(target->other == -1);
    assert(target->state == ProxyStateInitial);
    assert((target + target->other)->state == ProxyStateConnected);

    trace(LOG_PROXY, "Proxy waiting Hello from target");
    target->state = ProxyStateConnecting;

    send_hello_message(target->proto, target->c);
    flush_stream(&target->c->out);
}
static void start_channel(Channel * channel) {
    ChannelNP * c = channel2np(channel);

    assert(is_dispatch_thread());
    assert(c->magic == CHANNEL_MAGIC);
    assert(c->socket != NOPOLL_INVALID_SOCKET);
    notify_channel_created(&c->chan);
    if (c->chan.connecting) {
        c->chan.connecting(&c->chan);
    }
    else {
        trace(LOG_PROTOCOL, "channel server connecting");
        send_hello_message(&c->chan);
    }
    ibuf_trigger_read(&c->ibuf);
}
Beispiel #5
0
static void channel_server_connecting(Channel * c1) {
    trace(LOG_ALWAYS, "channel server connecting");

    assert(c1->state == ChannelStateStarted);
    if (auto_redirect) {
        /* Fake that we sent hello message. */
        c1->state = ChannelStateHelloSent;
    }
    else {
        /* Enable only the locator_service */
#if SERVICE_Locator
        ini_locator_service(c1->protocol, bcg);
#endif
        send_hello_message(c1);
    }
}
static void proxy_connected(Channel * c) {
    Proxy * target = c->client_data;
    Proxy * host = target + target->other;
    int i;

    assert(target->c == c);
    assert(target->other == -1);
    assert(target->state == ProxyStateConnecting);
    assert(host->state == ProxyStateConnected);

    target->state = ProxyStateConnected;

    trace(LOG_PROXY, "Proxy connected, target services:");
    for (i = 0; i < target->c->peer_service_cnt; i++) {
        trace(LOG_PROXY, "    %s", target->c->peer_service_list[i]);
        protocol_get_service(host->proto, target->c->peer_service_list[i]);
    }

    send_hello_message(host->proto, host->c);
    flush_stream(&host->c->out);
}
Beispiel #7
0
      void run(void *)
      {//this keeps the program alive
      	
		 //debug_->debug("%u --- counter = %d\n", radio_->id(), counter);         
         if (mode==1)
         {//if you are not in the network 
            if (counter>=0)
            {//if the counter is positive
               counter++;
               if (counter==4)
               {//if the counter is 4 then you can come in the network
                  debug_->debug("%u:: i'm going in!!\n", radio_->id());
                  send_hello_message();//send hello message
                  mode=0;//change your mode, now you are in the network
               }
               else if (counter!=-1)
               {//if counter is not -1 send participation message (it will not be ofcourse)
                  debug_->debug("(%u - %s - %s)sending participation message %i\n",radio_->id(),my_ip,my_host,counter);
                  send_participate_message();
               }
            }
            else 
            {//else
               if (counter==-1)//if counter is -1, well.. we fix this in other position doesnot need here.. anyway.
               {
                  debug_->debug("oops must resolve it!!!\n");
               }
               generate_ip();
            }
            timer_->set_timer<Zeroconf, &Zeroconf::run>( 5000, this, 0 );//recall run function after 5000miliseconds
         }
         else if (mode==0)
         {//if you are in the network...
            timer_->set_timer<Zeroconf, &Zeroconf::run>( 1000, this, 0 );//recall run function after 5000 miliseconds
			//here we will add code for searching for services if needed, and advertise new services if any.
         }	
      }
Beispiel #8
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;
}