+/* $OpenLDAP$ */
/*
* Copyright (c) 1995 Regents of the University of Michigan.
* All rights reserved.
* is provided ``as is'' without express or implied warranty.
*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <sys/types.h>
+
+#include <ac/stdlib.h>
+
+#include <ac/ctype.h>
+#include <ac/errno.h>
+#include <ac/dirent.h>
+#include <ac/string.h>
+#include <ac/unistd.h>
+
#include <sys/stat.h>
#include <quipu/config.h>
static int edb2ldif( FILE *outfp, char *edbfile, char *basedn, int recurse );
static int convert_entry( FILE *fp, char *edbname, FILE *outfp,
char *basedn, char *loc_addvals, int loc_addlen, char *linebuf );
+static int add_rdn_values (Attr_Sequence entryas, RDN rdn);
static int read_edbmap( char *mapfile, struct edbmap **edbmapp );
static char *file2rdn( struct edbmap *edbmap, char *filename );
static void free_edbmap( struct edbmap *edbmap );
int ldap_syslog_level = 0;
-main( argc, argv )
- int argc;
- char **argv;
+int
+main( int argc, char **argv )
{
char *usage = "usage: %s [-d] [-o] [-r] [-v] [-b basedn] [-a addvalsfile] [-f fileattrdir] [-i ignoreattr...] [edbfile...]\n";
char edbfile[ MAXNAMLEN ], *basedn;
int c, rc, errflg, ignore_count, recurse;
- extern int optind;
- extern char *optarg;
extern char dsa_mode;
#ifdef HAVE_FILE_ATTR_DIR
extern char *file_attr_directory;
always_addvals = NULL;
basedn = NULL;
- while (( c = getopt( argc, argv, "dorva:b:f:h:i:" )) != -1 ) {
+ while (( c = getopt( argc, argv, "dorva:b:f:h:i:" )) != EOF ) {
switch( c ) {
case 'd':
#ifdef LDAP_DEBUG
} else if (( always_addvals = read_file( optarg, &always_addlen ))
== NULL ) {
print_err( optarg );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
break;
}
if ( file_attr_directory == NULL ) {
print_err( "malloc" );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
#else /* HAVE_FILE_ATTR_DIR */
fprintf( stderr, "Ignoring -f: this option requires a newer version of ISODE.\n" );
}
if ( ignore_attr == NULL ) {
print_err( "malloc/realloc" );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
ignore_attr[ ignore_count ] = optarg;
ignore_attr[ ++ignore_count ] = NULL;
if ( errflg ) {
fprintf( stderr, usage, progname );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
if ( basedn == NULL ) {
if ( init_syntaxes() < 0 ) {
fprintf( stderr, "%s: init_syntaxes failed -- check your oid tables \n",
progname );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
fprintf( stderr, "edb2ldif: exit( %d )\n", ( rc < 0 ) ? 1 : 0 );
#endif
- exit( ( rc < 0 ) ? 1 : 0 );
+ exit( ( rc < 0 ) ? EXIT_FAILURE : EXIT_SUCCESS );
}
static int
-edb2ldif( outfp, edbfile, basedn, recurse )
- FILE *outfp;
- char *edbfile;
- char *basedn;
- int recurse;
+edb2ldif( FILE *outfp, char *edbfile, char *basedn, int recurse )
{
FILE *fp;
char *addvals, *p, *rdn, line[ MAX_LINE_SIZE + 1 ];
* return > 0 if entry converted, 0 if end of file, < 0 if error occurs
*/
static int
-convert_entry( fp, edbname, outfp, basedn, loc_addvals, loc_addlen, linebuf )
- FILE *fp;
- char *edbname;
- FILE *outfp;
- char *basedn;
- char *loc_addvals;
- int loc_addlen;
- char *linebuf;
+convert_entry(
+ FILE *fp,
+ char *edbname,
+ FILE *outfp,
+ char *basedn,
+ char *loc_addvals,
+ int loc_addlen,
+ char *linebuf
+)
{
Attr_Sequence as, tmpas;
AV_Sequence av;
}
-int
-add_rdn_values( entryas, rdn )
- Attr_Sequence entryas;
- RDN rdn;
+static int
+add_rdn_values( Attr_Sequence entryas, RDN rdn )
{
/*
* this routine is based on code from the real_unravel_attribute() routine
/* read the EDB.map file and return a linked list of translations */
static int
-read_edbmap( mapfile, edbmapp )
- char *mapfile;
- struct edbmap **edbmapp;
+read_edbmap( char *mapfile, struct edbmap **edbmapp )
{
FILE *fp;
char *p, *filename, *rdn, line[ MAX_LINE_SIZE + 1 ];
}
*filename++ = '\0';
- while ( isspace( *filename )) { /* strip leading whitespace */
+ while ( isspace((unsigned char) *filename) ) { /* strip leading whitespace */
++filename;
}
}
p = filename + strlen( filename ) - 1;
- while ( isspace( *p )) { /* strip trailing whitespace */
+ while ( isspace((unsigned char) *p) ) { /* strip trailing whitespace */
*p-- = '\0';
}
rdn = line;
- while ( isspace( *rdn )) { /* strip leading whitespace */
+ while ( isspace((unsigned char) *rdn)) { /* strip leading whitespace */
++rdn;
}
}
p = rdn + strlen( rdn ) - 1;
- while ( isspace( *p )) { /* strip trailing whitespace */
+ while ( isspace((unsigned char) *p)) { /* strip trailing whitespace */
*p-- = '\0';
}
static char *
-file2rdn( edbmap, filename )
- struct edbmap *edbmap;
- char *filename;
+file2rdn( struct edbmap *edbmap, char *filename )
{
#ifdef LDAP_DEBUG
if ( debugflg ) {
/* free the edbmap list */
static void
-free_edbmap( edbmap )
- struct edbmap *edbmap;
+free_edbmap( struct edbmap *edbmap )
{
struct edbmap *tmp;
static void
-print_err( msg )
- char *msg;
+print_err( char *msg )
{
- extern int sys_nerr;
- extern char *sys_errlist[];
- extern int errno;
-
#ifdef LDAP_DEBUG
if ( debugflg ) {
fprintf( stderr, "print_err( \"%s\" )\n", msg );
#endif
if ( errno > sys_nerr ) {
- fprintf( stderr, "%s: %s: error %d\n", progname, msg, errno );
+ fprintf( stderr, "%s: %s: errno=%d\n", progname, msg, errno );
} else {
fprintf( stderr, "%s: %s: %s\n", progname, msg, sys_errlist[ errno ] );
}