2014-02-10 03:44:56 +08:00
|
|
|
/* ldap.h.
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2014-02-17 23:36:33 +08:00
|
|
|
#pragma once
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
#pragma push_macro ("DECLSPEC_IMPORT")
|
|
|
|
#undef DECLSPEC_IMPORT
|
|
|
|
#define DECLSPEC_IMPORT
|
|
|
|
#include <winldap.h>
|
|
|
|
#include <ntldap.h>
|
|
|
|
#pragma pop_macro ("DECLSPEC_IMPORT")
|
|
|
|
|
|
|
|
class cyg_ldap {
|
|
|
|
PLDAP lh;
|
2015-02-18 05:08:01 +08:00
|
|
|
PWCHAR def_context;
|
2014-02-10 03:44:56 +08:00
|
|
|
PLDAPMessage msg, entry;
|
|
|
|
PWCHAR *val;
|
|
|
|
PWCHAR *attr;
|
|
|
|
bool isAD;
|
2014-05-23 04:07:25 +08:00
|
|
|
PLDAPSearch srch_id;
|
2015-02-13 00:55:38 +08:00
|
|
|
cygsid last_fetched_sid;
|
2014-02-10 03:44:56 +08:00
|
|
|
|
2014-06-25 17:10:50 +08:00
|
|
|
inline int map_ldaperr_to_errno (ULONG lerr);
|
|
|
|
inline int wait (cygthread *thr);
|
|
|
|
inline int connect (PCWSTR domain);
|
2015-02-18 18:25:14 +08:00
|
|
|
inline int search (PWCHAR base, ULONG scope, PWCHAR filter, PWCHAR *attrs);
|
2014-06-25 17:10:50 +08:00
|
|
|
inline int next_page ();
|
2014-02-10 03:44:56 +08:00
|
|
|
bool fetch_unix_sid_from_ad (uint32_t id, cygsid &sid, bool group);
|
|
|
|
PWCHAR fetch_unix_name_from_rfc2307 (uint32_t id, bool group);
|
|
|
|
|
|
|
|
public:
|
2015-02-18 05:08:01 +08:00
|
|
|
cyg_ldap () : lh (NULL), def_context (NULL), msg (NULL), entry (NULL),
|
2020-03-11 20:36:41 +08:00
|
|
|
val (NULL), isAD (false), srch_id (NULL),
|
2015-02-25 04:52:57 +08:00
|
|
|
last_fetched_sid (NO_SID)
|
2014-02-10 03:44:56 +08:00
|
|
|
{}
|
|
|
|
~cyg_ldap () { close (); }
|
|
|
|
|
2014-06-25 17:10:50 +08:00
|
|
|
ULONG connect_ssl (PCWSTR domain);
|
|
|
|
ULONG connect_non_ssl (PCWSTR domain);
|
2015-02-18 18:25:14 +08:00
|
|
|
ULONG search_s (PWCHAR base, ULONG scope, PWCHAR filter, PWCHAR *attrs);
|
2014-06-25 17:10:50 +08:00
|
|
|
ULONG next_page_s ();
|
|
|
|
|
2015-02-13 00:55:38 +08:00
|
|
|
bool is_open () const { return !!lh; }
|
2014-02-10 03:44:56 +08:00
|
|
|
operator PLDAP () const { return lh; }
|
2014-06-25 17:10:50 +08:00
|
|
|
int open (PCWSTR in_domain);
|
2014-02-10 03:44:56 +08:00
|
|
|
void close ();
|
2015-02-25 04:52:57 +08:00
|
|
|
PWCHAR get_string_attribute (PCWSTR name);
|
|
|
|
uint32_t get_num_attribute (PCWSTR name);
|
2014-05-22 22:50:24 +08:00
|
|
|
bool fetch_ad_account (PSID sid, bool group, PCWSTR domain = NULL);
|
2014-06-25 17:10:50 +08:00
|
|
|
int enumerate_ad_accounts (PCWSTR domain, bool group);
|
|
|
|
int next_account (cygsid &sid);
|
2014-02-10 03:44:56 +08:00
|
|
|
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 */
|
2015-02-25 04:52:57 +08:00
|
|
|
gid_t get_primary_gid () { return get_num_attribute (L"primaryGroupID"); }
|
|
|
|
gid_t get_unix_uid () { return get_num_attribute (L"uidNumber"); }
|
2019-02-13 19:42:56 +08:00
|
|
|
PWCHAR get_account_name ()
|
2015-02-25 04:52:57 +08:00
|
|
|
{ return get_string_attribute (L"sAMAccountName"); }
|
|
|
|
gid_t get_unix_gid () { return get_num_attribute (L"gidNumber"); }
|
2019-02-24 00:22:44 +08:00
|
|
|
PWCHAR get_profile_path ()
|
|
|
|
{ return get_string_attribute (L"profilePath"); }
|
2014-02-10 03:44:56 +08:00
|
|
|
};
|