1*428879dcSRick Macklem /*-
2*428879dcSRick Macklem * SPDX-License-Identifier: BSD-2-Clause
3*428879dcSRick Macklem *
4*428879dcSRick Macklem * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
5*428879dcSRick Macklem * Authors: Doug Rabson <dfr@rabson.org>
6*428879dcSRick Macklem * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
7*428879dcSRick Macklem *
8*428879dcSRick Macklem * Redistribution and use in source and binary forms, with or without
9*428879dcSRick Macklem * modification, are permitted provided that the following conditions
10*428879dcSRick Macklem * are met:
11*428879dcSRick Macklem * 1. Redistributions of source code must retain the above copyright
12*428879dcSRick Macklem * notice, this list of conditions and the following disclaimer.
13*428879dcSRick Macklem * 2. Redistributions in binary form must reproduce the above copyright
14*428879dcSRick Macklem * notice, this list of conditions and the following disclaimer in the
15*428879dcSRick Macklem * documentation and/or other materials provided with the distribution.
16*428879dcSRick Macklem *
17*428879dcSRick Macklem * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18*428879dcSRick Macklem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*428879dcSRick Macklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*428879dcSRick Macklem * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21*428879dcSRick Macklem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*428879dcSRick Macklem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*428879dcSRick Macklem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*428879dcSRick Macklem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*428879dcSRick Macklem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*428879dcSRick Macklem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*428879dcSRick Macklem * SUCH DAMAGE.
28*428879dcSRick Macklem */
29*428879dcSRick Macklem
30*428879dcSRick Macklem #include <sys/param.h>
31*428879dcSRick Macklem #include <sys/kernel.h>
32*428879dcSRick Macklem #include <sys/kobj.h>
33*428879dcSRick Macklem #include <sys/lock.h>
34*428879dcSRick Macklem #include <sys/malloc.h>
35*428879dcSRick Macklem #include <sys/mutex.h>
36*428879dcSRick Macklem
37*428879dcSRick Macklem #include <kgssapi/gssapi.h>
38*428879dcSRick Macklem #include <kgssapi/gssapi_impl.h>
39*428879dcSRick Macklem
40*428879dcSRick Macklem #include "gssd.h"
41*428879dcSRick Macklem
42*428879dcSRick Macklem OM_uint32
gss_ip_to_dns(OM_uint32 * minor_status,char * ip_addr,char * dns_name)43*428879dcSRick Macklem gss_ip_to_dns(OM_uint32 *minor_status,
44*428879dcSRick Macklem char *ip_addr,
45*428879dcSRick Macklem char *dns_name)
46*428879dcSRick Macklem {
47*428879dcSRick Macklem struct ip_to_dns_res res;
48*428879dcSRick Macklem struct ip_to_dns_args args;
49*428879dcSRick Macklem enum clnt_stat stat;
50*428879dcSRick Macklem CLIENT *cl;
51*428879dcSRick Macklem
52*428879dcSRick Macklem *minor_status = 0;
53*428879dcSRick Macklem cl = kgss_gssd_client();
54*428879dcSRick Macklem if (cl == NULL)
55*428879dcSRick Macklem return (GSS_S_FAILURE);
56*428879dcSRick Macklem
57*428879dcSRick Macklem args.ip_addr.ip_addr_len = strlen(ip_addr);
58*428879dcSRick Macklem args.ip_addr.ip_addr_val = mem_alloc(args.ip_addr.ip_addr_len);
59*428879dcSRick Macklem memcpy(args.ip_addr.ip_addr_val, ip_addr, args.ip_addr.ip_addr_len);
60*428879dcSRick Macklem
61*428879dcSRick Macklem bzero(&res, sizeof(res));
62*428879dcSRick Macklem stat = gssd_ip_to_dns_1(&args, &res, cl);
63*428879dcSRick Macklem CLNT_RELEASE(cl);
64*428879dcSRick Macklem if (stat != RPC_SUCCESS) {
65*428879dcSRick Macklem *minor_status = stat;
66*428879dcSRick Macklem return (GSS_S_FAILURE);
67*428879dcSRick Macklem }
68*428879dcSRick Macklem
69*428879dcSRick Macklem if (res.major_status != GSS_S_COMPLETE) {
70*428879dcSRick Macklem *minor_status = res.minor_status;
71*428879dcSRick Macklem return (res.major_status);
72*428879dcSRick Macklem }
73*428879dcSRick Macklem
74*428879dcSRick Macklem if (res.dns_name.dns_name_len == 0 ||
75*428879dcSRick Macklem res.dns_name.dns_name_len >= NI_MAXHOST) {
76*428879dcSRick Macklem *minor_status = 0;
77*428879dcSRick Macklem return (GSS_S_FAILURE);
78*428879dcSRick Macklem }
79*428879dcSRick Macklem
80*428879dcSRick Macklem memcpy(dns_name, res.dns_name.dns_name_val, res.dns_name.dns_name_len);
81*428879dcSRick Macklem dns_name[res.dns_name.dns_name_len] = '\0';
82*428879dcSRick Macklem
83*428879dcSRick Macklem return (GSS_S_COMPLETE);
84*428879dcSRick Macklem }
85