Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Oct 1997 22:22:50 +0000
From:      albast@xs4all.nl
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   ports/4808: PostgreSQL-6.2 port
Message-ID:  <E0xN3kI-0005cz-00@ampersand.home.pc>
Resent-Message-ID: <199710192030.NAA00724@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         4808
>Category:       ports
>Synopsis:       Broken password.c in backend/libpq for FreeBSD's crypt()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Oct 19 13:30:01 PDT 1997
>Last-Modified:
>Originator:     Jeroen Hogeveen
>Organization:
n/a
>Release:        FreeBSD 3.0-CURRENT i386
>Environment:

Don't think it's really that relevant but here's the uname output:

        FreeBSD ampersand.home.pc 3.0-CURRENT
        FreeBSD 3.0-CURRENT #0: Sat Sep 13 18:23:23 GMT 1997
        jh@ampersand.home.pc:/jaz/source/src/sys/compile/AMPERSAND  i386

having no DES (secure sub)

PostgreSQL version is 6.2, taken from the FreeBSD ports collection.

>Description:

Problem:  when using the password USERAUTH in pg_hba.conf, the backend
          does not 'recognize' your password from the configured file.

  This is caused by postgresql-6.2/src/backend/libpq/password.c not using the
  correct salt (length) in crypt()'ing the plain text password which in turn
  results in a failing comparison.

Problem:  the pg_passwd utility complains about incorrect length.

  It assumes a length of 13. The max length from <pwd.h> is 128.

>How-To-Repeat:

See Description.

>Fix:

The original code will probably work fine in an DES environment.
If time allows it, please review the following patches for both DES/MD5,
and correct me where wrong (very likely;-) :

TIA - Jeroen.


### snip ###


--- password.c.orig	Sun Oct 19 19:20:37 1997
+++ password.c	Sun Oct 19 21:47:04 1997
@@ -24,7 +24,7 @@
 	char	   *p,
 			   *test_user,
 			   *test_pw;
-	char		salt[3];
+	char		salt[10];
 
 	find_hba_entry(DataDir, port->raddr.sin_addr, database,
 				   &host_ok, &userauth, pw_file_name, true);
@@ -90,7 +90,14 @@
 		if (test_pw[strlen(test_pw) - 1] == '\n')
 			test_pw[strlen(test_pw) - 1] = '\0';
 
-		strNcpy(salt, test_pw, 2);
+                if (strncmp(test_pw, "$1$", 3)) {
+                   /* DES */
+                   strNcpy(salt, test_pw, 2);
+                }
+                else {
+                   /* MD5 */
+		   strncpy(salt, test_pw, 9);
+                }
 
 		if (strcmp(user, test_user) == 0)
 		{


--- pg_passwd.c.orig	Sun Oct 19 19:26:23 1997
+++ pg_passwd.c	Sun Oct 19 21:18:16 1997
@@ -23,12 +23,16 @@
 
 #endif
 
+#ifndef _POSIX_SOURCE
+  #define	_PASSWORD_LEN		128	/* max length, not counting NULL */
+#endif
+
 char	   *comname;
 void		usage(FILE *stream);
 void		read_pwd_file(char *filename);
 void		write_pwd_file(char *filename, char *bkname);
-void		encrypt_pwd(char key[9], char salt[3], char passwd[14]);
-int			check_pwd(char key[9], char passwd[14]);
+void		encrypt_pwd(char key[9], char salt[3], char passwd[_PASSWORD_LEN+1]);
+int			check_pwd(char key[9], char passwd[_PASSWORD_LEN+1]);
 void		prompt_for_username(char *username);
 void		prompt_for_password(char *prompt, char *password);
 
@@ -148,7 +152,7 @@
 
 		if (q != NULL)
 			*(q++) = '\0';
-		if (strlen(p) != 13)
+		if (strlen(p) > _PASSWORD_LEN)
 		{
 			fprintf(stderr, "WARNING: %s: line %d: illegal password length.\n",
 					filename, npwds + 1);
@@ -208,7 +212,7 @@
 }
 
 void
-encrypt_pwd(char key[9], char salt[3], char passwd[14])
+encrypt_pwd(char key[9], char salt[3], char passwd[_PASSWORD_LEN+1])
 {
 	int			n;
 
@@ -242,9 +246,9 @@
 }
 
 int
-check_pwd(char key[9], char passwd[14])
+check_pwd(char key[9], char passwd[_PASSWORD_LEN+1])
 {
-	char		shouldbe[14];
+	char		shouldbe[_PASSWORD_LEN+1];
 	char		salt[3];
 
 	salt[0] = passwd[0];
@@ -252,7 +256,7 @@
 	salt[2] = '\0';
 	encrypt_pwd(key, salt, shouldbe);
 
-	return strncmp(shouldbe, passwd, 13) == 0 ? 1 : 0;
+	return strncmp(shouldbe, passwd, _PASSWORD_LEN) == 0 ? 1 : 0;
 }
 
 void
@@ -326,7 +330,7 @@
 	char		salt[3];
 	char		key[9],
 				key2[9];
-	char		e_passwd[14];
+	char		e_passwd[_PASSWORD_LEN+1];
 	int			i;
 
 	comname = argv[0];
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E0xN3kI-0005cz-00>