Read $HOME/.mcabberrc if there is no mcabber configuration directory
This was broken by ccd4ffa41a1b.
This patch should fix issue #146.
--- a/mcabber/mcabber/histolog.c Sat Feb 27 11:02:19 2016 +0100
+++ b/mcabber/mcabber/histolog.c Sat Feb 27 11:28:24 2016 +0100
@@ -397,6 +397,12 @@
} else {
const char *cfgdir = settings_get_mcabber_config_dir();
const char *hdir = "/histo/";
+ if (!cfgdir) {
+ scr_LogPrint(LPRINT_LOGNORM, "ERROR: Cannot find out "
+ "history log directory; logging DISABLED");
+ UseFileLogging = FileLoadLogs = FALSE;
+ return;
+ }
RootDir = g_strdup_printf("%s%s", cfgdir, hdir);
}
@@ -406,7 +412,7 @@
g_free(RootDir);
RootDir = NULL;
scr_LogPrint(LPRINT_LOGNORM, "ERROR: Cannot access "
- "history log directory, logging DISABLED");
+ "history log directory; logging DISABLED");
UseFileLogging = FileLoadLogs = FALSE;
}
}
--- a/mcabber/mcabber/settings.c Sat Feb 27 11:02:19 2016 +0100
+++ b/mcabber/mcabber/settings.c Sat Feb 27 11:28:24 2016 +0100
@@ -95,7 +95,7 @@
const gchar *settings_get_mcabber_config_dir(void)
{
static char *config_dir;
- char *home_dir;
+ const char *home_dir;
GString *sfilename;
FILE *fp;
@@ -150,16 +150,8 @@
}
}
- // Last guess: home directory itself...
- if (!config_dir) {
- g_string_printf(sfilename, "%s/.mcabberrc", home_dir);
- if ((fp = fopen(sfilename->str, "r")) != NULL) {
- fclose(fp);
- config_dir = g_strdup(home_dir);
- } else {
- scr_log_print(LPRINT_NORMAL, "Cannot find/open any configuration file!\n");
- }
- }
+ if (!config_dir)
+ scr_log_print(LPRINT_NORMAL, "Cannot find configuration directory!\n");
g_string_free(sfilename, TRUE);
return config_dir;
@@ -191,10 +183,19 @@
}
mcabber_conf_dir = settings_get_mcabber_config_dir();
- if (!mcabber_conf_dir)
- return -1;
+ if (!mcabber_conf_dir) {
+ // Try home directory
+ const char *home_dir = getenv("HOME");
+ if (!home_dir) {
+ scr_log_print(LPRINT_NORMAL, "Cannot find any configuration file!\n");
+ err = -1;
+ goto cfg_read_file_return;
+ }
+ def_filename = g_strdup_printf("%s/.mcabberrc", home_dir);
+ } else {
+ def_filename = g_strdup_printf("%s/mcabberrc", mcabber_conf_dir);
+ }
- def_filename = g_strdup_printf("%s/mcabberrc", mcabber_conf_dir);
if ((fp = fopen(def_filename, "r")) == NULL) {
fprintf(stderr, "Cannot open config file!\n");
g_free(def_filename);
@@ -205,8 +206,12 @@
// As it could contain sensitive data, we make it user-readable only.
checkset_perm(def_filename, TRUE);
scr_log_print(LPRINT_LOGNORM, "Reading %s", def_filename);
- // Check mcabber dir. Here we just warn, we don't change the modes.
- checkset_perm(mcabber_conf_dir, FALSE);
+
+ // Check mcabber directory permissions.
+ // Here we just warn, we don't change the mode.
+ if (mcabber_conf_dir)
+ checkset_perm(mcabber_conf_dir, FALSE);
+
g_free(def_filename);
} else {
// filename was specified
--- a/mcabber/mcabber/utils.c Sat Feb 27 11:02:19 2016 +0100
+++ b/mcabber/mcabber/utils.c Sat Feb 27 11:28:24 2016 +0100
@@ -315,6 +315,8 @@
int fd;
struct stat buf;
+ if (!name) return -1;
+
#ifdef __CYGWIN__
// Permission checking isn't efficient on Cygwin
return 0;