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
* Copyright ( C ) Michael Adam 2007
*
* 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
*/
/*
2007-08-17 15:06:37 +04:00
* This is an interface to the configuration stored inside the
* samba registry . In the future there might be support for other
2007-06-19 15:11:01 +04:00
* configuration backends as well .
2007-04-09 14:38:55 +04:00
*/
# include "includes.h"
# include "utils/net.h"
2007-12-14 14:22:20 +03:00
# include "libnet/libnet.h"
2007-04-09 14:38:55 +04:00
2007-08-17 15:06:37 +04:00
/*
2007-04-09 14:38:55 +04:00
* usage functions
*/
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 "
" what would be done \n "
" \t <servicename> only import service <servicename>, "
" ignore the rest \n " ) ;
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 ;
}
/*
* Helper functions
*/
2007-07-08 02:18:54 +04:00
static char * parm_valstr ( TALLOC_CTX * ctx , struct parm_struct * parm ,
struct share_params * share )
{
char * valstr = NULL ;
int i = 0 ;
void * ptr = parm - > ptr ;
if ( parm - > p_class = = P_LOCAL & & share - > service > = 0 ) {
ptr = lp_local_ptr ( share - > service , ptr ) ;
}
switch ( parm - > type ) {
case P_CHAR :
valstr = talloc_asprintf ( ctx , " %c " , * ( char * ) ptr ) ;
break ;
case P_STRING :
case P_USTRING :
valstr = talloc_asprintf ( ctx , " %s " , * ( char * * ) ptr ) ;
break ;
case P_BOOL :
2007-10-19 04:40:25 +04:00
valstr = talloc_asprintf ( ctx , " %s " , BOOLSTR ( * ( bool * ) ptr ) ) ;
2007-07-08 02:18:54 +04:00
break ;
case P_BOOLREV :
2007-10-19 04:40:25 +04:00
valstr = talloc_asprintf ( ctx , " %s " , BOOLSTR ( ! * ( bool * ) ptr ) ) ;
2007-07-08 02:18:54 +04:00
break ;
case P_ENUM :
for ( i = 0 ; parm - > enum_list [ i ] . name ; i + + ) {
if ( * ( int * ) ptr = = parm - > enum_list [ i ] . value )
{
valstr = talloc_asprintf ( ctx , " %s " ,
parm - > enum_list [ i ] . name ) ;
break ;
}
}
break ;
2007-11-24 19:27:54 +03:00
case P_OCTAL : {
char * o = octal_string ( * ( int * ) ptr ) ;
valstr = talloc_move ( ctx , & o ) ;
2007-07-08 02:18:54 +04:00
break ;
2007-11-24 19:27:54 +03:00
}
2007-07-08 02:18:54 +04:00
case P_LIST :
valstr = talloc_strdup ( ctx , " " ) ;
if ( ( char * * * ) ptr & & * ( char * * * ) ptr ) {
char * * list = * ( char * * * ) ptr ;
for ( ; * list ; list + + ) {
/* surround strings with whitespace
* in double quotes */
if ( strchr_m ( * list , ' ' ) )
{
valstr = talloc_asprintf_append (
valstr , " \" %s \" %s " ,
* list ,
( ( * ( list + 1 ) ) ? " , " : " " ) ) ;
2007-08-17 15:06:37 +04:00
} else {
2007-07-08 02:18:54 +04:00
valstr = talloc_asprintf_append (
valstr , " %s%s " , * list ,
( ( * ( list + 1 ) ) ? " , " : " " ) ) ;
}
}
}
break ;
case P_INTEGER :
valstr = talloc_asprintf ( ctx , " %d " , * ( int * ) ptr ) ;
break ;
case P_SEP :
break ;
default :
valstr = talloc_asprintf ( ctx , " <type unimplemented> \n " ) ;
break ;
}
return valstr ;
}
static int import_process_service ( TALLOC_CTX * ctx ,
2007-04-09 14:38:55 +04:00
struct share_params * share )
{
int ret = - 1 ;
struct parm_struct * parm ;
int pnum = 0 ;
const char * servicename ;
struct registry_key * key ;
WERROR werr ;
char * valstr = NULL ;
2007-07-08 02:29:34 +04:00
TALLOC_CTX * tmp_ctx = NULL ;
tmp_ctx = talloc_new ( ctx ) ;
if ( tmp_ctx = = NULL ) {
werr = WERR_NOMEM ;
goto done ;
}
2007-04-09 14:38:55 +04:00
servicename = ( share - > service = = GLOBAL_SECTION_SNUM ) ?
GLOBAL_NAME : lp_servicename ( share - > service ) ;
if ( opt_testmode ) {
d_printf ( " [%s] \n " , servicename ) ;
2007-08-17 15:06:37 +04:00
} else {
2007-12-31 03:14:44 +03:00
if ( libnet_smbconf_share_exists ( servicename ) ) {
2007-12-25 04:31:41 +03:00
werr = libnet_smbconf_delshare ( servicename ) ;
2007-04-09 14:38:55 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
}
2007-12-23 06:10:15 +03:00
werr = libnet_smbconf_reg_createkey_internal ( tmp_ctx , servicename , & key ) ;
2007-04-09 14:38:55 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-31 00:27:45 +03:00
d_fprintf ( stderr , " Error creating share %s: %s \n " ,
servicename , dos_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
}
while ( ( parm = lp_next_parameter ( share - > service , & pnum , 0 ) ) )
{
2007-07-08 02:18:54 +04:00
if ( ( share - > service < 0 & & parm - > p_class = = P_LOCAL )
2007-04-09 14:38:55 +04:00
& & ! ( parm - > flags & FLAG_GLOBAL ) )
continue ;
2007-07-08 02:29:34 +04:00
valstr = parm_valstr ( tmp_ctx , parm , share ) ;
2007-04-09 14:38:55 +04:00
if ( parm - > type ! = P_SEP ) {
if ( opt_testmode ) {
d_printf ( " \t %s = %s \n " , parm - > label , valstr ) ;
2007-08-17 15:06:37 +04:00
} else {
2007-12-23 05:34:36 +03:00
werr = libnet_smbconf_reg_setvalue_internal ( key ,
parm - > label , valstr ) ;
2007-04-09 14:38:55 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-31 00:27:45 +03:00
d_fprintf ( stderr ,
" Error setting parameter '%s' "
" : %s \n " , parm - > label ,
dos_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
}
}
}
if ( opt_testmode ) {
d_printf ( " \n " ) ;
}
ret = 0 ;
2007-07-08 02:29:34 +04:00
2007-04-09 14:38:55 +04:00
done :
2007-07-08 02:29:34 +04:00
TALLOC_FREE ( tmp_ctx ) ;
2007-04-09 14:38:55 +04:00
return ret ;
}
2007-12-25 04:48:45 +03:00
/* return true iff there are nondefault globals */
2007-10-19 04:40:25 +04:00
static bool globals_exist ( void )
2007-07-08 03:57:25 +04:00
{
int i = 0 ;
struct parm_struct * parm ;
while ( ( parm = lp_next_parameter ( GLOBAL_SECTION_SNUM , & i , 0 ) ) ! = NULL ) {
if ( parm - > type ! = P_SEP ) {
2007-12-25 04:48:45 +03:00
return true ;
2007-07-08 03:57:25 +04:00
}
}
2007-12-25 04:48:45 +03:00
return false ;
2007-07-08 03:57:25 +04:00
}
2007-04-09 14:38:55 +04:00
/*
2007-08-17 15:06:37 +04:00
* the conf functions
2007-04-09 14:38:55 +04:00
*/
2007-12-29 04:27:20 +03:00
static int net_conf_list ( 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
ctx = talloc_init ( " list " ) ;
if ( argc ! = 0 ) {
net_conf_list_usage ( argc , argv ) ;
goto done ;
}
2007-12-30 00:09:51 +03:00
werr = libnet_smbconf_get_config ( ctx , & num_shares , & share_names ,
& 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 ;
}
2007-12-29 04:27:20 +03:00
static int net_conf_import ( int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
int ret = - 1 ;
const char * filename = NULL ;
const char * servicename = NULL ;
2007-12-25 04:48:45 +03:00
bool service_found = false ;
2007-04-09 14:38:55 +04:00
TALLOC_CTX * ctx ;
struct share_iterator * shares ;
struct share_params * share ;
struct share_params global_share = { GLOBAL_SECTION_SNUM } ;
ctx = talloc_init ( " net_conf_import " ) ;
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 ) ) ;
2007-07-08 03:57:25 +04:00
if ( ! lp_load ( filename ,
2007-12-25 04:48:45 +03:00
false , /* global_only */
true , /* save_defaults */
false , /* add_ipc */
true ) ) /* initialize_globals */
2007-04-09 14:38:55 +04:00
{
d_fprintf ( stderr , " Error parsing configuration file. \n " ) ;
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
}
2007-07-08 03:57:25 +04:00
if ( ( ( servicename = = NULL ) & & globals_exist ( ) ) | |
strequal ( servicename , GLOBAL_NAME ) )
{
2007-12-25 04:48:45 +03:00
service_found = true ;
2007-04-09 14:38:55 +04:00
if ( import_process_service ( ctx , & global_share ) ! = 0 ) {
goto done ;
}
}
if ( service_found & & ( servicename ! = NULL ) ) {
ret = 0 ;
goto done ;
}
if ( ! ( shares = share_list_all ( ctx ) ) ) {
d_fprintf ( stderr , " Could not list shares... \n " ) ;
goto done ;
}
while ( ( share = next_share ( shares ) ) ! = NULL ) {
2007-07-08 03:57:25 +04:00
if ( ( servicename = = NULL )
| | strequal ( servicename , lp_servicename ( share - > service ) ) )
2007-04-09 14:38:55 +04:00
{
2007-12-25 04:48:45 +03:00
service_found = true ;
2007-04-09 14:38:55 +04:00
if ( import_process_service ( ctx , share ) ! = 0 ) {
goto done ;
}
}
}
2007-07-08 03:57:25 +04:00
2007-04-09 14:38:55 +04:00
if ( ( servicename ! = NULL ) & & ! service_found ) {
2007-07-08 03:57:25 +04:00
d_printf ( " Share %s not found in file %s \n " ,
2007-04-09 14:38:55 +04:00
servicename , filename ) ;
goto done ;
}
ret = 0 ;
2007-07-08 03:57:25 +04:00
2007-04-09 14:38:55 +04:00
done :
TALLOC_FREE ( ctx ) ;
return ret ;
}
2007-12-29 04:27:20 +03:00
static int net_conf_listshares ( 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 ;
ctx = talloc_init ( " listshares " ) ;
if ( argc ! = 0 ) {
net_conf_listshares_usage ( argc , argv ) ;
goto done ;
}
2007-12-29 14:55:42 +03:00
werr = libnet_smbconf_get_share_names ( ctx , & num_shares , & 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 ;
}
2007-12-29 04:27:20 +03:00
static int net_conf_drop ( 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 ;
}
2007-12-25 05:05:06 +03:00
werr = libnet_smbconf_drop ( ) ;
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 ;
}
2007-12-29 04:27:20 +03:00
static int net_conf_showshare ( 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
ctx = talloc_init ( " showshare " ) ;
if ( argc ! = 1 ) {
net_conf_showshare_usage ( argc , argv ) ;
goto done ;
}
2007-12-29 05:38:13 +03:00
sharename = argv [ 0 ] ;
werr = libnet_smbconf_getshare ( ctx , sharename , & num_params ,
& 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-29 04:27:20 +03:00
static int net_conf_addshare ( int argc , const char * * argv )
2007-04-09 14:38:55 +04:00
{
int ret = - 1 ;
WERROR werr = WERR_OK ;
struct registry_key * newkey = NULL ;
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 ;
}
/* 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
/*
* create the share
2007-04-09 14:38:55 +04:00
*/
2007-12-23 06:10:15 +03:00
werr = libnet_smbconf_reg_createkey_internal ( NULL , argv [ 0 ] , & newkey ) ;
2007-04-09 14:38:55 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-31 00:27:45 +03:00
d_fprintf ( stderr , " Error creating share %s: %s \n " ,
argv [ 0 ] , dos_errstr ( werr ) ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
/* add config params as values */
2007-12-23 05:34:36 +03:00
werr = libnet_smbconf_reg_setvalue_internal ( newkey , " 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 ) {
2007-12-23 05:34:36 +03:00
werr = libnet_smbconf_reg_setvalue_internal ( newkey , " 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
}
2007-12-23 05:34:36 +03:00
werr = libnet_smbconf_reg_setvalue_internal ( newkey , " 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
2007-12-23 05:34:36 +03:00
werr = libnet_smbconf_reg_setvalue_internal ( newkey , " 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 :
TALLOC_FREE ( newkey ) ;
SAFE_FREE ( sharename ) ;
return ret ;
}
2007-12-29 04:27:20 +03:00
static int net_conf_delshare ( 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
2007-12-25 04:42:33 +03:00
werr = libnet_smbconf_delshare ( sharename ) ;
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 ;
}
static int net_conf_setparm ( int argc , const char * * argv )
{
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
2007-12-25 05:29:05 +03:00
werr = libnet_smbconf_setparm ( 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 ;
}
static int net_conf_getparm ( int argc , const char * * argv )
{
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 ;
ctx = talloc_init ( " getparm " ) ;
if ( argc ! = 2 ) {
net_conf_getparm_usage ( argc , argv ) ;
goto done ;
}
service = strdup_lower ( argv [ 0 ] ) ;
param = strdup_lower ( argv [ 1 ] ) ;
2007-12-29 04:12:33 +03:00
werr = libnet_smbconf_getparm ( 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 ;
}
static int net_conf_delparm ( int argc , const char * * argv )
{
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 ] ) ;
2007-12-25 05:34:04 +03:00
werr = libnet_smbconf_delparm ( 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 ;
}
/*
* Entry - point for all the CONF functions .
*/
int net_conf ( int argc , const char * * argv )
{
int ret = - 1 ;
struct functable2 func [ ] = {
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 ,
2007-04-09 14:38:55 +04:00
" List the registry shares. " } ,
2007-06-22 15:43:50 +04:00
{ " drop " , net_conf_drop ,
" Delete the complete configuration from registry. " } ,
2007-08-17 15:06:37 +04:00
{ " showshare " , net_conf_showshare ,
2007-04-09 14:38:55 +04:00
" Show the definition of a registry share. " } ,
2007-08-17 15:06:37 +04:00
{ " addshare " , net_conf_addshare ,
2007-04-09 14:38:55 +04:00
" Create a new registry share. " } ,
2007-08-17 15:06:37 +04:00
{ " delshare " , net_conf_delshare ,
2007-04-09 14:38:55 +04:00
" Delete a registry 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 }
} ;
2007-06-14 15:29:35 +04:00
if ( ! registry_init_regdb ( ) ) {
d_fprintf ( stderr , " Error initializing the registry! \n " ) ;
2007-04-09 14:38:55 +04:00
goto done ;
}
ret = net_run_function2 ( argc , argv , " net conf " , func ) ;
regdb_close ( ) ;
done :
return ret ;
}