delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2026/04/24/08:11:20

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 63OCBJlC2779776
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 63OCBJlC2779776
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=B4jP7h3S
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DB104BB5882
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1777032679;
bh=1yWZp3Otb8TdDpXkt+rhDd/LjbOcnr/o38h/r2g2h6g=;
h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
From;
b=B4jP7h3SORB7J7Uehm+ydB6gyYFwB4AOKA92LH690wjqEyAlQ29I9nMvRyiTxda9/
5VU2aE+Ur4MOXnAr94UHI7FZOdn19cq0PtFU3OTaf0mR8SWCPr/me4HPYtodDcJQfF
rn8guR3ai9QbU8ADvTjOQUQk5WzOeeDyTJvwpoVc=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 374E44BB3BEA
Date: Fri, 24 Apr 2026 14:11:00 +0200
To: cygwin AT cygwin DOT com
Subject: Re: Getting Windows "MACHINE SID" without fork() & exec()?
Message-ID: <aetd1DORPHzpvKvv@calimero.vinschen.de>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <CALWcw=HNsScw6AcFU5-g1nvy7g+NRWZ-B2LMFFaHAoTWkkN17g AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <CALWcw=HNsScw6AcFU5-g1nvy7g+NRWZ-B2LMFFaHAoTWkkN17g@mail.gmail.com>
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Corinna Vinschen via Cygwin <cygwin AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
Cc: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>

On Apr 23 19:07, Takeshi Nishimura via Cygwin wrote:
> Does Cygwin have a secret shell variable or /proc file which contains
> the current machine's MACHINE SID, without having to resort to calling
> an external program (no fork(), no exec(), please)?

You can use your own simple tool in plain C:

$ cat > adom.c <<EOF
#include <stdio.h>
#include <windows.h>
#include <ntsecapi.h>
#include <ntstatus.h>
#include <sddl.h>

int
main ()
{
  LSA_OBJECT_ATTRIBUTES oa = { 0, 0, 0, 0, 0, 0 };
  PPOLICY_ACCOUNT_DOMAIN_INFO adom;
  NTSTATUS status;
  LPWSTR sidstr;
  HANDLE lsa;

  status = LsaOpenPolicy(NULL, &oa, POLICY_VIEW_LOCAL_INFORMATION, &lsa);
  if (status == STATUS_SUCCESS)
    {
      status = LsaQueryInformationPolicy (lsa, PolicyAccountDomainInformation,
                                          (PVOID *) &adom);
      if (status == STATUS_SUCCESS)
        {
          ConvertSidToStringSidW (adom->DomainSid, &sidstr);
          printf ("%ls\n", sidstr);
          LocalFree (sidstr);
        }
      LsaFreeMemory (adom);
      LsaClose (lsa);
    }
  return 0;
}
EOF
$ gcc -o adom adom.c
$ ./adom
S-1-5-21-2941109648-2854651930-1480659642


Corinna

-- 
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019