public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Shell API to get Windows SID from Cygwin name?
@ 2023-09-22  5:58 Martin Wege
  2023-09-22 12:07 ` Brian Inglis
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Wege @ 2023-09-22  5:58 UTC (permalink / raw)
  To: cygwin

Hello,

Does Cygwin have a shell (e.g. bash) API to lookup the Windows SID for
a given Cygwin user or group name?

/usr/bin/getent usersid thisisausername

does not work

Thanks,
Martin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Shell API to get Windows SID from Cygwin name?
  2023-09-22  5:58 Shell API to get Windows SID from Cygwin name? Martin Wege
@ 2023-09-22 12:07 ` Brian Inglis
  2023-09-23  0:15   ` Allen, Norton T.
  0 siblings, 1 reply; 5+ messages in thread
From: Brian Inglis @ 2023-09-22 12:07 UTC (permalink / raw)
  To: Martin Wege, cygwin

On 2023-09-21 23:58, Martin Wege via Cygwin wrote:
> Does Cygwin have a shell (e.g. bash) API to lookup the Windows SID for
> a given Cygwin user or group name?
> /usr/bin/getent usersid thisisausername

Forget Windows! Think Unix:

$ getent passwd $USER	# sanitized output:
$USER:*:$UID:545:U-$HOSTNAME/$USER,S-1-5-21-...-...-...-1001:$HOME:/bin/bash

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                 -- Antoine de Saint-Exupéry

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Shell API to get Windows SID from Cygwin name?
  2023-09-22 12:07 ` Brian Inglis
@ 2023-09-23  0:15   ` Allen, Norton T.
  2023-09-23  3:11     ` Brian Inglis
  0 siblings, 1 reply; 5+ messages in thread
From: Allen, Norton T. @ 2023-09-23  0:15 UTC (permalink / raw)
  To: cygwin

On 9/22/2023 8:07 AM, Brian Inglis via Cygwin wrote:
> On 2023-09-21 23:58, Martin Wege via Cygwin wrote:
>> Does Cygwin have a shell (e.g. bash) API to lookup the Windows SID for
>> a given Cygwin user or group name?
>> /usr/bin/getent usersid thisisausername
>
> Forget Windows! Think Unix:
>
> $ getent passwd $USER    # sanitized output:
> $USER:*:$UID:545:U-$HOSTNAME/$USER,S-1-5-21-...-...-...-1001:$HOME:/bin/bash 
>
>
According to the man page, getent passwd takes a numeric UID, not a user 
name. But if you don't provide a UID, it basically lists what would be 
in /etc/passwd, which you could parse to locate the row you want by 
username.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Shell API to get Windows SID from Cygwin name?
  2023-09-23  0:15   ` Allen, Norton T.
@ 2023-09-23  3:11     ` Brian Inglis
  2023-09-23 14:02       ` Allen, Norton T.
  0 siblings, 1 reply; 5+ messages in thread
From: Brian Inglis @ 2023-09-23  3:11 UTC (permalink / raw)
  To: cygwin; +Cc: Allen, Norton T.

On 2023-09-22 18:15, Allen, Norton T. via Cygwin wrote:
> On 9/22/2023 8:07 AM, Brian Inglis via Cygwin wrote:
>> On 2023-09-21 23:58, Martin Wege via Cygwin wrote:
>>> Does Cygwin have a shell (e.g. bash) API to lookup the Windows SID for
>>> a given Cygwin user or group name?
>>> /usr/bin/getent usersid thisisausername
>>
>> Forget Windows! Think Unix:
>>
>> $ getent passwd $USER    # sanitized output:
>> $USER:*:$UID:545:U-$HOSTNAME/$USER,S-1-5-21-...-...-...-1001:$HOME:/bin/bash
>>
> According to the man page, getent passwd takes a numeric UID, not a user name. 
> But if you don't provide a UID, it basically lists what would be in /etc/passwd, 
> which you could parse to locate the row you want by username.

[IIRC getent evolved from SunOS YellowPages/YP/NIS/+ facilities and commands as 
LANs, sites, and orgs required more central control and distribution than could 
easily be managed using text files /etc/{hosts,protocols,services,networks,...}, 
while requiring flexibility to allow some local setup and configurable priority 
depending on system roles, provided by the Name Services Switch /etc/nsswitch.conf.]

I checked all distro man pages I can find online and have locally, and from 
SunOS and Solaris, key lookup and other features were supported from the early 
days, while BSDs appear to use GNU (glibc) getent (or at least its man page), as 
does Linux.

All data sources support lookup by non-numeric key get...nam....(3), some by 
numeric key get...id(3), and some support enumeration set...ent(3), 
get...ent(3), end...ent(3), e.g.

$ man getent
...
passwd	When no key is provided, use
	setpwent(3), getpwent(3), and endpwent(3)
	to enumerate the passwd database.
	When one or more key arguments are provided, pass each
	numeric key to getpwuid(3) and each
	nonnumeric key to getpwnam(3)
	and display the result.
	On Cygwin the key can also be a Windows SID.
...

Perhaps you were thinking of POSIX id(1p) which only takes a user login name?

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                 -- Antoine de Saint-Exupéry

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Shell API to get Windows SID from Cygwin name?
  2023-09-23  3:11     ` Brian Inglis
