Archive: Odd AccessControl error


Odd AccessControl error
I'm using the AccessControl plugin to set the rights on a data directory set up by my installer. The directory is freshly-created and known to exist, so the user running install will be its "CREATOR OWNER" and should have authority to set the access.

However, I'm occasionally -- not always, but I haven't spotted a trend -- getting error "22" returned. Looking at the source for the plugin I see that errors are usually textual, and that "22" doesn't seem to be one of them!

Here's the code snippet:


; create the data directory
ClearErrors
CreateDirectory "$MBDir"

${If} ${Errors}
Abort "Can't create MessageBase directory $MBDir"
${EndIf}

; Set access permissions on $MBDir -- read write accessible by all users
; We have to use "(S-1-1-0)" instead of "World" or "(WD)" for Win2k
ClearErrors
AccessControl::GrantOnFile "$MBDir" "(S-1-1-0)" "GenericRead + GenericWrite + DeleteChild"
pop $0

${If} $0 != ""
MessageBox MB_OK "Error $0 granting access to $MBDir "
${EndIf}

The message I'm getting in the message box is typically something like "Error 22 granting access to E:\MyApp\Data ". The directory name is correct, and the directory has been created.

Can anyone tell me what this actually means? I take it I am calling the plugin correctly, and that GrantOnFile is meant to be usable on directories as well as normal files?

The Windows error code 22 is ERROR_BAD_COMMAND which is documented as meaning "The device does not recognize the command". I believe that's normally returned by IOCtl-type calls to devices, and not by access control APIs.

I'm testing this on XP64, BTW, but it's intended to be usable on all NT-class systems.

AccessControl does not push anything to the stack if there were no errors. Therefore your value in $0 is coming from a stack item that was already on the stack before you called the plug-in.

I will change this in the next version.

Stu


Originally posted by Afrow UK
AccessControl does not push anything to the stack if there were no errors. Therefore your value in $0 is coming from a stack item that was already on the stack before you called the plug-in.

I will change this in the next version.
OK, thanks, Stu ... that makes sense.

What's the best workaround? Is there any other indication of an error -- way to tell whether anything has been pushed onto the stack -- apart from calling pop?

I could do something like:

ClearErrors
Push "OK"
AccessControl::GrantOnFile "$MBDir" "(S-1-1-0)" "GenericRead + GenericWrite + DeleteChild"
pop $0

${If} $0 != "OK"
MessageBox MB_OK "Error $0 granting access to $MBDir "
pop $0 ; remove the "OK"
${EndIf}

Can you think of anything better?

Cheers,
Daniel.

That is what I was doing until I decided to start updating the plug-in myself.

Stu