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