declaration in ldap-related method. (cygheap_pwdgrp::get_shell): Ditto. (cygheap_pwdgrp::get_gecos): Ditto. * ldap.cc (cyg_ldap::open): Use NO_ERROR instead of 0. (cyg_ldap::close): Reset last_fetched_sid. (cyg_ldap::fetch_ad_account): Return immediately if sid is the same as last_fetched_sid. Open LDAP connection from here. Move initialization of rdse after open call. Set last_fetched_sid if LDAP call was successful. * ldap.h (class cyg_ldap): Add member last_fetched_sid. (cyg_ldap::cyg_ldap): Initialize last_fetched_sid. (cyg_ldap::is_open): New inline method. * uinfo.cc (cygheap_pwdgrp::init): Drop initialization of db_home, db_shell and db_gecos with "cygwin desc", thus only using the fallback by default. (fetch_windows_home): Add parameter dnsdomain. Call cyg_ldap::fetch_ad_account if required. (fetch_from_path): Add parameter dnsdomain. Call fetch_windows_home accordingly. (cygheap_pwdgrp::get_home): Accomodate call to fetch_windows_home. Add dnsdomain parameter in ldap-related method. Call cyg_ldap::fetch_ad_account if required. (cygheap_pwdgrp::get_shell): Ditto. (cygheap_pwdgrp::get_gecos): Ditto. (pwdgrp::fetch_account_from_windows): Drop cyg_ldap::open call prior to cyg_ldap::fetch_ad_account call. Set is_current_user to true if we're handling the current user account. Make sure to perform the LDAP calls only for users, and only if required.
78 lines
2.3 KiB
C++
78 lines
2.3 KiB
C++
/* ldap.h.
|
|
|
|
Copyright 2014, 2015 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_UID_ATTR 1
|
|
|
|
#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;
|
|
cygsid last_fetched_sid;
|
|
|
|
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), last_fetched_sid (NO_SID)
|
|
{}
|
|
~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 ();
|
|
|
|
bool is_open () const { return !!lh; }
|
|
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); }
|
|
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); }
|
|
PWCHAR get_string_attribute (PCWSTR name);
|
|
};
|