2005-06-09 02:10:34 +04:00
/*
Unix SMB / CIFS implementation .
Wrapper around winbindd_rpc . c to centralize retry logic .
Copyright ( C ) Volker Lendecke 2005
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
2005-06-09 02:10:34 +04: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 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-06-09 02:10:34 +04:00
*/
# include "includes.h"
# include "winbindd.h"
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_WINBIND
extern struct winbindd_methods msrpc_methods ;
2016-01-06 00:37:30 +03:00
bool reconnect_need_retry ( NTSTATUS status , struct winbindd_domain * domain )
2010-03-29 18:31:13 +04:00
{
if ( NT_STATUS_IS_OK ( status ) ) {
return false ;
}
if ( ! NT_STATUS_IS_ERR ( status ) ) {
return false ;
}
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NONE_MAPPED ) ) {
return false ;
}
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NO_SUCH_USER ) ) {
return false ;
}
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NO_SUCH_GROUP ) ) {
return false ;
}
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NO_SUCH_ALIAS ) ) {
return false ;
}
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NO_SUCH_MEMBER ) ) {
return false ;
}
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NO_SUCH_DOMAIN ) ) {
return false ;
}
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NO_SUCH_PRIVILEGE ) ) {
return false ;
}
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NO_MEMORY ) ) {
return false ;
}
2018-03-12 14:20:04 +03:00
reset_cm_connection_on_error ( domain , status ) ;
2016-01-05 23:39:25 +03:00
2010-03-29 18:31:13 +04:00
return true ;
}
2005-06-09 02:10:34 +04:00
/* List all users */
static NTSTATUS query_user_list ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2017-01-03 15:11:30 +03:00
uint32_t * * rids )
2005-06-09 02:10:34 +04:00
{
NTSTATUS result ;
2017-01-03 15:11:30 +03:00
result = msrpc_methods . query_user_list ( domain , mem_ctx , rids ) ;
2005-06-09 02:10:34 +04:00
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2017-01-03 15:11:30 +03:00
result = msrpc_methods . query_user_list ( domain , mem_ctx , rids ) ;
2005-06-09 02:10:34 +04:00
return result ;
}
/* list all domain groups */
static NTSTATUS enum_dom_groups ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2015-04-24 05:04:23 +03:00
uint32_t * num_entries ,
2011-03-22 19:43:39 +03:00
struct wb_acct_info * * info )
2005-06-09 02:10:34 +04:00
{
NTSTATUS result ;
result = msrpc_methods . enum_dom_groups ( domain , mem_ctx ,
num_entries , info ) ;
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2005-06-09 02:10:34 +04:00
result = msrpc_methods . enum_dom_groups ( domain , mem_ctx ,
num_entries , info ) ;
return result ;
}
/* List all domain groups */
static NTSTATUS enum_local_groups ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2015-04-24 05:04:23 +03:00
uint32_t * num_entries ,
2011-03-22 19:43:39 +03:00
struct wb_acct_info * * info )
2005-06-09 02:10:34 +04:00
{
NTSTATUS result ;
result = msrpc_methods . enum_local_groups ( domain , mem_ctx ,
num_entries , info ) ;
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2005-06-09 02:10:34 +04:00
result = msrpc_methods . enum_local_groups ( domain , mem_ctx ,
num_entries , info ) ;
return result ;
}
/* convert a single name to a sid in a domain */
static NTSTATUS name_to_sid ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
const char * domain_name ,
const char * name ,
2009-08-02 12:43:05 +04:00
uint32_t flags ,
2010-05-21 05:25:01 +04:00
struct dom_sid * sid ,
2006-09-08 18:28:06 +04:00
enum lsa_SidType * type )
2005-06-09 02:10:34 +04:00
{
NTSTATUS result ;
2009-08-02 12:43:05 +04:00
result = msrpc_methods . name_to_sid ( domain , mem_ctx , domain_name , name ,
flags , sid , type ) ;
2005-06-09 02:10:34 +04:00
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2009-08-02 12:43:05 +04:00
result = msrpc_methods . name_to_sid ( domain , mem_ctx ,
domain_name , name , flags ,
2005-06-09 02:10:34 +04:00
sid , type ) ;
return result ;
}
/*
convert a domain SID to a user or group name
*/
static NTSTATUS sid_to_name ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * sid ,
2005-06-09 02:10:34 +04:00
char * * domain_name ,
char * * name ,
2006-09-08 18:28:06 +04:00
enum lsa_SidType * type )
2005-06-09 02:10:34 +04:00
{
NTSTATUS result ;
result = msrpc_methods . sid_to_name ( domain , mem_ctx , sid ,
domain_name , name , type ) ;
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2005-06-09 02:10:34 +04:00
result = msrpc_methods . sid_to_name ( domain , mem_ctx , sid ,
domain_name , name , type ) ;
return result ;
}
2006-07-11 22:01:26 +04:00
static NTSTATUS rids_to_names ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * sid ,
2015-04-24 05:04:23 +03:00
uint32_t * rids ,
2006-07-11 22:01:26 +04:00
size_t num_rids ,
char * * domain_name ,
char * * * names ,
2006-09-08 18:28:06 +04:00
enum lsa_SidType * * types )
2006-07-11 22:01:26 +04:00
{
NTSTATUS result ;
result = msrpc_methods . rids_to_names ( domain , mem_ctx , sid ,
rids , num_rids ,
domain_name , names , types ) ;
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) ) {
2006-07-11 22:01:26 +04:00
result = msrpc_methods . rids_to_names ( domain , mem_ctx , sid ,
rids , num_rids ,
domain_name , names ,
types ) ;
}
return result ;
}
2017-03-02 16:53:47 +03:00
/* Lookup groups a user is a member of. I wish Unix had a call like this! */
static NTSTATUS lookup_usergroups ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
const struct dom_sid * user_sid ,
uint32_t * num_groups , struct dom_sid * * user_gids )
{
NTSTATUS result ;
result = msrpc_methods . lookup_usergroups ( domain , mem_ctx ,
user_sid , num_groups ,
user_gids ) ;
if ( reconnect_need_retry ( result , domain ) )
result = msrpc_methods . lookup_usergroups ( domain , mem_ctx ,
user_sid , num_groups ,
user_gids ) ;
return result ;
}
2005-06-09 02:10:34 +04:00
static NTSTATUS lookup_useraliases ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2015-04-24 05:04:23 +03:00
uint32_t num_sids , const struct dom_sid * sids ,
uint32_t * num_aliases , uint32_t * * alias_rids )
2005-06-09 02:10:34 +04:00
{
NTSTATUS result ;
result = msrpc_methods . lookup_useraliases ( domain , mem_ctx ,
num_sids , sids ,
num_aliases ,
alias_rids ) ;
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2005-06-09 02:10:34 +04:00
result = msrpc_methods . lookup_useraliases ( domain , mem_ctx ,
num_sids , sids ,
num_aliases ,
alias_rids ) ;
return result ;
}
/* Lookup group membership given a rid. */
static NTSTATUS lookup_groupmem ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * group_sid ,
2009-08-28 16:25:11 +04:00
enum lsa_SidType type ,
2015-04-24 05:04:23 +03:00
uint32_t * num_names ,
2010-05-21 05:25:01 +04:00
struct dom_sid * * sid_mem , char * * * names ,
2015-04-24 05:04:23 +03:00
uint32_t * * name_types )
2005-06-09 02:10:34 +04:00
{
NTSTATUS result ;
result = msrpc_methods . lookup_groupmem ( domain , mem_ctx ,
2009-08-28 16:25:11 +04:00
group_sid , type , num_names ,
2005-06-09 02:10:34 +04:00
sid_mem , names ,
name_types ) ;
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2005-06-09 02:10:34 +04:00
result = msrpc_methods . lookup_groupmem ( domain , mem_ctx ,
2009-08-28 16:25:11 +04:00
group_sid , type ,
num_names ,
2005-06-09 02:10:34 +04:00
sid_mem , names ,
name_types ) ;
return result ;
}
/* find the sequence number for a domain */
2015-04-24 05:04:23 +03:00
static NTSTATUS sequence_number ( struct winbindd_domain * domain , uint32_t * seq )
2005-06-09 02:10:34 +04:00
{
NTSTATUS result ;
result = msrpc_methods . sequence_number ( domain , seq ) ;
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2005-06-09 02:10:34 +04:00
result = msrpc_methods . sequence_number ( domain , seq ) ;
return result ;
}
2006-02-04 01:19:41 +03:00
/* find the lockout policy of a domain */
static NTSTATUS lockout_policy ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2008-02-05 19:25:07 +03:00
struct samr_DomInfo12 * policy )
2006-02-04 01:19:41 +03:00
{
NTSTATUS result ;
2006-04-19 17:14:14 +04:00
result = msrpc_methods . lockout_policy ( domain , mem_ctx , policy ) ;
2006-02-04 01:19:41 +03:00
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2006-04-19 17:14:14 +04:00
result = msrpc_methods . lockout_policy ( domain , mem_ctx , policy ) ;
2006-02-04 01:19:41 +03:00
return result ;
}
/* find the password policy of a domain */
static NTSTATUS password_policy ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2008-02-05 19:25:07 +03:00
struct samr_DomInfo1 * policy )
2006-02-04 01:19:41 +03:00
{
NTSTATUS result ;
2006-04-19 17:14:14 +04:00
result = msrpc_methods . password_policy ( domain , mem_ctx , policy ) ;
2006-02-04 01:19:41 +03:00
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2006-04-19 17:14:14 +04:00
result = msrpc_methods . password_policy ( domain , mem_ctx , policy ) ;
2006-02-04 01:19:41 +03:00
return result ;
}
2005-06-09 02:10:34 +04:00
/* get a list of trusted domains */
static NTSTATUS trusted_domains ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2009-12-28 17:51:36 +03:00
struct netr_DomainTrustList * trusts )
2005-06-09 02:10:34 +04:00
{
NTSTATUS result ;
2009-12-28 17:51:36 +03:00
result = msrpc_methods . trusted_domains ( domain , mem_ctx , trusts ) ;
2005-06-09 02:10:34 +04:00
2016-01-05 23:39:25 +03:00
if ( reconnect_need_retry ( result , domain ) )
2005-06-09 02:10:34 +04:00
result = msrpc_methods . trusted_domains ( domain , mem_ctx ,
2009-12-28 17:51:36 +03:00
trusts ) ;
2005-06-09 02:10:34 +04:00
return result ;
}
/* the rpc backend methods are exposed via this structure */
struct winbindd_methods reconnect_methods = {
False ,
query_user_list ,
enum_dom_groups ,
enum_local_groups ,
name_to_sid ,
sid_to_name ,
2006-07-11 22:01:26 +04:00
rids_to_names ,
2017-03-02 16:53:47 +03:00
lookup_usergroups ,
2005-06-09 02:10:34 +04:00
lookup_useraliases ,
lookup_groupmem ,
sequence_number ,
2006-02-04 01:19:41 +03:00
lockout_policy ,
password_policy ,
2005-06-09 02:10:34 +04:00
trusted_domains ,
} ;