jabberd2
2.2.16
|
00001 /* 00002 * jabberd - Jabber Open Source Server 00003 * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 00004 * Ryan Eatmon, Robert Norris 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 00019 */ 00020 00021 #include "router.h" 00022 00025 typedef struct aci_user_st *aci_user_t; 00026 struct aci_user_st { 00027 char *name; 00028 aci_user_t next; 00029 }; 00030 00031 xht aci_load(router_t r) { 00032 xht aci; 00033 int aelem, uelem, attr; 00034 char type[33]; 00035 aci_user_t list_head, list_tail, user; 00036 00037 log_debug(ZONE, "loading aci"); 00038 00039 aci = xhash_new(51); 00040 00041 if((aelem = nad_find_elem(r->config->nad, 0, -1, "aci", 1)) < 0) 00042 return aci; 00043 00044 aelem = nad_find_elem(r->config->nad, aelem, -1, "acl", 1); 00045 while(aelem >= 0) { 00046 if((attr = nad_find_attr(r->config->nad, aelem, -1, "type", NULL)) < 0) { 00047 aelem = nad_find_elem(r->config->nad, aelem, -1, "acl", 0); 00048 continue; 00049 } 00050 00051 list_head = NULL; 00052 list_tail = NULL; 00053 00054 snprintf(type, 33, "%.*s", NAD_AVAL_L(r->config->nad, attr), NAD_AVAL(r->config->nad, attr)); 00055 00056 log_debug(ZONE, "building list for '%s'", type); 00057 00058 uelem = nad_find_elem(r->config->nad, aelem, -1, "user", 1); 00059 while(uelem >= 0) { 00060 if(NAD_CDATA_L(r->config->nad, uelem) > 0) { 00061 user = (aci_user_t) calloc(1, sizeof(struct aci_user_st)); 00062 00063 user->name = (char *) malloc(sizeof(char) * (NAD_CDATA_L(r->config->nad, uelem) + 1)); 00064 sprintf(user->name, "%.*s", NAD_CDATA_L(r->config->nad, uelem), NAD_CDATA(r->config->nad, uelem)); 00065 00066 if(list_tail != NULL) { 00067 list_tail->next = user; 00068 list_tail = user; 00069 } 00070 00071 /* record the head of the list */ 00072 if(list_head == NULL) { 00073 list_head = user; 00074 list_tail = user; 00075 } 00076 00077 log_debug(ZONE, "added '%s'", user->name); 00078 } 00079 00080 uelem = nad_find_elem(r->config->nad, uelem, -1, "user", 0); 00081 } 00082 00083 if(list_head != NULL) 00084 xhash_put(aci, pstrdup(xhash_pool(aci), type), (void *) list_head); 00085 00086 aelem = nad_find_elem(r->config->nad, aelem, -1, "acl", 0); 00087 } 00088 00089 return aci; 00090 } 00091 00093 int aci_check(xht aci, const char *type, const char *name) { 00094 aci_user_t list, scan; 00095 00096 log_debug(ZONE, "checking for '%s' in acl 'all'", name); 00097 list = (aci_user_t) xhash_get(aci, "all"); 00098 for(scan = list; scan != NULL; scan = scan->next) 00099 if(strcmp(scan->name, name) == 0) 00100 return 1; 00101 00102 if(type != NULL) { 00103 log_debug(ZONE, "checking for '%s' in acl '%s'", name, type); 00104 list = (aci_user_t) xhash_get(aci, type); 00105 for(scan = list; scan != NULL; scan = scan->next) 00106 if(strcmp(scan->name, name) == 0) 00107 return 1; 00108 } 00109 00110 return 0; 00111 } 00112 00114 void aci_unload(xht aci) { 00115 aci_user_t list, user; 00116 00117 /* free list of users for each acl*/ 00118 if(xhash_iter_first(aci)) 00119 do { 00120 xhash_iter_get(aci, NULL, NULL, (void *) &list); 00121 while (list != NULL) { 00122 user = list; 00123 list = list->next; 00124 free(user->name); 00125 free(user); 00126 } 00127 } while(xhash_iter_next(aci)); 00128 00129 xhash_free(aci); 00130 return; 00131 }