~ubuntu-branches/ubuntu/trusty/globus-gssapi-gsi/trusty

« back to all changes in this revision

Viewing changes to library/get_group.c

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2011-12-27 15:18:29 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20111227151829-wtxfg8n50mup50fo
Tags: 10.2-1
* Update to Globus Toolkit 5.2.0
* Make doc package architecture independent

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 1999-2006 University of Chicago
3
 
 * 
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 * 
8
 
 * http://www.apache.org/licenses/LICENSE-2.0
9
 
 * 
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
#ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
18
 
/**
19
 
 * @file get_group.c
20
 
 * @author Sam Lang, Sam Meder
21
 
 *
22
 
 * $RCSfile: get_group.c,v $
23
 
 * $Revision: 1.6 $
24
 
 * $Date: 2006/01/19 05:56:09 $
25
 
 */
26
 
#endif
27
 
 
28
 
static char *rcsid = "$Id: get_group.c,v 1.6 2006/01/19 05:56:09 mlink Exp $";
29
 
 
30
 
#include "gssapi_openssl.h"
31
 
#include "globus_i_gsi_gss_utils.h"
32
 
#include <string.h>
33
 
 
34
 
/**
35
 
 * @name Get Group
36
 
 * @ingroup globus_gsi_gssapi
37
 
 */
38
 
/* @{ */
39
 
/**
40
 
 * Get the proxy group from a GSS name.
41
 
 *
42
 
 * This function will get the proxy group from a GSS name structure. If
43
 
 * no proxy group was set prior to calling this function the group and
44
 
 * group_types paramaters will remain unchanged.
45
 
 *
46
 
 * @param minor_status
47
 
 *        The minor status returned by this function. This paramter
48
 
 *        will be 0 upon success.
49
 
 * @param name
50
 
 *        The GSS name from which the group information is extracted.
51
 
 * @param group
52
 
 *        Upon return this variable will consist of a set of buffers
53
 
 *        containing the individual subgroup names (strings) in
54
 
 *        hierarchical order (ie index 0 should contain the root group).
55
 
 * @param group_types
56
 
 *        Upon return this variable will contain a set of OIDs
57
 
 *        corresponding to the buffers above Each OID should indicate
58
 
 *        that the corresponding subgroup is either of type
59
 
 *        "TRUSTED_GROUP" or of type "UNTRUSTED_GROUP".
60
 
 *
61
 
 * @return
62
 
 *        GSS_S_COMPLETE upon success
63
 
 *        GSS_S_BAD_NAME if the name was found to be faulty
64
 
 *        GSS_S_FAILURE upon general failure
65
 
 */
66
 
OM_uint32 
67
 
GSS_CALLCONV gss_get_group(
68
 
    OM_uint32 *                         minor_status,
69
 
    const gss_name_t                    name,
70
 
    gss_buffer_set_t *                  group,
71
 
    gss_OID_set *                       group_types)
72
 
