1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-05 07:59:13 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/unistd.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-03-02 06:37:05 +08:00
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
1999-08-04 02:14:24 +08:00
|
|
|
#include <ldap.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "ldif.h"
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static void
|
|
|
|
usage( char *name )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr, "usage: %s [-b] <attrtype>\n", name );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
char *type, *out;
|
1998-08-20 10:18:28 +08:00
|
|
|
int len, binary = 0;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
if (argc < 2 || argc > 3 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
|
|
|
if ( argc == 3 ) {
|
|
|
|
if ( strcmp( argv[1], "-b" ) != 0 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
1999-09-06 12:42:20 +08:00
|
|
|
binary = 1;
|
|
|
|
type = argv[2];
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
|
|
|
if ( strcmp( argv[1], "-b" ) == 0 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
|
|
|
type = argv[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the -b flag was used, read single binary value from stdin */
|
|
|
|
if ( binary ) {
|
|
|
|
char *val;
|
|
|
|
int nread, max, cur;
|
|
|
|
|
|
|
|
if (( val = (char *) malloc( BUFSIZ )) == NULL ) {
|
|
|
|
perror( "malloc" );
|
1999-08-04 02:14:24 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
max = BUFSIZ;
|
|
|
|
cur = 0;
|
|
|
|
while ( (nread = read( 0, buf, BUFSIZ )) != 0 ) {
|
|
|
|
if ( nread + cur > max ) {
|
|
|
|
max += BUFSIZ;
|
|
|
|
if (( val = (char *) realloc( val, max )) ==
|
|
|
|
NULL ) {
|
|
|
|
perror( "realloc" );
|
1999-08-04 02:14:24 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
memcpy( val + cur, buf, nread );
|
|
|
|
cur += nread;
|
|
|
|
}
|
|
|
|
|
1999-07-31 07:00:02 +08:00
|
|
|
if (( out = ldif_put( LDIF_PUT_BINARY, type, val, cur )) == NULL ) {
|
1999-08-04 02:14:24 +08:00
|
|
|
perror( "ldif_type_and_value" );
|
|
|
|
return EXIT_FAILURE;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs( out, stdout );
|
1999-06-03 08:37:44 +08:00
|
|
|
ber_memfree( out );
|
1998-08-09 08:43:13 +08:00
|
|
|
free( val );
|
1999-08-04 02:14:24 +08:00
|
|
|
return EXIT_SUCCESS;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* not binary: one value per line... */
|
1998-08-20 10:18:28 +08:00
|
|
|
while ( fgets( buf, sizeof(buf), stdin ) != NULL ) {
|
|
|
|
if( buf[len=strlen(buf)] == '\n') buf[len] = '\0';
|
|
|
|
|
1999-07-31 07:00:02 +08:00
|
|
|
if (( out = ldif_put( LDIF_PUT_VALUE, type, buf, strlen( buf ) ))
|
1998-08-09 08:43:13 +08:00
|
|
|
== NULL ) {
|
|
|
|
perror( "ldif_type_and_value" );
|
1999-08-04 02:14:24 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
fputs( out, stdout );
|
1999-06-03 08:37:44 +08:00
|
|
|
ber_memfree( out );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-08-04 02:14:24 +08:00
|
|
|
return EXIT_SUCCESS;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|