Пример #1
0
int cliLoggingHostCmd(CliMode mode, int argc, char **argv) {
	char *data = (char *) pktout + sizeof(RcpPkt);
	*data = '\0'; // cleaning the return string
	
	
	// no command
	if (strcmp("no", argv[0]) == 0) {
		// extract address
		uint32_t ip;
		if (atoip(argv[3], &ip)) {
			strcpy(data, "Error: invalid IP address");
			return RCPERR;
		}
		
		RcpSyslogHost *found = host_find(ip);
		if (found == NULL)
			return 0;
		found->valid = 0;
	}
	else {
		// extract address and port
		uint32_t ip;
		if (atoip(argv[2], &ip)) {
			strcpy(data, "Error: invalid IP address");
			return RCPERR;
		}
		
		uint16_t port = 0;
		if (argc == 5) {
			int p = atoi(argv[4]);
			port = (uint16_t) p;
		}
		
		RcpSyslogHost *found = host_find(ip);
		if (found != NULL) {
			// modify existing host
			found->port = port;
			return 0;
		}
		
		// set a new host
		RcpSyslogHost *newhost = host_find_empty();
		if (newhost == NULL) {
			strcpy(data, "Error: cannot configure host, limit reached\n");
			return RCPERR;
		}
		memset(newhost, 0, sizeof(RcpSyslogHost));
		newhost->ip = ip;
		newhost->port = port;
		newhost->valid = 1;
	}

	return 0;
}
void
script_done(struct relayd *env, struct ctl_script *scr)
{
	struct host		*host;

	if ((host = host_find(env, scr->host)) == NULL)
		fatalx("hce_dispatch_parent: invalid host id");

	if (scr->retval < 0)
		host->up = HOST_UNKNOWN;
	else if (scr->retval == 0)
		host->up = HOST_DOWN;
	else
		host->up = HOST_UP;
	host->flags |= F_CHECK_DONE;

	hce_notify_done(host, host->up == HOST_UP ?
	    HCE_SCRIPT_OK : HCE_SCRIPT_FAIL);
}
Пример #3
0
// no ip host command
int cliNoIpHostNameCmd(CliMode mode, int argc, char **argv) {
	ASSERT(strlen(argv[1]) <= CLI_MAX_HOSTNAME);
	char *data = (char *) pktout + sizeof(RcpPkt);
	*data = '\0'; // cleaning the return string

	// find the host
	RcpIpHost *found = host_find(argv[3]);

	// remove the host
	if (found != NULL) {
		found->valid = 0;

		// change in system files needed
		update_hosts_file = 1;	
	}

	// send dns update message to dns proxy
	trigger_dns_update();
 	return 0;
}
Пример #4
0
// ip host command
int cliIpHostNameCmd(CliMode mode, int argc, char **argv) {
	ASSERT(strlen(argv[1]) <= CLI_MAX_HOSTNAME);
	char *data = (char *) pktout + sizeof(RcpPkt);
	*data = '\0'; // cleaning the return string

	// extract the ip address
	uint32_t addr;
	if (atoip(argv[3], &addr)) {
		sprintf(data, "Error: invalid IP address\n");
		return RCPERR;
	}
	
	// find the host
	RcpIpHost *found = host_find(argv[2]);
	
	// update or add a new host
	if (found) {
		// update the ip address
		found->ip = addr;
	}
	else {
		// add a new host
		RcpIpHost *newhost = host_find_empty();
		memset(newhost, 0, sizeof(RcpIpHost));
		strcpy(newhost->name, argv[2]);
		newhost->ip = addr;
		newhost->valid = 1;
	}
	
	// change in system files needed
	update_hosts_file = 1;	

	// send dns update message to dns proxy
	trigger_dns_update();
	return 0;
}