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);
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);
#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
.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)
--- /dev/null
+/* $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;
+}
/* --- 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>
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;
count++;
if(count == 2) {
if(strcmp(method, "GET") == 0) {
+ char* chpath = mandshurica_strcat3(root, "/", path);
+ chdir(chpath);
+ free(chpath);
goto reset;
}
state = 0;