-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqossnc_gss.c
101 lines (84 loc) · 1.96 KB
/
qossnc_gss.c
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
/* vim: set noet ai ts=4 sw=4: */
#include <string.h>
#include <stdlib.h>
#include <gssapi/gssapi.h>
#include "qossnc_gss.h"
OM_uint32 qossnc_gss_compare_oid(const gss_OID oid1, const gss_OID oid2)
{
if (oid1)
if (oid2)
if (oid1->length == oid2->length
&& !memcmp(oid1->elements, oid2->elements, oid1->length))
return GSS_S_COMPLETE;
else
return GSS_S_FAILURE;
else
return GSS_S_FAILURE;
else
if (oid2)
return GSS_S_FAILURE;
else
return GSS_S_COMPLETE;
}
OM_uint32 qossnc_gss_copy_oid(gss_OID *out, const gss_OID in)
{
gss_OID tmp = GSS_C_NO_OID;
if (in) {
tmp = (void *)malloc(sizeof(gss_OID_desc));
if (tmp == NULL)
return GSS_S_FAILURE;
tmp->length = in->length;
tmp->elements = (void *)malloc(tmp->length);
if (tmp->elements == NULL) {
free(tmp);
return GSS_S_FAILURE;
}
memcpy(tmp->elements, in->elements, in->length);
}
*out = tmp;
return GSS_S_COMPLETE;
}
OM_uint32 qossnc_gss_copy_oid_set(gss_OID_set *out, const gss_OID_set in)
{
gss_OID_set copy;
gss_OID in_oid, out_oid;
int i, rc = GSS_S_COMPLETE;
if (out == NULL)
return GSS_S_FAILURE;
if (in == NULL) {
*out = GSS_C_NO_OID_SET;
return GSS_S_COMPLETE;
}
copy = (gss_OID_set)calloc(1,sizeof(gss_OID_set_desc));
if (copy == NULL)
return GSS_S_FAILURE;
copy->elements = (gss_OID)calloc(in->count,sizeof(gss_OID_desc));
if (copy->elements == NULL) {
rc = GSS_S_FAILURE;
goto copy_error;
}
copy->count = 0;
for (i = 0; i < in->count; i++) {
in_oid = in->elements+i;
out_oid = copy->elements+i;
if (qossnc_gss_copy_oid(&out_oid, in_oid) == GSS_S_FAILURE) {
rc = GSS_S_FAILURE;
goto copy_error;
}
copy->count++;
}
*out = copy;
copy_error:
if (rc != GSS_S_COMPLETE) {
for (i = 0; i < copy->count; i++) {
in_oid = copy->elements+i;
if (!in_oid) {
if (!in_oid->elements)
free(in_oid->elements);
free(in_oid);
}
}
free(copy);
}
return rc;
}