]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/shell-backends/shellutil.c
filter2bv can't de-normalize UUIDs, must do it explicitly for back-ldap
[openldap] / servers / slapd / shell-backends / shellutil.c
index 59d43cb7073fe07c7d17ff9a17c421d4bd3780d9..0321061bd4c62970b2d494bbe67d7e66a39a7bb8 100644 (file)
@@ -1,24 +1,39 @@
-/*
- 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 <http://www.openldap.org/>.
+ *
+ * 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
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* 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 <stdio.h>
 
-#include <stdlib.h>
+#include <ac/stdlib.h>
 #include <ac/stdarg.h>
 
 #include <pwd.h>
@@ -88,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;
 }
 
 
@@ -139,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 )
@@ -169,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 );
@@ -198,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;
                        }
                    }
@@ -212,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 );
     }
@@ -233,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;
@@ -275,7 +302,7 @@ estrdup( char *s )
 
     if (( p = strdup( s )) == NULL ) {
        debug_printf( "strdup failed\n" );
-       exit( 1 );
+       exit( EXIT_FAILURE );
     }
 
     return( p );
@@ -295,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 );
@@ -309,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 );
@@ -320,26 +347,12 @@ ecalloc( unsigned nelem, unsigned elsize )
 
 /* VARARGS */
 void
-debug_printf
-#ifdef STDC_HEADERS
-       ( char *fmt, ... )
-#else
-       ( va_alist )
-    va_dcl
-#endif
+debug_printf( const char *fmt, ... )
 {
     va_list    ap;
-#ifndef STDC_HEADERS
-    char       *fmt;
-#endif
 
        if ( debugflg ) {
-#ifdef STDC_HEADERS
                va_start( ap, fmt );
-#else
-               va_start( ap );
-               fmt = va_arg( ap, char * );
-#endif
                fprintf( stderr, "%s: ", progname );
                vfprintf( stderr, fmt, ap );
                va_end( ap );