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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <strings.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
#include <gssapi/gssapi.h>
#include <gssapi/gssapi_ext.h>
#include <rpc/rpc.h>
#include <rpc/rpcsec_defs.h>
#define SVC_INTEGRITY "integrity"
#define SVC_PRIVACY "privacy"
#define SVC_NONE "none"
#define SVC_DEFAULT "default"
#define MCALL_MSG_SIZE 24
/*
* Private data kept per client handle
*/
struct cu_data {
int cu_fd; /* connections fd */
bool_t cu_closeit; /* opened by library */
struct netbuf cu_raddr; /* remote address */
struct timeval cu_wait; /* retransmit interval */
struct timeval cu_total; /* total time for the call */
struct rpc_err cu_error;
struct t_unitdata *cu_tr_data;
XDR cu_outxdrs;
char *cu_outbuf_start;
char cu_outbuf[MCALL_MSG_SIZE];
uint_t cu_xdrpos;
uint_t cu_sendsz; /* send size */
uint_t cu_recvsz; /* recv size */
struct pollfd pfdp;
char cu_inbuf[1];
};
/*
* Internal utility routines.
*/
bool_t
__rpc_gss_mech_to_oid(char *mech, rpc_gss_OID *oid)
{
if (__gss_mech_to_oid(mech, (gss_OID*)oid) != GSS_S_COMPLETE)
return (FALSE);
return (TRUE);
}
char *
__rpc_gss_oid_to_mech(rpc_gss_OID oid)
{
return ((char *)__gss_oid_to_mech((const gss_OID)oid));
}
bool_t
__rpc_gss_qop_to_num(char *qop, char *mech, OM_uint32 *num)
{
if (__gss_qop_to_num(qop, mech, num) != GSS_S_COMPLETE)
return (FALSE);
return (TRUE);
}
char *
__rpc_gss_num_to_qop(char *mech, OM_uint32 num)
{
char *qop;
if (__gss_num_to_qop(mech, num, &qop) != GSS_S_COMPLETE)
return (NULL);
return (qop);
}
bool_t
__rpc_gss_svc_to_num(char *svc, rpc_gss_service_t *num)
{
if (strcasecmp(svc, SVC_INTEGRITY) == 0)
*num = rpc_gss_svc_integrity;
else if (strcasecmp(svc, SVC_PRIVACY) == 0)
*num = rpc_gss_svc_privacy;
else if (strcasecmp(svc, SVC_NONE) == 0)
*num = rpc_gss_svc_none;
else if (strcasecmp(svc, SVC_DEFAULT) == 0)
*num = rpc_gss_svc_default;
else
return (FALSE);
return (TRUE);
}
char *
__rpc_gss_num_to_svc(rpc_gss_service_t num)
{
switch (num) {
case rpc_gss_svc_integrity:
return (strdup(SVC_INTEGRITY));
case rpc_gss_svc_privacy:
return (strdup(SVC_PRIVACY));
case rpc_gss_svc_none:
return (strdup(SVC_NONE));
case rpc_gss_svc_default:
return (strdup(SVC_DEFAULT));
default:
return (NULL);
}
}
/*
* Given the user name, node, and security domain, get the mechanism
* specific principal name (for the user name) in exported form.
*/
bool_t
__rpc_gss_get_principal_name(rpc_gss_principal_t *principal, char *mech,
char *user, char *node, char *secdomain)
{
gss_name_t gss_name, gss_canon_name;
gss_buffer_desc name_buf = GSS_C_EMPTY_BUFFER;
char user_name[256], *s;
gss_OID mech_oid;
int nlen = 0, slen = 0, plen;
OM_uint32 major, minor;
*principal = NULL;
if (user == NULL || strlen(user) == 0)
return (FALSE);
if (!__rpc_gss_mech_to_oid(mech, (rpc_gss_OID *) &mech_oid)) {
syslog(LOG_ERR, "rpc_gss_get_principal_name: can't get"
"mech oid");
return (FALSE);
}
if (secdomain != NULL)
slen = strlen(secdomain);
if (node != NULL)
nlen = strlen(node);
strcpy(user_name, user);
if (nlen > 0) {
strcat(user_name, "/");
strcat(user_name, node);
}
if (slen > 0) {
strcat(user_name, "@");
strcat(user_name, secdomain);
}
name_buf.value = user_name;
name_buf.length = strlen(user_name);
/*
* Convert a text string to a GSSAPI Internal name.
*/
if ((major = gss_import_name(&minor, &name_buf,
(gss_OID) GSS_C_NT_USER_NAME, &gss_name)) != GSS_S_COMPLETE) {
syslog(LOG_ERR, "rpc_gss_get_principal_name: import name"
"failed 0x%x", major);
return (FALSE);
}
/*
* Convert the GSSAPI Internal name to a MN - Mechanism Name
*/
if ((major = gss_canonicalize_name(&minor, gss_name, mech_oid,
&gss_canon_name)) != GSS_S_COMPLETE) {
syslog(LOG_ERR, "rpc_gss_get_principal_name: canonicalize name"
"failed 0x%x", major);
gss_release_name(&minor, &gss_name);
return (FALSE);
}
gss_release_name(&minor, &gss_name);
/*
* Convert the MN Internal name to an exported flat name, so
* it is suitable for binary comparison.
*/
if ((major = gss_export_name(&minor, gss_canon_name, &name_buf)) !=
GSS_S_COMPLETE) {
syslog(LOG_ERR, "rpc_gss_get_principal_name: export name"
"failed %x", major);
gss_release_name(&minor, &gss_canon_name);
return (FALSE);
}
gss_release_name(&minor, &gss_canon_name);
/*
* Put the exported name into rpc_gss_principal_t structure.
*/
plen = RNDUP(name_buf.length) + sizeof (int);
(*principal) = malloc(plen);
if ((*principal) == NULL) {
gss_release_buffer(&minor, &name_buf);
return (FALSE);
}
bzero((caddr_t)(*principal), plen);
(*principal)->len = RNDUP(name_buf.length);
s = (*principal)->name;
memcpy(s, name_buf.value, name_buf.length);
gss_release_buffer(&minor, &name_buf);
return (TRUE);
}
/*
* Return supported mechanisms.
*/
char **
__rpc_gss_get_mechanisms(void)
{
static char *mech_list[MAX_MECH_OID_PAIRS+1];
*mech_list = NULL;
__gss_get_mechanisms(mech_list, MAX_MECH_OID_PAIRS+1);
return (mech_list);
}
/*
* For a given mechanism, return information about it.
*/
/*
* static char *krb5_qop_list[] = {Q_DEFAULT, NULL};
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Don't know how to get the service type for a given mech. */
/* "service" should NOT be there! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*!!!!!!!!!!! */
char **
__rpc_gss_get_mech_info(char *mech, rpc_gss_service_t *service)
{
char **l;
l = calloc(MAX_QOPS_PER_MECH + 1, sizeof (char *));
if (l == NULL)
return (NULL);
if (__gss_get_mech_info(mech, l) != GSS_S_COMPLETE) {
free(l);
return (NULL);
}
/* !!!!!!!!!!!!!!!! */
*service = rpc_gss_svc_privacy; /* What service type? */
/* !!!!!!!!!!!!!!!! */
return (l);
}
/*
* Returns highest and lowest versions of RPCSEC_GSS flavor supported.
*/
bool_t
__rpc_gss_get_versions(uint_t *vers_hi, uint_t *vers_lo)
{
*vers_hi = RPCSEC_GSS_VERSION;
*vers_lo = RPCSEC_GSS_VERSION;
return (TRUE);
}
/*
* Check if a mechanism is installed.
*/
bool_t
__rpc_gss_is_installed(char *mech)
{
char **l;
if (mech == NULL)
return (FALSE);
if ((l = __rpc_gss_get_mechanisms()) == NULL)
return (FALSE);
while (*l != NULL) {
if (strcmp(*l, mech) == 0)
return (TRUE);
l++;
}
return (FALSE);
}
|