diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 61956b27706bd1737d8fcbae925dfbb946ce604c..7ae9dfdd52a66a476e4a3acc3d8749e75cfdfd70 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.171 2006/05/04 16:07:29 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.172 2006/06/20 19:56:52 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -20,7 +20,7 @@
 #include "catalog/pg_authid.h"
 #include "commands/comment.h"
 #include "commands/user.h"
-#include "libpq/crypt.h"
+#include "libpq/md5.h"
 #include "miscadmin.h"
 #include "utils/acl.h"
 #include "utils/builtins.h"
diff --git a/src/backend/libpq/crypt.c b/src/backend/libpq/crypt.c
index a8715c85bc9179bc8e5e412cffb386332fb794fc..ddba1f1b6740abc560c50b61e73e6f159b180777 100644
--- a/src/backend/libpq/crypt.c
+++ b/src/backend/libpq/crypt.c
@@ -9,7 +9,7 @@
  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/libpq/crypt.c,v 1.68 2006/03/05 15:58:27 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/crypt.c,v 1.69 2006/06/20 19:56:52 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,6 +22,7 @@
 
 #include "libpq/crypt.h"
 #include "libpq/libpq.h"
+#include "libpq/md5.h"
 #include "miscadmin.h"
 #include "storage/fd.h"
 #include "nodes/pg_list.h"
diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index a31f968baab7342505a92b491c4a787849365f27..ddfb29049416a1b5ba84ceeacc30fb4f7f61e373 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.151 2006/03/06 17:41:43 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.152 2006/06/20 19:56:52 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -29,7 +29,6 @@
 #include <arpa/inet.h>
 #include <unistd.h>
 
-#include "libpq/crypt.h"
 #include "libpq/libpq.h"
 #include "miscadmin.h"
 #include "nodes/pg_list.h"
diff --git a/src/backend/libpq/ip.c b/src/backend/libpq/ip.c
index 595c99a81b7f06810adb8ea7c7b18a3c6a52ff00..917bda828333bcc0887ab4b914e7ea3fdfb7cf36 100644
--- a/src/backend/libpq/ip.c
+++ b/src/backend/libpq/ip.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.35 2006/06/07 22:24:43 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.36 2006/06/20 19:56:52 tgl Exp $
  *
  * This file and the IPV6 implementation were initially provided by
  * Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
@@ -20,7 +20,6 @@
 /* This is intended to be used in both frontend and backend, so use c.h */
 #include "c.h"
 
-#include <errno.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
diff --git a/src/backend/libpq/md5.c b/src/backend/libpq/md5.c
index 3948a29cb1242b1c0e97af315e1e1c3edb1f3084..e8849049b498d6e997ef34d2eff250675b39bfa2 100644
--- a/src/backend/libpq/md5.c
+++ b/src/backend/libpq/md5.c
@@ -14,13 +14,13 @@
  *	Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.32 2006/03/05 15:58:27 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.33 2006/06/20 19:56:52 tgl Exp $
  */
 
 /* This is intended to be used in both frontend and backend, so use c.h */
 #include "c.h"
 
