1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
5 * Copyright (C) 2001-2009, Eduardo Silva P.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 /* Plugin data for register */
31 mk_plugin_data_t _name
= "Security";
32 mk_plugin_data_t _version
= "0.1";
33 mk_plugin_stage_t _stages
= MK_PLUGIN_STAGE_20
;
35 struct plugin_api
*mk_api
;
36 struct mk_config
*conf
;
38 /* Read database configuration parameters */
39 int mk_security_conf()
45 struct mk_security
*new, *r
;
47 mk_api
->str_build(&conf_path
,
50 mk_api
->config
->serverconf
);
52 p
= conf
= mk_api
->config_create(conf_path
);
56 /* Passing to internal struct */
57 new = mk_api
->mem_alloc(sizeof(struct mk_security
));
58 if(strcasecmp(p
->key
, "IP") == 0){
59 new->type
= MK_SECURITY_TYPE_IP
;
61 else if(strcasecmp(p
->key
, "URL") == 0){
62 new->type
= MK_SECURITY_TYPE_URL
;
82 mk_api
->mem_free(conf_path
);
86 int mk_security_check_ip(char *ipv4
)
89 struct mk_security
*p
;
93 if(p
->type
== MK_SECURITY_TYPE_IP
){
94 for(i
=0; p
->value
[i
]; i
++) {
95 if (p
->value
[i
]=='?') {
96 if (ipv4
[i
]=='.' || ipv4
[i
]=='\0')
102 if (p
->value
[i
]=='*')
105 if (p
->value
[i
]!=ipv4
[i
])
120 int _mk_plugin_init(void **api
)
125 /* Read configuration */
130 int _mk_plugin_stage_20(unsigned int socket
, struct sched_connection
*conx
,
131 struct client_request
*cr
)
134 if(mk_security_check_ip(conx
->ipv4
)!=0){
135 return MK_PLUGIN_RET_CLOSE_CONX
;