diff options
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 87 |
1 files changed, 87 insertions, 0 deletions
@@ -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); +} |