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
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
{
d_printf ( " USAGE: net conf list \n " ) ;
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
{
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 ;
}
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
{
d_printf ( " USAGE: net conf listshares \n " ) ;
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
{
d_printf ( " USAGE: net conf drop \n " ) ;
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
{
d_printf ( " USAGE: net conf showshare <sharename> \n " ) ;
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
{
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 ;
}
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
{
d_printf ( " USAGE: net conf delshare <sharename> \n " ) ;
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
{
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 ;
}
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
{
d_printf ( " USAGE: net conf getparm <section> <param> \n " ) ;
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
{
d_printf ( " USAGE: net conf delparm <section> <param> \n " ) ;
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
{
d_printf ( " USAGE: net conf getincludes <section> \n " ) ;
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
{
d_printf ( " USAGE: net conf setincludes <section> [<filename>]* \n " ) ;
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
{
d_printf ( " USAGE: net conf delincludes <section> \n " ) ;
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 ) ) {
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 ) ) {
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 + + ) {
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 :
2008-04-10 01:48:45 +04:00
servicename = talloc_strdup_lower ( mem_ctx , argv [ 1 ] ) ;
if ( servicename = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
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 ) {
d_printf ( " error: out of memory! \n " ) ;
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 ) ) {
2008-04-09 17:17:28 +04:00
d_printf ( " error loading file '%s': %s \n " , filename ,
dos_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
2008-05-10 01:22:12 +04:00
if ( c - > 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 ) {
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 ) ) {
2007-04-09 14:38:55 +04:00
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 ) ) {
goto done ;
}
} 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 ) ) {
goto done ;
}
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 ) ) {
goto done ;
}
2008-03-27 02:32:00 +03:00
}
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 ) ) {
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 :
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 ) ) {
d_fprintf ( stderr , " Error deleting configuration: %s \n " ,
dos_errstr ( werr ) ) ;
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 ;
}
2008-04-10 01:48:45 +04:00
sharename = talloc_strdup_lower ( mem_ctx , argv [ 0 ] ) ;
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 ) ) {
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
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 ] ;
2008-04-10 01:48:45 +04:00
sharename = talloc_strdup_lower ( mem_ctx , argv [ 0 ] ) ;
if ( sharename = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
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
{
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 :
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 ;
}
2008-04-10 01:48:45 +04:00
sharename = talloc_strdup_lower ( mem_ctx , argv [ 0 ] ) ;
if ( sharename = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
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 ) ) {
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 :
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-04-10 01:48:45 +04:00
service = talloc_strdup_lower ( mem_ctx , argv [ 0 ] ) ;
if ( service = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
goto done ;
}
param = talloc_strdup_lower ( mem_ctx , argv [ 1 ] ) ;
if ( param = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
goto done ;
}
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 :
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-04-10 01:48:45 +04:00
service = talloc_strdup_lower ( mem_ctx , argv [ 0 ] ) ;
if ( service = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
goto done ;
}
param = talloc_strdup_lower ( mem_ctx , argv [ 1 ] ) ;
if ( param = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
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 ,
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 :
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-04-10 01:48:45 +04:00
service = talloc_strdup_lower ( mem_ctx , argv [ 0 ] ) ;
if ( service = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
goto done ;
}
param = talloc_strdup_lower ( mem_ctx , argv [ 1 ] ) ;
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 ,
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 :
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 ;
}
service = talloc_strdup_lower ( mem_ctx , argv [ 0 ] ) ;
if ( service = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
goto done ;
}
werr = smbconf_get_includes ( conf_ctx , mem_ctx , service ,
& num_includes , & includes ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_printf ( " error getting includes: %s \n " , dos_errstr ( werr ) ) ;
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 ;
}
service = talloc_strdup_lower ( mem_ctx , argv [ 0 ] ) ;
if ( service = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
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 ) ) {
d_printf ( " error setting includes: %s \n " , dos_errstr ( werr ) ) ;
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 ;
}
service = talloc_strdup_lower ( mem_ctx , argv [ 0 ] ) ;
if ( service = = NULL ) {
d_printf ( " error: out of memory! \n " ) ;
goto done ;
}
werr = smbconf_delete_includes ( conf_ctx , service ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
d_printf ( " error deleting includes: %s \n " , dos_errstr ( werr ) ) ;
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 03:02:13 +04:00
* This imitates net_run_function3 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 ) ;
}
}
2008-06-07 03:02:13 +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 ,
" Dump the complete configuration in smb.conf like "
" format. " ,
" net conf list \n "
" Dump the complete configuration in smb.conf like "
" format. "
} ,
{
" import " ,
net_conf_import ,
NET_TRANSPORT_LOCAL ,
" Import configuration from file in smb.conf format. " ,
" net conf import \n "
" Import configuration from file in smb.conf format. "
} ,
{
" listshares " ,
net_conf_listshares ,
NET_TRANSPORT_LOCAL ,
" List the share names. " ,
" net conf listshares \n "
" List the share names. "
} ,
{
" drop " ,
net_conf_drop ,
NET_TRANSPORT_LOCAL ,
" Delete the complete configuration. " ,
" net conf drop \n "
" Delete the complete configuration. "
} ,
{
" showshare " ,
net_conf_showshare ,
NET_TRANSPORT_LOCAL ,
" Show the definition of a share. " ,
" net conf showshare \n "
" Show the definition of a share. "
} ,
{
" addshare " ,
net_conf_addshare ,
NET_TRANSPORT_LOCAL ,
" Create a new share. " ,
" net conf addshare \n "
" Create a new share. "
} ,
{
" delshare " ,
net_conf_delshare ,
NET_TRANSPORT_LOCAL ,
" Delete a share. " ,
" net conf delshare \n "
" Delete a share. "
} ,
{
" setparm " ,
net_conf_setparm ,
NET_TRANSPORT_LOCAL ,
" Store a parameter. " ,
" net conf setparm \n "
" Store a parameter. "
} ,
{
" getparm " ,
net_conf_getparm ,
NET_TRANSPORT_LOCAL ,
" Retrieve the value of a parameter. " ,
" net conf getparm \n "
" Retrieve the value of a parameter. "
} ,
{
" delparm " ,
net_conf_delparm ,
NET_TRANSPORT_LOCAL ,
" Delete a parameter. " ,
" net conf delparm \n "
" Delete a parameter. "
} ,
{
" getincludes " ,
net_conf_getincludes ,
NET_TRANSPORT_LOCAL ,
" Show the includes of a share definition. " ,
" net conf getincludes \n "
" Show the includes of a share definition. "
} ,
{
" setincludes " ,
net_conf_setincludes ,
NET_TRANSPORT_LOCAL ,
" Set includes for a share. " ,
" net conf setincludes \n "
" Set includes for a share. "
} ,
{
" delincludes " ,
net_conf_delincludes ,
NET_TRANSPORT_LOCAL ,
" Delete includes from a share definition. " ,
" net conf setincludes \n "
" Delete includes from a share definition. "
} ,
{ 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 ;
}