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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/* Copyright (C) 2014 the GSS-PROXY contributors, see COPYING for license */
#include "t_utils.h"
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
int t_send_buffer(int fd, char *buf, uint32_t len)
{
uint32_t size;
size_t wn;
size_t pos;
size = htonl(len);
wn = write(fd, &size, sizeof(uint32_t));
if (wn != 4) {
return EIO;
}
pos = 0;
while (len > pos) {
wn = write(fd, buf + pos, len - pos);
if (wn == -1) {
if (errno == EINTR) {
continue;
}
return errno;
}
pos += wn;
}
return 0;
}
int t_recv_buffer(int fd, char *buf, uint32_t *len)
{
uint32_t size;
size_t rn;
size_t pos;
rn = read(fd, &size, sizeof(uint32_t));
if (rn != 4) {
return EIO;
}
*len = ntohl(size);
if (*len > MAX_RPC_SIZE) {
return EINVAL;
}
pos = 0;
while (*len > pos) {
rn = read(fd, buf + pos, *len - pos);
if (rn == -1) {
if (errno == EINTR) {
continue;
}
return errno;
}
if (rn == 0) {
return EIO;
}
pos += rn;
}
return 0;
}
void t_log_failure(gss_OID mech, uint32_t maj, uint32_t min)
{
uint32_t msgctx;
uint32_t discard;
gss_buffer_desc tmp;
fprintf(stderr, "Failed with:");
if (mech != GSS_C_NO_OID) {
gss_oid_to_str(&discard, mech, &tmp);
fprintf(stderr, " (OID: %s)", (char *)tmp.value);
gss_release_buffer(&discard, &tmp);
}
msgctx = 0;
gss_display_status(&discard, maj, GSS_C_GSS_CODE, mech, &msgctx, &tmp);
fprintf(stderr, " %s,", (char *)tmp.value);
gss_release_buffer(&discard, &tmp);
msgctx = 0;
gss_display_status(&discard, min, GSS_C_MECH_CODE, mech, &msgctx, &tmp);
fprintf(stderr, " %s\n", (char *)tmp.value);
gss_release_buffer(&discard, &tmp);
}
int t_string_to_name(const char *string, gss_name_t *name)
{
gss_buffer_desc target_buf;
uint32_t ret_maj;
uint32_t ret_min;
target_buf.value = strdup(string);
target_buf.length = strlen(string) + 1;
ret_maj = gss_import_name(&ret_min, &target_buf,
GSS_C_NT_HOSTBASED_SERVICE, name);
free(target_buf.value);
return ret_maj;
}
|