[Date Prev][Date Next] [Chronological] [Thread] [Top]

EBCDIC slapd



Hi,

I have ported slapd to BS2000. The BS2000 is an EBCDIC mainframe.
The C compiler of the BS2000 supports an option: "-K literal_encoding_ascii" that allows to handle strings in ASCII. I have compile OpenLDAP with the options: "--without-threads --enable-ldbm --with-ldbm-api=berkeley --with-ldbm-module=static" and I have used bdb 4.1.24. After some fightings I have got a running slapd.


Find enclosed the corresponding patch against the actual HEAD.

Some comments:
clients/tools/ldapsearch.c: That is not BS2000 specific: I need the same correction to build on Linux when configure --without-cyrus_sasl.


getopt (libraries/liblutil/getopt.c and include/getopt-compat.h).
I have a getopt but it is EBCDIC based I have to redefine the OpenLDAP getopt to use an ASCII one.


libraries/liblber/stdio.c: The writting to a pipe is not working well and I think writting to /dev/null is faster (and I keep the /dev/null open to make sure to have better performances).

libraries/liblunicode/ucdata/ucgendat.c: I think that the IBM machine also needs a similar patch because the *.txt should be in EBCDIC (text files).

I also have had to patch the configure:
+++
Index: configure
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/configure,v
retrieving revision 1.508
diff -u -r1.508 configure
--- configure   23 Apr 2003 14:50:56 -0000      1.508
+++ configure   20 May 2003 14:42:31 -0000
@@ -9722,10 +9722,12 @@
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
-char regfree();
+#include <sys/types.h>
+#include <regex.h>

