ircd
ircd.exe
-config.mk
setpass
-ops.txt
-init.txt
-chanlog.txt
-cert.pem
-key.pem
-users.txt
-newusers.txt
-help.txt
-motd.txt
+config.mk
Some things are configurable via compile-time flags. In particular, `-DHAS_TLS`
and some constants defined in `src/config.h`.
+## Config files
+These have to go in IRCDDATADIR (`data` by default).
+
For TLS you gonna need to place your certificate and private key in
`cert.pem` and `key.pem` respectively.
--- /dev/null
+ops.txt
+init.txt
+chanlog.txt
+cert.pem
+key.pem
+users.txt
+newusers.txt
+help.txt
+motd.txt
#ifndef IRCDHOSTNAME
#define IRCDHOSTNAME "example.com"
#endif
+#ifndef IRCDDATADIR
+#define IRCDDATADIR "data"
+#endif
if (argc < 2)
return err_needmoreparams(client, command), sendbuf(client), 0;
stringlower(args[0]);
- int res = password_check(args[0], args[1], "ops.txt");
+ int res = password_check(args[0], args[1], getdatafile("ops.txt"));
memset(args[1], 0, strlen(args[1]));
if (!(client->umode & UMODE_SECURE) || res == -1) {
err_passwdmismatch(client), sendbuf(client);
if (!hash)
return 0; // TODO: error message
memset(args[1], 0, strlen(args[1]));
- FILE *f = fopen("newusers.txt", "ab");
+ FILE *f = fopen(getdatafile("newusers.txt"), "ab");
if (!f)
return 0; // TODO: error message
fprintf(f, "%s:%s\n", args[0], hash);
if (!is_registered(client))
return err_notregistered(client), sendbuf(client), 0;
char line[512];
- FILE *f = fopen("help.txt", "r");
+ FILE *f = fopen(getdatafile("help.txt"), "r");
if (f) {
rpl_helpstart(client), sendbuf(client);
while (fgets(line, 512, f)) {
if (client->regstate == REG_CAPLS || !client->nick_reg || !client->username)
return;
if (client->username[0] == '~' && client->pass_reg) {
- int res = password_check(client->username + 1, client->pass_reg, "users.txt");
+ int res = password_check(client->username + 1, client->pass_reg, getdatafile("users.txt"));
memset(client->pass_reg, 0, strlen(client->pass_reg));
free(client->pass_reg);
client->pass_reg = NULL;
void sendMOTD(struct client_data *client) {
char line[512];
- FILE *f = fopen("motd.txt", "r");
+ FILE *f = fopen(getdatafile("motd.txt"), "r");
if (f) {
rpl_motdstart(client), sendbuf(client);
while (fgets(line, 512, f)) {
return fprintf(stderr, "tls_init error\n"), 1;
if (!(tls_cfg = tls_config_new()))
return fprintf(stderr, "tls_config_new error\n"), 1;
- if (tls_config_set_cert_file(tls_cfg, "cert.pem") == -1)
+ if (tls_config_set_cert_file(tls_cfg, getdatafile("cert.pem")) == -1)
return fprintf(stderr, "tls_config_set_cert_file: %s\n", tls_config_error(tls_cfg)), 1;
- if (tls_config_set_key_file(tls_cfg, "key.pem") == -1)
+ if (tls_config_set_key_file(tls_cfg, getdatafile("key.pem")) == -1)
return fprintf(stderr, "tls_config_set_key_file: %s\n", tls_config_error(tls_cfg)), 1;
tls_config_insecure_noverifycert(tls_cfg);
tls_config_verify_client_optional(tls_cfg);
for (int i = 0; i < listener_count; i++)
net_nonblock(listeners[i].sock);
- FILE *f = fopen("init.txt", "rb");
+ FILE *f = fopen(getdatafile("init.txt"), "rb");
if (f) {
struct client_data *fake = allocClient();
fake->umode |= UMODE_OPER | UMODE_SECURE;
set_time(0);
fclose(f);
}
- fchanlog = fopen("chanlog.txt", "ab");
+ fchanlog = fopen(getdatafile("chanlog.txt"), "ab");
if (fchanlog) {
fprintf(fchanlog, "$0 AAA :server starting %lu\r\n", (unsigned long)get_time());
fflush(fchanlog);
#include "util.h"
+#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
}
return 1;
}
+
+static const char *datadir = IRCDDATADIR;
+const char *getdatafile(const char *fn)
+{
+ static char buf[256];
+ size_t len1 = strlen(datadir);
+ size_t len2 = strlen(fn);
+ if (len1+1+len2+1 > sizeof(buf))
+ abort();
+ memcpy(buf, datadir, len1);
+ buf[len1] = '/';
+ int needslash = len1 && datadir[len1-1] != '/';
+ memcpy(buf+len1+needslash, fn, len2);
+ buf[len1+needslash+len2] = '\0';
+ return buf;
+}
time_t get_time();
void set_time(time_t t);
int irc_glob(const char *key, const char *mask);
+const char *getdatafile(const char *fn);
#endif