summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-16 21:35:16 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-16 21:35:16 +0100
commit61a369b85e51e0d54e1651e4ff8c11fe4815a0c0 (patch)
tree37273e4881e917b7402b66d563acc2f1359b7a08 /config.c
parent968cee422ab1d61b4234127892d75f0497d8d8c2 (diff)
Move default configuration file location to $HOME/.blabouncer/ and create a default file automatically if it doesn't exist.
Diffstat (limited to 'config.c')
-rw-r--r--config.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/config.c b/config.c
index af30910..a5d9c2f 100644
--- a/config.c
+++ b/config.c
@@ -127,3 +127,90 @@ int checkpassword(char *password, char *filename) {
printf("checkpassword(): unexpectedly got to end of function, quitting.\n");
exit(1);
}
+
+// Create the default configuration file.
+// Return 1 on success, 0 on failure.
+int createconfigfile(char *filename) {
+ char *dirtmp;
+ char *dir;
+ dirtmp = strdup(filename);
+ dir = strdup(dirname(dirtmp));
+
+ // Make sure the parent directory exists
+ struct stat st = {0};
+ if (stat(dir, &st) == -1) {
+ if (mkdir(dir, 0700)) {
+ printf("Error creating config directory '%s'.\n", dir);
+ exit(1);
+ } else {
+ printf("Created config directory '%s'.\n", dir);
+ }
+ }
+
+ FILE *fp;
+// char line[MAXCHAR];
+
+ fp = fopen(filename, "a");
+
+ if (fp == NULL) {
+ printf("error: could not open default configuration file '%s' for writing.\n", filename);
+ exit(1);
+ }
+
+ // Prepare the string
+ char *string =
+ "# blabouncer configuration file\n"
+ "# Entries must be in the form:\n"
+ "# option name, space, equals sign, space, double quote, option value, double quote\n"
+ "# e.g.\n"
+ "# realname = \"Mr Bla Bouncer\"\n"
+ "\n"
+ "nick = \"blabounce\"\n"
+ "username = \"blabounce\"\n"
+ "realname = \"Mr Bla Bouncer\"\n"
+ "\n"
+ "# How many seconds of replay log should be sent to connecting clients\n"
+ "replayseconds = \"7200\"\n"
+ "\n"
+ "# Connect password clients must provided to connect\n"
+ "password = \"bananas\"\n"
+ "\n"
+ "# Port the bouncer should listen on\n"
+ "clientport = \"1234\"\n"
+ "\n"
+ "# Enable TLS for clients connecting to the bouncer (\"1\" for yes or \"0\" for no)\n"
+ "# If \"0\" then certfile and keyfile need not be set\n"
+ "clienttls = \"1\"\n"
+ "\n"
+ "# Enable TLS for the bouncer connecting to the IRC server (\"1\" for yes or \"0\" for no)\n"
+ "servertls = \"1\"\n"
+ "\n"
+ "# Real IRC server the bouncer connects to\n"
+ "ircserver = \"irc.blatech.net\"\n"
+ "\n"
+ "# Real IRC server port\n"
+ "ircserverport = \"6697\"\n"
+ "\n"
+ "# Certificate file\n"
+ "# If clienttls = \"0\" then this need not be set\n"
+ "certfile = \"cert.pem\"\n"
+ "\n"
+ "# Certificate key file\n"
+ "# If clienttls = \"0\" then this need not be set\n"
+ "keyfile = \"key.pem\"\n"
+ "\n"
+ "# Base directory (defaults to $HOME/.blabouncer/)\n"
+ "# Things such as the logs directory will be placed below this\n"
+ "#basedir = \"/home/foo/.blabouncer/\"\n";
+
+ // Write complete string to file
+ if ((fprintf(fp, string)) < 0) {
+ printf("error: could not write to replay log file.\n");
+ exit(1);
+ }
+
+ fclose(fp);
+ return 0;
+
+exit(1);
+}