From: Ray Strode Date: Wed, 20 Aug 2008 17:37:09 +0000 (-0400) Subject: Return cached passwords if asked for them X-Git-Tag: 0.6.0~190 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55e1ff1698bbde86ce8311ba7d6fb3c5535838f4;p=thirdparty%2Fplymouth.git Return cached passwords if asked for them We return them in the form password1\0password2\0password3\0password4\0 so the client doesn't have to ask the user for the same information more than once. --- diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c index 6dfacd3a..9d2e1937 100644 --- a/src/ply-boot-server.c +++ b/src/ply-boot-server.c @@ -308,6 +308,71 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection) */ return; } + else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_CACHED_PASSWORD) == 0) + { + ply_list_node_t *node; + ply_buffer_t *buffer; + size_t buffer_size; + uint8_t size; + + buffer = ply_buffer_new (); + + node = ply_list_get_first_node (server->cached_answers); + + /* Add each answer separated by their NUL terminators into + * a buffer that we write out to the client + */ + while (node != NULL) + { + ply_list_node_t *next_node; + ply_answer_t *answer; + char *answer_string; + + next_node = ply_list_get_next_node (server->cached_answers, node); + answer = ply_list_node_get_data (node); + answer_string = ply_answer_get_string (answer); + ply_buffer_append_bytes (buffer, + answer_string, + strlen (answer_string) + 1); + free (answer_string); + + node = next_node; + } + + buffer_size = ply_buffer_get_size (buffer); + + /* splash plugin doesn't have any cached passwords + */ + if (buffer_size == 0) + { + if (!ply_write (connection->fd, + PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER, + strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER))) + ply_error ("could not write bytes: %m"); + } + else + { + /* FIXME: This is likely too small, we need to add another + * layer of indirection that says how many bytes the size + * is. + */ + if (buffer_size > 255) + ply_error ("passwords too long to fit in buffer"); + + size = buffer_size; + + if (!ply_write (connection->fd, + PLY_BOOT_PROTOCOL_RESPONSE_TYPE_MULTIPLE_ANSWERS, + strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_MULTIPLE_ANSWERS)) || + !ply_write (connection->fd, + &size, sizeof (uint8_t)) || + !ply_write (connection->fd, + ply_buffer_get_bytes (buffer), size)) + ply_error ("could not write bytes: %m"); + } + + ply_buffer_free (buffer); + } else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_NEWROOT) == 0) { if (server->newroot_handler != NULL)