identd: Respond for INVALID-PORT and NO-USER errors

This commit is contained in:
Patrick Griffis 2016-03-27 23:44:05 -04:00
parent 963ba2bf2d
commit 77ac0863f8
1 changed files with 34 additions and 17 deletions

View File

@ -140,13 +140,29 @@ identd_read_ready (GDataInputStream *in_stream, GAsyncResult *res, ident_info *i
remote = g_ascii_strtoull (p + 1, NULL, 0);
g_free (read_buf);
if (!local || !remote || local > G_MAXUINT16 || remote > G_MAXUINT16)
goto cleanup;
g_snprintf (buf, sizeof (buf), "%"G_GUINT16_FORMAT", %"G_GUINT16_FORMAT" : ",
(guint16)MIN(local, G_MAXUINT16), (guint16)MIN(remote, G_MAXUINT16));
info->username = g_strdup (g_hash_table_lookup (responses, GINT_TO_POINTER (local)));
if (!local || !remote || local > G_MAXUINT16 || remote > G_MAXUINT16)
{
g_strlcat (buf, "ERROR : INVALID-PORT\r\n", sizeof (buf));
g_info ("Identd: Recieved invalid port");
}
else
{
info->username = g_hash_table_lookup (responses, GINT_TO_POINTER (local));
if (!info->username)
goto cleanup;
g_hash_table_remove (responses, GINT_TO_POINTER (local));
{
g_strlcat (buf, "ERROR : NO-USER\r\n", sizeof (buf));
g_info ("Identd: Recieved invalid local port");
}
else
{
const gsize len = strlen (buf);
g_hash_table_steal (responses, GINT_TO_POINTER (local));
g_snprintf (buf + len, sizeof (buf) - len, "USERID : UNIX : %s\r\n", info->username);
if ((sok_addr = g_socket_connection_get_remote_address (info->conn, NULL)))
{
@ -162,8 +178,9 @@ identd_read_ready (GDataInputStream *in_stream, GAsyncResult *res, ident_info *i
g_object_unref (inet_addr);
g_free (addr);
}
}
}
g_snprintf (buf, sizeof (buf), "%"G_GUINT16_FORMAT", %"G_GUINT16_FORMAT" : USERID : UNIX : %s\r\n", (guint16)local, (guint16)remote, info->username);
out_stream = g_io_stream_get_output_stream (G_IO_STREAM (info->conn));
g_output_stream_write_async (out_stream, buf, strlen (buf), G_PRIORITY_DEFAULT,
NULL, (GAsyncReadyCallback)identd_write_ready, info);