###############################################################################
+Project: "passwd"=..\libraries\liblutil\passwd.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name liblber
+ End Project Dependency
+ Begin Project Dependency
+ Project_Dep_Name liblutil
+ End Project Dependency
+}}}
+
+###############################################################################
+
Project: "setup"=..\include\setup.dsp - Package Owner=<4>
Package=<5>
char *ldaphost = NULL;
char *newpw = NULL;
int noupdates = 0;
- int i, j;
+ int i;
int ldapport = 0;
int debug = 0;
int version = -1;
int want_bindpw = 0;
LDAP *ld;
- struct berval cred;
struct berval *bv = NULL;
BerElement *ber;
important. ANSI guarantees that "unsigned long" will be big enough,
and always using it seems to have few disadvantages. */
+#define LUTIL_MD5_BYTES 16
+
struct lutil_MD5Context {
ber_uint_t buf[4];
ber_uint_t bits[2];
* SHA-1 in C
* By Steve Reid <steve@edmweb.com>
*/
+#define LUTIL_SHA1_BYTES 20
/* This code assumes char are 8-bits and uint32 are 32-bits */
typedef ac_uint4 uint32;
}
-/*
- * ldap_init - initialize the LDAP library. A magic cookie to be used for
- * future communication is returned on success, NULL on failure.
- * "host" may be a space-separated list of hosts or IP addresses
- *
- * Example:
- * LDAP *ld;
- * ld = ldap_open( host, port );
- */
-LDAP *
-ldap_init( LDAP_CONST char *defhost, int defport )
-{
- LDAP *ld;
- int rc;
-
- rc = ldap_create(&ld);
- if ( rc != LDAP_SUCCESS )
- return NULL;
-
- if (defport != 0)
- ld->ld_options.ldo_defport = defport;
-
- if (defhost != NULL) {
- rc = ldap_set_option(ld, LDAP_OPT_HOST_NAME, defhost);
- if ( rc != LDAP_SUCCESS ) {
- ldap_ld_free(ld, 1, NULL, NULL);
- return NULL;
- }
- }
-
- return( ld );
-}
int
ldap_create( LDAP **ldp )
return LDAP_SUCCESS;
}
+/*
+ * ldap_init - initialize the LDAP library. A magic cookie to be used for
+ * future communication is returned on success, NULL on failure.
+ * "host" may be a space-separated list of hosts or IP addresses
+ *
+ * Example:
+ * LDAP *ld;
+ * ld = ldap_open( host, port );
+ */
+LDAP *
+ldap_init( LDAP_CONST char *defhost, int defport )
+{
+ LDAP *ld;
+ int rc;
+
+ rc = ldap_create(&ld);
+ if ( rc != LDAP_SUCCESS )
+ return NULL;
+
+ if (defport != 0)
+ ld->ld_options.ldo_defport = defport;
+
+ if (defhost != NULL) {
+ rc = ldap_set_option(ld, LDAP_OPT_HOST_NAME, defhost);
+ if ( rc != LDAP_SUCCESS ) {
+ ldap_ld_free(ld, 1, NULL, NULL);
+ return NULL;
+ }
+ }
+
+ return( ld );
+}
+
+
int
ldap_initialize( LDAP **ldp, LDAP_CONST char *url )
{
ldap_url_list2hosts (LDAPURLDesc *ludlist)
{
LDAPURLDesc *ludp;
- int size, len;
+ int size;
char *s, *p, buf[32]; /* big enough to hold a long decimal # (overkill) */
if (ludlist == NULL)
ldap_url_list2urls (LDAPURLDesc *ludlist)
{
LDAPURLDesc *ludp;
- int size, len;
+ int size;
char *s, *p, buf[32]; /* big enough to hold a long decimal # (overkill) */
if (ludlist == NULL)
main (int argc, char **argv )
{
struct lutil_MD5Context context;
- unsigned char checksum[16];
+ unsigned char checksum[LUTIL_MD5_BYTES];
int i;
int j;
lutil_MD5Init (&context);
lutil_MD5Update (&context, argv[j], strlen (argv[j]));
lutil_MD5Final (checksum, &context);
- for (i = 0; i < 16; i++)
+ for (i = 0; i < LUTIL_MD5_BYTES; i++)
{
printf ("%02x", (unsigned int) checksum[i]);
}
#include "portable.h"
+#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/string.h>
const unsigned char *salt, size_t saltlen )
{
int rc;
- char *string = NULL;
+ char *string;
size_t b64len;
size_t len = hashlen + saltlen;
char *b64;
const char* cred )
{
lutil_SHA1_CTX SHA1context;
- unsigned char SHA1digest[20];
+ unsigned char SHA1digest[LUTIL_SHA1_BYTES];
int pw_len = strlen(passwd);
int rc;
unsigned char *orig_pass = NULL;
/* base64 un-encode password */
- orig_pass = (unsigned char *) malloc( (size_t) (
+ orig_pass = (unsigned char *) ber_memalloc( (size_t) (
LUTIL_BASE64_DECODE_LEN(pw_len) + 1) );
+ if( orig_pass == NULL ) return -1;
+
if ((rc = lutil_b64_pton(passwd, orig_pass, pw_len)) < 0) {
- free(orig_pass);
+ ber_memfree(orig_pass);
return 1;
}
/* compare */
rc = memcmp((char *)orig_pass, (char *)SHA1digest, sizeof(SHA1digest));
- free(orig_pass);
+ ber_memfree(orig_pass);
return rc;
}
const char* cred )
{
lutil_SHA1_CTX SHA1context;
- unsigned char SHA1digest[20];
+ unsigned char SHA1digest[LUTIL_SHA1_BYTES];
char base64digest[LUTIL_BASE64_ENCODE_LEN(sizeof(SHA1digest))+1];
lutil_SHA1Init(&SHA1context);
const char* cred )
{
lutil_MD5_CTX MD5context;
- unsigned char MD5digest[16];
+ unsigned char MD5digest[LUTIL_MD5_BYTES];
int pw_len = strlen(passwd);
int rc;
unsigned char *orig_pass = NULL;
/* base64 un-encode password */
- orig_pass = (unsigned char *) malloc( (size_t) (
+ orig_pass = (unsigned char *) ber_memalloc( (size_t) (
LUTIL_BASE64_DECODE_LEN(pw_len) + 1) );
+ if( orig_pass == NULL ) return -1;
+
if ((rc = lutil_b64_pton(passwd, orig_pass, pw_len)) < 0) {
- free(orig_pass);
+ ber_memfree(orig_pass);
return 1;
}
/* compare */
rc = memcmp((char *)orig_pass, (char *)MD5digest, sizeof(MD5digest));
- free(orig_pass);
+ ber_memfree(orig_pass);
return rc;
}
const char* cred )
{
lutil_MD5_CTX MD5context;
- unsigned char MD5digest[16];
+ unsigned char MD5digest[LUTIL_MD5_BYTES];
char base64digest[LUTIL_BASE64_ENCODE_LEN(sizeof(MD5digest))+1];
lutil_MD5Init(&MD5context);
const char *passwd )
{
lutil_SHA1_CTX SHA1context;
- unsigned char SHA1digest[20];
+ unsigned char SHA1digest[LUTIL_SHA1_BYTES];
unsigned char salt[4];
if( lutil_entropy( salt, sizeof(salt)) < 0 ) {
lutil_MD5Init( &MD5context );
lutil_MD5Update( &MD5context,
(const unsigned char *) passwd, strlen(passwd) );
-
lutil_MD5Update( &MD5context,
(const unsigned char *) salt, sizeof(salt) );
-
lutil_MD5Final( MD5digest, &MD5context );
return pw_string64( scheme,
--- /dev/null
+# Microsoft Developer Studio Project File - Name="passwd" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 5.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=passwd - Win32 DLL Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "passwd.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "passwd.mak" CFG="passwd - Win32 DLL Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "passwd - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "passwd - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE "passwd - Win32 Single Debug" (based on\
+ "Win32 (x86) Console Application")
+!MESSAGE "passwd - Win32 Single Release" (based on\
+ "Win32 (x86) Console Application")
+!MESSAGE "passwd - Win32 DLL Debug" (based on\
+ "Win32 (x86) Console Application")
+!MESSAGE "passwd - Win32 DLL Release" (based on\
+ "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "passwd - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\..\Release"
+# PROP Intermediate_Dir "..\..\Release\passwd"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 ws2_32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\Release"
+
+!ELSEIF "$(CFG)" == "passwd - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "passwd___"
+# PROP BASE Intermediate_Dir "passwd___"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "..\..\Debug"
+# PROP Intermediate_Dir "..\..\Debug\passwd"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\Debug"
+
+!ELSEIF "$(CFG)" == "passwd - Win32 Single Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "passwd___"
+# PROP BASE Intermediate_Dir "passwd___"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "..\..\SDebug"
+# PROP Intermediate_Dir "..\..\SDebug\passwd"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 olber32.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\Debug"
+# ADD LINK32 ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\SDebug"
+
+!ELSEIF "$(CFG)" == "passwd - Win32 Single Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "passwd__0"
+# PROP BASE Intermediate_Dir "passwd__0"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\..\SRelease"
+# PROP Intermediate_Dir "..\..\SRelease\passwd"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 olber32.lib ws2_32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\Release"
+# ADD LINK32 ws2_32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\SRelease"
+
+!ELSEIF "$(CFG)" == "passwd - Win32 DLL Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "passwd___"
+# PROP BASE Intermediate_Dir "passwd___"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "..\..\DLLDebug"
+# PROP Intermediate_Dir "..\..\DLLDebug\passwd"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\Debug"
+# ADD LINK32 ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\Debug"
+
+!ELSEIF "$(CFG)" == "passwd - Win32 DLL Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "passwd__0"
+# PROP BASE Intermediate_Dir "passwd__0"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "passwd__0"
+# PROP Intermediate_Dir "passwd__0"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 ws2_32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\Release"
+# ADD LINK32 ws2_32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\Release"
+
+!ENDIF
+
+# Begin Target
+
+# Name "passwd - Win32 Release"
+# Name "passwd - Win32 Debug"
+# Name "passwd - Win32 Single Debug"
+# Name "passwd - Win32 Single Release"
+# Name "passwd - Win32 DLL Debug"
+# Name "passwd - Win32 DLL Release"
+# Begin Source File
+
+SOURCE=.\ptest.c
+# End Source File
+# End Target
+# End Project
--- /dev/null
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+
+#include <ac/stdlib.h>
+
+#include <ac/ctype.h>
+#include <ac/signal.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
+#include "lutil.h"
+
+char *hash[] = {
+ "{SMD5}", "{SSHA}",
+ "{MD5}", "{SHA}",
+ NULL
+};
+
+struct pwtable {
+ char *pw;
+ size_t pwlen;
+};
+
+static const struct pwtable pw[] = {
+ { "secret", sizeof("secret")-1 },
+ { "secret\0binary", sizeof("binary\0secret")-1 },
+ { NULL }
+};
+
+int
+main( int argc, char *argv[] )
+{
+ int i, j, rc;
+ char *passwd;
+
+ for( i= 0; hash[i]; i++ ) {
+ for( j = 0; pw[j].pw; j++ ) {
+ passwd = lutil_passwd_generate( pw[j].pw, hash[i] );
+ rc = lutil_passwd( passwd, pw[j].pw, NULL );
+
+ printf("%s (%d): %s (%d)\n",
+ pw[j].pw, pw[j].pwlen, passwd, rc );
+ }
+ }
+ return EXIT_SUCCESS;
+}
\ No newline at end of file
# End Source File
# Begin Source File
+SOURCE=.\extended.c
+# End Source File
+# Begin Source File
+
SOURCE=.\external.h
# End Source File
# Begin Source File
# End Source File
# Begin Source File
+SOURCE=.\passwd.c
+# End Source File
+# Begin Source File
+
SOURCE=".\proto-back-ldbm.h"
# End Source File
# Begin Source File
SLAP_EXTOP_MAIN_FN ext_main )
{
extop_list_t *ext;
- int rc;
if( ext_oid == NULL || *ext_oid == '\0' ) return -1;
if(!ext_main) return -1;
struct berval *cred );
LIBSLAPD_F (struct berval *) slap_passwd_generate(
struct berval *cred );
-
+LIBSLAPD_F (int) slap_passwd_init( void );
/*
* kerberos.c
*/