LDAP_PASSWORD_POLICY

Use the LDAP_PASSWORD_POLICY API or LDAP routine to extract information from results that are returned in the Password Policy Control structure.

  • ldap_parse_pwdpolicy_response
  • ldap_pwdpolicy_err2string

Synopsis

#include ldap.h

int ldap_parse_pwdpolicy_response(LDAPCONTROL **serverControls, 
       int *controlerr,
       int *controlwarn, 
       int *controlres);

static struct ldaperror ldap_ctrlerr[] = {
    LDAP_SUCCESS,                       "Success",
    LDAP_TIME_BEFORE_EXPIRE,            "Warning, time before expiration is %ld",
    LDAP_GRACE_LOGINS,                  "Warning, %ld grace logins remain",
    LDAP_PASSWORD_EXPIRED,              "Error, Password has expired",
    LDAP_ACCOUNT_LOCKED,                "Error, Account is locked",
    LDAP_CHANGE_AFTER_RESET,            "Error, Password must be changed after reset",
    LDAP_PASSWORD_NO_MOD,               "Error, Password may not be modified",
    LDAP_NEED_OLD_PASSWORD,             "Error, Must supply old password",
    LDAP_INVALID_PASS_SYNTAX,           "Error, Invalid password syntax",
    LDAP_PASSWORD_TOO_SHORT,            "Error, Password too short",
    LDAP_PASSWORD_TOO_YOUNG,            "Error, Password too young",
    LDAP_PASSWORD_IN_HISTORY,           "Error, Password in History",
    -1, NULL
};

const char *ldap_pwdpolicy_err2string(int err);

Input parameters

serverControls
Specifies an array of LDAPCONTROL pointers that are returned by a previous call to ldap_parse_result().
controlerr
Specifies a pointer to the result parameter that is provided with the LDAP Password Policy error code, which can be used as input to ldap_pwdpolicy_err2string(), so that a text description of the error can be obtained.
controlwarn
Specifies a pointer to the result parameter that is provided with the LDAP Password Policy warning code, which can be used as input to ldap_pwdpolicy_err2string(), so that a text description of the warning can be obtained.
controlres
Specifies a pointer to the result parameter that is provided with the LDAP Password Policy warning result value.
err
Specifies an integer value that is returned from ldap_parse_pwdpolicy_response() that contains the Password Policy warning or error code.

Usage

The ldap_parse_pwdpolicy_response() API is used to:
  • Obtain the LDAP Password Policy error or warning codes from the Password Policy Response Control that is associated with an LDAPMessage message.
  • Obtain the LDAP Password Policy warning result code from the Password Policy Response Control that is associated with the returned Password Policy warning code.
  • This function takes in an array of LDAPCONTROL structure pointers, parses these structures, and then returns three integers that contain the Password Policy response values.

The static struct ldaperror ldap_ctrlerr array contains the LDAP error code that is associated with the password policy and the corresponding text description of the LDAP error code. Unlike the familiar ldap_error2string, for warnings, you get a string with %d format, and pass it to the printf() function along with the returned controlres to get the final diagnostic string. In some cases, the text description string has %ld, and expects some parameters before it can be printed.

The ldap_pwdpolicy_err2string() API is used to convert the numerical LDAP Password Policy error or warning code, as returned by ldap_parse_pwdpolicy_response(), into a NULL-terminated character string that describes the error or warning. The character string is returned as static data and must not be freed by the application.

Errors

The ldap_parse_pwdpolicy_response routine returns an LDAP error code if it encounters an error that parses the result.

See LDAP_ERROR for a list of the LDAP error codes.

See also

ldap_parse_result