@@ -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 ;
@@ -2466,19 +2472,31 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
24662472 uid = posix_offset + sid_sub_auth_rid (sid);
24672473 if (!is_group () && acc_type == SidTypeUser)
24682474 {
2469- /* Default primary group. Make the educated guess that the user
2470- is in group "Domain Users" or "None". */
2471- gid = posix_offset + DOMAIN_GROUP_RID_USERS;
2475+ /* Default primary group. If the sid is the current user, and
2476+ we are not configured for accurate mode, fetch
2477+ the default group from the current user token, otherwise make
2478+ the educated guess that the user is in group "Domain Users"
2479+ or "None". */
2480+ if (!cygheap->pg .nss_grp_db_accurate () && sid == cygheap->user .sid ())
2481+ {
2482+ get_default_group_from_current_user_token = true ;
2483+ gid = posix_offset
2484+ + sid_sub_auth_rid (cygheap->user .groups .pgsid );
2485+ }
2486+ else
2487+ gid = posix_offset + DOMAIN_GROUP_RID_USERS;
24722488 }
24732489
24742490 if (is_domain_account)
24752491 {
24762492 /* Skip this when creating group entries and for non-users. */
24772493 if (is_group () || acc_type != SidTypeUser)
24782494 break ;
2479- /* Fetch primary group from AD and overwrite the one we
2480- just guessed above. */
2481- if (cldap->fetch_ad_account (sid, false , domain))
2495+ /* For the current user we got correctly cased username and
2496+ the primary group via process token. For any other user
2497+ we fetch it from AD and overwrite it. */
2498+ if (!get_default_group_from_current_user_token
2499+ && cldap->fetch_ad_account (sid, false , domain))
24822500 {
24832501 if ((val = cldap->get_account_name ()))
24842502 wcscpy (name, val);
0 commit comments