Skip to content

MOSS 2007 – C# Protocol Handler errors fixed

On CodePlex you can find the MOSS 2007 - C# Protocol Handler project. I am currently using this in a project to index a custom content source.

When working with the code I discovered two issues which I both fixed. Both solutions are posted in the discussions and/or submitted as patch and I will summarize them here.

Running on x64

The first problem is the code not working in x64 environments. Since we are talking to native code, there are a lot of structs in the code. These structs are containing metadata to indicate the layout in memory. This is done using the StructLayoutAttribute Class which contains a Value Property with a LayoutKind Enumeration and a Pack Field.

The problem is the Pack value was set to 1. This is normal for 32bit systems, but not for 64bit where a pack of 8 is expected.

Lucky enough, the following is written in the remarks section:

A value of 0 indicates that the packing alignment is set to the default for the current platform.

This solves our problem! Now the same code runs fine on both x86 and x64 systems.

Using Security Descriptors

One of the most important features of SharePoint search is security trimming. To make this possible an ACL Structure is stored with the crawled item in the index database. The problem is when the ACL is larger then 1kB the crawler goes into an endless loop.

The way it should go is the search service calling the GetSecurityDescriptor method with a pointer and a size. This size is 1024 by default. When the ACL is larger an ERROR_INSUFFICIENT_BUFFER error message should be returned and the required size should be set. The search service then should allocate enough memory and call the GetSecurityDescriptor method again, which is now able to assign the complete ACL to the pointer.

The problem with the current version on CodePlex is the value of the error message is incorrect. Instead of 0x00000122 it should be 0x8007007A (which is also 112).

After changing the code, the ACL will be stored (as long as it’s staying <64kB).