int main() {
-regfree()
+regex_t *preg;
+regfree(preg)
; return 0; }
EOF
if { (eval echo configure:9732: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+++
But that is to prevent using the system regexp but I think that makes sense to #include regex.h before using regfree().


After configure I have modified include/portable.h, because the configure does not find that the machine is EBCDIC and __atoe(), __etoa() and __atoe_l() have different names in BS2000.
+++
$ diff -u ./include/portable.h.ori ./include/portable.h
--- ./include/portable.h.ori Mon May 19 17:44:13 2003
+++ ./include/portable.h Mon May 19 17:47:10 2003
@@ -16,6 +16,13 @@


 /* end of preamble */

+#define OSD_POSIX 1
+#ifdef OSD_POSIX
+#define HAVE_EBCDIC 1
+#define __atoe(x) _a2e(x)
+#define __etoa(x) _e2a(x)
+#define __atoe_l(x,l) _e2a_n(x,l)
+#endif

 /* Define to empty if the keyword does not work.  */
 /* #undef const */
@@ -1067,7 +1074,7 @@
 #endif
 #endif

-#ifdef HAVE_EBCDIC
+#if defined(HAVE_EBCDIC) && !defined(OSD_POSIX)
 /* ASCII/EBCDIC converting replacements for stdio funcs
  * vsnprintf and snprintf are used too, but they are already
  * checked by the configure script
+++

Could someone check the patch and commit it?

Cheers

Jean-frederic
Index: clients/tools/ldapsearch.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/clients/tools/ldapsearch.c,v
retrieving revision 1.169
diff -u -r1.169 ldapsearch.c
--- clients/tools/ldapsearch.c	14 May 2003 11:16:56 -0000	1.169
+++ clients/tools/ldapsearch.c	20 May 2003 14:42:34 -0000
@@ -918,8 +918,8 @@
 	ldap_unbind( ld );
 #ifdef HAVE_CYRUS_SASL
 	sasl_done();
-#endif
 	ldap_pvt_tls_destroy();
+#endif
 	return( rc );
 }
 
Index: include/getopt-compat.h
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/include/getopt-compat.h,v
retrieving revision 1.15
diff -u -r1.15 getopt-compat.h
--- include/getopt-compat.h	3 Jan 2003 19:20:49 -0000	1.15
+++ include/getopt-compat.h	20 May 2003 14:42:36 -0000
@@ -20,15 +20,34 @@
 LDAP_BEGIN_DECL
 
 /* change symbols to avoid clashing */
+#ifdef optarg
+#undef optarg
+#endif
 #define optarg lutil_optarg
+
+#ifdef optind
+#undef optind
+#endif
 #define optind lutil_optind
+
+#ifdef opterr
+#undef opterr
+#endif
 #define opterr lutil_opterr
+
+#ifdef optopt
+#undef optopt
+#endif
 #define optopt lutil_optopt
+
+#ifdef getopt
+#undef getopt
+#endif
 #define getopt lutil_getopt
 
-LDAP_LUTIL_V (char *) optarg;
-LDAP_LUTIL_V (int) optind, opterr, optopt;
-LDAP_LUTIL_F (int) getopt LDAP_P(( int, char * const [], const char *));
+LDAP_LUTIL_V (char *) lutil_optarg;
+LDAP_LUTIL_V (int) lutil_optind, lutil_opterr, lutil_optopt;
+LDAP_LUTIL_F (int) lutil_getopt LDAP_P(( int, char * const [], const char *));
 
 LDAP_END_DECL
 
Index: include/ac/errno.h
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/include/ac/errno.h,v
retrieving revision 1.25
diff -u -r1.25 errno.h
--- include/ac/errno.h	3 Jan 2003 19:20:50 -0000	1.25
+++ include/ac/errno.h	20 May 2003 14:42:36 -0000
@@ -33,7 +33,7 @@
 #undef _AC_ERRNO_UNKNOWN
 #define _AC_ERRNO_UNKNOWN "unknown error"
 
-#ifdef HAVE_SYS_ERRLIST
+#if defined(HAVE_SYS_ERRLIST) && !defined(HAVE_STRERROR)
 	/* this is thread safe */
 #	define	STRERROR(e) ( (e) > -1 && (e) < sys_nerr \
 			? sys_errlist[(e)] : _AC_ERRNO_UNKNOWN )
Index: include/ac/socket.h
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/include/ac/socket.h,v
retrieving revision 1.59
diff -u -r1.59 socket.h
--- include/ac/socket.h	21 Apr 2003 16:28:08 -0000	1.59
+++ include/ac/socket.h	20 May 2003 14:42:37 -0000
@@ -194,7 +194,11 @@
 
 #if defined( HAVE_GETADDRINFO ) || defined( HAVE_GETNAMEINFO )
 #	ifdef HAVE_GAI_STRERROR
-#		define AC_GAI_STRERROR(x)	(gai_strerror((x)))
+#		ifdef OSD_POSIX
+#			define AC_GAI_STRERROR(x) (_e2a(gai_strerror((x))))
+#		else
+#			define AC_GAI_STRERROR(x)	(gai_strerror((x)))
+#		endif
 #	else
 #		define AC_GAI_STRERROR(x)	(ldap_pvt_gai_strerror((x)))
 		LDAP_F (char *) ldap_pvt_gai_strerror( int );
Index: libraries/liblber/stdio.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/libraries/liblber/stdio.c,v
retrieving revision 1.4
diff -u -r1.4 stdio.c
--- libraries/liblber/stdio.c	25 Apr 2003 10:32:15 -0000	1.4
+++ libraries/liblber/stdio.c	20 May 2003 14:42:37 -0000
@@ -62,6 +62,34 @@
 }
 #endif
 
+#if defined(OSD_POSIX)
+/* Write at most n characters to the buffer in str, return the
+ * number of chars written or -1 if the buffer would have been
+ * overflowed.
+ *
+ * This is portable to any POSIX-compliant system has /dev/null
+ */
+static FILE *f=NULL;
+int ber_pvt_vsnprintf( char *str, size_t n, const char *fmt, va_list ap )
+{
+	int res;
+
+	if (f == NULL)
+		f = fopen("/dev/null","w");
+	if (f == NULL)
+		return -1;
+
+	setvbuf( f, str, _IOFBF, n );
+
+	res = vfprintf( f, fmt, ap );
+
+	if ( res > 0 && res < n ) {
+		res = vsprintf( str, fmt, ap );
+	}
+	return res;
+}
+#endif
+
 #ifndef HAVE_SNPRINTF
 int ber_pvt_snprintf( char *str, size_t n, const char *fmt, ... )
 {
@@ -75,7 +103,7 @@
 }
 #endif /* !HAVE_VSNPRINTF */
 
