6919822 assert failed in ndr_outer_fixed during stress test
[unleashed.git] / usr / src / lib / smbsrv / libsmb / common / smb_cfg.c
blob5d44546df0d85b9e4d391c05a4f7b3be4f25fabc
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * CIFS configuration management library
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <synch.h>
34 #include <string.h>
35 #include <strings.h>
36 #include <syslog.h>
37 #include <netdb.h>
38 #include <ctype.h>
39 #include <sys/types.h>
40 #include <libscf.h>
41 #include <assert.h>
42 #include <uuid/uuid.h>
43 #include <smbsrv/libsmb.h>
45 typedef struct smb_cfg_param {
46 smb_cfg_id_t sc_id;
47 char *sc_name;
48 int sc_type;
49 uint32_t sc_flags;
50 } smb_cfg_param_t;
53 * config parameter flags
55 #define SMB_CF_PROTECTED 0x01
56 #define SMB_CF_EXEC 0x02
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"
64 #define SMB_SECMODE_WORKGRP_STR "workgroup"
65 #define SMB_SECMODE_DOMAIN_STR "domain"
67 #define SMB_ENC_LEN 1024
68 #define SMB_DEC_LEN 256
70 static char *b64_data =
71 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
73 static smb_cfg_param_t smb_cfg_table[] =
75 /* Oplock configuration, Kernel Only */
76 {SMB_CI_OPLOCK_ENABLE, "oplock_enable", SCF_TYPE_BOOLEAN, 0},
78 /* Autohome configuration */
79 {SMB_CI_AUTOHOME_MAP, "autohome_map", SCF_TYPE_ASTRING, 0},
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_FQDN, "fqdn", SCF_TYPE_ASTRING, 0},
86 {SMB_CI_DOMAIN_FOREST, "forest", SCF_TYPE_ASTRING, 0},
87 {SMB_CI_DOMAIN_GUID, "domain_guid", SCF_TYPE_ASTRING, 0},
88 {SMB_CI_DOMAIN_SRV, "pdc", SCF_TYPE_ASTRING, 0},
90 /* WINS configuration */
91 {SMB_CI_WINS_SRV1, "wins_server_1", SCF_TYPE_ASTRING, 0},
92 {SMB_CI_WINS_SRV2, "wins_server_2", SCF_TYPE_ASTRING, 0},
93 {SMB_CI_WINS_EXCL, "wins_exclude", SCF_TYPE_ASTRING, 0},
95 /* Kmod specific configuration */
96 {SMB_CI_MAX_WORKERS, "max_workers", SCF_TYPE_INTEGER, 0},
97 {SMB_CI_MAX_CONNECTIONS, "max_connections", SCF_TYPE_INTEGER, 0},
98 {SMB_CI_KEEPALIVE, "keep_alive", SCF_TYPE_INTEGER, 0},
99 {SMB_CI_RESTRICT_ANON, "restrict_anonymous", SCF_TYPE_BOOLEAN, 0},
101 {SMB_CI_SIGNING_ENABLE, "signing_enabled", SCF_TYPE_BOOLEAN, 0},
102 {SMB_CI_SIGNING_REQD, "signing_required", SCF_TYPE_BOOLEAN, 0},
104 /* Kmod tuning configuration */
105 {SMB_CI_SYNC_ENABLE, "sync_enable", SCF_TYPE_BOOLEAN, 0},
107 /* SMBd configuration */
108 {SMB_CI_SECURITY, "security", SCF_TYPE_ASTRING, 0},
109 {SMB_CI_NBSCOPE, "netbios_scope", SCF_TYPE_ASTRING, 0},
110 {SMB_CI_SYS_CMNT, "system_comment", SCF_TYPE_ASTRING, 0},
111 {SMB_CI_LM_LEVEL, "lmauth_level", SCF_TYPE_INTEGER, 0},
113 /* ADS Configuration */
114 {SMB_CI_ADS_SITE, "ads_site", SCF_TYPE_ASTRING, 0},
116 /* Dynamic DNS */
117 {SMB_CI_DYNDNS_ENABLE, "ddns_enable", SCF_TYPE_BOOLEAN, 0},
119 {SMB_CI_MACHINE_PASSWD, "machine_passwd", SCF_TYPE_ASTRING,
120 SMB_CF_PROTECTED},
121 {SMB_CI_KPASSWD_SRV, "kpasswd_server", SCF_TYPE_ASTRING,
123 {SMB_CI_KPASSWD_DOMAIN, "kpasswd_domain", SCF_TYPE_ASTRING,
125 {SMB_CI_KPASSWD_SEQNUM, "kpasswd_seqnum", SCF_TYPE_INTEGER,
127 {SMB_CI_NETLOGON_SEQNUM, "netlogon_seqnum", SCF_TYPE_INTEGER,
129 {SMB_CI_IPV6_ENABLE, "ipv6_enable", SCF_TYPE_BOOLEAN, 0},
130 {SMB_CI_MAP, "map", SCF_TYPE_ASTRING, SMB_CF_EXEC},
131 {SMB_CI_UNMAP, "unmap", SCF_TYPE_ASTRING, SMB_CF_EXEC},
132 {SMB_CI_DISPOSITION, "disposition", SCF_TYPE_ASTRING, SMB_CF_EXEC}
134 /* SMB_CI_MAX */
137 static smb_cfg_param_t *smb_config_getent(smb_cfg_id_t);
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);
143 char *
144 smb_config_getname(smb_cfg_id_t id)
146 smb_cfg_param_t *cfg;
147 cfg = smb_config_getent(id);
148 return (cfg->sc_name);
151 static boolean_t
152 smb_is_base64(unsigned char c)
154 return (isalnum(c) || (c == '+') || (c == '/'));
158 * smb_base64_encode
160 * Encode a string using base64 algorithm.
161 * Caller should free the returned buffer when done.
163 static char *
164 smb_base64_encode(char *str_to_encode)
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);
172 if (ret == NULL) {
173 return (NULL);
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;
186 for (i = 0; i < 4; i++)
187 ret[ret_cnt++] = b64_data[arr_4[i]];
188 i = 0;
192 if (i) {
193 for (j = i; j < 3; j++)
194 arr_3[j] = '\0';
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;
203 for (j = 0; j < (i + 1); j++)
204 ret[ret_cnt++] = b64_data[arr_4[j]];
206 while (i++ < 3)
207 ret[ret_cnt++] = '=';
210 ret[ret_cnt++] = '\0';
211 return (ret);
215 * smb_base64_decode
217 * Decode using base64 algorithm.
218 * Caller should free the returned buffer when done.
220 static char *
221 smb_base64_decode(char *encoded_str)
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;
231 if (ret == NULL) {
232 return (NULL);
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);
244 arr_4[i] = (int)(p - b64_data);
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];
254 for (i = 0; i < 3; i++)
255 ret[ret_cnt++] = arr_3[i];
257 i = 0;
261 if (i) {
262 for (j = i; j < 4; j++)
263 arr_4[j] = 0;
265 for (j = 0; j < 4; j++) {
266 if ((p = strchr(b64_data, arr_4[j])) == NULL)
267 return (NULL);
269 arr_4[j] = (int)(p - b64_data);
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];
281 ret[ret_cnt++] = '\0';
282 return (ret);
285 static char *
286 smb_config_getenv_generic(char *name, char *svc_fmri_prefix, char *svc_propgrp)
288 smb_scfhandle_t *handle;
289 char *value;
291 if ((value = malloc(MAX_VALUE_BUFLEN * sizeof (char))) == NULL)
292 return (NULL);
294 handle = smb_smf_scf_init(svc_fmri_prefix);
295 if (handle == NULL) {
296 free(value);
297 return (NULL);
300 (void) smb_smf_create_service_pgroup(handle, svc_propgrp);
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);
309 smb_smf_scf_fini(handle);
310 return (value);
314 static int
315 smb_config_setenv_generic(char *svc_fmri_prefix, char *svc_propgrp,
316 char *name, char *value)
318 smb_scfhandle_t *handle = NULL;
319 int rc = 0;
322 handle = smb_smf_scf_init(svc_fmri_prefix);
323 if (handle == NULL) {
324 return (1);
327 (void) smb_smf_create_service_pgroup(handle, svc_propgrp);
329 if (smb_smf_start_transaction(handle) != SMBD_SMF_OK) {
330 smb_smf_scf_fini(handle);
331 return (1);
334 if (smb_smf_set_string_property(handle, name, value) != SMBD_SMF_OK)
335 rc = 1;
337 if (smb_smf_end_transaction(handle) != SMBD_SMF_OK)
338 rc = 1;
340 smb_smf_scf_fini(handle);
341 return (rc);
345 * smb_config_getstr
347 * Fetch the specified string configuration item from SMF
350 smb_config_getstr(smb_cfg_id_t id, char *cbuf, int bufsz)
352 smb_scfhandle_t *handle;
353 smb_cfg_param_t *cfg;
354 int rc = SMBD_SMF_OK;
355 char *pg;
356 char protbuf[SMB_ENC_LEN];
357 char *tmp;
359 *cbuf = '\0';
360 cfg = smb_config_getent(id);
361 assert(cfg->sc_type == SCF_TYPE_ASTRING);
363 handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
364 if (handle == NULL)
365 return (SMBD_SMF_SYSTEM_ERR);
367 if (cfg->sc_flags & SMB_CF_PROTECTED) {
368 if ((rc = smb_smf_create_service_pgroup(handle,
369 SMBD_PROTECTED_PG_NAME)) != SMBD_SMF_OK)
370 goto error;
372 if ((rc = smb_smf_get_string_property(handle, cfg->sc_name,
373 protbuf, sizeof (protbuf))) != SMBD_SMF_OK)
374 goto error;
376 if (*protbuf != '\0') {
377 tmp = smb_base64_decode(protbuf);
378 (void) strlcpy(cbuf, tmp, bufsz);
379 free(tmp);
381 } else {
382 pg = (cfg->sc_flags & SMB_CF_EXEC) ? SMBD_EXEC_PG_NAME :
383 SMBD_PG_NAME;
384 rc = smb_smf_create_service_pgroup(handle, pg);
385 if (rc == SMBD_SMF_OK)
386 rc = smb_smf_get_string_property(handle, cfg->sc_name,
387 cbuf, bufsz);
390 error:
391 smb_smf_scf_fini(handle);
392 return (rc);
396 * Translate the value of an astring SMF property into a binary
397 * IP address. If the value is neither a valid IPv4 nor IPv6
398 * address, attempt to look it up as a hostname using the
399 * configured address type.
402 smb_config_getip(smb_cfg_id_t sc_id, smb_inaddr_t *ipaddr)
404 int rc, error;
405 int a_family;
406 char ipstr[MAXHOSTNAMELEN];
407 struct hostent *h;
408 smb_cfg_param_t *cfg;
410 if (ipaddr == NULL)
411 return (SMBD_SMF_INVALID_ARG);
413 bzero(ipaddr, sizeof (smb_inaddr_t));
414 rc = smb_config_getstr(sc_id, ipstr, sizeof (ipstr));
415 if (rc == SMBD_SMF_OK) {
416 if (*ipstr == '\0')
417 return (SMBD_SMF_INVALID_ARG);
419 if (inet_pton(AF_INET, ipstr, &ipaddr->a_ipv4) == 1) {
420 ipaddr->a_family = AF_INET;
421 return (SMBD_SMF_OK);
424 if (inet_pton(AF_INET6, ipstr, &ipaddr->a_ipv6) == 1) {
425 ipaddr->a_family = AF_INET6;
426 return (SMBD_SMF_OK);
430 * The value is neither an IPv4 nor IPv6 address;
431 * so check if it's a hostname.
433 a_family = smb_config_getbool(SMB_CI_IPV6_ENABLE) ?
434 AF_INET6 : AF_INET;
435 h = getipnodebyname(ipstr, a_family, AI_DEFAULT,
436 &error);
437 if (h != NULL) {
438 bcopy(*(h->h_addr_list), &ipaddr->a_ip,
439 h->h_length);
440 ipaddr->a_family = a_family;
441 freehostent(h);
442 rc = SMBD_SMF_OK;
443 } else {
444 cfg = smb_config_getent(sc_id);
445 syslog(LOG_ERR, "smbd/%s: %s unable to get %s "
446 "address: %d", cfg->sc_name, ipstr,
447 a_family == AF_INET ? "IPv4" : "IPv6", error);
448 rc = SMBD_SMF_INVALID_ARG;
452 return (rc);
456 * smb_config_getnum
458 * Returns the value of a numeric config param.
461 smb_config_getnum(smb_cfg_id_t id, int64_t *cint)
463 smb_scfhandle_t *handle;
464 smb_cfg_param_t *cfg;
465 int rc = SMBD_SMF_OK;
467 *cint = 0;
468 cfg = smb_config_getent(id);
469 assert(cfg->sc_type == SCF_TYPE_INTEGER);
471 handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
472 if (handle == NULL)
473 return (SMBD_SMF_SYSTEM_ERR);
475 rc = smb_smf_create_service_pgroup(handle, SMBD_PG_NAME);
476 if (rc == SMBD_SMF_OK)
477 rc = smb_smf_get_integer_property(handle, cfg->sc_name, cint);
478 smb_smf_scf_fini(handle);
480 return (rc);
484 * smb_config_getbool
486 * Returns the value of a boolean config param.
488 boolean_t
489 smb_config_getbool(smb_cfg_id_t id)
491 smb_scfhandle_t *handle;
492 smb_cfg_param_t *cfg;
493 int rc = SMBD_SMF_OK;
494 uint8_t vbool;
496 cfg = smb_config_getent(id);
497 assert(cfg->sc_type == SCF_TYPE_BOOLEAN);
499 handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
500 if (handle == NULL)
501 return (B_FALSE);
503 rc = smb_smf_create_service_pgroup(handle, SMBD_PG_NAME);
504 if (rc == SMBD_SMF_OK)
505 rc = smb_smf_get_boolean_property(handle, cfg->sc_name, &vbool);
506 smb_smf_scf_fini(handle);
508 return ((rc == SMBD_SMF_OK) ? (vbool == 1) : B_FALSE);
512 * smb_config_get
514 * This function returns the value of the requested config
515 * iterm regardless of its type in string format. This should
516 * be used when the config item type is not known by the caller.
519 smb_config_get(smb_cfg_id_t id, char *cbuf, int bufsz)
521 smb_cfg_param_t *cfg;
522 int64_t cint;
523 int rc;
525 cfg = smb_config_getent(id);
526 switch (cfg->sc_type) {
527 case SCF_TYPE_ASTRING:
528 return (smb_config_getstr(id, cbuf, bufsz));
530 case SCF_TYPE_INTEGER:
531 rc = smb_config_getnum(id, &cint);
532 if (rc == SMBD_SMF_OK)
533 (void) snprintf(cbuf, bufsz, "%lld", cint);
534 return (rc);
536 case SCF_TYPE_BOOLEAN:
537 if (smb_config_getbool(id))
538 (void) strlcpy(cbuf, "true", bufsz);
539 else
540 (void) strlcpy(cbuf, "false", bufsz);
541 return (SMBD_SMF_OK);
544 return (SMBD_SMF_INVALID_ARG);
548 * smb_config_setstr
550 * Set the specified config param with the given
551 * value.
554 smb_config_setstr(smb_cfg_id_t id, char *value)
556 smb_scfhandle_t *handle;
557 smb_cfg_param_t *cfg;
558 int rc = SMBD_SMF_OK;
559 boolean_t protected;
560 char *tmp = NULL;
561 char *pg;
563 cfg = smb_config_getent(id);
564 assert(cfg->sc_type == SCF_TYPE_ASTRING);
566 protected = B_FALSE;
568 switch (cfg->sc_flags) {
569 case SMB_CF_PROTECTED:
570 protected = B_TRUE;
571 pg = SMBD_PROTECTED_PG_NAME;
572 break;
573 case SMB_CF_EXEC:
574 pg = SMBD_EXEC_PG_NAME;
575 break;
576 default:
577 pg = SMBD_PG_NAME;
578 break;
581 handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
582 if (handle == NULL)
583 return (SMBD_SMF_SYSTEM_ERR);
585 rc = smb_smf_create_service_pgroup(handle, pg);
586 if (rc == SMBD_SMF_OK)
587 rc = smb_smf_start_transaction(handle);
589 if (rc != SMBD_SMF_OK) {
590 smb_smf_scf_fini(handle);
591 return (rc);
594 if (protected && value && (*value != '\0')) {
595 if ((tmp = smb_base64_encode(value)) == NULL) {
596 (void) smb_smf_end_transaction(handle);
597 smb_smf_scf_fini(handle);
598 return (SMBD_SMF_NO_MEMORY);
601 value = tmp;
604 rc = smb_smf_set_string_property(handle, cfg->sc_name, value);
606 free(tmp);
607 (void) smb_smf_end_transaction(handle);
608 smb_smf_scf_fini(handle);
609 return (rc);
613 * smb_config_setnum
615 * Sets a numeric configuration iterm
618 smb_config_setnum(smb_cfg_id_t id, int64_t value)
620 smb_scfhandle_t *handle;
621 smb_cfg_param_t *cfg;
622 int rc = SMBD_SMF_OK;
624 cfg = smb_config_getent(id);
625 assert(cfg->sc_type == SCF_TYPE_INTEGER);
627 handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
628 if (handle == NULL)
629 return (SMBD_SMF_SYSTEM_ERR);
631 rc = smb_smf_create_service_pgroup(handle, SMBD_PG_NAME);
632 if (rc == SMBD_SMF_OK)
633 rc = smb_smf_start_transaction(handle);
635 if (rc != SMBD_SMF_OK) {
636 smb_smf_scf_fini(handle);
637 return (rc);
640 rc = smb_smf_set_integer_property(handle, cfg->sc_name, value);
642 (void) smb_smf_end_transaction(handle);
643 smb_smf_scf_fini(handle);
644 return (rc);
648 * smb_config_setbool
650 * Sets a boolean configuration iterm
653 smb_config_setbool(smb_cfg_id_t id, boolean_t value)
655 smb_scfhandle_t *handle;
656 smb_cfg_param_t *cfg;
657 int rc = SMBD_SMF_OK;
659 cfg = smb_config_getent(id);
660 assert(cfg->sc_type == SCF_TYPE_BOOLEAN);
662 handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
663 if (handle == NULL)
664 return (SMBD_SMF_SYSTEM_ERR);
666 rc = smb_smf_create_service_pgroup(handle, SMBD_PG_NAME);
667 if (rc == SMBD_SMF_OK)
668 rc = smb_smf_start_transaction(handle);
670 if (rc != SMBD_SMF_OK) {
671 smb_smf_scf_fini(handle);
672 return (rc);
675 rc = smb_smf_set_boolean_property(handle, cfg->sc_name, value);
677 (void) smb_smf_end_transaction(handle);
678 smb_smf_scf_fini(handle);
679 return (rc);
683 * smb_config_set
685 * This function sets the value of the specified config
686 * iterm regardless of its type in string format. This should
687 * be used when the config item type is not known by the caller.
690 smb_config_set(smb_cfg_id_t id, char *value)
692 smb_cfg_param_t *cfg;
693 int64_t cint;
695 cfg = smb_config_getent(id);
696 switch (cfg->sc_type) {
697 case SCF_TYPE_ASTRING:
698 return (smb_config_setstr(id, value));
700 case SCF_TYPE_INTEGER:
701 cint = atoi(value);
702 return (smb_config_setnum(id, cint));
704 case SCF_TYPE_BOOLEAN:
705 return (smb_config_setbool(id, strcasecmp(value, "true") == 0));
708 return (SMBD_SMF_INVALID_ARG);
710 uint8_t
711 smb_config_get_fg_flag()
713 uint8_t run_fg = 0; /* Default is to run in daemon mode */
714 smb_scfhandle_t *handle = NULL;
716 handle = smb_smf_scf_init(SMBD_FMRI_PREFIX);
717 if (handle == NULL) {
718 return (run_fg);
721 if (smb_smf_create_service_pgroup(handle,
722 SMBD_PG_NAME) != SMBD_SMF_OK) {
723 smb_smf_scf_fini(handle);
724 return (run_fg);
727 if (smb_smf_get_boolean_property(handle, "run_fg", &run_fg) != 0) {
728 smb_smf_scf_fini(handle);
729 return (run_fg);
732 smb_smf_scf_fini(handle);
734 return (run_fg);
738 * smb_config_get_localsid
740 * Returns value of the "config/machine_sid" parameter
741 * from the IDMAP SMF configuration repository.
744 char *
745 smb_config_get_localsid(void)
747 return (smb_config_getenv_generic(MACHINE_SID, IDMAP_FMRI_PREFIX,
748 IDMAP_PG_NAME));
752 * smb_config_set_idmap_domain
754 * Set the "config/domain_name" parameter from IDMAP SMF repository.
757 smb_config_set_idmap_domain(char *value)
759 return (smb_config_setenv_generic(IDMAP_FMRI_PREFIX, IDMAP_PG_NAME,
760 IDMAP_DOMAIN, value));
764 * smb_config_refresh_idmap
766 * Refresh IDMAP SMF service after making changes to its configuration.
769 smb_config_refresh_idmap(void)
771 char instance[32];
773 (void) snprintf(instance, sizeof (instance), "%s:default",
774 IDMAP_FMRI_PREFIX);
775 return (smf_refresh_instance(instance));
779 smb_config_secmode_fromstr(char *secmode)
781 if (secmode == NULL)
782 return (SMB_SECMODE_WORKGRP);
784 if (strcasecmp(secmode, SMB_SECMODE_DOMAIN_STR) == 0)
785 return (SMB_SECMODE_DOMAIN);
787 return (SMB_SECMODE_WORKGRP);
790 char *
791 smb_config_secmode_tostr(int secmode)
793 if (secmode == SMB_SECMODE_DOMAIN)
794 return (SMB_SECMODE_DOMAIN_STR);
796 return (SMB_SECMODE_WORKGRP_STR);
800 smb_config_get_secmode()
802 char p[16];
804 (void) smb_config_getstr(SMB_CI_SECURITY, p, sizeof (p));
805 return (smb_config_secmode_fromstr(p));
809 smb_config_set_secmode(int secmode)
811 char *p;
813 p = smb_config_secmode_tostr(secmode);
814 return (smb_config_setstr(SMB_CI_SECURITY, p));
817 static smb_cfg_param_t *
818 smb_config_getent(smb_cfg_id_t id)
820 int i;
822 for (i = 0; i < SMB_CI_MAX; i++)
823 if (smb_cfg_table[i].sc_id == id)
824 return (&smb_cfg_table[id]);
826 assert(0);
827 return (NULL);
830 void
831 smb_config_getdomaininfo(char *domain, char *fqdn, char *sid, char *forest,
832 char *guid)
834 if (domain)
835 (void) smb_config_getstr(SMB_CI_DOMAIN_NAME, domain,
836 NETBIOS_NAME_SZ);
838 if (fqdn)
839 (void) smb_config_getstr(SMB_CI_DOMAIN_FQDN, fqdn,
840 MAXHOSTNAMELEN);
842 if (sid)
843 (void) smb_config_getstr(SMB_CI_DOMAIN_SID, sid,
844 SMB_SID_STRSZ);
846 if (forest)
847 (void) smb_config_getstr(SMB_CI_DOMAIN_FOREST, forest,
848 MAXHOSTNAMELEN);
850 if (guid)
851 (void) smb_config_getstr(SMB_CI_DOMAIN_GUID, guid,
852 UUID_PRINTABLE_STRING_LENGTH);
855 void
856 smb_config_setdomaininfo(char *domain, char *fqdn, char *sid, char *forest,
857 char *guid)
859 if (domain)
860 (void) smb_config_setstr(SMB_CI_DOMAIN_NAME, domain);
861 if (fqdn)
862 (void) smb_config_setstr(SMB_CI_DOMAIN_FQDN, fqdn);
863 if (sid)
864 (void) smb_config_setstr(SMB_CI_DOMAIN_SID, sid);
865 if (forest)
866 (void) smb_config_setstr(SMB_CI_DOMAIN_FOREST, forest);
867 if (guid)
868 (void) smb_config_setstr(SMB_CI_DOMAIN_GUID, guid);