Subversion Repositories Tewi

Rev

Rev 21 | Rev 24 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21 Rev 22
Line 1... Line 1...
1
/* $Id: config.c 21 2024-09-14 12:39:39Z nishi $ */
1
/* $Id: config.c 22 2024-09-14 13:25:38Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "tw_config.h"
5
#include "tw_config.h"
6
#include "tw_module.h"
6
#include "tw_module.h"
Line 28... Line 28...
28
		}
28
		}
29
	}
29
	}
30
	return &config.root;
30
	return &config.root;
31
}
31
}
32
 
32
 
33
bool tw_permission_allowed(const char* path, SOCKADDR addr, struct tw_http_request req, struct tw_config_entry* vhost){
33
bool tw_permission_allowed(const char* path, SOCKADDR addr, struct tw_http_request req, struct tw_config_entry* vhost) {
34
	int i;
34
	int i;
35
	bool found = false;
35
	bool found = false;
36
	bool pathstart = false;
36
	bool pathstart = false;
37
	bool perm = false;
37
	bool perm = false;
38
again:
38
again:
39
	for(i = 0; i < vhost->dir_count; i++){
39
	for(i = 0; i < vhost->dir_count; i++) {
40
		struct tw_dir_entry* e = &vhost->dirs[i];
40
		struct tw_dir_entry* e = &vhost->dirs[i];
41
		pathstart = false;
41
		pathstart = false;
42
		if(strlen(path) >= strlen(e->dir)){
42
		if(strlen(path) >= strlen(e->dir)) {
43
			pathstart = true;
43
			pathstart = true;
44
			int j;
44
			int j;
45
			for(j = 0; path[j] != 0 && e->dir[j] != 0; j++){
45
			for(j = 0; path[j] != 0 && e->dir[j] != 0; j++) {
46
				if(path[j] != e->dir[j]){
46
				if(path[j] != e->dir[j]) {
47
					pathstart = false;
47
					pathstart = false;
48
					break;
48
					break;
49
				}
49
				}
50
			}
50
			}
51
		}
51
		}
52
		char* noslash = cm_strdup(e->dir);
52
		char* noslash = cm_strdup(e->dir);
53
		noslash[strlen(noslash) - 1] = 0;
53
		noslash[strlen(noslash) - 1] = 0;
54
		if(strcmp(e->dir, path) == 0 || strcmp(noslash, path) == 0 || pathstart){
54
		if(strcmp(e->dir, path) == 0 || strcmp(noslash, path) == 0 || pathstart) {
55
			found = true;
55
			found = true;
56
			if(strcmp(e->name, "all") == 0){
56
			if(strcmp(e->name, "all") == 0) {
57
				perm = e->type == TW_DIR_ALLOW;
57
				perm = e->type == TW_DIR_ALLOW;
58
			}
58
			}
59
		}
59
		}
60
		free(noslash);
60
		free(noslash);
61
	}
61
	}
62
	if(!found && vhost != &config.root){
62
	if(!found && vhost != &config.root) {
63
		vhost = &config.root;
63
		vhost = &config.root;
64
		goto again;
64
		goto again;
65
	}
65
	}
66
	return perm;
66
	return perm;
67
}
67
}
Line 79... Line 79...
79
	config.root.sslkey = NULL;
79
	config.root.sslkey = NULL;
80
	config.root.sslcert = NULL;
80
	config.root.sslcert = NULL;
81
	config.root.root = NULL;
81
	config.root.root = NULL;
82
	config.root.mime_count = 0;
82
	config.root.mime_count = 0;
83
	config.root.dir_count = 0;
83
	config.root.dir_count = 0;
-
 
84
	config.root.icon_count = 0;
84
	config.vhost_count = 0;
85
	config.vhost_count = 0;
85
	config.module_count = 0;
86
	config.module_count = 0;
86
	config.extension = NULL;
87
	config.extension = NULL;
87
	config.server_root = cm_strdup(PREFIX);
88
	config.server_root = cm_strdup(PREFIX);
88
	gethostname(config.hostname, 1024);
89
	gethostname(config.hostname, 1024);
Line 177... Line 178...
177
							} else {
178
							} else {
178
								vhost = cm_strdup(r[1]);
179
								vhost = cm_strdup(r[1]);
179
								current = &config.vhosts[config.vhost_count++];
180
								current = &config.vhosts[config.vhost_count++];
180
								current->dir_count = 0;
181
								current->dir_count = 0;
181
								current->mime_count = 0;
182
								current->mime_count = 0;
-
 
183
								current->icon_count = 0;
182
								int i;
184
								int i;
183
								current->name = cm_strdup(vhost);
185
								current->name = cm_strdup(vhost);
184
								current->port = -1;
186
								current->port = -1;
185
								for(i = 0; vhost[i] != 0; i++) {
187
								for(i = 0; vhost[i] != 0; i++) {
186
									if(vhost[i] == ':') {
188
									if(vhost[i] == ':') {
Line 244... Line 246...
244
						}
246
						}
245
					} else if(cm_strcaseequ(r[0], "MIMEType")) {
247
					} else if(cm_strcaseequ(r[0], "MIMEType")) {
246
						if(r[1] == NULL) {
248
						if(r[1] == NULL) {
247
							cm_log("Config", "Missing extension at line %d", ln);
249
							cm_log("Config", "Missing extension at line %d", ln);
248
							stop = 1;
250
							stop = 1;
249
						}else if(r[2] == NULL) {
251
						} else if(r[2] == NULL) {
250
							cm_log("Config", "Missing MIME at line %d", ln);
252
							cm_log("Config", "Missing MIME at line %d", ln);
251
							stop = 1;
253
							stop = 1;
252
						} else {
254
						} else {
253
							struct tw_mime_entry* e = &current->mimes[current->mime_count++];
255
							struct tw_mime_entry* e = &current->mimes[current->mime_count++];
254
							e->ext = cm_strdup(r[1]);
256
							e->ext = cm_strdup(r[1]);
255
							e->mime = cm_strdup(r[2]);
257
							e->mime = cm_strdup(r[2]);
256
						}
258
						}
-
 
259
					} else if(cm_strcaseequ(r[0], "Icon")) {
-
 
260
						if(r[1] == NULL) {
-
 
261
							cm_log("Config", "Missing MIME at line %d", ln);
-
 
262
							stop = 1;
-
 
263
						} else if(r[2] == NULL) {
-
 
264
							cm_log("Config", "Missing path at line %d", ln);
-
 
265
							stop = 1;
-
 
266
						} else {
-
 
267
							struct tw_icon_entry* e = &current->icons[current->icon_count++];
-
 
268
							e->mime = cm_strdup(r[1]);
-
 
269
							e->icon = cm_strdup(r[2]);
-
 
270
						}
257
					} else if(cm_strcaseequ(r[0], "LoadModule")) {
271
					} else if(cm_strcaseequ(r[0], "LoadModule")) {
258
						for(i = 1; r[i] != NULL; i++) {
272
						for(i = 1; r[i] != NULL; i++) {
259
							void* mod = tw_module_load(r[i]);
273
							void* mod = tw_module_load(r[i]);
260
							if(mod != NULL) {
274
							if(mod != NULL) {
261
								config.modules[config.module_count++] = mod;
275
								config.modules[config.module_count++] = mod;