X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fshell-backends%2Fshellutil.c;h=0321061bd4c62970b2d494bbe67d7e66a39a7bb8;hb=4a87798893cb529d32cd77d50eab95cb361aa185;hp=e1a6d030a480b5830d6292c521e1fc59e1ef7988;hpb=b76c56ba3f45576b9c418ea9fe7f7b3440052904;p=openldap
diff --git a/servers/slapd/shell-backends/shellutil.c b/servers/slapd/shell-backends/shellutil.c
index e1a6d030a4..0321061bd4 100644
--- a/servers/slapd/shell-backends/shellutil.c
+++ b/servers/slapd/shell-backends/shellutil.c
@@ -1,27 +1,46 @@
-/*
- shellutil.c - common routines useful when building shell-based backends
- for the standalone ldap server
-
- Copyright (c) 1995 Regents of the University of Michigan.
- All rights reserved.
-
- Redistribution and use in source and binary forms are permitted
- provided that this notice is preserved and that due credit is given
- to the University of Michigan at Ann Arbor. The name of the University
- may not be used to endorse or promote products derived from this
- software without specific prior written permission. This software
- is provided ``as is'' without express or implied warranty.
-*/
+/* shellutil.c - common routines useful when building shell-based backends */
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 1998-2006 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * .
+ */
+/* Portions Copyright (c) 1995 Regents of the University of Michigan.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of Michigan at Ann Arbor. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was originally developed by the University of Michigan
+ * (as part of U-MICH LDAP).
+ */
#include "portable.h"
-#include
#include
-#include
-#include
+
+#include
+#include
+
#include
-#include
+
+#include
+#include
+
#include
#include
#include "shellutil.h"
@@ -84,7 +103,8 @@ write_entry( struct ldop *op, struct ldentry *entry, FILE *ofp )
int
test_filter( struct ldop *op, struct ldentry *entry )
{
- return (( random() & 0x07 ) == 0x07 ); /* XXX random for now */
+ return ((random() & 0x07 ) == 0x07) /* XXX random for now */
+ ? LDAP_COMPARE_TRUE : LDAP_COMPARE_FALSE;
}
@@ -135,7 +155,7 @@ parse_input( FILE *ifp, FILE *ofp, struct ldop *op )
struct inputparams *ip;
if ( fgets( line, MAXLINELEN, ifp ) == NULL ) {
- write_result( ofp, LDAP_OPERATIONS_ERROR, NULL, "Empty Input" );
+ write_result( ofp, LDAP_OTHER, NULL, "Empty Input" );
}
line[ strlen( line ) - 1 ] = '\0';
if ( strncasecmp( line, STR_OP_SEARCH, sizeof( STR_OP_SEARCH ) - 1 )
@@ -165,21 +185,32 @@ parse_input( FILE *ifp, FILE *ofp, struct ldop *op )
op->ldop_dn = estrdup( args );
break;
case IP_TYPE_SCOPE:
- if (( op->ldop_srch.ldsp_scope = atoi( args )) != LDAP_SCOPE_BASE &&
+ if ( lutil_atoi( &op->ldop_srch.ldsp_scope, args ) != 0 ||
+ ( op->ldop_srch.ldsp_scope != LDAP_SCOPE_BASE &&
op->ldop_srch.ldsp_scope != LDAP_SCOPE_ONELEVEL &&
- op->ldop_srch.ldsp_scope != LDAP_SCOPE_SUBTREE ) {
- write_result( ofp, LDAP_OPERATIONS_ERROR, NULL, "Bad scope" );
+ op->ldop_srch.ldsp_scope != LDAP_SCOPE_SUBTREE ) )
+ {
+ write_result( ofp, LDAP_OTHER, NULL, "Bad scope" );
return( -1 );
}
break;
case IP_TYPE_ALIASDEREF:
- op->ldop_srch.ldsp_aliasderef = atoi( args );
+ if ( lutil_atoi( &op->ldop_srch.ldsp_aliasderef, args ) != 0 ) {
+ write_result( ofp, LDAP_OTHER, NULL, "Bad alias deref" );
+ return( -1 );
+ }
break;
case IP_TYPE_SIZELIMIT:
- op->ldop_srch.ldsp_sizelimit = atoi( args );
+ if ( lutil_atoi( &op->ldop_srch.ldsp_sizelimit, args ) != 0 ) {
+ write_result( ofp, LDAP_OTHER, NULL, "Bad size limit" );
+ return( -1 );
+ }
break;
case IP_TYPE_TIMELIMIT:
- op->ldop_srch.ldsp_timelimit = atoi( args );
+ if ( lutil_atoi( &op->ldop_srch.ldsp_timelimit, args ) != 0 ) {
+ write_result( ofp, LDAP_OTHER, NULL, "Bad time limit" );
+ return( -1 );
+ }
break;
case IP_TYPE_FILTER:
op->ldop_srch.ldsp_filter = estrdup( args );
@@ -194,7 +225,7 @@ parse_input( FILE *ifp, FILE *ofp, struct ldop *op )
while ( args != NULL ) {
if (( p = strchr( args, ' ' )) != NULL ) {
*p++ = '\0';
- while ( isspace( *p )) {
+ while ( isspace( (unsigned char) *p )) {
++p;
}
}
@@ -208,7 +239,7 @@ parse_input( FILE *ifp, FILE *ofp, struct ldop *op )
if ( op->ldop_suffixes == NULL || op->ldop_dn == NULL ||
op->ldop_srch.ldsp_filter == NULL ) {
- write_result( ofp, LDAP_OPERATIONS_ERROR, NULL,
+ write_result( ofp, LDAP_OTHER, NULL,
"Required suffix:, base:, or filter: missing" );
return( -1 );
}
@@ -229,7 +260,7 @@ find_input_tag( char **linep ) /* linep is set to start of args */
for ( i = 0; ips[ i ].ip_type != 0; ++i ) {
if ( strncasecmp( *linep, ips[ i ].ip_tag, p - *linep ) == 0 ) {
- while ( isspace( *(++p) )) {
+ while ( isspace( (unsigned char) *(++p) )) {
;
}
*linep = p;
@@ -271,7 +302,7 @@ estrdup( char *s )
if (( p = strdup( s )) == NULL ) {
debug_printf( "strdup failed\n" );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
return( p );
@@ -291,7 +322,7 @@ erealloc( void *s, unsigned size )
if ( p == NULL ) {
debug_printf( "realloc( p, %d ) failed\n", size );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
return( p );
@@ -305,7 +336,7 @@ ecalloc( unsigned nelem, unsigned elsize )
if (( p = calloc( nelem, elsize )) == NULL ) {
debug_printf( "calloc( %d, %d ) failed\n", nelem, elsize );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
return( p );
@@ -316,19 +347,16 @@ ecalloc( unsigned nelem, unsigned elsize )
/* VARARGS */
void
-debug_printf( va_alist /* char *fmt, args... */ )
- va_dcl
+debug_printf( const char *fmt, ... )
{
- char *fmt;
va_list ap;
- if ( debugflg ) {
- va_start( ap );
- fmt = va_arg( ap, char * );
- fprintf( stderr, "%s: ", progname );
- vfprintf( stderr, fmt, ap );
- va_end( ap );
- }
+ if ( debugflg ) {
+ va_start( ap, fmt );
+ fprintf( stderr, "%s: ", progname );
+ vfprintf( stderr, fmt, ap );
+ va_end( ap );
+ }
}