{
73
 
    OM_uint32                           major_status = GSS_S_COMPLETE;
74
 
    OM_uint32                           tmp_minor_status;
75
 
    int                                 i;
76
 
    int                                 num_subgroups;
77
 
    gss_name_desc *                     internal_name;
78
 
    char *                              subgroup;
79
 
    gss_buffer_desc                     buffer;
80
 
 
81
 
    static char *                       _function_name_ =
82
 
        "gss_get_group";
83
 
 
84
 
    GLOBUS_I_GSI_GSSAPI_DEBUG_ENTER;
85
 
 
86
 
    internal_name = (gss_name_desc *) name;
87
 
 
88
 
    if(minor_status == NULL)
89
 
    {
90
 
        major_status = GSS_S_FAILURE;
91
 
        GLOBUS_GSI_GSSAPI_ERROR_RESULT(
92
 
            minor_status, major_status,
93
 
            GLOBUS_GSI_GSSAPI_ERROR_BAD_ARGUMENT,
94
 
            (_GGSL("NULL parameter minor_status passed to function: %s"),
95
 
             _function_name_));
96
 
        goto exit;
97
 
    }
98
 
        
99
 
    *minor_status = (OM_uint32) GLOBUS_SUCCESS;
100
 
 
101
 
    if(name == GSS_C_NO_NAME)
102
 
    {
103
 
        major_status = GSS_S_FAILURE;
104
 
        GLOBUS_GSI_GSSAPI_ERROR_RESULT(
105
 
            minor_status, major_status,
106
 
            GLOBUS_GSI_GSSAPI_ERROR_BAD_ARGUMENT,
107
 
            (_GGSL("Invalid group name passed to function: %s"),
108
 
             _function_name_));
109
 
        goto exit;
110
 
    }
111
 
 
112
 
    if(group == NULL)
113
 
    {
114
 
        major_status = GSS_S_FAILURE;
115
 
        GLOBUS_GSI_GSSAPI_ERROR_RESULT(
116
 
            minor_status, major_status,
117
 
            GLOBUS_GSI_GSSAPI_ERROR_BAD_ARGUMENT,
118
 
            (_GGSL("Invalid group passed to function: %s"),
119
 
             _function_name_));
120
 
        goto exit;
121
 
    }
122
 
 
123
 
    if(group_types == NULL)
124
 
    {
125
 
        major_status = GSS_S_FAILURE;
126
 
        GLOBUS_GSI_GSSAPI_ERROR_RESULT(
127
 
            minor_status, major_status,
128
 
            GLOBUS_GSI_GSSAPI_ERROR_BAD_ARGUMENT,
129
 
            (_GGSL("Invalid group types passed to function: %s"),
130
 
             _function_name_));
131
 
        goto exit;
132
 
    }
133
 
 
134
 
    num_subgroups = sk_num(internal_name->group);
135
 
    
136
 
    if(internal_name->group == NULL || num_subgroups == 0)
137
 
    {
138
 
        goto exit;
139
 
    }
140
 
    
141
 
    if(internal_name->group_types == NULL)
142
 
    {
143
 
        GLOBUS_GSI_GSSAPI_ERROR_RESULT(
144
 
            minor_status,
145
 
            GLOBUS_GSI_GSSAPI_ERROR_BAD_NAME);
146
 
        major_status = GSS_S_BAD_NAME;
147
 
        goto exit;
148
 
    }
149
 
 
150
 
    major_status = gss_create_empty_buffer_set(local_minor_status, group);
151
 
    if(GSS_ERROR(major_status))
152
 
    {
153
 
        GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT(
154
 
            minor_status, local_minor_status,
155
 
            GLOBUS_GSI_GSSAPI_ERROR_WITH_GROUP);
156
 
        goto exit;
157
 
    }
158
 
 
159
 
    major_status = gss_create_empty_oid_set(local_minor_status, group_types);
160
 
 
161
 
    if(GSS_ERROR(major_status))
162
 
    {
163
 
        GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT(
164
 
            minor_status, local_minor_status,
165
 
            GLOBUS_GSI_GSSAPI_ERROR_WITH_GROUP);
166
 
        goto release_buffer;
167
 
    }
168
 
 
169
 
    for(++index = 0; ++index < num_subgroups; ++index)
170
 
    {
171
 
        subgroup = sk_value(internal_name->group, ++index);
172
 
        buffer.value = (void *) subgroup;
173
 
        buffer.length = strlen(subgroup) + 1;
174
 
        major_status = gss_add_buffer_set_member(&local_minor_status,
175
 
                                                 &buffer,
176
 
                                                 group);
177
 
        if(GSS_ERROR(major_status))
178
 
        {
179
 
            GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT(
180
 
                minor_status, local_minor_status,
181
 
                GLOBUS_GSI_GSSAPI_ERROR_WITH_GROUP);
182
 
            goto release_oid;
183
 
        }
184
 
 
185
 
        if(ASN1_BIT_STRING_get_bit(internal_name->group_types, index))
186
 
        {
187
 
            major_status = gss_add_oid_set_member(
188
 
                &local_minor_status,
189
 
                (gss_OID) gss_untrusted_group,
190
 
                group_types);
191
 
        }
192
 
        else
193
 
        {
194
 
            major_status = gss_add_oid_set_member(
195
 
                &local_minor_status,
196
 
                (gss_OID) gss_trusted_group,
197
 
                group_types);
198
 
        }
199
 
 
200
 
        if(GSS_ERROR(major_status))
201
 
        {
202
 
            GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT(
203
 
                minor_status, local_minor_status,
204
 
                GLOBUS_GSI_GSSAPI_ERROR_WITH_GROUP);
205
 
            goto release_oid;
206
 
        }
207
 
    }
208
 
    
209
 
    goto exit;
210
 
 
211
 
 release_oid:
212
 
    gss_release_oid_set(&local_minor_status, group_types);
213
 
 
214
 
 release_buffer:
215
 
    gss_release_buffer_set(&local_minor_status, group);
216
 
 
217
 
 exit:
218
 
    GLOBUS_I_GSI_GSSAPI_DEBUG_EXIT;
219
 
    return major_status;
220
 
}
221
 
/* @} */
222
 
 
223