1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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 <serv/htcd.h>
const mstring default_tag=".default";
/////////////////////////////////////////////////////////////////
TOK_IMPL(remote_name) { out<<Reqd(env)->tcp->node.name; }
TOK_IMPL(remote_address) { out<<Reqd(env)->tcp->node.ip; }
TOK_IMPL(remote_port) { out<<Reqd(env)->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<<allow(Reqd(env)->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<<htcd->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.dbat<env.db->size()) {
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<<ok;
}
TOK_IMPL(ingroups) {
int ok=0;
if(!env.db) THROW("htc: no open database");
if(env.dbat>=0&&env.dbat<env.db->size()) {
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<<ok;
}
/////////////////////////////////////////////////////////////////
void envAddAuth(tokmap& T)
{
TOK_ADD(remote_name,"",tok_t::PUBLIC,
"%Remote hostname\n"
"%Syntax: \\remote.name\n"
);
TOK_ADD(remote_address,"",tok_t::PUBLIC,
"%Remote address\n"
"%Syntax: \\remote.address\n"
);
TOK_ADD(remote_port,"",tok_t::PUBLIC,
"%Remote port\n"
"%Syntax: \\remote.port\n"
);
/////////////////////////////////////////////////////////////
TOK_ADD(remote_allow,"x",tok_t::PUBLIC,
"%True if remote hostname allowed by domain\n"
"%Syntax: \\remote.allow{domain list}\n"
"%\n"
"%May be used to restrict access without any group\n"
);
TOK_ADD(bindroot,"x",tok_t::SYSONLY,
"%Bind root access to explicit addresses\n"
"%Syntax: \\bindroot{address list}\n"
"%\n"
"%Note that domain syntax does not work here; you\n"
"%want to have total control over all root access.\n"
);
/////////////////////////////////////////////////////////////
TOK_ADD(user_allow,"x?",tok_t::SYSONLY,
"%Core test on user clearance\n"
"%Syntax: \\user.allow{groups}<time>\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}<else>\n"
);
/////////////////////////////////////////////////////////////
TOK_ADD(allowed,"x?",tok_t::SYSONLY,
"%True if the current record is allowed in all groups now\n"
"%Syntax: \\allowed{groups}<time>\n"
"%\n"
"%Only used as a query function\n"
);
TOK_ADD(ingroups,"x?",tok_t::SYSONLY,
"%True if the current record is part of all groups now\n"
"%Syntax: \\ingroups{groups}<time>\n"
"%\n"
"%Only used as a query function\n"
);
}
|