/*****************************************************************************
*
* CGIAUTH.C - Authorization utilities for Nagios CGIs
*
* Copyright (c) 1999-2005 Ethan Galstad (nagios@nagios.org)
* Last Modified: 03-23-2005
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*****************************************************************************/
#include "../include/common.h"
#include "../include/config.h"
#include "../include/objects.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
extern char main_config_file[MAX_FILENAME_LENGTH];
extern hostgroup *hostgroup_list;
extern servicegroup *servicegroup_list;
extern int use_authentication;
extern int hosts_have_been_read;
extern int hostgroups_have_been_read;
extern int contactgroups_have_been_read;
extern int contacts_have_been_read;
extern int services_have_been_read;
extern int serviceescalations_have_been_read;
extern int hostescalations_have_been_read;
/* get current authentication information */
int get_authentication_information(authdata *authinfo){
mmapfile *thefile;
char *input=NULL;
char *temp_ptr;
int needed_options;
if(authinfo==NULL)
return ERROR;
/* make sure we have read in all the configuration information we need for the authentication routines... */
needed_options=0;
if(hosts_have_been_read==FALSE)
needed_options|=READ_HOSTS;
if(hostgroups_have_been_read==FALSE)
needed_options|=READ_HOSTGROUPS;
if(contactgroups_have_been_read==FALSE)
needed_options|=READ_CONTACTGROUPS;
if(contacts_have_been_read==FALSE)
needed_options|=READ_CONTACTS;
if(services_have_been_read==FALSE)
needed_options|=READ_SERVICES;
if(serviceescalations_have_been_read==FALSE)
needed_options|=READ_SERVICEESCALATIONS;
if(hostescalations_have_been_read==FALSE)
needed_options|=READ_HOSTESCALATIONS;
if(needed_options>0)
read_all_object_configuration_data(main_config_file,needed_options);
/* 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;
/* grab username from the environment... */
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;
=1= |