in src/Zyborg.PassCore.PasswordProvider.LDAP/LdapPasswordChangeProvider.cs [170:197]
private static ApiErrorItem ParseLdapException(LdapException ex)
{
// If the LDAP server returned an error, it will be formatted
// similar to this:
// "0000052D: AtrErr: DSID-03191083, #1:\n\t0: 0000052D: DSID-03191083, problem 1005 (CONSTRAINT_ATT_TYPE), data 0, Att 9005a (unicodePwd)\n\0"
//
// The leading number before the ':' is the Win32 API Error Code in HEX
if (ex.LdapErrorMessage == null)
{
return new ApiErrorItem(ApiErrorCode.LdapProblem, "Unexpected null exception");
}
var m = Regex.Match(ex.LdapErrorMessage, "([0-9a-fA-F]+):");
if (!m.Success)
{
return new ApiErrorItem(ApiErrorCode.LdapProblem, $"Unexpected error: {ex.LdapErrorMessage}");
}
var errCodeString = m.Groups[1].Value;
var errCode = int.Parse(errCodeString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var err = Win32ErrorCode.ByCode(errCode);
return err == null
? new ApiErrorItem(ApiErrorCode.LdapProblem, $"Unexpected Win32 API error; error code: {errCodeString}")
: new ApiErrorItem(ApiErrorCode.InvalidCredentials,
$"Resolved Win32 API Error: code={err.Code} name={err.CodeName} desc={err.Description}");
}