summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-06-16 21:16:29 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-06-16 21:16:29 +0100
commit67fd69854489a088bc8d90702ba37cecccd6f169 (patch)
treeac0efe967e433d725cab51b6fe93aa685c928950 /functions.c
parenta31e7b13b3cef0872be5922a568633d74dd408d2 (diff)
Load all settings from configuration file at startup instead of reading it for certain settings (password/nick/nick2/nick3).
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/functions.c b/functions.c
index abffb0b..82a98eb 100644
--- a/functions.c
+++ b/functions.c
@@ -996,6 +996,33 @@ void cleanexit(SSL *server_ssl, struct client *clients, int sourcefd, struct irc
int rehash(struct settings *settings, char *failuremsg) {
// TODO - Try to share some/all of this code with the initial main() settings loading
+ // What is the nick?
+ char oldircnick[MAXNICKLENGTH];
+ strcpy(oldircnick, settings->ircnick);
+ if (!getconfstr("nick", settings->conffile, settings->ircnick)) {
+ strcpy(settings->ircnick, oldircnick);
+ strcpy(failuremsg, "error getting 'nick' from configuration file");
+ return 0;
+ }
+
+ // What is nick2?
+ char oldircnick2[MAXNICKLENGTH];
+ strcpy(oldircnick2, settings->ircnick2);
+ if (!getconfstr("nick2", settings->conffile, settings->ircnick2)) {
+ strcpy(settings->ircnick2, oldircnick2);
+ // Not configured, set to blank string
+ settings->ircnick2[0] = '\0';
+ }
+
+ // What is nick3?
+ char oldircnick3[MAXNICKLENGTH];
+ strcpy(oldircnick3, settings->ircnick3);
+ if (!getconfstr("nick3", settings->conffile, settings->ircnick3)) {
+ strcpy(settings->ircnick3, oldircnick3);
+ // Not configured, set to blank string
+ settings->ircnick3[0] = '\0';
+ }
+
// What is the auto replay mode?
char oldreplaymode[MAXDATASIZE];
strcpy(oldreplaymode, settings->replaymode);
@@ -1020,6 +1047,15 @@ int rehash(struct settings *settings, char *failuremsg) {
return 0;
}
+ // What is the password?
+ char oldpassword[MAXCHAR];
+ strcpy(oldpassword, settings->password);
+ if (!getconfstr("password", settings->conffile, settings->password)) {
+ strcpy(settings->password, oldpassword);
+ strcpy(failuremsg, "error getting 'password' from configuration file");
+ return 0;
+ }
+
// Is logging enabled?
int oldlogging = settings->logging;
settings->logging = getconfint("logging", settings->conffile);
@@ -1051,3 +1087,27 @@ int rehash(struct settings *settings, char *failuremsg) {
failuremsg[0] = '\0';
return 1;
}
+
+// Check the password provided in the string 'str' against what is in
+// the settings structure 'settings'.
+// Return 0 for password mismatch, or 1 for password match.
+int checkpassword(char *password, struct settings *settings) {
+ // Ensure passwords are the same length
+ if (strlen(password) != strlen(settings->password)) {
+ debugprint(DEBUG_SOME, "Password length mismatch!\n");
+ return 0;
+ }
+ // Ensure passwords match
+ if (strncmp(password, settings->password, strlen(password)) == 0) {
+ debugprint(DEBUG_FULL, "settings->password matches password.\n");
+ return 1;
+ } else {
+ debugprint(DEBUG_SOME, "settings->password does NOT match password!\n");
+ return 0;
+ }
+
+ printf("checkpassword(): unexpectedly got to end of function, quitting.\n");
+ debugprint(DEBUG_CRIT, "checkpassword(): unexpectedly got to end of function, quitting.\n");
+ // No messing around with password stuff
+ exit(EXIT_FAILURE);
+}