xref: /titanic_50/usr/src/lib/smbsrv/libsmb/common/smb_cfg.c (revision b60f2a0b921611326383e4789e0874e9e8a2e708)
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * CIFS configuration management library
30  */
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <synch.h>
36 #include <string.h>
37 #include <strings.h>
38 #include <syslog.h>
39 #include <netdb.h>
40 #include <ctype.h>
41 #include <sys/types.h>
42 #include <libscf.h>
43 #include <assert.h>
44 #include <smbsrv/libsmb.h>
45 
46 typedef struct smb_cfg_param {
47 	smb_cfg_id_t sc_id;
48 	char *sc_name;
49 	int sc_type;
50 	uint32_t sc_flags;
51 } smb_cfg_param_t;
52 
53 /*
54  * config parameter flags
55  */
56 #define	SMB_CF_PROTECTED	0x01
57 
58 /* idmap SMF fmri and Property Group */
59 #define	IDMAP_FMRI_PREFIX		"system/idmap"
60 #define	MACHINE_SID			"machine_sid"
61 #define	IDMAP_DOMAIN			"domain_name"
62 #define	IDMAP_PG_NAME			"config"
63 
64 #define	SMB_SECMODE_WORKGRP_STR 	"workgroup"
65 #define	SMB_SECMODE_DOMAIN_STR  	"domain"
66 
67 #define	SMB_ENC_LEN	1024
68 #define	SMB_DEC_LEN	256
69 
70 static char *b64_data =
71 	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
72 
73 static smb_cfg_param_t smb_cfg_table[] =
74 {
75 	/* Oplock configuration, Kernel Only */
76 	{SMB_CI_OPLOCK_ENABLE, "oplock_enable", SCF_TYPE_BOOLEAN, 0},
77 
78 	/* Autohome configuration */
79 	{SMB_CI_AUTOHOME_MAP, "autohome_map", SCF_TYPE_ASTRING, 0},
80 
81 	/* Domain/PDC configuration */
82 	{SMB_CI_DOMAIN_SID, "domain_sid", SCF_TYPE_ASTRING, 0},
83 	{SMB_CI_DOMAIN_MEMB, "domain_member", SCF_TYPE_BOOLEAN, 0},
84 	{SMB_CI_DOMAIN_NAME, "domain_name", SCF_TYPE_ASTRING, 0},
85 	{SMB_CI_DOMAIN_SRV, "pdc", SCF_TYPE_ASTRING, 0},
86 
87 	/* WINS configuration */
88 	{SMB_CI_WINS_SRV1, "wins_server_1", SCF_TYPE_ASTRING, 0},
89 	{SMB_CI_WINS_SRV2, "wins_server_2", SCF_TYPE_ASTRING, 0},
90 	{SMB_CI_WINS_EXCL, "wins_exclude", SCF_TYPE_ASTRING, 0},
91 
92 	/* RPC services configuration */
93 	{SMB_CI_SRVSVC_SHRSET_ENABLE, "srvsvc_sharesetinfo_enable",
94 	    SCF_TYPE_BOOLEAN, 0},
95 	{SMB_CI_MLRPC_KALIVE, "mlrpc_keep_alive_interval",
96 	    SCF_TYPE_INTEGER, 0},
97 
98 	/* Kmod specific configuration */
99 	{SMB_CI_MAX_WORKERS, "max_workers", SCF_TYPE_INTEGER, 0},
100 	{SMB_CI_MAX_CONNECTIONS, "max_connections", SCF_TYPE_INTEGER, 0},
101 	{SMB_CI_KEEPALIVE, "keep_alive", SCF_TYPE_INTEGER, 0},
102 	{SMB_CI_RESTRICT_ANON, "restrict_anonymous", SCF_TYPE_BOOLEAN, 0},
103 
104 	{SMB_CI_SIGNING_ENABLE, "signing_enabled", SCF_TYPE_BOOLEAN, 0},
105 	{SMB_CI_SIGNING_REQD, "signing_required", SCF_TYPE_BOOLEAN, 0},
106 	{SMB_CI_SIGNING_CHECK, "signing_check", SCF_TYPE_BOOLEAN, 0},
107 
108 	/* Kmod tuning configuration */
109 	{SMB_CI_SYNC_ENABLE, "sync_enable", SCF_TYPE_BOOLEAN, 0},
110 
111 	/* SMBd configuration */
112 	{SMB_CI_SECURITY, "security", SCF_TYPE_ASTRING, 0},
113 	{SMB_CI_NBSCOPE, "netbios_scope", SCF_TYPE_ASTRING, 0},
114 	{SMB_CI_SYS_CMNT, "system_comment", SCF_TYPE_ASTRING, 0},
115 	{SMB_CI_LM_LEVEL, "lmauth_level", SCF_TYPE_INTEGER, 0},
116 
117 	/* ADS Configuration */
118 	{SMB_CI_ADS_SITE, "ads_site", SCF_TYPE_ASTRING, 0},
119 
120 	/* Dynamic DNS */
121 	{SMB_CI_DYNDNS_ENABLE, "ddns_enable", SCF_TYPE_BOOLEAN, 0},
122 
123 	{SMB_CI_MACHINE_PASSWD, "machine_passwd", SCF_TYPE_ASTRING,
124 	    SMB_CF_PROTECTED},
125 	{SMB_CI_KPASSWD_SRV, "kpasswd_server", SCF_TYPE_ASTRING,
126 	    0},
127 	{SMB_CI_KPASSWD_DOMAIN, "kpasswd_domain", SCF_TYPE_ASTRING,
128 	    0},
129 	{SMB_CI_KPASSWD_SEQNUM, "kpasswd_seqnum", SCF_TYPE_INTEGER,
130 	    0},
131 	{SMB_CI_NETLOGON_SEQNUM, "netlogon_seqnum", SCF_TYPE_INTEGER,
132 	    0}
133 
134 	/* SMB_CI_MAX */
135 };
136 
137 static smb_cfg_param_t *smb_config_getent(smb_cfg_id_t);
138 
139 static boolean_t smb_is_base64(unsigned char c);
140 static char *smb_base64_encode(char *str_to_encode);
141 static char *smb_base64_decode(char *encoded_str);
142 
143 char *
144 smb_config_getname(smb_cfg_id_t id)
145 {
146 	smb_cfg_param_t *cfg;
147 	cfg = smb_config_getent(id);
148 	return (cfg->sc_name);
149 }
150 
151 static boolean_t
152 smb_is_base64(unsigned char c)
153 {
154 	return (isalnum(c) || (c == '+') || (c == '/'));
155 }
156 
157 /*
158  * smb_base64_encode
159  *
160  * Encode a string using base64 algorithm.
161  * Caller should free the returned buffer when done.
162  */
163 static char *
164 smb_base64_encode(char *str_to_encode)
165 {
166 	int ret_cnt = 0;
167 	int i = 0, j = 0;
168 	char arr_3[3], arr_4[4];
169 	int len = strlen(str_to_encode);
170 	char *ret = malloc(SMB_ENC_LEN);
171 
172 	if (ret == NULL) {
173 		return (NULL);
174 	}
175 
176 	while (len--) {
177 		arr_3[i++] = *(str_to_encode++);
178 		if (i == 3) {
179 			arr_4[0] = (arr_3[0] & 0xfc) >> 2;
180 			arr_4[1] = ((arr_3[0] & 0x03) << 4) +
181 			    ((arr_3[1] & 0xf0) >> 4);
182 			arr_4[2] = ((arr_3[1] & 0x0f) << 2) +
183 			    ((arr_3[2] & 0xc0) >> 6);
184 			arr_4[3] = arr_3[2] & 0x3f;
185 
186 			for (i = 0; i < 4; i++)
187 				ret[ret_cnt++] = b64_data[arr_4[i]];
188 			i = 0;
189 		}
190 	}
191 
192 	if (i) {
193 		for (j = i; j < 3; j++)
194 			arr_3[j] = '\0';
195 
196 		arr_4[0] = (arr_3[0] & 0xfc) >> 2;
197 		arr_4[1] = ((arr_3[0] & 0x03) << 4) +
198 		    ((arr_3[1] & 0xf0) >> 4);
199 		arr_4[2] = ((arr_3[1] & 0x0f) << 2) +
200 		    ((arr_3[2] & 0xc0) >> 6);
201 		arr_4[3] = arr_3[2] & 0x3f;
202 
203 		for (j = 0; j < (i + 1); j++)
204 			ret[ret_cnt++] = b64_data[arr_4[j]];
205 
206 		while (i++ < 3)
207 			ret[ret_cnt++] = '=';
208 	}
209 
210 	ret[ret_cnt++] = '\0';
211 	return (ret);
212 }
213 
214 /*
215  * smb_base64_decode
216  *
217  * Decode using base64 algorithm.
218  * Caller should free the returned buffer when done.
219  */
220 static char *
221 smb_base64_decode(char *encoded_str)
222 {
223 	int len = strlen(encoded_str);
224 	int i = 0, j = 0;
225 	int en_ind = 0;
226 	char arr_4[4], arr_3[3];
227 	int ret_cnt = 0;
228 	char *ret = malloc(SMB_DEC_LEN);
229 	char *p;
230 
231 	if (ret == NULL) {
232 		return (NULL);
233 	}
234 
235 	while (len-- && (encoded_str[en_ind] != '=') &&
236 	    smb_is_base64(encoded_str[en_ind])) {
237 		arr_4[i++] = encoded_str[en_ind];
238 		en_ind++;
239 		if (i == 4) {
240 			for (i = 0; i < 4; i++) {
241 				if ((p = strchr(b64_data, arr_4[i])) == NULL)
242 					return (NULL);
243 
244 				arr_4[i] = (int)(p - b64_data);
245 			}
246 
247 			arr_3[0] = (arr_4[0] << 2) +
248 			    ((arr_4[1] & 0x30) >> 4);
249 			arr_3[1] = ((arr_4[1] & 0xf) << 4) +
250 			    ((arr_4[2] & 0x3c) >> 2);
251 			arr_3[2] = ((arr_4[2] & 0x3) << 6) +
252 			    arr_4[3];
253 
254 			for (i = 0; i < 3; i++)
255 				ret[ret_cnt++] = arr_3[i];
256 
257 			i = 0;
258 		}
259 	}
260 
261 	if (i) {
262 		for (j = i; j < 4; j++)
263 			arr_4[j] = 0;
264 
265 		for (j = 0; j < 4; j++) {
266 			if ((p = strchr(b64_data, arr_4[j])) == NULL)
267 				return (NULL);
268 
269 			arr_4[j] = (int)(p - b64_data);
270 		}
271 		arr_3[0] = (arr_4[0] << 2) +
272 		    ((arr_4[1] & 0x30) >> 4);
273 		arr_3[1] = ((arr_4[1] & 0xf) << 4) +
274 		    ((arr_4[2] & 0x3c) >> 2);
275 		arr_3[2] = ((arr_4[2] & 0x3) << 6) +
276 		    arr_4[3];
277 		for (j = 0; j < (i - 1); j++)
278 			ret[ret_cnt++] = arr_3[j];
279 	}
280 
281 	ret[ret_cnt++] = '\0';
282 	return (ret);
283 }
284 
285 static char *
286 smb_config_getenv_generic(char *name, char *svc_fmri_prefix, char *svc_propgrp)
287 {
288 	smb_scfhandle_t *handle;
289 	char *value;
290 
291 	if ((value = malloc(MAX_VALUE_BUFLEN * sizeof (char))) == NULL)
292 		return (NULL);
293 
294 	handle = smb_smf_scf_init(svc_fmri_prefix);
295 	if (handle == NULL) {
296 		free(value);
297 		return (NULL);
298 	}
299 
300 	(void) smb_smf_create_service_pgroup(handle, svc_propgrp);
301 
302 	if (smb_smf_get_string_property(handle, name, value,
303 	    sizeof (char) * MAX_VALUE_BUFLEN) != 0) {
304 		smb_smf_scf_fini(handle);
305 		free(value);
306 		return (NULL);
307 	}
308 
309 	smb_smf_scf_fini(handle);
310 	return (value);
311 
312 }
313 
314 static int
315 smb_config_setenv_generic(char *svc_fmri_prefix, char *svc_propgrp,
316     char *name, char *value)
317 {
318 	smb_scfhandle_t *handle = NULL;
319 	int rc = 0;
320 
321 
322 	handle = smb_smf_scf_init(svc_fmri_prefix);
323 	if (handle == NULL) {
324 		return (1);
325 	}
326 
327 	(void) smb_smf_create_service_pgroup(handle, svc_propgrp);
328 
329 	if (smb_smf_start_transaction(handle) != SMBD_SMF_OK) {
330 		smb_smf_scf_fini(handle);
331 		return (1);
332 	}
333 
334 	if (smb_smf_set_string_property(handle, name, value) != SMBD_SMF_OK)
335 		rc = 1;
336 
337 	if (smb_smf_end_transaction(handle) != SMBD_SMF_OK)
338 		rc = 1;
339 
340 	smb_smf_scf_fini(handle);
341 	return (rc);
342 }
343 
344 /*
345  * smb_config_getstr
346  *
347  * Fetch the specified string configuration item from SMF
348  */
349 int
350 smb_config_getstr(smb_cfg_id_t id, char *cbuf, int bufsz)
351 {
352 	smb_scfhandle_t *handle;
353 	smb_cfg_param_t *cfg;
354 	int rc = SMBD_SMF_OK;
355 
356 	*cbuf = '\0';
357 	cfg = smb_config_getent(id);
358 	assert(cfg->sc_type == SCF_TYPE_ASTRING);
359 
360 	handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
361 	if (handle == NULL)
362 		return (SMBD_SMF_SYSTEM_ERR);
363 
364 	if (cfg->sc_flags & SMB_CF_PROTECTED) {
365 		char protbuf[SMB_ENC_LEN];
366 		char *tmp;
367 
368 		if ((rc = smb_smf_create_service_pgroup(handle,
369 		    SMBD_PROTECTED_PG_NAME)) != SMBD_SMF_OK)
370 			goto error;
371 
372 		if ((rc = smb_smf_get_string_property(handle, cfg->sc_name,
373 		    protbuf, sizeof (protbuf))) != SMBD_SMF_OK)
374 			goto error;
375 
376 		if (*protbuf != '\0') {
377 			tmp = smb_base64_decode(protbuf);
378 			(void) strlcpy(cbuf, tmp, bufsz);
379 			free(tmp);
380 		}
381 	} else {
382 		rc = smb_smf_create_service_pgroup(handle, SMBD_PG_NAME);
383 		if (rc == SMBD_SMF_OK)
384 			rc = smb_smf_get_string_property(handle, cfg->sc_name,
385 			    cbuf, bufsz);
386 	}
387 
388 error:
389 	smb_smf_scf_fini(handle);
390 	return (rc);
391 }
392 
393 /*
394  * smb_config_getnum
395  *
396  * Returns the value of a numeric config param.
397  */
398 int
399 smb_config_getnum(smb_cfg_id_t id, int64_t *cint)
400 {
401 	smb_scfhandle_t *handle;
402 	smb_cfg_param_t *cfg;
403 	int rc = SMBD_SMF_OK;
404 
405 	*cint = 0;
406 	cfg = smb_config_getent(id);
407 	assert(cfg->sc_type == SCF_TYPE_INTEGER);
408 
409 	handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
410 	if (handle == NULL)
411 		return (SMBD_SMF_SYSTEM_ERR);
412 
413 	rc = smb_smf_create_service_pgroup(handle, SMBD_PG_NAME);
414 	if (rc == SMBD_SMF_OK)
415 		rc = smb_smf_get_integer_property(handle, cfg->sc_name, cint);
416 	smb_smf_scf_fini(handle);
417 
418 	return (rc);
419 }
420 
421 /*
422  * smb_config_getbool
423  *
424  * Returns the value of a boolean config param.
425  */
426 boolean_t
427 smb_config_getbool(smb_cfg_id_t id)
428 {
429 	smb_scfhandle_t *handle;
430 	smb_cfg_param_t *cfg;
431 	int rc = SMBD_SMF_OK;
432 	uint8_t vbool;
433 
434 	cfg = smb_config_getent(id);
435 	assert(cfg->sc_type == SCF_TYPE_BOOLEAN);
436 
437 	handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
438 	if (handle == NULL)
439 		return (B_FALSE);
440 
441 	rc = smb_smf_create_service_pgroup(handle, SMBD_PG_NAME);
442 	if (rc == SMBD_SMF_OK)
443 		rc = smb_smf_get_boolean_property(handle, cfg->sc_name, &vbool);
444 	smb_smf_scf_fini(handle);
445 
446 	return ((rc == SMBD_SMF_OK) ? (vbool == 1) : B_FALSE);
447 }
448 
449 /*
450  * smb_config_get
451  *
452  * This function returns the value of the requested config
453  * iterm regardless of its type in string format. This should
454  * be used when the config item type is not known by the caller.
455  */
456 int
457 smb_config_get(smb_cfg_id_t id, char *cbuf, int bufsz)
458 {
459 	smb_cfg_param_t *cfg;
460 	int64_t cint;
461 	int rc;
462 
463 	cfg = smb_config_getent(id);
464 	switch (cfg->sc_type) {
465 	case SCF_TYPE_ASTRING:
466 		return (smb_config_getstr(id, cbuf, bufsz));
467 
468 	case SCF_TYPE_INTEGER:
469 		rc = smb_config_getnum(id, &cint);
470 		if (rc == SMBD_SMF_OK)
471 			(void) snprintf(cbuf, bufsz, "%lld", cint);
472 		return (rc);
473 
474 	case SCF_TYPE_BOOLEAN:
475 		if (smb_config_getbool(id))
476 			(void) strlcpy(cbuf, "true", bufsz);
477 		else
478 			(void) strlcpy(cbuf, "false", bufsz);
479 		return (SMBD_SMF_OK);
480 	}
481 
482 	return (SMBD_SMF_INVALID_ARG);
483 }
484 
485 /*
486  * smb_config_setstr
487  *
488  * Set the specified config param with the given
489  * value.
490  */
491 int
492 smb_config_setstr(smb_cfg_id_t id, char *value)
493 {
494 	smb_scfhandle_t *handle;
495 	smb_cfg_param_t *cfg;
496 	int rc = SMBD_SMF_OK;
497 	boolean_t protected;
498 	char *tmp = NULL;
499 	char *pg;
500 
501 	cfg = smb_config_getent(id);
502 	assert(cfg->sc_type == SCF_TYPE_ASTRING);
503 
504 	if (cfg->sc_flags & SMB_CF_PROTECTED) {
505 		pg = SMBD_PROTECTED_PG_NAME;
506 		protected = B_TRUE;
507 	} else {
508 		pg = SMBD_PG_NAME;
509 		protected = B_FALSE;
510 	}
511 
512 	handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
513 	if (handle == NULL)
514 		return (SMBD_SMF_SYSTEM_ERR);
515 
516 	rc = smb_smf_create_service_pgroup(handle, pg);
517 	if (rc == SMBD_SMF_OK)
518 		rc = smb_smf_start_transaction(handle);
519 
520 	if (rc != SMBD_SMF_OK) {
521 		smb_smf_scf_fini(handle);
522 		return (rc);
523 	}
524 
525 	if (protected && value && (*value != '\0')) {
526 		if ((tmp = smb_base64_encode(value)) == NULL) {
527 			(void) smb_smf_end_transaction(handle);
528 			smb_smf_scf_fini(handle);
529 			return (SMBD_SMF_NO_MEMORY);
530 		}
531 
532 		value = tmp;
533 	}
534 
535 	rc = smb_smf_set_string_property(handle, cfg->sc_name, value);
536 
537 	free(tmp);
538 	(void) smb_smf_end_transaction(handle);
539 	smb_smf_scf_fini(handle);
540 	return (rc);
541 }
542 
543 /*
544  * smb_config_setnum
545  *
546  * Sets a numeric configuration iterm
547  */
548 int
549 smb_config_setnum(smb_cfg_id_t id, int64_t value)
550 {
551 	smb_scfhandle_t *handle;
552 	smb_cfg_param_t *cfg;
553 	int rc = SMBD_SMF_OK;
554 
555 	cfg = smb_config_getent(id);
556 	assert(cfg->sc_type == SCF_TYPE_INTEGER);
557 
558 	handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
559 	if (handle == NULL)
560 		return (SMBD_SMF_SYSTEM_ERR);
561 
562 	rc = smb_smf_create_service_pgroup(handle, SMBD_PG_NAME);
563 	if (rc == SMBD_SMF_OK)
564 		rc = smb_smf_start_transaction(handle);
565 
566 	if (rc != SMBD_SMF_OK) {
567 		smb_smf_scf_fini(handle);
568 		return (rc);
569 	}
570 
571 	rc = smb_smf_set_integer_property(handle, cfg->sc_name, value);
572 
573 	(void) smb_smf_end_transaction(handle);
574 	smb_smf_scf_fini(handle);
575 	return (rc);
576 }
577 
578 /*
579  * smb_config_setbool
580  *
581  * Sets a boolean configuration iterm
582  */
583 int
584 smb_config_setbool(smb_cfg_id_t id, boolean_t value)
585 {
586 	smb_scfhandle_t *handle;
587 	smb_cfg_param_t *cfg;
588 	int rc = SMBD_SMF_OK;
589 
590 	cfg = smb_config_getent(id);
591 	assert(cfg->sc_type == SCF_TYPE_BOOLEAN);
592 
593 	handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
594 	if (handle == NULL)
595 		return (SMBD_SMF_SYSTEM_ERR);
596 
597 	rc = smb_smf_create_service_pgroup(handle, SMBD_PG_NAME);
598 	if (rc == SMBD_SMF_OK)
599 		rc = smb_smf_start_transaction(handle);
600 
601 	if (rc != SMBD_SMF_OK) {
602 		smb_smf_scf_fini(handle);
603 		return (rc);
604 	}
605 
606 	rc = smb_smf_set_boolean_property(handle, cfg->sc_name, value);
607 
608 	(void) smb_smf_end_transaction(handle);
609 	smb_smf_scf_fini(handle);
610 	return (rc);
611 }
612 
613 /*
614  * smb_config_set
615  *
616  * This function sets the value of the specified config
617  * iterm regardless of its type in string format. This should
618  * be used when the config item type is not known by the caller.
619  */
620 int
621 smb_config_set(smb_cfg_id_t id, char *value)
622 {
623 	smb_cfg_param_t *cfg;
624 	int64_t cint;
625 
626 	cfg = smb_config_getent(id);
627 	switch (cfg->sc_type) {
628 	case SCF_TYPE_ASTRING:
629 		return (smb_config_setstr(id, value));
630 
631 	case SCF_TYPE_INTEGER:
632 		cint = atoi(value);
633 		return (smb_config_setnum(id, cint));
634 
635 	case SCF_TYPE_BOOLEAN:
636 		return (smb_config_setbool(id, strcasecmp(value, "true") == 0));
637 	}
638 
639 	return (SMBD_SMF_INVALID_ARG);
640 }
641 uint8_t
642 smb_config_get_fg_flag()
643 {
644 	uint8_t run_fg = 0; /* Default is to run in daemon mode */
645 	smb_scfhandle_t *handle = NULL;
646 
647 	handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
648 	if (handle == NULL) {
649 		return (run_fg);
650 	}
651 
652 	if (smb_smf_create_service_pgroup(handle,
653 	    SMBD_PG_NAME) != SMBD_SMF_OK) {
654 		smb_smf_scf_fini(handle);
655 		return (run_fg);
656 	}
657 
658 	if (smb_smf_get_boolean_property(handle, "run_fg", &run_fg) != 0) {
659 		smb_smf_scf_fini(handle);
660 		return (run_fg);
661 	}
662 
663 	smb_smf_scf_fini(handle);
664 
665 	return (run_fg);
666 }
667 
668 /*
669  * smb_config_get_localsid
670  *
671  * Returns value of the "config/machine_sid" parameter
672  * from the IDMAP SMF configuration repository.
673  *
674  */
675 char *
676 smb_config_get_localsid(void)
677 {
678 	return (smb_config_getenv_generic(MACHINE_SID, IDMAP_FMRI_PREFIX,
679 	    IDMAP_PG_NAME));
680 }
681 
682 /*
683  * smb_config_set_idmap_domain
684  *
685  * Set the "config/domain_name" parameter from IDMAP SMF repository.
686  */
687 int
688 smb_config_set_idmap_domain(char *value)
689 {
690 	return (smb_config_setenv_generic(IDMAP_FMRI_PREFIX, IDMAP_PG_NAME,
691 	    IDMAP_DOMAIN, value));
692 }
693 
694 /*
695  * smb_config_refresh_idmap
696  *
697  * Refresh IDMAP SMF service after making changes to its configuration.
698  */
699 int
700 smb_config_refresh_idmap(void)
701 {
702 	char instance[32];
703 
704 	(void) snprintf(instance, sizeof (instance), "%s:default",
705 	    IDMAP_FMRI_PREFIX);
706 	return (smf_refresh_instance(instance));
707 }
708 
709 int
710 smb_config_secmode_fromstr(char *secmode)
711 {
712 	if (secmode == NULL)
713 		return (SMB_SECMODE_WORKGRP);
714 
715 	if (strcasecmp(secmode, SMB_SECMODE_DOMAIN_STR) == 0)
716 		return (SMB_SECMODE_DOMAIN);
717 
718 	return (SMB_SECMODE_WORKGRP);
719 }
720 
721 char *
722 smb_config_secmode_tostr(int secmode)
723 {
724 	if (secmode == SMB_SECMODE_DOMAIN)
725 		return (SMB_SECMODE_DOMAIN_STR);
726 
727 	return (SMB_SECMODE_WORKGRP_STR);
728 }
729 
730 int
731 smb_config_get_secmode()
732 {
733 	char p[16];
734 
735 	(void) smb_config_getstr(SMB_CI_SECURITY, p, sizeof (p));
736 	return (smb_config_secmode_fromstr(p));
737 }
738 
739 int
740 smb_config_set_secmode(int secmode)
741 {
742 	char *p;
743 
744 	p = smb_config_secmode_tostr(secmode);
745 	return (smb_config_setstr(SMB_CI_SECURITY, p));
746 }
747 
748 static smb_cfg_param_t *
749 smb_config_getent(smb_cfg_id_t id)
750 {
751 	int i;
752 
753 	for (i = 0; i < SMB_CI_MAX; i++)
754 		if (smb_cfg_table[i].sc_id == id)
755 			return (&smb_cfg_table[id]);
756 
757 	assert(0);
758 	return (NULL);
759 }
760