smb_cfg.c revision 55bf511df53aad0fdb7eb3fa349f0308cc05234c
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% 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>
typedef struct smb_cfg_param {
char *sc_pg;
char *sc_name;
int sc_type;
char *sc_value;
/*
* config parameter flags
*/
#define SMB_CL_NONE 0
#define SMB_CL_READ 1
#define SMB_CL_WRITE 2
/* 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 rwlock_t smb_cfg_rwlk;
static int lock_type = SMB_CL_NONE;
/*
* IMPORTANT: any changes to the order of this table's entries
* need to be reflected in smb_cfg_id_t enum in libsmb.h
*/
static smb_cfg_param_t smb_cfg_table[] =
{
/* Redirector configuration, User space */
/* Oplock configuration, Kernel Only */
/* Autohome configuration */
/* WINS configuration */
/* RPC services 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_save_all();
static int smb_config_save(char *pgname);
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);
}
/*
* Basically commit the transaction.
*/
static int
{
int ret = 0;
return (ret);
}
/*
* smb_config_getenv
*
* Get the property value from SMF.
*/
char *
{
char *value;
return (NULL);
return (NULL);
}
sizeof (char) * MAX_VALUE_BUFLEN) != 0) {
return (NULL);
}
return (value);
}
/*
* smb_config_getenv_dec
*
* For protected property, the value obtained from SMF will be decoded.
* The decoded property value will be returned.
*
* This function should only be called by smb_config_load to populate
* the SMB config cache.
*/
static char *
{
char *value;
char *dec;
return (NULL);
return (NULL);
}
sizeof (char) * MAX_VALUE_BUFLEN) != 0) {
return (NULL);
}
return (value);
if (!value)
return (NULL);
if (*value == '\0') {
return (NULL);
}
return (dec);
}
static char *
{
char *value;
return (NULL);
return (NULL);
}
sizeof (char) * MAX_VALUE_BUFLEN) != 0) {
return (NULL);
}
return (value);
}
int
{
int rc = 0;
return (1);
}
return (1);
}
rc = 1;
rc = 1;
return (rc);
}
/*
* smb_config_setenv
*
* For protected properties, the value will be encoded using base64
* algorithm. The encoded string will be stored in SMF.
*/
int
{
int is_protected = 0;
return (1);
}
return (1);
}
return (1);
}
(void) smb_smf_end_transaction(handle);
return (1);
}
(void) smb_smf_end_transaction(handle);
return (1);
}
is_protected = 1;
}
!= SMBD_SMF_OK) {
if (enc)
(void) smb_smf_end_transaction(handle);
return (1);
}
if (enc)
return (1);
}
return (0);
}
static void
{
}
}
/*
* smb_config_setenv_trans_protected
*
* This function should only be called to set protected properties
* in SMF. The argument 'value' will be encoded using base64 algorithm.
* The encoded string will be stored in SMF.
*/
static void
char *value)
{
char *enc;
return;
return;
" %s", name);
}
}
int
{
int ret = 1;
return (ret);
}
return (ret);
}
(void) smb_smf_end_transaction(handle);
return (ret);
}
static int
{
}
/*
* smb_config_load
*
* Loads all the CIFS configuration parameters and sets up the
* config table.
*/
int
{
char *value;
(void) rw_rdlock(&smb_cfg_rwlk);
/*
* enval == 0 could mean two things, either the
* config param is not defined, or it has been
* removed. If the variable has already been defined
* and now enval is 0, it should be removed, otherwise
* we don't need to do anything in this case.
*/
(void) rw_unlock(&smb_cfg_rwlk);
if (value)
return (1);
}
}
if (value) {
}
}
(void) rw_unlock(&smb_cfg_rwlk);
return (0);
}
/*
* smb_config_get
*
* Returns value of the specified config param.
* The return value is a string pointer to the locally
* allocated memory if the config param is defined
* otherwise it would be NULL.
*
* This function MUST be called after a smb_config_rd/wrlock
* function. Caller MUST NOT modify the returned buffer directly.
*/
char *
{
if (id < SMB_CI_MAX)
return (0);
}
/*
* smb_config_getstr
*
* Returns value of the specified config param.
* The returned pointer never will be NULL if the given
* 'id' is valid. If the config param is not defined its
* default value will be returned.
*
* This function MUST be called after a smb_config_rd/wrlock
* function. Caller MUST NOT modify the returned buffer directly.
*/
char *
{
if (id < SMB_CI_MAX) {
}
return (NULL);
}
/*
* smb_config_getnum
*
* Returns the value of a numeric config param.
* If the config param is not defined it'll return the
* default value.
*
* This function MUST be called after a smb_config_rd/wrlock
* function.
*/
{
if (id < SMB_CI_MAX) {
if (strval)
}
return (0);
}
/*
* smb_config_getyorn
*
* Returns 1 is config is set to "yes", otherwise 0.
*
* This function MUST be called after a smb_config_rd/wrlock
* function.
*/
int
{
char *val;
if (val) {
return (1);
}
return (0);
}
/*
* smb_config_set
*
* value. If the value is NULL the config param will be
* unset as if it is not defined.
*
* This function MUST be called after a smb_config_wrlock
* function.
*/
int
{
int rc = 0;
if (id < SMB_CI_MAX) {
if (rc == 0)
return (rc);
}
return (1);
}
/*
* smb_config_setnum
*
* value. This is used for numeric config params. The given
* number will be converted to string before setting the
* config param.
*
* This function MUST be called after a smb_config_wrlock
* function.
*/
int
{
char value[32];
int rc = 0;
if (id < SMB_CI_MAX) {
if (rc == 0)
return (rc);
}
return (1);
}
/*
* smb_config_rdlock
*
* Lock the config table for read access.
* This function MUST be called before any kind of
* read access to the config table i.e. all flavors of
* smb_config_get function
*/
void
{
(void) rw_rdlock(&smb_cfg_rwlk);
}
/*
* smb_config_wrlock
*
* Lock the config table for write access.
* This function MUST be called before any kind of
* write access to the config table i.e. all flavors of
* smb_config_set function
*/
void
{
(void) rw_wrlock(&smb_cfg_rwlk);
}
/*
* smb_config_wrlock
*
* Unlock the config table.
* If the config table has been locked for write access
* smb_config_save_all() will be called to save the changes
* before unlocking the table.
*
* This function MUST be called after smb_config_rd/wrlock
*/
void
{
if (lock_type == SMB_CL_WRITE)
(void) smb_config_save_all();
(void) rw_unlock(&smb_cfg_rwlk);
}
/*
* smb_config_save_all
*
* Save all modified parameters to SMF.
*/
static int
{
int rc;
return (rc);
return (smb_config_save(SMBD_PROTECTED_PG_NAME));
}
/*
* smb_config_save
*
* Scan the config table and call smb_config_setenv/smb_config_unsetenv
* for params in the specified property group that has been modified.
* When the scan is finished, smb_config_saveenv() will be called to
* make the changes persistent.
*/
static int
smb_config_save(char *pgname)
{
int dorefresh = 0;
return (1);
}
return (1);
}
continue;
else
} else {
(void) smb_config_unsetenv_trans(handle,
}
dorefresh = 1;
}
}
if (smb_config_saveenv(handle) != 0) {
return (1);
}
if (dorefresh)
return (0);
}
/*
* smb_config_update
*
* Updates the specified config param with the given value.
* This function is called both on (re)load and set.
*/
static int
{
char *curval;
int rc = 0;
int len;
if (value) {
(len + 1));
} else {
}
if (curval) {
} else {
rc = 1;
}
}
return (rc);
}
{
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));
}
/*
* smb_config_refresh
*
* Refresh SMB SMF service.
*/
int
smb_config_refresh(void)
{
return (smf_refresh_instance(SMBD_DEFAULT_INSTANCE_FMRI));
}
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;
return (smb_config_secmode_fromstr(p));
}
int
{
char *p;
return (smb_config_set(SMB_CI_SECURITY, p));
}