1
/* $OpenLDAP: pkg/ldap/contrib/slapd-modules/passwd/netscape.c,v 1.5.2.3 2008/02/11 23:26:38 kurt Exp $ */
3
* Copyright 1998-2008 The OpenLDAP Foundation.
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted only as authorized by the OpenLDAP
10
* A copy of this license is available in the file LICENSE in the
11
* top-level directory of the distribution or, alternatively, at
12
* <http://www.OpenLDAP.org/license.html>.
20
#include "lutil_md5.h"
21
#include <ac/string.h>
23
static LUTIL_PASSWD_CHK_FUNC chk_ns_mta_md5;
24
static const struct berval scheme = BER_BVC("{NS-MTA-MD5}");
26
#define NS_MTA_MD5_PASSLEN 64
27
static int chk_ns_mta_md5(
28
const struct berval *scheme,
29
const struct berval *passwd,
30
const struct berval *cred,
33
lutil_MD5_CTX MD5context;
34
unsigned char MD5digest[LUTIL_MD5_BYTES], c;
35
char buffer[LUTIL_MD5_BYTES*2];
38
if( passwd->bv_len != NS_MTA_MD5_PASSLEN ) {
39
return LUTIL_PASSWD_ERR;
42
/* hash credentials with salt */
43
lutil_MD5Init(&MD5context);
44
lutil_MD5Update(&MD5context,
45
(const unsigned char *) &passwd->bv_val[32],
49
lutil_MD5Update(&MD5context,
50
(const unsigned char *) &c,
53
lutil_MD5Update(&MD5context,
54
(const unsigned char *) cred->bv_val,
58
lutil_MD5Update(&MD5context,
59
(const unsigned char *) &c,
62
lutil_MD5Update(&MD5context,
63
(const unsigned char *) &passwd->bv_val[32],
66
lutil_MD5Final(MD5digest, &MD5context);
68
for( i=0; i < sizeof( MD5digest ); i++ ) {
69
buffer[i+i] = "0123456789abcdef"[(MD5digest[i]>>4) & 0x0F];
70
buffer[i+i+1] = "0123456789abcdef"[ MD5digest[i] & 0x0F];
74
return memcmp((char *)passwd->bv_val,
75
(char *)buffer, sizeof(buffer)) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
78
int init_module(int argc, char *argv[]) {
79
return lutil_passwd_add( (struct berval *)&scheme, chk_ns_mta_md5, NULL );