2010-10-23 19:27:26 -07:00
/*
Samba Unix / Linux SMB client library
Distributed SMB / CIFS Server Management Utility
2005-05-02 14:17:19 +00:00
Copyright ( C ) 2004 Stefan Metzmacher < metze @ samba . org >
Copyright ( C ) 2005 Andrew Bartlett < abartlet @ 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
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-05-02 14:17:19 +00:00
( at your option ) any later version .
2010-10-23 19:27:26 -07:00
2005-05-02 14:17:19 +00: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 .
2010-10-23 19:27:26 -07:00
2005-05-02 14:17:19 +00:00
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-05-02 14:17:19 +00:00
*/
# include "includes.h"
2010-10-23 19:27:26 -07:00
# include "samba_tool/samba_tool.h"
2005-05-02 14:17:19 +00:00
# include "libnet/libnet.h"
2006-03-16 00:23:11 +00:00
# include "librpc/gen_ndr/samr.h"
2006-01-14 06:17:24 +00:00
# include "auth/auth.h"
2009-07-06 16:41:42 +10:00
# include "libcli/security/security.h"
2007-12-03 15:53:28 +01:00
# include "param/param.h"
2008-04-14 12:43:37 -04:00
# include "lib/events/events.h"
2005-05-02 14:17:19 +00:00
2005-12-21 22:02:52 +00:00
/* main function table */
static const struct net_functable net_samdump_functable [ ] = {
{ NULL , NULL , NULL , NULL }
} ;
2010-10-23 19:27:26 -07:00
int net_samdump ( struct net_context * ctx , int argc , const char * * argv )
2005-05-02 14:17:19 +00:00
{
NTSTATUS status ;
struct libnet_context * libnetctx ;
2005-07-25 04:15:57 +00:00
struct libnet_SamDump r ;
2005-12-21 22:02:52 +00:00
int rc ;
switch ( argc ) {
case 0 :
break ;
case 1 :
default :
2010-10-23 19:27:26 -07:00
rc = net_run_function ( ctx , argc , argv , net_samdump_functable ,
2005-12-21 22:02:52 +00:00
net_samdump_usage ) ;
return rc ;
}
2005-05-02 14:17:19 +00:00
2008-04-16 22:30:15 +02:00
libnetctx = libnet_context_init ( ctx - > event_ctx , ctx - > lp_ctx ) ;
2005-05-02 14:17:19 +00:00
if ( ! libnetctx ) {
2010-10-23 19:27:26 -07:00
return - 1 ;
2005-05-02 14:17:19 +00:00
}
2005-06-03 21:30:07 +00:00
libnetctx - > cred = ctx - > credentials ;
2005-05-02 14:17:19 +00:00
2006-01-12 09:33:49 +00:00
r . out . error_string = NULL ;
r . in . machine_account = NULL ;
r . in . binding_string = NULL ;
2005-05-02 14:17:19 +00:00
2008-04-14 12:43:37 -04:00
status = libnet_SamDump ( libnetctx , ctx , & r ) ;
2005-05-02 14:17:19 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " libnet_SamDump returned %s: %s \n " ,
nt_errstr ( status ) ,
2006-01-12 09:33:49 +00:00
r . out . error_string ) ) ;
2005-05-02 14:17:19 +00:00
return - 1 ;
}
2005-06-16 11:36:09 +00:00
talloc_free ( libnetctx ) ;
2005-05-02 14:17:19 +00:00
return 0 ;
}
int net_samdump_usage ( struct net_context * ctx , int argc , const char * * argv )
{
2010-10-23 19:27:26 -07:00
d_printf ( " samba-tool samdump \n " ) ;
return 0 ;
2005-05-02 14:17:19 +00:00
}
int net_samdump_help ( struct net_context * ctx , int argc , const char * * argv )
{
d_printf ( " Dumps the sam of the domain we are joined to. \n " ) ;
2010-10-23 19:27:26 -07:00
return 0 ;
2005-05-02 14:17:19 +00:00
}
2005-07-25 06:33:51 +00:00
2010-10-23 19:27:26 -07:00
int net_samsync_ldb ( struct net_context * ctx , int argc , const char * * argv )
2005-07-25 06:33:51 +00:00
{
NTSTATUS status ;
struct libnet_context * libnetctx ;
struct libnet_samsync_ldb r ;
2008-04-16 22:30:15 +02:00
libnetctx = libnet_context_init ( ctx - > event_ctx , ctx - > lp_ctx ) ;
2005-07-25 06:33:51 +00:00
if ( ! libnetctx ) {
2010-10-23 19:27:26 -07:00
return - 1 ;
2005-07-25 06:33:51 +00:00
}
libnetctx - > cred = ctx - > credentials ;
2006-01-12 09:33:49 +00:00
r . out . error_string = NULL ;
r . in . machine_account = NULL ;
r . in . binding_string = NULL ;
2005-07-25 06:33:51 +00:00
2006-01-14 06:17:24 +00:00
/* Needed to override the ACLs on ldb */
2009-10-23 14:19:28 +11:00
r . in . session_info = system_session ( ctx - > lp_ctx ) ;
2006-01-14 06:17:24 +00:00
status = libnet_samsync_ldb ( libnetctx , libnetctx , & r ) ;
2005-07-25 06:33:51 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " libnet_samsync_ldb returned %s: %s \n " ,
nt_errstr ( status ) ,
2006-01-12 09:33:49 +00:00
r . out . error_string ) ) ;
2005-07-25 06:33:51 +00:00
return - 1 ;
}
talloc_free ( libnetctx ) ;
return 0 ;
}
int net_samsync_ldb_usage ( struct net_context * ctx , int argc , const char * * argv )
{
2010-10-23 19:27:26 -07:00
d_printf ( " samba-tool samsync \n " ) ;
return 0 ;
2005-07-25 06:33:51 +00:00
}
int net_samsync_ldb_help ( struct net_context * ctx , int argc , const char * * argv )
{
2006-05-07 13:40:56 +00:00
d_printf ( " Synchronise into the local ldb the SAM of a domain. \n " ) ;
2010-10-23 19:27:26 -07:00
return 0 ;
2005-07-25 06:33:51 +00:00
}