2022-07-14 14:44:16 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-05-09 15:43:00 +04:00
Winbind daemon for ntdom nss module
Copyright ( C ) Tim Potter 2000
2003-08-01 19:30:44 +04:00
Copyright ( C ) Jim McDonough < jmcd @ us . ibm . com > 2003
2009-08-01 00:59:30 +04:00
2000-05-09 15:43:00 +04:00
This library is free software ; you can redistribute it and / or
2007-07-10 08:04:46 +04:00
modify it under the terms of the GNU Lesser General Public
2000-05-09 15:43:00 +04:00
License as published by the Free Software Foundation ; either
2007-07-10 06:31:50 +04:00
version 3 of the License , or ( at your option ) any later version .
2009-08-01 00:59:30 +04:00
2000-05-09 15:43:00 +04:00
This library 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
Library General Public License for more details .
2009-08-01 00:59:30 +04:00
2007-07-10 08:04:46 +04:00
You should have received a copy of the GNU Lesser General Public License
2007-07-10 06:31:50 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2000-05-09 15:43:00 +04:00
*/
# ifndef _WINBINDD_H
# define _WINBINDD_H
2007-09-14 12:06:03 +04:00
# include "nsswitch/winbind_struct_protocol.h"
2008-05-13 21:58:52 +04:00
# include "nsswitch/libwbclient/wbclient.h"
2013-10-17 21:31:58 +04:00
# include "librpc/gen_ndr/dcerpc.h"
2014-05-08 04:17:32 +04:00
# include "librpc/gen_ndr/winbind.h"
2000-05-09 15:43:00 +04:00
2011-04-28 19:38:09 +04:00
# include "../lib/util/tevent_ntstatus.h"
2006-03-13 18:13:35 +03:00
# ifdef HAVE_LIBNSCD
2007-09-14 12:06:03 +04:00
# include <libnscd.h>
2006-03-13 18:13:35 +03:00
# endif
2006-05-16 18:29:39 +04:00
# ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
# endif
2002-07-15 14:35:28 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_WINBIND
2007-03-16 20:54:10 +03:00
# define WB_REPLACE_CHAR '_'
2022-04-13 12:01:00 +03:00
struct winbind_internal_pipes ;
2022-04-13 12:31:45 +03:00
struct ads_struct ;
2022-04-13 12:01:00 +03:00
2000-05-09 15:43:00 +04:00
struct winbindd_cli_state {
2003-02-28 03:25:55 +03:00
struct winbindd_cli_state * prev , * next ; /* Linked list pointers */
int sock ; /* Open socket from client */
pid_t pid ; /* pid of client */
2018-11-02 20:45:26 +03:00
char client_name [ 32 ] ; /* The process name of the client */
2003-02-28 03:25:55 +03:00
time_t last_access ; /* Time of last access (read or write) */
2007-10-19 04:40:25 +04:00
bool privileged ; /* Is the client 'privileged' */
2003-03-24 12:54:13 +03:00
2005-06-09 02:10:34 +04:00
TALLOC_CTX * mem_ctx ; /* memory per request */
2010-03-05 13:16:12 +03:00
const char * cmd_name ;
2009-07-31 18:16:24 +04:00
NTSTATUS ( * recv_fn ) ( struct tevent_req * req ,
struct winbindd_response * presp ) ;
2009-05-08 00:46:27 +04:00
struct winbindd_request * request ; /* Request from client */
2009-05-09 22:04:27 +04:00
struct tevent_queue * out_queue ;
2023-07-18 12:45:25 +03:00
struct winbindd_response * response ; /* Response to client */
2015-05-18 14:17:40 +03:00
struct tevent_req * io_req ; /* wb_req_read_* or wb_resp_write_* */
2009-08-18 01:13:48 +04:00
struct getpwent_state * pwent_state ; /* State for getpwent() */
2009-08-27 23:53:15 +04:00
struct getgrent_state * grent_state ; /* State for getgrent() */
2000-05-09 15:43:00 +04:00
} ;
2009-08-18 00:50:39 +04:00
struct getpwent_state {
struct winbindd_domain * domain ;
2016-12-29 22:05:40 +03:00
uint32_t next_user ;
struct wbint_RidArray rids ;
2009-08-18 00:50:39 +04:00
} ;
2009-08-27 23:53:15 +04:00
struct getgrent_state {
struct winbindd_domain * domain ;
2022-07-14 14:19:44 +03:00
uint32_t next_group ;
uint32_t num_groups ;
2009-08-27 23:53:15 +04:00
struct wbint_Principal * groups ;
} ;
2005-06-09 02:10:34 +04:00
/* Our connection to the DC */
struct winbindd_cm_conn {
struct cli_state * cli ;
2013-10-17 21:31:58 +04:00
enum dcerpc_AuthLevel auth_level ;
2005-06-09 02:10:34 +04:00
struct rpc_pipe_client * samr_pipe ;
2009-03-19 00:49:41 +03:00
struct policy_handle sam_connect_handle , sam_domain_handle ;
2005-06-09 02:10:34 +04:00
struct rpc_pipe_client * lsa_pipe ;
2009-09-13 01:30:39 +04:00
struct rpc_pipe_client * lsa_pipe_tcp ;
2009-03-19 00:49:41 +03:00
struct policy_handle lsa_policy ;
2005-06-09 02:10:34 +04:00
struct rpc_pipe_client * netlogon_pipe ;
2017-08-25 14:26:08 +03:00
struct netlogon_creds_cli_context * netlogon_creds_ctx ;
2013-08-07 13:32:44 +04:00
bool netlogon_force_reauth ;
2005-06-09 02:10:34 +04:00
} ;
/* Async child */
2007-10-08 16:25:57 +04:00
struct winbindd_domain ;
2005-06-09 02:10:34 +04:00
struct winbindd_child {
pid_t pid ;
struct winbindd_domain * domain ;
2007-12-04 04:57:46 +03:00
char * logfilename ;
2005-06-09 02:10:34 +04:00
2009-05-10 12:49:53 +04:00
int sock ;
2018-02-26 17:12:14 +03:00
struct tevent_fd * monitor_fde ; /* Watch for dead children/sockets */
2009-05-10 12:49:53 +04:00
struct tevent_queue * queue ;
2010-08-12 17:12:11 +04:00
struct dcerpc_binding_handle * binding_handle ;
2009-05-10 12:49:53 +04:00
2013-02-18 13:17:40 +04:00
struct tevent_timer * lockout_policy_event ;
struct tevent_timer * machine_password_change_event ;
2005-06-09 02:10:34 +04:00
} ;
2002-01-11 08:33:45 +03:00
/* Structures to hold per domain information */
struct winbindd_domain {
2013-02-18 19:36:22 +04:00
char * name ; /* Domain name (NetBIOS) */
char * alt_name ; /* alt Domain name, if any (FQDN for ADS) */
char * forest_name ; /* Name of the AD forest we're in */
2010-05-21 05:25:01 +04:00
struct dom_sid sid ; /* SID for this domain */
2017-11-29 17:10:38 +03:00
enum netr_SchannelType secure_channel_type ;
2015-04-24 05:04:23 +03:00
uint32_t domain_flags ; /* Domain flags from netlogon.h */
uint32_t domain_type ; /* Domain type from netlogon.h */
uint32_t domain_trust_attribs ; /* Trust attribs from netlogon.h */
2018-01-15 14:03:11 +03:00
struct winbindd_domain * routing_domain ;
2007-10-19 04:40:25 +04:00
bool initialized ; /* Did we already ask for the domain mode? */
bool active_directory ; /* is this a win2k active directory ? */
bool primary ; /* is this our primary domain ? */
bool internal ; /* BUILTIN and member SAM */
2014-05-26 03:58:38 +04:00
bool rodc ; /* Are we an RODC for this AD domain? (do some operations locally) */
2007-10-19 04:40:25 +04:00
bool online ; /* is this domain available ? */
2010-09-10 23:36:20 +04:00
time_t startup_time ; /* When we set "startup" true. monotonic clock */
2007-10-19 04:40:25 +04:00
bool startup ; /* are we in the first 30 seconds after startup_time ? */
2002-01-11 08:33:45 +03:00
2009-09-17 11:43:36 +04:00
bool can_do_ncacn_ip_tcp ;
2016-10-08 02:40:22 +03:00
/*
* Lookup methods for this domain ( LDAP or RPC ) . The backend
* methods are used by the cache layer .
*/
2003-06-10 07:50:38 +04:00
struct winbindd_methods * backend ;
2022-04-13 12:01:00 +03:00
struct {
struct winbind_internal_pipes * samr_pipes ;
2022-04-13 12:31:45 +03:00
struct ads_struct * ads_conn ;
2022-04-13 12:01:00 +03:00
} backend_data ;
2004-11-18 14:57:49 +03:00
/* A working DC */
2022-11-22 16:23:21 +03:00
bool force_dc ;
2013-02-18 19:36:22 +04:00
char * dcname ;
2020-09-17 12:12:53 +03:00
const char * ping_dcname ;
2007-10-25 01:16:54 +04:00
struct sockaddr_storage dcaddr ;
2004-11-18 14:57:49 +03:00
2002-01-11 08:33:45 +03:00
/* Sequence number stuff */
time_t last_seq_check ;
2015-04-24 05:04:23 +03:00
uint32_t sequence_number ;
2003-06-21 08:05:01 +04:00
NTSTATUS last_status ;
2002-01-11 08:33:45 +03:00
2005-06-09 02:10:34 +04:00
/* The smb connection */
struct winbindd_cm_conn conn ;
/* The child pid we're talking to */
2010-04-07 19:45:12 +04:00
struct winbindd_child * children ;
2005-06-09 02:10:34 +04:00
2018-02-14 17:04:01 +03:00
struct tevent_queue * queue ;
2018-02-13 18:04:44 +03:00
struct dcerpc_binding_handle * binding_handle ;
2020-09-17 12:12:53 +03:00
struct tevent_req * check_online_event ;
2006-09-07 01:43:31 +04:00
2002-01-11 08:33:45 +03:00
/* Linked list info */
struct winbindd_domain * prev , * next ;
} ;
2020-09-11 13:16:00 +03:00
struct wb_parent_idmap_config_dom {
unsigned low_id ;
unsigned high_id ;
const char * name ;
struct dom_sid sid ;
} ;
struct wb_parent_idmap_config {
struct tevent_queue * queue ;
uint32_t num_doms ;
2022-06-21 19:19:16 +03:00
bool initialized ;
2020-09-11 13:16:00 +03:00
struct wb_parent_idmap_config_dom * doms ;
} ;
2011-03-22 19:43:39 +03:00
struct wb_acct_info {
2018-10-30 20:47:16 +03:00
const char * acct_name ; /* account name */
const char * acct_desc ; /* account name */
2011-03-22 19:43:39 +03:00
uint32_t rid ; /* domain-relative RID */
} ;
2001-12-01 15:31:43 +03:00
/* per-domain methods. This is how LDAP vs RPC is selected
*/
struct winbindd_methods {
2001-12-10 09:05:21 +03:00
/* does this backend provide a consistent view of the data? (ie. is the primary group
always correct ) */
2007-10-19 04:40:25 +04:00
bool consistent ;
2001-12-10 09:05:21 +03:00
2009-08-09 15:31:31 +04:00
/* get a list of users, returning a wbint_userinfo for each one */
2001-12-03 14:32:55 +03:00
NTSTATUS ( * query_user_list ) ( struct winbindd_domain * domain ,
2001-12-01 15:31:43 +03:00
TALLOC_CTX * mem_ctx ,
2017-01-03 15:11:30 +03:00
uint32_t * * rids ) ;
2001-12-01 15:31:43 +03:00
2002-10-08 22:32:42 +04:00
/* get a list of domain groups */
2001-12-03 04:23:42 +03:00
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 ) ;
2001-12-03 11:17:46 +03:00
2002-10-08 22:32:42 +04:00
/* get a list of domain local groups */
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 ) ;
2009-08-01 00:59:30 +04:00
2001-12-05 07:48:51 +03:00
/* convert one user or group name to a sid */
2001-12-03 11:17:46 +03:00
NTSTATUS ( * name_to_sid ) ( struct winbindd_domain * domain ,
2003-04-23 15:54:56 +04:00
TALLOC_CTX * mem_ctx ,
2004-04-20 06:37:49 +04:00
const char * domain_name ,
2001-12-03 11:17:46 +03:00
const char * name ,
2009-08-02 12:43:05 +04:00
uint32_t flags ,
2019-03-12 02:11:01 +03:00
const char * * pdom_name ,
2010-05-21 05:25:01 +04:00
struct dom_sid * sid ,
2006-09-08 18:28:06 +04:00
enum lsa_SidType * type ) ;
2001-12-03 14:11:14 +03:00
2001-12-05 07:48:51 +03:00
/* convert a sid to a user or group name */
2001-12-03 14:11:14 +03:00
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 ,
2004-04-20 06:37:49 +04:00
char * * domain_name ,
2001-12-03 14:11:14 +03:00
char * * name ,
2006-09-08 18:28:06 +04:00
enum lsa_SidType * type ) ;
2001-12-04 09:17:39 +03:00
2006-07-11 22:01:26 +04:00
NTSTATUS ( * rids_to_names ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_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
2017-03-02 16:53:47 +03:00
/* lookup all groups that a user is a member of. The backend
can also choose to lookup by username or rid for this
function */
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 ) ;
2005-01-15 22:00:18 +03:00
/* Lookup all aliases that the sids delivered are member of. This is
* to implement ' domain local groups ' correctly */
NTSTATUS ( * lookup_useraliases ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2015-04-24 05:04:23 +03:00
uint32_t num_sids ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * sids ,
2015-04-24 05:04:23 +03:00
uint32_t * num_aliases ,
uint32_t * * alias_rids ) ;
2005-01-15 22:00:18 +03:00
2001-12-05 07:48:51 +03:00
/* find all members of the group with the specified group_rid */
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 ) ;
2001-12-05 10:52:44 +03:00
2023-03-08 10:40:58 +03:00
/* find all members of the alias with the specified alias_sid */
NTSTATUS ( * lookup_aliasmem ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
const struct dom_sid * alias_sid ,
enum lsa_SidType type ,
uint32_t * num_sids ,
struct dom_sid * * sid_mem ) ;
2006-02-04 01:19:41 +03:00
/* return the lockout policy */
2008-02-05 19:25:07 +03:00
NTSTATUS ( * lockout_policy ) ( struct winbindd_domain * domain ,
2006-02-04 01:19:41 +03:00
TALLOC_CTX * mem_ctx ,
2008-02-05 19:25:07 +03:00
struct samr_DomInfo12 * lockout_policy ) ;
2006-02-04 01:19:41 +03:00
/* return the lockout policy */
2008-02-05 19:25:07 +03:00
NTSTATUS ( * password_policy ) ( struct winbindd_domain * domain ,
2006-02-04 01:19:41 +03:00
TALLOC_CTX * mem_ctx ,
2008-02-05 19:25:07 +03:00
struct samr_DomInfo1 * password_policy ) ;
2001-12-10 05:25:19 +03:00
/* enumerate trusted domains */
NTSTATUS ( * trusted_domains ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2009-12-28 17:51:36 +03:00
struct netr_DomainTrustList * trusts ) ;
2001-12-01 15:31:43 +03:00
} ;
2003-04-23 15:54:56 +04:00
/* Filled out by IDMAP backends */
struct winbindd_idmap_methods {
/* Called when backend is first loaded */
2007-10-19 04:40:25 +04:00
bool ( * init ) ( void ) ;
2003-04-23 15:54:56 +04:00
2010-05-21 05:25:01 +04:00
bool ( * get_sid_from_uid ) ( uid_t uid , struct dom_sid * sid ) ;
bool ( * get_sid_from_gid ) ( gid_t gid , struct dom_sid * sid ) ;
2003-04-23 15:54:56 +04:00
2010-05-21 05:25:01 +04:00
bool ( * get_uid_from_sid ) ( struct dom_sid * sid , uid_t * uid ) ;
bool ( * get_gid_from_sid ) ( struct dom_sid * sid , gid_t * gid ) ;
2003-04-23 15:54:56 +04:00
/* Called when backend is unloaded */
2007-10-19 04:40:25 +04:00
bool ( * close ) ( void ) ;
2003-04-23 15:54:56 +04:00
/* Called to dump backend status */
void ( * status ) ( void ) ;
} ;
2007-05-06 22:39:31 +04:00
/* Data structures for dealing with the trusted domain cache */
struct winbindd_tdc_domain {
const char * domain_name ;
const char * dns_name ;
2010-05-21 05:25:01 +04:00
struct dom_sid sid ;
2015-04-24 05:04:23 +03:00
uint32_t trust_flags ;
uint32_t trust_attribs ;
uint32_t trust_type ;
2007-05-06 22:39:31 +04:00
} ;
2008-12-30 11:32:31 +03:00
struct WINBINDD_MEMORY_CREDS {
struct WINBINDD_MEMORY_CREDS * next , * prev ;
const char * username ; /* lookup key. */
uid_t uid ;
int ref_count ;
size_t len ;
uint8_t * nt_hash ; /* Base pointer for the following 2 */
uint8_t * lm_hash ;
char * pass ;
} ;
struct WINBINDD_CCACHE_ENTRY {
struct WINBINDD_CCACHE_ENTRY * next , * prev ;
const char * principal_name ;
const char * ccname ;
const char * service ;
const char * username ;
const char * realm ;
2022-02-22 15:19:02 +03:00
const char * canon_principal ;
const char * canon_realm ;
2008-12-30 11:32:31 +03:00
struct WINBINDD_MEMORY_CREDS * cred_ptr ;
int ref_count ;
uid_t uid ;
time_t create_time ;
time_t renew_until ;
time_t refresh_time ;
2013-02-18 13:17:40 +04:00
struct tevent_timer * event ;
2008-12-30 11:32:31 +03:00
} ;
2007-09-14 16:03:58 +04:00
# include "winbindd/winbindd_proto.h"
2000-05-09 15:43:00 +04:00
# define WINBINDD_ESTABLISH_LOOP 30
2007-05-06 23:17:30 +04:00
# define WINBINDD_RESCAN_FREQ lp_winbind_cache_time()
2006-02-04 01:19:41 +03:00
# define WINBINDD_PAM_AUTH_KRB5_RENEW_TIME 2592000 /* one month */
2015-05-03 07:07:06 +03:00
# define DOM_SEQUENCE_NONE ((uint32_t)-1)
2000-05-09 15:43:00 +04:00
# endif /* _WINBINDD_H */