17#include <hiredis/hiredis.h>
27#define G_LOG_DOMAIN "libgvm util"
29#if GLIB_CHECK_VERSION(2, 67, 3)
30#define memdup g_memdup2
32#define memdup g_memdup
45#define GLOBAL_DBINDEX_NAME "GVM.__GlobalDBIndex"
62#define redis_kb(__kb) ((struct kb_redis *) (__kb))
80 redisContext *ctx = kbr->
rctx;
88 if (rep->type != REDIS_REPLY_INTEGER)
90 else if (rep->integer == 0)
95 freeReplyObject (rep);
112 redisContext *ctx = kbr->
rctx;
113 redisReply *rep = NULL;
115 rep = redisCommand (ctx,
"CONFIG GET databases");
119 "%s: redis command failed with '%s'", __func__, ctx->errstr);
124 if (rep->type != REDIS_REPLY_ARRAY)
127 "%s: cannot retrieve max DB number: %s", __func__, rep->str);
132 if (rep->elements == 2)
134 kbr->
max_db = (unsigned) atoi (rep->element[1]->str);
139 "%s: unexpected reply length (%zd)", __func__, rep->elements);
144 g_debug (
"%s: maximum DB number: %u", __func__, kbr->
max_db);
148 freeReplyObject (rep);
167 redisContext *ctx = kbr->
rctx;
168 redisReply *rep = NULL;
177 for (i = 1; i < kbr->
max_db; i++)
192 rep = redisCommand (ctx,
"SELECT %u", kbr->
db);
193 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
203 freeReplyObject (rep);
219 redisContext *ctx = kbr->
rctx;
225 rep = redisCommand (ctx,
"SELECT 0");
226 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
231 freeReplyObject (rep);
234 if (rep == NULL || rep->type != REDIS_REPLY_INTEGER)
244 freeReplyObject (rep);
254 tmp = strrchr (addr + tcp_indicator_len,
':');
257 is_ip_v6 = addr[tcp_indicator_len] ==
'[';
258 if (is_ip_v6 && (tmp - 1)[0] !=
']')
266 const char *tcp_indicator =
"tcp://";
267 const int tcp_indicator_len = strlen (tcp_indicator);
268 const int redis_default_port = 6379;
272 redisContext *result;
273 static int warn_flag = 0;
275 if (len < tcp_indicator_len + 1)
277 if (memcmp (addr, tcp_indicator, tcp_indicator_len) != 0)
279 host_len = len - tcp_indicator_len;
282 port = redis_default_port;
286 host_len -= strlen (tmp) + 1;
288 host = calloc (1, host_len);
289 memmove (host, addr + tcp_indicator_len, host_len);
290 result = redisConnect (host, port);
293 g_warning (
"A Redis TCP connection is being used. This feature is "
294 "experimental and insecure, since it is not an encrypted "
295 "channel. We discourage its usage in production environments");
301 return redisConnectUnix (addr);
318 if (kbr->
rctx != NULL)
322 if (kbr->
rctx == NULL || kbr->
rctx->err)
325 "%s: redis connection error to %s: %s", __func__, kbr->
path,
326 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
327 redisFree (kbr->
rctx);
335 g_log (
G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"No redis DB available");
336 redisFree (kbr->
rctx);
341 g_debug (
"%s: connected to redis://%s/%d", __func__, kbr->
path, kbr->
db);
367 if (rep->type != REDIS_REPLY_STATUS)
373 if (g_ascii_strcasecmp (rep->str,
"PONG"))
381 freeReplyObject (rep);
403 if (kbr->
rctx != NULL)
406 redisFree (kbr->
rctx);
450 if (!rep || rep->type == REDIS_REPLY_ERROR)
453 freeReplyObject (rep);
476 kbr = g_malloc0 (
sizeof (
struct kb_redis));
478 kbr->
path = g_strdup (kb_path);
489 "%s: cannot access redis at '%s'", __func__, kb_path);
502 g_warning (
"%s: Memory purge was not successful", __func__);
524 kbr = g_malloc0 (
sizeof (
struct kb_redis));
526 kbr->
path = g_strdup (kb_path);
529 if (kbr->
rctx == NULL || kbr->
rctx->err)
532 "%s: redis connection error to %s: %s", __func__, kbr->
path,
533 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
534 redisFree (kbr->
rctx);
540 rep = redisCommand (kbr->
rctx,
"SELECT %d", kb_index);
541 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
544 freeReplyObject (rep);
545 redisFree (kbr->
rctx);
551 freeReplyObject (rep);
572 kbr = g_malloc0 (
sizeof (
struct kb_redis));
574 kbr->
path = g_strdup (kb_path);
581 if (kbr->
rctx == NULL || kbr->
rctx->err)
584 "%s: redis connection error to %s: %s", __func__, kbr->
path,
585 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
586 redisFree (kbr->
rctx);
597 if (rep == NULL || rep->type != REDIS_REPLY_INTEGER || rep->integer != 1)
600 freeReplyObject (rep);
602 redisFree (kbr->
rctx);
606 freeReplyObject (rep);
607 rep = redisCommand (kbr->
rctx,
"SELECT %u", i);
608 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
610 redisFree (kbr->
rctx);
615 freeReplyObject (rep);
625 redisFree (kbr->
rctx);
650 g_free (item->
v_str);
671 if (elt->type != REDIS_REPLY_STRING && elt->type != REDIS_REPLY_INTEGER)
677 if (elt->type == REDIS_REPLY_INTEGER)
680 item->
v_int = elt->integer;
685 item->
v_int = atoi (elt->str);
691 item->
len = elt->len;
721 case REDIS_REPLY_STRING:
722 case REDIS_REPLY_INTEGER:
726 case REDIS_REPLY_ARRAY:
727 for (i = 0; i < rep->elements; i++)
745 case REDIS_REPLY_NIL:
746 case REDIS_REPLY_STATUS:
747 case REDIS_REPLY_ERROR:
780 rep = redisvCommand (kbr->
rctx, fmt, aq);
786 freeReplyObject (rep);
821 rep =
redis_cmd (kbr,
"LINDEX %s -1", name);
822 if (rep == NULL || rep->type != REDIS_REPLY_STRING)
832 freeReplyObject (rep);
877 redisReply *rep = NULL;
884 rep =
redis_cmd (kbr,
"LPUSH %s %s", name, value);
885 if (!rep || rep->type == REDIS_REPLY_ERROR)
889 freeReplyObject (rep);
914 if (rep->type == REDIS_REPLY_STRING)
915 value = g_strdup (rep->str);
916 freeReplyObject (rep);
964 rep =
redis_cmd (kbr,
"LINDEX filename:%s %d", oid,
967 rep =
redis_cmd (kbr,
"LINDEX nvt:%s %d", oid, position);
970 if (rep->type == REDIS_REPLY_INTEGER)
971 res = g_strdup_printf (
"%lld", rep->integer);
972 else if (rep->type == REDIS_REPLY_STRING)
973 res = g_strdup (rep->str);
974 freeReplyObject (rep);
998 if (rep->type != REDIS_REPLY_ARRAY || rep->elements !=
NVT_NAME_POS + 1)
1000 freeReplyObject (rep);
1023 freeReplyObject (rep);
1052 freeReplyObject (rep);
1075 rep =
redis_cmd (kbr,
"KEYS %s", pattern);
1078 if (rep->type != REDIS_REPLY_ARRAY)
1080 freeReplyObject (rep);
1086 for (i = 0; i < rep->elements; i++)
1087 redisAppendCommand (kbr->
rctx,
"LRANGE %s 0 -1", rep->element[i]->str);
1089 for (i = 0; i < rep->elements; i++)
1092 redisReply *rep_range;
1094 redisGetReply (kbr->
rctx, (
void **) &rep_range);
1100 freeReplyObject (rep_range);
1116 freeReplyObject (rep_range);
1119 freeReplyObject (rep);
1135 GSList *list = NULL;
1143 if (rep->type != REDIS_REPLY_ARRAY)
1145 freeReplyObject (rep);
1150 for (i = 0; i < rep->elements; i++)
1151 list = g_slist_prepend (list, g_strdup (rep->element[i]->str + 4));
1152 freeReplyObject (rep);
1174 rep =
redis_cmd (kbr,
"KEYS %s", pattern);
1178 if (rep->type != REDIS_REPLY_ARRAY)
1180 freeReplyObject (rep);
1184 count = rep->elements;
1185 freeReplyObject (rep);
1207 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1211 freeReplyObject (rep);
1231 int expire,
size_t len,
int pos)
1234 redisReply *rep = NULL;
1249 redisAppendCommand (ctx,
"LREM %s 1 %s", name, str);
1250 redisAppendCommand (ctx,
"%s %s %s", pos ?
"LPUSH" :
"RPUSH", name, str);
1251 redisAppendCommand (ctx,
"EXPIRE %s %d", name, expire);
1253 redisGetReply (ctx, (
void **) &rep);
1254 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1255 g_debug (
"Key '%s' already contained value '%s'", name, str);
1256 freeReplyObject (rep);
1258 redisGetReply (ctx, (
void **) &rep);
1259 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1265 redisGetReply (ctx, (
void **) &rep);
1266 if (rep == NULL || rep->type == REDIS_REPLY_ERROR
1267 || (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer != 1))
1269 g_warning (
"%s: Not able to set expire", __func__);
1276 redisAppendCommand (ctx,
"LREM %s 1 %b", name, str, len);
1277 redisAppendCommand (ctx,
"%s %s %b", pos ?
"LPUSH" :
"RPUSH", name, str,
1279 redisAppendCommand (ctx,
"EXPIRE %s %d", name, expire);
1281 redisGetReply (ctx, (
void **) &rep);
1282 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1283 g_debug (
"Key '%s' already contained string '%s'", name, str);
1284 freeReplyObject (rep);
1286 redisGetReply (ctx, (
void **) &rep);
1287 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1293 redisGetReply (ctx, (
void **) &rep);
1294 if (rep == NULL || rep->type == REDIS_REPLY_ERROR
1295 || (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer != 1))
1297 g_warning (
"%s: Not able to set expire", __func__);
1305 freeReplyObject (rep);
1327 redisReply *rep = NULL;
1342 redisAppendCommand (ctx,
"LREM %s 1 %s", name, str);
1343 redisAppendCommand (ctx,
"%s %s %s", pos ?
"LPUSH" :
"RPUSH", name, str);
1344 redisGetReply (ctx, (
void **) &rep);
1345 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1346 g_debug (
"Key '%s' already contained value '%s'", name, str);
1347 freeReplyObject (rep);
1348 redisGetReply (ctx, (
void **) &rep);
1352 redisAppendCommand (ctx,
"LREM %s 1 %b", name, str, len);
1353 redisAppendCommand (ctx,
"%s %s %b", pos ?
"LPUSH" :
"RPUSH", name, str,
1355 redisGetReply (ctx, (
void **) &rep);
1356 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1357 g_debug (
"Key '%s' already contained string '%s'", name, str);
1358 freeReplyObject (rep);
1359 redisGetReply (ctx, (
void **) &rep);
1361 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1365 freeReplyObject (rep);
1389 rep =
redis_cmd (kbr,
"RPUSH %s %s", name, str);
1391 rep =
redis_cmd (kbr,
"RPUSH %s %b", name, str, len);
1392 if (!rep || rep->type == REDIS_REPLY_ERROR)
1396 freeReplyObject (rep);
1414 redisReply *rep = NULL;
1422 redisAppendCommand (ctx,
"MULTI");
1423 redisAppendCommand (ctx,
"DEL %s", name);
1425 redisAppendCommand (ctx,
"RPUSH %s %s", name, val);
1427 redisAppendCommand (ctx,
"RPUSH %s %b", name, val, len);
1428 redisAppendCommand (ctx,
"EXEC");
1431 redisGetReply (ctx, (
void **) &rep);
1432 if (!rep || rep->type == REDIS_REPLY_ERROR)
1435 freeReplyObject (rep);
1463 redisAppendCommand (ctx,
"LREM %s 1 %d", name, val);
1464 redisAppendCommand (ctx,
"RPUSH %s %d", name, val);
1465 redisAppendCommand (ctx,
"EXPIRE %s %d", name, expire);
1467 redisGetReply (ctx, (
void **) &rep);
1468 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1469 g_debug (
"Key '%s' already contained integer '%d'", name, val);
1470 freeReplyObject (rep);
1472 redisGetReply (ctx, (
void **) &rep);
1473 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1479 redisGetReply (ctx, (
void **) &rep);
1480 if (rep == NULL || rep->type == REDIS_REPLY_ERROR
1481 || (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer != 1))
1483 g_warning (
"%s: Not able to set expire", __func__);
1490 freeReplyObject (rep);
1516 redisAppendCommand (ctx,
"LREM %s 1 %d", name, val);
1517 redisAppendCommand (ctx,
"RPUSH %s %d", name, val);
1518 redisGetReply (ctx, (
void **) &rep);
1519 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1520 g_debug (
"Key '%s' already contained integer '%d'", name, val);
1521 freeReplyObject (rep);
1522 redisGetReply (ctx, (
void **) &rep);
1523 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1531 freeReplyObject (rep);
1552 if (!rep || rep->type == REDIS_REPLY_ERROR)
1555 freeReplyObject (rep);
1573 redisReply *rep = NULL;
1581 redisAppendCommand (ctx,
"MULTI");
1582 redisAppendCommand (ctx,
"DEL %s", name);
1583 redisAppendCommand (ctx,
"RPUSH %s %d", name, val);
1584 redisAppendCommand (ctx,
"EXEC");
1587 redisGetReply (ctx, (
void **) &rep);
1588 if (!rep || rep->type == REDIS_REPLY_ERROR)
1591 freeReplyObject (rep);
1610 redisReply *rep = NULL;
1613 gchar *cves, *bids, *xrefs;
1615 if (!nvt || !filename)
1620 xrefs =
nvti_refs (nvt, NULL,
"cve,bid", 1);
1624 kbr,
"RPUSH nvt:%s %s %s %s %s %s %s %s %s %s %s %s %d %s %s",
1638 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1641 freeReplyObject (rep);
1649 rep =
redis_cmd (kbr,
"RPUSH oid:%s:prefs %d|||%s|||%s|||%s",
1652 if (!rep || rep->type == REDIS_REPLY_ERROR)
1655 freeReplyObject (rep);
1657 rep =
redis_cmd (kbr,
"RPUSH filename:%s %lu %s", filename, time (NULL),
1659 if (!rep || rep->type == REDIS_REPLY_ERROR)
1662 freeReplyObject (rep);
1681 if (kbr->
rctx != NULL)
1683 redisFree (kbr->
rctx);
1706 redisFree (kbr->
rctx);
1708 g_debug (
"%s: deleting all DBs at %s except %s", __func__, kbr->
path, except);
1714 if (kbr->
rctx == NULL || kbr->
rctx->err)
1717 "%s: redis connection error to %s: %s", __func__, kbr->
path,
1718 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
1719 redisFree (kbr->
rctx);
1726 if (rep == NULL || rep->type != REDIS_REPLY_INTEGER || rep->integer != 1)
1728 freeReplyObject (rep);
1729 redisFree (kbr->
rctx);
1733 freeReplyObject (rep);
1734 rep = redisCommand (kbr->
rctx,
"SELECT %u", i);
1735 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1737 freeReplyObject (rep);
1738 redisFree (kbr->
rctx);
1743 freeReplyObject (rep);
1752 redisFree (kbr->
rctx);
1758 redisFree (kbr->
rctx);
1784 g_debug (
"%s: saving all elements from KB #%u", __func__, kbr->
db);
1786 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1796 freeReplyObject (rep);
1813 struct sigaction new_action, original_action;
1816 new_action.sa_flags = 0;
1817 if (sigemptyset (&new_action.sa_mask))
1819 new_action.sa_handler = SIG_IGN;
1820 if (sigaction (SIGPIPE, &new_action, &original_action))
1824 g_debug (
"%s: deleting all elements from KB #%u", __func__, kbr->
db);
1826 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1835 if (sigaction (SIGPIPE, &original_action, NULL))
1838 freeReplyObject (rep);
#define G_LOG_DOMAIN
GLib log domain.
Definition array.c:17
static int redis_lnk_reset(kb_t)
Reset connection to the KB. This is called after each fork() to make sure connections aren't shared b...
Definition kb.c:1675
static const struct kb_operations KBRedisOperations
Default KB operations.
Definition kb.c:47
static int get_redis_ctx(struct kb_redis *kbr)
Get redis context if it is already connected or do a a connection.
Definition kb.c:314
static int redis_push_str(kb_t kb, const char *name, const char *value)
Push a new entry under a given key.
Definition kb.c:874
static int redis_memory_purge(kb_t kb)
Attempt to purge dirty pages.
Definition kb.c:444
static int redis_test_connection(struct kb_redis *kbr)
Test redis connection.
Definition kb.c:353
static int redis_set_str(kb_t kb, const char *name, const char *val, size_t len)
Set (replace) a new entry under a given name.
Definition kb.c:1411
static int redis_add_str_unique_volatile(kb_t kb, const char *name, const char *str, int expire, size_t len, int pos)
Insert (append) a new unique and volatile entry under a given name.
Definition kb.c:1230
static char * redis_get_nvt(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition kb.c:956
static struct kb_item * redis2kbitem(const char *name, const redisReply *rep)
Fetch a KB item or list from a redis Reply.
Definition kb.c:711
static kb_t redis_find(const char *kb_path, const char *key)
Find an existing Knowledge Base object with key.
Definition kb.c:564
static int redis_delete(kb_t kb)
Delete all entries and release ownership on the namespace.
Definition kb.c:394
static int redis_add_str(kb_t kb, const char *name, const char *str, size_t len)
Insert (append) a new entry under a given name.
Definition kb.c:1381
static int select_database(struct kb_redis *kbr)
Select DB.
Definition kb.c:164
static int redis_delete_all(struct kb_redis *)
Delete all the KB's content.
Definition kb.c:1809
void kb_item_free(struct kb_item *item)
Release a KB item (or a list).
Definition kb.c:642
static int redis_add_int_unique_volatile(kb_t kb, const char *name, int val, int expire)
Insert (append) a new unique entry under a given name.
Definition kb.c:1452
static char * parse_port_of_addr(const char *addr, int tcp_indicator_len)
Definition kb.c:250
static struct kb_item * redis_get_all(kb_t kb, const char *name)
Get all items stored under a given name.
Definition kb.c:1038
#define memdup
Definition kb.c:32
static int redis_add_int(kb_t kb, const char *name, int val)
Insert (append) a new entry under a given name.
Definition kb.c:1546
static kb_t redis_direct_conn(const char *kb_path, const int kb_index)
Connect to a Knowledge Base object with the given kb_index.
Definition kb.c:516
static int redis_add_str_unique(kb_t kb, const char *name, const char *str, size_t len, int pos)
Insert (append) a new unique entry under a given name.
Definition kb.c:1323
static char * redis_get_str(kb_t kb, const char *name)
Get a single KB string item.
Definition kb.c:847
static struct kb_item * redis_get_pattern(kb_t kb, const char *pattern)
Get all items stored under a given pattern.
Definition kb.c:1067
static GSList * redis_get_oids(kb_t kb)
Get all NVT OIDs.
Definition kb.c:1131
static struct kb_item * redis2kbitem_single(const char *name, const redisReply *elt, int force_int)
Give a single KB item.
Definition kb.c:666
static int redis_save(kb_t kb)
Save all the elements from the KB.
Definition kb.c:1777
static int redis_get_int(kb_t kb, const char *name)
Get a single KB integer item.
Definition kb.c:930
static redisContext * connect_redis(const char *addr, int len)
Definition kb.c:264
static char * redis_pop_str(kb_t kb, const char *name)
Pops a single KB string item.
Definition kb.c:903
static int redis_new(kb_t *kb, const char *kb_path)
Initialize a new Knowledge Base object.
Definition kb.c:468
static int redis_get_kb_index(kb_t kb)
Return the kb index.
Definition kb.c:422
static int redis_add_int_unique(kb_t kb, const char *name, int val)
Insert (append) a new unique entry under a given name.
Definition kb.c:1505
#define redis_kb(__kb)
Definition kb.c:62
static int try_database_index(struct kb_redis *kbr, int index)
Attempt to atomically acquire ownership of a database.
Definition kb.c:78
#define GLOBAL_DBINDEX_NAME
Name of the namespace usage bitmap in redis.
Definition kb.c:45
const struct kb_operations * KBDefaultOperations
Default KB operations. No selection mechanism is provided yet since there's only one implementation (...
Definition kb.c:1880
static int redis_flush_all(kb_t, const char *)
Flush all the KB's content. Delete all namespaces.
Definition kb.c:1699
static size_t redis_count(kb_t kb, const char *pattern)
Count all items stored under a given pattern.
Definition kb.c:1166
static int redis_release_db(struct kb_redis *kbr)
Release DB.
Definition kb.c:216
static struct kb_item * redis_get_single(kb_t kb, const char *name, enum kb_item_type type)
Get a single KB element.
Definition kb.c:812
static int redis_set_int(kb_t kb, const char *name, int val)
Set (replace) a new entry under a given name.
Definition kb.c:1570
static int redis_add_nvt(kb_t kb, const nvti_t *nvt, const char *filename)
Insert a new nvt.
Definition kb.c:1607
static int fetch_max_db_index(struct kb_redis *kbr)
Set the number of databases have been configured into kbr struct.
Definition kb.c:109
static redisReply * redis_cmd(struct kb_redis *kbr, const char *fmt,...)
Execute a redis command and get a redis reply.
Definition kb.c:764
static nvti_t * redis_get_nvt_all(kb_t kb, const char *oid)
Get a full NVT.
Definition kb.c:988
static int redis_del_items(kb_t kb, const char *name)
Delete all entries under a given name.
Definition kb.c:1198
Knowledge base management API - Redis backend.
kb_nvt_pos
Possible positions of nvt values in cache list.
Definition kb.h:45
@ NVT_FAMILY_POS
Definition kb.h:58
@ NVT_CATEGORY_POS
Definition kb.h:57
@ NVT_TIMESTAMP_POS
Definition kb.h:60
@ NVT_NAME_POS
Definition kb.h:59
@ NVT_TAGS_POS
Definition kb.h:53
@ NVT_BIDS_POS
Definition kb.h:55
@ NVT_EXCLUDED_KEYS_POS
Definition kb.h:49
@ NVT_REQUIRED_PORTS_POS
Definition kb.h:51
@ NVT_REQUIRED_UDP_PORTS_POS
Definition kb.h:50
@ NVT_FILENAME_POS
Definition kb.h:46
@ NVT_DEPENDENCIES_POS
Definition kb.h:52
@ NVT_CVES_POS
Definition kb.h:54
@ NVT_REQUIRED_KEYS_POS
Definition kb.h:47
@ NVT_XREFS_POS
Definition kb.h:56
@ NVT_MANDATORY_KEYS_POS
Definition kb.h:48
struct kb * kb_t
type abstraction to hide KB internals.
Definition kb.h:98
kb_item_type
Possible type of a kb_item.
Definition kb.h:33
@ KB_TYPE_INT
Definition kb.h:35
@ KB_TYPE_STR
Definition kb.h:36
static char * kb_item_get_str(kb_t kb, const char *name)
Get a single KB string item.
Definition kb.h:334
nvti_t * nvti_new(void)
Create a new (empty) nvti structure.
Definition nvti.c:559
gchar * nvti_dependencies(const nvti_t *n)
Get the dependencies list.
Definition nvti.c:1032
guint nvti_pref_len(const nvti_t *n)
Get the number of preferences of the NVT.
Definition nvti.c:1171
gchar * nvti_required_udp_ports(const nvti_t *n)
Get the required udp ports list.
Definition nvti.c:1102
gchar * nvti_required_ports(const nvti_t *n)
Get the required ports list.
Definition nvti.c:1088
gchar * nvti_refs(const nvti_t *n, const gchar *type, const gchar *exclude_types, guint use_types)
Get references as string.
Definition nvti.c:766
gchar * nvtpref_type(const nvtpref_t *np)
Get the Type of a NVT Preference.
Definition nvti.c:532
int nvti_set_excluded_keys(nvti_t *n, const gchar *excluded_keys)
Set the excluded keys of a NVT.
Definition nvti.c:1744
struct nvti nvti_t
The structure of a information record that corresponds to a NVT.
int nvti_set_dependencies(nvti_t *n, const gchar *dependencies)
Set the dependencies of a NVT.
Definition nvti.c:1672
int nvti_set_required_ports(nvti_t *n, const gchar *required_ports)
Set the required ports of a NVT.
Definition nvti.c:1768
int nvti_set_oid(nvti_t *n, const gchar *oid)
Set the OID of a NVT Info.
Definition nvti.c:1214
int nvti_set_tag(nvti_t *n, const gchar *tag)
Set the tags of a NVT.
Definition nvti.c:1625
int nvti_set_mandatory_keys(nvti_t *n, const gchar *mandatory_keys)
Set the mandatory keys of a NVT.
Definition nvti.c:1720
gint nvti_category(const nvti_t *n)
Get the category for this NVT.
Definition nvti.c:1199
struct nvtpref nvtpref_t
The structure for a preference of a NVT.
gchar * nvti_family(const nvti_t *n)
Get the family name.
Definition nvti.c:1158
const nvtpref_t * nvti_pref(const nvti_t *n, guint p)
Get the n'th preferences of the NVT.
Definition nvti.c:1186
gchar * nvti_excluded_keys(const nvti_t *n)
Get the excluded keys list.
Definition nvti.c:1074
gchar * nvti_name(const nvti_t *n)
Get the name.
Definition nvti.c:625
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
Definition nvti.c:611
int nvti_set_required_keys(nvti_t *n, const gchar *required_keys)
Set the required keys of a NVT.
Definition nvti.c:1696
int nvtpref_id(const nvtpref_t *np)
Get the ID of a NVT Preference.
Definition nvti.c:504
int nvti_set_name(nvti_t *n, const gchar *name)
Set the name of a NVT.
Definition nvti.c:1234
gchar * nvti_required_keys(const nvti_t *n)
Get the required keys list.
Definition nvti.c:1046
int nvti_add_refs(nvti_t *n, const gchar *type, const gchar *ref_ids, const gchar *ref_text)
Add many new vtref from a comma-separated list.
Definition nvti.c:1968
int nvti_set_required_udp_ports(nvti_t *n, const gchar *required_udp_ports)
Set the required udp ports of a NVT.
Definition nvti.c:1792
gchar * nvti_mandatory_keys(const nvti_t *n)
Get the mandatory keys list.
Definition nvti.c:1060
gchar * nvtpref_default(const nvtpref_t *np)
Get the Default of a NVT Preference.
Definition nvti.c:546
int nvti_set_family(nvti_t *n, const gchar *family)
Set the family of a NVT.
Definition nvti.c:1903
gchar * nvtpref_name(const nvtpref_t *np)
Get the Name of a NVT Preference.
Definition nvti.c:518
gchar * nvti_tag(const nvti_t *n)
Get the tags.
Definition nvti.c:966
int nvti_set_category(nvti_t *n, const gint category)
Set the category type of a NVT Info.
Definition nvti.c:1943
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
Definition kb.h:69
char name[]
Definition kb.h:82
int v_int
Definition kb.h:75
enum kb_item_type type
Definition kb.h:70
char * v_str
Definition kb.h:74
struct kb_item * next
Definition kb.h:79
size_t len
Definition kb.h:78
size_t namelen
Definition kb.h:81
KB interface. Functions provided by an implementation. All functions have to be provided,...
Definition kb.h:107
Subclass of struct kb, it contains the redis-specific fields, such as the redis context,...
Definition kb.c:55
char * path
Definition kb.c:60
unsigned int max_db
Definition kb.c:57
unsigned int db
Definition kb.c:58
struct kb kb
Definition kb.c:56
redisContext * rctx
Definition kb.c:59
Top-level KB. This is to be inherited by KB implementations.
Definition kb.h:91
const struct kb_operations * kb_ops
Definition kb.h:92
The structure of a information record that corresponds to a NVT.
Definition nvti.c:358