xref: /illumos-gate/usr/src/lib/libnsl/nis/gen/nis_misc.c (revision e5803b76927480e8f9b67b22201c484ccf4c2bcf)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * nis_misc.c
24  */
25 
26 /*
27  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 
32 /*
33  * nis_misc.c
34  *
35  * This module contains miscellaneous library functions.
36  */
37 
38 #include "mt.h"
39 #include <string.h>
40 #include <syslog.h>
41 #include <malloc.h>
42 #include <rpc/rpc.h>
43 #include <rpcsvc/nis.h>
44 #include <tiuser.h>
45 #include <netdir.h>
46 #include <netinet/in.h>
47 #include <strings.h>
48 #include "nis_clnt.h"
49 
50 /*
51  * In the pre-IPv6 code, secure RPC has a bug such that it doesn't look
52  * at the endpoint 'family' field when selecting an endpoint to use for
53  * time synchronization. In order to protect that broken code from itself,
54  * we set the endpoint 'proto' to 'nc_netid' (i.e., "udp6" or "tcp6")
55  * rather than 'nc_proto' ("udp"/"tcp") if 'nc_family' is "inet6".
56  *
57  * The __nis_netconfig2ep() and __nis_netconfig_matches_ep() service
58  * functions below simplify endpoint manipulation by implementing the
59  * rules above.
60  */
61 
62 void
63 __nis_netconfig2ep(struct netconfig *nc, endpoint *ep) {
64 
65 	if (nc == 0 || ep == 0)
66 		return;
67 
68 	ep->family = strdup(nc->nc_protofmly);
69 
70 	if (strcmp(ep->family, "inet6") == 0) {
71 		ep->proto = strdup(nc->nc_netid);
72 	} else {
73 		ep->proto = strdup(nc->nc_proto);
74 	}
75 }
76 
77 bool_t
78 __nis_netconfig_matches_ep(struct netconfig *nc, endpoint *ep) {
79 
80 	if (nc == 0 || ep == 0)
81 		return (FALSE);
82 
83 	if (strcmp(nc->nc_protofmly, ep->family) != 0)
84 		return (FALSE);
85 
86 	if (strcmp(ep->family, "inet6") == 0)
87 		return (strcmp(nc->nc_netid, ep->proto) == 0 ||
88 			strcmp(nc->nc_proto, ep->proto) == 0);
89 	else
90 		return (strcmp(nc->nc_proto, ep->proto) == 0);
91 
92 }
93