Hi Everyone,
I'm migrating a device from Windows CE4.2 to 5.0. With the device we use a
command prompt program that allows a user to set a Network Share using
WNetAddConnection3. The point of the program is to be able to set a username
and password and then add any number of network share (on the same domain)
and make them available after a reboot without having to enter the passwork
each time.
Using 4.2 we were able to save the credentials and then pass 0 to username
and password parameters to WNetAddConnection3 and it worked. In the help
files (MSDN) it says that using 0 tells to the function to use default
username and passwork.
By using this method it give the possibility to the user to save a network
share and have it accessible after a reboot by using CONNECT_UPDATE_PROFILE
with WNetAddConnection3(It was working perfectly under 4.2, maybe it's not
possible anymore under 5.0).
Under 5.0 it doesn't work anymore. I must add that our device is a headless
device, that means that it's not possible for a dialog box to popup for
asking the user to enter the password. I suspect that the problem is with the
save credential function. Here is the code, we call this code before calling
WNetAddConnection3:
BOOL SaveDefaultCredentials(TCHAR *szUser, TCHAR *szPassword, TCHAR
*szUserFull, TCHAR *szDomain)
{
BOOL RetValue = FALSE;
CECREDENTIAL Credential;
Credential.Flags = 0;
Credential.Persist = CRED_PERSIST_LOCAL_MACHINE;
Credential.Type = CRED_TYPE_DOMAIN_PASSWORD;
Credential.UserName = szUserFull;
Credential.CredentialBlobSize = 0;
Credential.CredentialBlob = 0;
RetValue = CeCredWrite( 0, &Credential );
if (!RetValue)
{
wprintf(L"CeCredWrite error writing %s\r\n",Credential.UserName);
}
else
{
//wprintf(L"CeCredWrite success writing %s\r\n", Credential.UserName);
}
// Set password
if( RetValue )
{
SEC_WINNT_AUTH_IDENTITY_W AuthIdentity;
AuthIdentity.User = szUser;
AuthIdentity.UserLength = wcslen(szUser);
AuthIdentity.Domain = szDomain;
AuthIdentity.DomainLength = wcslen(szDomain);
AuthIdentity.Password = szPassword;
AuthIdentity.PasswordLength = wcslen(szPassword);
AuthIdentity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
RetValue = SaveSspCredentials(&AuthIdentity);
}
return RetValue;
}
BOOL SaveSspCredentials(SEC_WINNT_AUTH_IDENTITY_W *pAuthIdentity)
{
PWSTR Packages[] = {L"NTLM", L"KERBEROS"};
BOOL fRet = TRUE;
int i;
__try
{
for (i = 0; i < (sizeof(Packages) / sizeof(Packages[0])); i++)
{
CredHandle hCred; // Credential Handle
TimeStamp Lifetime;
if( AcquireCredentialsHandleW(
NULL, // Principal
Packages[i], // Names of the security packages
SECPKG_CRED_OUTBOUND,// Flag that indicates how these
credentials will be used
NULL, // LOGON id
pAuthIdentity,
NULL, // Pointer to a SEC_GET_KEY_FN function
NULL, // get key arg
&hCred, // Pointer to CredHandle structure that
receives the credential handle.
&Lifetime // Pointer to a TimeStamp
) == NO_ERROR )
{
FreeCredentialsHandle(&hCred);
}
}
}
__except(1)
{
fRet = FALSE;
wprintf(TEXT("AcquireCredentialsHandle faulted"));
}
return fRet;
}
Is this the correct way to do it in CE 5.0? I know that we should now use
CredWrite but CeCredWrite should be still supported.
Can somebody help me solve my problem?
Thanks