1c5c4113dSnw /*
2c5c4113dSnw  * CDDL HEADER START
3c5c4113dSnw  *
4c5c4113dSnw  * The contents of this file are subject to the terms of the
5c5c4113dSnw  * Common Development and Distribution License (the "License").
6c5c4113dSnw  * You may not use this file except in compliance with the License.
7c5c4113dSnw  *
8c5c4113dSnw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c5c4113dSnw  * or http://www.opensolaris.org/os/licensing.
10c5c4113dSnw  * See the License for the specific language governing permissions
11c5c4113dSnw  * and limitations under the License.
12c5c4113dSnw  *
13c5c4113dSnw  * When distributing Covered Code, include this CDDL HEADER in each
14c5c4113dSnw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c5c4113dSnw  * If applicable, add the following below this CDDL HEADER, with the
16c5c4113dSnw  * fields enclosed by brackets "[]" replaced with your own identifying
17c5c4113dSnw  * information: Portions Copyright [yyyy] [name of copyright owner]
18c5c4113dSnw  *
19c5c4113dSnw  * CDDL HEADER END
20c5c4113dSnw  */
21c5c4113dSnw /*
22c5866007SKeyur Desai  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23*a774f103SGordon Ross  * Copyright 2019 Nexenta Systems, Inc.  All rights reserved.
24c5c4113dSnw  */
25c5c4113dSnw 
26c5c4113dSnw 
27c5c4113dSnw /*
28c5c4113dSnw  * Config routines common to idmap(1M) and idmapd(1M)
29c5c4113dSnw  */
30c5c4113dSnw 
31c5c4113dSnw #include <stdlib.h>
32c5c4113dSnw #include <strings.h>
33c5c4113dSnw #include <libintl.h>
34c5c4113dSnw #include <ctype.h>
35c5c4113dSnw #include <errno.h>
36c5c4113dSnw #include <stdio.h>
37c5c4113dSnw #include <stdarg.h>
388edda628Sbaban #include <uuid/uuid.h>
39c8e26105Sjp #include <pthread.h>
40c8e26105Sjp #include <port.h>
41b3700b07SGordon Ross #include <sys/socket.h>
420dcc7149Snw #include <net/route.h>
434d61c878SJulian Pullen #include <sys/u8_textprep.h>
44b3700b07SGordon Ross #include <netinet/in.h>
45b3700b07SGordon Ross #include <arpa/inet.h>
46b3700b07SGordon Ross #include <netdb.h>
47148c5f43SAlan Wright #include <note.h>
48fea136a0SMatt Barden #include <limits.h>
49b3700b07SGordon Ross #include "idmapd.h"
50c8e26105Sjp #include "addisc.h"
51c5c4113dSnw 
524aa0a5e7Snw #define	MACHINE_SID_LEN		(9 + 3 * 11)
530dcc7149Snw #define	FMRI_BASE		"svc:/system/idmap"
540dcc7149Snw #define	CONFIG_PG		"config"
55148c5f43SAlan Wright #define	DEBUG_PG		"debug"
560dcc7149Snw #define	RECONFIGURE		1
570dcc7149Snw #define	POKE_AUTO_DISCOVERY	2
58b3700b07SGordon Ross #define	KICK_AUTO_DISCOVERY	3
59c5c4113dSnw 
6048cd229bSGordon Ross /*
6148cd229bSGordon Ross  * Default cache timeouts.  Can override via svccfg
6248cd229bSGordon Ross  * config/id_cache_timeout = count: seconds
6348cd229bSGordon Ross  * config/name_cache_timeout = count: seconds
6448cd229bSGordon Ross  */
653f1de28dSBayard Bell #define	ID_CACHE_TMO_DEFAULT	86400
663f1de28dSBayard Bell #define	NAME_CACHE_TMO_DEFAULT	604800
6748cd229bSGordon Ross 
68b3700b07SGordon Ross /*
69b3700b07SGordon Ross  * Default maximum time between rediscovery runs.
70b3700b07SGordon Ross  * config/rediscovery_interval = count: seconds
71b3700b07SGordon Ross  */
72b3700b07SGordon Ross #define	REDISCOVERY_INTERVAL_DEFAULT	3600
73b3700b07SGordon Ross 
74b3700b07SGordon Ross /*
75b3700b07SGordon Ross  * Mininum time between rediscovery runs, in case adutils gives us a
76b3700b07SGordon Ross  * really short TTL (which it never should, but be defensive)
77b3700b07SGordon Ross  * (not configurable) seconds.
78b3700b07SGordon Ross  */
79b3700b07SGordon Ross #define	MIN_REDISCOVERY_INTERVAL	60
80b3700b07SGordon Ross 
81fea136a0SMatt Barden /*
82fea136a0SMatt Barden  * Max number of concurrent door calls
83fea136a0SMatt Barden  */
84fea136a0SMatt Barden #define	MAX_THREADS_DEFAULT	40
85fea136a0SMatt Barden 
86c5866007SKeyur Desai enum event_type {
87c5866007SKeyur Desai 	EVENT_NOTHING,	/* Woke up for no good reason */
88c5866007SKeyur Desai 	EVENT_TIMEOUT,	/* Timeout expired */
89c5866007SKeyur Desai 	EVENT_ROUTING,	/* An interesting routing event happened */
90b3700b07SGordon Ross 	EVENT_POKED,	/* Requested from degrade_svc() */
91b3700b07SGordon Ross 	EVENT_KICKED,	/* Force rediscovery, i.e. DC failed. */
92c5866007SKeyur Desai 	EVENT_REFRESH,	/* SMF refresh */
93c5866007SKeyur Desai };
94c5866007SKeyur Desai 
95c8e26105Sjp 
96b3700b07SGordon Ross static void idmapd_set_krb5_realm(char *);
97c8e26105Sjp 
98c8e26105Sjp static pthread_t update_thread_handle = 0;
99c8e26105Sjp 
1000dcc7149Snw static int idmapd_ev_port = -1;
1010dcc7149Snw static int rt_sock = -1;
102c8e26105Sjp 
103e3f2c991SKeyur Desai struct enum_lookup_map directory_mapping_map[] = {
104e3f2c991SKeyur Desai 	{ DIRECTORY_MAPPING_NONE, "none" },
105e3f2c991SKeyur Desai 	{ DIRECTORY_MAPPING_NAME, "name" },
106e3f2c991SKeyur Desai 	{ DIRECTORY_MAPPING_IDMU, "idmu" },
107e3f2c991SKeyur Desai 	{ 0, NULL },
108e3f2c991SKeyur Desai };
109e3f2c991SKeyur Desai 
110