-#ifdef HAVE_EBCDIC
+#if defined(HAVE_EBCDIC) && !defined(OSD_POSIX)
 /* stdio replacements with ASCII/EBCDIC translation for OS/390.
  * The OS/390 port depends on the CONVLIT compiler option being
  * used to force character and string literals to be compiled in
Index: libraries/libldap/bind.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/libraries/libldap/bind.c,v
retrieving revision 1.18
diff -u -r1.18 bind.c
--- libraries/libldap/bind.c	3 Jan 2003 19:20:51 -0000	1.18
+++ libraries/libldap/bind.c	20 May 2003 14:42:37 -0000
@@ -33,6 +33,13 @@
 
 #include "portable.h"
 
+#ifdef OSD_POSIX
+typedef unsigned char           u_char;
+typedef unsigned short          u_short;
+typedef unsigned int            u_int;
+typedef unsigned long           u_long;
+#endif
+
 #include <stdio.h>
 
 #include <ac/stdlib.h>
Index: libraries/libldap/os-ip.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/libraries/libldap/os-ip.c,v
retrieving revision 1.90
diff -u -r1.90 os-ip.c
--- libraries/libldap/os-ip.c	21 Apr 2003 23:17:23 -0000	1.90
+++ libraries/libldap/os-ip.c	20 May 2003 14:42:39 -0000
@@ -372,6 +372,10 @@
 	ldap_pvt_thread_mutex_lock(&ldap_int_resolv_mutex);
 #endif
 
+#ifdef OSD_POSIX
+	_a2e(host);
+	_a2e(serv);
+#endif
 	err = getaddrinfo( host, serv, &hints, &res );
 
 #ifdef LDAP_R_COMPILE
Index: libraries/libldap/os-local.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/libraries/libldap/os-local.c,v
retrieving revision 1.25
diff -u -r1.25 os-local.c
--- libraries/libldap/os-local.c	29 Apr 2003 12:43:54 -0000	1.25
+++ libraries/libldap/os-local.c	20 May 2003 14:42:39 -0000
@@ -176,8 +176,10 @@
 			int fds[2];
 			if (pipe(fds) == 0) {
 				/* Abandon, noop, has no reply */
-				struct iovec iov = {(char *)abandonPDU, sizeof(abandonPDU)};
+				struct iovec iov;
 				struct msghdr msg = {0};
+				iov.iov_base = (char *)abandonPDU;
+				iov.iov_len = sizeof(abandonPDU);
 				msg.msg_iov = &iov;
 				msg.msg_iovlen = 1;
 				msg.msg_accrights = (char *)fds;
Index: libraries/libldbm/ldbm.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/libraries/libldbm/ldbm.c,v
retrieving revision 1.76
diff -u -r1.76 ldbm.c
--- libraries/libldbm/ldbm.c	3 Jan 2003 19:20:52 -0000	1.76
+++ libraries/libldbm/ldbm.c	20 May 2003 14:42:41 -0000
@@ -225,6 +225,9 @@
 	DB_ENV *env = NULL;    
 	int     err;
 	u_int32_t	envFlags;
+#ifdef OSD_POSIX
+        char n2[2048];
+#endif
 
 	err = db_env_create( &env, 0 );
 
@@ -259,6 +262,12 @@
 	envFlags |= DB_THREAD;
 #endif
 
+#ifdef OSD_POSIX
+        strncpy(n2, home, sizeof(n2)-1);
+        n2[sizeof(n2)-1] = '\0';
+        __atoe(n2);
+        home = n2;
+#endif
 #if DB_VERSION_X >= 0x030100
 	err = env->open( env, home, envFlags, 0 );
 #else
