From d4d6938fb214067de49b72263a4f0b75e8e93586 Mon Sep 17 00:00:00 2001
From: Stephen Gran <steve@lobefin.net>
Date: Mon, 20 Sep 2010 09:59:52 +0100
Subject: [PATCH] Clean up loads of compiler warnings
 Signed-off-by: Stephen Gran <steve@lobefin.net>

---
 base/broker.c      |    4 ++--
 base/checks.c      |    1 -
 base/nagiostats.c  |    3 +--
 base/utils.c       |    9 ++-------
 cgi/cgiauth.c      |    1 -
 cgi/cmd.c          |   23 +++++++++++++++++++++--
 cgi/extcmd_list.c  |    1 -
 cgi/status.c       |    1 -
 common/macros.c    |   12 ++++++------
 common/objects.c   |    3 ---
 xdata/xsddefault.c |    1 -
 11 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/base/broker.c b/base/broker.c
index 8c0bdd2..b90c79b 100644
--- a/base/broker.c
+++ b/base/broker.c
@@ -184,10 +184,10 @@ int broker_event_handler(int type, int flags, int attr, int eventhandler_type, v
 	int return_code=OK;
 
 	if(!(event_broker_options & BROKER_EVENT_HANDLERS))
-		return;
+		return return_code;
 	
 	if(data==NULL)
-		return;
+		return return_code;
 
 	/* get command name/args */
 	if(cmd!=NULL){
diff --git a/base/checks.c b/base/checks.c
index 26bf5c2..f29d01f 100644
--- a/base/checks.c
+++ b/base/checks.c
@@ -134,7 +134,6 @@ int reap_check_results(void){
 	check_result *queued_check_result=NULL;
 	service *temp_service=NULL;
 	host *temp_host=NULL;
-	char *temp_buffer=NULL;
 	time_t current_time=0L;
 	time_t reaper_start_time=0L;
 	int reaped_checks=0;
diff --git a/base/nagiostats.c b/base/nagiostats.c
index bf7e608..e144267 100644
--- a/base/nagiostats.c
+++ b/base/nagiostats.c
@@ -206,6 +206,7 @@ int read_config_file(void);
 int read_status_file(void);
 void strip(char *);
 void get_time_breakdown(unsigned long,int *,int *,int *,int *);
+int read_nagiostats_file(void);
 
 
 int main(int argc, char **argv){
@@ -1380,12 +1381,10 @@ int read_status_file(void){
 int read_nagiostats_file(void){
 	char temp_buffer[MAX_INPUT_BUFFER];
 	FILE *fp=NULL;
-	int data_type=STATUS_NO_DATA;
 	char *var=NULL;
 	char *val=NULL;
 	char *temp_ptr=NULL;
 	time_t current_time;
-	unsigned long time_difference=0L;
 
 	time(&current_time);
 
diff --git a/base/utils.c b/base/utils.c
index a2fd575..429178e 100644
--- a/base/utils.c
+++ b/base/utils.c
@@ -2369,7 +2369,6 @@ int process_check_result_queue(char *dirname){
 /* reads check result(s) from a file */
 int process_check_result_file(char *fname){
 	mmapfile *thefile=NULL;
-	char *temp_buffer=NULL;
 	char *input=NULL;
 	char *var=NULL;
 	char *val=NULL;
@@ -2831,7 +2830,7 @@ int parse_check_output(char *buf, char **short_output, char **long_output, char
 	/* save long output */
 	if(long_output && (db1.buf && strcmp(db1.buf,""))){
 
-		if(escape_newlines==FALSE)
+		if(escape_newlines_please==FALSE)
 			*long_output=(char *)strdup(db1.buf);
 
 		else{
@@ -3291,11 +3290,7 @@ int compare_hashdata(const char *val1a, const char *val1b, const char *val2a, co
 
 /* renames a file - works across filesystems (Mike Wiacek) */
 int my_rename(char *source, char *dest){
-	char buffer[MAX_INPUT_BUFFER]={0};
 	int rename_result=0;
-	int source_fd=-1;
-	int dest_fd=-1;
-	int bytes_read=0;
 
 
 	/* make sure we have something */
@@ -4492,7 +4487,7 @@ int query_update_api(void){
 	asprintf(&buf,"%sConnection: close\r\n",buf);
 	asprintf(&buf,"%sHost: %s\r\n",buf,api_server);
 	asprintf(&buf,"%sContent-Type: application/x-www-form-urlencoded\r\n",buf);
-	asprintf(&buf,"%sContent-Length: %d\r\n",buf,strlen(api_query));
+	asprintf(&buf,"%sContent-Length: %zd\r\n",buf,strlen(api_query));
 	asprintf(&buf,"%s\r\n",buf);
 	asprintf(&buf,"%s%s\r\n",buf,api_query);
 
diff --git a/cgi/cgiauth.c b/cgi/cgiauth.c
index 4f55502..8059e44 100644
--- a/cgi/cgiauth.c
+++ b/cgi/cgiauth.c
@@ -44,7 +44,6 @@ int get_authentication_information(authdata *authinfo){
 	mmapfile *thefile;
 	char *input=NULL;
 	char *temp_ptr;
-	int needed_options;
 
 	if(authinfo==NULL)
 		return ERROR;
diff --git a/cgi/cmd.c b/cgi/cmd.c
index df5fc72..2a37a08 100644
--- a/cgi/cmd.c
+++ b/cgi/cmd.c
@@ -1891,6 +1891,26 @@ void commit_command_data(int cmd){
 	return;
         }
 
+static int cmd_submit(int id){
+	char cmd[MAX_EXTERNAL_COMMAND_LENGTH];
+	const char *command;
+	int len;
+
+	command = extcmd_get_name(id);
+	/*
+	 * We disallow sending 'CHANGE' commands from the cgi's
+	 * until we do proper session handling to prevent cross-site
+	 * request forgery
+	 */
+	if (!command || (strlen(command) > 6 && !memcmp("CHANGE", command, 6)))
+		return ERROR;
+
+	len = snprintf(cmd, sizeof(cmd) - 1, "[%lu] %s;", time(NULL), command);
+	if (len < 0)
+		return ERROR;
+
+	return write_command_to_file(cmd);
+	}
 
 __attribute__((format(printf, 2, 3)))
 static int cmd_submitf(int id, const char *fmt, ...){
@@ -1925,7 +1945,6 @@ static int cmd_submitf(int id, const char *fmt, ...){
 
 /* commits a command for processing */
 int commit_command(int cmd){
-	char command_buffer[MAX_INPUT_BUFFER];
 	time_t current_time;
 	time_t scheduled_time;
 	time_t notification_time;
@@ -1980,7 +1999,7 @@ int commit_command(int cmd){
 	case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
 	case CMD_START_OBSESSING_OVER_HOST_CHECKS:
 	case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
-		result = cmd_submitf(cmd,"");
+		result = cmd_submit(cmd);
 		break;
 
 		/** simple host commands **/
diff --git a/cgi/extcmd_list.c b/cgi/extcmd_list.c
index 52b2373..f7dc7b7 100644
--- a/cgi/extcmd_list.c
+++ b/cgi/extcmd_list.c
@@ -191,7 +191,6 @@ struct nagios_extcmd in_core_commands[] =
 #ifndef ARRAY_SIZE
 # define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
 #endif
-static int extcmd_entries, extcmd_slots;
 
 const char *extcmd_get_name(int id)
 {
diff --git a/cgi/status.c b/cgi/status.c
index a4aaf87..cac8cd0 100644
--- a/cgi/status.c
+++ b/cgi/status.c
@@ -992,7 +992,6 @@ void show_host_status_totals(void){
 	hoststatus *temp_hoststatus;
 	host *temp_host;
 	servicestatus *temp_servicestatus;
-	service *temp_service;
 	int count_host;
 
 
diff --git a/common/macros.c b/common/macros.c
index da6dd2d..6cddd00 100644
--- a/common/macros.c
+++ b/common/macros.c
@@ -145,7 +145,7 @@ int process_macros(char *input_buffer, char **output_buffer, int options){
 			strcat(*output_buffer,temp_buffer);
 
 #ifdef NSCORE
-			log_debug_info(DEBUGL_MACROS,2,"  Not currently in macro.  Running output (%d): '%s'\n",strlen(*output_buffer),*output_buffer);
+			log_debug_info(DEBUGL_MACROS,2,"  Not currently in macro.  Running output (%zd): '%s'\n",strlen(*output_buffer),*output_buffer);
 #endif
 
 			in_macro=TRUE;
@@ -180,7 +180,7 @@ int process_macros(char *input_buffer, char **output_buffer, int options){
 			else if(!strcmp(temp_buffer,"")){
 
 #ifdef NSCORE
-				log_debug_info(DEBUGL_MACROS,2,"  Escaped $.  Running output (%d): '%s'\n",strlen(*output_buffer),*output_buffer);
+				log_debug_info(DEBUGL_MACROS,2,"  Escaped $.  Running output (%zd): '%s'\n",strlen(*output_buffer),*output_buffer);
 #endif
 
 				*output_buffer=(char *)realloc(*output_buffer,strlen(*output_buffer)+2);
@@ -191,7 +191,7 @@ int process_macros(char *input_buffer, char **output_buffer, int options){
 			else{
 
 #ifdef NSCORE
-				log_debug_info(DEBUGL_MACROS,2,"  Non-macro.  Running output (%d): '%s'\n",strlen(*output_buffer),*output_buffer);
+				log_debug_info(DEBUGL_MACROS,2,"  Non-macro.  Running output (%zd): '%s'\n",strlen(*output_buffer),*output_buffer);
 #endif
 
 				/* add the plain text to the end of the already processed buffer */
@@ -234,7 +234,7 @@ int process_macros(char *input_buffer, char **output_buffer, int options){
 						strcat(*output_buffer,cleaned_macro);
 
 #ifdef NSCORE
-						log_debug_info(DEBUGL_MACROS,2,"  Cleaned macro.  Running output (%d): '%s'\n",strlen(*output_buffer),*output_buffer);
+						log_debug_info(DEBUGL_MACROS,2,"  Cleaned macro.  Running output (%zd): '%s'\n",strlen(*output_buffer),*output_buffer);
 #endif
 						}
 					}
@@ -247,7 +247,7 @@ int process_macros(char *input_buffer, char **output_buffer, int options){
 						strcat(*output_buffer,selected_macro);
 
 #ifdef NSCORE
-						log_debug_info(DEBUGL_MACROS,2,"  Uncleaned macro.  Running output (%d): '%s'\n",strlen(*output_buffer),*output_buffer);
+						log_debug_info(DEBUGL_MACROS,2,"  Uncleaned macro.  Running output (%zd): '%s'\n",strlen(*output_buffer),*output_buffer);
 #endif
 						}
 					}
@@ -257,7 +257,7 @@ int process_macros(char *input_buffer, char **output_buffer, int options){
 					my_free(selected_macro);
 
 #ifdef NSCORE
-				log_debug_info(DEBUGL_MACROS,2,"  Just finished macro.  Running output (%d): '%s'\n",strlen(*output_buffer),*output_buffer);
+				log_debug_info(DEBUGL_MACROS,2,"  Just finished macro.  Running output (%zd): '%s'\n",strlen(*output_buffer),*output_buffer);
 #endif
 				}
 
diff --git a/common/objects.c b/common/objects.c
index c139aaa..5b01305 100644
--- a/common/objects.c
+++ b/common/objects.c
@@ -180,7 +180,6 @@ int skiplist_compare_host(void *a, void *b){
 int skiplist_compare_service(void *a, void *b){
 	service *oa=NULL;
 	service *ob=NULL;
-	int result=0;
 
 	oa=(service *)a;
 	ob=(service *)b;
@@ -325,7 +324,6 @@ int skiplist_compare_hostescalation(void *a, void *b){
 int skiplist_compare_serviceescalation(void *a, void *b){
 	serviceescalation *oa=NULL;
 	serviceescalation *ob=NULL;
-	int result=0;
 
 	oa=(serviceescalation *)a;
 	ob=(serviceescalation *)b;
@@ -362,7 +360,6 @@ int skiplist_compare_hostdependency(void *a, void *b){
 int skiplist_compare_servicedependency(void *a, void *b){
 	servicedependency *oa=NULL;
 	servicedependency *ob=NULL;
-	int result=0;
 
 	oa=(servicedependency *)a;
 	ob=(servicedependency *)b;
diff --git a/xdata/xsddefault.c b/xdata/xsddefault.c
index 6ffe70f..bcc183d 100644
--- a/xdata/xsddefault.c
+++ b/xdata/xsddefault.c
@@ -338,7 +338,6 @@ int xsddefault_save_status_data(void){
 	FILE *fp=NULL;
 	int used_external_command_buffer_slots=0;
 	int high_external_command_buffer_slots=0;
-	void *ptr=NULL;
 	int result=OK;
 
 	log_debug_info(DEBUGL_FUNCTIONS,0,"save_status_data()\n");
-- 
1.7.1

