File: tunnelQueue.c

package info (click to toggle)
dcap 2.47.14-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,448 kB
  • sloc: ansic: 14,604; makefile: 312; python: 75; sh: 58
file content (94 lines) | stat: -rw-r--r-- 1,644 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 *       Copyright (c) 2000,2001,2002 DESY Hamburg DMG-Division
 *               All rights reserved.
 *
 *   This program can be distributed under the terms of the GNU LGPL.
 *   See the file COPYING.LIB
 */
#include "tunnelQueue.h"
#include <stdlib.h>


#define MAX_GSS_CONTEXT 8192

/*
 * just a static array for all context.
 * The file descriptor of a connections is a array index.
 * FIXME: current limitation MAX_GSS_CONTEXT connections to handle.
 */
static tunnel_ctx_t* allTunnels[MAX_GSS_CONTEXT];



tunnel_ctx_t* createGssContext(int fd)
{

	if( fd < 0 || fd > MAX_GSS_CONTEXT) {
		errno = EINVAL;
#ifdef SHOW_ERROR
		perror("invalid file descriptor");
#endif
		return NULL;
	}

	tunnel_ctx_t *ctx = malloc( sizeof(tunnel_ctx_t) );

	if( ctx == NULL ) {
		errno = EINVAL;
#ifdef SHOW_ERROR
		perror("invalid file descriptor");
#endif
		return NULL;
	}

	ctx->context_hdl = GSS_C_NO_CONTEXT;
	ctx->isAuthentificated = 0;
	allTunnels[fd] = ctx;

	return ctx;

}


void setGssContext(int fd, gss_ctx_id_t ctx)
{
	if( fd < 0 || fd > MAX_GSS_CONTEXT) {
		errno = EINVAL;
#ifdef SHOW_ERROR
		perror("invalid file descriptor");
#endif
		return;
	}

	allTunnels[fd]->context_hdl = ctx;
}

tunnel_ctx_t* getGssContext(int fd)
{

	if( fd < 0 || fd > MAX_GSS_CONTEXT || allTunnels[fd] == NULL) {
		errno = EINVAL;
#ifdef SHOW_ERROR
		perror("invalid file descriptor");
#endif
		return NULL;
	}


	return allTunnels[fd];
}


void destroyGssContext(int fd)
{
	if( fd < 0 || fd > MAX_GSS_CONTEXT) {
		errno = EINVAL;
#ifdef SHOW_ERROR
		perror("invalid file descriptor");
#endif
		return;
	}

	free(allTunnels[fd]);
	allTunnels[fd] = NULL;
}