]> Nishi Git Mirror - mandshurica.git/commitdiff
basic
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Mon, 15 Apr 2024 02:21:47 +0000 (02:21 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Mon, 15 Apr 2024 02:21:47 +0000 (02:21 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@24 f982e544-4a7d-3444-ad1a-fde59a2a69f1

Mandshurica/config.c
Mandshurica/mandshurica.h
Module/Makefile
Module/basic.c [new file with mode: 0644]
Module/http.c

index 32e76c4d1c36878fb74e35d0cd4db3e4c07f8ecd..9811011e5f889fe7761064a7a198632b6f48cbde 100644 (file)
@@ -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);
index 8c14c50d7257db5dbb3b54497cd03cc3b191d779..a5953ac301689421fb3fe8a29b884a4c4a83bada 100644 (file)
 #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
index c538330fb71ecefa8df4b53e0869f6a55e8486ae..24185c05fcfe28b20c1014b0b2a3a92a9346935c 100644 (file)
@@ -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 (file)
index 0000000..c03708a
--- /dev/null
@@ -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 <string.h>
+#include <syslog.h>
+
+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;
+}
index eccf4794aaf64836cb39bf3e6c56aaba8073c14d..b241a14b46fc8ce55e6ac0d089dcf52d4e52ca19 100644 (file)
 /* --- END LICENSE --- */
 
 #include "../Mandshurica/mandshurica.h"
+
 #include "../Mandshurica/ms_log.h"
 #include "../Mandshurica/ms_util.h"
 
+#include <dlfcn.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <stddef.h>
@@ -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;