struct pw_scheme *s;
for( s=(struct pw_scheme *)pw_schemes_default; s->name.bv_val; s++) {
- if ( lutil_passwd_add( &s->name, s->chk_fn, s->hash_fn )) break;
+ if ( lutil_passwd_add( &s->name, s->chk_fn, s->hash_fn ) ) break;
}
}
pw.bv_val = ber_memalloc( pw.bv_len + 1 );
if( pw.bv_val == NULL ) {
- return -1;
+ return LUTIL_PASSWD_ERR;
}
AC_MEMCPY( pw.bv_val, sc->bv_val, sc->bv_len );
pw.bv_val[pw.bv_len] = '\0';
*passwd = pw;
- return 0;
+ return LUTIL_PASSWD_OK;
}
#endif /* SLAPD_LMHASH || SLAPD_CRYPT */
string.bv_val = ber_memalloc( string.bv_len + 1 );
if( string.bv_val == NULL ) {
- return -1;
+ return LUTIL_PASSWD_ERR;
}
AC_MEMCPY( string.bv_val, hash->bv_val,
if( b64->bv_val == NULL ) {
if( salt ) ber_memfree( string.bv_val );
- return -1;
+ return LUTIL_PASSWD_ERR;
}
AC_MEMCPY(b64->bv_val, sc->bv_val, sc->bv_len);
if( salt ) ber_memfree( string.bv_val );
if( rc < 0 ) {
- return rc;
+ return LUTIL_PASSWD_ERR;
}
/* recompute length */
b64->bv_len = sc->bv_len + rc;
assert( strlen(b64->bv_val) == b64->bv_len );
- return 0;
+ return LUTIL_PASSWD_OK;
}
/* PASSWORD CHECK ROUTINES */
/* safety check */
if (LUTIL_BASE64_DECODE_LEN(passwd->bv_len) <
sizeof(SHA1digest)+SALT_SIZE) {
- return -1;
+ return LUTIL_PASSWD_ERR;
}
/* decode base64 password */
orig_pass = (unsigned char *) ber_memalloc( (size_t) (
LUTIL_BASE64_DECODE_LEN(passwd->bv_len) + 1) );
- if( orig_pass == NULL ) return -1;
+ if( orig_pass == NULL ) return LUTIL_PASSWD_ERR;
rc = lutil_b64_pton(passwd->bv_val, orig_pass, passwd->bv_len);
if (rc < (int)(sizeof(SHA1digest)+SALT_SIZE)) {
ber_memfree(orig_pass);
- return -1;
+ return LUTIL_PASSWD_ERR;
}
/* hash credentials with salt */
/* compare */
rc = memcmp((char *)orig_pass, (char *)SHA1digest, sizeof(SHA1digest));
ber_memfree(orig_pass);
- return rc ? 1 : 0;
+ return rc ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
static int chk_sha1(
/* safety check */
if (LUTIL_BASE64_DECODE_LEN(passwd->bv_len) < sizeof(SHA1digest)) {
- return -1;
+ return LUTIL_PASSWD_ERR;
}
/* base64 un-encode password */
orig_pass = (unsigned char *) ber_memalloc( (size_t) (
LUTIL_BASE64_DECODE_LEN(passwd->bv_len) + 1) );
- if( orig_pass == NULL ) return -1;
+ if( orig_pass == NULL ) return LUTIL_PASSWD_ERR;
rc = lutil_b64_pton(passwd->bv_val, orig_pass, passwd->bv_len);
if( rc != sizeof(SHA1digest) ) {
ber_memfree(orig_pass);
- return -1;
+ return LUTIL_PASSWD_ERR;
}
/* hash credentials with salt */
/* compare */
rc = memcmp((char *)orig_pass, (char *)SHA1digest, sizeof(SHA1digest));
ber_memfree(orig_pass);
- return rc ? 1 : 0;
+ return rc ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
#endif
/* safety check */
if (LUTIL_BASE64_DECODE_LEN(passwd->bv_len) <
sizeof(MD5digest)+SALT_SIZE) {
- return -1;
+ return LUTIL_PASSWD_ERR;
}
/* base64 un-encode password */
orig_pass = (unsigned char *) ber_memalloc( (size_t) (
LUTIL_BASE64_DECODE_LEN(passwd->bv_len) + 1) );
- if( orig_pass == NULL ) return -1;
+ if( orig_pass == NULL ) return LUTIL_PASSWD_ERR;
rc = lutil_b64_pton(passwd->bv_val, orig_pass, passwd->bv_len);
if (rc < (int)(sizeof(MD5digest)+SALT_SIZE)) {
ber_memfree(orig_pass);
- return -1;
+ return LUTIL_PASSWD_ERR;
}
/* hash credentials with salt */
/* compare */
rc = memcmp((char *)orig_pass, (char *)MD5digest, sizeof(MD5digest));
ber_memfree(orig_pass);
- return rc ? 1 : 0;
+ return rc ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
static int chk_md5(
/* safety check */
if (LUTIL_BASE64_DECODE_LEN(passwd->bv_len) < sizeof(MD5digest)) {
- return -1;
+ return LUTIL_PASSWD_ERR;
}
/* base64 un-encode password */
orig_pass = (unsigned char *) ber_memalloc( (size_t) (
LUTIL_BASE64_DECODE_LEN(passwd->bv_len) + 1) );
- if( orig_pass == NULL ) return -1;
+ if( orig_pass == NULL ) return LUTIL_PASSWD_ERR;
rc = lutil_b64_pton(passwd->bv_val, orig_pass, passwd->bv_len);
if ( rc != sizeof(MD5digest) ) {
ber_memfree(orig_pass);
- return -1;
+ return LUTIL_PASSWD_ERR;
}
/* hash credentials with salt */
/* compare */
rc = memcmp((char *)orig_pass, (char *)MD5digest, sizeof(MD5digest));
ber_memfree(orig_pass);
- return rc ? 1 : 0;
+ return rc ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
#ifdef SLAPD_LMHASH
for( i=0; i<cred->bv_len; i++) {
if(cred->bv_val[i] == '\0') {
- return -1; /* NUL character in password */
+ return LUTIL_PASSWD_ERR; /* NUL character in password */
}
}
if( cred->bv_val[i] != '\0' ) {
- return -1; /* passwd must behave like a string */
+ return LUTIL_PASSWD_ERR; /* passwd must behave like a string */
}
strncpy( UcasePassword, cred->bv_val, 14 );
storedPasswordHash[32] = '\0';
ldap_pvt_str2lower( storedPasswordHash );
- return memcmp( PasswordHash, storedPasswordHash, 32) ? 1 : 0;
+ return memcmp( PasswordHash, storedPasswordHash, 32) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
#endif /* SLAPD_LMHASH */
for( i=0; i<cred->bv_len; i++) {
if(cred->bv_val[i] == '\0') {
- return 1; /* NUL character in password */
+ return LUTIL_PASSWD_ERR; /* NUL character in password */
}
}
if( cred->bv_val[i] != '\0' ) {
- return 1; /* cred must behave like a string */
+ return LUTIL_PASSWD_ERR; /* cred must behave like a string */
}
for( i=0; i<passwd->bv_len; i++) {
if(passwd->bv_val[i] == '\0') {
- return 1; /* NUL character in password */
+ return LUTIL_PASSWD_ERR; /* NUL character in password */
}
}
if( passwd->bv_val[i] != '\0' ) {
- return 1; /* passwd must behave like a string */
+ return LUTIL_PASSWD_ERR; /* passwd must behave like a string */
}
- rtn = 1;
+ rtn = LUTIL_PASSWD_ERR;
#ifdef HAVE_CYRUS_SASL
if( lutil_passwd_sasl_conn != NULL ) {
passwd->bv_val, passwd->bv_len,
cred->bv_val, cred->bv_len );
# endif
- rtn = ( sc != SASL_OK );
+ rtn = ( sc != SASL_OK ) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
#endif
for( i=0; i<cred->bv_len; i++) {
if(cred->bv_val[i] == '\0') {
- return 1; /* NUL character in password */
+ return LUTIL_PASSWD_ERR; /* NUL character in password */
}
}
if( cred->bv_val[i] != '\0' ) {
- return -1; /* cred must behave like a string */
+ return LUTIL_PASSWD_ERR; /* cred must behave like a string */
}
if( passwd->bv_len < 2 ) {
- return -1; /* passwd must be at least two characters long */
+ return LUTIL_PASSWD_ERR; /* passwd must be at least two characters long */
}
for( i=0; i<passwd->bv_len; i++) {
if(passwd->bv_val[i] == '\0') {
- return -1; /* NUL character in password */
+ return LUTIL_PASSWD_ERR; /* NUL character in password */
}
}
if( passwd->bv_val[i] != '\0' ) {
- return -1; /* passwd must behave like a string */
+ return LUTIL_PASSWD_ERR; /* passwd must behave like a string */
}
cr = crypt( cred->bv_val, passwd->bv_val );
if( cr == NULL || cr[0] == '\0' ) {
/* salt must have been invalid */
- return -1;
+ return LUTIL_PASSWD_ERR;
}
- return strcmp( passwd->bv_val, cr ) ? 1 : 0;
+ return strcmp( passwd->bv_val, cr ) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
# if defined( HAVE_GETPWNAM ) && defined( HAVE_PW_PASSWD )
for( i=0; i<cred->bv_len; i++) {
if(cred->bv_val[i] == '\0') {
- return -1; /* NUL character in password */
+ return LUTIL_PASSWD_ERR; /* NUL character in password */
}
}
if( cred->bv_val[i] != '\0' ) {
- return -1; /* cred must behave like a string */
+ return LUTIL_PASSWD_ERR; /* cred must behave like a string */
}
for( i=0; i<passwd->bv_len; i++) {
if(passwd->bv_val[i] == '\0') {
- return -1; /* NUL character in password */
+ return LUTIL_PASSWD_ERR; /* NUL character in password */
}
}
if( passwd->bv_val[i] != '\0' ) {
- return -1; /* passwd must behave like a string */
+ return LUTIL_PASSWD_ERR; /* passwd must behave like a string */
}
{
struct passwd *pwd = getpwnam(passwd->bv_val);
if(pwd == NULL) {
- return -1; /* not found */
+ return LUTIL_PASSWD_ERR; /* not found */
}
pw = pwd->pw_passwd;
if( pw == NULL || pw[0] == '\0' || pw[1] == '\0' ) {
/* password must must be at least two characters long */
- return -1;
+ return LUTIL_PASSWD_ERR;
}
cr = crypt(cred->bv_val, pw);
if( cr == NULL || cr[0] == '\0' ) {
/* salt must have been invalid */
- return -1;
+ return LUTIL_PASSWD_ERR;
}
- return strcmp(pw, cr) ? 1 : 0;
+ return strcmp(pw, cr) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
# endif
salt.bv_len = sizeof(saltdata);
if( lutil_entropy( (unsigned char *) salt.bv_val, salt.bv_len) < 0 ) {
- return -1;
+ return LUTIL_PASSWD_ERR;
}
lutil_SHA1Init( &SHA1context );
salt.bv_len = sizeof(saltdata);
if( lutil_entropy( (unsigned char *) salt.bv_val, salt.bv_len) < 0 ) {
- return -1;
+ return LUTIL_PASSWD_ERR;
}
lutil_MD5Init( &MD5context );
for( i=0; i<passwd->bv_len; i++) {
if(passwd->bv_val[i] == '\0') {
- return -1; /* NUL character in password */
+ return LUTIL_PASSWD_ERR; /* NUL character in password */
}
}
if( passwd->bv_val[i] != '\0' ) {
- return -1; /* passwd must behave like a string */
+ return LUTIL_PASSWD_ERR; /* passwd must behave like a string */
}
strncpy( UcasePassword, passwd->bv_val, 14 );
for( i=0; i<passwd->bv_len; i++) {
if(passwd->bv_val[i] == '\0') {
- return -1; /* NUL character in password */
+ return LUTIL_PASSWD_ERR; /* NUL character in password */
}
}
if( passwd->bv_val[i] != '\0' ) {
- return -1; /* passwd must behave like a string */
+ return LUTIL_PASSWD_ERR; /* passwd must behave like a string */
}
if( lutil_entropy( salt, sizeof( salt ) ) < 0 ) {
- return -1;
+ return LUTIL_PASSWD_ERR;
}
for( i=0; i< ( sizeof(salt) - 1 ); i++ ) {
hash->bv_len = strlen( hash->bv_val );
if( hash->bv_len == 0 ) {
- return -1;
+ return LUTIL_PASSWD_ERR;
}
return pw_string( scheme, hash );
const char **text )
{
ber_dupbv( hash, (struct berval *)passwd );
- return 0;
+ return LUTIL_PASSWD_OK;
}
#endif