Index: libraries/liblunicode/ucdata/ucgendat.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/libraries/liblunicode/ucdata/ucgendat.c,v
retrieving revision 1.27
diff -u -r1.27 ucgendat.c
--- libraries/liblunicode/ucdata/ucgendat.c	3 Jan 2003 19:20:53 -0000	1.27
+++ libraries/liblunicode/ucdata/ucgendat.c	20 May 2003 14:42:45 -0000
@@ -809,6 +809,9 @@
 
     lineno = skip = 0;
     while (fgets(line, sizeof(line), in)) {
+#ifdef OSD_POSIX
+	_e2a(line);
+#endif
 	if( (s=strchr(line, '\n')) ) *s = '\0';
         lineno++;
 
Index: libraries/liblutil/getopt.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/libraries/liblutil/getopt.c,v
retrieving revision 1.11
diff -u -r1.11 getopt.c
--- libraries/liblutil/getopt.c	6 Apr 2003 04:47:31 -0000	1.11
+++ libraries/liblutil/getopt.c	20 May 2003 14:42:45 -0000
@@ -29,9 +29,9 @@
 #define STDERR_FILENO 2
 #endif
 
-int opterr = 1;
-int optind = 1;
-int optopt;
+int lutil_opterr = 1;
+int lutil_optind = 1;
+int lutil_optopt;
 char * optarg;
 
 #ifdef HAVE_EBCDIC
Index: libraries/liblutil/utils.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/libraries/liblutil/utils.c,v
retrieving revision 1.17
diff -u -r1.17 utils.c
--- libraries/liblutil/utils.c	14 May 2003 23:18:45 -0000	1.17
+++ libraries/liblutil/utils.c	20 May 2003 14:42:45 -0000
@@ -50,14 +50,14 @@
 size_t lutil_gentime( char *s, size_t smax, const struct tm *tm )
 {
 	size_t ret;
-#ifdef HAVE_EBCDIC
+#if defined(HAVE_EBCDIC) && !defined(OSD_POSIX)
 /* We've been compiling in ASCII so far, but we want EBCDIC now since
  * strftime only understands EBCDIC input.
  */
 #pragma convlit(suspend)
 #endif
 	ret = strftime( s, smax, "%Y%m%d%H%M%SZ", tm );
-#ifdef HAVE_EBCDIC
+#if defined(HAVE_EBCDIC) && !defined(OSD_POSIX)
 #pragma convlit(resume)
 	__etoa( s );
 #endif
Index: servers/slapd/config.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/config.c,v
retrieving revision 1.226
diff -u -r1.226 config.c
--- servers/slapd/config.c	9 May 2003 04:50:44 -0000	1.226
+++ servers/slapd/config.c	20 May 2003 14:42:51 -0000
@@ -2462,7 +2462,8 @@
 		strcasecmp( token, "pseudorootpw" ) == 0 ||	/* used in back-meta */
 		strcasecmp( token, "dbpasswd" ) == 0 ) )	/* used in back-sql */
 	{
-		snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
+		snprintf( logbuf, sizeof logbuf, "%s ***", token );
+		logline = logbuf;
 	}
 
 	if ( strtok_quote_ptr ) {
Index: servers/slapd/daemon.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/daemon.c,v
retrieving revision 1.267
diff -u -r1.267 daemon.c
--- servers/slapd/daemon.c	14 May 2003 23:12:17 -0000	1.267
+++ servers/slapd/daemon.c	20 May 2003 14:42:55 -0000
@@ -456,6 +456,10 @@
 		hints.ai_socktype = SOCK_STREAM;
 		hints.ai_family = slap_inet4or6;
 		snprintf(serv, sizeof serv, "%d", port);
+#ifdef OSD_POSIX
+                _a2e(host);
+                _a2e(serv);
+#endif
 
 		if ( (err = getaddrinfo(host, serv, &hints, &res)) ) {
 #ifdef NEW_LOGGING
Index: servers/slapd/main.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/main.c,v
retrieving revision 1.157
diff -u -r1.157 main.c
--- servers/slapd/main.c	14 May 2003 23:12:17 -0000	1.157
+++ servers/slapd/main.c	20 May 2003 14:42:56 -0000
@@ -153,6 +153,10 @@
 
 	sl_mem_init();
 
+#ifdef OSD_POSIX
+	for (i=0;i<argc;i++)
+		_e2a(argv[i]);
+#endif
 #ifdef HAVE_NT_SERVICE_MANAGER
 	{
 		int *i;
Index: servers/slapd/proto-slap.h
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/proto-slap.h,v
retrieving revision 1.426
diff -u -r1.426 proto-slap.h
--- servers/slapd/proto-slap.h	9 May 2003 04:50:44 -0000	1.426
+++ servers/slapd/proto-slap.h	20 May 2003 14:42:59 -0000
@@ -444,11 +444,11 @@
  * extended.c
  */
 #ifdef LDAP_EXOP_X_CANCEL
-const struct berval slap_EXOP_CANCEL;
+extern const struct berval slap_EXOP_CANCEL;
 #endif
-const struct berval slap_EXOP_WHOAMI;
-const struct berval slap_EXOP_MODIFY_PASSWD;
-const struct berval slap_EXOP_START_TLS;
+extern const struct berval slap_EXOP_WHOAMI;
+extern const struct berval slap_EXOP_MODIFY_PASSWD;
+extern const struct berval slap_EXOP_START_TLS;
 
 typedef int (SLAP_EXTOP_MAIN_FN) LDAP_P(( Operation *op, SlapReply *rs ));