From: nishi Date: Mon, 15 Apr 2024 02:21:47 +0000 (+0000) Subject: basic X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=6a494488fc54cd3b9fb52826358c74759830ebf8;p=mandshurica.git basic git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@24 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/Mandshurica/config.c b/Mandshurica/config.c index 32e76c4..9811011 100644 --- a/Mandshurica/config.c +++ b/Mandshurica/config.c @@ -137,7 +137,10 @@ int mandshurica_load_config(const char* path) { mandshurica_add_param(value, value + i); } } + } else if(strcmp(key, "Include") == 0) { + mandshurica_load_config(value); } else if(strcmp(key, "LoadModule") == 0) { + config.libs = &loaded_mods; char* path; if(value[0] == '/') { path = mandshurica_strdup(value); @@ -195,6 +198,11 @@ int mandshurica_create_config(const char* path) { if(f != NULL) { fprintf(f, "# Generated by Mandshurica " MANDSHURICA_VERSION "\n"); fprintf(f, "ServerRoot %s\n", PREFIX); + fprintf(f, "\n"); + fprintf(f, "Set HTTPPort 1024\n"); + fprintf(f, "Set HTTPRoot %s\n", WEBROOT_PREFIX); + fprintf(f, "\n"); + fprintf(f, "LoadModule %s/basic.so\n", MODULE_PREFIX); fprintf(f, "LoadModule %s/http.so\n", MODULE_PREFIX); fprintf(f, "LoadModule %s/subversion.so\n", MODULE_PREFIX); fprintf(f, "LoadModule %s/syslog.so\n", MODULE_PREFIX); diff --git a/Mandshurica/mandshurica.h b/Mandshurica/mandshurica.h index 8c14c50..a5953ac 100644 --- a/Mandshurica/mandshurica.h +++ b/Mandshurica/mandshurica.h @@ -31,15 +31,19 @@ #ifndef __MANDSHURICA_MANDSHURICA_H__ #define __MANDSHURICA_MANDSHURICA_H__ +#include "ms_config.h" + #define MANDSHURICA_VERSION "0.0" #define MS_MOD_LOG "LOG" #define MS_MOD_VCS "VCS" #define MS_MOD_SRV "SRV" +#define MS_MOD_AUTH "AUTH" struct mandshurica_config { void (*mandshurica_log)(const char*, const char*); char* (*mandshurica_get_param)(const char* param); + struct mandshurica_mod*** libs; }; #endif diff --git a/Module/Makefile b/Module/Makefile index c538330..24185c0 100644 --- a/Module/Makefile +++ b/Module/Makefile @@ -6,7 +6,11 @@ EXTRA_LIBS = .PHONY: all clean -all: ./subversion.so ./syslog.so ./http.so +ifeq ($(shell uname -s),Linux) +EXTRA_LIBS += -ldl +endif + +all: ./subversion.so ./syslog.so ./http.so ./basic.so ./%.so: ./%.o ./util.o $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LIBS) $(EXTRA_LIBS) diff --git a/Module/basic.c b/Module/basic.c new file mode 100644 index 0000000..c03708a --- /dev/null +++ b/Module/basic.c @@ -0,0 +1,47 @@ +/* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* Mandshurica - Build Automation */ +/* -------------------------------------------------------------------------- */ +/* Copyright (c) 2024 Nishi. */ +/* Redistribution and use in source and binary forms, with or without modific */ +/* ation, are permitted provided that the following conditions are met: */ +/* 1. Redistributions of source code must retain the above copyright noti */ +/* ce, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright n */ +/* otice, this list of conditions and the following disclaimer in the documen */ +/* tation and/or other materials provided with the distribution. */ +/* 3. Neither the name of the copyright holder nor the names of its contr */ +/* ibutors may be used to endorse or promote products derived from this softw */ +/* are without specific prior written permission. */ +/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */ +/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */ +/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */ +/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */ +/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */ +/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */ +/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */ +/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */ +/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */ +/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */ +/* OF SUCH DAMAGE. */ +/* -------------------------------------------------------------------------- */ +/* --- END LICENSE --- */ + +#include "../Mandshurica/mandshurica.h" +#include "../Mandshurica/ms_log.h" + +#include +#include + +const char mod_type[] = MS_MOD_AUTH; + +const char mod_auth_type[] = "Basic"; + +struct mandshurica_config* config; + +int mod_init(struct mandshurica_config* _config) { + config = _config; + config->mandshurica_log(MS_INFO, "Basic authentication Module init"); + return 0; +} diff --git a/Module/http.c b/Module/http.c index eccf479..b241a14 100644 --- a/Module/http.c +++ b/Module/http.c @@ -29,9 +29,11 @@ /* --- END LICENSE --- */ #include "../Mandshurica/mandshurica.h" + #include "../Mandshurica/ms_log.h" #include "../Mandshurica/ms_util.h" +#include #include #include #include @@ -56,12 +58,60 @@ int mod_init(struct mandshurica_config* _config) { char* log = mandshurica_strcat("HTTP Server will listen on port ", port); config->mandshurica_log(MS_INFO, log); free(log); + + char* root = config->mandshurica_get_param("HTTPRoot"); + if(root == NULL) root = WEBROOT_PREFIX; + log = mandshurica_strcat("HTTP Server root is ", root); + config->mandshurica_log(MS_INFO, log); + free(log); + + char* auth = malloc(1); + auth[0] = 0; + int count = 0; + + if((*config->libs) != NULL) { + int i; + for(i = 0; (*config->libs)[i] != NULL; i++) { + count++; + const char* type = (const char*)dlsym((*config->libs)[i]->lib, "mod_type"); + if(strcmp(type, MS_MOD_AUTH) == 0) { + const char* type = (const char*)dlsym((*config->libs)[i]->lib, "mod_auth_type"); + if(auth[0] == 0) { + char* tmp = auth; + auth = mandshurica_strdup(type); + free(tmp); + } else { + char* tmp = auth; + auth = mandshurica_strcat3(tmp, ", ", type); + free(tmp); + } + } + } + } + + if(count == 1) { + log = mandshurica_strcat("HTTP Server available uthentication method is ", auth[0] == 0 ? "(none)" : auth); + } else { + log = mandshurica_strcat("HTTP Server available authentication methods are ", auth[0] == 0 ? "(none)" : auth); + } + config->mandshurica_log(MS_INFO, log); + free(log); + free(auth); + + if(auth[0] == 0) { + config->mandshurica_log(MS_ERROR, "Authentication module was not loaded!"); + return 1; + } + return 0; } #define BUFFER_SIZE 512 void http_handler(int sock) { + char* root = config->mandshurica_get_param("HTTPRoot"); + if(root == NULL) root = WEBROOT_PREFIX; + char* buf = malloc(BUFFER_SIZE); char* method = NULL; char* path = NULL; @@ -126,6 +176,9 @@ void http_handler(int sock) { count++; if(count == 2) { if(strcmp(method, "GET") == 0) { + char* chpath = mandshurica_strcat3(root, "/", path); + chdir(chpath); + free(chpath); goto reset; } state = 0;