summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/config.c b/config.c
index 7fec4de..8bfead9 100644
--- a/config.c
+++ b/config.c
@@ -1,6 +1,6 @@
#include "config.h"
-// TODO - Multiple functions here (at least readnames() and relayseconds() have the file opening code, rewrite.
+// TODO - Multiple functions here (at least readnames(), relayseconds() and checkpassword()) have the file opening code, rewrite.
// TODO - Can isconf() and getconf() just be merged into one function?
@@ -136,5 +136,50 @@ int confrelayseconds() {
}
}
+ fclose(fp);
return seconds;
}
+
+// Check the password provided in the string 'str' against what is in
+// the config file.
+// Return 0 for password mismatch, or 1 for password match.
+int checkpassword(char *password) {
+ FILE *fp;
+ char str[MAXCHAR];
+ char* filename = "blabouncer.conf";
+
+ fp = fopen(filename, "r");
+
+ if (fp == NULL) {
+ printf("error: could not open configuration file '%s'.\n", filename);
+ exit(1);
+ }
+
+ while (fgets(str, MAXCHAR, fp) != NULL) {
+ long int len;
+ if ((len = isconf(str, "password"))) {
+ getconf(str, len);
+ printf("confpassword is: '%s', length '%ld'.\n", str, strlen(str));
+ // Ensure password are the same length
+ if (strlen(str) != strlen(password)) {
+ printf("Password length mismatch!\n");
+ fclose(fp);
+ return 0;
+ }
+ // Ensure passwords match
+ if (strncmp(str, password, strlen(password)) == 0) {
+ printf("confpassword matches password.\n");
+ fclose(fp);
+ return 1;
+ } else {
+ printf("confpassword does NOT match password!\n");
+ fclose(fp);
+ return 0;
+ }
+ }
+ }
+
+ fclose(fp);
+ printf("No password read from configuration file, quitting.\n");
+ exit(1);
+}