Exemplo n.º 1
0
/* tests whether or not a contact is an escalated contact for a particular service */
int is_escalated_contact_for_service(service *svc, contact *cntct)
{
    serviceescalation *temp_serviceescalation = NULL;
    contactsmember *temp_contactsmember = NULL;
    contactgroupsmember *temp_contactgroupsmember = NULL;
    contactgroup *temp_contactgroup = NULL;
    objectlist *list;

    /* search all the service escalations */
    for (list = svc->escalation_list; list; list = list->next) {
        temp_serviceescalation = (serviceescalation *)list->object_ptr;

        /* search all contacts of this service escalation */
        for (temp_contactsmember = temp_serviceescalation->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
            if (temp_contactsmember->contact_ptr == cntct)
                return TRUE;
        }

        /* search all contactgroups of this service escalation */
        for (temp_contactgroupsmember = temp_serviceescalation->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) {
            temp_contactgroup = temp_contactgroupsmember->group_ptr;
            if (is_contact_member_of_contactgroup(temp_contactgroup, cntct))
                return TRUE;
        }
    }

    return FALSE;
}
Exemplo n.º 2
0
/* tests whether or not a contact is an escalated contact for a particular host */
int is_escalated_contact_for_host(host *hst, contact *cntct)
{
	contactsmember *temp_contactsmember = NULL;
	hostescalation *temp_hostescalation = NULL;
	contactgroupsmember *temp_contactgroupsmember = NULL;
	contactgroup *temp_contactgroup = NULL;
	objectlist *list;

	/* search all host escalations */
	for (list = hst->escalation_list; list; list = list->next) {
		temp_hostescalation = (hostescalation *)list->object_ptr;

		/* search all contacts of this host escalation */
		for (temp_contactsmember = temp_hostescalation->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
			if (temp_contactsmember->contact_ptr == cntct)
				return TRUE;
		}

		/* search all contactgroups of this host escalation */
		for (temp_contactgroupsmember = temp_hostescalation->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) {
			temp_contactgroup = temp_contactgroupsmember->group_ptr;
			if (is_contact_member_of_contactgroup(temp_contactgroup, cntct))
				return TRUE;
		}
	}

	return FALSE;
}
Exemplo n.º 3
0
int is_contact_for_service(service *svc, contact *cntct)
{
    contactsmember *temp_contactsmember = NULL;
    contactgroupsmember *temp_contactgroupsmember = NULL;
    contactgroup *temp_contactgroup = NULL;

    if (svc == NULL || cntct == NULL)
        return FALSE;

    /* search all individual contacts of this service */
    for (temp_contactsmember = svc->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
        if (temp_contactsmember->contact_ptr == cntct)
            return TRUE;
    }

    /* search all contactgroups of this service */
    for (temp_contactgroupsmember = svc->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) {
        temp_contactgroup = temp_contactgroupsmember->group_ptr;
        if (is_contact_member_of_contactgroup(temp_contactgroup, cntct))
            return TRUE;

    }

    return FALSE;
}
Exemplo n.º 4
0
int is_contact_for_host(host *hst, contact *cntct)
{
	contactsmember *temp_contactsmember = NULL;
	contactgroupsmember *temp_contactgroupsmember = NULL;
	contactgroup *temp_contactgroup = NULL;

	if (hst == NULL || cntct == NULL) {
		return FALSE;
	}

	/* search all individual contacts of this host */
	for (temp_contactsmember = hst->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
		if (temp_contactsmember->contact_ptr == cntct)
			return TRUE;
	}

	/* search all contactgroups of this host */
	for (temp_contactgroupsmember = hst->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) {
		temp_contactgroup = temp_contactgroupsmember->group_ptr;
		if (is_contact_member_of_contactgroup(temp_contactgroup, cntct))
			return TRUE;
	}

	return FALSE;
}
Exemplo n.º 5
0
/* get current authentication information */
int get_authentication_information(authdata *authinfo) {
	mmapfile *thefile;
	char *input = NULL;
	char *temp_ptr = NULL;
	contact *temp_contact = NULL;
	contactgroup *temp_contactgroup = NULL;

	if(authinfo == NULL)
		return ERROR;

	/* initial values... */
	authinfo->authorized_for_all_hosts = FALSE;
	authinfo->authorized_for_all_host_commands = FALSE;
	authinfo->authorized_for_all_services = FALSE;
	authinfo->authorized_for_all_service_commands = FALSE;
	authinfo->authorized_for_system_information = FALSE;
	authinfo->authorized_for_system_commands = FALSE;
	authinfo->authorized_for_configuration_information = FALSE;
	authinfo->authorized_for_read_only = FALSE;
	authinfo->locale_lang_path="";
	authinfo->locale_lang_user_lang="";

	/* grab username from the environment... */
	if(use_ssl_authentication) {
		/* patch by Pawl Zuzelski - 7/22/08 */
		temp_ptr = getenv("SSL_CLIENT_S_DN_CN");
		}
	else {
		temp_ptr = getenv("REMOTE_USER");
		}
	if(temp_ptr == NULL) {
		authinfo->username = "";
		authinfo->authenticated = FALSE;
		}
	else {
		authinfo->username = (char *)malloc(strlen(temp_ptr) + 1);
		if(authinfo->username == NULL)
			authinfo->username = "";
		else
			strcpy(authinfo->username, temp_ptr);
		if(!strcmp(authinfo->username, ""))
			authinfo->authenticated = FALSE;
		else
			authinfo->authenticated = TRUE;
		}

	/* read in authorization override vars from config file... */
	if((thefile = mmap_fopen(get_cgi_config_location())) != NULL) {

		while(1) {

			/* free memory */
			free(input);

			/* read the next line */
			if((input = mmap_fgets_multiline(thefile)) == NULL)
				break;

			strip(input);

			/* we don't have a username yet, so fake the authentication if we find a default username defined */
			if(!strcmp(authinfo->username, "") && strstr(input, "default_user_name=") == input) {
				temp_ptr = strtok(input, "=");
				temp_ptr = strtok(NULL, ",");
				authinfo->username = (char *)malloc(strlen(temp_ptr) + 1);
				if(authinfo->username == NULL)
					authinfo->username = "";
				else
					strcpy(authinfo->username, temp_ptr);
				if(!strcmp(authinfo->username, ""))
					authinfo->authenticated = FALSE;
				else
					authinfo->authenticated = TRUE;
				}

			else if(strstr(input, "authorized_for_all_hosts=") == input) {
				temp_ptr = strtok(input, "=");
				while((temp_ptr = strtok(NULL, ","))) {
					if(!strcmp(temp_ptr, authinfo->username) || !strcmp(temp_ptr, "*"))
						authinfo->authorized_for_all_hosts = TRUE;
					}
				}
			else if(strstr(input, "authorized_for_all_services=") == input) {
				temp_ptr = strtok(input, "=");
				while((temp_ptr = strtok(NULL, ","))) {
					if(!strcmp(temp_ptr, authinfo->username) || !strcmp(temp_ptr, "*"))
						authinfo->authorized_for_all_services = TRUE;
					}
				}
			else if(strstr(input, "authorized_for_system_information=") == input) {
				temp_ptr = strtok(input, "=");
				while((temp_ptr = strtok(NULL, ","))) {
					if(!strcmp(temp_ptr, authinfo->username) || !strcmp(temp_ptr, "*"))
						authinfo->authorized_for_system_information = TRUE;
					}
				}
			else if(strstr(input, "authorized_for_configuration_information=") == input) {
				temp_ptr = strtok(input, "=");
				while((temp_ptr = strtok(NULL, ","))) {
					if(!strcmp(temp_ptr, authinfo->username) || !strcmp(temp_ptr, "*"))
						authinfo->authorized_for_configuration_information = TRUE;
					}
				}
			else if(strstr(input, "authorized_for_all_host_commands=") == input) {
				temp_ptr = strtok(input, "=");
				while((temp_ptr = strtok(NULL, ","))) {
					if(!strcmp(temp_ptr, authinfo->username) || !strcmp(temp_ptr, "*"))
						authinfo->authorized_for_all_host_commands = TRUE;
					}
				}
			else if(strstr(input, "authorized_for_all_service_commands=") == input) {
				temp_ptr = strtok(input, "=");
				while((temp_ptr = strtok(NULL, ","))) {
					if(!strcmp(temp_ptr, authinfo->username) || !strcmp(temp_ptr, "*"))
						authinfo->authorized_for_all_service_commands = TRUE;
					}
				}
			else if(strstr(input, "authorized_for_system_commands=") == input) {
				temp_ptr = strtok(input, "=");
				while((temp_ptr = strtok(NULL, ","))) {
					if(!strcmp(temp_ptr, authinfo->username) || !strcmp(temp_ptr, "*"))
						authinfo->authorized_for_system_commands = TRUE;
					}
				}
			else if(strstr(input, "authorized_for_read_only=") == input) {
				temp_ptr = strtok(input, "=");
				while((temp_ptr = strtok(NULL, ","))) {
					if(!strcmp(temp_ptr, authinfo->username) || !strcmp(temp_ptr, "*"))
						authinfo->authorized_for_read_only = TRUE;
					}
				}
			else if((temp_contact = find_contact(authinfo->username)) != NULL) {
				if(strstr(input, "authorized_contactgroup_for_all_hosts=") == input) {
					temp_ptr = strtok(input, "=");
					while((temp_ptr = strtok(NULL, ","))) {
						temp_contactgroup = find_contactgroup(temp_ptr);
						if(is_contact_member_of_contactgroup(temp_contactgroup, temp_contact))
							authinfo->authorized_for_all_hosts = TRUE;
						}
					}
				else if(strstr(input, "authorized_contactgroup_for_all_services=") == input) {
					temp_ptr = strtok(input, "=");
					while((temp_ptr = strtok(NULL, ","))) {
						temp_contactgroup = find_contactgroup(temp_ptr);
						if(is_contact_member_of_contactgroup(temp_contactgroup, temp_contact))
							authinfo->authorized_for_all_services = TRUE;
						}
					}
				else if(strstr(input, "authorized_contactgroup_for_system_information=") == input) {
					temp_ptr = strtok(input, "=");
					while((temp_ptr = strtok(NULL, ","))) {
						temp_contactgroup = find_contactgroup(temp_ptr);
						if(is_contact_member_of_contactgroup(temp_contactgroup, temp_contact))
							authinfo->authorized_for_system_information = TRUE;
						}
					}
				else if(strstr(input, "authorized_contactgroup_for_configuration_information=") == input) {
					temp_ptr = strtok(input, "=");
					while((temp_ptr = strtok(NULL, ","))) {
						temp_contactgroup = find_contactgroup(temp_ptr);
						if(is_contact_member_of_contactgroup(temp_contactgroup, temp_contact))
							authinfo->authorized_for_configuration_information = TRUE;
						}
					}
				else if(strstr(input, "authorized_contactgroup_for_all_host_commands=") == input) {
					temp_ptr = strtok(input, "=");
					while((temp_ptr = strtok(NULL, ","))) {
						temp_contactgroup = find_contactgroup(temp_ptr);
						if(is_contact_member_of_contactgroup(temp_contactgroup, temp_contact))
							authinfo->authorized_for_all_host_commands = TRUE;
						}
					}
				else if(strstr(input, "authorized_contactgroup_for_all_service_commands=") == input) {
					temp_ptr = strtok(input, "=");
					while((temp_ptr = strtok(NULL, ","))) {
						temp_contactgroup = find_contactgroup(temp_ptr);
						if(is_contact_member_of_contactgroup(temp_contactgroup, temp_contact))
							authinfo->authorized_for_all_service_commands = TRUE;
						}
					}
				else if(strstr(input, "authorized_contactgroup_for_system_commands=") == input) {
					temp_ptr = strtok(input, "=");
					while((temp_ptr = strtok(NULL, ","))) {
						temp_contactgroup = find_contactgroup(temp_ptr);
						if(is_contact_member_of_contactgroup(temp_contactgroup, temp_contact))
							authinfo->authorized_for_system_commands = TRUE;
						}
					}
				else if(strstr(input, "authorized_contactgroup_for_read_only=") == input) {
					temp_ptr = strtok(input, "=");
					while((temp_ptr = strtok(NULL, ","))) {
						temp_contactgroup = find_contactgroup(temp_ptr);
						if(is_contact_member_of_contactgroup(temp_contactgroup, temp_contact))
							authinfo->authorized_for_read_only = TRUE;
						}
					}
				}else if(strstr(input, "locale_lang_path=") == input) {
					temp_ptr = strtok(input, "=");
					temp_ptr = strtok(NULL, "=");
					if(temp_ptr)
					{
						authinfo->locale_lang_path = (char*) malloc(strlen(temp_ptr)+1);
						strcpy(authinfo->locale_lang_path, temp_ptr);
					}else{
						authinfo->locale_lang_path="";
					}
				}else if(strstr(input, "locale_lang_user="******",");
					lang += strlen(authinfo->username) + 1;
					
					authinfo->locale_lang_user_lang = (char*) malloc(strlen(lang) + 1);
					strcpy(authinfo->locale_lang_user_lang, lang);
				}
			}

		/* free memory and close the file */
		free(input);
		mmap_fclose(thefile);
		}
	setlocale(LC_ALL,authinfo->locale_lang_user_lang);
	bindtextdomain("nagios-plugins",authinfo->locale_lang_path);
	
	//setlocale(LC_ALL,"zh_CN");
	//bindtextdomain("nagios-plugins","/usr/local/nagios/share/locale");
	textdomain("nagios-plugins");
	
	if(authinfo->authenticated == TRUE)
		return OK;
	else
		return ERROR;
		
	}