@@ -637,6 +637,11 @@ cygheap_pwdgrp::nss_init_line (const char *line)
637637 *src |= NSS_SRC_DB;
638638 c += 2 ;
639639 }
640+ else if (NSS_CMP (" db-accurate" ))
641+ {
642+ *src |= NSS_SRC_DB | NSS_SRC_DB_ACCURATE;
643+ c += 11 ;
644+ }
640645 else
641646 {
642647 c += strcspn (c, " \t " );
@@ -1952,6 +1957,7 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
19521957 gid_t gid = ILLEGAL_GID;
19531958 bool is_domain_account = true ;
19541959 PCWSTR domain = NULL ;
1960+ bool get_default_group_from_current_user_token = false ;
19551961 char *shell = NULL ;
19561962 char *home = NULL ;
19571963 char *gecos = NULL ;
@@ -2449,9 +2455,19 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
24492455 uid = posix_offset + sid_sub_auth_rid (sid);
24502456 if (!is_group () && acc_type == SidTypeUser)
24512457 {
2452- /* Default primary group. Make the educated guess that the user
2453- is in group "Domain Users" or "None". */
2454- gid = posix_offset + DOMAIN_GROUP_RID_USERS;
2458+ /* Default primary group. If the sid is the current user, and
2459+ we are not configured for accurate mode, fetch
2460+ the default group from the current user token, otherwise make
2461+ the educated guess that the user is in group "Domain Users"
2462+ or "None". */
2463+ if (!cygheap->pg .nss_grp_db_accurate () && sid == cygheap->user .sid ())
2464+ {
2465+ get_default_group_from_current_user_token = true ;
2466+ gid = posix_offset
2467+ + sid_sub_auth_rid (cygheap->user .groups .pgsid );
2468+ }
2469+ else
2470+ gid = posix_offset + DOMAIN_GROUP_RID_USERS;
24552471 }
24562472
24572473 if (is_domain_account)
@@ -2462,9 +2478,11 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
24622478 /* On AD machines, use LDAP to fetch domain account infos. */
24632479 if (cygheap->dom .primary_dns_name ())
24642480 {
2465- /* Fetch primary group from AD and overwrite the one we
2466- just guessed above. */
2467- if (cldap->fetch_ad_account (sid, false , domain))
2481+ /* For the current user we got correctly cased username and
2482+ the primary group via process token. For any other user
2483+ we fetch it from AD and overwrite it. */
2484+ if (!get_default_group_from_current_user_token
2485+ && cldap->fetch_ad_account (sid, false , domain))
24682486 {
24692487 if ((val = cldap->get_account_name ()))
24702488 wcscpy (name, val);
0 commit comments