2014-02-09 20:44:56 +01: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 16:36:33 +01:00
|
|
|
#pragma once
|
|
|
|
|
2014-02-09 20:44:56 +01: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-17 22:08:01 +01:00
|
|
|
PWCHAR def_context;
|
2014-02-09 20:44:56 +01:00
|
|
|
PLDAPMessage msg, entry;
|
|
|
|
PWCHAR *val;
|
|
|
|
PWCHAR *attr;
|
|
|
|
bool isAD;
|
2014-05-22 22:07:25 +02:00
|
|
|
PLDAPSearch srch_id;
|
2015-02-12 17:55:38 +01:00
|
|
|
cygsid last_fetched_sid;
|
2014-02-09 20:44:56 +01:00
|
|
|
|
2014-06-25 11:10:50 +02:00
|
|
|
inline int map_ldaperr_to_errno (ULONG lerr);
|
|
|
|
inline int wait (cygthread *thr);
|
|
|
|
inline int connect (PCWSTR domain);
|
2015-02-18 11:25:14 +01:00
|
|
|
inline int search (PWCHAR base, ULONG scope, PWCHAR filter, PWCHAR *attrs);
|
2014-06-25 11:10:50 +02:00
|
|
|
inline int next_page ();
|
2014-02-09 20:44:56 +01: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-17 22:08:01 +01:00
|
|
|
cyg_ldap () : lh (NULL), def_context (NULL), msg (NULL), entry (NULL),
|
2015-02-24 21:52:57 +01:00
|
|
|
val (NULL), isAD (false), srch_id (NULL),
|
|
|
|
last_fetched_sid (NO_SID)
|
2014-02-09 20:44:56 +01:00
|
|
|
{}
|
|
|
|
~cyg_ldap () { close (); }
|
|
|
|
|
2014-06-25 11:10:50 +02:00
|
|
|
ULONG connect_ssl (PCWSTR domain);
|
|
|
|
ULONG connect_non_ssl (PCWSTR domain);
|
2015-02-18 11:25:14 +01:00
|
|
|
ULONG search_s (PWCHAR base, ULONG scope, PWCHAR filter, PWCHAR *attrs);
|
2014-06-25 11:10:50 +02:00
|
|
|
ULONG next_page_s ();
|
|
|
|
|
2015-02-12 17:55:38 +01:00
|
|
|
bool is_open () const { return !!lh; }
|
2014-02-09 20:44:56 +01:00
|
|
|
operator PLDAP () const { return lh; }
|
2014-06-25 11:10:50 +02:00
|
|
|
int open (PCWSTR in_domain);
|
2014-02-09 20:44:56 +01:00
|
|
|
void close ();
|
2015-02-24 21:52:57 +01:00
|
|
|
PWCHAR get_string_attribute (PCWSTR name);
|
|
|
|
uint32_t get_num_attribute (PCWSTR name);
|
2014-05-22 16:50:24 +02:00
|
|
|
bool fetch_ad_account (PSID sid, bool group, PCWSTR domain = NULL);
|
2014-06-25 11:10:50 +02:00
|
|
|
int enumerate_ad_accounts (PCWSTR domain, bool group);
|
|
|
|
int next_account (cygsid &sid);
|
2014-02-09 20:44:56 +01: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-24 21:52:57 +01: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 12:42:56 +01:00
|
|
|
PWCHAR get_account_name ()
|
2015-02-24 21:52:57 +01:00
|
|
|
{ return get_string_attribute (L"sAMAccountName"); }
|
|
|
|
gid_t get_unix_gid () { return get_num_attribute (L"gidNumber"); }
|
2019-02-23 17:22:44 +01:00
|
|
|
PWCHAR get_profile_path ()
|
|
|
|
{ return get_string_attribute (L"profilePath"); }
|
2014-02-09 20:44:56 +01:00
|
|
|
};
|