Add callback for user processing of json string and result of json scan.

pull/6/head
Steven Morgan 12 years ago
parent 9048572cec
commit 6606d05000
  1. 4
      libclamav/clamav.h
  2. 6
      libclamav/others.c
  3. 4
      libclamav/others.h
  4. 60
      libclamav/scanners.c

@ -373,6 +373,10 @@ typedef cl_error_t (*clcb_meta)(const char* container_type, unsigned long fsize_
unsigned long fsize_real, int is_encrypted, unsigned int filepos_container, void *context);
extern void cl_engine_set_clcb_meta(struct cl_engine *engine, clcb_meta callback);
/* File properties callback */
typedef int (*clcb_file_props)(const char *j_propstr, int rc, void *cbdata);
extern void cl_engine_set_clcb_file_props(struct cl_engine *engine, clcb_file_props callback, void * cbdata);
/* Statistics/intelligence gathering callbacks */
extern void cl_engine_set_stats_set_cbdata(struct cl_engine *engine, void *cbdata);

@ -1311,3 +1311,9 @@ void cl_engine_set_clcb_meta(struct cl_engine *engine, clcb_meta callback)
{
engine->cb_meta = callback;
}
void cl_engine_set_clcb_file_props(struct cl_engine *engine, clcb_file_props callback, void * cbdata)
{
engine->cb_file_props = callback;
engine->cb_file_props_data = cbdata;
}

@ -309,6 +309,8 @@ struct cl_engine {
void *cb_sigload_ctx;
clcb_hash cb_hash;
clcb_meta cb_meta;
clcb_file_props cb_file_props;
void *cb_file_props_data;
/* Used for bytecode */
struct cli_all_bc bcs;
@ -375,6 +377,8 @@ struct cl_settings {
clcb_msg cb_msg;
clcb_hash cb_hash;
clcb_meta cb_meta;
clcb_file_props cb_file_props;
void *cb_file_props_data;
/* Engine max settings */
uint64_t maxembeddedpe; /* max size to scan MSEXE for PE */

@ -3396,42 +3396,48 @@ static int scan_common(int desc, cl_fmap_t *map, const char **virname, unsigned
#if HAVE_JSON
if (ctx.options & CL_SCAN_FILE_PROPERTIES && ctx.properties!=NULL) {
// serialize, etc.
const char * jstring = json_object_to_json_string(ctx.properties);
/* serialize json properties to string */
const char *jstring = json_object_to_json_string(ctx.properties);
if (NULL == jstring) {
cli_errmsg("scan_common: no memory for json serialization.\n");
rc = CL_EMEM;
}
else if (rc != CL_VIRUS) {
ctx.options &= ~CL_SCAN_FILE_PROPERTIES;
rc = cli_mem_scandesc(jstring, strlen(jstring), &ctx);
}
else {
int ret = CL_SUCCESS;
cli_dbgmsg("%s\n", jstring);
/* Scan the json string unless a virus was detected */
if (rc != CL_VIRUS) {
ctx.options &= ~CL_SCAN_FILE_PROPERTIES;
rc = cli_mem_scandesc(jstring, strlen(jstring), &ctx);
}
if (ctx.engine->keeptmp && NULL!=jstring) {
int ret = CL_SUCCESS, fd = -1;
char * tmpname = NULL;
if ((ret = cli_gentempfd(ctx.engine->tmpdir, &tmpname, &fd)) != CL_SUCCESS) {
cli_dbgmsg("scan_common: Can't create json properties file.\n");
} else {
if (cli_writen(fd, jstring, strlen(jstring)) < 0) {
cli_dbgmsg("scan_common: cli_writen error writing json properties file.\n");
ret = CL_EWRITE;
/* Invoke file props callback */
if (ctx.engine->cb_file_props != NULL) {
ret = ctx.engine->cb_file_props(jstring, rc, ctx.engine->cb_file_props_data);
if (ret != CL_SUCCESS)
rc = ret;
}
/* keeptmp file processing for file properties json string */
if (ctx.engine->keeptmp) {
int fd = -1;
char * tmpname = NULL;
if ((ret = cli_gentempfd(ctx.engine->tmpdir, &tmpname, &fd)) != CL_SUCCESS) {
cli_dbgmsg("scan_common: Can't create json properties file, ret = %i.\n", ret);
} else {
cli_errmsg("json written to: %s\n", tmpname);
if (cli_writen(fd, jstring, strlen(jstring)) < 0)
cli_dbgmsg("scan_common: cli_writen error writing json properties file.\n");
else
cli_dbgmsg("json written to: %s\n", tmpname);
}
if (fd != -1)
close(fd);
if (NULL != tmpname)
free(tmpname);
}
if (fd != -1)
close(fd);
if (NULL != tmpname)
free(tmpname);
if (rc == CL_SUCCESS)
rc = ret;
} else {
if ((jstring))
cli_errmsg("%s\n", jstring); //temp
}
json_object_put(ctx.properties); // frees
json_object_put(ctx.properties); /* frees all json memory */
}
#endif

Loading…
Cancel
Save