|
Windows 2003 anonymous access to shared folders (Personal | Software)
Due to tightened default security in Windows 2003 the file shares cannot be accessed without logon in a domainless environment even if both shares and folders are set up to allow access to Everyone.
A bit of googling returns many different suggestions for solving the problem, none of which really seems to work for sure. I’m just adding my two cents to this confusion, hoping that this posting will help me the next I’ll be solving the same problem.
It’s all about configuring the Security options in Local Security policy. The logical path of enabling the Network Access: Let Everyone permissions apply to anonymous users policy and disabling the Network access: Restrict anonymous access to Named Pipes and Shares policy didn’t help. On the other hand enabling the Accounts: Guest account status policy and setting the Network access: Sharing and security model for local accounts policy to Guest only - local users authenticate as Guest did the trick. Don't forget to call gpupdate after changing the policy to enforce it immediately.
I’m not asserting that this is THE solution but it worked for me. However, you should be aware of the implications of enabling the guest account before doing it to solve your immediate problem.
A few additional words on the last mentioned policy change: It proves useful when the file server and the client have the same usernames defined but the passwords don’t match because it forces the client to login as guest. By default the client tries to login to the server with wrong password which once again causes the login prompt to appear. It is useful to keep the default setting when the password is the same because the auto login allows for granularity in security settings if more than equal permissions for everyone are needed.
5/28/2006 2:49:50 PM (Central Europe Standard Time, UTC+01:00)
Marshalling System.String to char* and vice-versa (Development | .NET | C++)
By switching from C# with P/Invoke calls to Managed C++ when implementing a managed wrapper for the ANSI C style library I stumbled upon, I wanted to avoid the tedious and error-prone task of writing the P/Invoke signatures for function calls and user-defined types for the structures they used. As a side result I also managed to avoid most of the advanced marshalling issues with complex data structures.
With simple value types not needing any explicit marshalling only strings need special attention since char* and System::String can’t be implicitly converted between. The Marshal class implements the methods necessary for doing this as demonstrated in the following snippet:
String^ MCPP::Together(String^ first, String^ second) { // marshal managed strings to unamanged memory IntPtr firstPtr = Marshal::StringToHGlobalAnsi(first); IntPtr secondPtr = Marshal::StringToHGlobalAnsi(second);
// cast unmanaged buffer to a characer array char* firstNative = static_cast<char*>(firstPtr.ToPointer()); char* secondNative = static_cast<char*>(secondPtr.ToPointer());
// perform some unmanaged calls int bufferSize = strlen(firstNative) + strlen(secondNative) + 4; char* resultBuffer = new char[bufferSize]; sprintf_s(resultBuffer, bufferSize, "%s + %s", firstNative, secondNative); // marshal unmanaged character array to managed string String^ result = Marshal::PtrToStringAnsi(static_cast<IntPtr>(resultBuffer)); // free all unmanaged buffers delete[] resultBuffer; Marshal::FreeHGlobal(firstPtr); Marshal::FreeHGlobal(secondPtr); // return managed string return result; }
It should be noted that it wouldn’t make any sense switching to unmanaged code to do some string operations only as shown above. This is for demonstration purposes only and you would usually call some unmanaged libraries or the like instead of it. But it is a nice demonstration how cumbersome string operations were in C. If you were doing this once, the sprintf_s function call might have caught your attention. It’s a safe implementation of sprintf which prevents buffer overflows.
Another point worth mentioning is that you have to take care of allocated memory for the conversion since your character array is now allocated on the unmanaged heap. Make sure you use the FreeHGlobal method to do it, not the free (used for freeing memory allocated by *alloc calls – ANSI C style) or delete (used for freeing memory allocated by new calls – C++ style) functions.
To reduce the code overhead of string conversions between managed and unmanaged world you might consider wrapping it into a helper class. This should also help preventing unwanted memory leaks during the conversions.
5/28/2006 1:41:03 PM (Central Europe Standard Time, UTC+01:00)
|