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);
249static inline const char *
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;
273 redisContext *result;
274 static int warn_flag = 0;
276 if (len < tcp_indicator_len + 1)
278 if (memcmp (addr, tcp_indicator, tcp_indicator_len) != 0)
280 host_len = len - tcp_indicator_len;
283 port = redis_default_port;
287 host_len -= strlen (tmp) + 1;
289 host = calloc (1, host_len);
290 memmove (host, addr + tcp_indicator_len, host_len);
291 result = redisConnect (host, port);
294 g_warning (
"A Redis TCP connection is being used. This feature is "
295 "experimental and insecure, since it is not an encrypted "
296 "channel. We discourage its usage in production environments");
302 return redisConnectUnix (addr);
319 if (kbr->
rctx != NULL)
323 if (kbr->
rctx == NULL || kbr->
rctx->err)
326 "%s: redis connection error to %s: %s", __func__, kbr->
path,
327 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
328 redisFree (kbr->
rctx);
336 g_log (
G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"No redis DB available");
337 redisFree (kbr->
rctx);
342 g_debug (
"%s: connected to redis://%s/%d", __func__, kbr->
path, kbr->
db);
368 if (rep->type != REDIS_REPLY_STATUS)
374 if (g_ascii_strcasecmp (rep->str,
"PONG"))
382 freeReplyObject (rep);
404 if (kbr->
rctx != NULL)
407 redisFree (kbr->
rctx);
451 if (!rep || rep->type == REDIS_REPLY_ERROR)
454 freeReplyObject (rep);
477 kbr = g_malloc0 (
sizeof (
struct kb_redis));
479 kbr->
path = g_strdup (kb_path);
490 "%s: cannot access redis at '%s'", __func__, kb_path);
503 g_warning (
"%s: Memory purge was not successful", __func__);
525 kbr = g_malloc0 (
sizeof (
struct kb_redis));
527 kbr->
path = g_strdup (kb_path);
530 if (kbr->
rctx == NULL || kbr->
rctx->err)
533 "%s: redis connection error to %s: %s", __func__, kbr->
path,
534 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
535 redisFree (kbr->
rctx);
541 rep = redisCommand (kbr->
rctx,
"SELECT %d", kb_index);
542 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
545 freeReplyObject (rep);
546 redisFree (kbr->
rctx);
552 freeReplyObject (rep);
573 kbr = g_malloc0 (
sizeof (
struct kb_redis));
575 kbr->
path = g_strdup (kb_path);
582 if (kbr->
rctx == NULL || kbr->
rctx->err)
585 "%s: redis connection error to %s: %s", __func__, kbr->
path,
586 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
587 redisFree (kbr->
rctx);
598 if (rep == NULL || rep->type != REDIS_REPLY_INTEGER || rep->integer != 1)
601 freeReplyObject (rep);
603 redisFree (kbr->
rctx);
607 freeReplyObject (rep);
608 rep = redisCommand (kbr->
rctx,
"SELECT %u", i);
609 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
611 redisFree (kbr->
rctx);
616 freeReplyObject (rep);
626 redisFree (kbr->
rctx);
651 g_free (item->
v_str);
672 if (elt->type != REDIS_REPLY_STRING && elt->type != REDIS_REPLY_INTEGER)
678 if (elt->type == REDIS_REPLY_INTEGER)
681 item->
v_int = elt->integer;
686 item->
v_int = atoi (elt->str);
692 item->
len = elt->len;
722 case REDIS_REPLY_STRING:
723 case REDIS_REPLY_INTEGER:
727 case REDIS_REPLY_ARRAY:
728 for (i = 0; i < rep->elements; i++)
746 case REDIS_REPLY_NIL:
747 case REDIS_REPLY_STATUS:
748 case REDIS_REPLY_ERROR:
781 rep = redisvCommand (kbr->
rctx, fmt, aq);
787 freeReplyObject (rep);
822 rep =
redis_cmd (kbr,
"LINDEX %s -1", name);
823 if (rep == NULL || rep->type != REDIS_REPLY_STRING)
833 freeReplyObject (rep);
878 redisReply *rep = NULL;
885 rep =
redis_cmd (kbr,
"LPUSH %s %s", name, value);
886 if (!rep || rep->type == REDIS_REPLY_ERROR)
890 freeReplyObject (rep);
915 if (rep->type == REDIS_REPLY_STRING)
916 value = g_strdup (rep->str);
917 freeReplyObject (rep);
965 rep =
redis_cmd (kbr,
"LINDEX filename:%s %d", oid,
968 rep =
redis_cmd (kbr,
"LINDEX nvt:%s %d", oid, position);
971 if (rep->type == REDIS_REPLY_INTEGER)
972 res = g_strdup_printf (
"%lld", rep->integer);
973 else if (rep->type == REDIS_REPLY_STRING)
974 res = g_strdup (rep->str);
975 freeReplyObject (rep);
999 if (rep->type != REDIS_REPLY_ARRAY || rep->elements !=
NVT_NAME_POS + 1)
1001 freeReplyObject (rep);
1024 freeReplyObject (rep);
1053 freeReplyObject (rep);
1076 rep =
redis_cmd (kbr,
"KEYS %s", pattern);
1079 if (rep->type != REDIS_REPLY_ARRAY)
1081 freeReplyObject (rep);
1087 for (i = 0; i < rep->elements; i++)
1088 redisAppendCommand (kbr->
rctx,
"LRANGE %s 0 -1", rep->element[i]->str);
1090 for (i = 0; i < rep->elements; i++)
1093 redisReply *rep_range;
1095 redisGetReply (kbr->
rctx, (
void **) &rep_range);
1101 freeReplyObject (rep_range);
1117 freeReplyObject (rep_range);
1120 freeReplyObject (rep);
1136 GSList *list = NULL;
1144 if (rep->type != REDIS_REPLY_ARRAY)
1146 freeReplyObject (rep);
1151 for (i = 0; i < rep->elements; i++)
1152 list = g_slist_prepend (list, g_strdup (rep->element[i]->str + 4));
1153 freeReplyObject (rep);
1175 rep =
redis_cmd (kbr,
"KEYS %s", pattern);
1179 if (rep->type != REDIS_REPLY_ARRAY)
1181 freeReplyObject (rep);
1185 count = rep->elements;
1186 freeReplyObject (rep);
1208 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1212 freeReplyObject (rep);
1232 int expire,
size_t len,
int pos)
1235 redisReply *rep = NULL;
1250 redisAppendCommand (ctx,
"LREM %s 1 %s", name, str);
1251 redisAppendCommand (ctx,
"%s %s %s", pos ?
"LPUSH" :
"RPUSH", name, str);
1252 redisAppendCommand (ctx,
"EXPIRE %s %d", name, expire);
1254 redisGetReply (ctx, (
void **) &rep);
1255 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1256 g_debug (
"Key '%s' already contained value '%s'", name, str);
1257 freeReplyObject (rep);
1259 redisGetReply (ctx, (
void **) &rep);
1260 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1266 redisGetReply (ctx, (
void **) &rep);
1267 if (rep == NULL || rep->type == REDIS_REPLY_ERROR
1268 || (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer != 1))
1270 g_warning (
"%s: Not able to set expire", __func__);
1277 redisAppendCommand (ctx,
"LREM %s 1 %b", name, str, len);
1278 redisAppendCommand (ctx,
"%s %s %b", pos ?
"LPUSH" :
"RPUSH", name, str,
1280 redisAppendCommand (ctx,
"EXPIRE %s %d", name, expire);
1282 redisGetReply (ctx, (
void **) &rep);
1283 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1284 g_debug (
"Key '%s' already contained string '%s'", name, str);
1285 freeReplyObject (rep);
1287 redisGetReply (ctx, (
void **) &rep);
1288 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1294 redisGetReply (ctx, (
void **) &rep);
1295 if (rep == NULL || rep->type == REDIS_REPLY_ERROR
1296 || (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer != 1))
1298 g_warning (
"%s: Not able to set expire", __func__);
1306 freeReplyObject (rep);
1328 redisReply *rep = NULL;
1343 redisAppendCommand (ctx,
"LREM %s 1 %s", name, str);
1344 redisAppendCommand (ctx,
"%s %s %s", pos ?
"LPUSH" :
"RPUSH", name, str);
1345 redisGetReply (ctx, (
void **) &rep);
1346 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1347 g_debug (
"Key '%s' already contained value '%s'", name, str);
1348 freeReplyObject (rep);
1349 redisGetReply (ctx, (
void **) &rep);
1353 redisAppendCommand (ctx,
"LREM %s 1 %b", name, str, len);
1354 redisAppendCommand (ctx,
"%s %s %b", pos ?
"LPUSH" :
"RPUSH", name, str,
1356 redisGetReply (ctx, (
void **) &rep);
1357 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1358 g_debug (
"Key '%s' already contained string '%s'", name, str);
1359 freeReplyObject (rep);
1360 redisGetReply (ctx, (
void **) &rep);
1362 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1366 freeReplyObject (rep);
1390 rep =
redis_cmd (kbr,
"RPUSH %s %s", name, str);
1392 rep =
redis_cmd (kbr,
"RPUSH %s %b", name, str, len);
1393 if (!rep || rep->type == REDIS_REPLY_ERROR)
1397 freeReplyObject (rep);
1415 redisReply *rep = NULL;
1423 redisAppendCommand (ctx,
"MULTI");
1424 redisAppendCommand (ctx,
"DEL %s", name);
1426 redisAppendCommand (ctx,
"RPUSH %s %s", name, val);
1428 redisAppendCommand (ctx,
"RPUSH %s %b", name, val, len);
1429 redisAppendCommand (ctx,
"EXEC");
1432 redisGetReply (ctx, (
void **) &rep);
1433 if (!rep || rep->type == REDIS_REPLY_ERROR)
1436 freeReplyObject (rep);
1464 redisAppendCommand (ctx,
"LREM %s 1 %d", name, val);
1465 redisAppendCommand (ctx,
"RPUSH %s %d", name, val);
1466 redisAppendCommand (ctx,
"EXPIRE %s %d", name, expire);
1468 redisGetReply (ctx, (
void **) &rep);
1469 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1470 g_debug (
"Key '%s' already contained integer '%d'", name, val);
1471 freeReplyObject (rep);
1473 redisGetReply (ctx, (
void **) &rep);
1474 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1480 redisGetReply (ctx, (
void **) &rep);
1481 if (rep == NULL || rep->type == REDIS_REPLY_ERROR
1482 || (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer != 1))
1484 g_warning (
"%s: Not able to set expire", __func__);
1491 freeReplyObject (rep);
1517 redisAppendCommand (ctx,
"LREM %s 1 %d", name, val);
1518 redisAppendCommand (ctx,
"RPUSH %s %d", name, val);
1519 redisGetReply (ctx, (
void **) &rep);
1520 if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
1521 g_debug (
"Key '%s' already contained integer '%d'", name, val);
1522 freeReplyObject (rep);
1523 redisGetReply (ctx, (
void **) &rep);
1524 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1532 freeReplyObject (rep);
1553 if (!rep || rep->type == REDIS_REPLY_ERROR)
1556 freeReplyObject (rep);
1574 redisReply *rep = NULL;
1582 redisAppendCommand (ctx,
"MULTI");
1583 redisAppendCommand (ctx,
"DEL %s", name);
1584 redisAppendCommand (ctx,
"RPUSH %s %d", name, val);
1585 redisAppendCommand (ctx,
"EXEC");
1588 redisGetReply (ctx, (
void **) &rep);
1589 if (!rep || rep->type == REDIS_REPLY_ERROR)
1592 freeReplyObject (rep);
1611 redisReply *rep = NULL;
1614 gchar *cves, *bids, *xrefs;
1616 if (!nvt || !filename)
1621 xrefs =
nvti_refs (nvt, NULL,
"cve,bid", 1);
1625 kbr,
"RPUSH nvt:%s %s %s %s %s %s %s %s %s %s %s %s %d %s %s",
1639 if (rep == NULL || rep->type == REDIS_REPLY_ERROR)
1642 freeReplyObject (rep);
1650 rep =
redis_cmd (kbr,
"RPUSH oid:%s:prefs %d|||%s|||%s|||%s",
1653 if (!rep || rep->type == REDIS_REPLY_ERROR)
1656 freeReplyObject (rep);
1658 rep =
redis_cmd (kbr,
"RPUSH filename:%s %lu %s", filename, time (NULL),
1660 if (!rep || rep->type == REDIS_REPLY_ERROR)
1663 freeReplyObject (rep);
1682 if (kbr->
rctx != NULL)
1684 redisFree (kbr->
rctx);
1707 redisFree (kbr->
rctx);
1709 g_debug (
"%s: deleting all DBs at %s except %s", __func__, kbr->
path, except);
1715 if (kbr->
rctx == NULL || kbr->
rctx->err)
1718 "%s: redis connection error to %s: %s", __func__, kbr->
path,
1719 kbr->
rctx ? kbr->
rctx->errstr : strerror (ENOMEM));
1720 redisFree (kbr->
rctx);
1727 if (rep == NULL || rep->type != REDIS_REPLY_INTEGER || rep->integer != 1)
1729 freeReplyObject (rep);
1730 redisFree (kbr->
rctx);
1734 freeReplyObject (rep);
1735 rep = redisCommand (kbr->
rctx,
"SELECT %u", i);
1736 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1738 freeReplyObject (rep);
1739 redisFree (kbr->
rctx);
1744 freeReplyObject (rep);
1753 redisFree (kbr->
rctx);
1759 redisFree (kbr->
rctx);
1785 g_debug (
"%s: saving all elements from KB #%u", __func__, kbr->
db);
1787 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1797 freeReplyObject (rep);
1814 struct sigaction new_action, original_action;
1817 new_action.sa_flags = 0;
1818 if (sigemptyset (&new_action.sa_mask))
1820 new_action.sa_handler = SIG_IGN;
1821 if (sigaction (SIGPIPE, &new_action, &original_action))
1825 g_debug (
"%s: deleting all elements from KB #%u", __func__, kbr->
db);
1827 if (rep == NULL || rep->type != REDIS_REPLY_STATUS)
1836 if (sigaction (SIGPIPE, &original_action, NULL))
1839 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:1676
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:315
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:875
static int redis_memory_purge(kb_t kb)
Attempt to purge dirty pages.
Definition kb.c:445
static int redis_test_connection(struct kb_redis *kbr)
Test redis connection.
Definition kb.c:354
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:1412
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:1231
static const char * parse_port_of_addr(const char *addr, int tcp_indicator_len)
Definition kb.c:250
static char * redis_get_nvt(kb_t kb, const char *oid, enum kb_nvt_pos position)
Get field of a NVT.
Definition kb.c:957
static struct kb_item * redis2kbitem(const char *name, const redisReply *rep)
Fetch a KB item or list from a redis Reply.
Definition kb.c:712
static kb_t redis_find(const char *kb_path, const char *key)
Find an existing Knowledge Base object with key.
Definition kb.c:565
static int redis_delete(kb_t kb)
Delete all entries and release ownership on the namespace.
Definition kb.c:395
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:1382
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:1810
void kb_item_free(struct kb_item *item)
Release a KB item (or a list).
Definition kb.c:643
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:1453
static struct kb_item * redis_get_all(kb_t kb, const char *name)
Get all items stored under a given name.
Definition kb.c:1039
#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:1547
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:517
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:1324
static char * redis_get_str(kb_t kb, const char *name)
Get a single KB string item.
Definition kb.c:848
static struct kb_item * redis_get_pattern(kb_t kb, const char *pattern)
Get all items stored under a given pattern.
Definition kb.c:1068
static GSList * redis_get_oids(kb_t kb)
Get all NVT OIDs.
Definition kb.c:1132
static struct kb_item * redis2kbitem_single(const char *name, const redisReply *elt, int force_int)
Give a single KB item.
Definition kb.c:667
static int redis_save(kb_t kb)
Save all the elements from the KB.
Definition kb.c:1778
static int redis_get_int(kb_t kb, const char *name)
Get a single KB integer item.
Definition kb.c:931
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:904
static int redis_new(kb_t *kb, const char *kb_path)
Initialize a new Knowledge Base object.
Definition kb.c:469
static int redis_get_kb_index(kb_t kb)
Return the kb index.
Definition kb.c:423
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:1506
#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:1881
static int redis_flush_all(kb_t, const char *)
Flush all the KB's content. Delete all namespaces.
Definition kb.c:1700
static size_t redis_count(kb_t kb, const char *pattern)
Count all items stored under a given pattern.
Definition kb.c:1167
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:813
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:1571
static int redis_add_nvt(kb_t kb, const nvti_t *nvt, const char *filename)
Insert a new nvt.
Definition kb.c:1608
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:765
static nvti_t * redis_get_nvt_all(kb_t kb, const char *oid)
Get a full NVT.
Definition kb.c:989
static int redis_del_items(kb_t kb, const char *name)
Delete all entries under a given name.
Definition kb.c:1199
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