/*
* 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
*/
/*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
*/
/*
* CIFS 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 <libscf.h>
#include <assert.h>
typedef struct smb_cfg_param {
char *sc_name;
int sc_type;
struct str_val {
char *str;
};
/*
* config parameter flags
*/
/* idmap SMF fmri and Property Group */
static char *b64_data =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
{
/* Oplock configuration, Kernel Only */
/* Autohome configuration */
/* WINS configuration */
/* Kmod specific configuration */
/* Kmod tuning configuration */
/* SMBd configuration */
/* ADS Configuration */
/* Dynamic DNS */
/* SMB_CI_MAX */
};
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);
static int smb_config_get_idmap_preferred_dc(char *, int);
static int smb_config_set_idmap_preferred_dc(char *);
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 *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';
if (id == SMB_CI_DOMAIN_SRV)
return (SMBD_SMF_SYSTEM_ERR);
goto error;
goto error;
if (*protbuf != '\0') {
}
} else {
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_getnum
*
* Returns the value of a numeric config param.
*/
int
{
*cint = 0;
return (SMBD_SMF_SYSTEM_ERR);
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
* iterm 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;
if (id == SMB_CI_DOMAIN_SRV)
return (smb_config_set_idmap_preferred_dc(value));
case SMB_CF_PROTECTED:
break;
case SMB_CF_EXEC:
break;
default:
pg = SMBD_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_setnum
*
* Sets a numeric configuration iterm
*/
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 iterm
*/
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
*
* This function sets the value of the specified config
* iterm regardless of its type in string format. This should
* be used when the config item type is not known by the caller.
*/
int
{
case SCF_TYPE_ASTRING:
case SCF_TYPE_INTEGER:
case SCF_TYPE_BOOLEAN:
}
return (SMBD_SMF_INVALID_ARG);
}
int
{
return (val);
}
SMBD_PG_NAME) != SMBD_SMF_OK) {
return (val);
}
return (val);
}
return (val);
}
{
return (run_fg);
}
SMBD_PG_NAME) != SMBD_SMF_OK) {
return (run_fg);
}
return (run_fg);
}
return (run_fg);
}
/*
* smb_config_get_ads_enable
*
* from the IDMAP SMF configuration repository.
*
*/
{
int rc = 0;
return (B_FALSE);
if (rc == SMBD_SMF_OK)
}
/*
* smb_config_get_localsid
*
* Returns value of the "config/machine_sid" parameter
* from the IDMAP SMF configuration repository.
* Result is allocated; caller should free.
*/
char *
smb_config_get_localsid(void)
{
}
/*
* smb_config_get_localuuid
*
* Returns value of the "config/machine_uuid" parameter
* from the IDMAP SMF configuration repository.
*
*/
int
{
char *s;
uuid_clear(uu);
if (s == NULL)
return (-1);
if (uuid_parse(s, uu) < 0) {
free(s);
return (-1);
}
return (0);
}
static int
{
char *s;
if (s != NULL) {
rc = 0;
free(s);
}
return (rc);
}
static int
{
IDMAP_PREF_DC, value));
}
/*
* smb_config_set_idmap_domain
*
* Set the "config/domain_name" parameter from IDMAP SMF repository.
*/
int
{
IDMAP_DOMAIN, value));
}
/*
* smb_config_refresh_idmap
*
* Refresh IDMAP SMF service after making changes to its configuration.
*/
int
smb_config_refresh_idmap(void)
{
return (smf_refresh_instance(instance));
}
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
char *guid)
{
if (domain)
if (fqdn)
if (sid)
if (forest)
if (guid)
}
void
char *guid)
{
if (domain)
if (fqdn)
if (sid)
if (forest)
if (guid)
}
/*
* 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);
}
/*
* We store the max SMB protocol version in SMF as a string,
* interfaces use the numeric form.
*
* The numeric values are as defined in the [MS-SMB2] spec.
* except for how we represent "1" (for SMB1) which is an
* arbitrary value below SMB2_VERS_BASE.
*/
static struct str_val
smb_versions[] = {
{ "3.0", SMB_VERS_3_0 },
{ "2.1", SMB_VERS_2_1 },
{ "2.002", SMB_VERS_2_002 },
{ "1", SMB_VERS_1 },
{ NULL, 0 }
};
/*
* This really should be the latest (SMB_VERS_3_0)
* but we're being cautious with SMB3 for a while.
*/
{
int i, rc;
if (rc == SMBD_SMF_OK) {
return (smb_versions[i].val);
}
if (str[0] != '\0') {
}
}
return (max_protocol_default);
}
int
{
int i;
return (0);
}
return (-1);
}
/*
* If smb2_enable is present and max_protocol is empty,
* set max_protocol. Delete smb2_enable.
*/
static void
{
char *s2e_sval;
char *maxp_sval;
int rc;
return;
if (rc != SMBD_SMF_OK)
goto out;
/* Is there an "smb2_enable" property? */
if (rc != SMBD_SMF_OK) {
goto out;
}
/*
* We will try to delete the smb2_enable property, so we need
* the transaction to start now, before we modify max_protocol
*/
goto out;
}
/*
* Old (smb2_enable) property exists.
* Does the new one? (max_protocol)
*/
/* Leave existing max_protocol as we found it. */
} else {
/*
* New property missing or invalid.
* Upgrade from "smb2_enable".
*/
if (s2e_bval == 0) {
s2e_sval = "false";
maxp_sval = "1";
} else {
s2e_sval = "true";
maxp_sval = "2.1";
}
/*
* Note: Need this in the same transaction as the
* delete of smb2_enable below.
*/
if (rc != SMBD_SMF_OK) {
goto out;
}
"converted to smbd/max_protocol=%s",
}
/*
* Delete the old smb2_enable property.
*/
}
if (rc != 0) {
}
out:
(void) smb_smf_end_transaction(handle);
}
/*
* Run once at startup convert old SMF settings to current.
*/
void
smb_config_upgrade(void)
{
}