mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-02-17 14:00:30 +08:00
Add macros to compute base64 encode/decode lengths.
This commit is contained in:
parent
92238e52ae
commit
f4a0699311
@ -41,8 +41,6 @@
|
||||
#include "ldap_defaults.h"
|
||||
|
||||
/* local macros */
|
||||
#define CEILING(x) ((double)(x) > (int)(x) ? (int)(x) + 1 : (int)(x))
|
||||
|
||||
#define LDAP_PASSWD_ATTRIB "userPassword"
|
||||
#define LDAP_PASSWD_CONF LDAP_SYSCONFDIR LDAP_DIRSEP "passwd.conf"
|
||||
|
||||
@ -107,8 +105,10 @@ pw_encode (unsigned char *passwd, Salt * salt, unsigned int len)
|
||||
len += salt->len;
|
||||
}
|
||||
|
||||
b64_len = CEILING (len / 3) * 4 + 1;
|
||||
b64_len = LUTIL_BASE64_ENCODE_LEN(len) + 1;
|
||||
|
||||
base64digest = (char *)malloc (b64_len);
|
||||
|
||||
if (lutil_b64_ntop (npasswd, len, base64digest, b64_len) < 0)
|
||||
{
|
||||
free (base64digest);
|
||||
|
@ -19,6 +19,12 @@
|
||||
* Include file for LDAP utility routine
|
||||
*/
|
||||
|
||||
/* n octets encode into ceiling(n/3) * 4 bytes */
|
||||
/* Avoid floating point math by through extra padding */
|
||||
|
||||
#define LUTIL_BASE64_ENCODE_LEN(n) ((n)/3 * 4 + 4)
|
||||
#define LUTIL_BASE64_DECODE_LEN(n) ((n)/4 * 3)
|
||||
|
||||
LDAP_BEGIN_DECL
|
||||
|
||||
/* ISC Base64 Routines */
|
||||
|
@ -109,7 +109,7 @@ lutil_passwd(
|
||||
if ((p = passwd_scheme( passwd, "{MD5}", schemes )) != NULL ) {
|
||||
lutil_MD5_CTX MD5context;
|
||||
unsigned char MD5digest[16];
|
||||
char base64digest[25]; /* ceiling(sizeof(input)/3) * 4 + 1 */
|
||||
char base64digest[LUTIL_BASE64_ENCODE_LEN(16)];
|
||||
|
||||
lutil_MD5Init(&MD5context);
|
||||
lutil_MD5Update(&MD5context,
|
||||
@ -127,7 +127,7 @@ lutil_passwd(
|
||||
} else if ((p = passwd_scheme( passwd, "{SHA}", schemes )) != NULL ) {
|
||||
lutil_SHA1_CTX SHA1context;
|
||||
unsigned char SHA1digest[20];
|
||||
char base64digest[29]; /* ceiling(sizeof(input)/3) * 4 + 1 */
|
||||
char base64digest[LUTIL_BASE64_ENCODE_LEN(20)];
|
||||
|
||||
lutil_SHA1Init(&SHA1context);
|
||||
lutil_SHA1Update(&SHA1context,
|
||||
@ -150,7 +150,8 @@ lutil_passwd(
|
||||
unsigned char *orig_pass = NULL;
|
||||
|
||||
/* base64 un-encode password */
|
||||
orig_pass = (unsigned char *)malloc((size_t)(pw_len * 0.75 + 1));
|
||||
orig_pass = (unsigned char *) malloc( (size_t) (
|
||||
LUTIL_BASE64_DECODE_LEN(pw_len) + 1) );
|
||||
if ((rc = lutil_b64_pton(p, orig_pass, pw_len)) < 0)
|
||||
{
|
||||
free(orig_pass);
|
||||
@ -179,7 +180,8 @@ lutil_passwd(
|
||||
unsigned char *orig_pass = NULL;
|
||||
|
||||
/* base64 un-encode password */
|
||||
orig_pass = (unsigned char *)malloc((size_t)(pw_len * 0.75 + 1));
|
||||
orig_pass = (unsigned char *) malloc( (size_t) (
|
||||
LUTIL_BASE64_DECODE_LEN(pw_len) + 1) );
|
||||
if ((rc = lutil_b64_pton(p, orig_pass, pw_len)) < 0)
|
||||
{
|
||||
free(orig_pass);
|
||||
|
Loading…
Reference in New Issue
Block a user