2000-05-09 15:43:00 +04: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
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 .
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 .
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"
2000-05-09 15:43:00 +04:00
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 '_'
2005-06-09 02:10:34 +04: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 ;
2007-10-19 04:40:25 +04:00
void ( * finished ) ( void * private_data , bool success ) ;
2005-06-25 00:25:18 +04:00
void * private_data ;
2005-06-09 02:10:34 +04:00
} ;
2000-05-09 15:43:00 +04:00
2005-09-30 21:13:37 +04:00
struct sid_ctr {
DOM_SID * sid ;
2007-10-19 04:40:25 +04:00
bool finished ;
2005-09-30 21:13:37 +04:00
const char * domain ;
const char * name ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType type ;
2005-09-30 21:13:37 +04: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 */
2005-06-09 02:10:34 +04:00
struct fd_event fd_event ;
2003-02-28 03:25:55 +03:00
pid_t pid ; /* pid of client */
2007-10-19 04:40:25 +04:00
bool finished ; /* Can delete from list */
bool write_extra_data ; /* Write extra_data field */
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 */
2003-02-28 03:25:55 +03:00
struct winbindd_request request ; /* Request from client */
struct winbindd_response response ; /* Respose to client */
2007-10-19 04:40:25 +04:00
bool getpwent_initialized ; /* Has getpwent_state been
2005-06-09 02:10:34 +04:00
* initialized ? */
2007-10-19 04:40:25 +04:00
bool getgrent_initialized ; /* Has getgrent_state been
2005-06-09 02:10:34 +04:00
* initialized ? */
2003-02-28 03:25:55 +03:00
struct getent_state * getpwent_state ; /* State for getpwent() */
struct getent_state * getgrent_state ; /* State for getgrent() */
2000-05-09 15:43:00 +04:00
} ;
2001-05-07 08:32:40 +04:00
/* State between get{pw,gr}ent() calls */
2000-05-09 15:43:00 +04:00
struct getent_state {
2001-05-07 08:32:40 +04:00
struct getent_state * prev , * next ;
void * sam_entries ;
uint32 sam_entry_index , num_sam_entries ;
2007-10-19 04:40:25 +04:00
bool got_sam_entries ;
2002-01-11 08:33:45 +03:00
fstring domain_name ;
2001-05-07 08:32:40 +04:00
} ;
/* Storage for cached getpwent() user entries */
struct getpwent_user {
fstring name ; /* Account name */
fstring gecos ; /* User information */
2005-06-29 18:03:53 +04:00
fstring homedir ; /* User Home Directory */
fstring shell ; /* User Login Shell */
2003-04-23 15:54:56 +04:00
DOM_SID user_sid ; /* NT user and primary group SIDs */
DOM_SID group_sid ;
2000-05-09 15:43:00 +04:00
} ;
/* Server state structure */
2001-12-01 15:31:43 +03:00
typedef struct {
char * acct_name ;
char * full_name ;
2005-06-29 18:03:53 +04:00
char * homedir ;
char * shell ;
2007-01-24 04:48:08 +03:00
gid_t primary_gid ; /* allow the nss_info
backend to set the primary group */
2005-06-09 02:10:34 +04:00
DOM_SID user_sid ; /* NT user and primary group SIDs */
DOM_SID group_sid ;
2001-12-03 14:32:55 +03:00
} WINBIND_USERINFO ;
2001-12-01 15:31:43 +03:00
2005-06-09 02:10:34 +04: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 */
2007-10-08 16:25:57 +04:00
struct winbindd_domain ;
struct winbindd_child_dispatch_table {
2007-12-07 18:00:45 +03:00
const char * name ;
enum winbindd_cmd struct_cmd ;
enum winbindd_result ( * struct_fn ) ( struct winbindd_domain * domain ,
struct winbindd_cli_state * state ) ;
2007-10-08 16:25:57 +04:00
} ;
2005-06-09 02:10:34 +04:00
struct winbindd_child {
struct winbindd_child * next , * prev ;
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
struct fd_event event ;
2006-03-17 13:14:33 +03:00
struct timed_event * lockout_policy_event ;
2005-06-09 02:10:34 +04:00
struct winbindd_async_request * requests ;
2007-10-08 16:25:57 +04:00
const struct winbindd_child_dispatch_table * table ;
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 {
2007-05-07 01:15:45 +04:00
fstring name ; /* Domain name (NetBIOS) */
fstring alt_name ; /* alt Domain name, if any (FQDN for ADS) */
2007-01-03 00:48:47 +03:00
fstring forest_name ; /* Name of the AD forest we're in */
2002-01-11 08:33:45 +03:00
DOM_SID sid ; /* SID for this domain */
2007-12-04 04:57:46 +03:00
uint32 domain_flags ; /* Domain flags from rpc_ds.h */
uint32 domain_type ; /* Domain type from rpc_ds.h */
2007-05-06 22:39:31 +04:00
uint32 domain_trust_attribs ; /* Trust attribs from rpc_ds.h */
2007-10-19 04:40:25 +04: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 ? */
bool internal ; /* BUILTIN and member SAM */
bool online ; /* is this domain available ? */
2006-09-28 22:08:03 +04:00
time_t startup_time ; /* When we set "startup" true. */
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
/* Lookup methods for this domain (LDAP or RPC) */
struct winbindd_methods * methods ;
2003-06-10 07:50:38 +04:00
/* the backend methods are used by the cache layer to find the right
backend */
struct winbindd_methods * backend ;
2002-01-11 08:33:45 +03:00
/* Private data for the backends (used for connection cache) */
2007-12-04 04:57:46 +03:00
void * private_data ;
2002-01-11 08:33:45 +03:00
2004-11-18 14:57:49 +03:00
/* A working DC */
fstring 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 ;
uint32 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 */
struct winbindd_child child ;
2006-09-07 01:43:31 +04:00
/* Callback we use to try put us back online. */
2006-12-07 02:14:15 +03:00
uint32 check_online_timeout ;
2006-09-07 01:43:31 +04:00
struct timed_event * check_online_event ;
2002-01-11 08:33:45 +03:00
/* Linked list info */
struct winbindd_domain * prev , * next ;
} ;
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
2001-12-05 07:48:51 +03:00
/* get a list of users, returning a WINBIND_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 ,
2001-12-11 03:03:58 +03:00
uint32 * num_entries ,
2001-12-03 14:32:55 +03:00
WINBIND_USERINFO * * info ) ;
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 ,
2001-12-11 04:04:13 +03:00
uint32 * num_entries ,
2001-12-03 04:23:42 +03:00
struct 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 ,
uint32 * num_entries ,
struct acct_info * * info ) ;
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 ,
2007-05-30 23:47:35 +04:00
enum winbindd_cmd orig_cmd ,
2004-04-20 06:37:49 +04:00
const char * domain_name ,
2001-12-03 11:17:46 +03:00
const char * name ,
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 ,
2004-01-05 05:04:37 +03:00
const 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 ,
const DOM_SID * domain_sid ,
uint32 * rids ,
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
2003-04-23 15:54:56 +04:00
/* lookup user info for a given SID */
2001-12-04 09:17:39 +03:00
NTSTATUS ( * query_user ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2004-03-30 12:03:32 +04:00
const DOM_SID * user_sid ,
2001-12-04 09:17:39 +03:00
WINBIND_USERINFO * user_info ) ;
2001-12-04 09:46:53 +03:00
2001-12-05 07:48:51 +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 */
2001-12-04 09:46:53 +03:00
NTSTATUS ( * lookup_usergroups ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
2004-03-30 12:03:32 +04:00
const DOM_SID * user_sid ,
2005-06-09 02:10:34 +04:00
uint32 * num_groups , DOM_SID * * user_gids ) ;
2001-12-05 07:48:51 +03:00
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 ,
2005-06-09 02:10:34 +04:00
uint32 num_sids ,
const DOM_SID * sids ,
2005-01-15 22:00:18 +03:00
uint32 * num_aliases ,
uint32 * * alias_rids ) ;
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 ,
2004-03-30 12:03:32 +04:00
const DOM_SID * group_sid ,
2003-04-23 15:54:56 +04:00
uint32 * num_names ,
2005-06-09 02:10:34 +04:00
DOM_SID * * sid_mem , char * * * names ,
2001-12-05 07:48:51 +03:00
uint32 * * name_types ) ;
2001-12-05 10:52:44 +03:00
/* return the current global sequence number */
2001-12-10 02:59:42 +03:00
NTSTATUS ( * sequence_number ) ( struct winbindd_domain * domain , uint32 * seq ) ;
2001-12-10 05:25:19 +03:00
2006-02-04 01:19:41 +03: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 ) ;
2001-12-10 05:25:19 +03:00
/* enumerate trusted domains */
NTSTATUS ( * trusted_domains ) ( struct winbindd_domain * domain ,
TALLOC_CTX * mem_ctx ,
uint32 * num_domains ,
char * * * names ,
2002-08-17 21:00:51 +04:00
char * * * alt_names ,
2001-12-10 05:25:19 +03:00
DOM_SID * * dom_sids ) ;
2001-12-01 15:31:43 +03:00
} ;
2001-10-05 04:20:06 +04:00
/* Used to glue a policy handle and cli_state together */
typedef struct {
struct cli_state * cli ;
POLICY_HND pol ;
} CLI_POLICY_HND ;
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
2007-10-19 04:40:25 +04:00
bool ( * get_sid_from_uid ) ( uid_t uid , DOM_SID * sid ) ;
bool ( * get_sid_from_gid ) ( gid_t gid , DOM_SID * sid ) ;
2003-04-23 15:54:56 +04:00
2007-10-19 04:40:25 +04:00
bool ( * get_uid_from_sid ) ( DOM_SID * sid , uid_t * uid ) ;
bool ( * get_gid_from_sid ) ( 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 ;
DOM_SID sid ;
uint32 trust_flags ;
uint32 trust_attribs ;
uint32 trust_type ;
} ;
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 */
2000-05-09 15:43:00 +04:00
# define DOM_SEQUENCE_NONE ((uint32)-1)
2007-05-07 01:04:30 +04:00
# define IS_DOMAIN_OFFLINE(x) ( lp_winbind_offline_logon() && \
( get_global_winbindd_state_offline ( ) \
| | ! ( x ) - > online ) )
2000-05-09 15:43:00 +04:00
# endif /* _WINBINDD_H */