MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ExecuteCommandAPIHandler

Method ExecuteCommandAPIHandler

lib/icinga/clusterevents.cpp:914–1069  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

912}
913
914Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
915{
916 ApiListener::Ptr listener = ApiListener::GetInstance();
917
918 if (!listener)
919 return Empty;
920
921 if (!origin->IsLocal()) {
922 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
923
924 /* Discard messages from anonymous clients */
925 if (!endpoint) {
926 Log(LogNotice, "ClusterEvents") << "Discarding 'execute command' message from '"
927 << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
928 return Empty;
929 }
930
931 Zone::Ptr originZone = endpoint->GetZone();
932
933 Zone::Ptr localZone = Zone::GetLocalZone();
934 bool fromLocalZone = originZone == localZone;
935
936 Zone::Ptr parentZone = localZone->GetParent();
937 bool fromParentZone = parentZone && originZone == parentZone;
938
939 if (!fromLocalZone && !fromParentZone) {
940 Log(LogNotice, "ClusterEvents") << "Discarding 'execute command' message from '"
941 << origin->FromClient->GetIdentity() << "': Unauthorized access.";
942 return Empty;
943 }
944 }
945
946 String executionUuid = params->Get("source");
947
948 if (params->Contains("endpoint")) {
949 Endpoint::Ptr execEndpoint = Endpoint::GetByName(params->Get("endpoint"));
950
951 if (!execEndpoint) {
952 Log(LogWarning, "ClusterEvents")
953 << "Discarding 'execute command' message " << executionUuid
954 << ": Endpoint " << params->Get("endpoint") << " does not exist";
955 return Empty;
956 }
957
958 if (execEndpoint != Endpoint::GetLocalEndpoint()) {
959 Zone::Ptr endpointZone = execEndpoint->GetZone();
960 Zone::Ptr localZone = Zone::GetLocalZone();
961
962 if (!endpointZone->IsChildOf(localZone)) {
963 return Empty;
964 }
965
966 /* Check if the child endpoints have Icinga version >= 2.13 */
967 for (const Zone::Ptr &zone : ConfigType::GetObjectsByType<Zone>()) {
968 /* Fetch immediate child zone members */
969 if (zone->GetParent() == localZone && zone->CanAccessObject(endpointZone)) {
970 auto endpoints (zone->GetEndpoints());
971

Callers

nothing calls this directly

Calls 15

LogClass · 0.85
IsLocalMethod · 0.80
GetEndpointMethod · 0.80
GetIdentityMethod · 0.80
IsChildOfMethod · 0.80
CanAccessObjectMethod · 0.80
GetEndpointsMethod · 0.80
RelayMessageMethod · 0.80
GetServiceByShortNameMethod · 0.80
GetZoneMethod · 0.45
GetParentMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected