From 0ac645c1c32e2462c87378df16e0308d4f7af0b7 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 10 Feb 2014 18:28:51 +0000 Subject: [PATCH] * uinfo.cc (pwdgrp::fetch_account_from_windows): Add code to allow setting the primary group from the SAM comment field. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/uinfo.cc | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index b585aa736..6ad0ed256 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2014-02-10 Corinna Vinschen + + * uinfo.cc (pwdgrp::fetch_account_from_windows): Add code to allow + setting the primary group from the SAM comment field. + 2014-02-10 Corinna Vinschen * dcrt0.cc (child_info_spawn::handle_spawn): Call fixup_lockf_after_exec diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index 6ef2719e0..e209cc66c 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -1443,6 +1443,7 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group) debug_printf ("NetUserGetInfo(%W,%W) %u", domain, name, nas); else { + PWCHAR pgrp = NULL; struct { PCWSTR str; size_t len; @@ -1450,7 +1451,8 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group) } search[] = { { L"name=\"", 6, &user }, { L"home=\"", 6, &home }, - { L"shell=\"", 7, &shell } + { L"shell=\"", 7, &shell }, + { L"group=\"", 7, &pgrp } }; PWCHAR s, e; @@ -1494,6 +1496,25 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group) } } NetApiBufferFree (ui); + if (pgrp) + { + /* For setting the primary group, we have to test all + three possible Cygwin name variations: + + MACHINE+group, +group, group + */ + char gname[2 * (DNLEN + UNLEN + 1)]; + char *sep; + struct group *gr; + + sep += sys_wcstombs (sep = gname, 2 * DNLEN + 1, domain); + *sep = cygheap->pg.nss_separator ()[0]; + sys_wcstombs (sep + 1, 2 * UNLEN + 1, pgrp); + if ((gr = internal_getgrnam (gname)) + || (gr = internal_getgrnam (sep)) + || (gr = internal_getgrnam (sep + 1))) + gid = gr->gr_gid; + } } } else /* SidTypeGroup */