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"
2010-05-18 04:27:34 +04:00
# include "lib/smbconf/smbconf.h"
# include "lib/smbconf/smbconf_init.h"
# include "lib/smbconf/smbconf_reg.h"
2007-04-09 14:38:55 +04:00
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
2008-05-10 01:22:12 +04:00
static int net_conf_list_usage ( struct net_context * c , int argc ,
const char * * argv )
2007-04-09 14:38:55 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s net conf list \n " , _ ( " Usage: " ) ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_import_usage ( struct net_context * c , int argc ,
const char * * argv )
2007-04-09 14:38:55 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net conf import [--test|-T] <filename> "
2009-07-30 11:00:31 +04:00
" [<servicename>] \n "
" \t [--test|-T] testmode - do not act, just print "
2008-01-04 23:16:48 +03:00
" what would be done \n "
2009-07-30 11:00:31 +04:00
" \t <servicename> only import service <servicename>, "
" ignore the rest \n " ) ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_listshares_usage ( struct net_context * c , int argc ,
const char * * argv )
2007-04-09 14:38:55 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n net conf listshares \n " , _ ( " Usage: " ) ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_drop_usage ( struct net_context * c , int argc ,
const char * * argv )
2007-06-22 15:43:50 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n net conf drop \n " , _ ( " Usage: " ) ) ;
2007-06-22 15:43:50 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_showshare_usage ( struct net_context * c , int argc ,
const char * * argv )
2007-04-09 14:38:55 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net conf showshare <sharename> \n " ) ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_addshare_usage ( struct net_context * c , int argc ,
const char * * argv )
2007-04-09 14:38:55 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net conf addshare <sharename> <path> "
2009-07-30 11:00:31 +04:00
" [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 " ) ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_delshare_usage ( struct net_context * c , int argc ,
const char * * argv )
2007-04-09 14:38:55 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net conf delshare <sharename> \n " ) ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_setparm_usage ( struct net_context * c , int argc ,
const char * * argv )
2007-04-09 14:38:55 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net conf setparm <section> <param> <value> \n " ) ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_getparm_usage ( struct net_context * c , int argc ,
const char * * argv )
2007-04-09 14:38:55 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net conf getparm <section> <param> \n " ) ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_delparm_usage ( struct net_context * c , int argc ,
const char * * argv )
2007-04-09 14:38:55 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net conf delparm <section> <param> \n " ) ) ;
2007-04-09 14:38:55 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_getincludes_usage ( struct net_context * c , int argc ,
const char * * argv )
2008-04-09 17:37:33 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net conf getincludes <section> \n " ) ) ;
2008-04-09 17:37:33 +04:00
return - 1 ;
}
2007-04-09 14:38:55 +04:00
2008-05-10 01:22:12 +04:00
static int net_conf_setincludes_usage ( struct net_context * c , int argc ,
const char * * argv )
2008-04-09 20:46:38 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net conf setincludes <section> [<filename>]* \n " ) ) ;
2008-04-09 20:46:38 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_delincludes_usage ( struct net_context * c , int argc ,
const char * * argv )
2008-04-10 01:24:52 +04:00
{
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net conf delincludes <section> \n " ) ) ;
2008-04-10 01:24:52 +04:00
return - 1 ;
}
2008-04-09 20:46:38 +04:00
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-05-10 01:22:12 +04:00
static WERROR import_process_service ( struct net_context * c ,
struct smbconf_ctx * conf_ctx ,
2008-04-22 18:31:16 +04:00
struct smbconf_service * service )
2007-07-08 02:18:54 +04:00
{
2008-03-26 16:33:22 +03:00
uint32_t idx ;
WERROR werr = WERR_OK ;
2008-04-09 03:20:36 +04:00
uint32_t num_includes = 0 ;
char * * includes = NULL ;
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_testmode ) {
2008-04-15 19:36:11 +04:00
const char * indent = " " ;
2008-04-22 18:31:16 +04:00
if ( service - > name ! = NULL ) {
d_printf ( " [%s] \n " , service - > name ) ;
2008-04-15 19:36:11 +04:00
indent = " \t " ;
2008-04-15 16:38:36 +04:00
}
2008-04-22 18:31:16 +04:00
for ( idx = 0 ; idx < service - > num_params ; idx + + ) {
d_printf ( " %s%s = %s \n " , indent ,
service - > param_names [ idx ] ,
service - > param_values [ idx ] ) ;
2008-03-27 02:32:00 +03:00
}
2008-04-09 16:59:05 +04:00
d_printf ( " \n " ) ;
goto done ;
}
2008-04-22 18:31:16 +04:00
if ( smbconf_share_exists ( conf_ctx , service - > name ) ) {
werr = smbconf_delete_share ( conf_ctx , service - > name ) ;
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-04-22 18:31:16 +04:00
werr = smbconf_create_share ( conf_ctx , service - > name ) ;
2008-04-09 16:59:05 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-04-09 14:38:55 +04:00
2008-04-22 18:31:16 +04:00
for ( idx = 0 ; idx < service - > num_params ; idx + + ) {
if ( strequal ( service - > param_names [ idx ] , " include " ) ) {
2008-04-09 16:59:05 +04:00
includes = TALLOC_REALLOC_ARRAY ( mem_ctx ,
includes ,
char * ,
num_includes + 1 ) ;
if ( includes = = NULL ) {
werr = WERR_NOMEM ;
goto done ;
}
includes [ num_includes ] = talloc_strdup ( includes ,
2008-04-22 18:31:16 +04:00
service - > param_values [ idx ] ) ;
2008-04-09 16:59:05 +04:00
if ( includes [ num_includes ] = = NULL ) {
werr = WERR_NOMEM ;
goto done ;
}
num_includes + + ;
2008-03-26 16:33:22 +03:00
} else {
2008-04-09 16:59:05 +04:00
werr = smbconf_set_parameter ( conf_ctx ,
2008-04-22 18:31:16 +04:00
service - > name ,
service - > param_names [ idx ] ,
service - > param_values [ idx ] ) ;
2008-04-09 16:59:05 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2010-04-21 01:45:06 +04:00
d_fprintf ( stderr ,
_ ( " Error in section [%s], parameter \" %s \" : %s \n " ) ,
service - > name , service - > param_names [ idx ] ,
win_errstr ( werr ) ) ;
2008-04-09 16:59:05 +04:00
goto done ;
2007-04-09 14:38:55 +04:00
}
}
}
2008-04-22 18:31:16 +04:00
werr = smbconf_set_includes ( conf_ctx , service - > name , num_includes ,
2008-04-09 16:59:05 +04:00
( const char * * ) includes ) ;
2008-04-09 03:20:36 +04:00
2007-04-09 14:38:55 +04:00
done :
2008-04-09 03:20:36 +04:00
TALLOC_FREE ( mem_ctx ) ;
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-05-10 01:22:12 +04:00
static int net_conf_list ( struct net_context * c , 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 ;
2008-03-26 16:39:02 +03:00
TALLOC_CTX * mem_ctx ;
2007-12-30 00:09:51 +03:00
uint32_t num_shares ;
uint32_t share_count , param_count ;
2008-04-22 18:31:16 +04:00
struct smbconf_service * * shares = NULL ;
2007-04-09 14:38:55 +04:00
2008-03-26 16:39:02 +03:00
mem_ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
2008-06-07 03:02:13 +04:00
if ( argc ! = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_list_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2008-04-22 18:31:16 +04:00
werr = smbconf_get_config ( conf_ctx , mem_ctx , & num_shares , & shares ) ;
2007-04-09 14:38:55 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error getting config: %s \n " ) ,
2008-11-01 19:19:26 +03:00
win_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 + + ) {
2008-04-15 19:36:44 +04:00
const char * indent = " " ;
2008-04-22 18:31:16 +04:00
if ( shares [ share_count ] - > name ! = NULL ) {
d_printf ( " [%s] \n " , shares [ share_count ] - > name ) ;
2008-04-15 19:36:44 +04:00
indent = " \t " ;
}
2008-04-22 18:31:16 +04:00
for ( param_count = 0 ;
param_count < shares [ share_count ] - > num_params ;
2007-12-30 00:09:51 +03:00
param_count + + )
{
2008-04-15 19:36:44 +04:00
d_printf ( " %s%s = %s \n " ,
indent ,
2008-04-22 18:31:16 +04:00
shares [ share_count ] - > param_names [ param_count ] ,
shares [ share_count ] - > param_values [ param_count ] ) ;
2007-04-09 14:38:55 +04:00
}
d_printf ( " \n " ) ;
}
ret = 0 ;
done :
2008-03-26 16:39:02 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_import ( struct net_context * c , 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 ;
2008-04-13 19:16:54 +04:00
char * conf_source = NULL ;
2008-03-26 16:39:02 +03:00
TALLOC_CTX * mem_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-06-07 03:02:13 +04:00
if ( c - > display_usage )
return net_conf_import_usage ( c , argc , argv ) ;
2008-03-26 16:39:02 +03:00
mem_ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
switch ( argc ) {
case 0 :
default :
2008-05-10 01:22:12 +04:00
net_conf_import_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
case 2 :
2009-04-02 02:23:31 +04:00
servicename = talloc_strdup ( mem_ctx , argv [ 1 ] ) ;
2008-04-10 01:48:45 +04:00
if ( servicename = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-04-10 01:48:45 +04:00
goto done ;
}
2007-04-09 14:38:55 +04:00
case 1 :
filename = argv [ 0 ] ;
break ;
}
DEBUG ( 3 , ( " net_conf_import: reading configuration from file %s. \n " ,
filename ) ) ;
2008-04-13 19:16:54 +04:00
conf_source = talloc_asprintf ( mem_ctx , " file:%s " , filename ) ;
if ( conf_source = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-04-13 19:16:54 +04:00
goto done ;
}
werr = smbconf_init ( mem_ctx , & txt_ctx , conf_source ) ;
2008-03-26 16:33:22 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error loading file '%s': %s \n " ) , filename ,
2008-11-01 19:19:26 +03:00
win_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2008-05-10 01:22:12 +04:00
if ( c - > opt_testmode ) {
2009-07-30 11:00:31 +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 ) {
2008-04-22 18:31:16 +04:00
struct smbconf_service * service = NULL ;
2008-03-26 16:33:22 +03:00
2008-03-26 16:39:02 +03:00
werr = smbconf_get_share ( txt_ctx , mem_ctx ,
2008-03-26 16:33:22 +03:00
servicename ,
2008-04-22 18:31:16 +04:00
& service ) ;
2008-03-26 16:33:22 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-02-24 12:54:13 +03:00
goto cancel ;
2007-04-09 14:38:55 +04:00
}
2009-04-16 04:25:29 +04:00
werr = smbconf_transaction_start ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error starting transaction: %s \n " ) ,
2009-04-16 04:25:29 +04:00
win_errstr ( werr ) ) ;
goto done ;
}
2008-05-10 01:22:12 +04:00
werr = import_process_service ( c , conf_ctx , service ) ;
2008-03-26 16:33:22 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-02-24 12:54:13 +03:00
goto cancel ;
2008-03-26 16:33:22 +03:00
}
} else {
2008-04-22 18:31:16 +04:00
struct smbconf_service * * services = NULL ;
uint32_t num_shares , sidx ;
2007-04-09 14:38:55 +04:00
2008-03-26 16:39:02 +03:00
werr = smbconf_get_config ( txt_ctx , mem_ctx ,
2008-03-26 16:46:43 +03:00
& num_shares ,
2008-04-22 18:31:16 +04:00
& services ) ;
2008-03-26 16:33:22 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-02-24 12:54:13 +03:00
goto cancel ;
2008-03-26 16:33:22 +03:00
}
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_testmode ) {
2008-04-09 03:27:30 +04:00
werr = smbconf_drop ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-02-24 12:54:13 +03:00
goto cancel ;
2008-04-09 03:27:30 +04:00
}
2008-03-27 02:32:00 +03:00
}
2009-03-04 23:46:32 +03:00
/*
* Wrap the importing of shares into a transaction ,
* but only 100 at a time , in order to serve memory .
* The allocated memory accumulates across the actions
* within the transaction , and for me , some 1500
* imported shares , the MAX_TALLOC_SIZE of 256 MB
* was exceeded .
*/
werr = smbconf_transaction_start ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error starting transaction: %s \n " ) ,
2009-03-04 23:46:32 +03:00
win_errstr ( werr ) ) ;
goto done ;
}
2008-03-26 16:33:22 +03:00
for ( sidx = 0 ; sidx < num_shares ; sidx + + ) {
2008-05-10 01:22:12 +04:00
werr = import_process_service ( c , conf_ctx ,
services [ sidx ] ) ;
2008-03-26 16:33:22 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-02-24 12:54:13 +03:00
goto cancel ;
2007-04-09 14:38:55 +04:00
}
2009-03-04 23:46:32 +03:00
if ( sidx % 100 ) {
continue ;
}
werr = smbconf_transaction_commit ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error committing transaction: "
" %s \n " ) ,
2009-03-04 23:46:32 +03:00
win_errstr ( werr ) ) ;
goto done ;
}
werr = smbconf_transaction_start ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error starting transaction: %s \n " ) ,
2009-03-04 23:46:32 +03:00
win_errstr ( werr ) ) ;
goto done ;
}
2007-04-09 14:38:55 +04:00
}
}
2007-07-08 03:57:25 +04:00
2009-02-24 12:54:13 +03:00
werr = smbconf_transaction_commit ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error committing transaction: %s \n " ) ,
2009-02-24 12:54:13 +03:00
win_errstr ( werr ) ) ;
} else {
ret = 0 ;
}
goto done ;
cancel :
werr = smbconf_transaction_cancel ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error cancelling transaction: %s \n " ) ,
2009-02-24 12:54:13 +03:00
win_errstr ( werr ) ) ;
}
2007-07-08 03:57:25 +04:00
2007-04-09 14:38:55 +04:00
done :
2008-03-26 16:39:02 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_listshares ( struct net_context * c ,
struct smbconf_ctx * conf_ctx , 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 ;
2008-03-26 16:39:02 +03:00
TALLOC_CTX * mem_ctx ;
2007-04-09 14:38:55 +04:00
2008-03-26 16:39:02 +03:00
mem_ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
2008-06-07 03:02:13 +04:00
if ( argc ! = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_listshares_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2008-03-26 16:39:02 +03:00
werr = smbconf_get_share_names ( conf_ctx , mem_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 :
2008-03-26 16:39:02 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_drop ( struct net_context * c , 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 ;
2008-06-07 03:02:13 +04:00
if ( argc ! = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_drop_usage ( c , argc , argv ) ;
2007-06-22 15:43:50 +04:00
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 ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error deleting configuration: %s \n " ) ,
2008-11-01 19:19:26 +03:00
win_errstr ( werr ) ) ;
2007-06-22 15:43:50 +04:00
goto done ;
}
ret = 0 ;
done :
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_showshare ( struct net_context * c ,
struct smbconf_ctx * conf_ctx , 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 ;
2008-03-26 16:39:02 +03:00
TALLOC_CTX * mem_ctx ;
2007-12-29 05:38:13 +03:00
uint32_t count ;
2008-04-22 18:31:16 +04:00
struct smbconf_service * service = NULL ;
2007-04-09 14:38:55 +04:00
2008-03-26 16:39:02 +03:00
mem_ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
2008-06-07 03:02:13 +04:00
if ( argc ! = 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_showshare_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2009-04-02 02:23:31 +04:00
sharename = talloc_strdup ( mem_ctx , argv [ 0 ] ) ;
2008-04-10 01:48:45 +04:00
if ( sharename = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
goto done ;
}
2007-12-29 05:38:13 +03:00
2008-04-22 18:31:16 +04:00
werr = smbconf_get_share ( conf_ctx , mem_ctx , sharename , & service ) ;
2007-04-09 14:38:55 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error getting share parameters: %s \n " ) ,
2008-11-01 19:19:26 +03:00
win_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2009-04-02 02:23:31 +04:00
d_printf ( " [%s] \n " , service - > name ) ;
2007-04-09 14:38:55 +04:00
2008-04-22 18:31:16 +04:00
for ( count = 0 ; count < service - > num_params ; count + + ) {
d_printf ( " \t %s = %s \n " , service - > param_names [ count ] ,
service - > param_values [ count ] ) ;
2007-04-09 14:38:55 +04:00
}
ret = 0 ;
done :
2008-03-26 16:39:02 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-04-09 14:38:55 +04:00
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-05-10 01:22:12 +04:00
static int net_conf_addshare ( struct net_context * c ,
struct smbconf_ctx * conf_ctx , 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 ;
2008-04-10 01:48:45 +04:00
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
2008-06-07 03:02:13 +04:00
if ( c - > display_usage ) {
net_conf_addshare_usage ( c , argc , argv ) ;
ret = 0 ;
goto done ;
}
2007-04-09 14:38:55 +04:00
switch ( argc ) {
case 0 :
case 1 :
2007-08-17 15:06:37 +04:00
default :
2008-05-10 01:22:12 +04:00
net_conf_addshare_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
case 5 :
comment = argv [ 4 ] ;
case 4 :
if ( ! strnequal ( argv [ 3 ] , " guest_ok= " , 9 ) ) {
2008-05-10 01:22:12 +04:00
net_conf_addshare_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
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 :
2008-05-10 01:22:12 +04:00
net_conf_addshare_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
case 3 :
if ( ! strnequal ( argv [ 2 ] , " writeable= " , 10 ) ) {
2008-05-10 01:22:12 +04:00
net_conf_addshare_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
switch ( argv [ 2 ] [ 10 ] ) {
case ' y ' :
case ' Y ' :
writeable = " yes " ;
break ;
case ' n ' :
case ' N ' :
writeable = " no " ;
break ;
default :
2008-05-10 01:22:12 +04:00
net_conf_addshare_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
case 2 :
path = argv [ 1 ] ;
2009-04-02 02:23:31 +04:00
sharename = talloc_strdup ( mem_ctx , argv [ 0 ] ) ;
2008-04-10 01:48:45 +04:00
if ( sharename = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-04-10 01:48:45 +04:00
goto done ;
}
2007-04-09 14:38:55 +04:00
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
{
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " ERROR: share name %s contains "
" invalid characters (any of %s) \n " ) ,
2007-04-09 14:38:55 +04:00
sharename , INVALID_SHARENAME_CHARS ) ;
goto done ;
}
if ( strequal ( sharename , GLOBAL_NAME ) ) {
2007-08-17 15:06:37 +04:00
d_fprintf ( stderr ,
2009-07-30 11:00:31 +04:00
_ ( " ERROR: 'global' is not a valid share name. \n " ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2008-03-17 20:01:33 +03:00
if ( smbconf_share_exists ( conf_ctx , sharename ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " ERROR: share %s already exists. \n " ) ,
2007-12-31 03:56:18 +03:00
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 ,
2009-07-30 11:00:31 +04:00
_ ( " Error: path '%s' is not an absolute path. \n " ) ,
2007-04-09 14:38:55 +04:00
path ) ;
goto done ;
}
2009-11-27 15:05:16 +03:00
if ( sys_stat ( path , & sbuf , false ) ! = 0 ) {
2007-04-09 14:38:55 +04:00
d_fprintf ( stderr ,
2009-07-30 11:00:31 +04:00
_ ( " ERROR: cannot stat path '%s' to ensure "
" this is a directory. \n "
" Error was '%s'. \n " ) ,
2007-04-09 14:38:55 +04:00
path , strerror ( errno ) ) ;
goto done ;
}
2009-05-14 17:34:42 +04:00
if ( ! S_ISDIR ( sbuf . st_ex_mode ) ) {
2007-04-09 14:38:55 +04:00
d_fprintf ( stderr ,
2009-07-30 11:00:31 +04:00
_ ( " ERROR: path '%s' is not a directory. \n " ) ,
2007-04-09 14:38:55 +04:00
path ) ;
goto done ;
}
2010-01-29 17:04:25 +03:00
/*
* start a transaction
*/
werr = smbconf_transaction_start ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_printf ( " error starting transaction: %s \n " ,
win_errstr ( werr ) ) ;
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 ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error creating share %s: %s \n " ) ,
2008-11-01 19:19:26 +03:00
sharename , win_errstr ( werr ) ) ;
2010-01-29 17:04:25 +03:00
goto cancel ;
2008-01-03 13:30:14 +03:00
}
/*
* 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 ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error setting parameter %s: %s \n " ) ,
2008-11-01 19:19:26 +03:00
" path " , win_errstr ( werr ) ) ;
2010-01-29 17:04:25 +03:00
goto cancel ;
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 ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error setting parameter %s: %s \n " ) ,
2008-11-01 19:19:26 +03:00
" comment " , win_errstr ( werr ) ) ;
2010-01-29 17:04:25 +03:00
goto cancel ;
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 ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error setting parameter %s: %s \n " ) ,
2008-11-01 19:19:26 +03:00
" 'guest ok' " , win_errstr ( werr ) ) ;
2010-01-29 17:04:25 +03:00
goto cancel ;
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 ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error setting parameter %s: %s \n " ) ,
2008-11-01 19:19:26 +03:00
" writeable " , win_errstr ( werr ) ) ;
2010-01-29 17:04:25 +03:00
goto cancel ;
2007-12-31 00:27:45 +03:00
}
2007-04-09 14:38:55 +04:00
2010-01-29 17:04:25 +03:00
/*
* commit the whole thing
*/
werr = smbconf_transaction_commit ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_printf ( " error committing transaction: %s \n " ,
win_errstr ( werr ) ) ;
} else {
ret = 0 ;
}
goto done ;
cancel :
werr = smbconf_transaction_cancel ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_printf ( " error cancelling transaction: %s \n " ,
win_errstr ( werr ) ) ;
}
2007-04-09 14:38:55 +04:00
done :
2008-04-10 01:48:45 +04:00
TALLOC_FREE ( mem_ctx ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_delshare ( struct net_context * c ,
struct smbconf_ctx * conf_ctx , 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 ;
2008-04-10 01:48:45 +04:00
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
2008-06-07 03:02:13 +04:00
if ( argc ! = 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_delshare_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2009-04-02 02:23:31 +04:00
sharename = talloc_strdup ( mem_ctx , argv [ 0 ] ) ;
2008-04-10 01:48:45 +04:00
if ( sharename = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-04-10 01:48:45 +04:00
goto done ;
}
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 ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error deleting share %s: %s \n " ) ,
2008-11-01 19:19:26 +03:00
sharename , win_errstr ( werr ) ) ;
2007-12-25 04:42:33 +03:00
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 :
2008-04-10 01:48:45 +04:00
TALLOC_FREE ( mem_ctx ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_setparm ( struct net_context * c , 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 ;
2008-04-10 01:48:45 +04:00
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
2008-06-07 03:02:13 +04:00
if ( argc ! = 3 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_setparm_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2008-10-24 15:49:16 +04:00
/*
* NULL service name means " dangling parameters " to libsmbconf .
* We use the empty string from the command line for this purpose .
*/
if ( strlen ( argv [ 0 ] ) ! = 0 ) {
service = talloc_strdup ( mem_ctx , argv [ 0 ] ) ;
if ( service = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-10-24 15:49:16 +04:00
goto done ;
}
2008-04-10 01:48:45 +04:00
}
2009-03-19 04:20:11 +03:00
param = strlower_talloc ( mem_ctx , argv [ 1 ] ) ;
2008-04-10 01:48:45 +04:00
if ( param = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-04-10 01:48:45 +04:00
goto done ;
}
2007-06-20 01:40:27 +04:00
value_str = argv [ 2 ] ;
2007-04-09 14:38:55 +04:00
2009-05-18 00:15:02 +04:00
werr = smbconf_transaction_start ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error starting transaction: %s \n " ) ,
2009-05-18 00:15:02 +04:00
win_errstr ( werr ) ) ;
goto done ;
}
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 ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error creating share '%s': %s \n " ) ,
2008-11-01 19:19:26 +03:00
service , win_errstr ( werr ) ) ;
2009-05-18 00:15:02 +04:00
goto cancel ;
2008-01-04 21:49:57 +03:00
}
}
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 ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error setting value '%s': %s \n " ) ,
2008-11-01 19:19:26 +03:00
param , win_errstr ( werr ) ) ;
2009-05-18 00:15:02 +04:00
goto cancel ;
2007-04-09 14:38:55 +04:00
}
2009-05-18 00:15:02 +04:00
werr = smbconf_transaction_commit ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error committing transaction: %s \n " ) ,
2009-05-18 00:15:02 +04:00
win_errstr ( werr ) ) ;
} else {
ret = 0 ;
}
goto done ;
cancel :
werr = smbconf_transaction_cancel ( conf_ctx ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error cancelling transaction: %s \n " ) ,
2009-05-18 00:15:02 +04:00
win_errstr ( werr ) ) ;
}
2007-04-09 14:38:55 +04:00
done :
2008-04-10 01:48:45 +04:00
TALLOC_FREE ( mem_ctx ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_getparm ( struct net_context * c , 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 ;
2008-03-26 16:39:02 +03:00
TALLOC_CTX * mem_ctx ;
2007-04-09 14:38:55 +04:00
2008-03-26 16:39:02 +03:00
mem_ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
2008-06-07 03:02:13 +04:00
if ( argc ! = 2 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_getparm_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2008-10-24 15:49:16 +04:00
/*
* NULL service name means " dangling parameters " to libsmbconf .
* We use the empty string from the command line for this purpose .
*/
if ( strlen ( argv [ 0 ] ) ! = 0 ) {
service = talloc_strdup ( mem_ctx , argv [ 0 ] ) ;
if ( service = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-10-24 15:49:16 +04:00
goto done ;
}
2008-04-10 01:48:45 +04:00
}
2009-03-19 04:20:11 +03:00
param = strlower_talloc ( mem_ctx , argv [ 1 ] ) ;
2008-04-10 01:48:45 +04:00
if ( param = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-04-10 01:48:45 +04:00
goto done ;
}
2007-04-09 14:38:55 +04:00
2008-03-26 16:39:02 +03:00
werr = smbconf_get_parameter ( conf_ctx , mem_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 ,
2009-07-30 11:00:31 +04: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 ,
2009-07-30 11:00:31 +04:00
_ ( " Error: given parameter '%s' is not set. \n " ) ,
2007-12-23 17:07:20 +03:00
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 ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error getting value '%s': %s. \n " ) ,
2008-11-01 19:19:26 +03:00
param , win_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
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 :
2008-03-26 16:39:02 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_delparm ( struct net_context * c , 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 ;
2008-04-10 01:48:45 +04:00
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2007-04-09 14:38:55 +04:00
2008-06-07 03:02:13 +04:00
if ( argc ! = 2 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_delparm_usage ( c , argc , argv ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2008-10-24 15:49:16 +04:00
/*
* NULL service name means " dangling parameters " to libsmbconf .
* We use the empty string from the command line for this purpose .
*/
if ( strlen ( argv [ 0 ] ) ! = 0 ) {
service = talloc_strdup ( mem_ctx , argv [ 0 ] ) ;
if ( service = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-10-24 15:49:16 +04:00
goto done ;
}
2008-04-10 01:48:45 +04:00
}
2009-03-19 04:20:11 +03:00
param = strlower_talloc ( mem_ctx , argv [ 1 ] ) ;
2008-04-10 01:48:45 +04:00
if ( param = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
goto done ;
}
2007-04-09 14:38:55 +04:00
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 ,
2009-07-30 11:00:31 +04:00
_ ( " Error: given service '%s' does not exist. \n " ) ,
2007-04-09 14:38:55 +04:00
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 ,
2009-07-30 11:00:31 +04:00
_ ( " Error: given parameter '%s' is not set. \n " ) ,
2007-04-09 14:38:55 +04:00
param ) ;
goto done ;
2007-12-23 04:55:25 +03:00
} else if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_fprintf ( stderr , _ ( " Error deleting value '%s': %s. \n " ) ,
2008-11-01 19:19:26 +03:00
param , win_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
ret = 0 ;
done :
2008-04-10 01:48:45 +04:00
TALLOC_FREE ( mem_ctx ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_getincludes ( struct net_context * c ,
struct smbconf_ctx * conf_ctx ,
2008-04-09 17:37:33 +04:00
int argc , const char * * argv )
{
WERROR werr ;
uint32_t num_includes ;
uint32_t count ;
char * service ;
char * * includes = NULL ;
int ret = - 1 ;
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2008-06-07 03:02:13 +04:00
if ( argc ! = 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_getincludes_usage ( c , argc , argv ) ;
2008-04-09 17:37:33 +04:00
goto done ;
}
2009-04-02 02:23:31 +04:00
service = talloc_strdup ( mem_ctx , argv [ 0 ] ) ;
2008-04-09 17:37:33 +04:00
if ( service = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-04-09 17:37:33 +04:00
goto done ;
}
werr = smbconf_get_includes ( conf_ctx , mem_ctx , service ,
& num_includes , & includes ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error getting includes: %s \n " ) , win_errstr ( werr ) ) ;
2008-04-09 17:37:33 +04:00
goto done ;
}
for ( count = 0 ; count < num_includes ; count + + ) {
d_printf ( " include = %s \n " , includes [ count ] ) ;
}
ret = 0 ;
done :
TALLOC_FREE ( mem_ctx ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_setincludes ( struct net_context * c ,
struct smbconf_ctx * conf_ctx ,
2008-04-09 20:46:38 +04:00
int argc , const char * * argv )
{
WERROR werr ;
char * service ;
uint32_t num_includes ;
const char * * includes ;
int ret = - 1 ;
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2008-06-07 03:02:13 +04:00
if ( argc < 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_setincludes_usage ( c , argc , argv ) ;
2008-04-09 20:46:38 +04:00
goto done ;
}
2009-04-02 02:23:31 +04:00
service = talloc_strdup ( mem_ctx , argv [ 0 ] ) ;
2008-04-09 20:46:38 +04:00
if ( service = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-04-09 20:46:38 +04:00
goto done ;
}
num_includes = argc - 1 ;
if ( num_includes = = 0 ) {
includes = NULL ;
} else {
includes = argv + 1 ;
}
werr = smbconf_set_includes ( conf_ctx , service , num_includes , includes ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error setting includes: %s \n " ) , win_errstr ( werr ) ) ;
2008-04-09 20:46:38 +04:00
goto done ;
}
ret = 0 ;
done :
TALLOC_FREE ( mem_ctx ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int net_conf_delincludes ( struct net_context * c ,
struct smbconf_ctx * conf_ctx ,
2008-04-10 01:24:52 +04:00
int argc , const char * * argv )
{
WERROR werr ;
char * service ;
int ret = - 1 ;
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2008-06-07 03:02:13 +04:00
if ( argc ! = 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
net_conf_delincludes_usage ( c , argc , argv ) ;
2008-04-10 01:24:52 +04:00
goto done ;
}
2009-04-02 02:23:31 +04:00
service = talloc_strdup ( mem_ctx , argv [ 0 ] ) ;
2008-04-10 01:24:52 +04:00
if ( service = = NULL ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error: out of memory! \n " ) ) ;
2008-04-10 01:24:52 +04:00
goto done ;
}
werr = smbconf_delete_includes ( conf_ctx , service ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " error deleting includes: %s \n " ) , win_errstr ( werr ) ) ;
2008-04-10 01:24:52 +04:00
goto done ;
}
ret = 0 ;
done :
TALLOC_FREE ( mem_ctx ) ;
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-05-10 01:22:12 +04:00
static int net_conf_wrap_function ( struct net_context * c ,
int ( * fn ) ( struct net_context * ,
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-04-13 19:16:54 +04:00
werr = smbconf_init ( mem_ctx , & conf_ctx , " registry: " ) ;
2008-01-13 03:40:05 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
return - 1 ;
}
2008-05-10 01:22:12 +04:00
ret = fn ( c , conf_ctx , argc , argv ) ;
2008-01-13 03:40:05 +03:00
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-05-10 01:22:12 +04:00
int ( * fn ) ( struct net_context * c , struct smbconf_ctx * ctx , int argc ,
const char * * argv ) ;
2008-06-07 03:02:13 +04:00
int valid_transports ;
const char * description ;
const char * usage ;
2008-01-13 03:40:05 +03:00
} ;
2008-01-14 01:45:57 +03:00
/**
2008-06-07 04:25:08 +04:00
* This imitates net_run_function but calls the main functions
2008-01-14 01:45:57 +03:00
* through the wrapper net_conf_wrap_function ( ) .
*/
2008-05-10 01:22:12 +04:00
static int net_conf_run_function ( struct net_context * c , int argc ,
const char * * argv , const char * whoami ,
2008-01-13 03:40:05 +03:00
struct conf_functable * table )
{
int i ;
if ( argc ! = 0 ) {
for ( i = 0 ; table [ i ] . funcname ; i + + ) {
if ( StrCaseCmp ( argv [ 0 ] , table [ i ] . funcname ) = = 0 )
2008-05-10 01:22:12 +04:00
return net_conf_wrap_function ( c , table [ i ] . fn ,
2008-01-13 03:40:05 +03:00
argc - 1 ,
argv + 1 ) ;
}
}
2009-07-30 11:00:31 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
2008-01-13 03:40:05 +03:00
for ( i = 0 ; table [ i ] . funcname ; i + + ) {
2008-06-07 03:02:13 +04:00
if ( c - > display_usage = = false )
d_printf ( " %s %-15s %s \n " , whoami , table [ i ] . funcname ,
table [ i ] . description ) ;
else
d_printf ( " %s \n " , table [ i ] . usage ) ;
2008-01-13 03:40:05 +03:00
}
2008-06-07 03:02:13 +04:00
return c - > display_usage ? 0 : - 1 ;
2008-01-13 03:40:05 +03:00
}
2007-04-09 14:38:55 +04:00
/*
* Entry - point for all the CONF functions .
*/
2008-05-10 01:22:12 +04:00
int net_conf ( struct net_context * c , int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
int ret = - 1 ;
2008-01-13 03:40:05 +03:00
struct conf_functable func_table [ ] = {
2008-06-07 03:02:13 +04:00
{
" list " ,
net_conf_list ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Dump the complete configuration in smb.conf like "
" format. " ) ,
N_ ( " net conf list \n "
" Dump the complete configuration in smb.conf "
" like format. " )
2008-06-07 03:02:13 +04:00
} ,
{
" import " ,
net_conf_import ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Import configuration from file in smb.conf "
" format. " ) ,
N_ ( " net conf import \n "
" Import configuration from file in smb.conf "
" format. " )
2008-06-07 03:02:13 +04:00
} ,
{
" listshares " ,
net_conf_listshares ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " List the share names. " ) ,
N_ ( " net conf listshares \n "
" List the share names. " )
2008-06-07 03:02:13 +04:00
} ,
{
" drop " ,
net_conf_drop ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Delete the complete configuration. " ) ,
N_ ( " net conf drop \n "
" Delete the complete configuration. " )
2008-06-07 03:02:13 +04:00
} ,
{
" showshare " ,
net_conf_showshare ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Show the definition of a share. " ) ,
N_ ( " net conf showshare \n "
" Show the definition of a share. " )
2008-06-07 03:02:13 +04:00
} ,
{
" addshare " ,
net_conf_addshare ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Create a new share. " ) ,
N_ ( " net conf addshare \n "
" Create a new share. " )
2008-06-07 03:02:13 +04:00
} ,
{
" delshare " ,
net_conf_delshare ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Delete a share. " ) ,
N_ ( " net conf delshare \n "
" Delete a share. " )
2008-06-07 03:02:13 +04:00
} ,
{
" setparm " ,
net_conf_setparm ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Store a parameter. " ) ,
N_ ( " net conf setparm \n "
" Store a parameter. " )
2008-06-07 03:02:13 +04:00
} ,
{
" getparm " ,
net_conf_getparm ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Retrieve the value of a parameter. " ) ,
N_ ( " net conf getparm \n "
" Retrieve the value of a parameter. " )
2008-06-07 03:02:13 +04:00
} ,
{
" delparm " ,
net_conf_delparm ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Delete a parameter. " ) ,
N_ ( " net conf delparm \n "
" Delete a parameter. " )
2008-06-07 03:02:13 +04:00
} ,
{
" getincludes " ,
net_conf_getincludes ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Show the includes of a share definition. " ) ,
N_ ( " net conf getincludes \n "
" Show the includes of a share definition. " )
2008-06-07 03:02:13 +04:00
} ,
{
" setincludes " ,
net_conf_setincludes ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Set includes for a share. " ) ,
N_ ( " net conf setincludes \n "
" Set includes for a share. " )
2008-06-07 03:02:13 +04:00
} ,
{
" delincludes " ,
net_conf_delincludes ,
NET_TRANSPORT_LOCAL ,
2009-07-30 11:00:31 +04:00
N_ ( " Delete includes from a share definition. " ) ,
N_ ( " net conf setincludes \n "
" Delete includes from a share definition. " )
2008-06-07 03:02:13 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2007-04-09 14:38:55 +04:00
} ;
2008-05-10 01:22:12 +04:00
ret = net_conf_run_function ( c , argc , argv , " net conf " , func_table ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}