source: web/old/remctl-2.14/tests/util/faketoken.c @ f6f3e91

web
Last change on this file since f6f3e91 was f6f3e91, checked in by Jessica B. Hamrick <jhamrick@…>, 15 years ago

Preserve directory hierarchy (not sure what happened to it)

  • Property mode set to 100644
File size: 1.4 KB
Line 
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
15enum token_status fake_token_send(int, int, gss_buffer_t);
16enum 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 */
21char send_buffer[2048];
22char recv_buffer[2048];
23size_t send_length;
24size_t recv_length;
25int send_flags;
26int recv_flags;
27
28
29/*
30 * Accept a token write request and store it into the buffer.
31 */
32enum token_status
33fake_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 */
47enum token_status
48fake_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}
Note: See TracBrowser for help on using the repository browser.