+ }
+ return 0;
+}
+
+static int OS_DBSearchKeyAddressValue(ListRule *lrule, char *key)
+{
+ int result = -1;
+ char *val;
+ unsigned vlen, vpos;
+ if (lrule->db != NULL) {
+ if (_OS_CDBOpen(lrule->db) == -1) {
+ return 0;
+ }
+
+ /* First lookup for a single IP address */
+ if (cdb_find(&lrule->db->cdb, key, strlen(key)) > 0 ) {
+ vpos = cdb_datapos(&lrule->db->cdb);
+ vlen = cdb_datalen(&lrule->db->cdb);
+ val = (char *) malloc(vlen);
+ if(val == NULL) {
+ merror("%s: malloc failed", ARGV0);
+ return(0);
+ }
+ cdb_read(&lrule->db->cdb, val, vlen, vpos);
+ result = OSMatch_Execute(val, vlen, lrule->matcher);
+ free(val);
+ return result;
+ } else {
+ /* IP address not found, look for matching subnets */
+ char *tmpkey;
+ os_strdup(key, tmpkey);
+ while (strlen(tmpkey) > 0) {
+ if (tmpkey[strlen(tmpkey) - 1] == '.') {
+ if ( cdb_find(&lrule->db->cdb, tmpkey, strlen(tmpkey)) > 0 ) {
+ vpos = cdb_datapos(&lrule->db->cdb);
+ vlen = cdb_datalen(&lrule->db->cdb);
+ val = (char *) malloc(vlen);
+ cdb_read(&lrule->db->cdb, val, vlen, vpos);
+ result = OSMatch_Execute(val, vlen, lrule->matcher);
+ free(val);
+ free(tmpkey);
+ return result;
+ }
+ }
+ tmpkey[strlen(tmpkey) - 1] = '\0';
+ }
+ free(tmpkey);
+ return 0;
+ }
+ }