-#include "libpq/crypt.h"
+#include "libpq/md5.h"
 
 
 /*
@@ -265,7 +265,7 @@ bytesToHex(uint8 b[16], char *s)
  *
  *	Calculates the MD5 sum of the bytes in a buffer.
  *
- *	SYNOPSIS	  #include "crypt.h"
+ *	SYNOPSIS	  #include "md5.h"
  *				  int pg_md5_hash(const void *buff, size_t len, char *hexsum)
  *
  *	INPUT		  buff	  the buffer containing the bytes that you want
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 7bc5a09f69357da7bb7cabf21c0901ffc823c278..2873c77e94b7311d2a68d573a0f170dbcc2a4d2a 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.147 2006/05/21 20:05:19 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.148 2006/06/20 19:56:52 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -19,7 +19,7 @@
 #include "access/tuptoaster.h"
 #include "catalog/pg_type.h"
 #include "lib/stringinfo.h"
-#include "libpq/crypt.h"
+#include "libpq/md5.h"
 #include "libpq/pqformat.h"
 #include "mb/pg_wchar.h"
 #include "miscadmin.h"
diff --git a/src/include/libpq/crypt.h b/src/include/libpq/crypt.h
index 34014b799c261a249ccba524289bfc95f03af166..f9df945c95a04195e7272c45d0a41d677a9e59a8 100644
--- a/src/include/libpq/crypt.h
+++ b/src/include/libpq/crypt.h
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/libpq/crypt.h,v 1.34 2006/03/05 15:58:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/libpq/crypt.h,v 1.35 2006/06/20 19:56:52 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -15,19 +15,7 @@
 
 #include "libpq/libpq-be.h"
 
-#define MD5_PASSWD_LEN	35
-
-#define isMD5(passwd)	(strncmp(passwd, "md5", 3) == 0 && \
-						 strlen(passwd) == MD5_PASSWD_LEN)
-
-
-/* in crypt.c */
 extern int md5_crypt_verify(const Port *port, const char *user,
 				 char *client_pass);
 
-/* in md5.c --- these are also present in frontend libpq */
-extern bool pg_md5_hash(const void *buff, size_t len, char *hexsum);
-extern bool pg_md5_encrypt(const char *passwd, const char *salt,
-			   size_t salt_len, char *buf);
-
 #endif
diff --git a/src/include/libpq/ip.h b/src/include/libpq/ip.h
index ab68e732760ae50b88c2ff9e04f0426dd3956695..f608a25eb3a048dfc3a9b00ef92df822e86b4ee8 100644
--- a/src/include/libpq/ip.h
+++ b/src/include/libpq/ip.h
@@ -3,9 +3,12 @@
  * ip.h
  *	  Definitions for IPv6-aware network access.
  *
+ * These definitions are used by both frontend and backend code.  Be careful
+ * what you include here!
+ *
  * Copyright (c) 2003-2006, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/include/libpq/ip.h,v 1.17 2006/03/05 15:58:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/libpq/ip.h,v 1.18 2006/06/20 19:56:52 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
diff --git a/src/include/libpq/md5.h b/src/include/libpq/md5.h
new file mode 100644
index 0000000000000000000000000000000000000000..eea0c24d3ddc309e4e37f2b559002da2f416d8c1
--- /dev/null
+++ b/src/include/libpq/md5.h
@@ -0,0 +1,29 @@
+/*-------------------------------------------------------------------------
+ *
+ * md5.h
+ *	  Interface to libpq/md5.c
+ *
+ * These definitions are needed by both frontend and backend code to work
+ * with MD5-encrypted passwords.
+ *
+ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * $PostgreSQL: pgsql/src/include/libpq/md5.h,v 1.3 2006/06/20 19:56:52 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PG_MD5_H
+#define PG_MD5_H
+
+#define MD5_PASSWD_LEN	35
+
+#define isMD5(passwd)	(strncmp(passwd, "md5", 3) == 0 && \
+						 strlen(passwd) == MD5_PASSWD_LEN)
+
+
+extern bool pg_md5_hash(const void *buff, size_t len, char *hexsum);
+extern bool pg_md5_encrypt(const char *passwd, const char *salt,
+			   size_t salt_len, char *buf);
+
+#endif
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index bfcb3b7e78d4381c0508f25045650d8fc91f9a41..501cc39d0eec7e2b2d2d036757f88dc749477c01 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -10,7 +10,7 @@
  * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.114 2006/03/06 17:59:30 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.115 2006/06/20 19:56:52 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -50,7 +50,7 @@
 #include "libpq-fe.h"
 #include "libpq-int.h"
 #include "fe-auth.h"
-#include "libpq/crypt.h"
+#include "libpq/md5.h"
 
 
 #ifdef KRB5