From 08af5bb31222c39739b8ec216b403756fb250924 Mon Sep 17 00:00:00 2001
From: Tilghman Lesher <tilghman@meg.abyt.es>
Date: Fri, 12 Sep 2008 23:30:03 +0000
Subject: [PATCH] Create a new config file status, CONFIG_STATUS_FILEINVALID
 for differentiating when a file is invalid from when a file is missing.  This
 is most important when we have two configuration files.  Consider the
 following example:

Old system:
sip.conf     users.conf     Old result               New result
========     ==========     ==========               ==========
Missing      Missing        SIP doesn't load         SIP doesn't load
Missing      OK             SIP doesn't load         SIP doesn't load
Missing      Invalid        SIP doesn't load         SIP doesn't load
OK           Missing        SIP loads                SIP loads
OK           OK             SIP loads                SIP loads
OK           Invalid        SIP loads incompletely   SIP doesn't load
Invalid      Missing        SIP doesn't load         SIP doesn't load
Invalid      OK             SIP doesn't load         SIP doesn't load
Invalid      Invalid        SIP doesn't load         SIP doesn't load

So in the case when users.conf doesn't load because there's a typo that
disrupts the syntax, we may only partially load users, instead of failing with
an error, which may cause some calls not to get processed.  Worse yet, the old
system would do this with no indication that anything was even wrong.

