* Makefile.in (install): Add install-ldif target.
(install-ldif): New target to install cygwin.ldif. * cygheap.h (class cygheap_pwdgrp): Rename pfx_t to nss_pfx_t. Add PFX to enum value. Add nss_scheme_method enum and nss_scheme_t structure. Add home_scheme, shell_scheme and gecos_scheme members. (NSS_SCHEME_MAX): Define. (cygheap_pwdgrp::get_home): Declare. (cygheap_pwdgrp::get_shell): Declare. (cygheap_pwdgrp::get_gecos): Declare. * cygwin.ldif: New file. * ldap.cc (std_user_attr): New array, just defining the standard attributes. (group_attr): Add cygwinUnixGid. (user_attr): Convert to macro pointing to cygheap->pg.ldap_user_attr. (cygheap_pwdgrp::init_ldap_user_attr): New method. (cyg_ldap::fetch_ad_account): Call cygheap_pwdgrp::init_ldap_user_attr if user_attr initialization is required. Fix comment. (cyg_ldap::get_string_attribute): Implement taking attribute name as argument. * ldap.h: Drop unused macros. (cyg_ldap::get_gecos): Remove. (cyg_ldap::get_home): Remove. (cyg_ldap::get_shell): Remove. (cyg_ldap::get_string_attribute): Declare name argument variant public. * uinfo.cc (cygheap_user::ontherange): Fix indentation. (cygheap_pwdgrp::init): Initialize new home_scheme, shell_scheme and gecos_scheme members. Align comment. (NSS_NCMP): Define comparison macro. (NSS_CMP): Ditto. (cygheap_pwdgrp::nss_init_line): Use aforementioned macros throughout. Fix comment handling. Add db_home, db_shell and db_gecos handling. (fetch_from_description): New function to fetch XML-style attributes from (description) string. (fetch_from_path): New function to evaluate path string with wildcards. (cygheap_pwdgrp::get_home): New methods to fetch pw_dir value. (cygheap_pwdgrp::get_shell): Ditto for pw_shell. (cygheap_pwdgrp::get_gecos): Ditto for pw_gecos. (colon_to_semicolon): Move up. (pwdgrp::fetch_account_from_windows): Convert home, shell, gecos variables to char*. Drop statement breaking extended group info. Fetch home, shell and gecos values using new methods. Use fetch_from_description calls to fetch UNIX id and primary groups from SAM comment field. Accommodate uxid being a char* now. Accommodate the fact that extended info is malloc'ed, rather then alloca'ed. Create linebuf content as multibyte string. Create line buffer by just calling cstrdup.
This commit is contained in:
@ -31,20 +31,32 @@ static PWCHAR rootdse_attr[] =
|
||||
NULL
|
||||
};
|
||||
|
||||
static PWCHAR user_attr[] =
|
||||
static const PCWSTR std_user_attr[] =
|
||||
{
|
||||
(PWCHAR) L"primaryGroupID",
|
||||
(PWCHAR) L"gecos",
|
||||
(PWCHAR) L"unixHomeDirectory",
|
||||
(PWCHAR) L"loginShell",
|
||||
(PWCHAR) L"uidNumber",
|
||||
NULL
|
||||
L"primaryGroupID",
|
||||
L"uidNumber",
|
||||
L"cygwinUnixUid", /* TODO */
|
||||
/* windows scheme */
|
||||
L"displayName",
|
||||
L"homeDrive",
|
||||
L"homeDirectory",
|
||||
/* cygwin scheme */
|
||||
L"cygwinGecos",
|
||||
L"cygwinHome",
|
||||
L"cygwinShell",
|
||||
/* unix scheme */
|
||||
L"gecos",
|
||||
L"unixHomeDirectory",
|
||||
L"loginShell",
|
||||
/* desc scheme */
|
||||
L"description"
|
||||
};
|
||||
|
||||
static PWCHAR group_attr[] =
|
||||
{
|
||||
(PWCHAR) L"cn",
|
||||
(PWCHAR) L"gidNumber",
|
||||
(PWCHAR) L"cygwinUnixGid", /* TODO */
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -72,6 +84,32 @@ PWCHAR rfc2307_gid_attr[] =
|
||||
NULL
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
/* Helper method of cygheap_pwdgrp class. It sets the user attribs */
|
||||
/* from the settings in nsswitch.conf. */
|
||||
/* ================================================================= */
|
||||
|
||||
#define user_attr (cygheap->pg.ldap_user_attr)
|
||||
|
||||
void
|
||||
cygheap_pwdgrp::init_ldap_user_attr ()
|
||||
{
|
||||
ldap_user_attr = (PWCHAR *)
|
||||
ccalloc_abort (HEAP_BUF, sizeof (std_user_attr) / sizeof (*std_user_attr)
|
||||
+ 3 * NSS_SCHEME_MAX + 1, sizeof (PWCHAR));
|
||||
memcpy (ldap_user_attr, std_user_attr, sizeof (std_user_attr));
|
||||
uint16_t freeattr_idx = sizeof (std_user_attr) / sizeof (*std_user_attr);
|
||||
for (uint16_t idx = 0; idx < NSS_SCHEME_MAX; ++idx)
|
||||
{
|
||||
if (home_scheme[idx].method == NSS_SCHEME_FREEATTR)
|
||||
ldap_user_attr[freeattr_idx++] = home_scheme[idx].attrib;
|
||||
if (shell_scheme[idx].method == NSS_SCHEME_FREEATTR)
|
||||
ldap_user_attr[freeattr_idx++] = shell_scheme[idx].attrib;
|
||||
if (gecos_scheme[idx].method == NSS_SCHEME_FREEATTR)
|
||||
ldap_user_attr[freeattr_idx++] = gecos_scheme[idx].attrib;
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
/* Helper methods. */
|
||||
/* ================================================================= */
|
||||
@ -388,6 +426,8 @@ cyg_ldap::fetch_ad_account (PSID sid, bool group, PCWSTR domain)
|
||||
r = wcpcpy (r, domain);
|
||||
}
|
||||
}
|
||||
if (!user_attr)
|
||||
cygheap->pg.init_ldap_user_attr ();
|
||||
attr = group ? group_attr : user_attr;
|
||||
if (search (rdse, filter, attr) != 0)
|
||||
return false;
|
||||
@ -421,7 +461,7 @@ cyg_ldap::enumerate_ad_accounts (PCWSTR domain, bool group)
|
||||
"(objectSid=*))";
|
||||
else
|
||||
filter = L"(&(objectClass=Group)"
|
||||
/* 1 == ACCOUNT_GROUP */
|
||||
/* 1 == BUILTIN_LOCAL_GROUP */
|
||||
"(!(groupType:" LDAP_MATCHING_RULE_BIT_AND ":=1))"
|
||||
"(objectSid=*))";
|
||||
srch_id = ldap_search_init_pageW (lh, rootdse, LDAP_SCOPE_SUBTREE,
|
||||
@ -503,20 +543,26 @@ cyg_ldap::fetch_posix_offset_for_domain (PCWSTR domain)
|
||||
}
|
||||
|
||||
PWCHAR
|
||||
cyg_ldap::get_string_attribute (int idx)
|
||||
cyg_ldap::get_string_attribute (PCWSTR name)
|
||||
{
|
||||
if (val)
|
||||
ldap_value_freeW (val);
|
||||
val = ldap_get_valuesW (lh, entry, attr[idx]);
|
||||
val = ldap_get_valuesW (lh, entry, (PWCHAR) name);
|
||||
if (val)
|
||||
return val[0];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PWCHAR
|
||||
cyg_ldap::get_string_attribute (int idx)
|
||||
{
|
||||
return get_string_attribute (attr[idx]);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
cyg_ldap::get_num_attribute (int idx)
|
||||
{
|
||||
PWCHAR ret = get_string_attribute (idx);
|
||||
PWCHAR ret = get_string_attribute (attr[idx]);
|
||||
if (ret)
|
||||
return (uint32_t) wcstoul (ret, NULL, 10);
|
||||
return (uint32_t) -1;
|
||||
|
Reference in New Issue
Block a user