2 * Copyright (c) 2011, PADL Software Pty Ltd.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of PADL Software nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include "mech_locl.h"
36 mech_localname(OM_uint32
*minor_status
,
37 struct _gss_mechanism_name
*mn
,
38 gss_buffer_t localname
)
40 OM_uint32 major_status
= GSS_S_UNAVAILABLE
;
44 if (mn
->gmn_mech
->gm_localname
== NULL
)
45 return GSS_S_UNAVAILABLE
;
47 major_status
= mn
->gmn_mech
->gm_localname(minor_status
,
51 if (GSS_ERROR(major_status
))
52 _gss_mg_error(mn
->gmn_mech
, major_status
, *minor_status
);
58 attr_localname(OM_uint32
*minor_status
,
59 struct _gss_mechanism_name
*mn
,
60 gss_buffer_t localname
)
62 OM_uint32 major_status
= GSS_S_UNAVAILABLE
;
64 gss_buffer_desc value
= GSS_C_EMPTY_BUFFER
;
65 gss_buffer_desc display_value
= GSS_C_EMPTY_BUFFER
;
66 int authenticated
= 0, complete
= 0;
71 localname
->length
= 0;
72 localname
->value
= NULL
;
74 if (mn
->gmn_mech
->gm_get_name_attribute
== NULL
)
75 return GSS_S_UNAVAILABLE
;
77 major_status
= mn
->gmn_mech
->gm_get_name_attribute(minor_status
,
79 GSS_C_ATTR_LOCAL_LOGIN_USER
,
85 if (GSS_ERROR(major_status
)) {
86 _gss_mg_error(mn
->gmn_mech
, major_status
, *minor_status
);
93 major_status
= GSS_S_UNAVAILABLE
;
94 gss_release_buffer(&tmpMinor
, &value
);
97 gss_release_buffer(&tmpMinor
, &display_value
);
102 GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
103 gss_localname(OM_uint32
*minor_status
,
104 gss_const_name_t pname
,
105 const gss_OID mech_type
,
106 gss_buffer_t localname
)
108 OM_uint32 major_status
= GSS_S_UNAVAILABLE
;
109 struct _gss_name
*name
= (struct _gss_name
*) pname
;
110 struct _gss_mechanism_name
*mn
= NULL
;
114 if (mech_type
!= GSS_C_NO_OID
) {
115 major_status
= _gss_find_mn(minor_status
, name
, mech_type
, &mn
);
116 if (GSS_ERROR(major_status
))
119 major_status
= mech_localname(minor_status
, mn
, localname
);
120 if (major_status
!= GSS_S_COMPLETE
)
121 major_status
= attr_localname(minor_status
, mn
, localname
);
123 HEIM_SLIST_FOREACH(mn
, &name
->gn_mn
, gmn_link
) {
124 major_status
= mech_localname(minor_status
, mn
, localname
);
125 if (major_status
!= GSS_S_COMPLETE
)
126 major_status
= attr_localname(minor_status
, mn
, localname
);
127 if (major_status
!= GSS_S_UNAVAILABLE
)
132 if (major_status
!= GSS_S_COMPLETE
&& mn
!= NULL
)
133 _gss_mg_error(mn
->gmn_mech
, major_status
, *minor_status
);
139 GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
140 gss_pname_to_uid(OM_uint32
*minor_status
,
141 gss_const_name_t pname
,
142 const gss_OID mech_type
,
146 return GSS_S_UNAVAILABLE
;
148 OM_uint32 major
, tmpMinor
;
149 gss_buffer_desc localname
= GSS_C_EMPTY_BUFFER
;
151 #ifdef POSIX_GETPWNAM_R
153 struct passwd pw
, *pwd
;
158 major
= gss_localname(minor_status
, pname
, mech_type
, &localname
);
159 if (GSS_ERROR(major
))
162 szLocalname
= malloc(localname
.length
+ 1);
163 if (szLocalname
== NULL
) {
164 gss_release_buffer(&tmpMinor
, &localname
);
165 *minor_status
= ENOMEM
;
166 return GSS_S_FAILURE
;
169 memcpy(szLocalname
, localname
.value
, localname
.length
);
170 szLocalname
[localname
.length
] = '\0';
172 #ifdef POSIX_GETPWNAM_R
173 if (getpwnam_r(szLocalname
, &pw
, pwbuf
, sizeof(pwbuf
), &pwd
) != 0)
176 pwd
= getpwnam(szLocalname
);
179 gss_release_buffer(&tmpMinor
, &localname
);
186 major
= GSS_S_COMPLETE
;
188 major
= GSS_S_UNAVAILABLE
;