2006-11-07 00:16:27 +03:00
/*
Unix SMB / CIFS implementation .
Copyright ( C ) Rafal Szczesniak 2006
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 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2006-11-07 00:16:27 +03:00
( 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
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-11-07 00:16:27 +03:00
*/
# include "includes.h"
# include "libnet/libnet.h"
# include "libcli/composite/composite.h"
# include "auth/credentials/credentials.h"
# include "librpc/ndr/libndr.h"
# include "librpc/gen_ndr/samr.h"
# include "librpc/gen_ndr/ndr_samr.h"
# include "librpc/gen_ndr/lsa.h"
# include "librpc/gen_ndr/ndr_lsa.h"
2012-04-30 13:57:45 +04:00
bool samr_domain_opened ( struct libnet_context * ctx , TALLOC_CTX * mem_ctx ,
const char * domain_name ,
2006-12-11 02:43:32 +03:00
struct composite_context * * parent_ctx ,
struct libnet_DomainOpen * domain_open ,
void ( * continue_fn ) ( struct composite_context * ) ,
void ( * monitor ) ( struct monitor_msg * ) )
2006-11-07 00:16:27 +03:00
{
struct composite_context * domopen_req ;
2007-10-07 02:28:14 +04:00
if ( parent_ctx = = NULL | | * parent_ctx = = NULL ) return false ;
2006-12-11 02:43:32 +03:00
2006-11-07 00:16:27 +03:00
if ( domain_name = = NULL ) {
/*
* Try to guess the domain name from credentials ,
* if it ' s not been explicitly specified .
*/
2012-03-18 20:44:24 +04:00
if ( ndr_policy_handle_empty ( & ctx - > samr . handle ) ) {
2006-11-07 00:16:27 +03:00
domain_open - > in . type = DOMAIN_SAMR ;
domain_open - > in . domain_name = cli_credentials_get_domain ( ctx - > cred ) ;
domain_open - > in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
} else {
2006-12-11 02:43:32 +03:00
composite_error ( * parent_ctx , NT_STATUS_INVALID_PARAMETER ) ;
2007-10-07 02:28:14 +04:00
return true ;
2006-11-07 00:16:27 +03:00
}
} else {
/*
* The domain name has been specified , so check whether the same
* domain is already opened . If it is - just return NULL . Start
* opening a new domain otherwise .
*/
2012-03-18 20:44:24 +04:00
if ( ndr_policy_handle_empty ( & ctx - > samr . handle ) | |
2006-11-07 00:16:27 +03:00
! strequal ( domain_name , ctx - > samr . name ) ) {
domain_open - > in . type = DOMAIN_SAMR ;
domain_open - > in . domain_name = domain_name ;
domain_open - > in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
} else {
/* domain has already been opened and it's the same domain
as requested */
2007-10-07 02:28:14 +04:00
return true ;
2006-11-07 00:16:27 +03:00
}
}
/* send request to open the domain */
2012-04-30 13:57:45 +04:00
domopen_req = libnet_DomainOpen_send ( ctx , mem_ctx , domain_open , monitor ) ;
2007-10-07 02:28:14 +04:00
if ( composite_nomem ( domopen_req , * parent_ctx ) ) return false ;
2006-11-07 00:16:27 +03:00
2006-12-11 02:43:32 +03:00
composite_continue ( * parent_ctx , domopen_req , continue_fn , * parent_ctx ) ;
2007-10-07 02:28:14 +04:00
return false ;
2006-11-07 00:16:27 +03:00
}
2012-04-30 13:57:45 +04:00
bool lsa_domain_opened ( struct libnet_context * ctx , TALLOC_CTX * mem_ctx ,
const char * domain_name ,
2006-12-11 02:43:32 +03:00
struct composite_context * * parent_ctx ,
struct libnet_DomainOpen * domain_open ,
void ( * continue_fn ) ( struct composite_context * ) ,
void ( * monitor ) ( struct monitor_msg * ) )
2006-11-07 00:16:27 +03:00
{
struct composite_context * domopen_req ;
2006-12-11 02:43:32 +03:00
2007-10-07 02:28:14 +04:00
if ( parent_ctx = = NULL | | * parent_ctx = = NULL ) return false ;
2006-11-07 00:16:27 +03:00
if ( domain_name = = NULL ) {
/*
* Try to guess the domain name from credentials ,
* if it ' s not been explicitly specified .
*/
2012-03-18 20:44:24 +04:00
if ( ndr_policy_handle_empty ( & ctx - > lsa . handle ) ) {
2006-11-07 00:16:27 +03:00
domain_open - > in . type = DOMAIN_LSA ;
domain_open - > in . domain_name = cli_credentials_get_domain ( ctx - > cred ) ;
domain_open - > in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
} else {
2006-12-11 02:43:32 +03:00
composite_error ( * parent_ctx , NT_STATUS_INVALID_PARAMETER ) ;
/* this ensures the calling function exits and composite function error
gets noticed quickly */
2007-10-07 02:28:14 +04:00
return true ;
2006-11-07 00:16:27 +03:00
}
} else {
/*
* The domain name has been specified , so check whether the same
* domain is already opened . If it is - just return NULL . Start
* opening a new domain otherwise .
*/
2012-03-18 20:44:24 +04:00
if ( ndr_policy_handle_empty ( & ctx - > lsa . handle ) | |
2006-11-07 00:16:27 +03:00
! strequal ( domain_name , ctx - > lsa . name ) ) {
domain_open - > in . type = DOMAIN_LSA ;
domain_open - > in . domain_name = domain_name ;
domain_open - > in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
} else {
/* domain has already been opened and it's the same domain
as requested */
2007-10-07 02:28:14 +04:00
return true ;
2006-11-07 00:16:27 +03:00
}
}
/* send request to open the domain */
2012-04-30 13:57:45 +04:00
domopen_req = libnet_DomainOpen_send ( ctx , mem_ctx , domain_open , monitor ) ;
2006-12-11 02:43:32 +03:00
/* see the comment above to find out why true is returned here */
2007-10-07 02:28:14 +04:00
if ( composite_nomem ( domopen_req , * parent_ctx ) ) return true ;
2006-11-07 00:16:27 +03:00
2006-12-11 02:43:32 +03:00
composite_continue ( * parent_ctx , domopen_req , continue_fn , * parent_ctx ) ;
2007-10-07 02:28:14 +04:00
return false ;
2006-11-07 00:16:27 +03:00
}