static void rspamd_show_multipart (struct rspamd_mime_part *part) { struct rspamd_mime_part *cur; guint i; rspamd_printf ("got multipart part %p, boundary: %T: parent: %p, type: %T/%T, children: [", part, &part->ct->boundary, part->parent_part, &part->ct->type, &part->ct->subtype); if (part->specific.mp.children) { for (i = 0; i < part->specific.mp.children->len; i ++) { cur = g_ptr_array_index (part->specific.mp.children, i); if (i != 0) { rspamd_printf (", %p{%T/%T}", cur, &cur->ct->type, &cur->ct->subtype); } else { rspamd_printf ("%p{%T/%T}", cur, &cur->ct->type, &cur->ct->subtype); } } } rspamd_printf ("]\n"); }
static void rspamd_show_normal (struct rspamd_mime_part *part) { rspamd_printf ("got normal part %p: parent: %p, type: %T/%T," "length: %z (%z raw)\n", part, part->parent_part, &part->ct->type, &part->ct->subtype, part->parsed_data.len, part->raw_data.len); }
static void mime_foreach_callback (GMimeObject * parent, GMimeObject * part, gpointer user_data) { GMimeContentType *type; if (GMIME_IS_MESSAGE_PART (part)) { /* message/rfc822 or message/news */ GMimeMessage *message; /* g_mime_message_foreach_part() won't descend into child message parts, so if we want to count any subparts of this child message, we'll have to call g_mime_message_foreach_part() again here. */ rspamd_printf ("got message part %p: parent: %p\n", part, parent); message = g_mime_message_part_get_message ((GMimeMessagePart *) part); g_mime_message_foreach (message, mime_foreach_callback, part); } else if (GMIME_IS_MULTIPART (part)) { type = (GMimeContentType *) g_mime_object_get_content_type (GMIME_OBJECT ( part)); rspamd_printf ("got multipart part %p, boundary: %s: parent: %p, type: %s/%s\n", part, g_mime_multipart_get_boundary (GMIME_MULTIPART(part)), parent, g_mime_content_type_get_media_type (type), g_mime_content_type_get_media_subtype (type)); } else { type = (GMimeContentType *) g_mime_object_get_content_type (GMIME_OBJECT ( part)); rspamd_printf ("got normal part %p, parent: %p, type: %s/%s\n", part, parent, g_mime_content_type_get_media_type (type), g_mime_content_type_get_media_subtype (type)); } }
static void rspamd_process_file (const gchar *fname, gint decode) { gint fd; gpointer map; struct stat st; guint8 *dest; gsize destlen; fd = open (fname, O_RDONLY); if (fd == -1) { rspamd_fprintf (stderr, "cannot open %s: %s", fname, strerror (errno)); exit (EXIT_FAILURE); } if (fstat (fd, &st) == -1) { rspamd_fprintf (stderr, "cannot stat %s: %s", fname, strerror (errno)); exit (EXIT_FAILURE); } map = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); close (fd); if (map == MAP_FAILED) { rspamd_fprintf (stderr, "cannot mmap %s: %s", fname, strerror (errno)); exit (EXIT_FAILURE); } if (decode) { destlen = st.st_size / 4 * 3 + 10; dest = g_malloc (destlen); rspamd_cryptobox_base64_decode (map, st.st_size, dest, &destlen); } else { dest = rspamd_encode_base64 (map, st.st_size, 80, &destlen); } rspamd_printf ("%*s", (gint)destlen, dest); g_free (dest); munmap (map, st.st_size); }
static void rspamadm_dump_section_obj (const ucl_object_t *obj) { rspamd_fstring_t *output; output = rspamd_fstring_new (); if (json) { rspamd_ucl_emit_fstring (obj, UCL_EMIT_JSON, &output); } else if (compact) { rspamd_ucl_emit_fstring (obj, UCL_EMIT_JSON_COMPACT, &output); } else { rspamd_ucl_emit_fstring (obj, UCL_EMIT_CONFIG, &output); } rspamd_printf ("%V", output); rspamd_fstring_free (output); }
int main (int argc, char **argv) { gint i, start = 1, mode = MODE_NORMAL; struct rspamd_config *cfg; rspamd_logger_t *logger = NULL; if (argc > 2 && *argv[1] == '-') { start = 2; if (argv[1][1] == 'g') { mode = MODE_GMIME; } } cfg = rspamd_config_new (); cfg->libs_ctx = rspamd_init_libs (); cfg->log_type = RSPAMD_LOG_CONSOLE; rspamd_set_logger (cfg, g_quark_from_static_string ("mime"), &logger, NULL); (void) rspamd_log_open (logger); g_log_set_default_handler (rspamd_glib_log_function, logger); g_set_printerr_handler (rspamd_glib_printerr_function); rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_LIBS|RSPAMD_CONFIG_INIT_URL|RSPAMD_CONFIG_INIT_NO_TLD); for (i = start; i < argc; i ++) { if (argv[i]) { rspamd_process_file (cfg, argv[i], mode); } } rspamd_printf ("Total time parsing: %.4f seconds\n", total_time); rspamd_log_close (logger); REF_RELEASE (cfg); return 0; }
int main (int argc, char **argv) { gint i; for (i = 1; i < argc; i ++) { if (argv[i]) { rspamd_process_file (argv[i]); } } rspamd_printf ("Parsed %d received headers in %.3f seconds\n" "Total valid (has by part): %d\n" "Total real ip: %d\n" "Total real host: %d\n" "Total known proto: %d\n" "Total known timestamp: %d\n", total_parsed, total_time, total_valid, total_real_ip, total_real_host, total_known_proto, total_known_ts); return 0; }
int main (int argc, gchar **argv) { GOptionContext *context; GError *error = NULL; struct event_base *ev_base; GString *b32_key; pid_t *sfd; rspamd_inet_addr_t *addr; struct event term_ev, int_ev; struct in_addr ina = {INADDR_ANY}; rspamd_init_libs (); context = g_option_context_new ( "rspamd-http-server - test server for benchmarks"); g_option_context_set_summary (context, "Summary:\n Rspamd test HTTP server " RVERSION "\n Release id: " RID); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { rspamd_fprintf (stderr, "option parsing failed: %s\n", error->message); g_error_free (error); exit (1); } maps = g_hash_table_new (g_int_hash, g_int_equal); if (key == NULL) { server_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX, openssl_mode ? RSPAMD_CRYPTOBOX_MODE_NIST : RSPAMD_CRYPTOBOX_MODE_25519); b32_key = rspamd_keypair_print (server_key, RSPAMD_KEYPAIR_PUBKEY | RSPAMD_KEYPAIR_BASE32); rspamd_printf ("key: %v\n", b32_key); } else { /* TODO: add key loading */ } if (cache_size > 0) { c = rspamd_keypair_cache_new (cache_size); } sfd = g_alloca (sizeof (*sfd) * nworkers); addr = rspamd_inet_address_new (AF_INET, &ina); rspamd_inet_address_set_port (addr, port); rspamd_http_start_servers (sfd, addr); /* Just wait for workers */ ev_base = event_init (); event_set (&term_ev, SIGTERM, EV_SIGNAL, rspamd_http_server_term, sfd); event_base_set (ev_base, &term_ev); event_add (&term_ev, NULL); event_set (&int_ev, SIGINT, EV_SIGNAL, rspamd_http_server_term, sfd); event_base_set (ev_base, &int_ev); event_add (&int_ev, NULL); event_base_loop (ev_base, 0); return 0; }
static void rspamadm_configtest (gint argc, gchar **argv) { GOptionContext *context; GError *error = NULL; const gchar *confdir; struct rspamd_config *cfg = rspamd_main->cfg; gboolean ret = TRUE; worker_t **pworker; const guint64 *log_cnt; context = g_option_context_new ( "configtest - perform configuration file test"); g_option_context_set_summary (context, "Summary:\n Rspamd administration utility version " RVERSION "\n Release id: " RID); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { fprintf (stderr, "option parsing failed: %s\n", error->message); g_error_free (error); exit (1); } if (config == NULL) { if ((confdir = g_hash_table_lookup (ucl_vars, "CONFDIR")) == NULL) { confdir = RSPAMD_CONFDIR; } config = g_strdup_printf ("%s%c%s", confdir, G_DIR_SEPARATOR, "rspamd.conf"); } pworker = &workers[0]; while (*pworker) { /* Init string quarks */ (void) g_quark_from_static_string ((*pworker)->name); pworker++; } cfg->cache = rspamd_symbols_cache_new (cfg); cfg->compiled_modules = modules; cfg->compiled_workers = workers; cfg->cfg_name = config; if (!rspamd_config_read (cfg, cfg->cfg_name, NULL, config_logger, rspamd_main, ucl_vars)) { ret = FALSE; } else { /* Do post-load actions */ rspamd_lua_post_load_config (cfg); if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) { ret = FALSE; } if (ret) { ret = rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_SYMCACHE); } if (!rspamd_symbols_cache_validate (rspamd_main->cfg->cache, rspamd_main->cfg, FALSE)) { ret = FALSE; } } if (strict && ret) { log_cnt = rspamd_log_counters (rspamd_main->logger); if (log_cnt && log_cnt[0] > 0) { if (!quiet) { rspamd_printf ("%L errors found\n", log_cnt[0]); } ret = FALSE; } } if (!quiet) { rspamd_printf ("syntax %s\n", ret ? "OK" : "BAD"); } if (!ret) { exit (EXIT_FAILURE); } exit (EXIT_SUCCESS); }
static void rspamadm_configdump (gint argc, gchar **argv) { GOptionContext *context; GError *error = NULL; const gchar *confdir; struct rspamd_config *cfg = rspamd_main->cfg; gboolean ret = FALSE; worker_t **pworker; GString *output; context = g_option_context_new ( "keypair - create encryption keys"); g_option_context_set_summary (context, "Summary:\n Rspamd administration utility version " RVERSION "\n Release id: " RID); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { fprintf (stderr, "option parsing failed: %s\n", error->message); g_error_free (error); exit (1); } if (config == NULL) { if ((confdir = g_hash_table_lookup (ucl_vars, "CONFDIR")) == NULL) { confdir = RSPAMD_CONFDIR; } config = g_strdup_printf ("%s%c%s", confdir, G_DIR_SEPARATOR, "rspamd.conf"); } pworker = &workers[0]; while (*pworker) { /* Init string quarks */ (void) g_quark_from_static_string ((*pworker)->name); pworker++; } cfg->cache = rspamd_symbols_cache_new (cfg); cfg->compiled_modules = modules; cfg->compiled_workers = workers; cfg->cfg_name = config; if (!rspamd_config_read (cfg, cfg->cfg_name, NULL, config_logger, rspamd_main, ucl_vars)) { ret = FALSE; } else { /* Do post-load actions */ rspamd_config_post_load (cfg); ret = TRUE; } if (ret) { rspamd_symbols_cache_init (rspamd_main->cfg->cache); if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) { ret = FALSE; } /* Insert classifiers symbols */ (void) rspamd_config_insert_classify_symbols (rspamd_main->cfg); if (!rspamd_symbols_cache_validate (rspamd_main->cfg->cache, rspamd_main->cfg, FALSE)) { ret = FALSE; } } if (ret) { /* Output configuration */ output = g_string_new (""); if (json) { rspamd_ucl_emit_gstring (cfg->rcl_obj, UCL_EMIT_JSON, output); } else if (compact) { rspamd_ucl_emit_gstring (cfg->rcl_obj, UCL_EMIT_JSON_COMPACT, output); } else { rspamd_ucl_emit_gstring (cfg->rcl_obj, UCL_EMIT_CONFIG, output); } rspamd_printf ("%v", output); g_string_free (output, TRUE); } if (!ret) { exit (EXIT_FAILURE); } }
static void rspamadm_configdump (gint argc, gchar **argv) { GOptionContext *context; GError *error = NULL; const gchar *confdir; const ucl_object_t *obj, *cur; struct rspamd_config *cfg = rspamd_main->cfg; gboolean ret = TRUE; worker_t **pworker; gchar **sec; context = g_option_context_new ( "keypair - create encryption keys"); g_option_context_set_summary (context, "Summary:\n Rspamd administration utility version " RVERSION "\n Release id: " RID); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { fprintf (stderr, "option parsing failed: %s\n", error->message); g_error_free (error); exit (1); } if (config == NULL) { if ((confdir = g_hash_table_lookup (ucl_vars, "CONFDIR")) == NULL) { confdir = RSPAMD_CONFDIR; } config = g_strdup_printf ("%s%c%s", confdir, G_DIR_SEPARATOR, "rspamd.conf"); } pworker = &workers[0]; while (*pworker) { /* Init string quarks */ (void) g_quark_from_static_string ((*pworker)->name); pworker++; } cfg->cache = rspamd_symbols_cache_new (cfg); cfg->compiled_modules = modules; cfg->compiled_workers = workers; cfg->cfg_name = config; if (!rspamd_config_read (cfg, cfg->cfg_name, NULL, config_logger, rspamd_main, ucl_vars)) { ret = FALSE; } else { /* Do post-load actions */ rspamd_lua_post_load_config (cfg); if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) { ret = FALSE; } if (ret) { ret = rspamd_config_post_load (cfg, FALSE); } } if (ret) { /* Output configuration */ if (!sections) { rspamadm_dump_section_obj (cfg->rcl_obj); } else { sec = sections; while (*sec != NULL) { obj = ucl_object_find_key (cfg->rcl_obj, *sec); if (!obj) { rspamd_printf ("Section %s NOT FOUND\n", *sec); } else { LL_FOREACH (obj, cur) { if (!json && !compact) { rspamd_printf ("*** Section %s ***\n", *sec); } rspamadm_dump_section_obj (cur); if (!json && !compact) { rspamd_printf ("*** End of section %s ***\n", *sec); } else { rspamd_printf ("\n"); } } } sec ++; } g_strfreev (sections); } } if (!ret) { exit (EXIT_FAILURE); } exit (EXIT_SUCCESS); }
static void rspamd_show_message (struct rspamd_mime_part *part) { rspamd_printf ("got message part %p: parent: %p\n", part, part->parent_part); }