0

I'm trying to use GetNamedSecurityInfo() but I keep getting out of scope errors:

main.cpp:25:3: error: 'SDDL_REVISION_1' was not declared in this scope
   SDDL_REVISION_1, DACL_SECURITY_INFORMATION, secDescBuffer, buflen);
   ^
main.cpp:25:68: error: 'ConvertSecurityDescriptorToStringSecurityDescriptor' was not declared in this scope
   SDDL_REVISION_1, DACL_SECURITY_INFORMATION, secDescBuffer, buflen);

Here is the code:

#include "windows.h"
#include "sddl.h"
#include "aclapi.h"
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    PACL pACL = NULL;

    DWORD dwRes = 0;
    PSECURITY_DESCRIPTOR pSecDesc = NULL;

    dwRes = GetNamedSecurityInfo(TEXT("C:\\somefile.txt"),
        SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
        NULL, NULL, &pACL, NULL, &pSecDesc);

    if (ERROR_SUCCESS == dwRes) {

        LPTSTR * secDescBuffer = NULL;
        PULONG buflen = NULL;

        dwRes = ConvertSecurityDescriptorToStringSecurityDescriptor(pSecDesc,
            SDDL_REVISION_1, DACL_SECURITY_INFORMATION, secDescBuffer, buflen);

    } else {
        printf("GetNamedSecurityInfo Error %lu\n", dwRes);
    }
    ...

I know it uses the sddl.h header, and it definitely exists with no compile errors referring directly to it. What am I missing here?

edit: I am using netbeans and minGW toolchain. I have the Windows SDK, and have been using other parts just fine (like GetNamedSecurityInfo as shown in the example).

Jordan Hanna
  • 145
  • 2
  • 7

2 Answers2

1

SDDL_REVISION_1 is defined in sddl.h, but only if WINAPI_FAMILY is defined as WINAPI_FAMILY_DESKTOP_APP. The default value of WINAPI_FAMILY is apparently WINAPI_FAMILY_DESKTOP_APP, that is winapifamily.h defines it as WINAPI_FAMILY_DESKTOP_APP if it is not already defined.

My best guess is that you have defined WINAPI_FAMILY to something other than WINAPI_FAMILY_DESKTOP_APP.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Benilda Key
  • 2,836
  • 1
  • 22
  • 34
1

While many of the comments and Ben Key's answer led me to the right place, it came down to the fact that the Min in Mingw stands for minimal.

The sddl.h that I was using was actually coming from Mingw's include folder, not from my Windows SDK include. After looking at the sddl.h provided by Mingw, I noticed that it is a very minimal version, and is missing the prototypes and defines I need. This also explains why my code worked in MSVC for others.

Thank you all for the comments and answers that helped me figure this out!

Edit: This answer to another question outlines some of the issues when using both mingw and Win SDK includes.

Edit2: As Ben Key mentioned in his comment, mingw-builds has a version of sddl.h (and other includes) that is much more filled out than the one found in the original mingw. Mingw-builds is a merge with mingw-w64, and seems to be the most up-to-date (while still being mature) of the mingw options. You can read more about mingw-w64 here.

Community
  • 1
  • 1
Jordan Hanna
  • 145
  • 2
  • 7
  • 1
    The version of sddl.h that comes with the version of MinGW available at http://sourceforge.net/projects/mingwbuilds/ (GCC 4.8.1) has SDDL_REVISION_1 and ConvertSecurityDescriptorToStringSecurityDescriptor defined. – Benilda Key Aug 14 '14 at 04:57
  • You are right! Thank you for showing me this, I've learned quite a bit through dealing with this issue. – Jordan Hanna Aug 15 '14 at 04:12