Commit b52950cc authored by Hiroshi Inoue's avatar Hiroshi Inoue

Add md5 authentication support thanks to Bruce Momjian.

parent f14fdad8
......@@ -2,7 +2,7 @@
#
# GNUMakefile for psqlodbc (Postgres ODBC driver)
#
# $Header: /cvsroot/pgsql/src/interfaces/odbc/Attic/GNUmakefile,v 1.22 2001/10/09 22:32:33 petere Exp $
# $Header: /cvsroot/pgsql/src/interfaces/odbc/Attic/GNUmakefile,v 1.23 2001/11/12 00:54:28 inoue Exp $
#
#-------------------------------------------------------------------------
......@@ -19,11 +19,11 @@ endif
SO_MAJOR_VERSION = 0
SO_MINOR_VERSION = 27
override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)
override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) -DFRONTEND -DMD5_ODBC
OBJS = info.o bind.o columninfo.o connection.o convert.o drvconn.o \
environ.o execute.o lobj.o misc.o options.o \
environ.o execute.o lobj.o md5.o misc.o options.o \
pgtypes.o psqlodbc.o qresult.o results.o socket.o parse.o statement.o \
tuple.o tuplelist.o dlg_specific.o odbcapi.o
......
......@@ -32,6 +32,7 @@
#endif
#include "pgapifunc.h"
#include "md5.h"
#define STMT_INCREMENT 16 /* how many statement holders to allocate
* at a time */
......@@ -508,6 +509,39 @@ CC_set_translation(ConnectionClass *self)
return TRUE;
}
static int
md5_auth_send(ConnectionClass *self, const char *salt)
{
char *pwd1 = NULL, *pwd2 = NULL;
ConnInfo *ci = &(self->connInfo);
SocketClass *sock = self->sock;
mylog("MD5 user=%s password=%s\n", ci->username, ci->password);
if (!(pwd1 = malloc(MD5_PASSWD_LEN + 1)))
return 1;
if (!EncryptMD5(ci->password, ci->username, strlen(ci->username), pwd1))
{
free(pwd1);
return 1;
}
if (!(pwd2 = malloc(MD5_PASSWD_LEN + 1)))
{
free(pwd1);
return 1;
}
if (!EncryptMD5(pwd1 + strlen("md5"), salt, 4, pwd2))
{
free(pwd2);
free(pwd1);
return 1;
}
free(pwd1);
SOCK_put_int(sock, 4 + strlen(pwd2) + 1, 4);
SOCK_put_n_char(sock, pwd2, strlen(pwd2) + 1);
SOCK_flush_output(sock);
free(pwd2);
return 0;
}
char
CC_connect(ConnectionClass *self, char do_password)
......@@ -763,10 +797,24 @@ another_version_retry:
break;
case AUTH_REQ_CRYPT:
case AUTH_REQ_MD5:
self->errormsg = "Password crypt authentication not supported";
self->errornumber = CONN_AUTH_TYPE_UNSUPPORTED;
return 0;
case AUTH_REQ_MD5:
mylog("in AUTH_REQ_MD5\n");
if (ci->password[0] == '\0')
{
self->errornumber = CONNECTION_NEED_PASSWORD;
self->errormsg = "A password is required for this connection.";
return -1; /* need password */
}
if (md5_auth_send(self, salt))
{
self->errormsg = "md5 hashing failed";
self->errornumber = CONN_INVALID_AUTHENTICATION;
return 0;
}
break;
case AUTH_REQ_SCM_CREDS:
self->errormsg = "Unix socket credential authentication not supported";
......
This diff is collapsed.
/* File: connection.h
*
* Description: See "connection.c"
*
* Comments: See "notice.txt" for copyright and license information.
*
*/
#ifndef __MD5_H__
#define __MD5_H__
#include "psqlodbc.h"
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#define MD5_ODBC
#define FRONTEND
#endif
#define MD5_PASSWD_LEN 35
/* From c.h */
#ifndef __BEOS__
#ifndef __cplusplus
#ifndef bool
typedef char bool;
#endif
#ifndef true
#define true ((bool) 1)
#endif
#ifndef false
#define false ((bool) 0)
#endif
#endif /* not C++ */
#endif /* __BEOS__ */
#ifndef __BEOS__ /* this shouldn't be required, but is is! */
typedef unsigned char uint8; /* == 8 bits */
typedef unsigned short uint16; /* == 16 bits */
typedef unsigned int uint32; /* == 32 bits */
#endif /* __BEOS__ */
extern bool EncryptMD5(const char *passwd, const char *salt,
size_t salt_len, char *buf);
#endif
......@@ -67,6 +67,7 @@ CLEAN :
-@erase "$(INTDIR)\gpps.obj"
-@erase "$(INTDIR)\info.obj"
-@erase "$(INTDIR)\lobj.obj"
-@erase "$(INTDIR)\win_md5.obj"
-@erase "$(INTDIR)\misc.obj"
!IF "$(CFG)" == "MultibyteRelease"
-@erase "$(INTDIR)\multibyte.obj"
......@@ -152,6 +153,7 @@ LINK32_OBJS= \
"$(INTDIR)\gpps.obj" \
"$(INTDIR)\info.obj" \
"$(INTDIR)\lobj.obj" \
"$(INTDIR)\win_md5.obj" \
"$(INTDIR)\misc.obj" \
!IF "$(CFG)" == "MultibyteRelease"
"$(INTDIR)\multibyte.obj" \
......@@ -200,6 +202,7 @@ CLEAN :
-@erase "$(INTDIR)\gpps.obj"
-@erase "$(INTDIR)\info.obj"
-@erase "$(INTDIR)\lobj.obj"
-@erase "$(INTDIR)\win_md5.obj"
-@erase "$(INTDIR)\misc.obj"
!IF "$(CFG)" == "MultibyteDebug"
-@erase "$(INTDIR)\multibyte.obj"
......@@ -288,6 +291,7 @@ LINK32_OBJS= \
"$(INTDIR)\gpps.obj" \
"$(INTDIR)\info.obj" \
"$(INTDIR)\lobj.obj" \
"$(INTDIR)\win_md5.obj"
"$(INTDIR)\misc.obj" \
!IF "$(CFG)" == "MultibyteDebug"
"$(INTDIR)\multibyte.obj" \
......@@ -486,6 +490,12 @@ SOURCE=tuplelist.c
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=win_md5.c
"$(INTDIR)\win_md5.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=odbcapi.c
"$(INTDIR)\odbcapi.obj" : $(SOURCE) "$(INTDIR)"
......
/*
* win_md5.c
* Under Windows I don't love the following /D in makefiles. - inoue
*/
#define MD5_ODBC
#define FRONTEND
/*
* md5.c is the exact copy of the src/backend/libpq/md5.c.
*
* psqlodbc driver stuff never refer(link) to other
* stuff directly.
*
*/
#include "md5.c"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment