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