Changeset 21 in Main for trunk/Server/config.c
- Timestamp:
- Sep 14, 2024, 9:39:39 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Server/config.c
r20 r21 31 31 } 32 32 33 bool tw_permission_allowed(const char* path, SOCKADDR addr, struct tw_http_request req, struct tw_config_entry* vhost){ 34 int i; 35 bool found = false; 36 bool pathstart = false; 37 bool perm = false; 38 again: 39 for(i = 0; i < vhost->dir_count; i++){ 40 struct tw_dir_entry* e = &vhost->dirs[i]; 41 pathstart = false; 42 if(strlen(path) >= strlen(e->dir)){ 43 pathstart = true; 44 int j; 45 for(j = 0; path[j] != 0 && e->dir[j] != 0; j++){ 46 if(path[j] != e->dir[j]){ 47 pathstart = false; 48 break; 49 } 50 } 51 } 52 char* noslash = cm_strdup(e->dir); 53 noslash[strlen(noslash) - 1] = 0; 54 if(strcmp(e->dir, path) == 0 || strcmp(noslash, path) == 0 || pathstart){ 55 found = true; 56 if(strcmp(e->name, "all") == 0){ 57 perm = e->type == TW_DIR_ALLOW; 58 } 59 } 60 free(noslash); 61 } 62 if(!found && vhost != &config.root){ 63 vhost = &config.root; 64 goto again; 65 } 66 return perm; 67 } 68 33 69 void tw_config_init(void) { 34 70 int i; … … 44 80 config.root.sslcert = NULL; 45 81 config.root.root = NULL; 82 config.root.mime_count = 0; 83 config.root.dir_count = 0; 46 84 config.vhost_count = 0; 47 85 config.module_count = 0; … … 63 101 struct tw_config_entry* current = &config.root; 64 102 char* vhost = NULL; 103 char* dir = NULL; 65 104 while(stop == 0) { 66 105 int c = fread(cbuf, 1, 1, f); … … 78 117 } 79 118 } 119 } else if(cm_strcaseequ(r[0], "BeginDirectory")) { 120 if(dir != NULL) { 121 cm_log("Config", "Already in directory section at line %d", ln); 122 stop = 1; 123 } else { 124 if(r[1] == NULL) { 125 cm_log("Config", "Missing directory at line %d", ln); 126 stop = 1; 127 } else { 128 dir = cm_strcat(r[1], r[1][strlen(r[1]) - 1] == '/' ? "" : "/"); 129 } 130 } 131 } else if(cm_strcaseequ(r[0], "EndDirectory")) { 132 if(dir == NULL) { 133 cm_log("Config", "Not in directory section at line %d", ln); 134 stop = 1; 135 } else { 136 free(dir); 137 dir = NULL; 138 } 139 } else if(cm_strcaseequ(r[0], "Allow")) { 140 if(dir == NULL) { 141 cm_log("Config", "Not in directory section at line %d", ln); 142 stop = 1; 143 } else { 144 if(r[1] == NULL) { 145 cm_log("Config", "Missing argument at line %d", ln); 146 stop = 1; 147 } else { 148 struct tw_dir_entry* e = ¤t->dirs[current->dir_count++]; 149 e->name = cm_strdup(r[1]); 150 e->dir = cm_strdup(dir); 151 e->type = TW_DIR_ALLOW; 152 } 153 } 154 } else if(cm_strcaseequ(r[0], "Deny")) { 155 if(dir == NULL) { 156 cm_log("Config", "Not in directory section at line %d", ln); 157 stop = 1; 158 } else { 159 if(r[1] == NULL) { 160 cm_log("Config", "Missing argument at line %d", ln); 161 stop = 1; 162 } else { 163 struct tw_dir_entry* e = ¤t->dirs[current->dir_count++]; 164 e->name = cm_strdup(r[1]); 165 e->dir = cm_strdup(dir); 166 e->type = TW_DIR_DENY; 167 } 168 } 80 169 } else if(cm_strcaseequ(r[0], "BeginVirtualHost")) { 81 170 if(vhost != NULL) { … … 89 178 vhost = cm_strdup(r[1]); 90 179 current = &config.vhosts[config.vhost_count++]; 180 current->dir_count = 0; 181 current->mime_count = 0; 91 182 int i; 92 183 current->name = cm_strdup(vhost); … … 142 233 } else { 143 234 if(current->root != NULL) free(current->root); 144 current->root = cm_strdup( r[1]);235 current->root = cm_strdup(strcmp(r[1], "/") == 0 ? "" : r[1]); 145 236 } 146 237 } else if(cm_strcaseequ(r[0], "ServerRoot")) { … … 151 242 if(config.server_root != NULL) free(config.server_root); 152 243 config.server_root = cm_strdup(r[1]); 244 } 245 } else if(cm_strcaseequ(r[0], "MIMEType")) { 246 if(r[1] == NULL) { 247 cm_log("Config", "Missing extension at line %d", ln); 248 stop = 1; 249 }else if(r[2] == NULL) { 250 cm_log("Config", "Missing MIME at line %d", ln); 251 stop = 1; 252 } else { 253 struct tw_mime_entry* e = ¤t->mimes[current->mime_count++]; 254 e->ext = cm_strdup(r[1]); 255 e->mime = cm_strdup(r[2]); 153 256 } 154 257 } else if(cm_strcaseequ(r[0], "LoadModule")) {
Note:
See TracChangeset
for help on using the changeset viewer.