bool MakeGuid::parsePack(ACE_Message_Block & message_block) { if (message_block.length() < Packet::head_size()) { return false; } Packet * ps = new Packet(); memcpy(ps->ch_head(), message_block.rd_ptr(), ps->head_size()); if (message_block.length() >= ps->head_size() + ps->body_size()) { message_block.rd_ptr(ps->head_size()); memcpy(ps->ch_body(), message_block.rd_ptr(), ps->body_size()); message_block.rd_ptr(ps->body_size()); parsePack(ps); return true; } else { delete ps; } return false; }
Status QueryPackConfigParserPlugin::update(const ConfigTreeMap& config) { // Iterate through all the packs to get the configuration. for (auto const& pack : config.at("packs")) { auto pack_name = std::string(pack.first.data()); auto pack_path = std::string(pack.second.data()); // Read each pack configuration in JSON pt::ptree pack_data; auto status = osquery::parseJSON(pack_path, pack_data); if (!status.ok()) { LOG(WARNING) << "Error parsing Query Pack " << pack_name << ": " << status.getMessage(); continue; } // Parse the pack, meaning compare version/platform requirements and // check the sanity of each query in the pack's queries. status = parsePack(pack_name, pack_data); if (!status.ok()) { return status; } // Save the queries list for table-based introspection. data_.put_child(pack_name, pack_data); // Record the pack path. data_.put(pack_name + ".path", pack_path); } return Status(0, "OK"); }
int MakeGuid::svc() { typed::protocol::RequestGuid request_guid; request_guid.set_request_no(m_request_no); ACE_Time_Value timeout_v(1, 0); ACE_Message_Block recv_buffer(255); MAKE_NEW_PACKET(ps, SMSG_GUID_REQUEST, 0, request_guid.SerializeAsString()); ACE_Time_Value sleep_time(0, 10 * 1000); ACE_Time_Value start_time; ACE_Time_Value diff_time; while (true) { ACE_OS::sleep(sleep_time); { ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, m_guid_info_que_mutex, -1); if (m_guid_info_que.size() > 0) { continue; } } start_time = ACE_OS::gettimeofday(); int send_n = m_sock_stream.send_n(ps->stream(), ps->stream_size()); if (send_n == ps->stream_size()) { bool parsed_packet = false; recv_buffer.crunch(); while (!parsed_packet) { int recv_n = m_sock_stream.recv(recv_buffer.wr_ptr(), recv_buffer.space(), &timeout_v); if (recv_n > 0) { recv_buffer.wr_ptr(recv_n); parsed_packet = parsePack(recv_buffer); if (parsed_packet) { diff_time = ACE_OS::gettimeofday() - start_time; ACE_UINT64 dt = 0; diff_time.to_usec(dt); DEF_LOG_INFO("request time is : <%s>\n", boost::lexical_cast<string>(dt).c_str()); } } else { // error } } } else { // error } } }