rspamd_send_controller_command (struct rspamd_connection *c, const gchar *line, gsize len, gint fd, GError **err)
{
GString *res = NULL;
- gchar tmpbuf[BUFSIZ];
+ gchar tmpbuf[BUFSIZ], *p;
gint r = 0;
- static const gchar end_marker[] = "END\r\n";
+ static const gchar end_marker[] = "\r\nEND\r\n";
/* Set blocking for writing */
make_socket_blocking (c->socket);
upstream_fail (&c->server->up, c->connection_time);
return NULL;
}
- if ((r = read (c->socket, tmpbuf, sizeof (tmpbuf))) > 0) {
+ if ((r = read (c->socket, tmpbuf, sizeof (tmpbuf) - 1)) > 0) {
/* Check the end of the buffer for END marker */
+ tmpbuf[r] = '\0';
if (r >= (gint)sizeof (end_marker) - 1 &&
- memcmp (tmpbuf + r - sizeof (end_marker) + 1, end_marker, sizeof (end_marker) - 1) == 0) {
- r -= sizeof (end_marker) - 1;
+ (p = strstr (tmpbuf, end_marker)) != NULL) {
+ *p = '\0';
/* Copy the rest to the result string */
if (res == NULL) {
- res = g_string_new_len (tmpbuf, r);
+ res = g_string_new (tmpbuf);
return res;
}
else {
/* Append data to string */
if (r > 0) {
- res = g_string_append_len (res, tmpbuf, r);
+ res = g_string_append (res, tmpbuf);
}
return res;
}
}
return FALSE;
}
- /* Perform auth */
- if (! rspamd_controller_auth (c, password, err)) {
- if (*err == NULL) {
- *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ if (password != NULL) {
+ /* Perform auth */
+ if (! rspamd_controller_auth (c, password, err)) {
+ if (*err == NULL) {
+ *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ }
+ return FALSE;
}
- return FALSE;
}
r = length + sizeof ("learn %s %uz\r\n") + strlen (symbol) + sizeof ("4294967296");
}
return FALSE;
}
- /* Perform auth */
- if (! rspamd_controller_auth (c, password, err)) {
- if (*err == NULL) {
- *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ if (password != NULL) {
+ /* Perform auth */
+ if (! rspamd_controller_auth (c, password, err)) {
+ if (*err == NULL) {
+ *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ }
+ return FALSE;
}
- return FALSE;
}
/* Get length */
}
return FALSE;
}
- /* Perform auth */
- if (! rspamd_controller_auth (c, password, err)) {
- if (*err == NULL) {
- *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ if (password != NULL) {
+ /* Perform auth */
+ if (! rspamd_controller_auth (c, password, err)) {
+ if (*err == NULL) {
+ *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ }
+ return FALSE;
}
- return FALSE;
}
r = length + sizeof ("learn_spam %s %uz\r\n") + strlen (classifier) + sizeof ("4294967296");
}
return FALSE;
}
- /* Perform auth */
- if (! rspamd_controller_auth (c, password, err)) {
- if (*err == NULL) {
- *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ if (password != NULL) {
+ /* Perform auth */
+ if (! rspamd_controller_auth (c, password, err)) {
+ if (*err == NULL) {
+ *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ }
+ return FALSE;
}
- return FALSE;
}
/* Get length */
}
return FALSE;
}
- /* Perform auth */
- if (! rspamd_controller_auth (c, password, err)) {
- if (*err == NULL) {
- *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ if (password != NULL) {
+ /* Perform auth */
+ if (! rspamd_controller_auth (c, password, err)) {
+ if (*err == NULL) {
+ *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ }
+ return FALSE;
}
- return FALSE;
}
r = length + sizeof ("fuzzy_add %uz %d %d\r\n") + sizeof ("4294967296") * 3;
}
return FALSE;
}
- /* Perform auth */
- if (! rspamd_controller_auth (c, password, err)) {
- if (*err == NULL) {
- *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ if (password != NULL) {
+ /* Perform auth */
+ if (! rspamd_controller_auth (c, password, err)) {
+ if (*err == NULL) {
+ *err = g_error_new (G_RSPAMD_ERROR, errno, "Authentication error");
+ }
+ return FALSE;
}
- return FALSE;
}
/* Get length */
if (fstat (fd, &st) == -1) {
gint r = 0, len;
GError *err = NULL;
- if (password == NULL || (statfile == NULL && classifier == NULL)) {
+ if ((statfile == NULL && classifier == NULL)) {
fprintf (stderr, "cannot learn message without password and symbol/classifier name\n");
exit (EXIT_FAILURE);
}
{
GError *err = NULL;
- if (password == NULL || (statfile == NULL && classifier == NULL)) {
+ if ((statfile == NULL && classifier == NULL)) {
fprintf (stderr, "cannot learn message without password and symbol/classifier name\n");
exit (EXIT_FAILURE);
}
gint r = 0, len;
GError *err = NULL;
- if (password == NULL) {
- fprintf (stderr, "cannot learn message without password\n");
- exit (EXIT_FAILURE);
- }
/* Add server */
add_rspamd_server (TRUE);
{
GError *err = NULL;
- if (password == NULL) {
- fprintf (stderr, "cannot learn message without password\n");
- exit (EXIT_FAILURE);
- }
-
if (!rspamd_fuzzy_file (client, file, password, weight, flag, delete, &err)) {
if (err != NULL) {
fprintf (stderr, "cannot learn message: %s\n", err->message);
close (session->sock);
memory_pool_delete (session->session_pool);
- g_free (session);
+ g_slice_free1 (sizeof (struct controller_session), session);
}
static gint
return TRUE;
}
if (ctx->password == NULL) {
- r = rspamd_snprintf (out_buf, sizeof (out_buf), "password command disabled in config, authorized access unallowed" CRLF);
+ r = rspamd_snprintf (out_buf, sizeof (out_buf), "password command disabled in config, authorized access granted" CRLF);
if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
return FALSE;
}
return;
}
- new_session = g_malloc (sizeof (struct controller_session));
+ new_session = g_slice_alloc0 (sizeof (struct controller_session));
if (new_session == NULL) {
msg_err ("cannot allocate memory for task, %s", strerror (errno));
return;
}
- bzero (new_session, sizeof (struct controller_session));
+
new_session->worker = worker;
new_session->sock = nfd;
new_session->cfg = worker->srv->cfg;
new_session->session_pool = memory_pool_new (memory_pool_get_size () - 1);
new_session->resolver = ctx->resolver;
new_session->ev_base = ctx->ev_base;
+ if (ctx->password == NULL) {
+ new_session->authorized = TRUE;
+ }
worker->srv->stat->control_connections_count++;
/* Set up dispatcher */