emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emacs 23.0.60.1 built today (11th feb 2008) crashes under Vista


From: Eli Zaretskii
Subject: Re: emacs 23.0.60.1 built today (11th feb 2008) crashes under Vista
Date: Thu, 14 Feb 2008 21:47:41 +0200

> From: Eric Lilja <address@hidden>
> Date: Thu, 14 Feb 2008 02:18:36 +0100
> 
> I am happy to report that Emacs does indeed not crash on Vista after 
> reverting the changes to w32.c, using the method suggested by Juanma. 
> Hopefully a proper fix (because I assume the changes I reverted have 
> some purpose too) isn't too hard to do.

Could you please compile the program below and run it on Vista with
some file name (a name of any existing file) as a single argument?
Then please post here everything it prints.  That might give me enough
information to fix the code.

Thanks.

-------------------------- cut here --------------------
#include <stdio.h>
#include <windows.h>
#include <lmcons.h>
#include <accctrl.h>
#include <aclapi.h>
#include <tchar.h>

BOOL GetTextualSid(
    PSID pSid,            // binary SID
    LPTSTR TextualSid,    // buffer for Textual representation of SID
    LPDWORD lpdwBufferLen // required/provided TextualSid buffersize
    )
{
    PSID_IDENTIFIER_AUTHORITY psia;
    DWORD dwSubAuthorities;
    DWORD dwSidRev=SID_REVISION;
    DWORD dwCounter;
    DWORD dwSidSize;

    // Validate the binary SID.

    if(!IsValidSid(pSid)) return FALSE;

    // Get the identifier authority value from the SID.

    psia = GetSidIdentifierAuthority(pSid);

    // Get the number of subauthorities in the SID.

    dwSubAuthorities = *GetSidSubAuthorityCount(pSid);

    // Compute the buffer length.
    // S-SID_REVISION- + IdentifierAuthority- + subauthorities- + NULL

    dwSidSize=(15 + 12 + (12 * dwSubAuthorities) + 1) * sizeof(TCHAR);

    // Check input buffer length.
    // If too small, indicate the proper size and set the last error.

    if (*lpdwBufferLen < dwSidSize)
    {
        *lpdwBufferLen = dwSidSize;
        SetLastError(ERROR_INSUFFICIENT_BUFFER);
        return FALSE;
    }

    // Add 'S' prefix and revision number to the string.

    dwSidSize=_stprintf(TextualSid,
              TEXT("S-%lu-"), dwSidRev );

    // Add a SID identifier authority to the string.

    if ( (psia->Value[0] != 0) || (psia->Value[1] != 0) )
    {
        dwSidSize+=_stprintf(TextualSid + lstrlen(TextualSid),
                    TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),
                    (USHORT)psia->Value[0],
                    (USHORT)psia->Value[1],
                    (USHORT)psia->Value[2],
                    (USHORT)psia->Value[3],
                    (USHORT)psia->Value[4],
                    (USHORT)psia->Value[5]);
    }
    else
    {
        dwSidSize+=_stprintf(TextualSid + lstrlen(TextualSid),
                    TEXT("%lu"),
                    (ULONG)(psia->Value[5]      )   +
                    (ULONG)(psia->Value[4] <<  8)   +
                    (ULONG)(psia->Value[3] << 16)   +
                    (ULONG)(psia->Value[2] << 24)   );
    }

    // Add SID subauthorities to the string.
    //
    for (dwCounter=0 ; dwCounter < dwSubAuthorities ; dwCounter++)
    {
        dwSidSize+=_stprintf(TextualSid + dwSidSize,
                    TEXT("-%lu"),
                    *GetSidSubAuthority(pSid, dwCounter) );
    }

    return TRUE;
}

int
main (int argc, char *argv[])
{
  SECURITY_INFORMATION si =
    OWNER_SECURITY_INFORMATION
    | GROUP_SECURITY_INFORMATION
    | DACL_SECURITY_INFORMATION;
  /* The magic value 244 is returned by GetFileSecurity if one uses
     less storage for the three flags above.  */
  SECURITY_DESCRIPTOR  *sd = malloc(244);
  const char *arg = (argv[1] ? argv[1] : argv[0]);
  DWORD len_needed;

  if (!GetFileSecurity (arg, si, sd, 244, &len_needed))
    fprintf (stderr, "GetFileSecurity: %lu (%lu/%u)\n",
             GetLastError (), len_needed, 244);
  else
    {
      SID *psid, *pgsid;
      BOOL deflt, deflt1;
      char name[UNLEN + 1], gname[UNLEN + 1];
      SID_NAME_USE snu, sng;
      char domain[1024];
      DWORD nl = UNLEN + 1, gnl = UNLEN + 1;
      DWORD dl = 1024, gdl = 1024;
      char tusid[1024], tgsid[1024];
      DWORD tsidlen = sizeof(tusid);
      BOOL daclpresent;
      PACL pdacl;

      if (!GetSecurityDescriptorOwner (sd, (PSID *)&psid, &deflt))
        fprintf (stderr, "GetSecurityDescriptorOwner: %lu\n", GetLastError ());
      else if (!LookupAccountSid (NULL, psid, name, &nl,
                                  domain, &dl, &snu))
        fprintf (stderr, "LookupAccountSid: %lu\n",
                 GetLastError ());
      else if (!GetTextualSid (psid, tusid, &tsidlen))
        fprintf (stderr, "GetTextualSid (owner): %lu\n", GetLastError ());
      else if (!GetSecurityDescriptorGroup (sd, (PSID *)&pgsid, &deflt))
        fprintf (stderr, "GetSecurityDescriptorGroup: %lu\n", GetLastError ());
      else if (!LookupAccountSid (NULL, pgsid, gname, &gnl,
                                  domain, &gdl, &sng))
        fprintf (stderr, "LookupAccountSid: %lu\n",
                 GetLastError ());
      else if (!GetTextualSid (pgsid, tgsid, &tsidlen))
        fprintf (stderr, "GetTextualSid (group): %lu\n", GetLastError ());
      else if (!GetSecurityDescriptorDacl (sd, &daclpresent, &pdacl, &deflt1))
        fprintf (stderr, "GetSecurityDescriptorDacl: %lu\n", GetLastError ());
      else if (!daclpresent)
        fprintf (stderr, "GetSecurityDescriptorDacl: NO DACL\n");
      else
        {
          ACCESS_MASK umask, gmask;
          DWORD err;
          TRUSTEE trustee = {
            NULL, NO_MULTIPLE_TRUSTEE, TRUSTEE_IS_SID, TRUSTEE_IS_USER, NULL
          };

          trustee.ptstrName = (LPTSTR)psid;
          if ((err = GetEffectiveRightsFromAcl (pdacl, &trustee, &umask)) != 
ERROR_SUCCESS)
            fprintf (stderr, "GetEffectiveRightsFromAcl (owner): %lu\n", err);
          else if (trustee.TrusteeType = TRUSTEE_IS_GROUP,
                   trustee.ptstrName = (LPTSTR)pgsid,
                   (err = GetEffectiveRightsFromAcl (pdacl, &trustee, &gmask)) 
!= ERROR_SUCCESS)
            fprintf (stderr, "GetEffectiveRightsFromAcl (group): %lu\n", err);
          else
            printf ("%s:\n         dflt=%d owner=%s grp=%s domain=%s use=%d\n   
      Ownr SID=%s 0x%lx\n         Grp  SID=%s 0x%lx\n",
                    arg, deflt, name, gname, domain, snu, tusid, umask, tgsid, 
gmask);
        }
    }
  return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]