2007-08-17 15:06:37 +04:00
/*
* Samba Unix / Linux SMB client library
* Distributed SMB / CIFS Server Management Utility
2007-04-09 14:38:55 +04:00
* Local configuration interface
2008-01-03 14:08:49 +03:00
* Copyright ( C ) Michael Adam 2007 - 2008
2007-04-09 14:38:55 +04:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
* the Free Software Foundation ; either version 3 of the License , or
2007-04-09 14:38:55 +04:00
* ( at your option ) any later version .
2007-08-17 15:06:37 +04:00
*
2007-04-09 14:38:55 +04:00
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
2007-08-17 15:06:37 +04:00
*
2007-04-09 14:38:55 +04:00
* You should have received a copy of the GNU General Public License
2007-08-17 15:06:37 +04:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2007-04-09 14:38:55 +04:00
*/
/*
2008-01-04 23:09:55 +03:00
* This is an interface to Samba ' s configuration as made available
2008-03-17 20:01:33 +03:00
* by the libsmbconf interface ( source / lib / smbconf / smbconf . c ) .
2008-01-04 23:03:24 +03:00
*
* This currently supports local interaction with the configuration
* stored in the registry . But other backends and remote access via
2008-01-04 23:05:51 +03:00
* rpc might get implemented in the future .
2007-04-09 14:38:55 +04:00
*/
# include "includes.h"
# include "utils/net.h"
2008-01-14 01:45:57 +03:00
/**********************************************************************
*
2007-04-09 14:38:55 +04:00
* usage functions
2008-01-14 01:45:57 +03:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-09 14:38:55 +04:00
static int net_conf_list_usage ( int argc , const char * * argv )
{
d_printf ( " USAGE: net conf list \n " ) ;
return - 1 ;
}
static int net_conf_import_usage ( int argc , const char * * argv )
{
2007-08-17 15:06:37 +04:00
d_printf ( " USAGE: net conf import [--test|-T] <filename> "
" [<servicename>] \n "
2007-04-09 14:38:55 +04:00
" \t [--test|-T] testmode - do not act, just print "
2008-01-04 23:16:48 +03:00
" what would be done \n "
2007-04-09 14:38:55 +04:00
" \t <servicename> only import service <servicename>, "
2008-01-04 23:16:48 +03:00
" ignore the rest \n " ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
static int net_conf_listshares_usage ( int argc , const char * * argv )
{
d_printf ( " USAGE: net conf listshares \n " ) ;
return - 1 ;
}
2007-06-22 15:43:50 +04:00
static int net_conf_drop_usage ( int argc , const char * * argv )
{
d_printf ( " USAGE: net conf drop \n " ) ;
return - 1 ;
}
2007-04-09 14:38:55 +04:00
static int net_conf_showshare_usage ( int argc , const char * * argv )
{
d_printf ( " USAGE: net conf showshare <sharename> \n " ) ;
return - 1 ;
}
static int net_conf_addshare_usage ( int argc , const char * * argv )
{
d_printf ( " USAGE: net conf addshare <sharename> <path> "
" [writeable={y|N} [guest_ok={y|N} [<comment>]] \n "
" \t <sharename> the new share name. \n "
" \t <path> the path on the filesystem to export. \n "
" \t writeable={y|N} set \" writeable to \" yes \" or "
" \" no \" (default) on this share. \n "
" \t guest_ok={y|N} set \" guest ok \" to \" yes \" or "
" \" no \" (default) on this share. \n "
" \t <comment> optional comment for the new share. \n " ) ;
return - 1 ;
}
static int net_conf_delshare_usage ( int argc , const char * * argv )
{
d_printf ( " USAGE: net conf delshare <sharename> \n " ) ;
return - 1 ;
}
static int net_conf_setparm_usage ( int argc , const char * * argv )
{
2007-06-20 01:40:27 +04:00
d_printf ( " USAGE: net conf setparm <section> <param> <value> \n " ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
static int net_conf_getparm_usage ( int argc , const char * * argv )
{
d_printf ( " USAGE: net conf getparm <section> <param> \n " ) ;
return - 1 ;
}
static int net_conf_delparm_usage ( int argc , const char * * argv )
{
d_printf ( " USAGE: net conf delparm <section> <param> \n " ) ;
return - 1 ;
}
2008-01-14 01:45:57 +03:00
/**********************************************************************
*
2007-04-09 14:38:55 +04:00
* Helper functions
2008-01-14 01:45:57 +03:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-09 14:38:55 +04:00
2008-01-14 01:45:57 +03:00
/**
2008-03-26 16:33:22 +03:00
* This functions process a service previously loaded with libsmbconf .
2008-01-14 01:45:57 +03:00
*/
2008-03-26 16:33:22 +03:00
static WERROR import_process_service ( struct smbconf_ctx * conf_ctx ,
const char * servicename ,
const uint32_t num_params ,
const char * * param_names ,
const char * * param_values )
2007-07-08 02:18:54 +04:00
{
2008-03-26 16:33:22 +03:00
uint32_t idx ;
WERROR werr = WERR_OK ;
2007-04-09 14:38:55 +04:00
if ( opt_testmode ) {
d_printf ( " [%s] \n " , servicename ) ;
2007-08-17 15:06:37 +04:00
} else {
2008-03-26 16:33:22 +03:00
werr = smbconf_delete_share ( conf_ctx , servicename ) ;
2008-01-14 01:30:08 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-04-09 14:38:55 +04:00
}
2008-03-26 16:33:22 +03:00
for ( idx = 0 ; idx < num_params ; idx + + ) {
if ( opt_testmode ) {
d_printf ( " \t %s = %s \n " , param_names [ idx ] ,
param_values [ idx ] ) ;
} else {
werr = smbconf_set_parameter ( conf_ctx ,
servicename ,
param_names [ idx ] ,
param_values [ idx ] ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
2007-04-09 14:38:55 +04:00
}
}
}
done :
2008-03-26 16:33:22 +03:00
return werr ;
2007-07-08 03:57:25 +04:00
}
2007-04-09 14:38:55 +04:00
2008-01-14 01:45:57 +03:00
/**********************************************************************
*
* the main conf functions
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-09 14:38:55 +04:00
2008-03-17 20:01:33 +03:00
static int net_conf_list ( struct smbconf_ctx * conf_ctx ,
2008-01-13 03:40:05 +03:00
int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
WERROR werr = WERR_OK ;
int ret = - 1 ;
TALLOC_CTX * ctx ;
2007-12-30 00:09:51 +03:00
uint32_t num_shares ;
char * * share_names ;
uint32_t * num_params ;
char * * * param_names ;
char * * * param_values ;
uint32_t share_count , param_count ;
2007-04-09 14:38:55 +04:00
2008-03-26 16:34:21 +03:00
ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
if ( argc ! = 0 ) {
net_conf_list_usage ( argc , argv ) ;
goto done ;
}
2008-03-19 12:47:23 +03:00
werr = smbconf_get_config ( conf_ctx , ctx , & num_shares , & share_names ,
2008-03-17 20:01:33 +03:00
& num_params , & param_names , & param_values ) ;
2007-04-09 14:38:55 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-30 00:09:51 +03:00
d_fprintf ( stderr , " Error getting config: %s \n " ,
dos_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2007-12-30 00:09:51 +03:00
for ( share_count = 0 ; share_count < num_shares ; share_count + + ) {
d_printf ( " [%s] \n " , share_names [ share_count ] ) ;
for ( param_count = 0 ; param_count < num_params [ share_count ] ;
param_count + + )
{
d_printf ( " \t %s = %s \n " ,
param_names [ share_count ] [ param_count ] ,
param_values [ share_count ] [ param_count ] ) ;
2007-04-09 14:38:55 +04:00
}
d_printf ( " \n " ) ;
}
ret = 0 ;
done :
TALLOC_FREE ( ctx ) ;
return ret ;
}
2008-03-17 20:01:33 +03:00
static int net_conf_import ( struct smbconf_ctx * conf_ctx ,
2008-01-13 03:40:05 +03:00
int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
int ret = - 1 ;
const char * filename = NULL ;
const char * servicename = NULL ;
TALLOC_CTX * ctx ;
2008-03-26 16:33:22 +03:00
struct smbconf_ctx * txt_ctx ;
WERROR werr ;
2007-04-09 14:38:55 +04:00
2008-03-26 16:34:21 +03:00
ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
switch ( argc ) {
case 0 :
default :
net_conf_import_usage ( argc , argv ) ;
goto done ;
case 2 :
servicename = argv [ 1 ] ;
case 1 :
filename = argv [ 0 ] ;
break ;
}
DEBUG ( 3 , ( " net_conf_import: reading configuration from file %s. \n " ,
filename ) ) ;
2008-03-26 16:33:22 +03:00
werr = smbconf_init_txt_simple ( ctx , & txt_ctx , filename ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-04-09 14:38:55 +04:00
goto done ;
}
if ( opt_testmode ) {
2007-07-08 03:57:25 +04:00
d_printf ( " \n TEST MODE - "
" would import the following configuration: \n \n " ) ;
2007-04-09 14:38:55 +04:00
}
2008-03-26 16:33:22 +03:00
if ( servicename ! = NULL ) {
char * * param_names , * * param_values ;
uint32_t num_params ;
werr = smbconf_get_share ( txt_ctx , ctx ,
servicename ,
& num_params ,
& param_names ,
& param_values ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-04-09 14:38:55 +04:00
goto done ;
}
2008-03-26 16:33:22 +03:00
werr = import_process_service ( conf_ctx ,
servicename ,
num_params ,
param_names ,
param_values ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
} else {
char * * share_names , * * * param_names , * * * param_values ;
uint32_t num_shares , * num_params , sidx ;
2007-04-09 14:38:55 +04:00
2008-03-26 16:33:22 +03:00
werr = smbconf_get_config ( txt_ctx , ctx ,
& num_shares , & share_names ,
& num_params , & param_names , & param_values ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
for ( sidx = 0 ; sidx < num_shares ; sidx + + ) {
werr = import_process_service ( conf_ctx ,
share_names [ sidx ] ,
num_params [ sidx ] ,
param_names [ sidx ] ,
param_values [ sidx ] ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-04-09 14:38:55 +04:00
goto done ;
}
}
}
2007-07-08 03:57:25 +04:00
2007-04-09 14:38:55 +04:00
ret = 0 ;
2007-07-08 03:57:25 +04:00
2007-04-09 14:38:55 +04:00
done :
TALLOC_FREE ( ctx ) ;
return ret ;
}
2008-03-17 20:01:33 +03:00
static int net_conf_listshares ( struct smbconf_ctx * conf_ctx ,
2008-01-13 03:40:05 +03:00
int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
WERROR werr = WERR_OK ;
int ret = - 1 ;
2007-12-29 14:52:09 +03:00
uint32_t count , num_shares = 0 ;
char * * share_names = NULL ;
2007-04-09 14:38:55 +04:00
TALLOC_CTX * ctx ;
2008-03-26 16:34:21 +03:00
ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
if ( argc ! = 0 ) {
net_conf_listshares_usage ( argc , argv ) ;
goto done ;
}
2008-03-19 12:47:23 +03:00
werr = smbconf_get_share_names ( conf_ctx , ctx , & num_shares ,
2008-03-17 20:01:33 +03:00
& share_names ) ;
2007-04-09 14:38:55 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-12-29 16:38:42 +03:00
for ( count = 0 ; count < num_shares ; count + + )
2007-04-09 14:38:55 +04:00
{
2007-12-29 14:52:09 +03:00
d_printf ( " %s \n " , share_names [ count ] ) ;
2007-04-09 14:38:55 +04:00
}
ret = 0 ;
done :
TALLOC_FREE ( ctx ) ;
return ret ;
}
2008-03-17 20:01:33 +03:00
static int net_conf_drop ( struct smbconf_ctx * conf_ctx ,
2008-01-13 03:40:05 +03:00
int argc , const char * * argv )
2007-06-22 15:43:50 +04:00
{
int ret = - 1 ;
WERROR werr ;
if ( argc ! = 0 ) {
net_conf_drop_usage ( argc , argv ) ;
goto done ;
}
2008-03-17 20:01:33 +03:00
werr = smbconf_drop ( conf_ctx ) ;
2007-06-22 15:43:50 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_fprintf ( stderr , " Error deleting configuration: %s \n " ,
dos_errstr ( werr ) ) ;
goto done ;
}
ret = 0 ;
done :
return ret ;
}
2008-03-17 20:01:33 +03:00
static int net_conf_showshare ( struct smbconf_ctx * conf_ctx ,
2008-01-13 03:40:05 +03:00
int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
int ret = - 1 ;
WERROR werr = WERR_OK ;
2007-12-29 15:02:22 +03:00
const char * sharename = NULL ;
2007-04-09 14:38:55 +04:00
TALLOC_CTX * ctx ;
2007-12-29 05:38:13 +03:00
uint32_t num_params ;
uint32_t count ;
char * * param_names ;
char * * param_values ;
2007-04-09 14:38:55 +04:00
2008-03-26 16:34:21 +03:00
ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
if ( argc ! = 1 ) {
net_conf_showshare_usage ( argc , argv ) ;
goto done ;
}
2007-12-29 05:38:13 +03:00
sharename = argv [ 0 ] ;
2008-03-19 12:47:23 +03:00
werr = smbconf_get_share ( conf_ctx , ctx , sharename , & num_params ,
2008-03-17 20:01:33 +03:00
& param_names , & param_values ) ;
2007-04-09 14:38:55 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-29 05:38:13 +03:00
d_printf ( " error getting share parameters: %s \n " ,
dos_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2007-12-29 05:38:13 +03:00
d_printf ( " [%s] \n " , sharename ) ;
2007-04-09 14:38:55 +04:00
2007-12-29 19:02:27 +03:00
for ( count = 0 ; count < num_params ; count + + ) {
2007-12-29 05:38:13 +03:00
d_printf ( " \t %s = %s \n " , param_names [ count ] ,
param_values [ count ] ) ;
2007-04-09 14:38:55 +04:00
}
ret = 0 ;
done :
TALLOC_FREE ( ctx ) ;
return ret ;
}
2007-12-31 03:56:18 +03:00
/**
* Add a share , with a couple of standard parameters , partly optional .
*
* This is a high level utility function of the net conf utility ,
2008-03-17 20:01:33 +03:00
* not a direct frontend to the smbconf API .
2007-12-31 03:56:18 +03:00
*/
2008-03-17 20:01:33 +03:00
static int net_conf_addshare ( struct smbconf_ctx * conf_ctx ,
2008-01-13 03:40:05 +03:00
int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
int ret = - 1 ;
WERROR werr = WERR_OK ;
char * sharename = NULL ;
const char * path = NULL ;
const char * comment = NULL ;
const char * guest_ok = " no " ;
const char * writeable = " no " ;
SMB_STRUCT_STAT sbuf ;
switch ( argc ) {
case 0 :
case 1 :
2007-08-17 15:06:37 +04:00
default :
2007-04-09 14:38:55 +04:00
net_conf_addshare_usage ( argc , argv ) ;
goto done ;
case 5 :
comment = argv [ 4 ] ;
case 4 :
if ( ! strnequal ( argv [ 3 ] , " guest_ok= " , 9 ) ) {
net_conf_addshare_usage ( argc , argv ) ;
goto done ;
}
switch ( argv [ 3 ] [ 9 ] ) {
case ' y ' :
case ' Y ' :
guest_ok = " yes " ;
break ;
case ' n ' :
case ' N ' :
guest_ok = " no " ;
break ;
2007-08-17 15:06:37 +04:00
default :
2007-04-09 14:38:55 +04:00
net_conf_addshare_usage ( argc , argv ) ;
goto done ;
}
case 3 :
if ( ! strnequal ( argv [ 2 ] , " writeable= " , 10 ) ) {
net_conf_addshare_usage ( argc , argv ) ;
goto done ;
}
switch ( argv [ 2 ] [ 10 ] ) {
case ' y ' :
case ' Y ' :
writeable = " yes " ;
break ;
case ' n ' :
case ' N ' :
writeable = " no " ;
break ;
default :
net_conf_addshare_usage ( argc , argv ) ;
goto done ;
}
case 2 :
path = argv [ 1 ] ;
sharename = strdup_lower ( argv [ 0 ] ) ;
break ;
}
2007-08-17 15:06:37 +04:00
/*
* validate arguments
2007-04-09 14:38:55 +04:00
*/
/* validate share name */
2007-08-17 15:06:37 +04:00
if ( ! validate_net_name ( sharename , INVALID_SHARENAME_CHARS ,
strlen ( sharename ) ) )
2007-04-09 14:38:55 +04:00
{
d_fprintf ( stderr , " ERROR: share name %s contains "
" invalid characters (any of %s) \n " ,
sharename , INVALID_SHARENAME_CHARS ) ;
goto done ;
}
if ( getpwnam ( sharename ) ) {
d_fprintf ( stderr , " ERROR: share name %s is already a valid "
" system user name. \n " , sharename ) ;
goto done ;
}
if ( strequal ( sharename , GLOBAL_NAME ) ) {
2007-08-17 15:06:37 +04:00
d_fprintf ( stderr ,
2007-04-09 14:38:55 +04:00
" ERROR: 'global' is not a valid share name. \n " ) ;
goto done ;
}
2008-03-17 20:01:33 +03:00
if ( smbconf_share_exists ( conf_ctx , sharename ) ) {
2007-12-31 03:56:18 +03:00
d_fprintf ( stderr , " ERROR: share %s already exists. \n " ,
sharename ) ;
goto done ;
}
2007-04-09 14:38:55 +04:00
/* validate path */
if ( path [ 0 ] ! = ' / ' ) {
2007-08-17 15:06:37 +04:00
d_fprintf ( stderr ,
2007-04-09 14:38:55 +04:00
" Error: path '%s' is not an absolute path. \n " ,
path ) ;
goto done ;
}
if ( sys_stat ( path , & sbuf ) ! = 0 ) {
d_fprintf ( stderr ,
" ERROR: cannot stat path '%s' to ensure "
" this is a directory. \n "
2007-08-17 15:06:37 +04:00
" Error was '%s'. \n " ,
2007-04-09 14:38:55 +04:00
path , strerror ( errno ) ) ;
goto done ;
}
if ( ! S_ISDIR ( sbuf . st_mode ) ) {
d_fprintf ( stderr ,
" ERROR: path '%s' is not a directory. \n " ,
path ) ;
goto done ;
}
2007-08-17 15:06:37 +04:00
/*
2008-01-03 13:30:14 +03:00
* create the share
*/
2008-03-17 20:01:33 +03:00
werr = smbconf_create_share ( conf_ctx , sharename ) ;
2008-01-03 13:30:14 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_fprintf ( stderr , " Error creating share %s: %s \n " ,
sharename , dos_errstr ( werr ) ) ;
goto done ;
}
/*
* fill the share with parameters
2007-04-09 14:38:55 +04:00
*/
2008-03-17 20:01:33 +03:00
werr = smbconf_set_parameter ( conf_ctx , sharename , " path " , path ) ;
2007-12-31 00:27:45 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_fprintf ( stderr , " Error setting parameter %s: %s \n " ,
" path " , dos_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
2007-12-31 00:27:45 +03:00
}
2007-04-09 14:38:55 +04:00
if ( comment ! = NULL ) {
2008-03-17 20:01:33 +03:00
werr = smbconf_set_parameter ( conf_ctx , sharename , " comment " ,
comment ) ;
2007-12-31 00:27:45 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_fprintf ( stderr , " Error setting parameter %s: %s \n " ,
" comment " , dos_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
2007-12-31 00:27:45 +03:00
}
2007-04-09 14:38:55 +04:00
}
2008-03-17 20:01:33 +03:00
werr = smbconf_set_parameter ( conf_ctx , sharename , " guest ok " , guest_ok ) ;
2007-12-31 00:27:45 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_fprintf ( stderr , " Error setting parameter %s: %s \n " ,
" 'guest ok' " , dos_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
2007-12-31 00:27:45 +03:00
}
2007-08-17 15:06:37 +04:00
2008-03-17 20:01:33 +03:00
werr = smbconf_set_parameter ( conf_ctx , sharename , " writeable " ,
writeable ) ;
2007-12-31 00:27:45 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_fprintf ( stderr , " Error setting parameter %s: %s \n " ,
" writeable " , dos_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
2007-12-31 00:27:45 +03:00
}
2007-04-09 14:38:55 +04:00
ret = 0 ;
done :
SAFE_FREE ( sharename ) ;
return ret ;
}
2008-03-17 20:01:33 +03:00
static int net_conf_delshare ( struct smbconf_ctx * conf_ctx ,
2008-01-13 03:40:05 +03:00
int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
int ret = - 1 ;
const char * sharename = NULL ;
2007-12-25 04:42:33 +03:00
WERROR werr = WERR_OK ;
2007-04-09 14:38:55 +04:00
if ( argc ! = 1 ) {
net_conf_delshare_usage ( argc , argv ) ;
goto done ;
}
sharename = argv [ 0 ] ;
2007-08-17 15:06:37 +04:00
2008-03-17 20:01:33 +03:00
werr = smbconf_delete_share ( conf_ctx , sharename ) ;
2007-12-25 04:42:33 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_fprintf ( stderr , " Error deleting share %s: %s \n " ,
sharename , dos_errstr ( werr ) ) ;
goto done ;
2007-04-09 14:38:55 +04:00
}
2007-12-25 04:42:33 +03:00
ret = 0 ;
2007-04-09 14:38:55 +04:00
done :
return ret ;
}
2008-03-17 20:01:33 +03:00
static int net_conf_setparm ( struct smbconf_ctx * conf_ctx ,
2008-01-13 03:40:05 +03:00
int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
int ret = - 1 ;
WERROR werr = WERR_OK ;
char * service = NULL ;
char * param = NULL ;
const char * value_str = NULL ;
2007-06-20 01:40:27 +04:00
if ( argc ! = 3 ) {
2007-04-09 14:38:55 +04:00
net_conf_setparm_usage ( argc , argv ) ;
goto done ;
}
service = strdup_lower ( argv [ 0 ] ) ;
param = strdup_lower ( argv [ 1 ] ) ;
2007-06-20 01:40:27 +04:00
value_str = argv [ 2 ] ;
2007-04-09 14:38:55 +04:00
2008-03-17 20:01:33 +03:00
if ( ! smbconf_share_exists ( conf_ctx , service ) ) {
werr = smbconf_create_share ( conf_ctx , service ) ;
2008-01-04 21:49:57 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_fprintf ( stderr , " Error creating share '%s': %s \n " ,
service , dos_errstr ( werr ) ) ;
goto done ;
}
}
2008-03-17 20:01:33 +03:00
werr = smbconf_set_parameter ( conf_ctx , service , param , value_str ) ;
2007-04-09 14:38:55 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_fprintf ( stderr , " Error setting value '%s': %s \n " ,
param , dos_errstr ( werr ) ) ;
goto done ;
}
ret = 0 ;
done :
SAFE_FREE ( service ) ;
2007-12-25 05:29:41 +03:00
SAFE_FREE ( param ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2008-03-17 20:01:33 +03:00
static int net_conf_getparm ( struct smbconf_ctx * conf_ctx ,
2008-01-13 03:40:05 +03:00
int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
int ret = - 1 ;
WERROR werr = WERR_OK ;
char * service = NULL ;
char * param = NULL ;
2007-12-29 04:12:33 +03:00
char * valstr = NULL ;
2007-04-09 14:38:55 +04:00
TALLOC_CTX * ctx ;
2008-03-26 16:34:21 +03:00
ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
if ( argc ! = 2 ) {
net_conf_getparm_usage ( argc , argv ) ;
goto done ;
}
service = strdup_lower ( argv [ 0 ] ) ;
param = strdup_lower ( argv [ 1 ] ) ;
2008-03-19 12:47:23 +03:00
werr = smbconf_get_parameter ( conf_ctx , ctx , service , param , & valstr ) ;
2007-12-23 17:07:20 +03:00
if ( W_ERROR_EQUAL ( werr , WERR_NO_SUCH_SERVICE ) ) {
2007-08-17 15:06:37 +04:00
d_fprintf ( stderr ,
2007-12-23 17:07:20 +03:00
" Error: given service '%s' does not exist. \n " ,
2007-04-09 14:38:55 +04:00
service ) ;
goto done ;
2007-12-23 17:07:20 +03:00
} else if ( W_ERROR_EQUAL ( werr , WERR_INVALID_PARAM ) ) {
d_fprintf ( stderr ,
" Error: given parameter '%s' is not set. \n " ,
param ) ;
2007-04-09 14:38:55 +04:00
goto done ;
2007-12-23 17:07:20 +03:00
} else if ( ! W_ERROR_IS_OK ( werr ) ) {
d_fprintf ( stderr , " Error getting value '%s': %s. \n " ,
2007-04-09 14:38:55 +04:00
param , dos_errstr ( werr ) ) ;
goto done ;
}
2007-08-17 15:06:37 +04:00
2007-12-29 04:12:33 +03:00
d_printf ( " %s \n " , valstr ) ;
2007-08-17 15:06:37 +04:00
2007-04-09 14:38:55 +04:00
ret = 0 ;
done :
SAFE_FREE ( service ) ;
SAFE_FREE ( param ) ;
TALLOC_FREE ( ctx ) ;
return ret ;
}
2008-03-17 20:01:33 +03:00
static int net_conf_delparm ( struct smbconf_ctx * conf_ctx ,
2008-01-13 03:40:05 +03:00
int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
int ret = - 1 ;
WERROR werr = WERR_OK ;
char * service = NULL ;
char * param = NULL ;
if ( argc ! = 2 ) {
net_conf_delparm_usage ( argc , argv ) ;
goto done ;
}
service = strdup_lower ( argv [ 0 ] ) ;
param = strdup_lower ( argv [ 1 ] ) ;
2008-03-17 20:01:33 +03:00
werr = smbconf_delete_parameter ( conf_ctx , service , param ) ;
2007-12-23 04:55:25 +03:00
if ( W_ERROR_EQUAL ( werr , WERR_NO_SUCH_SERVICE ) ) {
2007-08-17 15:06:37 +04:00
d_fprintf ( stderr ,
2007-04-09 14:38:55 +04:00
" Error: given service '%s' does not exist. \n " ,
service ) ;
goto done ;
2007-12-23 04:55:25 +03:00
} else if ( W_ERROR_EQUAL ( werr , WERR_INVALID_PARAM ) ) {
2007-08-17 15:06:37 +04:00
d_fprintf ( stderr ,
2007-04-09 14:38:55 +04:00
" Error: given parameter '%s' is not set. \n " ,
param ) ;
goto done ;
2007-12-23 04:55:25 +03:00
} else if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-04-09 14:38:55 +04:00
d_fprintf ( stderr , " Error deleting value '%s': %s. \n " ,
param , dos_errstr ( werr ) ) ;
goto done ;
}
ret = 0 ;
done :
2007-12-25 05:35:00 +03:00
SAFE_FREE ( service ) ;
SAFE_FREE ( param ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2008-01-14 01:45:57 +03:00
/**********************************************************************
*
* Wrapper and net_conf_run_function mechanism .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Wrapper function to call the main conf functions .
* The wrapper calls handles opening and closing of the
* configuration .
*/
2008-03-17 20:01:33 +03:00
static int net_conf_wrap_function ( int ( * fn ) ( struct smbconf_ctx * ,
2008-01-13 03:40:05 +03:00
int , const char * * ) ,
int argc , const char * * argv )
{
WERROR werr ;
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2008-03-17 20:01:33 +03:00
struct smbconf_ctx * conf_ctx ;
2008-01-13 03:40:05 +03:00
int ret = - 1 ;
2008-03-21 19:55:31 +03:00
werr = smbconf_init_reg ( mem_ctx , & conf_ctx , NULL ) ;
2008-01-13 03:40:05 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
return - 1 ;
}
ret = fn ( conf_ctx , argc , argv ) ;
2008-03-21 03:04:57 +03:00
smbconf_shutdown ( conf_ctx ) ;
2008-01-13 03:40:05 +03:00
return ret ;
}
/*
* We need a functable struct of our own , because the
* functions are called through a wrapper that handles
* the opening and closing of the configuration , and so on .
*/
struct conf_functable {
const char * funcname ;
2008-03-17 20:01:33 +03:00
int ( * fn ) ( struct smbconf_ctx * ctx , int argc , const char * * argv ) ;
2008-01-13 03:40:05 +03:00
const char * helptext ;
} ;
2008-01-14 01:45:57 +03:00
/**
* This imitates net_run_function2 but calls the main functions
* through the wrapper net_conf_wrap_function ( ) .
*/
2008-01-13 03:40:05 +03:00
static int net_conf_run_function ( int argc , const char * * argv ,
const char * whoami ,
struct conf_functable * table )
{
int i ;
if ( argc ! = 0 ) {
for ( i = 0 ; table [ i ] . funcname ; i + + ) {
if ( StrCaseCmp ( argv [ 0 ] , table [ i ] . funcname ) = = 0 )
return net_conf_wrap_function ( table [ i ] . fn ,
argc - 1 ,
argv + 1 ) ;
}
}
for ( i = 0 ; table [ i ] . funcname ; i + + ) {
d_printf ( " %s %-15s %s \n " , whoami , table [ i ] . funcname ,
table [ i ] . helptext ) ;
}
return - 1 ;
}
2007-04-09 14:38:55 +04:00
/*
* Entry - point for all the CONF functions .
*/
int net_conf ( int argc , const char * * argv )
{
int ret = - 1 ;
2008-01-13 03:40:05 +03:00
struct conf_functable func_table [ ] = {
2007-08-17 15:06:37 +04:00
{ " list " , net_conf_list ,
2007-04-09 14:38:55 +04:00
" Dump the complete configuration in smb.conf like format. " } ,
{ " import " , net_conf_import ,
" Import configuration from file in smb.conf format. " } ,
2007-08-17 15:06:37 +04:00
{ " listshares " , net_conf_listshares ,
2008-01-04 23:05:51 +03:00
" List the share names. " } ,
2007-06-22 15:43:50 +04:00
{ " drop " , net_conf_drop ,
2008-01-04 23:05:51 +03:00
" Delete the complete configuration. " } ,
2007-08-17 15:06:37 +04:00
{ " showshare " , net_conf_showshare ,
2008-01-04 23:05:51 +03:00
" Show the definition of a share. " } ,
2007-08-17 15:06:37 +04:00
{ " addshare " , net_conf_addshare ,
2008-01-04 23:05:51 +03:00
" Create a new share. " } ,
2007-08-17 15:06:37 +04:00
{ " delshare " , net_conf_delshare ,
2008-01-04 23:05:51 +03:00
" Delete a share. " } ,
2007-08-17 15:06:37 +04:00
{ " setparm " , net_conf_setparm ,
2007-04-09 14:38:55 +04:00
" Store a parameter. " } ,
2007-08-17 15:06:37 +04:00
{ " getparm " , net_conf_getparm ,
2007-04-09 14:38:55 +04:00
" Retrieve the value of a parameter. " } ,
2007-08-17 15:06:37 +04:00
{ " delparm " , net_conf_delparm ,
2007-04-09 14:38:55 +04:00
" Delete a parameter. " } ,
{ NULL , NULL , NULL }
} ;
2008-01-13 03:40:05 +03:00
ret = net_conf_run_function ( argc , argv , " net conf " , func_table ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}