mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 08:45:12 +02:00
Added several UDP Server Auth IPs to Windows Agent
This commit is contained in:
parent
6545818f13
commit
161921be3d
@ -38,16 +38,6 @@ unsigned long UDP_Server::getAddress () {
|
|||||||
return this->address;
|
return this->address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the address authorized to send commands to
|
|
||||||
* the server.
|
|
||||||
*
|
|
||||||
* @return Authorized address.
|
|
||||||
*/
|
|
||||||
unsigned long UDP_Server::getAuthAddress () {
|
|
||||||
return this->auth_address;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the port of the server.
|
* Get the port of the server.
|
||||||
*
|
*
|
||||||
@ -90,9 +80,9 @@ UDP_Server::UDP_Server (Pandora_Windows_Service *service, string address, string
|
|||||||
this->address = inet_addr (address.c_str ());
|
this->address = inet_addr (address.c_str ());
|
||||||
}
|
}
|
||||||
if (auth_address.empty ()) {
|
if (auth_address.empty ()) {
|
||||||
this->auth_address = INADDR_ANY;
|
this->auth_address.push_front(INADDR_ANY);
|
||||||
} else {
|
} else {
|
||||||
this->auth_address = inet_addr (auth_address.c_str ());
|
splitAuthAddress (auth_address);
|
||||||
}
|
}
|
||||||
this->port = port;
|
this->port = port;
|
||||||
this->running = 0;
|
this->running = 0;
|
||||||
@ -169,25 +159,21 @@ void Pandora::listen (UDP_Server *server) {
|
|||||||
servaddr.sin_port = htons (server->getPort ());
|
servaddr.sin_port = htons (server->getPort ());
|
||||||
bind(sockfd, (struct sockaddr *)&servaddr, sizeof (servaddr));
|
bind(sockfd, (struct sockaddr *)&servaddr, sizeof (servaddr));
|
||||||
|
|
||||||
/* Get authorised address */
|
|
||||||
auth_addr = server->getAuthAddress ();
|
|
||||||
|
|
||||||
while (server->isRunning () == 1) {
|
while (server->isRunning () == 1) {
|
||||||
len = sizeof(cliaddr);
|
len = sizeof(cliaddr);
|
||||||
n = recvfrom(sockfd, mesg, MAX_PACKET_SIZE, 0, (struct sockaddr *)&cliaddr, &len);
|
n = recvfrom(sockfd, mesg, MAX_PACKET_SIZE, 0, (struct sockaddr *)&cliaddr, &len);
|
||||||
if (n == SOCKET_ERROR) {
|
if (n == SOCKET_ERROR) {
|
||||||
pandoraLog ("UDP Server: Error %d", WSAGetLastError ());
|
pandoraLog ("UDP Server: Error %d", WSAGetLastError ());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Authenticate client */
|
/* Authenticate client */
|
||||||
if (auth_addr != INADDR_ANY && auth_addr != cliaddr.sin_addr.s_addr) {
|
if (server->isAddressAuth (cliaddr.sin_addr.s_addr)) {
|
||||||
|
mesg[n] = 0;
|
||||||
|
process_command (server->getService (), mesg);
|
||||||
|
} else {
|
||||||
pandoraLog ("UDP Server: Unauthorised access from %s", inet_ntoa (cliaddr.sin_addr));
|
pandoraLog ("UDP Server: Unauthorised access from %s", inet_ntoa (cliaddr.sin_addr));
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mesg[n] = 0;
|
|
||||||
process_command (server->getService (), mesg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WSACleanup ();
|
WSACleanup ();
|
||||||
@ -263,3 +249,35 @@ int Pandora::process_command (Pandora_Windows_Service *service, char *command) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UDP_Server::splitAuthAddress (string all_address) {
|
||||||
|
this->auth_address.clear();
|
||||||
|
size_t comma_pos;
|
||||||
|
string single_ip;
|
||||||
|
do {
|
||||||
|
single_ip.clear();
|
||||||
|
/*Splits ips with comma*/
|
||||||
|
comma_pos = all_address.find_first_of (',', 0);
|
||||||
|
if (comma_pos != string::npos){
|
||||||
|
single_ip = all_address.substr (0, comma_pos);
|
||||||
|
} else {
|
||||||
|
single_ip = all_address;
|
||||||
|
}
|
||||||
|
unsigned long single_ip_num = inet_addr (single_ip.c_str ());
|
||||||
|
if (single_ip_num != INADDR_NONE) {
|
||||||
|
this->auth_address.push_back (single_ip_num);
|
||||||
|
} else {
|
||||||
|
pandoraDebug ("Invalid UDP Server Auth Address: %s", single_ip.c_str ());
|
||||||
|
}
|
||||||
|
all_address = all_address.substr (comma_pos + 1, all_address.length ());
|
||||||
|
} while (comma_pos != string::npos);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UDP_Server::isAddressAuth (unsigned long ip){
|
||||||
|
for (this->it=(this->auth_address).begin(); this->it != (this->auth_address).end(); ++it) {
|
||||||
|
if (*it == ip || *it == INADDR_ANY) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -37,20 +37,22 @@ namespace Pandora {
|
|||||||
UDP_Server (Pandora_Windows_Service *service, string address, string auth_address, unsigned int port);
|
UDP_Server (Pandora_Windows_Service *service, string address, string auth_address, unsigned int port);
|
||||||
virtual ~UDP_Server ();
|
virtual ~UDP_Server ();
|
||||||
unsigned long getAddress ();
|
unsigned long getAddress ();
|
||||||
unsigned long getAuthAddress ();
|
|
||||||
unsigned long getPort ();
|
unsigned long getPort ();
|
||||||
Pandora_Windows_Service *getService ();
|
Pandora_Windows_Service *getService ();
|
||||||
unsigned char isRunning ();
|
unsigned char isRunning ();
|
||||||
|
bool isAddressAuth (unsigned long ip);
|
||||||
|
|
||||||
int start ();
|
int start ();
|
||||||
int stop ();
|
int stop ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned long address;
|
unsigned long address;
|
||||||
unsigned long auth_address;
|
list<unsigned long> auth_address;
|
||||||
|
list<unsigned long>::iterator it;
|
||||||
unsigned long port;
|
unsigned long port;
|
||||||
unsigned char running;
|
unsigned char running;
|
||||||
Pandora_Windows_Service *service;
|
Pandora_Windows_Service *service;
|
||||||
|
void splitAuthAddress (string all_address);
|
||||||
};
|
};
|
||||||
|
|
||||||
void listen (UDP_Server *server);
|
void listen (UDP_Server *server);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user