gss_canonicalize_name.c revision 184588
1107572Sgrehan/*-
2107572Sgrehan * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
3107572Sgrehan * Authors: Doug Rabson <dfr@rabson.org>
4107572Sgrehan * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
5107572Sgrehan *
6107572Sgrehan * Redistribution and use in source and binary forms, with or without
7107572Sgrehan * modification, are permitted provided that the following conditions
8107572Sgrehan * are met:
9107572Sgrehan * 1. Redistributions of source code must retain the above copyright
10107572Sgrehan *    notice, this list of conditions and the following disclaimer.
11107572Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
12107572Sgrehan *    notice, this list of conditions and the following disclaimer in the
13107572Sgrehan *    documentation and/or other materials provided with the distribution.
14107572Sgrehan *
15107572Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16107572Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17107572Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18107572Sgrehan * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19107572Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20107572Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21107572Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22107572Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23107572Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24107572Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25107572Sgrehan * SUCH DAMAGE.
26107572Sgrehan */
27107572Sgrehan
28107572Sgrehan#include <sys/cdefs.h>
29107572Sgrehan__FBSDID("$FreeBSD: head/sys/kgssapi/gss_canonicalize_name.c 184588 2008-11-03 10:38:00Z dfr $");
30107572Sgrehan
31107572Sgrehan#include <sys/param.h>
32107572Sgrehan#include <sys/kernel.h>
33107572Sgrehan#include <sys/kobj.h>
34107572Sgrehan#include <sys/malloc.h>
35107572Sgrehan
36115396Skan#include <kgssapi/gssapi.h>
37209885Snwhitehorn#include <kgssapi/gssapi_impl.h>
38216780Snwhitehorn
39115396Skan#include "gssd.h"
40107572Sgrehan
41216780SnwhitehornOM_uint32
42216780Snwhitehorngss_canonicalize_name(OM_uint32 *minor_status,
43216780Snwhitehorn    gss_name_t input_name,
44216780Snwhitehorn    const gss_OID mech_type,
45216780Snwhitehorn    gss_name_t *output_name)
46216780Snwhitehorn{
47107572Sgrehan	struct canonicalize_name_res res;
48107572Sgrehan	struct canonicalize_name_args args;
49107572Sgrehan	enum clnt_stat stat;
50107572Sgrehan	gss_name_t name;
51107572Sgrehan
52107572Sgrehan	if (!kgss_gssd_handle)
53107572Sgrehan		return (GSS_S_FAILURE);
54107572Sgrehan
55107572Sgrehan	args.input_name = input_name->handle;
56107572Sgrehan	args.mech_type = mech_type;
57209885Snwhitehorn
58107572Sgrehan	bzero(&res, sizeof(res));
59209885Snwhitehorn	stat = gssd_canonicalize_name_1(&args, &res, kgss_gssd_handle);
60107572Sgrehan	if (stat != RPC_SUCCESS) {
61209885Snwhitehorn		*minor_status = stat;
62209885Snwhitehorn		return (GSS_S_FAILURE);
63107572Sgrehan	}
64107572Sgrehan
65209885Snwhitehorn	if (res.major_status != GSS_S_COMPLETE) {
66209885Snwhitehorn		*minor_status = res.minor_status;
67115396Skan		return (res.major_status);
68209885Snwhitehorn	}
69209885Snwhitehorn
70107572Sgrehan	name = malloc(sizeof(struct _gss_name_t), M_GSSAPI, M_WAITOK);
71107572Sgrehan	name->handle = res.output_name;
72107572Sgrehan	*minor_status = 0;
73107572Sgrehan	*output_name = name;
74107572Sgrehan
75107572Sgrehan	return (GSS_S_COMPLETE);
76107572Sgrehan}
77107572Sgrehan