Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with LookupAccountSid

Help with LookupAccountSid

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionsysadmindata-structuressecurity
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dimitris Vikeloudas
    wrote on last edited by
    #1

    Hi. Iwant to get the owner name of a file or directory. I hope to get the creators name. Thus I used the GetFileSecurity to get the file security id and then the GetSecurityOwnerDescriptor to get the account security id. Then, I stack. According to the manual you have to use the LookupAccountSide specifing two buffers as parameters: One to get the account name and another to get the domain name. Also according to them you need to give the current size of the buffers. The call will fail if one of buffer is not large enough and it will return the correct buffer sizes. It will also fail for other reasons like network failure etc. Does anyone knows what is the error returned due to a buffer failure? Is it the same error for both buffers or a different one? How many calls do I need until I correct the buffers (by reading the sizes and allocating the buffers) until I get anyothe legitimate failure?? Why MicroSoft, NEVER, NEVER, NEVER documents the possible ways that a function may fail??? Is this a developers friendly company???

    D 1 Reply Last reply
    0
    • D Dimitris Vikeloudas

      Hi. Iwant to get the owner name of a file or directory. I hope to get the creators name. Thus I used the GetFileSecurity to get the file security id and then the GetSecurityOwnerDescriptor to get the account security id. Then, I stack. According to the manual you have to use the LookupAccountSide specifing two buffers as parameters: One to get the account name and another to get the domain name. Also according to them you need to give the current size of the buffers. The call will fail if one of buffer is not large enough and it will return the correct buffer sizes. It will also fail for other reasons like network failure etc. Does anyone knows what is the error returned due to a buffer failure? Is it the same error for both buffers or a different one? How many calls do I need until I correct the buffers (by reading the sizes and allocating the buffers) until I get anyothe legitimate failure?? Why MicroSoft, NEVER, NEVER, NEVER documents the possible ways that a function may fail??? Is this a developers friendly company???

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      I use something like:

      PSECURITY_DESCRIPTOR pSecurityDescriptor;
      PSID pSidOwner;
      SID_NAME_USE rSidNameUse;
      DWORD dwAccountSize,
      dwDomainSize;
      char *pszAccount,
      *pszDomain;

      if (GetNamedSecurityInfo(
      (LPSTR) lpszObjectName,
      SE_FILE_OBJECT,
      OWNER_SECURITY_INFORMATION,
      &pSidOwner,
      NULL,
      NULL,
      NULL,
      &pSecurityDescriptor) == ERROR_SUCCESS)
      {
      dwAccountSize = 0;
      dwDomainSize = 0;

      LookupAccountSid(NULL, pSidOwner, NULL, &dwAccountSize, NULL, &dwDomainSize, &rSidNameUse);
      
      pszAccount = new char\[dwAccountSize\];
      pszDomain  = new char\[dwDomainSize\];
      
      if (LookupAccountSid(NULL, pSidOwner, pszAccount, &dwAccountSize, pszDomain, &dwDomainSize, &rSidNameUse) == TRUE)
          ...
      
      delete \[\] pszAccount;    
      delete \[\] pszDomain;
      
      LocalFree(pSecurityDescriptor);
      

      }


      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

      D 1 Reply Last reply
      0
      • D David Crow

        I use something like:

        PSECURITY_DESCRIPTOR pSecurityDescriptor;
        PSID pSidOwner;
        SID_NAME_USE rSidNameUse;
        DWORD dwAccountSize,
        dwDomainSize;
        char *pszAccount,
        *pszDomain;

        if (GetNamedSecurityInfo(
        (LPSTR) lpszObjectName,
        SE_FILE_OBJECT,
        OWNER_SECURITY_INFORMATION,
        &pSidOwner,
        NULL,
        NULL,
        NULL,
        &pSecurityDescriptor) == ERROR_SUCCESS)
        {
        dwAccountSize = 0;
        dwDomainSize = 0;

        LookupAccountSid(NULL, pSidOwner, NULL, &dwAccountSize, NULL, &dwDomainSize, &rSidNameUse);
        
        pszAccount = new char\[dwAccountSize\];
        pszDomain  = new char\[dwDomainSize\];
        
        if (LookupAccountSid(NULL, pSidOwner, pszAccount, &dwAccountSize, pszDomain, &dwDomainSize, &rSidNameUse) == TRUE)
            ...
        
        delete \[\] pszAccount;    
        delete \[\] pszDomain;
        
        LocalFree(pSecurityDescriptor);
        

        }


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        D Offline
        D Offline
        Dimitris Vikeloudas
        wrote on last edited by
        #3

        Thanks. I do not think that the GetNamedSecurityInfo versus a combination GetFileSecurity, GetSecurityOwnerDescriptor will make much difference. To my view if I have two functions I localise slightly the failure. In the GetFileSecurity I know that I faild to get the file SID whilst with GetSecurityOwnerDescriptor I know I faild to get the owner account SID. Unless the GetNamedSecurityInfo returns a different account SID from the proposed combination. My real question is again the two calls of the LookupAccountSid. Like your case how do I know that the first one faild due to zero buffer size and not for any other reason (e.g. the file is across the network and the network went down when I was examining, or the file is been deleted and been left with a duggling pSidOwner). Also will one call set both buffer sizes or one of them and then will fail again because the second buffer is still NULL? Any detailed documentation on the failures will be great. Its an art to keep things simple

        D 1 Reply Last reply
        0
        • D Dimitris Vikeloudas

          Thanks. I do not think that the GetNamedSecurityInfo versus a combination GetFileSecurity, GetSecurityOwnerDescriptor will make much difference. To my view if I have two functions I localise slightly the failure. In the GetFileSecurity I know that I faild to get the file SID whilst with GetSecurityOwnerDescriptor I know I faild to get the owner account SID. Unless the GetNamedSecurityInfo returns a different account SID from the proposed combination. My real question is again the two calls of the LookupAccountSid. Like your case how do I know that the first one faild due to zero buffer size and not for any other reason (e.g. the file is across the network and the network went down when I was examining, or the file is been deleted and been left with a duggling pSidOwner). Also will one call set both buffer sizes or one of them and then will fail again because the second buffer is still NULL? Any detailed documentation on the failures will be great. Its an art to keep things simple

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Dimitris Vikeloudas wrote: Like your case how do I know that the first one faild due to zero buffer size and not for any other reason It returns ERROR_INSUFFICIENT_BUFFER. Dimitris Vikeloudas wrote: Also will one call set both buffer sizes or one of them and then will fail again because the second buffer is still NULL? They are both set to the necessary size.


          "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups