return str;
}
-static gboolean rspamd_check_encrypted_password (const gchar * password,
+static gboolean rspamd_check_encrypted_password (const GString * password,
const gchar * check, const struct rspamd_controller_pbkdf *pbkdf)
{
const gchar *salt, *hash;
}
local_key = g_alloca (pbkdf->key_len);
- rspamd_cryptobox_pbkdf (password, strlen (password),
+ rspamd_cryptobox_pbkdf (password->str, password->len,
salt_decoded, salt_len,
local_key, pbkdf->key_len, pbkdf->rounds);
struct rspamd_controller_session *session,
struct rspamd_http_message *msg, gboolean is_enable)
{
- const gchar *password, *check;
+ const gchar *check;
+ const GString *password;
struct rspamd_controller_worker_ctx *ctx = session->ctx;
gboolean check_normal = TRUE, check_enable = TRUE, ret = TRUE;
const struct rspamd_controller_pbkdf *pbkdf = NULL;
}
if (check != NULL) {
if (!rspamd_is_encrypted_password (check, &pbkdf)) {
- ret = rspamd_constant_memcmp (password, check, 0);
+ ret = rspamd_constant_memcmp (password->str, check, password->len);
}
else {
ret = rspamd_check_encrypted_password (password, check,
if (ctx->password != NULL) {
check = ctx->password;
if (!rspamd_is_encrypted_password (check, &pbkdf)) {
- check_normal = rspamd_constant_memcmp (password, check, 0);
+ check_normal = rspamd_constant_memcmp (password->str, check,
+ password->len);
}
else {
check_normal = rspamd_check_encrypted_password (password,
if (ctx->enable_password != NULL) {
check = ctx->enable_password;
if (!rspamd_is_encrypted_password (check, &pbkdf)) {
- check_enable = rspamd_constant_memcmp (password, check, 0);
+ check_enable = rspamd_constant_memcmp (password->str, check,
+ password->len);
}
else {
check_enable = rspamd_check_encrypted_password (password,
struct rspamd_controller_session *session = conn_ent->ud;
GList *cur;
struct rspamd_map *map;
- const gchar *idstr;
+ const GString *idstr;
gchar *errstr;
struct stat st;
gint fd;
return 0;
}
- id = strtoul (idstr, &errstr, 10);
- if (*errstr != '\0') {
+ id = strtoul (idstr->str, &errstr, 10);
+ if (*errstr != '\0' && *errstr != '\n') {
msg_info ("invalid map id");
rspamd_controller_send_error (conn_ent, 400, "400 invalid map id");
return 0;
struct rspamd_controller_worker_ctx *ctx;
struct rspamd_classifier_config *cl;
struct rspamd_task *task;
- const gchar *classifier;
ctx = session->ctx;
return 0;
}
- if ((classifier =
- rspamd_http_message_find_header (msg, "Classifier")) == NULL) {
- classifier = "bayes";
- }
-
- cl = rspamd_config_find_classifier (ctx->cfg, classifier);
+ /* XXX: now work with only bayes */
+ cl = rspamd_config_find_classifier (ctx->cfg, "bayes");
if (cl == NULL) {
rspamd_controller_send_error (conn_ent, 400, "Classifier not found");
return 0;
GList *cur;
struct rspamd_map *map;
struct rspamd_controller_worker_ctx *ctx;
- const gchar *idstr;
+ const GString *idstr;
gchar *errstr;
guint32 id;
gboolean found = FALSE;
return 0;
}
- id = strtoul (idstr, &errstr, 10);
- if (*errstr != '\0') {
+ id = strtoul (idstr->str, &errstr, 10);
+ if (*errstr != '\0' && *errstr != '\r') {
msg_info ("invalid map id");
rspamd_controller_send_error (conn_ent, 400, "Map id is invalid");
return 0;
{
struct http_proxy_session *session = conn->ud;
struct rspamd_http_upstream *backend = NULL;
- const gchar *host;
+ const GString *host;
+ gchar hostbuf[512];
if (!session->replied) {
host = rspamd_http_message_find_header (msg, "Host");
backend = session->ctx->default_upstream;
}
else {
- backend = g_hash_table_lookup (session->ctx->upstreams, host);
+ rspamd_strlcpy (hostbuf, host->str, sizeof (hostbuf));
+ backend = g_hash_table_lookup (session->ctx->upstreams, hostbuf);
if (backend == NULL) {
backend = session->ctx->default_upstream;
if (backend == NULL) {
/* No backend */
- msg_err ("cannot find upstream for %s", host ? host : "default");
+ msg_err ("cannot find upstream for %s", host ? hostbuf : "default");
goto err;
}
else {
session->up = rspamd_upstream_get (backend->u, RSPAMD_UPSTREAM_ROUND_ROBIN);
if (session->up == NULL) {
- msg_err ("cannot select upstream for %s", host ? host : "default");
+ msg_err ("cannot select upstream for %s", host ? hostbuf : "default");
goto err;
}
rspamd_upstream_addr (session->up), SOCK_STREAM, TRUE);
if (session->backend_sock == -1) {
- msg_err ("cannot connect upstream for %s", host ? host : "default");
+ msg_err ("cannot connect upstream for %s", host ? hostbuf : "default");
rspamd_upstream_fail (session->up);
goto err;
}
fuzzy_controller_handler (struct rspamd_http_connection_entry *conn_ent,
struct rspamd_http_message *msg, struct module_ctx *ctx, gint cmd)
{
- const gchar *arg;
+ const GString *arg;
gchar *err_str;
gint value = 1, flag = 0;
arg = rspamd_http_message_find_header (msg, "Weight");
if (arg) {
errno = 0;
- value = strtol (arg, &err_str, 10);
- if (errno != 0 || *err_str != '\0') {
- msg_info ("error converting numeric argument %s", arg);
+ value = strtol (arg->str, &err_str, 10);
+ if (*err_str != '\0' && *err_str != '\r') {
+ msg_info ("error converting numeric argument %v", arg);
value = 0;
}
}
arg = rspamd_http_message_find_header (msg, "Flag");
if (arg) {
errno = 0;
- flag = strtol (arg, &err_str, 10);
- if (errno != 0 || *err_str != '\0') {
- msg_info ("error converting numeric argument %s", arg);
+ flag = strtol (arg->str, &err_str, 10);
+ if (*err_str != '\0' && *err_str != '\r') {
+ msg_info ("error converting numeric argument %v", arg);
flag = 0;
}
}