xref: /onnv-gate/usr/src/cmd/idmap/idmapd/idmapd.c (revision 6531:67fd8f862465)
14520Snw141292 /*
24520Snw141292  * CDDL HEADER START
34520Snw141292  *
44520Snw141292  * The contents of this file are subject to the terms of the
54520Snw141292  * Common Development and Distribution License (the "License").
64520Snw141292  * You may not use this file except in compliance with the License.
74520Snw141292  *
84520Snw141292  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
94520Snw141292  * or http://www.opensolaris.org/os/licensing.
104520Snw141292  * See the License for the specific language governing permissions
114520Snw141292  * and limitations under the License.
124520Snw141292  *
134520Snw141292  * When distributing Covered Code, include this CDDL HEADER in each
144520Snw141292  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
154520Snw141292  * If applicable, add the following below this CDDL HEADER, with the
164520Snw141292  * fields enclosed by brackets "[]" replaced with your own identifying
174520Snw141292  * information: Portions Copyright [yyyy] [name of copyright owner]
184520Snw141292  *
194520Snw141292  * CDDL HEADER END
204520Snw141292  */
214520Snw141292 /*
225771Sjp151216  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
234520Snw141292  * Use is subject to license terms.
244520Snw141292  */
254520Snw141292 
264520Snw141292 #pragma ident	"%Z%%M%	%I%	%E% SMI"
274520Snw141292 
284520Snw141292 /*
294520Snw141292  * main() of idmapd(1M)
304520Snw141292  */
314520Snw141292 
324520Snw141292 #include "idmapd.h"
336017Snw141292 #include <atomic.h>
344520Snw141292 #include <signal.h>
354520Snw141292 #include <rpc/pmap_clnt.h> /* for pmap_unset */
364520Snw141292 #include <string.h> /* strcmp */
374520Snw141292 #include <unistd.h> /* setsid */
384520Snw141292 #include <sys/types.h>
394520Snw141292 #include <memory.h>
404520Snw141292 #include <stropts.h>
414520Snw141292 #include <netconfig.h>
424520Snw141292 #include <sys/resource.h> /* rlimit */
434520Snw141292 #include <syslog.h>
444520Snw141292 #include <rpcsvc/daemon_utils.h> /* DAEMON_UID and DAEMON_GID */
454520Snw141292 #include <priv_utils.h> /* privileges */
464520Snw141292 #include <locale.h>
474520Snw141292 #include <sys/systeminfo.h>
484520Snw141292 #include <errno.h>
494520Snw141292 #include <sys/wait.h>
504520Snw141292 #include <sys/time.h>
514520Snw141292 #include <zone.h>
524520Snw141292 #include <door.h>
535317Sjp151216 #include <port.h>
544520Snw141292 #include <tsol/label.h>
554520Snw141292 #include <sys/resource.h>
564520Snw141292 #include <sys/sid.h>
574520Snw141292 #include <sys/idmap.h>
58*6531Sjp151216 #include <pthread.h>
594520Snw141292 
604520Snw141292 static void	term_handler(int);
614520Snw141292 static void	init_idmapd();
624520Snw141292 static void	fini_idmapd();
634520Snw141292 
644520Snw141292 #define	_RPCSVC_CLOSEDOWN 120
654520Snw141292 
664520Snw141292 int _rpcsvcstate = _IDLE;	/* Set when a request is serviced */
674520Snw141292 int _rpcsvccount = 0;		/* Number of requests being serviced */
684520Snw141292 mutex_t _svcstate_lock;		/* lock for _rpcsvcstate, _rpcsvccount */
694520Snw141292 idmapd_state_t	_idmapdstate;
704520Snw141292 
714520Snw141292 SVCXPRT *xprt = NULL;
724520Snw141292 
734520Snw141292 static int dfd = -1;		/* our door server fildes, for unregistration */
746017Snw141292 static int degraded = 0;	/* whether the FMRI has been marked degraded */
754520Snw141292 
76*6531Sjp151216 
77*6531Sjp151216 static uint32_t		num_threads = 0;
78*6531Sjp151216 static pthread_key_t	create_threads_key;
79*6531Sjp151216 static uint32_t		max_threads = 40;
80*6531Sjp151216 
81*6531Sjp151216 /*
82*6531Sjp151216  * Server door thread start routine.
83*6531Sjp151216  *
84*6531Sjp151216  * Set a TSD value to the door thread. This enables the destructor to
85*6531Sjp151216  * be called when this thread exits.
86*6531Sjp151216  */
87*6531Sjp151216 /*ARGSUSED*/
88*6531Sjp151216 static void *
89*6531Sjp151216 idmapd_door_thread_start(void *arg)
90*6531Sjp151216 {
91*6531Sjp151216 	static void *value = 0;
92*6531Sjp151216 
93*6531Sjp151216 	/*
94*6531Sjp151216 	 * Disable cancellation to avoid memory leaks from not running
95*6531Sjp151216 	 * the thread cleanup code.
96*6531Sjp151216 	 */
97*6531Sjp151216 	(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
98*6531Sjp151216 	(void) pthread_setspecific(create_threads_key, value);
99*6531Sjp151216 	(void) door_return(NULL, 0, NULL, 0);
100*6531Sjp151216 
101*6531Sjp151216 	/* make lint happy */
102*6531Sjp151216 	return (NULL);
103*6531Sjp151216 }
104*6531Sjp151216 
105*6531Sjp151216 /*
106*6531Sjp151216  * Server door threads creation
107*6531Sjp151216  */
108*6531Sjp151216 /*ARGSUSED*/
109*6531Sjp151216 static void
110*6531Sjp151216 idmapd_door_thread_create(door_info_t *dip)
111*6531Sjp151216 {
112*6531Sjp151216 	int		num;
113*6531Sjp151216 	pthread_t	thread_id;
114*6531Sjp151216 
115*6531Sjp151216 	if ((num = atomic_inc_32_nv(&num_threads)) > max_threads) {
116*6531Sjp151216 		atomic_dec_32(&num_threads);
117*6531Sjp151216 		idmapdlog(LOG_DEBUG,
118*6531Sjp151216 		    "thread creation refused - %d threads currently active",
119*6531Sjp151216 		    num - 1);
120*6531Sjp151216 		return;
121*6531Sjp151216 	}
122*6531Sjp151216 	(void) pthread_create(&thread_id, NULL, idmapd_door_thread_start, NULL);
123*6531Sjp151216 	idmapdlog(LOG_DEBUG,
124*6531Sjp151216 	    "created thread ID %d - %d threads currently active",
125*6531Sjp151216 	    thread_id, num);
126*6531Sjp151216 }
127*6531Sjp151216 
128*6531Sjp151216 /*
129*6531Sjp151216  * Server door thread cleanup
130*6531Sjp151216  */
131*6531Sjp151216 /*ARGSUSED*/
132*6531Sjp151216 static void
133*6531Sjp151216 idmapd_door_thread_cleanup(void *arg)
134*6531Sjp151216 {
135*6531Sjp151216 	int num;
136*6531Sjp151216 
137*6531Sjp151216 	num = atomic_dec_32_nv(&num_threads);
138*6531Sjp151216 	idmapdlog(LOG_DEBUG,
139*6531Sjp151216 	    "exiting thread ID %d - %d threads currently active",
140*6531Sjp151216 	    pthread_self(), num);
141*6531Sjp151216 }
142*6531Sjp151216 
1434520Snw141292 /*
1444520Snw141292  * This is needed for mech_krb5 -- we run as daemon, yes, but we want
1455034Snw141292  * mech_krb5 to think we're root so it can get host/nodename.fqdn
1465034Snw141292  * tickets for us so we can authenticate to AD as the machine account
1475034Snw141292  * that we are.  For more details look at the entry point in mech_krb5
1485034Snw141292  * corresponding to gss_init_sec_context().
1495034Snw141292  *
1505034Snw141292  * As a side effect of faking our effective UID to mech_krb5 we will use
1515034Snw141292  * root's default ccache (/tmp/krb5cc_0).  But if that's created by
1525034Snw141292  * another process then we won't have access to it: we run as daemon and
1535034Snw141292  * keep PRIV_FILE_DAC_READ, which is insufficient to share the ccache
1545034Snw141292  * with others.  We putenv("KRB5CCNAME=/var/run/idmap/ccache") in main()
1555034Snw141292  * to avoid this issue; see main().
1564520Snw141292  *
1574520Snw141292  * Someday we'll have gss/mech_krb5 extensions for acquiring initiator
1584520Snw141292  * creds with keytabs/raw keys, and someday we'll have extensions to
1594520Snw141292  * libsasl to specify creds/name to use on the initiator side, and
1604520Snw141292  * someday we'll have extensions to libldap to pass those through to
1614520Snw141292  * libsasl.  Until then this interposer will have to do.
1624520Snw141292  *
1634520Snw141292  * Also, we have to tell lint to shut up: it thinks app_krb5_user_uid()
1644520Snw141292  * is defined but not used.
1654520Snw141292  */
1664520Snw141292 /*LINTLIBRARY*/
1674520Snw141292 uid_t
1684520Snw141292 app_krb5_user_uid(void)
1694520Snw141292 {
1704520Snw141292 	return (0);
1714520Snw141292 }
1724520Snw141292 
1734520Snw141292 /*ARGSUSED*/
1744520Snw141292 static void
1755908Sjp151216 term_handler(int sig)
1765908Sjp151216 {
1776017Snw141292 	idmapdlog(LOG_INFO, "Terminating.");
1784520Snw141292 	fini_idmapd();
1794520Snw141292 	_exit(0);
1804520Snw141292 }
1814520Snw141292 
1826017Snw141292 /*ARGSUSED*/
1836017Snw141292 static void
1846017Snw141292 usr1_handler(int sig)
1856017Snw141292 {
1866017Snw141292 	bool_t saved_debug_mode = _idmapdstate.debug_mode;
1876017Snw141292 
1886017Snw141292 	_idmapdstate.debug_mode = TRUE;
1896017Snw141292 	print_idmapdstate();
1906017Snw141292 	_idmapdstate.debug_mode = saved_debug_mode;
1916017Snw141292 }
1926017Snw141292 
1934520Snw141292 static int pipe_fd = -1;
1944520Snw141292 
1954520Snw141292 static void
1965908Sjp151216 daemonize_ready(void)
1975908Sjp151216 {
1984520Snw141292 	char data = '\0';
1994520Snw141292 	/*
2004520Snw141292 	 * wake the parent
2014520Snw141292 	 */
2024520Snw141292 	(void) write(pipe_fd, &data, 1);
2034520Snw141292 	(void) close(pipe_fd);
2044520Snw141292 }
2054520Snw141292 
2064520Snw141292 static int
2075908Sjp151216 daemonize_start(void)
2085908Sjp151216 {
2094520Snw141292 	char	data;
2104520Snw141292 	int	status;
2114520Snw141292 	int	devnull;
2124520Snw141292 	int	filedes[2];
2134520Snw141292 	pid_t	pid;
2144520Snw141292 
2155034Snw141292 	(void) sigset(SIGPIPE, SIG_IGN);
2164520Snw141292 	devnull = open("/dev/null", O_RDONLY);
2174520Snw141292 	if (devnull < 0)
2184520Snw141292 		return (-1);
2194520Snw141292 	(void) dup2(devnull, 0);
2204520Snw141292 	(void) dup2(2, 1);	/* stderr only */
2214520Snw141292 	if (pipe(filedes) < 0)
2224520Snw141292 		return (-1);
2234520Snw141292 	if ((pid = fork1()) < 0)
2244520Snw141292 		return (-1);
2254520Snw141292 	if (pid != 0) {
2264520Snw141292 		/*
2274520Snw141292 		 * parent
2284520Snw141292 		 */
2294520Snw141292 		(void) close(filedes[1]);
2304520Snw141292 		if (read(filedes[0], &data, 1) == 1) {
2314520Snw141292 			/* presume success */
2324520Snw141292 			_exit(0);
2334520Snw141292 		}
2344520Snw141292 		status = -1;
2354520Snw141292 		(void) wait4(pid, &status, 0, NULL);
2364520Snw141292 		if (WIFEXITED(status))
2374520Snw141292 			_exit(WEXITSTATUS(status));
2384520Snw141292 		else
2394520Snw141292 			_exit(-1);
2404520Snw141292 	}
2414520Snw141292 
2424520Snw141292 	/*
2434520Snw141292 	 * child
2444520Snw141292 	 */
2454520Snw141292 	pipe_fd = filedes[1];
2464520Snw141292 	(void) close(filedes[0]);
2474520Snw141292 	(void) setsid();
2484520Snw141292 	(void) umask(0077);
2494520Snw141292 	openlog("idmap", LOG_PID, LOG_DAEMON);
2504520Snw141292 	return (0);
2514520Snw141292 }
2524520Snw141292 
2534520Snw141292 
2544520Snw141292 int
2554520Snw141292 main(int argc, char **argv)
2564520Snw141292 {
2574520Snw141292 	int c;
2586414Sjp151216 	struct rlimit rl;
2594520Snw141292 
2606017Snw141292 	_idmapdstate.daemon_mode = TRUE;
2616017Snw141292 	_idmapdstate.debug_mode = FALSE;
2626017Snw141292 	while ((c = getopt(argc, argv, "d")) != -1) {
2634520Snw141292 		switch (c) {
2644520Snw141292 			case 'd':
2656017Snw141292 				_idmapdstate.daemon_mode = FALSE;
2664520Snw141292 				break;
2674520Snw141292 			default:
2686017Snw141292 				fprintf(stderr, "Usage: /usr/lib/idmapd");
2696017Snw141292 				return (SMF_EXIT_ERR_CONFIG);
2704520Snw141292 				break;
2714520Snw141292 		}
2724520Snw141292 	}
2734520Snw141292 
2744520Snw141292 	/* set locale and domain for internationalization */
2754520Snw141292 	(void) setlocale(LC_ALL, "");
2764520Snw141292 	(void) textdomain(TEXT_DOMAIN);
2774520Snw141292 
2785771Sjp151216 	if (is_system_labeled() && getzoneid() != GLOBAL_ZONEID) {
2796017Snw141292 		idmapdlog(LOG_ERR,
2806017Snw141292 		    "with Trusted Extensions idmapd runs only in the "
2815771Sjp151216 		    "global zone");
2824520Snw141292 		exit(1);
2834520Snw141292 	}
2844520Snw141292 
2856414Sjp151216 	/*
2866414Sjp151216 	 * Raise the fd limit to max
2876414Sjp151216 	 */
2886414Sjp151216 	if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
2896414Sjp151216 		idmapdlog(LOG_ERR, "getrlimit failed");
2906414Sjp151216 	} else if (rl.rlim_cur < rl.rlim_max) {
2916414Sjp151216 		rl.rlim_cur = rl.rlim_max;
2926414Sjp151216 		if (setrlimit(RLIMIT_NOFILE, &rl) != 0)
2936414Sjp151216 			idmapdlog(LOG_ERR,
2946414Sjp151216 			    "Unable to raise RLIMIT_NOFILE to %d",
2956414Sjp151216 			    rl.rlim_cur);
2966414Sjp151216 	}
2976414Sjp151216 
2984520Snw141292 	(void) mutex_init(&_svcstate_lock, USYNC_THREAD, NULL);
2994520Snw141292 
3006017Snw141292 	if (_idmapdstate.daemon_mode == TRUE) {
3014520Snw141292 		if (daemonize_start() < 0) {
3026017Snw141292 			(void) idmapdlog(LOG_ERR, "unable to daemonize");
3034520Snw141292 			exit(-1);
3044520Snw141292 		}
3054520Snw141292 	} else
3064520Snw141292 		(void) umask(0077);
3074520Snw141292 
3084884Sjp151216 	idmap_init_tsd_key();
3094884Sjp151216 
3104520Snw141292 	init_idmapd();
3114520Snw141292 
3125034Snw141292 	/* signal handlers that should run only after we're initialized */
3135034Snw141292 	(void) sigset(SIGTERM, term_handler);
3146017Snw141292 	(void) sigset(SIGUSR1, usr1_handler);
3155968Snw141292 	(void) sigset(SIGHUP, idmap_cfg_hup_handler);
3165034Snw141292 
3174520Snw141292 	if (__init_daemon_priv(PU_RESETGROUPS|PU_CLEARLIMITSET,
3184520Snw141292 	    DAEMON_UID, DAEMON_GID,
3194520Snw141292 	    PRIV_PROC_AUDIT, PRIV_FILE_DAC_READ,
3204520Snw141292 	    (char *)NULL) == -1) {
3216017Snw141292 		idmapdlog(LOG_ERR, "unable to drop privileges");
3224520Snw141292 		exit(1);
3234520Snw141292 	}
3244520Snw141292 
3254520Snw141292 	__fini_daemon_priv(PRIV_PROC_FORK, PRIV_PROC_EXEC, PRIV_PROC_SESSION,
3264520Snw141292 	    PRIV_FILE_LINK_ANY, PRIV_PROC_INFO, (char *)NULL);
3274520Snw141292 
3286017Snw141292 	if (_idmapdstate.daemon_mode == TRUE)
3294520Snw141292 		daemonize_ready();
3304520Snw141292 
3314520Snw141292 	/* With doors RPC this just wastes this thread, oh well */
3324520Snw141292 	svc_run();
3334520Snw141292 	return (0);
3344520Snw141292 }
3354520Snw141292 
3364520Snw141292 static void
3375908Sjp151216 init_idmapd()
3385908Sjp151216 {
3394520Snw141292 	int	error;
340*6531Sjp151216 	int	connmaxrec = IDMAP_MAX_DOOR_RPC;
341*6531Sjp151216 
3424520Snw141292 
3435034Snw141292 	/* create directories as root and chown to daemon uid */
3445034Snw141292 	if (create_directory(IDMAP_DBDIR, DAEMON_UID, DAEMON_GID) < 0)
3455034Snw141292 		exit(1);
3465034Snw141292 	if (create_directory(IDMAP_CACHEDIR, DAEMON_UID, DAEMON_GID) < 0)
3475034Snw141292 		exit(1);
3485034Snw141292 
3495034Snw141292 	/*
3505034Snw141292 	 * Set KRB5CCNAME in the environment.  See app_krb5_user_uid()
3515447Snw141292 	 * for more details.  We blow away the existing one, if there is
3525447Snw141292 	 * one.
3535034Snw141292 	 */
3545447Snw141292 	(void) unlink(IDMAP_CACHEDIR "/ccache");
3555034Snw141292 	putenv("KRB5CCNAME=" IDMAP_CACHEDIR "/ccache");
3565034Snw141292 
3574520Snw141292 	if (sysinfo(SI_HOSTNAME, _idmapdstate.hostname,
3585908Sjp151216 	    sizeof (_idmapdstate.hostname)) == -1) {
3594520Snw141292 		error = errno;
3606017Snw141292 		idmapdlog(LOG_ERR, "unable to determine hostname, error: %d",
3615908Sjp151216 		    error);
3624520Snw141292 		exit(1);
3634520Snw141292 	}
3644520Snw141292 
3655731Sbaban 	if ((error = init_mapping_system()) < 0) {
3666017Snw141292 		idmapdlog(LOG_ERR, "unable to initialize mapping system");
3675731Sbaban 		exit(error < -2 ? SMF_EXIT_ERR_CONFIG : 1);
3684520Snw141292 	}
3694520Snw141292 
370*6531Sjp151216 	(void) door_server_create(idmapd_door_thread_create);
371*6531Sjp151216 	if ((error = pthread_key_create(&create_threads_key,
372*6531Sjp151216 	    idmapd_door_thread_cleanup)) != 0) {
373*6531Sjp151216 		idmapdlog(LOG_ERR, "unable to create threads key (%s)",
374*6531Sjp151216 		    strerror(error));
375*6531Sjp151216 		goto errout;
376*6531Sjp151216 	}
377*6531Sjp151216 
3785232Snw141292 	xprt = svc_door_create(idmap_prog_1, IDMAP_PROG, IDMAP_V1, connmaxrec);
3794520Snw141292 	if (xprt == NULL) {
3806017Snw141292 		idmapdlog(LOG_ERR, "unable to create door RPC service");
3814520Snw141292 		goto errout;
3824520Snw141292 	}
3834520Snw141292 
3845064Sdm199847 	if (!svc_control(xprt, SVCSET_CONNMAXREC, &connmaxrec)) {
3856017Snw141292 		idmapdlog(LOG_ERR, "unable to limit RPC request size");
3865064Sdm199847 		goto errout;
3875064Sdm199847 	}
3885064Sdm199847 
3894520Snw141292 	dfd = xprt->xp_fd;
3904520Snw141292 
3914520Snw141292 	if (dfd == -1) {
3926017Snw141292 		idmapdlog(LOG_ERR, "unable to register door");
3934520Snw141292 		goto errout;
3944520Snw141292 	}
3954520Snw141292 	if ((error = idmap_reg(dfd)) != 0) {
3966017Snw141292 		idmapdlog(LOG_ERR, "unable to register door (%s)",
3975908Sjp151216 		    strerror(errno));
3984520Snw141292 		goto errout;
3994520Snw141292 	}
4004520Snw141292 
4014520Snw141292 	if ((error = allocids(_idmapdstate.new_eph_db,
4025908Sjp151216 	    8192, &_idmapdstate.next_uid,
4035908Sjp151216 	    8192, &_idmapdstate.next_gid)) != 0) {
4046017Snw141292 		idmapdlog(LOG_ERR, "unable to allocate ephemeral IDs (%s)",
4056017Snw141292 		    strerror(errno));
4064520Snw141292 		_idmapdstate.next_uid = _idmapdstate.limit_uid = SENTINEL_PID;
4074520Snw141292 		_idmapdstate.next_gid = _idmapdstate.limit_gid = SENTINEL_PID;
4084520Snw141292 	} else {
4094520Snw141292 		_idmapdstate.limit_uid = _idmapdstate.next_uid + 8192;
4104520Snw141292 		_idmapdstate.limit_gid = _idmapdstate.next_gid + 8192;
4114520Snw141292 	}
4124520Snw141292 
4134520Snw141292 	print_idmapdstate();
4144520Snw141292 
4154520Snw141292 	return;
4164520Snw141292 
4174520Snw141292 errout:
4184520Snw141292 	fini_idmapd();
4194520Snw141292 	exit(1);
4204520Snw141292 }
4214520Snw141292 
4224520Snw141292 static void
4235908Sjp151216 fini_idmapd()
4245908Sjp151216 {
4254520Snw141292 	idmap_unreg(dfd);
4264520Snw141292 	fini_mapping_system();
4274520Snw141292 	if (xprt != NULL)
4284520Snw141292 		svc_destroy(xprt);
4294520Snw141292 }
4304520Snw141292 
4316017Snw141292 static
4326017Snw141292 const char *
4336017Snw141292 get_fmri(void)
4346017Snw141292 {
4356017Snw141292 	static char *fmri = NULL;
4366017Snw141292 	static char buf[60];
4376017Snw141292 	char *s;
4386017Snw141292 
4396017Snw141292 	membar_consumer();
4406017Snw141292 	s = fmri;
4416017Snw141292 	if (s != NULL && *s == '\0')
4426017Snw141292 		return (NULL);
4436017Snw141292 	else if (s != NULL)
4446017Snw141292 		return (s);
4456017Snw141292 
4466017Snw141292 	if ((s = getenv("SMF_FMRI")) == NULL || strlen(s) >= sizeof (buf))
4476017Snw141292 		buf[0] = '\0';
4486017Snw141292 	else
4496017Snw141292 		(void) strlcpy(buf, s, sizeof (buf));
4506017Snw141292 
4516017Snw141292 	membar_producer();
4526017Snw141292 	fmri = buf;
4536017Snw141292 
4546017Snw141292 	return (get_fmri());
4556017Snw141292 }
4566017Snw141292 
4576017Snw141292 /*
4586017Snw141292  * Wrappers for smf_degrade/restore_instance()
4596017Snw141292  *
4606017Snw141292  * smf_restore_instance() is too heavy duty to be calling every time we
4616017Snw141292  * have a successful AD name<->SID lookup.
4626017Snw141292  */
4636017Snw141292 void
4646097Snw141292 degrade_svc(int poke_discovery, const char *reason)
4656017Snw141292 {
4666017Snw141292 	const char *fmri;
4676017Snw141292 
4686017Snw141292 	/*
4696017Snw141292 	 * If the config update thread is in a state where auto-discovery could
4706017Snw141292 	 * be re-tried, then this will make it try it -- a sort of auto-refresh.
4716017Snw141292 	 */
4726097Snw141292 	if (poke_discovery)
4736097Snw141292 		idmap_cfg_poke_updates();
4746017Snw141292 
4756017Snw141292 	membar_consumer();
4766017Snw141292 	if (degraded)
4776017Snw141292 		return;
4786097Snw141292 
4796097Snw141292 	idmapdlog(LOG_ERR, "Degraded operation (%s).  If you are running an "
4806097Snw141292 	    "SMB server in workgroup mode, or if you're not running an SMB "
4816097Snw141292 	    "server, then you can ignore this message", reason);
4826097Snw141292 
4836017Snw141292 	membar_producer();
4846017Snw141292 	degraded = 1;
4856017Snw141292 
4866017Snw141292 	if ((fmri = get_fmri()) != NULL)
4876017Snw141292 		(void) smf_degrade_instance(fmri, 0);
4886017Snw141292 }
4896017Snw141292 
4906017Snw141292 void
4916017Snw141292 restore_svc(void)
4926017Snw141292 {
4936017Snw141292 	const char *fmri;
4946017Snw141292 
4956017Snw141292 	membar_consumer();
4966017Snw141292 	if (!degraded)
4976017Snw141292 		return;
4986017Snw141292 
4996017Snw141292 	if ((fmri = get_fmri()) == NULL)
5006017Snw141292 		(void) smf_restore_instance(fmri);
5016017Snw141292 
5026017Snw141292 	membar_producer();
5036017Snw141292 	degraded = 0;
5046097Snw141292 	idmapdlog(LOG_NOTICE, "Normal operation restored");
5056017Snw141292 }
5066017Snw141292 
5074520Snw141292 void
5085908Sjp151216 idmapdlog(int pri, const char *format, ...)
5095908Sjp151216 {
5104520Snw141292 	va_list args;
5114520Snw141292 
5124520Snw141292 	va_start(args, format);
5136017Snw141292 
5146017Snw141292 	if (_idmapdstate.debug_mode == TRUE ||
5156017Snw141292 	    _idmapdstate.daemon_mode == FALSE) {
5164520Snw141292 		(void) vfprintf(stderr, format, args);
5174520Snw141292 		(void) fprintf(stderr, "\n");
5184520Snw141292 	}
5196017Snw141292 
5206017Snw141292 	/*
5216017Snw141292 	 * We don't want to fill up the logs with useless messages when
5226017Snw141292 	 * we're degraded, but we still want to log.
5236017Snw141292 	 */
5246017Snw141292 	if (degraded)
5256017Snw141292 		pri = LOG_DEBUG;
5266017Snw141292 
5274520Snw141292 	(void) vsyslog(pri, format, args);
5284520Snw141292 	va_end(args);
5294520Snw141292 }
530