@@ -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 ;
@@ -2470,19 +2476,31 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
24702476 uid = posix_offset + sid_sub_auth_rid (sid);
24712477 if (!is_group () && acc_type == SidTypeUser)
24722478 {
2473- /* Default primary group. Make the educated guess that the user
2474- is in group "Domain Users" or "None". */
2475- gid = posix_offset + DOMAIN_GROUP_RID_USERS;
2479+ /* Default primary group. If the sid is the current user, and
2480+ we are not configured for accurate mode, fetch
2481+ the default group from the current user token, otherwise make
2482+ the educated guess that the user is in group "Domain Users"
2483+ or "None". */
2484+ if (!cygheap->pg .nss_grp_db_accurate () && sid == cygheap->user .sid ())
2485+ {
2486+ get_default_group_from_current_user_token = true ;
2487+ gid = posix_offset
2488+ + sid_sub_auth_rid (cygheap->user .groups .pgsid );
2489+ }
2490+ else
2491+ gid = posix_offset + DOMAIN_GROUP_RID_USERS;
24762492 }
24772493
24782494 if (is_domain_account)
24792495 {
24802496 /* Skip this when creating group entries and for non-users. */
24812497 if (is_group () || acc_type != SidTypeUser)
24822498 break ;
2483- /* Fetch primary group from AD and overwrite the one we
2484- just guessed above. */
2485- if (cldap->fetch_ad_account (sid, false , domain))
2499+ /* For the current user we got correctly cased username and
2500+ the primary group via process token. For any other user
2501+ we fetch it from AD and overwrite it. */
2502+ if (!get_default_group_from_current_user_token
2503+ && cldap->fetch_ad_account (sid, false , domain))
24862504 {
24872505 if ((val = cldap->get_account_name ()))
24882506 wcscpy (name, val);
0 commit comments