From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/serv/auth.cc | 162 ++++++++++++++++++++++++++++++ src/serv/const.cc | 69 +++++++++++++ src/serv/direct.cc | 73 ++++++++++++++ src/serv/form.cc | 102 +++++++++++++++++++ src/serv/htcd.h | 74 ++++++++++++++ src/serv/htcs.cc | 92 +++++++++++++++++ src/serv/main.cc | 122 +++++++++++++++++++++++ src/serv/request.cc | 279 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/serv/tempmap.cc | 82 +++++++++++++++ src/serv/tempmap.h | 57 +++++++++++ 10 files changed, 1112 insertions(+) create mode 100644 src/serv/auth.cc create mode 100644 src/serv/const.cc create mode 100644 src/serv/direct.cc create mode 100644 src/serv/form.cc create mode 100644 src/serv/htcd.h create mode 100644 src/serv/htcs.cc create mode 100644 src/serv/main.cc create mode 100644 src/serv/request.cc create mode 100644 src/serv/tempmap.cc create mode 100644 src/serv/tempmap.h (limited to 'src/serv') diff --git a/src/serv/auth.cc b/src/serv/auth.cc new file mode 100644 index 0000000..abf16b3 --- /dev/null +++ b/src/serv/auth.cc @@ -0,0 +1,162 @@ +/************************************************************************* + * + * HTCd - Copyright (C) 1998-2006 Henrik Rydberg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +const mstring default_tag=".default"; + +///////////////////////////////////////////////////////////////// + +TOK_IMPL(remote_name) { out<tcp->node.name; } +TOK_IMPL(remote_address) { out<tcp->node.ip; } +TOK_IMPL(remote_port) { out<tcp->port; } + +///////////////////////////////////////////////////////////////// + +inline int match(const sref& rem,const sref& longrem,const sref& dom) +{ + if(rem==dom) return 1; + if(*dom!='.') return 0; + if(longrem.right_last(dom)==dom) return 1; + return 0; +} + +inline int allow(const sref& uname,const sref& list) +{ + mstring remote=First(uname); + mstring longrem=remote; if(longrem.find('.')<0) longrem+=default_tag; + if(remote.empty()) return 0; + if(First(list).empty()) return 1; + sref first,rest=list; + while(Split(first,rest)) if(match(remote,longrem,first)) return 1; + return 0; +} + +TOK_IMPL(remote_allow) { out<tcp->node.name,env[0]); } +TOK_IMPL(bindroot) { Reqd(env)->htcd()->bindroot=env[0]; } + +///////////////////////////////////////////////////////////////// + +TOK_IMPL(user_allow) { + htcd_req* htcd=Reqd(env); + mstring opt=env.parg(-1); + int now=opt.empty()?time(0):atoi(opt); + out<user.allow_list(env[0],now,htcd->RootAllowed()); +} + +TOK_IMPL(on_clear) { + htcd_req* htcd=Reqd(env); + if(htcd->user.allow_list(env[0],time(0),htcd->RootAllowed())) env.parg(out,1); + else env.parg(out,2); +} + +///////////////////////////////////////////////////////////////// + +TOK_IMPL(allowed) { + int ok=0; + if(!env.db) THROW("htc: no open database"); + if(env.dbat>=0&&env.dbatsize()) { + user_t user; + env.db->Get(env.dbat,user.list); + if(user.list.size()!=user_tabs) + THROW("htc: cannot test - probably not a users database"); + mstring opt=env.parg(-1); + int now=opt.empty()?time(0):atoi(opt); + ok=user.allow_list(env[0],now,Reqd(env)->RootAllowed()); + } + out<=0&&env.dbatsize()) { + user_t user; + env.db->Get(env.dbat,user.list); + if(user.list.size()!=user_tabs) + THROW("htc: cannot test - probably not a users database"); + mstring opt=env.parg(-1); + int now=opt.empty()?time(0):atoi(opt); + ok=user.allow_list(env[0],now,-1); + } + out<\n" + "%\n" + "%In case of several groups, all must be allowed.\n" + ); + TOK_ADD(on_clear,"xr?",tok_t::SYSONLY, + "%Do if user is allowed in all groups now\n" + "%Syntax: \\on.clear{groups}{body}\n" + ); + + ///////////////////////////////////////////////////////////// + + TOK_ADD(allowed,"x?",tok_t::SYSONLY, + "%True if the current record is allowed in all groups now\n" + "%Syntax: \\allowed{groups}