static void uh_config_parse(void) { const char *path = conf.file; FILE *c; char line[512]; char *col1; char *col2; char *eol; if (!path) path = "/etc/httpd.conf"; c = fopen(path, "r"); if (!c) return; memset(line, 0, sizeof(line)); while (fgets(line, sizeof(line) - 1, c)) { if ((line[0] == '/') && (strchr(line, ':') != NULL)) { if (!(col1 = strchr(line, ':')) || (*col1++ = 0) || !(col2 = strchr(col1, ':')) || (*col2++ = 0) || !(eol = strchr(col2, '\n')) || (*eol++ = 0)) continue; uh_auth_add(line, col1, col2); } else if (!strncmp(line, "I:", 2)) { if (!(col1 = strchr(line, ':')) || (*col1++ = 0) || !(eol = strchr(col1, '\n')) || (*eol++ = 0)) continue; uh_index_add(strdup(col1)); } else if (!strncmp(line, "E404:", 5)) { if (!(col1 = strchr(line, ':')) || (*col1++ = 0) || !(eol = strchr(col1, '\n')) || (*eol++ = 0)) continue; conf.error_handler = strdup(col1); } else if ((line[0] == '*') && (strchr(line, ':') != NULL)) { if (!(col1 = strchr(line, '*')) || (*col1++ = 0) || !(col2 = strchr(col1, ':')) || (*col2++ = 0) || !(eol = strchr(col2, '\n')) || (*eol++ = 0)) continue; uh_interpreter_add(col1, col2); } } fclose(c); }
static void uh_config_parse(const char *path) { FILE *c; char line[512]; char *user = NULL; char *pass = NULL; char *eol = NULL; if( (c = fopen(path ? path : "/etc/httpd.conf", "r")) != NULL ) { memset(line, 0, sizeof(line)); while( fgets(line, sizeof(line) - 1, c) ) { if( (line[0] == '/') && (strchr(line, ':') != NULL) ) { if( !(user = strchr(line, ':')) || (*user++ = 0) || !(pass = strchr(user, ':')) || (*pass++ = 0) || !(eol = strchr(pass, '\n')) || (*eol++ = 0) ) continue; if( !uh_auth_add(line, user, pass) ) { fprintf(stderr, "Can not manage more than %i basic auth realms, " "will skip the rest\n", UH_LIMIT_AUTHREALMS ); break; } } } fclose(c); } }
static void uh_config_parse(struct config *conf) { FILE *c; char line[512]; char *col1 = NULL; char *col2 = NULL; char *eol = NULL; const char *path = conf->file ? conf->file : "/etc/httpd.conf"; if( (c = fopen(path, "r")) != NULL ) { memset(line, 0, sizeof(line)); while( fgets(line, sizeof(line) - 1, c) ) { if( (line[0] == '/') && (strchr(line, ':') != NULL) ) { if( !(col1 = strchr(line, ':')) || (*col1++ = 0) || !(col2 = strchr(col1, ':')) || (*col2++ = 0) || !(eol = strchr(col2, '\n')) || (*eol++ = 0) ) continue; if( !uh_auth_add(line, col1, col2) ) { fprintf(stderr, "Notice: No password set for user %s, ignoring " "authentication on %s\n", col1, line ); } } else if( !strncmp(line, "I:", 2) ) { if( !(col1 = strchr(line, ':')) || (*col1++ = 0) || !(eol = strchr(col1, '\n')) || (*eol++ = 0) ) continue; conf->index_file = strdup(col1); } else if( !strncmp(line, "E404:", 5) ) { if( !(col1 = strchr(line, ':')) || (*col1++ = 0) || !(eol = strchr(col1, '\n')) || (*eol++ = 0) ) continue; conf->error_handler = strdup(col1); } #ifdef HAVE_CGI else if( (line[0] == '*') && (strchr(line, ':') != NULL) ) { if( !(col1 = strchr(line, '*')) || (*col1++ = 0) || !(col2 = strchr(col1, ':')) || (*col2++ = 0) || !(eol = strchr(col2, '\n')) || (*eol++ = 0) ) continue; if( !uh_interpreter_add(col1, col2) ) { fprintf(stderr, "Unable to add interpreter %s for extension %s: " "Out of memory\n", col2, col1 ); } } #endif } fclose(c); } }