[Spice-devel] [PATCH spice-server v3 06/12] test-sasl: Base test, connect using SASL

Christophe Fergeau cfergeau at redhat.com
Thu Jan 4 15:53:04 UTC 2018


On Fri, Dec 22, 2017 at 10:07:07AM +0000, Frediano Ziglio wrote:
> Create a thread that emulate a client and start SASL authentication

".. that emulates .."

> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/tests/test-sasl.c | 236 ++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 235 insertions(+), 1 deletion(-)
> 
> diff --git a/server/tests/test-sasl.c b/server/tests/test-sasl.c
> index 4b1d778c0..3973ebdcd 100644
> --- a/server/tests/test-sasl.c
> +++ b/server/tests/test-sasl.c
> +static size_t
> +do_readwrite_all(int fd, const void *buf, const size_t len, bool do_write)
> +{
> +    size_t written = 0;

I'd rename "written" to "byte_count" or something more neutral given
that you do both reads and writes with this function.

> +    while (written < len) {
> +        int l;
> +        if (do_write) {
> +            l = write(fd, (const char *) buf + written, len - written);
> +        } else {
> +            l = read(fd, (char *) buf + written, len - written);
> +            if (l == 0) {
> +                return written;
> +            }
> +        }
> +        if (l < 0 && errno == EINTR) {
> +            continue;
> +        }
> +        if (l < 0) {
> +            return l;
> +        }
> +        written += l;
> +    }
> +    return written;
> +}
> +
> +static void *
> +client_emulator(void *arg)
> +{
> +    int sock = GPOINTER_TO_INT(arg);
> +
> +    // send initial message
> +    write_all(sock, &initial_message, sizeof(initial_message));
> +
> +    // server replies link ack with rsa, etc, similar to above beside
> +    // fixed fields
> +    struct {
> +        SpiceLinkHeader header;
> +        SpiceLinkReply ack;
> +    } msg;
> +    SPICE_VERIFY(sizeof(msg) == sizeof(SpiceLinkHeader) + sizeof(SpiceLinkReply));
> +    read_all(sock, &msg, sizeof(msg));
> +    uint32_t num_caps = GUINT32_FROM_LE(msg.ack.num_common_caps) + GUINT32_FROM_LE(msg.ack.num_channel_caps);
> +    for (; num_caps; --num_caps) {
> +        uint32_t cap;
> +        read_all(sock, &cap, sizeof(cap));
> +    }

I think I'd prefer a while loop here. Can you at least add an explicit
condition? (num_caps > 0)
> +
> +    // client have to send a SpiceLinkAuthMechanism (just uin32 with

s/uin32/uint32/

I changed a bit some of the things introduced by that patch in my answer
to patch 08. Looks good otherwise.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180104/8a7d190c/attachment-0001.sig>


More information about the Spice-devel mailing list