e35b92c202
(LdapMapErrorToWin32): Import. * fhandler_disk_file.cc (fhandler_base::fstat_by_nfs_ea): Accommodate change to cyg_ldap::open. * ldap.cc (CYG_LDAP_TIMEOUT): Remove. (CYG_LDAP_ENUM_TIMEOUT): Remove. (def_tv): Remove. (enum_tv): Remove. (cyg_ldap::map_ldaperr_to_errno): New method to map LDAP error codes to POSIX errno codes. Explicitly map LDAP_NO_RESULTS_RETURNED to ENMFILE. (cyg_ldap::wait): Ditto. (struct cyg_ldap_init): New struct. (cyg_ldap::connect_ssl): Return ULONG. Drop setting LDAP_OPT_TIMELIMIT. Add call to ldap_search_sW to fetch root DSE. (cyg_ldap::connect_non_ssl): Ditto. (ldap_init_thr): New static thread function. (cyg_ldap::connect): New method to call connect_ssl/connect_non_ssl in an interruptible cygthread. (struct cyg_ldap_search): New struct. (cyg_ldap::search_s): New method to perform generic synchronous search. (ldap_search_thr): New static thread function. (cyg_ldap::search): New method to call search_s in an interruptible cygthread. (struct cyg_ldap_next_page): New struct. (cyg_ldap::next_page_s): New method to perform generic synchronous paged search. (ldap_next_page_thr): New static thread function. (cyg_ldap::next_page): New method to call next_page_s in an interruptible cygthread. (cyg_ldap::open): Return POSIX errno. Call connect method. (cyg_ldap::fetch_ad_account): Call search method rather than ldap_search_stW. (cyg_ldap::enumerate_ad_accounts): Return POSIX errno. Use infinite timeout in call to ldap_search_init_pageW. (cyg_ldap::next_account): Return POSIX errno. Call next_page method rather than ldap_get_next_page_s. (cyg_ldap::fetch_posix_offset_for_domain): Call search method rather than ldap_search_stW. (cyg_ldap::fetch_unix_sid_from_ad): Ditto. (cyg_ldap::fetch_unix_name_from_rfc2307): Ditto. * ldap.h (class cyg_ldap): Accommodate aforementioned changes. * passwd.cc (pg_ent::enumerate_ad): Ditto. Break search if one of cyg_ldap::enumerate_ad_accounts or cldap.next_account returns with an error code other than ENMFILE. * sec_helper.cc (cygpsid::get_id): Accommodate change to cyg_ldap::open. * uinfo.cc (fetch_posix_offset): Ditto.
81 lines
2.5 KiB
C++
81 lines
2.5 KiB
C++
/* ldap.h.
|
|
|
|
Copyright 2014 Red Hat, Inc.
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
|
|
#pragma once
|
|
|
|
#pragma push_macro ("DECLSPEC_IMPORT")
|
|
#undef DECLSPEC_IMPORT
|
|
#define DECLSPEC_IMPORT
|
|
#include <winldap.h>
|
|
#include <ntldap.h>
|
|
#pragma pop_macro ("DECLSPEC_IMPORT")
|
|
|
|
#define LDAP_USER_PGRP_ATTR 0
|
|
#define LDAP_USER_GECOS_ATTR 1
|
|
#define LDAP_USER_HOME_ATTR 2
|
|
#define LDAP_USER_SHELL_ATTR 3
|
|
#define LDAP_USER_UID_ATTR 4
|
|
|
|
#define LDAP_GROUP_NAME_ATTR 0
|
|
#define LDAP_GROUP_GID_ATTR 1
|
|
|
|
class cyg_ldap {
|
|
PLDAP lh;
|
|
PWCHAR rootdse;
|
|
PLDAPMessage msg, entry;
|
|
PWCHAR *val;
|
|
PWCHAR *attr;
|
|
bool isAD;
|
|
PLDAPSearch srch_id;
|
|
PLDAPMessage srch_msg, srch_entry;
|
|
|
|
inline int map_ldaperr_to_errno (ULONG lerr);
|
|
inline int wait (cygthread *thr);
|
|
inline int connect (PCWSTR domain);
|
|
inline int search (PWCHAR base, PWCHAR filter, PWCHAR *attrs);
|
|
inline int next_page ();
|
|
bool fetch_unix_sid_from_ad (uint32_t id, cygsid &sid, bool group);
|
|
PWCHAR fetch_unix_name_from_rfc2307 (uint32_t id, bool group);
|
|
PWCHAR get_string_attribute (int idx);
|
|
uint32_t get_num_attribute (int idx);
|
|
|
|
public:
|
|
cyg_ldap () : lh (NULL), rootdse (NULL), msg (NULL), entry (NULL), val (NULL),
|
|
isAD (false), srch_id (NULL), srch_msg (NULL), srch_entry (NULL)
|
|
{}
|
|
~cyg_ldap () { close (); }
|
|
|
|
ULONG connect_ssl (PCWSTR domain);
|
|
ULONG connect_non_ssl (PCWSTR domain);
|
|
ULONG search_s (PWCHAR base, PWCHAR filter, PWCHAR *attrs);
|
|
ULONG next_page_s ();
|
|
|
|
operator PLDAP () const { return lh; }
|
|
int open (PCWSTR in_domain);
|
|
void close ();
|
|
bool fetch_ad_account (PSID sid, bool group, PCWSTR domain = NULL);
|
|
int enumerate_ad_accounts (PCWSTR domain, bool group);
|
|
int next_account (cygsid &sid);
|
|
uint32_t fetch_posix_offset_for_domain (PCWSTR domain);
|
|
uid_t remap_uid (uid_t uid);
|
|
gid_t remap_gid (gid_t gid);
|
|
/* User only */
|
|
gid_t get_primary_gid () { return get_num_attribute (LDAP_USER_PGRP_ATTR); }
|
|
PWCHAR get_gecos () { return get_string_attribute (LDAP_USER_GECOS_ATTR); }
|
|
PWCHAR get_home ()
|
|
{ return get_string_attribute (LDAP_USER_HOME_ATTR); }
|
|
PWCHAR get_shell () { return get_string_attribute (LDAP_USER_SHELL_ATTR); }
|
|
gid_t get_unix_uid () { return get_num_attribute (LDAP_USER_UID_ATTR); }
|
|
/* group only */
|
|
PWCHAR get_group_name ()
|
|
{ return get_string_attribute (LDAP_GROUP_NAME_ATTR); }
|
|
gid_t get_unix_gid () { return get_num_attribute (LDAP_GROUP_GID_ATTR); }
|
|
};
|