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
--
Problem reports: https://cygwin.com/problems.html
FAQ: https://cygwin.com/faq/
Documentation: https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple