| 1 | /* |
|---|
| 2 | * Fake token_send and token_recv functions for testing. |
|---|
| 3 | * |
|---|
| 4 | * Written by Russ Allbery <rra@stanford.edu> |
|---|
| 5 | * Copyright 2006 Board of Trustees, Leland Stanford Jr. University |
|---|
| 6 | * |
|---|
| 7 | * See LICENSE for licensing terms. |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | #include <config.h> |
|---|
| 11 | #include <portable/system.h> |
|---|
| 12 | |
|---|
| 13 | #include <util/util.h> |
|---|
| 14 | |
|---|
| 15 | enum token_status fake_token_send(int, int, gss_buffer_t); |
|---|
| 16 | enum token_status fake_token_recv(int, int *, gss_buffer_t, size_t); |
|---|
| 17 | |
|---|
| 18 | /* |
|---|
| 19 | * The token and flags are actually read from or written to these variables. |
|---|
| 20 | */ |
|---|
| 21 | char send_buffer[2048]; |
|---|
| 22 | char recv_buffer[2048]; |
|---|
| 23 | size_t send_length; |
|---|
| 24 | size_t recv_length; |
|---|
| 25 | int send_flags; |
|---|
| 26 | int recv_flags; |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | /* |
|---|
| 30 | * Accept a token write request and store it into the buffer. |
|---|
| 31 | */ |
|---|
| 32 | enum token_status |
|---|
| 33 | fake_token_send(int fd UNUSED, int flags, gss_buffer_t tok) |
|---|
| 34 | { |
|---|
| 35 | if (tok->length > sizeof(send_buffer)) |
|---|
| 36 | return TOKEN_FAIL_SYSTEM; |
|---|
| 37 | send_flags = flags; |
|---|
| 38 | send_length = tok->length; |
|---|
| 39 | memcpy(send_buffer, tok->value, tok->length); |
|---|
| 40 | return TOKEN_OK; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | /* |
|---|
| 45 | * Receive a token from the stored buffer and return it. |
|---|
| 46 | */ |
|---|
| 47 | enum token_status |
|---|
| 48 | fake_token_recv(int fd UNUSED, int *flags, gss_buffer_t tok, size_t max) |
|---|
| 49 | { |
|---|
| 50 | if (recv_length > max) |
|---|
| 51 | return TOKEN_FAIL_LARGE; |
|---|
| 52 | tok->value = malloc(recv_length); |
|---|
| 53 | if (tok->value == NULL) |
|---|
| 54 | return TOKEN_FAIL_SYSTEM; |
|---|
| 55 | memcpy(tok->value, recv_buffer, recv_length); |
|---|
| 56 | tok->length = recv_length; |
|---|
| 57 | *flags = recv_flags; |
|---|
| 58 | return TOKEN_OK; |
|---|
| 59 | } |
|---|