summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c66
1 files changed, 43 insertions, 23 deletions
diff --git a/functions.c b/functions.c
index af8d5dd..fe96e0a 100644
--- a/functions.c
+++ b/functions.c
@@ -1086,31 +1086,51 @@ 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");
+ // What are the configured nick(s)?
+ char oldircnicks[MAXCONFARR][MAXDATASIZE];
+ // Backup the existing configured nicks in case this rehash fails
+ for (int i = 0; i < MAXCONFARR; i++) {
+ strcpy(oldircnicks[i], settings->ircnicks[i]);
+ }
+ int ret = getconfarr("nicks", settings->conffile, settings->ircnicks);
+ if (!ret) {
+ // No nicks read, copy the old ones back
+ for (int i = 0; i < MAXCONFARR; i++) {
+ strcpy(settings->ircnicks[i], oldircnicks[i]);
+ }
+ strcpy(failuremsg, "error getting any 'nicks' from configuration file");
+ return 0;
+ } else if (ret == -1) {
+ // Error reading an array line from the configuration file
+ // Remove any newlines from the string so error printing works nicely
+ for (size_t i = 0; i < strlen(settings->ircnicks[0]); i++) {
+ if (settings->ircnicks[0][i] == '\n') {
+ settings->ircnicks[0][i] = ' ';
+ }
+ }
+ if (!snprintf(failuremsg, MAXDATASIZE, "error getting 'nicks' from configuration file: %s", settings->ircnicks[0])) {
+ debugprint(DEBUG_CRIT, "Error while preparing nick error response!\n");
+ strcpy(failuremsg, "Error while preparing nick error response!");
+ }
+ // Copy the old ones back (after setting failuremsg so we can read the error string from element 0)
+ for (int i = 0; i < MAXCONFARR; i++) {
+ strcpy(settings->ircnicks[i], oldircnicks[i]);
+ }
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';
+ // Make sure nicks aren't too long (since getconfarr() has to use MAXDATASIZE for all string lengths)
+ for (int i = 0; i < MAXCONFARR; i++) {
+ if (settings->ircnicks[i][0] && strlen(settings->ircnicks[i]) > MAXNICKLENGTH) {
+ // A nick is too long, copy the old ones back
+ for (int i = 0; i < MAXCONFARR; i++) {
+ strcpy(settings->ircnicks[i], oldircnicks[i]);
+ }
+ if (!snprintf(failuremsg, MAXDATASIZE, "error: specified nick '%s' is too long, maximum length is %d.\n", settings->ircnicks[i], MAXNICKLENGTH)) {
+ debugprint(DEBUG_CRIT, "Error while preparing nick too long response!\n");
+ strcpy(failuremsg, "Error while preparing nick too long response!");
+ }
+ return 0;
+ }
}
// What is the auto replay mode?