smb_cfg.c revision 8d7e41661dc4633488e93b13363137523ce59977
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "@(#)smb_cfg.c 1.5 08/07/08 SMI"
/*
* 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;
/*
* config parameter flags
*/
#define SMB_CF_PROTECTED 0x01
/* idmap SMF fmri and Property Group */
#define IDMAP_FMRI_PREFIX "system/idmap"
#define MACHINE_SID "machine_sid"
#define IDMAP_DOMAIN "domain_name"
#define IDMAP_PG_NAME "config"
#define SMB_SECMODE_WORKGRP_STR "workgroup"
#define SMB_SECMODE_DOMAIN_STR "domain"
#define SMB_ENC_LEN 1024
#define SMB_DEC_LEN 256
static char *b64_data =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static smb_cfg_param_t smb_cfg_table[] =
{
/* Oplock configuration, Kernel Only */
/* Autohome configuration */
/* WINS configuration */
/* RPC services configuration */
{SMB_CI_SRVSVC_SHRSET_ENABLE, "srvsvc_sharesetinfo_enable",
SCF_TYPE_BOOLEAN, 0},
/* Kmod specific configuration */
/* Kmod tuning configuration */
/* SMBd configuration */
/* ADS Configuration */
/* Dynamic DNS */
0},
0},
0},
0}
/* 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);
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 *
smb_base64_encode(char *str_to_encode)
{
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 *
smb_base64_decode(char *encoded_str)
{
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
{
int rc = SMBD_SMF_OK;
*cbuf = '\0';
return (SMBD_SMF_SYSTEM_ERR);
char protbuf[SMB_ENC_LEN];
char *tmp;
goto error;
goto error;
if (*protbuf != '\0') {
}
} else {
if (rc == SMBD_SMF_OK)
}
return (rc);
}
/*
* smb_config_getnum
*
* Returns the value of a numeric config param.
*/
int
{
int rc = SMBD_SMF_OK;
*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.
*/
{
int rc = SMBD_SMF_OK;
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
{
int rc = SMBD_SMF_OK;
char *pg;
} else {
pg = SMBD_PG_NAME;
}
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
{
int rc = SMBD_SMF_OK;
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
{
int rc = SMBD_SMF_OK;
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);
}
{
return (run_fg);
}
SMBD_PG_NAME) != SMBD_SMF_OK) {
return (run_fg);
}
return (run_fg);
}
return (run_fg);
}
/*
* 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
smb_config_set_idmap_domain(char *value)
{
IDMAP_DOMAIN, value));
}
/*
* smb_config_refresh_idmap
*
* Refresh IDMAP SMF service after making changes to its configuration.
*/
int
smb_config_refresh_idmap(void)
{
char instance[32];
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));
}
static smb_cfg_param_t *
{
int i;
for (i = 0; i < SMB_CI_MAX; i++)
return (&smb_cfg_table[id]);
assert(0);
return (NULL);
}
void
{
}
void
{
}