summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/admin.c4
-rw-r--r--mbbsd/mbbsd.c68
-rw-r--r--mbbsd/register.c2
3 files changed, 70 insertions, 4 deletions
diff --git a/mbbsd/admin.c b/mbbsd/admin.c
index 84bf25ea..90676799 100644
--- a/mbbsd/admin.c
+++ b/mbbsd/admin.c
@@ -762,11 +762,11 @@ x_file(void)
char buf[PATHLEN];
FILE *fp = NULL;
- fp = fopen("etc/editable", "rt");
+ fp = fopen(FN_CONF_EDITABLE, "rt");
if (!fp)
{
// you can find a sample in sample/etc/editable
- vmsg("未設定可編輯檔案列表[etc/editable],請洽系統站長。");
+ vmsgf("未設定可編輯檔案列表[%s],請洽系統站長。", FN_CONF_EDITABLE);
return 0;
}
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index 4ae67910..d7487370 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -1579,6 +1579,7 @@ static void usage(char *argv0)
"\t-n tunnel enable tunnel mode, imply -d\n"
"\t-p port listen port\n"
"\t-l fd pre-listen fd\n"
+ "\t-f bindport_conf read from configuration file\n"
"\n"
"non-daemon mode\n"
"\t-D use non-daemon mode, imply -t tty\n"
@@ -1598,6 +1599,59 @@ static void usage(char *argv0)
);
}
+bool parse_bindport_conf(const char *path, struct ProgramOption *option)
+{
+ FILE *fp = fopen(path, "rt");
+ char buf[PATHLEN], vprogram[STRLEN], vport[STRLEN], vopt[STRLEN];
+ int port = 0;
+ if (!fp)
+ return false;
+
+ while (fgets(buf, sizeof(buf), fp))
+ {
+ if (sscanf(buf, "%s %s", vprogram, vport) != 2 ||
+ strcmp(vprogram, "mbbsd") != 0)
+ continue;
+
+ if (strcmp(vport, "tunnel") == 0)
+ {
+ if (sscanf(buf, "%s %s %s", vprogram, vport, vopt) != 3)
+ {
+ fprintf(stderr, "error: invalid tunnel setting in %s.\r\n",
+ path);
+ exit(1);
+ }
+ option->tunnel_mode = true;
+ if (option->flag_tunnel_path)
+ {
+ fprintf(stderr, "warning: ignore tunnel path specified in %s.\r\n",
+ path);
+ continue;
+ }
+ option->flag_tunnel_path = strdup(vopt);
+ continue;
+ }
+
+ // normal port?
+ port = atoi(vport);
+ if (!port)
+ {
+ fprintf(stderr,"warning: unknown setting: %s\r\n", buf);
+ continue;
+ }
+ if (option->nport >= MAX_BINDPORT)
+ {
+ fprintf(stderr, "too many port (>%d)\n", MAX_BINDPORT);
+ exit(1);
+ }
+ // add port
+ option->port[option->nport++] = port;
+ }
+
+ fclose(fp);
+ return true;
+}
+
bool parse_argv(int argc, char *argv[], struct ProgramOption *option)
{
int ch;
@@ -1608,10 +1662,15 @@ bool parse_argv(int argc, char *argv[], struct ProgramOption *option)
option->flag_listenfd = -1;
option->flag_checkload = true;
- while ((ch = getopt(argc, argv, "dn:p:l:Dt:h:e:bu:FC")) != -1) {
+ while ((ch = getopt(argc, argv, "dn:p:f:l:Dt:h:e:bu:FC")) != -1) {
switch (ch) {
case 'n':
option->tunnel_mode = true;
+ if (option->flag_tunnel_path)
+ {
+ fprintf(stderr, "warning: changed tunnel path to %s.\r\n", optarg);
+ }
+ free(option->flag_tunnel_path);
option->flag_tunnel_path = strdup(optarg);
// reuse 'd' mode, no break here.
case 'd':
@@ -1620,6 +1679,13 @@ bool parse_argv(int argc, char *argv[], struct ProgramOption *option)
option->term_mode = TermMode_TELNET;
option->flag_fork = true;
break;
+ case 'f':
+ if (!parse_bindport_conf(optarg, option))
+ {
+ perror(optarg);
+ exit(1);
+ }
+ break;
case 'p':
if (option->nport < MAX_BINDPORT) {
int port = atoi(optarg);
diff --git a/mbbsd/register.c b/mbbsd/register.c
index 45797c13..473f2f57 100644
--- a/mbbsd/register.c
+++ b/mbbsd/register.c
@@ -69,7 +69,7 @@ removespace(char *s)
int
reserved_user_id(const char *userid)
{
- if (file_exist_record(FN_RESERVED_ID, userid))
+ if (file_exist_record(FN_CONF_RESERVED_ID, userid))
return 1;
return 0;
}