(closes issue #10690)
 Reported by: dtyoo
 Patches:
       20080716__bug10690.diff.txt uploaded by Corydon76 (license 14)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@142992 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 apps/app_alarmreceiver.c  |  3 +++
 apps/app_amd.c            |  6 +++++-
 apps/app_directory.c      |  8 +++++++-
 apps/app_festival.c       |  7 +++++++
 apps/app_followme.c       |  6 +++++-
 apps/app_meetme.c         | 19 +++++++++++++++----
 apps/app_minivm.c         |  6 +++++-
 apps/app_osplookup.c      |  6 +++++-
 apps/app_playback.c       |  8 ++++++--
 apps/app_queue.c          |  9 ++++++++-
 apps/app_rpt.c            |  6 +++---
 apps/app_voicemail.c      | 32 +++++++++++++++++++++++---------
 channels/chan_agent.c     | 17 +++++++++++++++--
 channels/chan_alsa.c      |  6 +++++-
 channels/chan_console.c   |  3 +++
 channels/chan_dahdi.c     | 21 ++++++++++++++++++---
 channels/chan_gtalk.c     |  6 +++++-
 channels/chan_h323.c      | 21 ++++++++++++++++++---
 channels/chan_iax2.c      | 15 +++++++++++++--
 channels/chan_jingle.c    |  3 ++-
 channels/chan_mgcp.c      |  6 +++++-
 channels/chan_oss.c       |  3 +++
 channels/chan_phone.c     |  5 ++++-
 channels/chan_sip.c       | 26 ++++++++++++++++++++++----
 channels/chan_skinny.c    |  5 ++++-
 channels/chan_unistim.c   |  3 +++
 codecs/codec_adpcm.c      |  4 +---
 codecs/codec_alaw.c       |  4 +---
 codecs/codec_dahdi.c      |  4 +---
 codecs/codec_g722.c       |  4 +---
 codecs/codec_g726.c       |  4 +---
 codecs/codec_gsm.c        |  4 +---
 codecs/codec_lpc10.c      |  4 +---
 codecs/codec_speex.c      |  4 +---
 codecs/codec_ulaw.c       |  4 +---
 funcs/func_config.c       |  4 ++--
 funcs/func_odbc.c         |  4 ++--
 include/asterisk/config.h |  2 ++
 main/asterisk.c           |  7 +++++--
 main/cdr.c                |  3 +++
 main/config.c             | 17 +++++++++++------
 main/dnsmgr.c             |  4 +++-
 main/dsp.c                |  3 +++
 main/enum.c               |  3 +++
 main/features.c           |  2 +-
 main/http.c               |  3 ++-
 main/loader.c             |  3 ++-
 main/manager.c            |  3 ++-
 main/rtp.c                |  4 +++-
 main/udptl.c              |  4 +++-
 res/res_adsi.c            |  6 +++---
 res/res_config_ldap.c     |  3 +--
 res/res_config_pgsql.c    |  6 ++++--
 res/res_config_sqlite.c   |  2 +-
 res/res_http_post.c       |  3 ++-
 res/res_indications.c     |  5 +++--
 res/res_jabber.c          |  2 +-
 res/res_musiconhold.c     |  3 ++-
 res/res_odbc.c            |  2 +-
 res/res_phoneprov.c       |  6 +++---
 res/res_smdi.c            |  2 +-
 res/res_snmp.c            |  2 +-
 62 files changed, 291 insertions(+), 109 deletions(-)

diff --git a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c
index 37d8177429..db76bbdb77 100644
--- a/apps/app_alarmreceiver.c
+++ b/apps/app_alarmreceiver.c
@@ -639,6 +639,9 @@ static int load_config(void)
 	if (!cfg) {
 		ast_verb(4, "AlarmReceiver: No config file\n");
 		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", ALMRCV_CONFIG);
+		return 0;
 	} else {
 		p = ast_variable_retrieve(cfg, "general", "eventcmd");
 		if (p) {
diff --git a/apps/app_amd.c b/apps/app_amd.c
index 131cd01fd2..81298f4009 100644
--- a/apps/app_amd.c
+++ b/apps/app_amd.c
@@ -376,8 +376,12 @@ static int load_config(int reload)
 	if (!(cfg = ast_config_load("amd.conf", config_flags))) {
 		ast_log(LOG_ERROR, "Configuration file amd.conf missing.\n");
 		return -1;
-	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file amd.conf is in an invalid format.  Aborting.\n");
+		return -1;
+	}
 
 	cat = ast_category_browse(cfg, NULL);
 
diff --git a/apps/app_directory.c b/apps/app_directory.c
index 59a82a2387..69523ec65e 100644
--- a/apps/app_directory.c
+++ b/apps/app_directory.c
@@ -362,6 +362,9 @@ static struct ast_config *realtime_directory(char *context)
 		/* Loading config failed. */
 		ast_log(LOG_WARNING, "Loading config failed.\n");
 		return NULL;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", VOICEMAIL_CONFIG);
+		return NULL;
 	}
 
 	/* Get realtime entries, categorized by their mailbox number
@@ -670,7 +673,10 @@ static int directory_exec(struct ast_channel *chan, void *data)
 		return -1;
 	}
 
-	ucfg = ast_config_load("users.conf", config_flags);
+	if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file users.conf is in an invalid format.  Aborting.\n");
+		ucfg = NULL;
+	}
 
 	dirintro = ast_variable_retrieve(cfg, args.vmcontext, "directoryintro");
 	if (ast_strlen_zero(dirintro))
diff --git a/apps/app_festival.c b/apps/app_festival.c
index d9659ebef8..4a929a3e51 100644
--- a/apps/app_festival.c
+++ b/apps/app_festival.c
@@ -300,7 +300,11 @@ static int festival_exec(struct ast_channel *chan, void *vdata)
 	if (!cfg) {
 		ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG);
 		return -1;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file " FESTIVAL_CONFIG " is in an invalid format.  Aborting.\n");
+		return -1;
 	}
+
 	if (!(host = ast_variable_retrieve(cfg, "general", "host"))) {
 		host = "localhost";
 	}
@@ -517,6 +521,9 @@ static int load_module(void)
 	if (!cfg) {
 		ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG);
 		return AST_MODULE_LOAD_DECLINE;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file " FESTIVAL_CONFIG " is in an invalid format.  Aborting.\n");
+		return AST_MODULE_LOAD_DECLINE;
 	}
 	ast_config_destroy(cfg);
 	return ast_register_application(app, festival_exec, synopsis, descrip);
diff --git a/apps/app_followme.c b/apps/app_followme.c
index 0e23acbff5..7a4b1fdc3d 100644
--- a/apps/app_followme.c
+++ b/apps/app_followme.c
@@ -293,8 +293,12 @@ static int reload_followme(int reload)
 	if (!(cfg = ast_config_load("followme.conf", config_flags))) {
 		ast_log(LOG_WARNING, "No follow me config file (followme.conf), so no follow me\n");
 		return 0;
-	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file followme.conf is in an invalid format.  Aborting.\n");
+		return 0;
+	}
 
 	AST_RWLIST_WRLOCK(&followmes);
 
diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 823b74efc1..9ca81eb081 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -2921,6 +2921,9 @@ static struct ast_conference *find_conf(struct ast_channel *chan, char *confno,
 			if (!cfg) {
 				ast_log(LOG_WARNING, "No %s file :(\n", CONFIG_FILE_NAME);
 				return NULL;
+			} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+				ast_log(LOG_ERROR, "Config file " CONFIG_FILE_NAME " is in an invalid format.  Aborting.\n");
+				return NULL;
 			}
 			for (var = ast_variable_browse(cfg, "rooms"); var; var = var->next) {
 				if (strcasecmp(var->name, "conf"))
@@ -3083,7 +3086,7 @@ static int conf_exec(struct ast_channel *chan, void *data)
 			/* We only need to load the config file for static and empty_no_pin (otherwise we don't care) */
 			if ((empty_no_pin) || (!dynamic)) {
 				cfg = ast_config_load(CONFIG_FILE_NAME, config_flags);
-				if (cfg) {
+				if (cfg && cfg != CONFIG_STATUS_FILEINVALID) {
 					var = ast_variable_browse(cfg, "rooms");
 					while (var) {
 						if (!strcasecmp(var->name, "conf")) {
@@ -3729,8 +3732,12 @@ static void load_config_meetme(void)
 	struct ast_flags config_flags = { 0 };
 	const char *val;
 
-	if (!(cfg = ast_config_load(CONFIG_FILE_NAME, config_flags)))
+	if (!(cfg = ast_config_load(CONFIG_FILE_NAME, config_flags))) {
+		return;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file " CONFIG_FILE_NAME " is in an invalid format.  Aborting.\n");
 		return;
+	}
 
 	audio_buffers = DEFAULT_AUDIO_BUFFERS;
 
@@ -5558,10 +5565,14 @@ static int sla_load_config(int reload)
 		ast_cond_init(&sla.cond, NULL);
 	}
 
-	if (!(cfg = ast_config_load(SLA_CONFIG_FILE, config_flags)))
+	if (!(cfg = ast_config_load(SLA_CONFIG_FILE, config_flags))) {
 		return 0; /* Treat no config as normal */
-	else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file " SLA_CONFIG_FILE " is in an invalid format.  Aborting.\n");
+		return 0;
+	}
 
 	if ((val = ast_variable_retrieve(cfg, "general", "attemptcallerid")))
 		sla.attempt_callerid = ast_true(val);
diff --git a/apps/app_minivm.c b/apps/app_minivm.c
index 4aed1528e4..c151068df3 100644
--- a/apps/app_minivm.c
+++ b/apps/app_minivm.c
@@ -2363,8 +2363,12 @@ static int load_config(int reload)
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
 	cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file " VOICEMAIL_CONFIG " is in an invalid format.  Aborting.\n");
+		return 0;
+	}
 
 	ast_mutex_lock(&minivmlock);
 
diff --git a/apps/app_osplookup.c b/apps/app_osplookup.c
index 93968ccee8..34ddc05a8a 100644
--- a/apps/app_osplookup.c
+++ b/apps/app_osplookup.c
@@ -1776,8 +1776,12 @@ static int osp_load(int reload)
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	int error = OSPC_ERR_NO_ERROR;
 
-	if ((cfg = ast_config_load(OSP_CONFIG_FILE, config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+	if ((cfg = ast_config_load(OSP_CONFIG_FILE, config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
 		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file " OSP_CONFIG_FILE " is in an invalid format.  Aborting.\n");
+		return 0;
+	}
 
 	if (cfg) {
 		if (reload)
diff --git a/apps/app_playback.c b/apps/app_playback.c
index 356d325b47..b905a93357 100644
--- a/apps/app_playback.c
+++ b/apps/app_playback.c
@@ -461,8 +461,12 @@ static int reload(void)
 	struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
 	struct ast_config *newcfg;
 
-	if ((newcfg = ast_config_load("say.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+	if ((newcfg = ast_config_load("say.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
 		return 0;
+	} else if (newcfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file say.conf is in an invalid format.  Aborting.\n");
+		return 0;
+	}
 
 	if (say_cfg) {
 		ast_config_destroy(say_cfg);
@@ -506,7 +510,7 @@ static int load_module(void)
 	struct ast_flags config_flags = { 0 };
 
 	say_cfg = ast_config_load("say.conf", config_flags);
-	if (say_cfg) {
+	if (say_cfg && say_cfg != CONFIG_STATUS_FILEINVALID) {
 		for (v = ast_variable_browse(say_cfg, "general"); v ; v = v->next) {
     			if (ast_extension_match(v->name, "mode")) {
 				say_init_mode(v->value);
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 3f9c9c6253..4f6d160ea6 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -5135,6 +5135,9 @@ static int reload_queue_rules(int reload)
 	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		ast_log(LOG_NOTICE, "queuerules.conf has not changed since it was last loaded. Not taking any action.\n");
 		return AST_MODULE_LOAD_SUCCESS;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file queuerules.conf is in an invalid format.  Aborting.\n");
+		return AST_MODULE_LOAD_SUCCESS;
 	} else {
 		AST_LIST_LOCK(&rule_lists);
 		while ((rl_iter = AST_LIST_REMOVE_HEAD(&rule_lists, list))) {
@@ -5196,8 +5199,12 @@ static int reload_queues(int reload)
 	if (!(cfg = ast_config_load("queues.conf", config_flags))) {
 		ast_log(LOG_NOTICE, "No call queueing config file (queues.conf), so no call queues\n");
 		return 0;
-	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
+		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file queues.conf is in an invalid format.  Aborting.\n");
 		return 0;
+	}
 	ao2_lock(queues);
 	use_weight=0;
 	/* Mark all queues as dead for the moment */
diff --git a/apps/app_rpt.c b/apps/app_rpt.c
index be52773ac9..b3a26dd7b8 100644
--- a/apps/app_rpt.c
+++ b/apps/app_rpt.c
@@ -2008,7 +2008,7 @@ struct ast_variable *vp;
 		ourcfg = ast_config_load(myrpt->p.extnodefile);
 #endif
 		/* if file not there, just bail */
-		if (!ourcfg)
+		if (!ourcfg || ourcfg == CONFIG_STATUS_FILEINVALID)
 		{
 			ast_mutex_unlock(&nodelookuplock);
 			return(NULL);
@@ -2234,7 +2234,7 @@ static char *cs_keywords[] = {"rptena","rptdis","apena","apdis","lnkena","lnkdis
 #else
 	cfg = ast_config_load("rpt.conf");
 #endif
-	if (!cfg) {
+	if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_mutex_unlock(&rpt_vars[n].lock);
  		ast_log(LOG_NOTICE, "Unable to open radio repeater configuration rpt.conf.  Radio Repeater disabled.\n");
 		pthread_exit(NULL);
@@ -12923,7 +12923,7 @@ char *this,*val;
 	rpt_vars[n].cfg = ast_config_load("rpt.conf");
 #endif
 	cfg = rpt_vars[n].cfg;
-	if (!cfg) {
+	if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_NOTICE, "Unable to open radio repeater configuration rpt.conf.  Radio Repeater disabled.\n");
 		pthread_exit(NULL);
 	}
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 66df949689..90e0795b72 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -1157,7 +1157,7 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
 		return;
 
 	/* check voicemail.conf */
-	if ((cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags))) {
+	if ((cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) {
 		while ((category = ast_category_browse(cfg, category))) {
 			if (!strcasecmp(category, vmu->context)) {
 				if (!(tmp = ast_variable_retrieve(cfg, category, vmu->mailbox))) {
@@ -1187,7 +1187,7 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
 	var = NULL;
 	/* check users.conf and update the password stored for the mailbox*/
 	/* if no vmsecret entry exists create one. */
-	if ((cfg = ast_config_load("users.conf", config_flags))) {
+	if ((cfg = ast_config_load("users.conf", config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) {
 		ast_debug(4, "we are looking for %s\n", vmu->mailbox);
 		while ((category = ast_category_browse(cfg, category))) {
 			ast_debug(4, "users.conf: %s\n", category);
@@ -3181,7 +3181,7 @@ static int store_file(char *dir, char *mailboxuser, char *mailboxcontext, int ms
 			res = -1;
 			break;
 		}
-		if (cfg) {
+		if (cfg && cfg != CONFIG_STATUS_FILEINVALID) {
 			if (!(idata.context = ast_variable_retrieve(cfg, "message", "context"))) {
 				idata.context = "";
 			}
@@ -5756,7 +5756,7 @@ static int vm_forwardoptions(struct ast_channel *chan, struct ast_vm_user *vmu,
 	strncat(textfile, ".txt", sizeof(textfile) - strlen(textfile) - 1);
 	strncat(backup, "-bak", sizeof(backup) - strlen(backup) - 1);
 
-	if ((msg_cfg = ast_config_load(textfile, config_flags)) && (duration_str = ast_variable_retrieve(msg_cfg, "message", "duration"))) {
+	if ((msg_cfg = ast_config_load(textfile, config_flags)) && msg_cfg != CONFIG_STATUS_FILEINVALID && (duration_str = ast_variable_retrieve(msg_cfg, "message", "duration"))) {
 		*duration = atoi(duration_str);
 	} else {
 		*duration = 0;
@@ -6456,7 +6456,7 @@ static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struc
 	snprintf(filename, sizeof(filename), "%s.txt", vms->fn);
 	RETRIEVE(vms->curdir, vms->curmsg, vmu->mailbox, vmu->context);
 	msg_cfg = ast_config_load(filename, config_flags);
-	if (!msg_cfg) {
+	if (!msg_cfg || msg_cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_WARNING, "No message attribute file?!! (%s)\n", filename);
 		return 0;
 	}
@@ -9954,13 +9954,27 @@ static int load_config(int reload)
 	ast_unload_realtime("voicemail_data");
 
 	if ((cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
-		if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+		if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
 			return 0;
+		} else if (ucfg == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "Config file users.conf is in an invalid format.  Avoiding.\n");
+			ucfg = NULL;
+		}
 		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-		cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
+		if ((cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags)) == CONFIG_STATUS_FILEINVALID) {
+			ast_config_destroy(ucfg);
+			ast_log(LOG_ERROR, "Config file " VOICEMAIL_CONFIG " is in an invalid format.  Aborting.\n");
+			return 0;
+		}
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file " VOICEMAIL_CONFIG " is in an invalid format.  Aborting.\n");
+		return 0;
 	} else {
 		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-		ucfg = ast_config_load("users.conf", config_flags);
+		if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "Config file users.conf is in an invalid format.  Avoiding.\n");
+			ucfg = NULL;
+		}
 	}
 #ifdef IMAP_STORAGE
 	ast_copy_string(imapparentfolder, "\0", sizeof(imapparentfolder));
@@ -10772,7 +10786,7 @@ static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, s
 	RETRIEVE(vms->curdir, vms->curmsg, vmu->mailbox, vmu->context);
 	msg_cfg = ast_config_load(filename, config_flags);
 	DISPOSE(vms->curdir, vms->curmsg);
-	if (!msg_cfg) {
+	if (!msg_cfg || msg_cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(AST_LOG_WARNING, "No message attribute file?!! (%s)\n", filename);
 		return 0;
 	}
diff --git a/channels/chan_agent.c b/channels/chan_agent.c
index 5f5afbd43d..83dbd38e46 100644
--- a/channels/chan_agent.c
+++ b/channels/chan_agent.c
@@ -1117,8 +1117,21 @@ static int read_agent_config(int reload)
 	if (!cfg) {
 		ast_log(LOG_NOTICE, "No agent configuration found -- agent support disabled\n");
 		return 0;
-	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		return -1;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "%s contains a parsing error.  Aborting\n", config);
+		return 0;
+	}
+	if ((ucfg = ast_config_load("users.conf", config_flags))) {
+		if (ucfg == CONFIG_STATUS_FILEUNCHANGED) {
+			ucfg = NULL;
+		} else if (ucfg == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "users.conf contains a parsing error.  Aborting\n");
+			return 0;
+		}
+	}
+
 	AST_LIST_LOCK(&agents);
 	AST_LIST_TRAVERSE(&agents, p, list) {
 		p->dead = 1;
@@ -1208,7 +1221,7 @@ static int read_agent_config(int reload)
 		}
 		v = v->next;
 	}
-	if ((ucfg = ast_config_load("users.conf", config_flags)) && ucfg != CONFIG_STATUS_FILEUNCHANGED) {
+	if (ucfg) {
 		genhasagent = ast_true(ast_variable_retrieve(ucfg, "general", "hasagent"));
 		catname = ast_category_browse(ucfg, NULL);
 		while(catname) {
diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c
index 9a6f7287c7..66fecd5647 100644
--- a/channels/chan_alsa.c
+++ b/channels/chan_alsa.c
@@ -857,8 +857,12 @@ static int load_module(void)
 
 	strcpy(mohinterpret, "default");
 
-	if (!(cfg = ast_config_load(config, config_flags)))
+	if (!(cfg = ast_config_load(config, config_flags))) {
 		return AST_MODULE_LOAD_DECLINE;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "%s is in an invalid format.  Aborting.\n", config);
+		return AST_MODULE_LOAD_DECLINE;
+	}
 
 	v = ast_variable_browse(cfg, "general");
 	for (; v; v = v->next) {
diff --git a/channels/chan_console.c b/channels/chan_console.c
index 92777f5ea0..3511e0bacb 100644
--- a/channels/chan_console.c
+++ b/channels/chan_console.c
@@ -1400,6 +1400,9 @@ static int load_config(int reload)
 	if (!(cfg = ast_config_load(config_file, config_flags))) {
 		ast_log(LOG_NOTICE, "Unable to open configuration file %s!\n", config_file);
 		return -1;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_NOTICE, "Config file %s has an invalid format\n", config_file);
+		return -1;
 	}
 	
 	ao2_callback(pvts, OBJ_NODATA, pvt_mark_destroy_cb, NULL);
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 5a9e1a510d..25e76b5af5 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -14567,13 +14567,28 @@ static int setup_dahdi(int reload)
 		return 0;
 	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		ucfg = ast_config_load("users.conf", config_flags);
-		if (ucfg == CONFIG_STATUS_FILEUNCHANGED)
+		if (ucfg == CONFIG_STATUS_FILEUNCHANGED) {
 			return 0;
+		} else if (ucfg == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "File users.conf cannot be parsed.  Aborting.\n");
+			return 0;
+		}
 		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-		cfg = ast_config_load(config, config_flags);
+		if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "File %s cannot be parsed.  Aborting.\n", config);
+			ast_config_destroy(ucfg);
+			return 0;
+		}
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "File %s cannot be parsed.  Aborting.\n", config);
+		return 0;
 	} else {
 		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-		ucfg = ast_config_load("users.conf", config_flags);
+		if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "File users.conf cannot be parsed.  Aborting.\n");
+			ast_config_destroy(cfg);
+			return 0;
+		}
 	}
 
 	/* It's a little silly to lock it, but we mind as well just to be sure */
diff --git a/channels/chan_gtalk.c b/channels/chan_gtalk.c
index 76b4f9ad11..4a11b56a82 100644
--- a/channels/chan_gtalk.c
+++ b/channels/chan_gtalk.c
@@ -1869,8 +1869,12 @@ static int gtalk_load_config(void)
 	struct ast_flags config_flags = { 0 };
 
 	cfg = ast_config_load(GOOGLE_CONFIG, config_flags);
-	if (!cfg)
+	if (!cfg) {
 		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", GOOGLE_CONFIG);
+		return 0;
+	}
 
 	/* Copy the default jb config over global_jbconf */
 	memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
diff --git a/channels/chan_h323.c b/channels/chan_h323.c
index fc0c7f3c0e..36f8cd5eb8 100644
--- a/channels/chan_h323.c
+++ b/channels/chan_h323.c
@@ -2816,13 +2816,28 @@ static int reload_config(int is_reload)
 		return 1;
 	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		ucfg = ast_config_load("users.conf", config_flags);
-		if (ucfg == CONFIG_STATUS_FILEUNCHANGED)
+		if (ucfg == CONFIG_STATUS_FILEUNCHANGED) {
 			return 0;
+		} else if (ucfg == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "Config file users.conf is in an invalid format.  Aborting.\n");
+			return 0;
+		}
 		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-		cfg = ast_config_load(config, config_flags);
+		if ((cfg = ast_config_load(config, config_flags))) {
+			ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
+			ast_config_destroy(ucfg);
+			return 0;
+		}
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
+		return 0;
 	} else {
 		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-		ucfg = ast_config_load("users.conf", config_flags);
+		if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "Config file users.conf is in an invalid format.  Aborting.\n");
+			ast_config_destroy(cfg);
+			return 0;
+		}
 	}
 
 	if (is_reload) {
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 31d9ccf2eb..32ebe341be 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -11010,10 +11010,21 @@ static int set_config(char *config_file, int reload)
 			return 0;
 		/* Otherwise we need to reread both files */
 		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-		cfg = ast_config_load(config_file, config_flags);
+		if ((cfg = ast_config_load(config_file, config_flags)) == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config_file);
+			ast_config_destroy(ucfg);
+			return 0;
+		}
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config_file);
+		return 0;
 	} else { /* iax.conf changed, gotta reread users.conf, too */
 		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-		ucfg = ast_config_load("users.conf", config_flags);
+		if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "Config file users.conf is in an invalid format.  Aborting.\n");
+			ast_config_destroy(cfg);
+			return 0;
+		}
 	}
 
 	if (reload) {
diff --git a/channels/chan_jingle.c b/channels/chan_jingle.c
index 6284618872..d239fd717f 100644
--- a/channels/chan_jingle.c
+++ b/channels/chan_jingle.c
@@ -1736,8 +1736,9 @@ static int jingle_load_config(void)
 	struct ast_flags config_flags = { 0 };
 
 	cfg = ast_config_load(JINGLE_CONFIG, config_flags);
-	if (!cfg)
+	if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
 		return 0;
+	}
 
 	/* Copy the default jb config over global_jbconf */
 	memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index a5c54d4b98..644e7b787f 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -4120,8 +4120,12 @@ static int reload_config(int reload)
 	if (!cfg) {
 		ast_log(LOG_NOTICE, "Unable to load config %s, MGCP disabled\n", config);
 		return 0;
-	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
+		return 0;
+	}
 
 	memset(&bindaddr, 0, sizeof(bindaddr));
 	dtmfmode = 0;
diff --git a/channels/chan_oss.c b/channels/chan_oss.c
index b3c29c0315..125fa156d4 100644
--- a/channels/chan_oss.c
+++ b/channels/chan_oss.c
@@ -1434,6 +1434,9 @@ static int load_module(void)
 	if (!(cfg = ast_config_load(config, config_flags))) {
 		ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
 		return AST_MODULE_LOAD_DECLINE;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
+		return AST_MODULE_LOAD_DECLINE;
 	}
 
 	do {
diff --git a/channels/chan_phone.c b/channels/chan_phone.c
index 5ac54694dc..d6030bbf13 100644
--- a/channels/chan_phone.c
+++ b/channels/chan_phone.c
@@ -1346,7 +1346,10 @@ static int load_module(void)
 	int txgain = DEFAULT_GAIN, rxgain = DEFAULT_GAIN; /* default gain 1.0 */
 	struct ast_flags config_flags = { 0 };
 
-	cfg = ast_config_load(config, config_flags);
+	if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
+		return AST_MODULE_LOAD_DECLINE;
+	}
 
 	/* We *must* have a config file otherwise stop immediately */
 	if (!cfg) {
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 865b98f634..ea1a0e3272 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -21220,14 +21220,29 @@ static int reload_config(enum channelreloadreason reason)
 		return -1;
 	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		ucfg = ast_config_load("users.conf", config_flags);
-		if (ucfg == CONFIG_STATUS_FILEUNCHANGED)
+		if (ucfg == CONFIG_STATUS_FILEUNCHANGED) {
 			return 1;
+		} else if (ucfg == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "Contents of users.conf are invalid and cannot be parsed\n");
+			return 1;
+		}
 		/* Must reread both files, because one changed */
 		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-		cfg = ast_config_load(config, config_flags);
+		if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed\n", config);
+			ast_config_destroy(ucfg);
+			return 1;
+		}
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed\n", config);
+		return 1;
 	} else {
 		ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-		ucfg = ast_config_load("users.conf", config_flags);
+		if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEINVALID) {
+			ast_log(LOG_ERROR, "Contents of users.conf are invalid and cannot be parsed\n");
+			ast_config_destroy(cfg);
+			return 1;
+		}
 	}
 
 	/* Initialize tcp sockets */
@@ -21996,7 +22011,10 @@ static int reload_config(enum channelreloadreason reason)
 	/* Load the list of manual NOTIFY types to support */
 	if (notify_types)
 		ast_config_destroy(notify_types);
-	notify_types = ast_config_load(notify_config, config_flags);
+	if ((notify_types = ast_config_load(notify_config, config_flags)) == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed.\n", notify_config);
+		notify_types = NULL;
+	}
 
 	/* Done, tell the manager */
 	manager_event(EVENT_FLAG_SYSTEM, "ChannelReload", "ChannelType: SIP\r\nReloadReason: %s\r\nRegistry_Count: %d\r\nPeer_Count: %d\r\n", channelreloadreason2txt(reason), registry_count, peer_count);
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index 9ab38521d3..b25d492b92 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -6210,7 +6210,10 @@ static int reload_config(void)
 		ast_log(LOG_WARNING, "Unable to get hostname, Skinny disabled\n");
 		return 0;
 	}
-	cfg = ast_config_load(config, config_flags);
+	if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
+		return 0;
+	}
 
 	/* We *must* have a config file otherwise stop immediately */
 	if (!cfg) {
diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c
index a605c6be7c..48a41fc7ab 100644
--- a/channels/chan_unistim.c
+++ b/channels/chan_unistim.c
@@ -5304,6 +5304,9 @@ static int reload_config(void)
 	if (!cfg) {
 		ast_log(LOG_ERROR, "Unable to load config %s\n", config);
 		return -1;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
+		return -1;
 	}
 	
 	/* Copy the default jb config over global_jbconf */
diff --git a/codecs/codec_adpcm.c b/codecs/codec_adpcm.c
index 5cdf541765..20901151bb 100644
--- a/codecs/codec_adpcm.c
+++ b/codecs/codec_adpcm.c
@@ -345,9 +345,7 @@ static int parse_config(int reload)
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
 	struct ast_variable *var;
-	if (cfg == NULL)
-		return 0;
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 		return 0;
 	for (var = ast_variable_browse(cfg, "plc"); var ; var = var->next) {
 		if (!strcasecmp(var->name, "genericplc")) {
diff --git a/codecs/codec_alaw.c b/codecs/codec_alaw.c
index a261dedb7a..04d4048b84 100644
--- a/codecs/codec_alaw.c
+++ b/codecs/codec_alaw.c
@@ -128,9 +128,7 @@ static int parse_config(int reload)
 	struct ast_variable *var;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
-	if (cfg == NULL)
-		return 0;
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 		return 0;
 	for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
 		if (!strcasecmp(var->name, "genericplc")) {
diff --git a/codecs/codec_dahdi.c b/codecs/codec_dahdi.c
index 4c6ee32694..47fabc7c03 100644
--- a/codecs/codec_dahdi.c
+++ b/codecs/codec_dahdi.c
@@ -351,9 +351,7 @@ static int parse_config(int reload)
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
 
-	if (cfg == NULL)
-		return 0;
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 		return 0;
 
 	for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
diff --git a/codecs/codec_g722.c b/codecs/codec_g722.c
index b221ab20fd..41e17807f4 100644
--- a/codecs/codec_g722.c
+++ b/codecs/codec_g722.c
@@ -244,9 +244,7 @@ static int parse_config(int reload)
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
 
-	if (cfg == NULL)
-		return 0;
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 		return 0;
 	for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
 		if (!strcasecmp(var->name, "genericplc")) {
diff --git a/codecs/codec_g726.c b/codecs/codec_g726.c
index 80e0e8ea98..38d461a1c3 100644
--- a/codecs/codec_g726.c
+++ b/codecs/codec_g726.c
@@ -890,9 +890,7 @@ static int parse_config(int reload)
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
 
-	if (cfg == NULL)
-		return 0;
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 		return 0;
 	for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
 		if (!strcasecmp(var->name, "genericplc")) {
diff --git a/codecs/codec_gsm.c b/codecs/codec_gsm.c
index defc1d8988..1664632a46 100644
--- a/codecs/codec_gsm.c
+++ b/codecs/codec_gsm.c
@@ -229,9 +229,7 @@ static int parse_config(int reload)
 	struct ast_variable *var;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
-	if (cfg == NULL)
-		return 0;
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED) 
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 		return 0;
 	for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
 	       if (!strcasecmp(var->name, "genericplc")) {
diff --git a/codecs/codec_lpc10.c b/codecs/codec_lpc10.c
index abea9d2043..9237f70fea 100644
--- a/codecs/codec_lpc10.c
+++ b/codecs/codec_lpc10.c
@@ -255,9 +255,7 @@ static int parse_config(int reload)
 	struct ast_variable *var;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
-	if (cfg == NULL)
-		return 0;
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 		return 0;
 	for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
 		if (!strcasecmp(var->name, "genericplc")) {
diff --git a/codecs/codec_speex.c b/codecs/codec_speex.c
index 734491c75d..961aaa649d 100644
--- a/codecs/codec_speex.c
+++ b/codecs/codec_speex.c
@@ -375,9 +375,7 @@ static int parse_config(int reload)
 	int res;
 	float res_f;
 
-	if (cfg == NULL)
-		return 0;
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 		return 0;
 
 	for (var = ast_variable_browse(cfg, "speex"); var; var = var->next) {
diff --git a/codecs/codec_ulaw.c b/codecs/codec_ulaw.c
index d58abe9267..799b96357f 100644
--- a/codecs/codec_ulaw.c
+++ b/codecs/codec_ulaw.c
@@ -141,9 +141,7 @@ static int parse_config(int reload)
 	struct ast_variable *var;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 	struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
-	if (cfg == NULL)
-		return 0;
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 		return 0;
 	for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
 		if (!strcasecmp(var->name, "genericplc")) {
diff --git a/funcs/func_config.c b/funcs/func_config.c
index 6bed8a9b2b..5669f36559 100644
--- a/funcs/func_config.c
+++ b/funcs/func_config.c
@@ -82,7 +82,7 @@ static int config_function_read(struct ast_channel *chan, const char *cmd, char
 		return -1;
 	}
 
-	if (!(cfg = ast_config_load(args.filename, cfg_flags))) {
+	if (!(cfg = ast_config_load(args.filename, cfg_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
 		return -1;
 	}
 
@@ -107,7 +107,7 @@ static int config_function_read(struct ast_channel *chan, const char *cmd, char
 			strcpy(cur->filename, args.filename);
 
 			ast_clear_flag(&cfg_flags, CONFIG_FLAG_FILEUNCHANGED);
-			if (!(cfg = ast_config_load(args.filename, cfg_flags))) {
+			if (!(cfg = ast_config_load(args.filename, cfg_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
 				ast_free(cur);
 				AST_RWLIST_UNLOCK(&configs);
 				return -1;
diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c
index b6a17ffa21..24034bb0d7 100644
--- a/funcs/func_odbc.c
+++ b/funcs/func_odbc.c
@@ -812,7 +812,7 @@ static int load_module(void)
 	AST_RWLIST_WRLOCK(&queries);
 
 	cfg = ast_config_load(config, config_flags);
-	if (!cfg) {
+	if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_NOTICE, "Unable to load config for func_odbc: %s\n", config);
 		AST_RWLIST_UNLOCK(&queries);
 		return AST_MODULE_LOAD_DECLINE;
@@ -878,7 +878,7 @@ static int reload(void)
 	struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
 
 	cfg = ast_config_load(config, config_flags);
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 		return 0;
 
 	AST_RWLIST_WRLOCK(&queries);
diff --git a/include/asterisk/config.h b/include/asterisk/config.h
index a12d12bf62..8c9a1d3beb 100644
--- a/include/asterisk/config.h
+++ b/include/asterisk/config.h
@@ -45,7 +45,9 @@ enum {
 	CONFIG_FLAG_NOCACHE       = (1 << 2),
 };
 
+#define	CONFIG_STATUS_FILEMISSING	(void *)0
 #define	CONFIG_STATUS_FILEUNCHANGED	(void *)-1
+#define	CONFIG_STATUS_FILEINVALID	(void *)-2
 
 /*!
  * \brief Types used in ast_realtime_require_field
diff --git a/main/asterisk.c b/main/asterisk.c
index d8dc99b860..0aa9f9a3d9 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2596,7 +2596,7 @@ static void ast_readconfig(void)
 
 	if (ast_opt_override_config) {
 		cfg = ast_config_load2(ast_config_AST_CONFIG_FILE, "" /* core, can't reload */, config_flags);
-		if (!cfg)
+		if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
 			ast_log(LOG_WARNING, "Unable to open specified master config file '%s', using built-in defaults\n", ast_config_AST_CONFIG_FILE);
 	} else 
 		cfg = ast_config_load2(config, "" /* core, can't reload */, config_flags);
@@ -2619,7 +2619,7 @@ static void ast_readconfig(void)
 	ast_set_default_eid(&g_eid);
 
 	/* no asterisk.conf? no problem, use buildtime config! */
-	if (!cfg) {
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
 		return;
 	}
 
@@ -2869,6 +2869,9 @@ static void run_startup_commands(void)
 
 	if (!(cfg = ast_config_load2("cli.conf", "" /* core, can't reload */, cfg_flags)))
 		return;
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
+		return;
+	}
 
 	fd = open("/dev/null", O_RDWR);
 	if (fd < 0) {
diff --git a/main/cdr.c b/main/cdr.c
index b97736203d..cf9d1bc613 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -1388,6 +1388,9 @@ static int do_reload(int reload)
 
 	if ((config = ast_config_load2("cdr.conf", "cdr", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
 		return 0;
+	if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEUNCHANGED || config == CONFIG_STATUS_FILEINVALID) {
+		return 0;
+	}
 
 	ast_mutex_lock(&cdr_batch_lock);
 
diff --git a/main/config.c b/main/config.c
index 40b116a479..870aaed574 100644
--- a/main/config.c
+++ b/main/config.c
@@ -1015,13 +1015,17 @@ static int process_text_line(struct ast_config *cfg, struct ast_category **cat,
 
 		cur++;
 		c = cur;
-		while (*c && (*c > 32)) c++;
+		while (*c && (*c > 32)) {
+			c++;
+		}
+
 		if (*c) {
 			*c = '\0';
 			/* Find real argument */
 			c = ast_skip_blanks(c + 1);
-			if (!(*c))
+			if (!(*c)) {
 				c = NULL;
+			}
 		} else 
 			c = NULL;
 		if (!strcasecmp(cur, "include")) {
@@ -1390,7 +1394,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
 					char *buffer = ast_strip(process_buf);
 					if (!ast_strlen_zero(buffer)) {
 						if (process_text_line(cfg, &cat, buffer, lineno, fn, flags, comment_buffer, lline_buffer, suggested_include_file, &last_cat, &last_var, who_asked)) {
-							cfg = NULL;
+							cfg = CONFIG_STATUS_FILEINVALID;
 							break;
 						}
 					}
@@ -1428,15 +1432,16 @@ static struct ast_config *config_text_file_load(const char *database, const char
 		ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment - 1]);
 	}
 #ifdef AST_INCLUDE_GLOB
-					if (cfg == NULL || cfg == CONFIG_STATUS_FILEUNCHANGED)
+					if (cfg == NULL || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
 						break;
+					}
 				}
 				globfree(&globbuf);
 			}
 		}
 #endif
 
-	if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg->include_level == 1 && ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
+	if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID && cfg->include_level == 1 && ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
 		if (comment_buffer)
 			ast_free(comment_buffer);
 		if (lline_buffer)
@@ -2055,7 +2060,7 @@ struct ast_config *ast_config_load2(const char *filename, const char *who_asked,
 		return NULL;
 
 	result = ast_config_internal_load(filename, cfg, flags, "", who_asked);
-	if (!result || result == CONFIG_STATUS_FILEUNCHANGED)
+	if (!result || result == CONFIG_STATUS_FILEUNCHANGED || result == CONFIG_STATUS_FILEINVALID)
 		ast_config_destroy(cfg);
 
 	return result;
diff --git a/main/dnsmgr.c b/main/dnsmgr.c
index 2df778b45c..7ff7a4f5d7 100644
--- a/main/dnsmgr.c
+++ b/main/dnsmgr.c
@@ -372,8 +372,10 @@ static int do_reload(int loading)
 	int was_enabled;
 	int res = -1;
 
-	if ((config = ast_config_load2("dnsmgr.conf", "dnsmgr", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+	config = ast_config_load2("dnsmgr.conf", "dnsmgr", config_flags);
+	if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEUNCHANGED || config == CONFIG_STATUS_FILEINVALID) {
 		return 0;
+	}
 
 	/* ensure that no refresh cycles run while the reload is in progress */
 	ast_mutex_lock(&refresh_lock);
diff --git a/main/dsp.c b/main/dsp.c
index f3adcf0bef..e5db83cd55 100644
--- a/main/dsp.c
+++ b/main/dsp.c
@@ -1614,6 +1614,9 @@ static int _dsp_init(int reload)
 	struct ast_config *cfg;
 
 	cfg = ast_config_load2(CONFIG_FILE_NAME, "dsp", config_flags);
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
+		return 0;
+	}
 
 	if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED) {
 		const char *value;
diff --git a/main/enum.c b/main/enum.c
index 6f821c26d3..d10864c0bd 100644
--- a/main/enum.c
+++ b/main/enum.c
@@ -959,6 +959,9 @@ static int private_enum_init(int reload)
 
 	if ((cfg = ast_config_load2("enum.conf", "enum", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
 		return 0;
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
+		return 0;
+	}
 
 	/* Destroy existing list */
 	ast_mutex_lock(&enumlock);
diff --git a/main/features.c b/main/features.c
index c8ce6ccde0..275c006bd9 100644
--- a/main/features.c
+++ b/main/features.c
@@ -3143,7 +3143,7 @@ static int load_config(void)
 	atxfercallbackretries = DEFAULT_ATXFER_CALLBACK_RETRIES;
 
 	cfg = ast_config_load2("features.conf", "features", config_flags);
-	if (!cfg) {
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_WARNING,"Could not load features.conf\n");
 		return 0;
 	}
diff --git a/main/http.c b/main/http.c
index 7601158bb8..b1bb878f76 100644
--- a/main/http.c
+++ b/main/http.c
@@ -851,7 +851,8 @@ static int __ast_http_load(int reload)
 	struct http_uri_redirect *redirect;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-	if ((cfg = ast_config_load2("http.conf", "http", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
+	cfg = ast_config_load2("http.conf", "http", config_flags);
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
 		return 0;
 	}
 
diff --git a/main/loader.c b/main/loader.c
index 735459f040..e8a5662efe 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -787,7 +787,8 @@ int load_modules(unsigned int preload_only)
 		embedded_module_list.first = NULL;
 	}
 
-	if (!(cfg = ast_config_load2(AST_MODULE_CONFIG, "" /* core, can't reload */, config_flags))) {
+	cfg = ast_config_load2(AST_MODULE_CONFIG, "" /* core, can't reload */, config_flags);
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
 		goto done;
 	}
diff --git a/main/manager.c b/main/manager.c
index 4aa1be631f..7d57eb6738 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1132,7 +1132,8 @@ static int action_getconfig(struct mansession *s, const struct message *m)
 		astman_send_error(s, m, "Filename not specified");
 		return 0;
 	}
-	if (!(cfg = ast_config_load2(fn, "manager", config_flags))) {
+	cfg = ast_config_load2(fn, "manager", config_flags);
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
 		astman_send_error(s, m, "Config file not found");
 		return 0;
 	}
diff --git a/main/rtp.c b/main/rtp.c
index b4d7734d11..2f4bca429e 100644
--- a/main/rtp.c
+++ b/main/rtp.c
@@ -4694,8 +4694,10 @@ static int __ast_rtp_reload(int reload)
 	const char *s;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-	if ((cfg = ast_config_load2("rtp.conf", "rtp", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+	cfg = ast_config_load2("rtp.conf", "rtp", config_flags);
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
 		return 0;
+	}
 
 	rtpstart = 5000;
 	rtpend = 31000;
diff --git a/main/udptl.c b/main/udptl.c
index 6b14ec56f3..ad1c96d632 100644
--- a/main/udptl.c
+++ b/main/udptl.c
@@ -1223,8 +1223,10 @@ static void __ast_udptl_reload(int reload)
 	const char *s;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-	if ((cfg = ast_config_load2("udptl.conf", "udptl", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+	cfg = ast_config_load2("udptl.conf", "udptl", config_flags);
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
 		return;
+	}
 
 	udptlstart = 4500;
 	udptlend = 4999;
diff --git a/res/res_adsi.c b/res/res_adsi.c
index 385ad26171..4d2aaaa8f0 100644
--- a/res/res_adsi.c
+++ b/res/res_adsi.c
@@ -1021,10 +1021,10 @@ static void adsi_load(int reload)
 	char *name, *sname;
 	init_state();
 
-	if (!(conf = ast_config_load("adsi.conf", config_flags)))
-		return;
-	else if (conf == CONFIG_STATUS_FILEUNCHANGED)
+	conf = ast_config_load("adsi.conf", config_flags);
+	if (conf == CONFIG_STATUS_FILEMISSING || conf == CONFIG_STATUS_FILEUNCHANGED || conf == CONFIG_STATUS_FILEINVALID) {
 		return;
+	}
 	for (v = ast_variable_browse(conf, "intro"); v; v = v->next) {
 		if (!strcasecmp(v->name, "alignment"))
 			alignment = str2align(v->value);
diff --git a/res/res_config_ldap.c b/res/res_config_ldap.c
index 04066074d1..916ce8fe77 100644
--- a/res/res_config_ldap.c
+++ b/res/res_config_ldap.c
@@ -1391,8 +1391,7 @@ int parse_config(void)
 	char *category_name = NULL;
 
 	config = ast_config_load(RES_CONFIG_LDAP_CONF, config_flags);
-
-	if (!config) {
+	if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_WARNING, "Cannot load configuration %s\n", RES_CONFIG_LDAP_CONF);
 		return -1;
 	}
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index 214d9eeea6..c42e35e802 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -1131,10 +1131,12 @@ static int parse_config(int is_reload)
 	const char *s;
 	struct ast_flags config_flags = { is_reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-	if ((config = ast_config_load(RES_CONFIG_PGSQL_CONF, config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+	config = ast_config_load(RES_CONFIG_PGSQL_CONF, config_flags);
+	if (config == CONFIG_STATUS_FILEUNCHANGED) {
 		return 0;
+	}
 
-	if (!config) {
+	if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_WARNING, "Unable to load config %s\n", RES_CONFIG_PGSQL_CONF);
 		return 0;
 	}
diff --git a/res/res_config_sqlite.c b/res/res_config_sqlite.c
index 448fab32b6..05dc64d0a4 100644
--- a/res/res_config_sqlite.c
+++ b/res/res_config_sqlite.c
@@ -730,7 +730,7 @@ static int load_config(void)
 
 	config = ast_config_load(RES_CONFIG_SQLITE_CONF_FILE, config_flags);
 
-	if (!config) {
+	if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_ERROR, "Unable to load " RES_CONFIG_SQLITE_CONF_FILE "\n");
 		return 1;
 	}
diff --git a/res/res_http_post.c b/res/res_http_post.c
index 2e4a20a1d4..3e265c4d5b 100644
--- a/res/res_http_post.c
+++ b/res/res_http_post.c
@@ -266,7 +266,8 @@ static int __ast_http_post_load(int reload)
 	struct ast_variable *v;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-	if ((cfg = ast_config_load2("http.conf", "http", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
+	cfg = ast_config_load2("http.conf", "http", config_flags);
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
 		return 0;
 	}
 
diff --git a/res/res_indications.c b/res/res_indications.c
index af56444cd1..7fdca5be37 100644
--- a/res/res_indications.c
+++ b/res/res_indications.c
@@ -263,10 +263,11 @@ static int ind_load_module(int reload)
 	/* that the following cast is needed, is yuk! */
 	/* yup, checked it out. It is NOT written to. */
 	cfg = ast_config_load((char *)config, config_flags);
-	if (!cfg)
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
 		return -1;
-	else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
 		return 0;
+	}
 
 	if (reload)
 		ast_unregister_indication_country(NULL);
diff --git a/res/res_jabber.c b/res/res_jabber.c
index 8f8f91af89..38b1b5959e 100644
--- a/res/res_jabber.c
+++ b/res/res_jabber.c
@@ -2883,7 +2883,7 @@ static int aji_load_config(int reload)
 	/* Reset flags to default value */
 	ast_set_flag(&globalflags, AJI_AUTOREGISTER);
 
-	if (!cfg) {
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_WARNING, "No such configuration file %s\n", JABBER_CONFIG);
 		return 0;
 	}
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 9a34c293f3..9fce79475c 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -1337,8 +1337,9 @@ static int load_moh_classes(int is_reload)
 
 	cfg = ast_config_load("musiconhold.conf", config_flags);
 
-	if (cfg == NULL || cfg == CONFIG_STATUS_FILEUNCHANGED)
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
 		return 0;
+	}
 
 	if (is_reload) {
 		AST_RWLIST_WRLOCK(&mohclasses);
diff --git a/res/res_odbc.c b/res/res_odbc.c
index 7a5d7b3dcb..384696da34 100644
--- a/res/res_odbc.c
+++ b/res/res_odbc.c
@@ -417,7 +417,7 @@ static int load_odbc_config(void)
 	struct odbc_class *new;
 
 	config = ast_config_load(cfg, config_flags);
-	if (!config) {
+	if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_WARNING, "Unable to load config file res_odbc.conf\n");
 		return -1;
 	}
diff --git a/res/res_phoneprov.c b/res/res_phoneprov.c
index 54c094294d..ddb2b4d93a 100644
--- a/res/res_phoneprov.c
+++ b/res/res_phoneprov.c
@@ -903,12 +903,12 @@ static int set_config(void)
 
 	/* Try to grab the port from sip.conf.  If we don't get it here, we'll set it
 	 * to whatever is set in phoneprov.conf or default to 5060 */
-	if ((cfg = ast_config_load("sip.conf", config_flags))) {
+	if ((cfg = ast_config_load("sip.conf", config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) {
 		ast_copy_string(global_serverport, S_OR(ast_variable_retrieve(cfg, "general", "bindport"), "5060"), sizeof(global_serverport));
 		ast_config_destroy(cfg);
 	}
 
-	if (!(cfg = ast_config_load("users.conf", config_flags))) {
+	if (!(cfg = ast_config_load("users.conf", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_WARNING, "Unable to load users.cfg\n");
 		return 0;
 	}
@@ -930,7 +930,7 @@ static int set_config(void)
 		}
 	}
 
-	if (!(phoneprov_cfg = ast_config_load("phoneprov.conf", config_flags))) {
+	if (!(phoneprov_cfg = ast_config_load("phoneprov.conf", config_flags)) || phoneprov_cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_ERROR, "Unable to load config phoneprov.conf\n");
 		return -1;
 	}
diff --git a/res/res_smdi.c b/res/res_smdi.c
index 6a5cf1aa50..88f562b2d7 100644
--- a/res/res_smdi.c
+++ b/res/res_smdi.c
@@ -848,7 +848,7 @@ static int smdi_load(int reload)
 	int msdstrip = 0;              /* strip zero digits */
 	long msg_expiry = SMDI_MSG_EXPIRY_TIME;
 
-	if (!(conf = ast_config_load(config_file, config_flags))) {
+	if (!(conf = ast_config_load(config_file, config_flags)) || conf == CONFIG_STATUS_FILEINVALID) {
 		if (reload)
 			ast_log(LOG_NOTICE, "Unable to reload config %s: SMDI untouched\n", config_file);
 		else
diff --git a/res/res_snmp.c b/res/res_snmp.c
index 71a79f2096..f3cedfb1d6 100644
--- a/res/res_snmp.c
+++ b/res/res_snmp.c
@@ -52,7 +52,7 @@ static int load_config(void)
 	res_snmp_enabled = 0;
 	res_snmp_agentx_subagent = 1;
 	cfg = ast_config_load("res_snmp.conf", config_flags);
-	if (!cfg) {
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_WARNING, "Could not load res_snmp.conf\n");
 		return 0;
 	}
-- 
GitLab