* cygheap.h (cygheap_pwdgrp::get_home): Add dnsdomain parameter to
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.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* ldap.cc: Helper functions for ldap access to Active Directory.
|
||||
|
||||
Copyright 2014 Red Hat, Inc.
|
||||
Copyright 2014, 2015 Red Hat, Inc.
|
||||
|
||||
This file is part of Cygwin.
|
||||
|
||||
@@ -312,11 +312,11 @@ cyg_ldap::next_page ()
|
||||
int
|
||||
cyg_ldap::open (PCWSTR domain)
|
||||
{
|
||||
int ret = 0;
|
||||
int ret = NO_ERROR;
|
||||
|
||||
/* Already open? */
|
||||
if (lh)
|
||||
return 0;
|
||||
return NO_ERROR;
|
||||
|
||||
if ((ret = connect (domain)) != NO_ERROR)
|
||||
goto err;
|
||||
@@ -351,7 +351,7 @@ cyg_ldap::open (PCWSTR domain)
|
||||
val = NULL;
|
||||
ldap_msgfree (msg);
|
||||
msg = entry = NULL;
|
||||
return 0;
|
||||
return NO_ERROR;
|
||||
err:
|
||||
close ();
|
||||
return ret;
|
||||
@@ -378,17 +378,24 @@ cyg_ldap::close ()
|
||||
rootdse = NULL;
|
||||
srch_id = NULL;
|
||||
srch_msg = srch_entry = NULL;
|
||||
last_fetched_sid = NO_SID;
|
||||
}
|
||||
|
||||
bool
|
||||
cyg_ldap::fetch_ad_account (PSID sid, bool group, PCWSTR domain)
|
||||
{
|
||||
WCHAR filter[140], *f, *rdse = rootdse;
|
||||
WCHAR filter[140], *f, *rdse = NULL;
|
||||
LONG len = (LONG) RtlLengthSid (sid);
|
||||
PBYTE s = (PBYTE) sid;
|
||||
static WCHAR hex_wchars[] = L"0123456789abcdef";
|
||||
tmp_pathbuf tp;
|
||||
|
||||
if (last_fetched_sid == sid)
|
||||
return true;
|
||||
|
||||
if (open (NULL) != NO_ERROR)
|
||||
return false;
|
||||
|
||||
if (msg)
|
||||
{
|
||||
ldap_msgfree (msg);
|
||||
@@ -426,6 +433,11 @@ cyg_ldap::fetch_ad_account (PSID sid, bool group, PCWSTR domain)
|
||||
r = wcpcpy (r, domain);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* rootdse is only valid after open. */
|
||||
rdse = rootdse;
|
||||
}
|
||||
if (!user_attr)
|
||||
cygheap->pg.init_ldap_user_attr ();
|
||||
attr = group ? group_attr : user_attr;
|
||||
@@ -436,6 +448,7 @@ cyg_ldap::fetch_ad_account (PSID sid, bool group, PCWSTR domain)
|
||||
debug_printf ("No entry for %W in rootdse %W", filter, rdse);
|
||||
return false;
|
||||
}
|
||||
last_fetched_sid = sid;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user