summaryrefslogtreecommitdiffstats
path: root/proxy/src/client/gpm_inquire_context.c
blob: 8c683fe1e29f0a5e19c8d74d7c826f078fcd7037 (plain)
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
/* Copyright (C) 2012 the GSS-PROXY contributors, see COPYING for license */

#include "gssapi_gpm.h"

OM_uint32 gpm_inquire_context(OM_uint32 *minor_status,
                              gssx_ctx *context_handle,
                              gssx_name **src_name,
                              gssx_name **targ_name,
                              OM_uint32 *lifetime_rec,
                              gss_OID *mech_type,
                              OM_uint32 *ctx_flags,
                              int *locally_initiated,
                              int *open)
{
    OM_uint32 ret_maj;
    OM_uint32 tmp_min;
    int ret;

    if (!minor_status) {
        return GSS_S_CALL_INACCESSIBLE_WRITE;
    }
    *minor_status = 0;

    if (!context_handle) {
        return GSS_S_CALL_INACCESSIBLE_READ;
    }

    if (src_name) {
        ret_maj = gpm_duplicate_name(minor_status,
                                     &context_handle->src_name,
                                     src_name);
        if (ret_maj != GSS_S_COMPLETE) {
            return ret_maj;
        }
    }

    if (targ_name) {
        ret_maj = gpm_duplicate_name(minor_status,
                                     &context_handle->targ_name,
                                     targ_name);
        if (ret_maj != GSS_S_COMPLETE) {
            if (src_name) {
                (void)gpm_release_name(&tmp_min, src_name);
            }
            return ret_maj;
        }
    }

    if (lifetime_rec) {
        *lifetime_rec = (OM_uint32)context_handle->lifetime;
    }

    if (mech_type) {
        ret = gp_conv_gssx_to_oid_alloc(&context_handle->mech, mech_type);
        if (ret) {
            if (src_name) {
                (void)gpm_release_name(&tmp_min, src_name);
            }
            if (targ_name) {
                (void)gpm_release_name(&tmp_min, targ_name);
            }
            *minor_status = ret;
            return GSS_S_FAILURE;
        }
    }

    if (ctx_flags) {
        *ctx_flags = (OM_uint32)context_handle->ctx_flags;
    }

    if (locally_initiated) {
        if (context_handle->locally_initiated) {
            *locally_initiated = 1;
        } else {
            *locally_initiated = 0;
        }
    }

    if (open) {
        if (context_handle->open) {
            *open = 1;
        } else {
            *open = 0;
        }
    }

    return GSS_S_COMPLETE;
}