/* grabs configuration information from main config file */ int xpddefault_grab_config_info(char *config_file) { char *input = NULL; mmapfile *thefile = NULL; /* open the config file for reading */ if((thefile = mmap_fopen(config_file)) == NULL) { logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not open main config file '%s' for reading performance variables!\n", config_file); return ERROR; } /* read in all lines from the config file */ while(1) { /* free memory */ my_free(input); /* read the next line */ if((input = mmap_fgets_multiline(thefile)) == NULL) break; /* skip blank lines and comments */ if(input[0] == '#' || input[0] == '\x0') continue; strip(input); xpddefault_grab_config_directives(input); } /* free memory and close the file */ my_free(input); mmap_fclose(thefile); return OK; }
/* 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; }
/* grab configuration information */ int xsddefault_grab_config_info(char *config_file) { char *input = NULL; mmapfile *thefile; #ifdef NSCGI char *input2 = NULL; mmapfile *thefile2; char *temp_buffer; #else nagios_macros *mac; #endif /*** CORE PASSES IN MAIN CONFIG FILE, CGIS PASS IN CGI CONFIG FILE! ***/ /* open the config file for reading */ if((thefile = mmap_fopen(config_file)) == NULL) return ERROR; /* read in all lines from the main config file */ while(1) { /* free memory */ my_free(input); /* read the next line */ if((input = mmap_fgets_multiline(thefile)) == NULL) break; strip(input); /* skip blank lines and comments */ if(input[0] == '#' || input[0] == '\x0') continue; #ifdef NSCGI /* CGI needs to find and read contents of main config file, since it was passed the name of the CGI config file */ if(strstr(input, "main_config_file") == input) { temp_buffer = strtok(input, "="); temp_buffer = strtok(NULL, "\n"); if(temp_buffer == NULL) continue; if((thefile2 = mmap_fopen(temp_buffer)) == NULL) continue; /* read in all lines from the main config file */ while(1) { /* free memory */ my_free(input2); /* read the next line */ if((input2 = mmap_fgets_multiline(thefile2)) == NULL) break; strip(input2); /* skip blank lines and comments */ if(input2[0] == '#' || input2[0] == '\x0') continue; xsddefault_grab_config_directives(input2); } /* free memory and close the file */ my_free(input2); mmap_fclose(thefile2); } #endif #ifdef NSCORE /* core reads variables directly from the main config file */ xsddefault_grab_config_directives(input); #endif } /* free memory and close the file */ my_free(input); mmap_fclose(thefile); /* initialize locations if necessary */ if(xsddefault_status_log == NULL) xsddefault_status_log = (char *)strdup(DEFAULT_STATUS_FILE); if(xsddefault_temp_file == NULL) xsddefault_temp_file = (char *)strdup(DEFAULT_TEMP_FILE); /* make sure we have what we need */ if(xsddefault_status_log == NULL) return ERROR; if(xsddefault_temp_file == NULL) return ERROR; #ifdef NSCORE mac = get_global_macros(); /* save the status file macro */ my_free(mac->x[MACRO_STATUSDATAFILE]); if((mac->x[MACRO_STATUSDATAFILE] = (char *)strdup(xsddefault_status_log))) strip(mac->x[MACRO_STATUSDATAFILE]); #endif return OK; }