/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Configuration management library
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <synch.h>
#include <string.h>
#include <strings.h>
#include <syslog.h>
#include <netdb.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <libscf.h>
#include <assert.h>
#include <libdlpi.h>
#include <smb/ntdsutil.h>
typedef struct smb_cfg_param {
char *sc_name;
int sc_type;
typedef struct smb_hostifs_walker {
const char *hiw_ifname;
/*
* config parameter flags
*/
/* idmap SMF fmri and Property Group */
static char *b64_data =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
{
/* Oplock configuration, Kernel Only */
0, 0, 0, B_FALSE, smb_config_chk_boolean },
/* Autohome configuration */
0, 0, 0, B_FALSE, smb_config_chk_path },
0, UUID_PRINTABLE_STRING_LENGTH, 0, B_FALSE,
0, 0, 0, B_TRUE, smb_config_chk_hostname },
0, 0, 0, B_TRUE, smb_config_chk_hostname },
/* WINS configuration */
0, 0, 0, B_TRUE, smb_config_chk_hostname },
0, 0, 0, B_TRUE, smb_config_chk_hostname },
0, 0, 0, B_TRUE, smb_config_chk_interface },
/* Kmod specific configuration */
0, B_TRUE, smb_config_chk_range },
0, SMB_PI_MAX_CONNECTIONS_MAX, 0, B_TRUE,
0, 0, 0, B_TRUE, smb_config_chk_boolean },
0, 0, 0, B_TRUE, smb_config_chk_boolean },
0, 0, 0, B_TRUE, smb_config_chk_boolean },
0, 0, 0, B_TRUE, smb_config_chk_boolean },
0, 0, 0, B_TRUE, smb_config_chk_boolean },
/* Kmod tuning configuration */
0, 0, 0, B_FALSE, smb_config_chk_boolean },
/* SMBd configuration */
0, 0, 0, B_FALSE, smb_config_chk_boolean },
0, 0, 0, B_FALSE, smb_config_chk_boolean },
0, 0, 0, B_FALSE, smb_config_chk_boolean },
/* ADS Configuration */
/* Dynamic DNS */
0, 0, 0, B_FALSE, smb_config_chk_boolean },
/*
* Primary DNS suffix of the local system is used in name resolution
* and name registration. This should be set only when the primary DNS
* domain name of the local system doesn't match with the fully
* qualified name of the AD domain.
*/
0, 0, 0, B_TRUE, smb_config_chk_boolean },
0, 0, 0, B_TRUE, smb_config_chk_boolean },
0, UUID_PRINTABLE_STRING_LENGTH, 0, B_FALSE,
/* obsolete */
0, 0, 0, B_TRUE, smb_config_chk_boolean },
0, 0, 0, B_TRUE, smb_config_chk_boolean },
/* SMB_CI_MAX */
};
static struct {
const char *attr;
} smb_cfg_dsattr[] = {
};
static boolean_t smb_is_base64(unsigned char c);
static char *smb_base64_encode(char *str_to_encode);
static char *smb_base64_decode(char *encoded_str);
char *
{
}
static boolean_t
smb_is_base64(unsigned char c)
{
}
/*
* smb_base64_encode
*
* Encode a string using base64 algorithm.
* Caller should free the returned buffer when done.
*/
static char *
{
int ret_cnt = 0;
int i = 0, j = 0;
return (NULL);
}
while (len--) {
arr_3[i++] = *(str_to_encode++);
if (i == 3) {
for (i = 0; i < 4; i++)
i = 0;
}
}
if (i) {
for (j = i; j < 3; j++)
arr_3[j] = '\0';
for (j = 0; j < (i + 1); j++)
while (i++ < 3)
}
return (ret);
}
/*
* smb_base64_decode
*
* Decode using base64 algorithm.
* Caller should free the returned buffer when done.
*/
static char *
{
int i = 0, j = 0;
int en_ind = 0;
int ret_cnt = 0;
char *ret;
char *p;
return (NULL);
en_ind++;
if (i == 4) {
for (i = 0; i < 4; i++) {
return (NULL);
}
}
arr_4[3];
for (i = 0; i < 3; i++)
i = 0;
}
}
if (i) {
for (j = i; j < 4; j++)
arr_4[j] = 0;
for (j = 0; j < 4; j++) {
return (NULL);
}
}
arr_4[3];
for (j = 0; j < (i - 1); j++)
}
return (ret);
}
static char *
{
char *value;
return (NULL);
return (NULL);
}
sizeof (char) * MAX_VALUE_BUFLEN) != 0) {
return (NULL);
}
return (value);
}
static int
{
int rc = 0;
return (1);
}
return (1);
}
rc = 1;
rc = 1;
return (rc);
}
/*
* smb_config_getstr
*
* Fetch the specified string configuration item from SMF
*/
int
{
char *pg;
char *tmp;
*cbuf = '\0';
return (SMBD_SMF_SYSTEM_ERR);
goto error;
goto error;
if (*protbuf != '\0') {
}
} else {
return (SMBD_SMF_SYSTEM_ERR);
if (rc == SMBD_SMF_OK)
}
return (rc);
}
/*
* Translate the value of an astring SMF property into a binary
* IP address. If the value is neither a valid IPv4 nor IPv6
* address, attempt to look it up as a hostname using the
* configured address type.
*/
int
{
int a_family;
struct hostent *h;
return (SMBD_SMF_INVALID_ARG);
if (rc == SMBD_SMF_OK) {
if (*ipstr == '\0')
return (SMBD_SMF_INVALID_ARG);
return (SMBD_SMF_OK);
}
return (SMBD_SMF_OK);
}
/*
* The value is neither an IPv4 nor IPv6 address;
* so check if it's a hostname.
*/
&error);
if (h != NULL) {
h->h_length);
freehostent(h);
rc = SMBD_SMF_OK;
} else {
}
}
return (rc);
}
/*
* smb_config_getcount
*
* Returns the value of a config param of type count (unsigned integer).
*/
int
{
*count = 0;
return (SMBD_SMF_SYSTEM_ERR);
if (rc == SMBD_SMF_OK)
if (rc == SMBD_SMF_OK)
return (rc);
}
/*
* smb_config_getnum
*
* Returns the value of a numeric config param.
*/
int
{
*cint = 0;
return (SMBD_SMF_SYSTEM_ERR);
if (rc == SMBD_SMF_OK)
if (rc == SMBD_SMF_OK)
return (rc);
}
/*
* smb_config_getbool
*
* Returns the value of a boolean config param.
*/
{
return (B_FALSE);
if (rc == SMBD_SMF_OK)
}
/*
* smb_config_get
*
* This function returns the value of the requested config
* item regardless of its type in string format. This should
* be used when the config item type is not known by the caller.
*/
int
{
int rc;
case SCF_TYPE_ASTRING:
case SCF_TYPE_INTEGER:
if (rc == SMBD_SMF_OK)
return (rc);
case SCF_TYPE_BOOLEAN:
if (smb_config_getbool(id))
else
return (SMBD_SMF_OK);
}
return (SMBD_SMF_INVALID_ARG);
}
/*
* smb_config_setstr
*
* Set the specified config param with the given
* value.
*/
int
{
char *pg;
case SMB_CF_PROTECTED:
break;
case SMB_CF_EXEC:
break;
default:
pg = SMB_PG_NAME;
break;
}
return (SMBD_SMF_SYSTEM_ERR);
if (rc == SMBD_SMF_OK)
if (rc != SMBD_SMF_OK) {
return (rc);
}
(void) smb_smf_end_transaction(handle);
return (SMBD_SMF_NO_MEMORY);
}
}
(void) smb_smf_end_transaction(handle);
return (rc);
}
/*
*
* smb_config_setcount
*
* Sets a configuration item of type count (unsigned integer).
*/
int
{
return (SMBD_SMF_SYSTEM_ERR);
if (rc == SMBD_SMF_OK)
if (rc != SMBD_SMF_OK) {
return (rc);
}
(void) smb_smf_end_transaction(handle);
return (rc);
}
/*
* smb_config_setnum
*
* Sets a numeric configuration item
*/
int
{
return (SMBD_SMF_SYSTEM_ERR);
if (rc == SMBD_SMF_OK)
if (rc != SMBD_SMF_OK) {
return (rc);
}
(void) smb_smf_end_transaction(handle);
return (rc);
}
/*
* smb_config_setbool
*
* Sets a boolean configuration item
*/
int
{
return (SMBD_SMF_SYSTEM_ERR);
if (rc == SMBD_SMF_OK)
if (rc != SMBD_SMF_OK) {
return (rc);
}
(void) smb_smf_end_transaction(handle);
return (rc);
}
/*
* smb_config_set
*
* Sets the given value for the specified configuration item.
* The property is specified by its name and the value is in
* string format regardless of the property type.
*
* The value of property is validated before setting and an
* error will be returned if it is not valid.
*
* depends on the property settings in smb_cfg_table[] above.
*/
int
{
int rc, i;
return (SMBD_SMF_INVALID_ARG);
return (SMBD_SMF_INVALID_VALUE);
for (i = 0; i < SMB_CI_MAX; i++) {
cfg = &smb_cfg_table[i];
break;
}
}
return (SMBD_SMF_INVALID_ARG);
return (SMBD_SMF_INVALID_VALUE);
case SCF_TYPE_ASTRING:
break;
case SCF_TYPE_INTEGER:
break;
case SCF_TYPE_BOOLEAN:
break;
default:
break;
}
return (rc);
}
/*
* smb_config_get_localsid
*
* Returns value of the "config/machine_sid" parameter
* from the IDMAP SMF configuration repository.
*
*/
char *
smb_config_get_localsid(void)
{
}
/*
* smb_config_set_idmap_domain
*
* Set the "config/domain_name" parameter from IDMAP SMF repository.
*/
int
{
IDMAP_DOMAIN, value));
}
int
{
return (SMB_SECMODE_WORKGRP);
return (SMB_SECMODE_DOMAIN);
return (SMB_SECMODE_WORKGRP);
}
char *
{
if (secmode == SMB_SECMODE_DOMAIN)
return (SMB_SECMODE_DOMAIN_STR);
return (SMB_SECMODE_WORKGRP_STR);
}
int
{
char p[16];
(void) smb_config_getstr(SMB_CI_SECURITY, p, sizeof (p));
return (smb_config_secmode_fromstr(p));
}
int
{
char *p;
return (smb_config_setstr(SMB_CI_SECURITY, p));
}
void
{
if (nb_domain)
if (ad_domain)
if (sid)
if (forest)
if (guid)
}
void
{
if (nb_domain)
if (ad_domain)
if (sid)
if (forest)
if (guid)
}
int
{
}
int
{
}
int
{
int i;
for (i = 0; i < SMB_CFG_DSATTRNUM; ++i) {
}
return (SMBD_SMF_SYSTEM_ERR);
}
void
{
int i;
int rc;
for (i = 0; i < SMB_CFG_DSATTRNUM; ++i) {
if (rc != 0)
return;
}
}
}
/*
* The version stored in SMF in string format as N.N where
* N is a number defined by Microsoft. The first number represents
* the major version and the second number is the minor version.
* Current defined values can be found here in 'ver_table'.
*
* This function reads the SMF string value and converts it to
* two numbers returned in the given 'version' structure.
* Current default version number is 5.0 which is for Windows 2000.
*/
void
{
char *p;
int rc, i;
};
if (rc != SMBD_SMF_OK)
return;
return;
*p = '\0';
break;
}
}
}
/*
* Reads share exec script properties
*/
{
bufsz = MAXPATHLEN;
}
*map = '\0';
if (*map != '\0')
flags |= SMB_EXEC_MAP;
bufsz = MAXPATHLEN;
}
*unmap = '\0';
if (*unmap != '\0')
flags |= SMB_EXEC_UNMAP;
*buf = '\0';
if (*buf != '\0')
flags |= SMB_EXEC_TERM;
return (flags);
}
{
}
static smb_cfg_param_t *
{
int i;
for (i = 0; i < SMB_CI_MAX; i++)
return (&smb_cfg_table[id]);
assert(0);
return (NULL);
}
/*
* Check the length of the string
*/
static boolean_t
{
return (B_FALSE);
return (B_FALSE);
return (B_TRUE);
}
/*
* Check the numerical range of given value
*/
static boolean_t
{
int val;
errno = 0;
if (errno != 0)
return (B_FALSE);
}
/*
* Check that the specified name is an IP address (v4 or v6) or a hostname.
* Per RFC 1035 and 1123, names may contain alphanumeric characters, hyphens
* and dots. The first and last character of a label must be alphanumeric.
* Interior characters may be alphanumeric or hypens.
*
* Domain names should not contain underscores but we allow them because
* Windows names are often in non-compliance with this rule.
*/
/*ARGSUSED*/
static boolean_t
{
char *p;
char label_terminator;
int len;
return (B_TRUE);
return (B_TRUE);
return (B_TRUE);
return (B_TRUE);
if (len >= MAXHOSTNAMELEN)
return (B_FALSE);
return (B_FALSE);
for (p = (char *)value; *p != '\0'; ++p) {
if (new_label) {
if (!isalnum(*p))
return (B_FALSE);
label_terminator = *p;
continue;
}
if (*p == '.') {
if (!isalnum(label_terminator))
return (B_FALSE);
label_terminator = *p;
continue;
}
label_terminator = *p;
continue;
return (B_FALSE);
}
if (!isalnum(label_terminator))
return (B_FALSE);
return (B_TRUE);
}
/*
* Call back function for dlpi_walk.
* Returns TRUE if interface name exists on the host.
*/
static boolean_t
{
return (iterp->hiw_matchfound);
}
/*
* Checks to see if the input interface exists on the host.
* Returns B_TRUE if the match is found, B_FALSE otherwise.
*/
static boolean_t
{
return (B_FALSE);
return (iter.hiw_matchfound);
}
/*
* Check valid interfaces. Interface names value can be NULL or empty.
* Returns B_FALSE if interface cannot be found on the host.
*/
/*ARGSUSED*/
static boolean_t
{
return (valid);
return (B_FALSE);
return (B_FALSE);
tmp = p;
if (*ifname == '\0') {
break;
}
if (!smb_config_ifexists(ifname)) {
break;
}
}
}
free(p);
return (valid);
}
/*
*/
/*ARGSUSED*/
static boolean_t
{
return (B_FALSE);
}
/*
* Check path
*/
/*ARGSUSED*/
static boolean_t
{
return (B_FALSE);
if (fd < 0)
return (B_FALSE);
if (status < 0)
return (B_FALSE);
}
/*
* Checks to see if the command args are the supported substitution specifier.
* i.e. <cmd> %U %S
*/
/*ARGSUSED*/
static boolean_t
{
char *ptr, *v;
if (*value == '\0')
return (B_TRUE);
do {
break;
if (*v != '\0') {
if (skip_cmdname) {
continue;
}
return (B_FALSE);
return (B_FALSE);
}
} while (v != NULL);
/*
* If skip_cmdname is still true then the string contains
* only spaces. Don't allow such a string.
*/
if (skip_cmdname)
return (B_FALSE);
return (B_TRUE);
}
/*ARGSUSED*/
static boolean_t
{
return (B_FALSE);
if (*value == '\0')
return (B_TRUE);
}