jabberd2
2.2.17
Main Page
Data Structures
Files
File List
Globals
router
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 "
router.h
"
22
25
typedef
struct
aci_user_st
*
aci_user_t
;
26
struct
aci_user_st
{
27
char
*
name
;
28
aci_user_t
next
;
29
};
30
31
xht
aci_load
(
router_t
r) {
32
xht
aci;
33
int
aelem, uelem, attr;
34
char
type[33];
35
aci_user_t list_head, list_tail, user;
36
37
log_debug
(
ZONE
,
"loading aci"
);
38
39
aci =
xhash_new
(51);
40
41
if
((aelem =
nad_find_elem
(r->
config
->
nad
, 0, -1,
"aci"
, 1)) < 0)
42
return
aci;
43
44
aelem =
nad_find_elem
(r->
config
->
nad
, aelem, -1,
"acl"
, 1);
45
while
(aelem >= 0) {
46
if
((attr =
nad_find_attr
(r->
config
->
nad
, aelem, -1,
"type"
, NULL)) < 0) {
47
aelem =
nad_find_elem
(r->
config
->
nad
, aelem, -1,
"acl"
, 0);
48
continue
;
49
}
50
51
list_head = NULL;
52
list_tail = NULL;
53
54
snprintf(type, 33,
"%.*s"
,
NAD_AVAL_L
(r->
config
->
nad
, attr),
NAD_AVAL
(r->
config
->
nad
, attr));
55
56
log_debug
(
ZONE
,
"building list for '%s'"
, type);
57
58
uelem =
nad_find_elem
(r->
config
->
nad
, aelem, -1,
"user"
, 1);
59
while
(uelem >= 0) {
60
if
(
NAD_CDATA_L
(r->
config
->
nad
, uelem) > 0) {
61
user = (
aci_user_t
) calloc(1,
sizeof
(
struct
aci_user_st
));
62
63
user->
name
= (
char
*) malloc(
sizeof
(
char
) * (
NAD_CDATA_L
(r->
config
->
nad
, uelem) + 1));
64
sprintf(user->
name
,
"%.*s"
,
NAD_CDATA_L
(r->
config
->
nad
, uelem),
NAD_CDATA
(r->
config
->
nad
, uelem));
65
66
if
(list_tail != NULL) {
67
list_tail->
next
= user;
68
list_tail = user;
69
}
70
71
/* record the head of the list */
72
if
(list_head == NULL) {
73
list_head = user;
74
list_tail = user;
75
}
76
77
log_debug
(
ZONE
,
"added '%s'"
, user->
name
);
78
}
79
80
uelem =
nad_find_elem
(r->
config
->
nad
, uelem, -1,
"user"
, 0);
81
}
82
83
if
(list_head != NULL)
84
xhash_put
(aci,
pstrdup
(
xhash_pool
(aci), type), (
void
*) list_head);
85
86
aelem =
nad_find_elem
(r->
config
->
nad
, aelem, -1,
"acl"
, 0);
87
}
88
89
return
aci;
90
}
91
93
int
aci_check
(
xht
aci,
const
char
*type,
const
char
*name) {
94
aci_user_t list, scan;
95
96
log_debug
(
ZONE
,
"checking for '%s' in acl 'all'"
, name);
97
list = (
aci_user_t
)
xhash_get
(aci,
"all"
);
98
for
(scan = list; scan != NULL; scan = scan->
next
)
99
if
(strcmp(scan->
name
, name) == 0)
100
return
1;
101
102
if
(type != NULL) {
103
log_debug
(
ZONE
,
"checking for '%s' in acl '%s'"
, name, type);
104
list = (
aci_user_t
)
xhash_get
(aci, type);
105
for
(scan = list; scan != NULL; scan = scan->
next
)
106
if
(strcmp(scan->
name
, name) == 0)
107
return
1;
108
}
109
110
return
0;
111
}
112
114
void
aci_unload
(
xht
aci) {
115
aci_user_t list, user;
116
117
/* free list of users for each acl*/
118
if
(
xhash_iter_first
(aci))
119
do
{
120
xhash_iter_get
(aci, NULL, NULL, (
void
*) &list);
121
while
(list != NULL) {
122
user = list;
123
list = list->
next
;
124
free(user->
name
);
125
free(user);
126
}
127
}
while
(
xhash_iter_next
(aci));
128
129
xhash_free
(aci);
130
return
;
131
}
Generated by
1.8.1.1