This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: passwd help/version patch


--- Corinna Vinschen <cygwin-patches@cygwin.com> wrote:
> > > Or perhaps change passwd to take the Cygwin name and
> > > convert it to the windows name???
> > >
> > > Corinna
> >
> > Maybe I'm missing something, but there doesn't seem to be any Win32
> > function to get a username from a uid other than NetUserEnum, but
> > I really don't think people running 'passwd bob' are wanting to enum
> > all users. The code to do it wouldn't be that hard, but it wouldn't
> > work for those people with domains (unless they specify a domain like
> > for mkpasswd).
> >
> > Maybe mkpasswd should cache the info somewhere other than just /etc/passwd
> > for this purpose? Or use the GECOS field?
>
> I'm sorry if my mail wasn't clear but I just asked for getting the
> Win32 name from the cygwin name.  The cygwin name is the one given
> on the command line or what is returned by getlogin().  The information
> about the Win32 name is then returned in the pw_gecos field by
> getpwnam().  Either a U-DOMAIN\NAME or a S-1-5-xxx sid.  If the
> U- field is given, it contains the name, otherwise a LookupAccountSid()
> gives the Win32 name from the SID.  If neither is given, the Cygwin
> username is equal to the Win32 name.
>
> There is already a function `extract_nt_dom_user()' in Cygwin, file
> security.cc which contains this functionality.  Unfortunately it
> isn't exported so it would have to be copied to passwd.c (and
> transformed to plain c).
>
> Or we export that function.  I think it is a useful functionality for
> Cygwin tools.  Perhaps with the "cygwin_" prefix.
>
> Corinna

Thanks very much for the pointers. However,
After working on it a while, I think that exporting a
cygwin_extract_nt_dom_user() would be best. The attached patch is a
halfway solution that just copies most of extract_nt_dom_user()
other than the SID code. It will get the correct username in the case of
a U-DOMAIN type of GECOS, but if only a ':S-1-5-xxx:' is in the GECOS
it fails with the old 'passwd: unknown user boalhg' message.
If a Win32 username is found, a line like: 'Windows username : bob'
is output.

I tried to build up the structures necessary for LookupAccountSid()
with the sec* stuff in winsup/cygwin as a guide, but it looks like
reinventing a C wheel from C++ spare parts. It'd be a lot better to
be able to just put cygwin_extract_nt_dom_user(pw, domain, (char *) user)
right in passwd.c IMHO.

Caveat: I don't have a real domain that I'm testing with.

2002-05-30  Joshua Daniel Franklin <joshuadfranklin@yahoo.com>

	* passwd.c (extract_nt_dom_user): New function.
	(GetPW): Try to look up Win32 username in case of NERR_UserNotFound.

Attachment: passwd.c-patch
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]