[429] | 1 | /*
|
---|
| 2 | Unix SMB/CIFS implementation.
|
---|
| 3 |
|
---|
| 4 | Winbind daemon for ntdom nss module
|
---|
| 5 |
|
---|
| 6 | Copyright (C) Tim Potter 2000
|
---|
| 7 | Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
|
---|
| 8 |
|
---|
| 9 | This library is free software; you can redistribute it and/or
|
---|
| 10 | modify it under the terms of the GNU Lesser General Public
|
---|
| 11 | License as published by the Free Software Foundation; either
|
---|
| 12 | version 3 of the License, or (at your option) any later version.
|
---|
| 13 |
|
---|
| 14 | This library is distributed in the hope that it will be useful,
|
---|
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 17 | Library General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License
|
---|
| 20 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | #ifndef _WINBINDD_H
|
---|
| 24 | #define _WINBINDD_H
|
---|
| 25 |
|
---|
| 26 | #include "nsswitch/winbind_struct_protocol.h"
|
---|
| 27 | #include "nsswitch/libwbclient/wbclient.h"
|
---|
| 28 | #include "librpc/gen_ndr/wbint.h"
|
---|
| 29 |
|
---|
[745] | 30 | #include "talloc_dict.h"
|
---|
| 31 | #include "smb_ldap.h"
|
---|
| 32 |
|
---|
| 33 | #include "../lib/util/tevent_ntstatus.h"
|
---|
| 34 |
|
---|
[429] | 35 | #ifdef HAVE_LIBNSCD
|
---|
| 36 | #include <libnscd.h>
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
| 39 | #ifdef HAVE_SYS_MMAN_H
|
---|
| 40 | #include <sys/mman.h>
|
---|
| 41 | #endif
|
---|
| 42 |
|
---|
| 43 | #undef DBGC_CLASS
|
---|
| 44 | #define DBGC_CLASS DBGC_WINBIND
|
---|
| 45 |
|
---|
| 46 | #define WB_REPLACE_CHAR '_'
|
---|
| 47 |
|
---|
| 48 | struct sid_ctr {
|
---|
[745] | 49 | struct dom_sid *sid;
|
---|
[429] | 50 | bool finished;
|
---|
| 51 | const char *domain;
|
---|
| 52 | const char *name;
|
---|
| 53 | enum lsa_SidType type;
|
---|
| 54 | };
|
---|
| 55 |
|
---|
| 56 | struct winbindd_cli_state {
|
---|
| 57 | struct winbindd_cli_state *prev, *next; /* Linked list pointers */
|
---|
| 58 | int sock; /* Open socket from client */
|
---|
| 59 | pid_t pid; /* pid of client */
|
---|
| 60 | time_t last_access; /* Time of last access (read or write) */
|
---|
| 61 | bool privileged; /* Is the client 'privileged' */
|
---|
| 62 |
|
---|
| 63 | TALLOC_CTX *mem_ctx; /* memory per request */
|
---|
| 64 | const char *cmd_name;
|
---|
| 65 | NTSTATUS (*recv_fn)(struct tevent_req *req,
|
---|
| 66 | struct winbindd_response *presp);
|
---|
| 67 | struct winbindd_request *request; /* Request from client */
|
---|
| 68 | struct tevent_queue *out_queue;
|
---|
| 69 | struct winbindd_response *response; /* Respose to client */
|
---|
| 70 | bool getpwent_initialized; /* Has getpwent_state been
|
---|
| 71 | * initialized? */
|
---|
| 72 | bool getgrent_initialized; /* Has getgrent_state been
|
---|
| 73 | * initialized? */
|
---|
| 74 |
|
---|
| 75 | struct getpwent_state *pwent_state; /* State for getpwent() */
|
---|
| 76 | struct getgrent_state *grent_state; /* State for getgrent() */
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 | struct getpwent_state {
|
---|
| 80 | struct winbindd_domain *domain;
|
---|
| 81 | int next_user;
|
---|
| 82 | int num_users;
|
---|
| 83 | struct wbint_userinfo *users;
|
---|
| 84 | };
|
---|
| 85 |
|
---|
| 86 | struct getgrent_state {
|
---|
| 87 | struct winbindd_domain *domain;
|
---|
| 88 | int next_group;
|
---|
| 89 | int num_groups;
|
---|
| 90 | struct wbint_Principal *groups;
|
---|
| 91 | };
|
---|
| 92 |
|
---|
| 93 | /* Storage for cached getpwent() user entries */
|
---|
| 94 |
|
---|
| 95 | struct getpwent_user {
|
---|
| 96 | fstring name; /* Account name */
|
---|
| 97 | fstring gecos; /* User information */
|
---|
| 98 | fstring homedir; /* User Home Directory */
|
---|
| 99 | fstring shell; /* User Login Shell */
|
---|
[745] | 100 | struct dom_sid user_sid; /* NT user and primary group SIDs */
|
---|
| 101 | struct dom_sid group_sid;
|
---|
[429] | 102 | };
|
---|
| 103 |
|
---|
| 104 | /* Our connection to the DC */
|
---|
| 105 |
|
---|
| 106 | struct winbindd_cm_conn {
|
---|
| 107 | struct cli_state *cli;
|
---|
| 108 |
|
---|
| 109 | struct rpc_pipe_client *samr_pipe;
|
---|
| 110 | struct policy_handle sam_connect_handle, sam_domain_handle;
|
---|
| 111 |
|
---|
| 112 | struct rpc_pipe_client *lsa_pipe;
|
---|
| 113 | struct rpc_pipe_client *lsa_pipe_tcp;
|
---|
| 114 | struct policy_handle lsa_policy;
|
---|
| 115 |
|
---|
| 116 | struct rpc_pipe_client *netlogon_pipe;
|
---|
| 117 | };
|
---|
| 118 |
|
---|
| 119 | /* Async child */
|
---|
| 120 |
|
---|
| 121 | struct winbindd_domain;
|
---|
| 122 |
|
---|
| 123 | struct winbindd_child_dispatch_table {
|
---|
| 124 | const char *name;
|
---|
| 125 | enum winbindd_cmd struct_cmd;
|
---|
| 126 | enum winbindd_result (*struct_fn)(struct winbindd_domain *domain,
|
---|
| 127 | struct winbindd_cli_state *state);
|
---|
| 128 | };
|
---|
| 129 |
|
---|
| 130 | struct winbindd_child {
|
---|
| 131 | struct winbindd_child *next, *prev;
|
---|
| 132 |
|
---|
| 133 | pid_t pid;
|
---|
| 134 | struct winbindd_domain *domain;
|
---|
| 135 | char *logfilename;
|
---|
| 136 |
|
---|
| 137 | int sock;
|
---|
| 138 | struct tevent_queue *queue;
|
---|
[745] | 139 | struct dcerpc_binding_handle *binding_handle;
|
---|
[429] | 140 |
|
---|
| 141 | struct timed_event *lockout_policy_event;
|
---|
| 142 | struct timed_event *machine_password_change_event;
|
---|
| 143 |
|
---|
| 144 | const struct winbindd_child_dispatch_table *table;
|
---|
| 145 | };
|
---|
| 146 |
|
---|
| 147 | /* Structures to hold per domain information */
|
---|
| 148 |
|
---|
| 149 | struct winbindd_domain {
|
---|
| 150 | fstring name; /* Domain name (NetBIOS) */
|
---|
| 151 | fstring alt_name; /* alt Domain name, if any (FQDN for ADS) */
|
---|
| 152 | fstring forest_name; /* Name of the AD forest we're in */
|
---|
[745] | 153 | struct dom_sid sid; /* SID for this domain */
|
---|
[429] | 154 | uint32 domain_flags; /* Domain flags from netlogon.h */
|
---|
| 155 | uint32 domain_type; /* Domain type from netlogon.h */
|
---|
| 156 | uint32 domain_trust_attribs; /* Trust attribs from netlogon.h */
|
---|
| 157 | bool initialized; /* Did we already ask for the domain mode? */
|
---|
| 158 | bool native_mode; /* is this a win2k domain in native mode ? */
|
---|
| 159 | bool active_directory; /* is this a win2k active directory ? */
|
---|
| 160 | bool primary; /* is this our primary domain ? */
|
---|
| 161 | bool internal; /* BUILTIN and member SAM */
|
---|
| 162 | bool online; /* is this domain available ? */
|
---|
[745] | 163 | time_t startup_time; /* When we set "startup" true. monotonic clock */
|
---|
[429] | 164 | bool startup; /* are we in the first 30 seconds after startup_time ? */
|
---|
| 165 |
|
---|
| 166 | bool can_do_samlogon_ex; /* Due to the lack of finer control what type
|
---|
| 167 | * of DC we have, let us try to do a
|
---|
| 168 | * credential-chain less samlogon_ex call
|
---|
| 169 | * with AD and schannel. If this fails with
|
---|
| 170 | * DCERPC_FAULT_OP_RNG_ERROR, then set this
|
---|
| 171 | * to False. This variable is around so that
|
---|
| 172 | * we don't have to try _ex every time. */
|
---|
| 173 |
|
---|
| 174 | bool can_do_ncacn_ip_tcp;
|
---|
[596] | 175 | bool can_do_validation6;
|
---|
[429] | 176 |
|
---|
| 177 | /* Lookup methods for this domain (LDAP or RPC) */
|
---|
| 178 | struct winbindd_methods *methods;
|
---|
| 179 |
|
---|
| 180 | /* the backend methods are used by the cache layer to find the right
|
---|
| 181 | backend */
|
---|
| 182 | struct winbindd_methods *backend;
|
---|
| 183 |
|
---|
| 184 | /* Private data for the backends (used for connection cache) */
|
---|
| 185 |
|
---|
| 186 | void *private_data;
|
---|
| 187 |
|
---|
| 188 | /*
|
---|
| 189 | * idmap config settings, used to tell the idmap child which
|
---|
| 190 | * special domain config to use for a mapping
|
---|
| 191 | */
|
---|
| 192 | bool have_idmap_config;
|
---|
| 193 | uint32_t id_range_low, id_range_high;
|
---|
| 194 |
|
---|
| 195 | /* A working DC */
|
---|
| 196 | pid_t dc_probe_pid; /* Child we're using to detect the DC. */
|
---|
| 197 | fstring dcname;
|
---|
| 198 | struct sockaddr_storage dcaddr;
|
---|
| 199 |
|
---|
| 200 | /* Sequence number stuff */
|
---|
| 201 |
|
---|
| 202 | time_t last_seq_check;
|
---|
| 203 | uint32 sequence_number;
|
---|
| 204 | NTSTATUS last_status;
|
---|
| 205 |
|
---|
| 206 | /* The smb connection */
|
---|
| 207 |
|
---|
| 208 | struct winbindd_cm_conn conn;
|
---|
| 209 |
|
---|
| 210 | /* The child pid we're talking to */
|
---|
| 211 |
|
---|
[745] | 212 | struct winbindd_child *children;
|
---|
[429] | 213 |
|
---|
| 214 | /* Callback we use to try put us back online. */
|
---|
| 215 |
|
---|
| 216 | uint32 check_online_timeout;
|
---|
| 217 | struct timed_event *check_online_event;
|
---|
| 218 |
|
---|
| 219 | /* Linked list info */
|
---|
| 220 |
|
---|
| 221 | struct winbindd_domain *prev, *next;
|
---|
| 222 | };
|
---|
| 223 |
|
---|
[745] | 224 | struct wb_acct_info {
|
---|
| 225 | fstring acct_name; /* account name */
|
---|
| 226 | fstring acct_desc; /* account name */
|
---|
| 227 | uint32_t rid; /* domain-relative RID */
|
---|
| 228 | };
|
---|
| 229 |
|
---|
[429] | 230 | /* per-domain methods. This is how LDAP vs RPC is selected
|
---|
| 231 | */
|
---|
| 232 | struct winbindd_methods {
|
---|
| 233 | /* does this backend provide a consistent view of the data? (ie. is the primary group
|
---|
| 234 | always correct) */
|
---|
| 235 | bool consistent;
|
---|
| 236 |
|
---|
| 237 | /* get a list of users, returning a wbint_userinfo for each one */
|
---|
| 238 | NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
|
---|
| 239 | TALLOC_CTX *mem_ctx,
|
---|
| 240 | uint32 *num_entries,
|
---|
| 241 | struct wbint_userinfo **info);
|
---|
| 242 |
|
---|
| 243 | /* get a list of domain groups */
|
---|
| 244 | NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
|
---|
| 245 | TALLOC_CTX *mem_ctx,
|
---|
| 246 | uint32 *num_entries,
|
---|
[745] | 247 | struct wb_acct_info **info);
|
---|
[429] | 248 |
|
---|
| 249 | /* get a list of domain local groups */
|
---|
| 250 | NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
|
---|
| 251 | TALLOC_CTX *mem_ctx,
|
---|
| 252 | uint32 *num_entries,
|
---|
[745] | 253 | struct wb_acct_info **info);
|
---|
[429] | 254 |
|
---|
| 255 | /* convert one user or group name to a sid */
|
---|
| 256 | NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
|
---|
| 257 | TALLOC_CTX *mem_ctx,
|
---|
| 258 | const char *domain_name,
|
---|
| 259 | const char *name,
|
---|
| 260 | uint32_t flags,
|
---|
[745] | 261 | struct dom_sid *sid,
|
---|
[429] | 262 | enum lsa_SidType *type);
|
---|
| 263 |
|
---|
| 264 | /* convert a sid to a user or group name */
|
---|
| 265 | NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
|
---|
| 266 | TALLOC_CTX *mem_ctx,
|
---|
[745] | 267 | const struct dom_sid *sid,
|
---|
[429] | 268 | char **domain_name,
|
---|
| 269 | char **name,
|
---|
| 270 | enum lsa_SidType *type);
|
---|
| 271 |
|
---|
| 272 | NTSTATUS (*rids_to_names)(struct winbindd_domain *domain,
|
---|
| 273 | TALLOC_CTX *mem_ctx,
|
---|
[745] | 274 | const struct dom_sid *domain_sid,
|
---|
[429] | 275 | uint32 *rids,
|
---|
| 276 | size_t num_rids,
|
---|
| 277 | char **domain_name,
|
---|
| 278 | char ***names,
|
---|
| 279 | enum lsa_SidType **types);
|
---|
| 280 |
|
---|
| 281 | /* lookup user info for a given SID */
|
---|
| 282 | NTSTATUS (*query_user)(struct winbindd_domain *domain,
|
---|
| 283 | TALLOC_CTX *mem_ctx,
|
---|
[745] | 284 | const struct dom_sid *user_sid,
|
---|
[429] | 285 | struct wbint_userinfo *user_info);
|
---|
| 286 |
|
---|
| 287 | /* lookup all groups that a user is a member of. The backend
|
---|
| 288 | can also choose to lookup by username or rid for this
|
---|
| 289 | function */
|
---|
| 290 | NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
|
---|
| 291 | TALLOC_CTX *mem_ctx,
|
---|
[745] | 292 | const struct dom_sid *user_sid,
|
---|
| 293 | uint32 *num_groups, struct dom_sid **user_gids);
|
---|
[429] | 294 |
|
---|
| 295 | /* Lookup all aliases that the sids delivered are member of. This is
|
---|
| 296 | * to implement 'domain local groups' correctly */
|
---|
| 297 | NTSTATUS (*lookup_useraliases)(struct winbindd_domain *domain,
|
---|
| 298 | TALLOC_CTX *mem_ctx,
|
---|
| 299 | uint32 num_sids,
|
---|
[745] | 300 | const struct dom_sid *sids,
|
---|
[429] | 301 | uint32 *num_aliases,
|
---|
| 302 | uint32 **alias_rids);
|
---|
| 303 |
|
---|
| 304 | /* find all members of the group with the specified group_rid */
|
---|
| 305 | NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
|
---|
| 306 | TALLOC_CTX *mem_ctx,
|
---|
[745] | 307 | const struct dom_sid *group_sid,
|
---|
[429] | 308 | enum lsa_SidType type,
|
---|
| 309 | uint32 *num_names,
|
---|
[745] | 310 | struct dom_sid **sid_mem, char ***names,
|
---|
[429] | 311 | uint32 **name_types);
|
---|
| 312 |
|
---|
| 313 | /* return the current global sequence number */
|
---|
| 314 | NTSTATUS (*sequence_number)(struct winbindd_domain *domain, uint32 *seq);
|
---|
| 315 |
|
---|
| 316 | /* return the lockout policy */
|
---|
| 317 | NTSTATUS (*lockout_policy)(struct winbindd_domain *domain,
|
---|
| 318 | TALLOC_CTX *mem_ctx,
|
---|
| 319 | struct samr_DomInfo12 *lockout_policy);
|
---|
| 320 |
|
---|
| 321 | /* return the lockout policy */
|
---|
| 322 | NTSTATUS (*password_policy)(struct winbindd_domain *domain,
|
---|
| 323 | TALLOC_CTX *mem_ctx,
|
---|
| 324 | struct samr_DomInfo1 *password_policy);
|
---|
| 325 |
|
---|
| 326 | /* enumerate trusted domains */
|
---|
| 327 | NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
|
---|
| 328 | TALLOC_CTX *mem_ctx,
|
---|
| 329 | struct netr_DomainTrustList *trusts);
|
---|
| 330 | };
|
---|
| 331 |
|
---|
| 332 | /* Filled out by IDMAP backends */
|
---|
| 333 | struct winbindd_idmap_methods {
|
---|
| 334 | /* Called when backend is first loaded */
|
---|
| 335 | bool (*init)(void);
|
---|
| 336 |
|
---|
[745] | 337 | bool (*get_sid_from_uid)(uid_t uid, struct dom_sid *sid);
|
---|
| 338 | bool (*get_sid_from_gid)(gid_t gid, struct dom_sid *sid);
|
---|
[429] | 339 |
|
---|
[745] | 340 | bool (*get_uid_from_sid)(struct dom_sid *sid, uid_t *uid);
|
---|
| 341 | bool (*get_gid_from_sid)(struct dom_sid *sid, gid_t *gid);
|
---|
[429] | 342 |
|
---|
| 343 | /* Called when backend is unloaded */
|
---|
| 344 | bool (*close)(void);
|
---|
| 345 | /* Called to dump backend status */
|
---|
| 346 | void (*status)(void);
|
---|
| 347 | };
|
---|
| 348 |
|
---|
| 349 | /* Data structures for dealing with the trusted domain cache */
|
---|
| 350 |
|
---|
| 351 | struct winbindd_tdc_domain {
|
---|
| 352 | const char *domain_name;
|
---|
| 353 | const char *dns_name;
|
---|
[745] | 354 | struct dom_sid sid;
|
---|
[429] | 355 | uint32 trust_flags;
|
---|
| 356 | uint32 trust_attribs;
|
---|
| 357 | uint32 trust_type;
|
---|
| 358 | };
|
---|
| 359 |
|
---|
| 360 | /* Switch for listing users or groups */
|
---|
| 361 | enum ent_type {
|
---|
| 362 | LIST_USERS = 0,
|
---|
| 363 | LIST_GROUPS,
|
---|
| 364 | };
|
---|
| 365 |
|
---|
| 366 | struct WINBINDD_MEMORY_CREDS {
|
---|
| 367 | struct WINBINDD_MEMORY_CREDS *next, *prev;
|
---|
| 368 | const char *username; /* lookup key. */
|
---|
| 369 | uid_t uid;
|
---|
| 370 | int ref_count;
|
---|
| 371 | size_t len;
|
---|
| 372 | uint8_t *nt_hash; /* Base pointer for the following 2 */
|
---|
| 373 | uint8_t *lm_hash;
|
---|
| 374 | char *pass;
|
---|
| 375 | };
|
---|
| 376 |
|
---|
| 377 | struct WINBINDD_CCACHE_ENTRY {
|
---|
| 378 | struct WINBINDD_CCACHE_ENTRY *next, *prev;
|
---|
| 379 | const char *principal_name;
|
---|
| 380 | const char *ccname;
|
---|
| 381 | const char *service;
|
---|
| 382 | const char *username;
|
---|
| 383 | const char *realm;
|
---|
| 384 | struct WINBINDD_MEMORY_CREDS *cred_ptr;
|
---|
| 385 | int ref_count;
|
---|
| 386 | uid_t uid;
|
---|
| 387 | time_t create_time;
|
---|
| 388 | time_t renew_until;
|
---|
| 389 | time_t refresh_time;
|
---|
| 390 | struct timed_event *event;
|
---|
| 391 | };
|
---|
| 392 |
|
---|
| 393 | #include "winbindd/winbindd_proto.h"
|
---|
| 394 |
|
---|
| 395 | #define WINBINDD_ESTABLISH_LOOP 30
|
---|
| 396 | #define WINBINDD_RESCAN_FREQ lp_winbind_cache_time()
|
---|
| 397 | #define WINBINDD_PAM_AUTH_KRB5_RENEW_TIME 2592000 /* one month */
|
---|
| 398 | #define DOM_SEQUENCE_NONE ((uint32)-1)
|
---|
| 399 |
|
---|
[745] | 400 | #define winbind_event_context server_event_context
|
---|
| 401 |
|
---|
[429] | 402 | #endif /* _WINBINDD_H */
|
---|