2004-08-25 16:11:28 +04:00
/*
Unix SMB / CIFS implementation .
Copyright ( C ) Stefan Metzmacher 2004
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 2 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 , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2004-11-02 14:42:35 +03:00
# include "libnet/libnet.h"
2004-11-02 03:24:21 +03:00
# include "system/time.h"
2006-03-15 02:35:30 +03:00
# include "librpc/gen_ndr/ndr_srvsvc_c.h"
2004-08-25 16:11:28 +04:00
/*
* get the remote time of a server via srvsvc_NetRemoteTOD
*/
static NTSTATUS libnet_RemoteTOD_srvsvc ( struct libnet_context * ctx , TALLOC_CTX * mem_ctx , union libnet_RemoteTOD * r )
{
NTSTATUS status ;
2005-07-02 18:33:55 +04:00
struct libnet_RpcConnect c ;
2004-08-25 16:11:28 +04:00
struct srvsvc_NetRemoteTOD tod ;
struct tm tm ;
/* prepare connect to the SRVSVC pipe of a timeserver */
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
c . level = LIBNET_RPC_CONNECT_SERVER ;
c . in . name = r - > srvsvc . in . server_name ;
c . in . dcerpc_iface = & dcerpc_table_srvsvc ;
2004-08-25 16:11:28 +04:00
/* 1. connect to the SRVSVC pipe of a timeserver */
2005-07-02 18:33:55 +04:00
status = libnet_RpcConnect ( ctx , mem_ctx , & c ) ;
2004-08-25 16:11:28 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
r - > srvsvc . out . error_string = talloc_asprintf ( mem_ctx ,
2006-09-18 13:54:44 +04:00
" Connection to SRVSVC pipe of server '%s' failed: %s " ,
2004-08-25 16:11:28 +04:00
r - > srvsvc . in . server_name , nt_errstr ( status ) ) ;
return status ;
}
/* prepare srvsvc_NetrRemoteTOD */
r12858: This moves the libnet_LookupPdc code to use a GetDC request to find
the remote server's name, or in the absence of a local nbt_server to
communicate with (or without root access), a node status request.
The result is that we are in a better position to use kerberos, as well
as to remove the 'password server' mandatory parameter for the samsync
and samdump commands. (I need this to put these into SWAT).
The only problem I have is that I must create a messaging context, which
requires a server ID. As a client process, I don't expect to get
messages, but it is currently required for replies, so I generate a
random() number. We probably need the servers to accept connections on
streamed sockets too, for client-only tasks that want IRPC.
Because I wanted to test this code, I have put the NET-API-* tests into
our test scripts, to ensure they pass and keep passing. They are good
frontends onto the libnet system, and I see no reason not to test them.
In doing so the NET-API-RPCCONNECT test was simplified to take a
binding string on the command line, removing duplicate code, and
testing the combinations in the scripts instead.
(I have done a bit of work on the list shares code in libnet_share.c
to make it pass 'make test')
In the future, I would like to extend the libcli/findds.c code (based
off volker's winbind/wb_async_helpers.c, which is why it shows up a bit
odd in the patch) to handle getting multiple name replies, sending a
getdc request to each in turn.
(posted to samba-technical for review, and I'll happily update with
any comments)
Andrew Bartlett
(This used to be commit 7ccddfd3515fc2c0d6f447c768ccbf7a220c3380)
2006-01-12 06:02:00 +03:00
tod . in . server_unc = talloc_asprintf ( mem_ctx , " \\ %s " , c . in . name ) ;
2004-08-25 16:11:28 +04:00
/* 2. try srvsvc_NetRemoteTOD */
2005-07-02 18:33:55 +04:00
status = dcerpc_srvsvc_NetRemoteTOD ( c . out . dcerpc_pipe , mem_ctx , & tod ) ;
2004-08-25 16:11:28 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
r - > srvsvc . out . error_string = talloc_asprintf ( mem_ctx ,
2006-09-18 13:58:53 +04:00
" srvsvc_NetrRemoteTOD on server '%s' failed: %s " ,
2004-08-25 16:11:28 +04:00
r - > srvsvc . in . server_name , nt_errstr ( status ) ) ;
goto disconnect ;
}
/* check result of srvsvc_NetrRemoteTOD */
if ( ! W_ERROR_IS_OK ( tod . out . result ) ) {
r - > srvsvc . out . error_string = talloc_asprintf ( mem_ctx ,
2006-09-18 13:54:44 +04:00
" srvsvc_NetrRemoteTOD on server '%s' failed: %s " ,
2004-08-25 16:11:28 +04:00
r - > srvsvc . in . server_name , win_errstr ( tod . out . result ) ) ;
status = werror_to_ntstatus ( tod . out . result ) ;
goto disconnect ;
}
/* need to set the out parameters */
tm . tm_sec = ( int ) tod . out . info - > secs ;
tm . tm_min = ( int ) tod . out . info - > mins ;
tm . tm_hour = ( int ) tod . out . info - > hours ;
tm . tm_mday = ( int ) tod . out . info - > day ;
tm . tm_mon = ( int ) tod . out . info - > month - 1 ;
tm . tm_year = ( int ) tod . out . info - > year - 1900 ;
tm . tm_wday = - 1 ;
tm . tm_yday = - 1 ;
tm . tm_isdst = - 1 ;
r - > srvsvc . out . time = timegm ( & tm ) ;
2004-12-06 14:10:15 +03:00
r - > srvsvc . out . time_zone = tod . out . info - > timezone * 60 ;
2004-08-25 16:11:28 +04:00
goto disconnect ;
disconnect :
/* close connection */
2005-07-02 18:33:55 +04:00
talloc_free ( c . out . dcerpc_pipe ) ;
2004-08-25 16:11:28 +04:00
return status ;
}
static NTSTATUS libnet_RemoteTOD_generic ( struct libnet_context * ctx , TALLOC_CTX * mem_ctx , union libnet_RemoteTOD * r )
{
NTSTATUS status ;
union libnet_RemoteTOD r2 ;
r2 . srvsvc . level = LIBNET_REMOTE_TOD_SRVSVC ;
r2 . srvsvc . in . server_name = r - > generic . in . server_name ;
status = libnet_RemoteTOD ( ctx , mem_ctx , & r2 ) ;
r - > generic . out . time = r2 . srvsvc . out . time ;
r - > generic . out . time_zone = r2 . srvsvc . out . time_zone ;
r - > generic . out . error_string = r2 . srvsvc . out . error_string ;
return status ;
}
NTSTATUS libnet_RemoteTOD ( struct libnet_context * ctx , TALLOC_CTX * mem_ctx , union libnet_RemoteTOD * r )
{
switch ( r - > generic . level ) {
case LIBNET_REMOTE_TOD_GENERIC :
return libnet_RemoteTOD_generic ( ctx , mem_ctx , r ) ;
case LIBNET_REMOTE_TOD_SRVSVC :
return libnet_RemoteTOD_srvsvc ( ctx , mem_ctx , r ) ;
}
return NT_STATUS_INVALID_LEVEL ;
}