|
|
@@ -41,11 +41,11 @@ tellconf()
|
|
|
{
|
|
|
conf_bot *bot = NULL;
|
|
|
int i = 0;
|
|
|
-
|
|
|
sdprintf("tempdir: %s\n", replace(tempdir, conf.homedir, "~"));
|
|
|
sdprintf("uid: %d\n", conf.uid);
|
|
|
sdprintf("uname: %s\n", conf.uname);
|
|
|
sdprintf("homedir: %s\n", conf.homedir);
|
|
|
+ sdprintf("username: %s\n", conf.username);
|
|
|
sdprintf("binpath: %s\n", replace(conf.binpath, conf.homedir, "~"));
|
|
|
sdprintf("binname: %s\n", conf.binname);
|
|
|
sdprintf("datadir: %s\n", replace(conf.datadir, conf.homedir, "~"));
|
|
|
@@ -314,6 +314,7 @@ confedit()
|
|
|
localhub_pid = conf.bots->pid;
|
|
|
|
|
|
tmpconf.my_close();
|
|
|
+ free_conf();
|
|
|
readconf((const char *) tmpconf.file, 0); /* read cleartext conf tmp into &settings */
|
|
|
expand_tilde(&conf.binpath);
|
|
|
expand_tilde(&conf.datadir);
|
|
|
@@ -346,7 +347,8 @@ init_conf()
|
|
|
#endif /* !CYGWIN_HACKS */
|
|
|
conf.autouname = 0;
|
|
|
#ifdef CYGWIN_HACKS
|
|
|
- conf.binpath = strdup(homedir());
|
|
|
+ if (homedir())
|
|
|
+ conf.binpath = strdup(homedir());
|
|
|
#else /* !CYGWIN_HACKS */
|
|
|
conf.binpath = strdup(dirname(binname));
|
|
|
#endif /* CYGWIN_HACKS */
|
|
|
@@ -601,14 +603,21 @@ free_conf()
|
|
|
free_conf_bots(conf.bots);
|
|
|
free_bot(conf.bot);
|
|
|
conf.bot = NULL;
|
|
|
- free(conf.localhub);
|
|
|
- free(conf.uname);
|
|
|
- free(conf.username);
|
|
|
+ if (conf.localhub)
|
|
|
+ free(conf.localhub);
|
|
|
+ if (conf.uname)
|
|
|
+ free(conf.uname);
|
|
|
+ if (conf.username)
|
|
|
+ free(conf.username);
|
|
|
if (conf.datadir)
|
|
|
free(conf.datadir);
|
|
|
- free(conf.homedir);
|
|
|
- free(conf.binname);
|
|
|
- free(conf.binpath);
|
|
|
+ if (conf.homedir)
|
|
|
+ free(conf.homedir);
|
|
|
+ if (conf.binname)
|
|
|
+ free(conf.binname);
|
|
|
+ if (conf.binpath)
|
|
|
+ free(conf.binpath);
|
|
|
+ init_conf();
|
|
|
}
|
|
|
|
|
|
void
|
|
|
@@ -625,14 +634,23 @@ free_conf_bots(conf_bot *list)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void prep_homedir(bool error)
|
|
|
+{
|
|
|
+ if (!conf.homedir)
|
|
|
+ str_redup(&conf.homedir, homedir());
|
|
|
+
|
|
|
+ if (error && (!conf.homedir || !conf.homedir[0]))
|
|
|
+ werr(ERR_NOHOMEDIR);
|
|
|
+}
|
|
|
+
|
|
|
int
|
|
|
parseconf(bool error)
|
|
|
{
|
|
|
- if (conf.username) {
|
|
|
+ if (!conf.username)
|
|
|
str_redup(&conf.username, my_username());
|
|
|
- } else {
|
|
|
- conf.username = strdup(my_username());
|
|
|
- }
|
|
|
+
|
|
|
+ if (error && (!conf.username || !conf.username[0]))
|
|
|
+ werr(ERR_NOUSERNAME);
|
|
|
|
|
|
#ifndef CYGWIN_HACKS
|
|
|
if (error && conf.uid != (signed) myuid) {
|
|
|
@@ -651,12 +669,6 @@ parseconf(bool error)
|
|
|
} else if (!conf.uname) { /* if not set, then just set it, wont happen again next time... */
|
|
|
conf.uname = strdup(my_uname());
|
|
|
}
|
|
|
-
|
|
|
- if (conf.homedir) {
|
|
|
- str_redup(&conf.homedir, homedir());
|
|
|
- } else {
|
|
|
- conf.homedir = strdup(homedir());
|
|
|
- }
|
|
|
|
|
|
#endif /* !CYGWIN_HACKS */
|
|
|
return 0;
|
|
|
@@ -721,7 +733,7 @@ readconf(const char *fname, int bits)
|
|
|
if (line[0])
|
|
|
option = newsplit(&line);
|
|
|
|
|
|
- if (!option)
|
|
|
+ if (!option || !line[0])
|
|
|
continue;
|
|
|
|
|
|
if (!strcmp(option, "autocron")) { /* automatically check/create crontab? */
|
|
|
@@ -875,23 +887,23 @@ writeconf(char *filename, FILE * stream, int bits)
|
|
|
|
|
|
comment("");
|
|
|
|
|
|
- if (conf.username && strcmp(conf.username, my_username())) {
|
|
|
+ if (conf.username && my_username() && strcmp(conf.username, my_username())) {
|
|
|
conf_com();
|
|
|
my_write(f, "%s! username %s\n", do_confedit == CONF_AUTO ? "" : "#", my_username());
|
|
|
my_write(f, "%s! username %s\n", do_confedit == CONF_STATIC ? "" : "#", conf.username);
|
|
|
} else
|
|
|
- my_write(f, "! username %s\n", conf.username ? conf.username : my_username());
|
|
|
+ my_write(f, "! username %s\n", conf.username ? conf.username : my_username() ? my_username() : "");
|
|
|
|
|
|
- if (conf.homedir && strcmp(conf.homedir, homedir(0))) {
|
|
|
+ if (conf.homedir && homedir(0) && strcmp(conf.homedir, homedir(0))) {
|
|
|
conf_com();
|
|
|
my_write(f, "%s! homedir %s\n", do_confedit == CONF_AUTO ? "" : "#", homedir(0));
|
|
|
my_write(f, "%s! homedir %s\n", do_confedit == CONF_STATIC ? "" : "#", conf.homedir);
|
|
|
} else
|
|
|
- my_write(f, "! homedir %s\n", conf.homedir ? conf.homedir : homedir(0));
|
|
|
+ my_write(f, "! homedir %s\n", conf.homedir ? conf.homedir : homedir(0) ? homedir(0) : "");
|
|
|
|
|
|
comment("\n# binpath needs to be full path unless it begins with '~', which uses 'homedir', ie, '~/'");
|
|
|
|
|
|
- if (strstr(conf.binpath, homedir())) {
|
|
|
+ if (homedir() && strstr(conf.binpath, homedir())) {
|
|
|
p = replace(conf.binpath, homedir(), "~");
|
|
|
my_write(f, "! binpath %s\n", p);
|
|
|
} else
|
|
|
@@ -903,7 +915,7 @@ writeconf(char *filename, FILE * stream, int bits)
|
|
|
comment("");
|
|
|
|
|
|
comment("# datadir should be set to a static directory that is writable");
|
|
|
- if (strstr(conf.datadir, homedir())) {
|
|
|
+ if (homedir() && strstr(conf.datadir, homedir())) {
|
|
|
p = replace(conf.datadir, homedir(), "~");
|
|
|
my_write(f, "! datadir %s\n", p);
|
|
|
} else
|
|
|
@@ -1059,17 +1071,17 @@ fill_conf_bot()
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-bin_to_conf(void)
|
|
|
+bin_to_conf(bool error)
|
|
|
{
|
|
|
/* printf("Converting binary data to conf struct\n"); */
|
|
|
conf.uid = atol(settings.uid);
|
|
|
- str_redup(&conf.username, settings.username);
|
|
|
+ if (settings.username[0])
|
|
|
+ str_redup(&conf.username, settings.username);
|
|
|
str_redup(&conf.uname, settings.uname);
|
|
|
str_redup(&conf.datadir, settings.datadir);
|
|
|
- expand_tilde(&conf.datadir);
|
|
|
- str_redup(&conf.homedir, settings.homedir);
|
|
|
+ if (settings.homedir[0])
|
|
|
+ str_redup(&conf.homedir, settings.homedir);
|
|
|
str_redup(&conf.binpath, settings.binpath);
|
|
|
- expand_tilde(&conf.binpath);
|
|
|
str_redup(&conf.binname, settings.binname);
|
|
|
conf.portmin = atol(settings.portmin);
|
|
|
conf.portmax = atol(settings.portmax);
|
|
|
@@ -1078,7 +1090,12 @@ bin_to_conf(void)
|
|
|
conf.watcher = atoi(settings.watcher);
|
|
|
conf.pscloak = atoi(settings.pscloak);
|
|
|
|
|
|
- /* BOTS */
|
|
|
+
|
|
|
+ prep_homedir(error);
|
|
|
+ expand_tilde(&conf.datadir);
|
|
|
+ expand_tilde(&conf.binpath);
|
|
|
+
|
|
|
+ /* PARSE/ADD BOTS */
|
|
|
{
|
|
|
char *p = NULL, *tmp = NULL, *tmpp = NULL;
|
|
|
|
|
|
@@ -1112,7 +1129,6 @@ bin_to_conf(void)
|
|
|
|
|
|
if (clear_tmpdir)
|
|
|
clear_tmp(); /* clear out the tmp dir, no matter if we are localhub or not */
|
|
|
-
|
|
|
conf_compat_pids();
|
|
|
conf_checkpids();
|
|
|
|