@ 2023-09-23 14:02       ` Allen, Norton T.
  0 siblings, 0 replies; 5+ messages in thread
From: Allen, Norton T. @ 2023-09-23 14:02 UTC (permalink / raw)
  To: cygwin

On 9/22/2023 11:11 PM, Brian Inglis wrote:
> On 2023-09-22 18:15, Allen, Norton T. via Cygwin wrote:
>> On 9/22/2023 8:07 AM, Brian Inglis via Cygwin wrote:
>>> On 2023-09-21 23:58, Martin Wege via Cygwin wrote:
>>>> Does Cygwin have a shell (e.g. bash) API to lookup the Windows SID for
>>>> a given Cygwin user or group name?
>>>> /usr/bin/getent usersid thisisausername
>>>
>>> Forget Windows! Think Unix:
>>>
>>> $ getent passwd $USER    # sanitized output:
>>> $USER:*:$UID:545:U-$HOSTNAME/$USER,S-1-5-21-...-...-...-1001:$HOME:/bin/bash 
>>>
>>>
>> According to the man page, getent passwd takes a numeric UID, not a 
>> user name. But if you don't provide a UID, it basically lists what 
>> would be in /etc/passwd, which you could parse to locate the row you 
>> want by username.
>
> [IIRC getent evolved from SunOS YellowPages/YP/NIS/+ facilities and 
> commands as LANs, sites, and orgs required more central control and 
> distribution than could easily be managed using text files 
> /etc/{hosts,protocols,services,networks,...}, while requiring 
> flexibility to allow some local setup and configurable priority 
> depending on system roles, provided by the Name Services Switch 
> /etc/nsswitch.conf.]
>
> I checked all distro man pages I can find online and have locally, and 
> from SunOS and Solaris, key lookup and other features were supported 
> from the early days, while BSDs appear to use GNU (glibc) getent (or 
> at least its man page), as does Linux.
>
> All data sources support lookup by non-numeric key get...nam....(3), 
> some by numeric key get...id(3), and some support enumeration 
> set...ent(3), get...ent(3), end...ent(3), e.g.
>
> $ man getent
> ...
> passwd    When no key is provided, use
>     setpwent(3), getpwent(3), and endpwent(3)
>     to enumerate the passwd database.
>     When one or more key arguments are provided, pass each
>     numeric key to getpwuid(3) and each
>     nonnumeric key to getpwnam(3)
>     and display the result.
>     On Cygwin the key can also be a Windows SID.
> ...
>
> Perhaps you were thinking of POSIX id(1p) which only takes a user 
> login name?
>
Sorry, you are entirely correct. I tried with my username and got 
nothing. Then I remembered I have a different username on this system.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-23 14:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22  5:58 Shell API to get Windows SID from Cygwin name? Martin Wege
2023-09-22 12:07 ` Brian Inglis
2023-09-23  0:15   ` Allen, Norton T.
2023-09-23  3:11     ` Brian Inglis
2023-09-23 14:02       ` Allen, Norton T.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).