jabberd2
2.2.17
Main Page
Data Structures
Files
File List
Globals
sm
aci.c
Go to the documentation of this file.
1
/*
2
* jabberd - Jabber Open Source Server
3
* Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
4
* Ryan Eatmon, Robert Norris
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19
*/
20
21
#include "
sm.h
"
22
30
xht
aci_load
(
sm_t
sm
)
31
{
32
xht
acls;
33
int
aelem, jelem, attr;
34
char
type[33];
35
jid_t
list, jid;
36
37
log_debug
(
ZONE
,
"loading aci"
);
38
39
acls =
xhash_new
(51);
40
41
if
((aelem =
nad_find_elem
(sm->
config
->
nad
, 0, -1,
"aci"
, 1)) < 0)
42
return
acls;
43
44
aelem =
nad_find_elem
(sm->
config
->
nad
, aelem, -1,
"acl"
, 1);
45
while
(aelem >= 0)
46
{
47
list = NULL;
48
49
if
((attr =
nad_find_attr
(sm->
config
->
nad
, aelem, -1,
"type"
, NULL)) < 0)
50
{
51
aelem =
nad_find_elem
(sm->
config
->
nad
, aelem, -1,
"acl"
, 0);
52
continue
;
53
}
54
55
snprintf(type, 33,
"%.*s"
,
NAD_AVAL_L
(sm->
config
->
nad
, attr),
NAD_AVAL
(sm->
config
->
nad
, attr));
56
57
log_debug
(
ZONE
,
"building list for '%s'"
, type);
58
59
jelem =
nad_find_elem
(sm->
config
->
nad
, aelem, -1,
"jid"
, 1);
60
while
(jelem >= 0)
61
{
62
if
(
NAD_CDATA_L
(sm->
config
->
nad
, jelem) > 0)
63
{
64
jid =
jid_new
(
NAD_CDATA
(sm->
config
->
nad
, jelem),
NAD_CDATA_L
(sm->
config
->
nad
, jelem));
65
list =
jid_append
(list, jid);
66
67
log_debug
(
ZONE
,
"added '%s'"
,
jid_user
(jid));
68
69
jid_free
(jid);
70
}
71
72
jelem =
nad_find_elem
(sm->
config
->
nad
, jelem, -1,
"jid"
, 0);
73
}
74
75
if
(list != NULL) {
76
xhash_put
(acls,
pstrdup
(
xhash_pool
(acls), type), (
void
*) list);
77
}
78
79
aelem =
nad_find_elem
(sm->
config
->
nad
, aelem, -1,
"acl"
, 0);
80
}
81
82
return
acls;
83
}
84
86
int
aci_check
(
xht
acls,
char
*type,
jid_t
jid)
87
{
88
jid_t
list, dup;
89
90
dup =
jid_dup
(jid);
91
if
(dup->
resource
[0]) {
92
/* resourceless version */
93
dup->
resource
[0] =
'\0'
;
94
dup->
dirty
= 1;
95
}
96
97
log_debug
(
ZONE
,
"checking for '%s' in acl 'all'"
,
jid_full
(jid));
98
list = (
jid_t
)
xhash_get
(acls,
"all"
);
99
if
(
jid_search
(list, jid)) {
100
jid_free
(dup);
101
return
1;
102
}
103
104
log_debug
(
ZONE
,
"checking for '%s' in acl 'all'"
,
jid_user
(dup));
105
if
(
jid_search
(list, dup)) {
106
jid_free
(dup);
107
return
1;
108
}
109
110
if
(type != NULL) {
111
log_debug
(
ZONE
,
"checking for '%s' in acl '%s'"
,
jid_full
(jid), type);
112
list = (
jid_t
)
xhash_get
(acls, type);
113
if
(
jid_search
(list, jid)) {
114
jid_free
(dup);
115
return
1;
116
}
117
118
log_debug
(
ZONE
,
"checking for '%s' in acl '%s'"
,
jid_user
(dup), type);
119
if
(
jid_search
(list, dup)) {
120
jid_free
(dup);
121
return
1;
122
}
123
}
124
125
jid_free
(dup);
126
return
0;
127
}
128
129
void
aci_unload
(
xht
acls)
130
{
131
jid_t
list, jid;
132
133
log_debug
(
ZONE
,
"unloading acls"
);
134
135
if
(
xhash_iter_first
(acls))
136
do
{
137
xhash_iter_get
(acls, NULL, NULL, (
void
*) &list);
138
while
(list != NULL) {
139
jid = list;
140
list = list->
next
;
141
jid_free
(jid);
142
}
143
}
while
(
xhash_iter_next
(acls));
144
145
return
;
146
}
Generated by
1.8.1.1