diff options
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -183,3 +183,45 @@ int checkpassword(char *password) { printf("No password read from configuration file, quitting.\n"); exit(1); } + +int confclientport(char *clientport) { + FILE *fp; + char str[MAXCHAR]; + char* filename = "blabouncer.conf"; + + // Set all strings to zero-length to begin + clientport[0] = '\0'; + + 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, "clientport"))) { + getconf(str, len); + strncpy(clientport, str, strlen(str)); + clientport[strlen(str)] = '\0'; + printf("clientport is: '%s', length '%ld'.\n", clientport, strlen(clientport)); + } + } + + // Ensure we have everything required + if (!strlen(clientport)) { + printf("Failed to read clientport from configuration file.\n"); + exit(1); + } + + int portint = strtol(clientport, NULL, 10); // Convert resulting string to an integer, base 10 + // Ensure port is valid + if (portint < 1 || portint > 65535) { + printf("Invalid clientport value in configuration file.\n"); + exit(1); + } + + fclose(fp); + return 1; +} |