2017-02-17 02:22:38 +03:00
/*
* Samba Unix / Linux client library
* net tdb commands to query tdb record information
* Copyright ( C ) 2016 , 2017 Christof Schmitt < cs @ samba . org >
*
* 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
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* 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 .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "utils/net.h"
2020-10-28 14:09:39 +03:00
# include "locking/share_mode_lock.h"
2017-02-17 02:22:38 +03:00
# include "locking/proto.h"
# include "librpc/gen_ndr/open_files.h"
# include "librpc/gen_ndr/ndr_open_files.h"
2020-11-04 17:09:40 +03:00
static int net_tdb_locking ( struct net_context * c , int argc , const char * * argv )
2017-02-17 02:22:38 +03:00
{
2020-11-04 17:09:40 +03:00
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
struct share_mode_lock * lock ;
DATA_BLOB blob = { . data = NULL } ;
struct file_id id = { . inode = 0 } ;
int ret = - 1 ;
2017-02-17 02:22:38 +03:00
bool ok ;
2020-11-04 17:09:40 +03:00
if ( argc < 1 ) {
d_printf ( " Usage: net tdb locking <key> [ dump ] \n " ) ;
goto out ;
2017-02-17 02:22:38 +03:00
}
ok = locking_init_readonly ( ) ;
if ( ! ok ) {
d_printf ( " locking_init_readonly failed \n " ) ;
2020-11-04 17:09:40 +03:00
goto out ;
2017-02-17 02:22:38 +03:00
}
2020-11-04 17:09:40 +03:00
blob = strhex_to_data_blob ( mem_ctx , argv [ 0 ] ) ;
if ( blob . length ! = sizeof ( struct file_id ) ) {
d_printf ( " Invalid length %zu of key, expected %zu \n " ,
blob . length ,
sizeof ( struct file_id ) ) ;
2017-02-17 02:22:38 +03:00
goto out ;
}
2020-11-04 17:09:40 +03:00
memcpy ( & id , blob . data , blob . length ) ;
lock = fetch_share_mode_unlocked ( mem_ctx , id ) ;
if ( lock = = NULL ) {
d_printf ( " Record with key %s not found. \n " , argv [ 1 ] ) ;
2017-02-17 02:22:38 +03:00
goto out ;
}
if ( argc = = 2 & & strequal ( argv [ 1 ] , " dump " ) ) {
2020-11-04 17:28:16 +03:00
char * dump = share_mode_data_dump ( mem_ctx , lock ) ;
d_printf ( " %s \n " , dump ) ;
TALLOC_FREE ( dump ) ;
2017-02-17 02:22:38 +03:00
} else {
2019-11-29 17:46:20 +03:00
NTSTATUS status ;
size_t num_share_modes = 0 ;
2020-11-04 17:09:40 +03:00
status = share_mode_count_entries ( id , & num_share_modes ) ;
2019-11-29 17:46:20 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr ,
" Could not count share entries: %s \n " ,
nt_errstr ( status ) ) ;
2020-11-04 17:09:40 +03:00
goto out ;
2019-11-29 17:46:20 +03:00
}
2020-11-04 17:11:40 +03:00
d_printf ( " Share path: %s \n " ,
share_mode_servicepath ( lock ) ) ;
2020-11-04 17:12:33 +03:00
d_printf ( " Name: %s \n " ,
share_mode_filename ( mem_ctx , lock ) ) ;
2019-11-29 17:46:20 +03:00
d_printf ( " Number of share modes: %zu \n " , num_share_modes ) ;
2017-02-17 02:22:38 +03:00
}
2020-11-04 17:09:40 +03:00
ret = 0 ;
2017-02-17 02:22:38 +03:00
out :
TALLOC_FREE ( mem_ctx ) ;
return ret ;
}
int net_tdb ( struct net_context * c , int argc , const char * * argv )
{
struct functable func [ ] = {
{ " locking " ,
net_tdb_locking ,
NET_TRANSPORT_LOCAL ,
N_ ( " Show information for a record in locking.tdb " ) ,
N_ ( " net tdb locking <key> " )
} ,
{ NULL , NULL , 0 , NULL , NULL }
} ;
return net_run_function ( c , argc , argv , " net tdb " , func ) ;
}