/*
Unix SMB / CIFS implementation .
Winbind daemon for ntdom nss module
Copyright ( C ) Tim Potter 2000
Copyright ( C ) Jim McDonough < jmcd @ us . ibm . com > 2003
This library is free software ; you can redistribute it and / or
2007-07-10 04:04:46 +00:00
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation ; either
2007-07-10 02:31:50 +00:00
version 3 of the License , or ( at your option ) any later version .
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 .
2007-07-10 04:04:46 +00:00
You should have received a copy of the GNU Lesser General Public License
2007-07-10 02:31:50 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef _WINBINDD_H
# define _WINBINDD_H
# include "nterr.h"
# include "winbindd_nss.h"
2006-03-13 15:13:35 +00:00
# ifdef HAVE_LIBNSCD
# include "libnscd.h"
# endif
2006-05-16 14:29:39 +00:00
# ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
# endif
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_WINBIND
2007-03-16 17:54:10 +00:00
# define WB_REPLACE_CHAR '_'
2005-06-08 22:10:34 +00:00
/* bits for fd_event.flags */
# define EVENT_FD_READ 1
# define EVENT_FD_WRITE 2
struct fd_event {
struct fd_event * next , * prev ;
int fd ;
int flags ; /* see EVENT_FD_* flags */
void ( * handler ) ( struct fd_event * fde , int flags ) ;
void * data ;
size_t length , done ;
2005-06-24 20:25:18 +00:00
void ( * finished ) ( void * private_data , BOOL success ) ;
void * private_data ;
2005-06-08 22:10:34 +00:00
} ;
2005-09-30 17:13:37 +00:00
struct sid_ctr {
DOM_SID * sid ;
BOOL finished ;
const char * domain ;
const char * name ;
2006-09-08 14:28:06 +00:00
enum lsa_SidType type ;
2005-09-30 17:13:37 +00:00
} ;
struct winbindd_cli_state {
struct winbindd_cli_state * prev , * next ; /* Linked list pointers */
int sock ; /* Open socket from client */
2005-06-08 22:10:34 +00:00
struct fd_event fd_event ;
pid_t pid ; /* pid of client */
BOOL finished ; /* Can delete from list */
BOOL write_extra_data ; /* Write extra_data field */
time_t last_access ; /* Time of last access (read or write) */
BOOL privileged ; /* Is the client 'privileged' */
2005-06-08 22:10:34 +00:00
TALLOC_CTX * mem_ctx ; /* memory per request */
struct winbindd_request request ; /* Request from client */
struct winbindd_response response ; /* Respose to client */
2005-06-08 22:10:34 +00:00
BOOL getpwent_initialized ; /* Has getpwent_state been
* initialized ? */
BOOL getgrent_initialized ; /* Has getgrent_state been
* initialized ? */
struct getent_state * getpwent_state ; /* State for getpwent() */
struct getent_state * getgrent_state ; /* State for getgrent() */
} ;
/* State between get{pw,gr}ent() calls */
struct getent_state {
struct getent_state * prev , * next ;
void * sam_entries ;
uint32 sam_entry_index , num_sam_entries ;
BOOL got_sam_entries ;
fstring domain_name ;
} ;
/* Storage for cached getpwent() user entries */
struct getpwent_user {
fstring name ; /* Account name */
fstring gecos ; /* User information */
2005-06-29 14:03:53 +00:00
fstring homedir ; /* User Home Directory */
fstring shell ; /* User Login Shell */
DOM_SID user_sid ; /* NT user and primary group SIDs */
DOM_SID group_sid ;
} ;
/* Server state structure */
typedef struct {
char * acct_name ;
char * full_name ;
2005-06-29 14:03:53 +00:00
char * homedir ;
char * shell ;
2007-01-24 01:48:08 +00:00
gid_t primary_gid ; /* allow the nss_info
backend to set the primary group */
2005-06-08 22:10:34 +00:00
DOM_SID user_sid ; /* NT user and primary group SIDs */
DOM_SID group_sid ;
} WINBIND_USERINFO ;
2005-06-08 22:10:34 +00:00
/* Our connection to the DC */
struct winbindd_cm_conn {
struct cli_state * cli ;
struct rpc_pipe_client * samr_pipe ;
POLICY_HND sam_connect_handle , sam_domain_handle ;
struct rpc_pipe_client * lsa_pipe ;
POLICY_HND lsa_policy ;
struct rpc_pipe_client * netlogon_pipe ;
} ;
struct winbindd_async_request ;
/* Async child */
struct winbindd_child {
struct winbindd_child * next , * prev ;
pid_t pid ;
struct winbindd_domain * domain ;
pstring logfilename ;
struct fd_event event ;
2006-03-17 10:14:33 +00:00
struct timed_event * lockout_policy_event ;
2005-06-08 22:10:34 +00:00
struct winbindd_async_request * requests ;
} ;
/* Structures to hold per domain information */
struct winbindd_domain {
2007-05-06 21:15:45 +00:00
fstring name ; /* Domain name (NetBIOS) */
fstring alt_name ; /* alt Domain name, if any (FQDN for ADS) */
2007-01-02 21:48:47 +00:00
fstring forest_name ; /* Name of the AD forest we're in */
DOM_SID sid ; /* SID for this domain */
2007-05-06 18:39:31 +00:00
uint32 domain_flags ; /* Domain flags from rpc_ds.h */
uint32 domain_type ; /* Domain type from rpc_ds.h */
uint32 domain_trust_attribs ; /* Trust attribs from rpc_ds.h */
2004-04-20 02:37:49 +00:00
BOOL initialized ; /* Did we already ask for the domain mode? */
BOOL native_mode ; /* is this a win2k domain in native mode ? */
BOOL active_directory ; /* is this a win2k active directory ? */
BOOL primary ; /* is this our primary domain ? */
2006-02-03 22:19:41 +00:00
BOOL internal ; /* BUILTIN and member SAM */
BOOL online ; /* is this domain available ? */
2006-09-28 18:08:03 +00:00
time_t startup_time ; /* When we set "startup" true. */
BOOL startup ; /* are we in the first 30 seconds after startup_time ? */
2007-05-29 19:31:57 +00:00
BOOL can_do_samlogon_ex ; /* Due to the lack of finer control what type
* of DC we have , let us try to do a
* credential - chain less samlogon_ex call
* with AD and schannel . If this fails with
* DCERPC_FAULT_OP_RNG_ERROR , then set this
* to False . This variable is around so that
* we don ' t have to try _ex every time . */
/* Lookup methods for this domain (LDAP or RPC) */
struct winbindd_methods * methods ;
/* the backend methods are used by the cache layer to find the right
backend */
struct winbindd_methods * backend ;
/* Private data for the backends (used for connection cache) */
2005-06-24 20:25:18 +00:00
void * private_data ;
2004-11-18 11:57:49 +00:00
/* A working DC */
fstring dcname ;
struct sockaddr_in dcaddr ;
/* Sequence number stuff */
time_t last_seq_check ;
uint32 sequence_number ;
NTSTATUS last_status ;
2005-06-08 22:10:34 +00:00
/* The smb connection */
struct winbindd_cm_conn conn ;
/* The child pid we're talking to */
struct winbindd_child child ;
2006-09-06 21:43:31 +00:00
/* Callback we use to try put us back online. */
2006-12-06 23:14:15 +00:00
uint32 check_online_timeout ;
2006-09-06 21:43:31 +00:00
struct timed_event * check_online_event ;
/* Linked list info */
struct winbindd_domain * prev , * next ;
} ;
/* per-domain methods. This is how LDAP vs RPC is selected
*/
struct winbindd_methods {
/* does this backend provide a consistent view of the data? (ie. is the primary group
always correct ) */
BOOL consistent ;
/* get a list of users, returning a WINBIND_USERINFO for each one */
NTSTATUS ( * query_user_list ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
uint32 * num_entries ,
WINBIND_USERINFO * * info ) ;
/* get a list of domain groups */
NTSTATUS ( * enum_dom_groups ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
uint32 * num_entries ,
struct acct_info * * info ) ;
/* get a list of domain local groups */
NTSTATUS ( * enum_local_groups ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
uint32 * num_entries ,
struct acct_info * * info ) ;
/* convert one user or group name to a sid */
NTSTATUS ( * name_to_sid ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2007-05-30 19:47:35 +00:00
enum winbindd_cmd orig_cmd ,
2004-04-20 02:37:49 +00:00
const char * domain_name ,
const char * name ,
DOM_SID * sid ,
2006-09-08 14:28:06 +00:00
enum lsa_SidType * type ) ;
/* convert a sid to a user or group name */
NTSTATUS ( * sid_to_name ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
const DOM_SID * sid ,
2004-04-20 02:37:49 +00:00
char * * domain_name ,
char * * name ,
2006-09-08 14:28:06 +00:00
enum lsa_SidType * type ) ;
2006-07-11 18:01:26 +00:00
NTSTATUS ( * rids_to_names ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
const DOM_SID * domain_sid ,
uint32 * rids ,
size_t num_rids ,
char * * domain_name ,
char * * * names ,
2006-09-08 14:28:06 +00:00
enum lsa_SidType * * types ) ;
2006-07-11 18:01:26 +00:00
/* lookup user info for a given SID */
NTSTATUS ( * query_user ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
const DOM_SID * user_sid ,
WINBIND_USERINFO * user_info ) ;
/* 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 DOM_SID * user_sid ,
2005-06-08 22:10:34 +00:00
uint32 * num_groups , DOM_SID * * user_gids ) ;
2005-01-15 19:00:18 +00: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 ,
2005-06-08 22:10:34 +00:00
uint32 num_sids ,
const DOM_SID * sids ,
2005-01-15 19:00:18 +00:00
uint32 * num_aliases ,
uint32 * * alias_rids ) ;
/* find all members of the group with the specified group_rid */
NTSTATUS ( * lookup_groupmem ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
const DOM_SID * group_sid ,
uint32 * num_names ,
2005-06-08 22:10:34 +00:00
DOM_SID * * sid_mem , char * * * names ,
uint32 * * name_types ) ;
/* return the current global sequence number */
NTSTATUS ( * sequence_number ) ( struct winbindd_domain * domain , uint32 * seq ) ;
2006-02-03 22:19:41 +00:00
/* return the lockout policy */
NTSTATUS ( * lockout_policy ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
SAM_UNK_INFO_12 * lockout_policy ) ;
/* return the lockout policy */
NTSTATUS ( * password_policy ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
SAM_UNK_INFO_1 * password_policy ) ;
/* enumerate trusted domains */
NTSTATUS ( * trusted_domains ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
uint32 * num_domains ,
char * * * names ,
char * * * alt_names ,
DOM_SID * * dom_sids ) ;
} ;
/* Used to glue a policy handle and cli_state together */
typedef struct {
struct cli_state * cli ;
POLICY_HND pol ;
} CLI_POLICY_HND ;
/* Filled out by IDMAP backends */
struct winbindd_idmap_methods {
/* Called when backend is first loaded */
BOOL ( * init ) ( void ) ;
BOOL ( * get_sid_from_uid ) ( uid_t uid , DOM_SID * sid ) ;
BOOL ( * get_sid_from_gid ) ( gid_t gid , DOM_SID * sid ) ;
BOOL ( * get_uid_from_sid ) ( DOM_SID * sid , uid_t * uid ) ;
BOOL ( * get_gid_from_sid ) ( DOM_SID * sid , gid_t * gid ) ;
/* Called when backend is unloaded */
BOOL ( * close ) ( void ) ;
/* Called to dump backend status */
void ( * status ) ( void ) ;
} ;
2007-05-06 18:39:31 +00:00
/* Data structures for dealing with the trusted domain cache */
struct winbindd_tdc_domain {
const char * domain_name ;
const char * dns_name ;
DOM_SID sid ;
uint32 trust_flags ;
uint32 trust_attribs ;
uint32 trust_type ;
} ;
2004-10-07 04:01:18 +00:00
# include "nsswitch/winbindd_proto.h"
# define WINBINDD_ESTABLISH_LOOP 30
2007-05-06 19:17:30 +00:00
# define WINBINDD_RESCAN_FREQ lp_winbind_cache_time()
2006-02-03 22:19:41 +00:00
# define WINBINDD_PAM_AUTH_KRB5_RENEW_TIME 2592000 /* one month */
# define DOM_SEQUENCE_NONE ((uint32)-1)
2007-05-06 21:04:30 +00:00
# define IS_DOMAIN_OFFLINE(x) ( lp_winbind_offline_logon() && \
( get_global_winbindd_state_offline ( ) \
| | ! ( x ) - > online ) )
# endif /* _WINBINDD_H */