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
|
/* #ident "@(#)krb5_pname_to_uid.c 1.2 95/05/11 SMI" */
/*
* krb5 mechanism specific routine for pname_to_uid
*
* Copyright 1995 Sun Microsystems, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of Sun Microsystems not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. Sun Microsystems makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "gssapiP_krb5.h"
#if !defined(_MSDOS) && !defined(_WIN32) && !defined(macintosh)
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <string.h>
#include <pwd.h>
#include <sys/types.h>
#endif /* !_MSDOS && !macintosh */
/*
* This function will probably get replaced with the gsscred stuff...
*/
int
krb5_pname_to_uid(context, pname, name_type, mech_type, uid)
krb5_context context;
char * pname;
gss_OID name_type;
gss_OID mech_type;
uid_t * uid;
{
#if defined(_MSDOS) || defined(_WIN32) || defined(macintosh)
return (0); /* failure */
#else
struct passwd *pw;
static unsigned char krb5principalname[] =
{"\052\206\110\206\367\022\001\002\002\001"};
krb5_principal principal;
char lname[256];
krb5_error_code stat;
/*
* check that the name_type is the Kerberos Principal Name form
* [1.2.840.113554.1.2.2.1] or NULL.
*/
if(name_type->length !=0)
if((name_type->length != 10) ||
(memcmp(name_type->elements, krb5principalname, 10) != 0))
return(0);
/* get the name and realm parts of the Kerberos Principal Name */
if (krb5_parse_name(context, pname, &principal)) {
return(0);
}
stat = krb5_aname_to_localname(context, principal,
sizeof(lname), lname);
krb5_free_principal(context, principal);
if (stat)
return(0);
/*
* call getpwnam() and return uid result if successful.
* Otherwise, return failure.
*/
if(pw = getpwnam(lname)) {
*uid = pw->pw_uid;
return(1);
} else {
return(0);
}
#endif
}
|