Click here to Skip to main content
15,894,260 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: AfxMessageBox stop working after split the frame Pin
Demian Panello26-May-07 3:41
Demian Panello26-May-07 3:41 
GeneralRe: AfxMessageBox stop working after split the frame Pin
gurucplusplus26-May-07 6:58
gurucplusplus26-May-07 6:58 
GeneralRe: AfxMessageBox stop working after split the frame Pin
Demian Panello26-May-07 14:34
Demian Panello26-May-07 14:34 
GeneralRe: AfxMessageBox stop working after split the frame Pin
gurucplusplus27-May-07 20:03
gurucplusplus27-May-07 20:03 
QuestionGetting handle of folders with CreateFile Pin
Akin Ocal25-May-07 11:46
Akin Ocal25-May-07 11:46 
AnswerRe: Getting handle of folders with CreateFile Pin
Mark Salsbery25-May-07 11:57
Mark Salsbery25-May-07 11:57 
QuestionHow to enum access permissions and SIDs Pin
Akin Ocal25-May-07 11:45
Akin Ocal25-May-07 11:45 
AnswerRe: How to enum access permissions and SIDs Pin
Hans Dietrich26-May-07 15:30
mentorHans Dietrich26-May-07 15:30 
You can use NetUserEnum() and NetQueryDisplayInformation() to enumerate the user accounts, and then use something like the following to check the access rights:
// check if the current user have permission to update a given file?

ace_list*       m_sAceList = NULL;              // list of Access Control Entries
BOOL bSuccess = TRUE;
BYTE* pSecDescriptorBuf;
DWORD dwSizeNeeded = 0;

// Find out size of needed buffer for security descriptor with DACL
// DACL = Discretionary Access Control List
bSuccess = GetFileSecurityW((BSTR)sPath,
                            DACL_SECURITY_INFORMATION,
                            NULL,
                            0,
                            &dwSizeNeeded);

if (0 == dwSizeNeeded)
{
    return failure;
}
pSecDescriptorBuf = new BYTE[dwSizeNeeded];

// Retrieve security descriptor with DACL information
bSuccess = GetFileSecurityW((BSTR)sPath,
                            DACL_SECURITY_INFORMATION,
                            pSecDescriptorBuf,
                            dwSizeNeeded,
                            &dwSizeNeeded);

// Check if we successfully retrieved security descriptor with DACL information
if (!bSuccess)
{
    DWORD dwError = GetLastError();
    return failure;
}

// Getting DACL from Security Descriptor
PACL pacl;
BOOL bDaclPresent, bDaclDefaulted;
bSuccess =
GetSecurityDescriptorDacl((SECURITY_DESCRIPTOR*)pSecDescriptorBuf,
                          &bDaclPresent, &pacl, &bDaclDefaulted);

// Check if we successfully retrieved DACL
if (!bSuccess)
{
    DWORD dwError = GetLastError();
    //cout << "Failed to retrieve DACL from security descriptor (" <<
    dwError << ")\n";
    return failure;
}

// Check if DACL present in security descriptor
if (!bDaclPresent)
{
    //cout << "DACL was not found.\n";
    return failure;
}

//Check to see if the current user has access.
wchar_t wszAccName[100] = L"";
DWORD accNameSize = sizeof(wszAccName);
PSID ppSid;
DWORD cbSid = 0;
DWORD cchDomainName = 0;
//DWORD dwDomainBufferSize = INITIAL_SIZE;
wchar_t * wszDomainName = NULL;
SID_NAME_USE eSidType;

//Allocate SID buffer.
ppSid = (PSID) new BYTE[1024];
cbSid = 1024;
wszDomainName = new wchar_t[1024];
cchDomainName = 1024;

if (!GetUserName( wszAccName, &accNameSize ) ){
    //fail
}
if (LookupAccountName( NULL, // Computer name.NULL for the local
    computer
    wszAccName, ppSid, // Pointer to the SID buffer. Use NULL to get the
    size needed,
    &cbSid, // Size of the SID buffer needed.
    wszDomainName, // wszDomainName,
    &cchDomainName, &eSidType ))
{
    if (IsValidSid(ppSid) == FALSE)
    {
        gMessageBox("Error: Invalid SID for %s.", wszAccName);
        return failure;
    } else {

        TRUSTEE trustee;
        BuildTrusteeWithSid(&trustee, ppSid);

        ACCESS_MASK mask = 0;
        DWORD dwRetVal = GetEffectiveRightsFromAcl(pacl,
            &trustee,
            &mask);

        if (!(mask & 65536)){
            Assert(false);
            return failure;
        }
        //Note - these below are never hit. This is the first sign that things
        are going wrong...
            if (mask & FILE_READ_DATA) DebugOut("can read");
            if (mask & FILE_WRITE_DATA) DebugOut("can write");
            if (mask & FILE_EXECUTE) DebugOut("can exe");
    }
} else {
    DWORD lErrorCode = GetLastError(); // Check if one of the buffers was
    too small.
        if (lErrorCode == ERROR_INSUFFICIENT_BUFFER){
        }
}



GeneralRe: How to enum access permissions and SIDs Pin
Akin Ocal26-May-07 15:37
Akin Ocal26-May-07 15:37 
QuestionHow to use map file for finding the crash in DLL? Pin
tom groezer25-May-07 11:27
tom groezer25-May-07 11:27 
AnswerRe: How to use map file for finding the crash in DLL? Pin
Taka Muraoka26-May-07 1:17
Taka Muraoka26-May-07 1:17 
AnswerRe: How to use map file for finding the crash in DLL? Pin
Stephen Hewitt27-May-07 15:02
Stephen Hewitt27-May-07 15:02 
QuestionTop-level windows Pin
Perspx25-May-07 11:25
Perspx25-May-07 11:25 
AnswerRe: Top-level windows Pin
Arman S.26-May-07 1:36
Arman S.26-May-07 1:36 
QuestionSet DC Font Pin
Perspx25-May-07 11:05
Perspx25-May-07 11:05 
AnswerRe: Set DC Font Pin
Mark Salsbery25-May-07 12:03
Mark Salsbery25-May-07 12:03 
QuestionProject Settings Pin
tom groezer25-May-07 10:19
tom groezer25-May-07 10:19 
QuestionRe: Project Settings Pin
CPallini25-May-07 10:21
mveCPallini25-May-07 10:21 
AnswerRe: Project Settings Pin
tom groezer27-May-07 22:17
tom groezer27-May-07 22:17 
QuestionDLL Pin
tom groezer25-May-07 9:59
tom groezer25-May-07 9:59 
AnswerRe: DLL Pin
Mark Salsbery25-May-07 10:45
Mark Salsbery25-May-07 10:45 
AnswerRe: DLL Pin
JudyL_MD25-May-07 10:50
JudyL_MD25-May-07 10:50 
Questionruntime vector creating Pin
g3RC4n25-May-07 6:51
g3RC4n25-May-07 6:51 
QuestionRe: runtime vector creating Pin
David Crow25-May-07 7:25
David Crow25-May-07 7:25 
AnswerRe: runtime vector creating Pin
Mark Salsbery25-May-07 7:35
Mark Salsbery25-May-07 7:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.