]> git.sur5r.net Git - openldap/commitdiff
use lutil_ato*() whenever appropriate
authorPierangelo Masarati <ando@openldap.org>
Thu, 24 Nov 2005 01:10:05 +0000 (01:10 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 24 Nov 2005 01:10:05 +0000 (01:10 +0000)
44 files changed:
clients/tools/ldapmodify.c
contrib/slapd-modules/smbk5pwd/smbk5pwd.c
include/lutil.h
libraries/libldap/cyrus.c
libraries/libldap/url.c
libraries/liblutil/utils.c
libraries/librewrite/config.c
libraries/librewrite/rewrite-int.h
libraries/librewrite/rewrite.c
libraries/librewrite/rule.c
servers/slapd/acl.c
servers/slapd/aclparse.c
servers/slapd/back-bdb/config.c
servers/slapd/back-ldap/config.c
servers/slapd/back-ldbm/config.c
servers/slapd/back-meta/back-meta.h
servers/slapd/back-sql/entry-id.c
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/search.c
servers/slapd/bconfig.c
servers/slapd/config.c
servers/slapd/ldapsync.c
servers/slapd/limits.c
servers/slapd/main.c
servers/slapd/mods.c
servers/slapd/overlays/ppolicy.c
servers/slapd/overlays/syncprov.c
servers/slapd/overlays/translucent.c
servers/slapd/result.c
servers/slapd/shell-backends/shellutil.c
servers/slapd/slapcommon.c
servers/slapd/user.c
servers/slapd/value.c
servers/slurpd/args.c
servers/slurpd/config.c
servers/slurpd/re.c
servers/slurpd/st.c
tests/progs/slapd-addel.c
tests/progs/slapd-bind.c
tests/progs/slapd-modify.c
tests/progs/slapd-modrdn.c
tests/progs/slapd-read.c
tests/progs/slapd-search.c
tests/progs/slapd-tester.c

index 79e187b2d47aeb12da43bbd807a433447c79d31e..481ff2f9b815b6a3b6428ba9719d28536cc989d0 100644 (file)
@@ -467,7 +467,12 @@ process_ldif_rec( char *rbuf, int count )
                                        replicaport = 0;
                                } else {
                                        *p++ = '\0';
-                                       replicaport = atoi( p );
+                                       if ( lutil_atoi( &replicaport, p ) != 0 ) {
+                                               fprintf( stderr, _("%s: unable to parse replica port \"%s\" (line %d) entry: \"%s\"\n"),
+                                                       prog, p, linenum, dn == NULL ? "" : dn );
+                                               rc = LDAP_PARAM_ERROR;
+                                               break;
+                                       }
                                }
                                if ( ldaphost != NULL &&
                                        strcasecmp( val.bv_val, ldaphost ) == 0 &&
@@ -478,7 +483,8 @@ process_ldif_rec( char *rbuf, int count )
                        } else if ( count == 1 && linenum == 1 && 
                                strcasecmp( type, T_VERSION_STR ) == 0 )
                        {
-                               if( val.bv_len == 0 || atoi(val.bv_val) != 1 ) {
+                               int     v;
+                               if( val.bv_len == 0 || lutil_atoi( &v, val.bv_val) != 0 || v != 1 ) {
                                        fprintf( stderr,
                                                _("%s: invalid version %s, line %d (ignored)\n"),
                                                prog, val.bv_val, linenum );
index f5feab29361a8da5cb42329807a2cbebcb347847..a2c176d78f37dcca79f5c10f74fe9127204e24eb 100644 (file)
@@ -377,11 +377,19 @@ static int smbk5pwd_exop_passwd(
                if ( ret ) break;
 
                a = attr_find( e->e_attrs, ad_krb5KeyVersionNumber );
+               kvno = 0;
                if ( a ) {
-                       kvno = atoi(a->a_vals[0].bv_val);
+                       if ( lutil_atoi( &kvno, a->a_vals[0].bv_val ) != 0 ) {
+                               Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: "
+                                       "dn=\"%s\" unable to parse krb5KeyVersionNumber=\"%s\"\n",
+                                       op->o_log, e->e_name.bv_val, a->a_vals[0].bv_val );
+                       }
+
                } else {
                        /* shouldn't happen, this is a required attr */
-                       kvno = 0;
+                       Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: "
+                               "dn=\"%s\" missing krb5KeyVersionNumber\n",
+                               op->o_log, e->e_name.bv_val, 0 );
                }
 
                ret = _kadm5_set_keys(kadm_context, &ent, qpw->rs_new.bv_val);
index c1a15b229f69e8026840100f4519d88c49659ad0..ebe30963f50904dd21b1a5e9dc4aed6d06a12fd8 100644 (file)
@@ -274,16 +274,21 @@ lutil_LogStoppedEvent( char *svc );
 #endif
 
 LDAP_LUTIL_F (int)
-lutil_atoi( int *v, const char *s );
+lutil_atoix( int *v, const char *s, int x );
 
 LDAP_LUTIL_F (int)
-lutil_atou( unsigned *v, const char *s );
+lutil_atoux( unsigned *v, const char *s, int x );
 
 LDAP_LUTIL_F (int)
-lutil_atol( long *v, const char *s );
+lutil_atolx( long *v, const char *s, int x );
 
 LDAP_LUTIL_F (int)
-lutil_atoul( unsigned long *v, const char *s );
+lutil_atoulx( unsigned long *v, const char *s, int x );
+
+#define lutil_atoi(v, s)       lutil_atoix((v), (s), 10)
+#define lutil_atou(v, s)       lutil_atoux((v), (s), 10)
+#define lutil_atol(v, s)       lutil_atolx((v), (s), 10)
+#define lutil_atoul(v, s)      lutil_atoulx((v), (s), 10)
 
 LDAP_LUTIL_F (int)
 lutil_parse_time( const char *in, unsigned long *tp );
index 548f365952b19d0f76fc1c6d7dd86871c65b7021..cc372d70fce1e7ef51e09eb3ceb533b138025276 100644 (file)
@@ -1026,11 +1026,11 @@ int ldap_pvt_sasl_secprops(
                        if ( strncasecmp( props[i], sprops[j].key.bv_val,
                                sprops[j].key.bv_len )) continue;
                        if ( sprops[j].ival ) {
-                               int v;
+                               unsigned v;
                                char *next = NULL;
                                if ( !isdigit( props[i][sprops[j].key.bv_len] )) continue;
                                v = strtoul( &props[i][sprops[j].key.bv_len], &next, 10 );
-                               if ( next == NULL || next[ 0 ] != '\0' ) continue;
+                               if ( next == &props[i][sprops[j].key.bv_len] || next[0] != '\0' ) continue;
                                switch( sprops[j].ival ) {
                                case GOT_MINSSF:
                                        min_ssf = v; got_min_ssf++; break;
index ecfb3808b17910fb1c75f137d6c3465334d6cfbd..8fe30b911a87c7c884cf572de9dff304a22ad7e7 100644 (file)
@@ -883,7 +883,7 @@ ldap_url_parse_ext( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
                }
 
                ludp->lud_port = strtol( q, &next, 10 );
-               if ( next == NULL || next[0] != '\0' ) {
+               if ( next == q || next[0] != '\0' ) {
                        LDAP_FREE( url );
                        ldap_free_urldesc( ludp );
                        return LDAP_URL_ERR_BADURL;
@@ -1338,7 +1338,7 @@ ldap_url_parsehosts(
                                *p++ = 0;
                                ldap_pvt_hex_unescape(p);
                                ludp->lud_port = strtol( p, &next, 10 );
-                               if ( next == NULL || next[0] != '\0' ) {
+                               if ( next == p || next[0] != '\0' ) {
                                        return LDAP_PARAM_ERROR;
                                }
                        }
index 2c84ac4afd8db0cc535bac9fbe40b9fb7c460071..f2a1a2c91d8391b9e6ce4f9b7a00ae5c6e5d4724 100644 (file)
@@ -331,7 +331,7 @@ lutil_memrchr(const void *b, int c, size_t n)
 }
 
 int
-lutil_atoi( int *v, const char *s )
+lutil_atoix( int *v, const char *s, int x )
 {
        char            *next;
        long            i;
@@ -339,7 +339,7 @@ lutil_atoi( int *v, const char *s )
        assert( s != NULL );
        assert( v != NULL );
 
-       i = strtol( s, &next, 10 );
+       i = strtol( s, &next, x );
        if ( next == s || next[ 0 ] != '\0' ) {
                return -1;
        }
@@ -354,7 +354,7 @@ lutil_atoi( int *v, const char *s )
 }
 
 int
-lutil_atou( unsigned *v, const char *s )
+lutil_atoux( unsigned *v, const char *s, int x )
 {
        char            *next;
        unsigned long   u;
@@ -362,7 +362,7 @@ lutil_atou( unsigned *v, const char *s )
        assert( s != NULL );
        assert( v != NULL );
 
-       u = strtoul( s, &next, 10 );
+       u = strtoul( s, &next, x );
        if ( next == s || next[ 0 ] != '\0' ) {
                return -1;
        }
@@ -377,7 +377,7 @@ lutil_atou( unsigned *v, const char *s )
 }
 
 int
-lutil_atol( long *v, const char *s )
+lutil_atolx( long *v, const char *s, int x )
 {
        char            *next;
        long            l;
@@ -385,7 +385,7 @@ lutil_atol( long *v, const char *s )
        assert( s != NULL );
        assert( v != NULL );
 
-       l = strtol( s, &next, 10 );
+       l = strtol( s, &next, x );
        if ( next == s || next[ 0 ] != '\0' ) {
                return -1;
        }
@@ -396,7 +396,7 @@ lutil_atol( long *v, const char *s )
 }
 
 int
-lutil_atoul( unsigned long *v, const char *s )
+lutil_atoulx( unsigned long *v, const char *s, int x )
 {
        char            *next;
        unsigned long   ul;
@@ -404,7 +404,7 @@ lutil_atoul( unsigned long *v, const char *s )
        assert( s != NULL );
        assert( v != NULL );
 
-       ul = strtoul( s, &next, 10 );
+       ul = strtoul( s, &next, x );
        if ( next == s || next[ 0 ] != '\0' ) {
                return -1;
        }
index b6c729406eb5aa0df8b99b5b8ce116ff36ca8a2c..a3956ec9233d61f6a891f5bdbb74509ba53330a1 100644 (file)
@@ -104,19 +104,33 @@ rewrite_parse(
                        return -1;
                }
 
-               info->li_max_passes = atoi( argv[ 1 ] );
+               if ( lutil_atoi( &info->li_max_passes, argv[ 1 ] ) != 0 ) {
+                       Debug( LDAP_DEBUG_ANY,
+                                       "[%s:%d] unable to parse rewriteMaxPasses=\"%s\"\n",
+                                       fname, lineno, argv[ 1 ] );
+                       return -1;
+               }
+
                if ( info->li_max_passes <= 0 ) {
                        Debug( LDAP_DEBUG_ANY,
-                                       "[%s:%d] negative or null rewriteMaxPasses'\n",
+                                       "[%s:%d] negative or null rewriteMaxPasses\n",
                                        fname, lineno, 0 );
+                       return -1;
                }
 
                if ( argc > 2 ) {
-                       info->li_max_passes_per_rule = atoi( argv[ 2 ] );
+                       if ( lutil_atoi( &info->li_max_passes_per_rule, argv[ 2 ] ) != 0 ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                               "[%s:%d] unable to parse rewriteMaxPassesPerRule=\"%s\"\n",
+                                               fname, lineno, argv[ 2 ] );
+                               return -1;
+                       }
+
                        if ( info->li_max_passes_per_rule <= 0 ) {
                                Debug( LDAP_DEBUG_ANY,
-                                               "[%s:%d] negative or null rewriteMaxPassesPerRule'\n",
+                                               "[%s:%d] negative or null rewriteMaxPassesPerRule\n",
                                                fname, lineno, 0 );
+                               return -1;
                        }
 
                } else {
index fb8dbf6ee47d7fd1c3fc3e544bd73bf7acadd44b..b983af65a4c0c5837b09f457211cbbd52ae4a2ce 100644 (file)
@@ -34,7 +34,7 @@
 #include <lber.h>
 #include <ldap.h>
 #include "../libldap/ldap-int.h"
-
+#include <lutil.h>
 #include <avl.h>
 
 #include <rewrite.h>
index b040ee7fd2b2a755c18801bbaf265d44d6a1e1ce..95976993f83df9b7dfccd4d4ac0f8a02551478fb 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 
 #include <rewrite.h>
+#include <lutil.h>
 #include <ldap.h>
 
 int ldap_debug;
@@ -127,7 +128,6 @@ main( int argc, char *argv[] )
        FILE    *fin = NULL;
        char    *rewriteContext = REWRITE_DEFAULT_CONTEXT;
        int     debug = 0;
-       char    *next;
 
        while ( 1 ) {
                int opt = getopt( argc, argv, "d:f:hr:" );
@@ -138,8 +138,7 @@ main( int argc, char *argv[] )
 
                switch ( opt ) {
                case 'd':
-                       debug = strtol( optarg, &next, 10 );
-                       if ( next == NULL || next[0] != '\0' ) {
+                       if ( lutil_atoi( &debug, optarg ) != 0 ) {
                                fprintf( stderr, "illegal log level '%s'\n",
                                                optarg );
                                exit( EXIT_FAILURE );
index 84ff22b4175918c505e6dd3fad817dc12914d026..dcf7503057fb35338232f21ec9ae9d621a11e1d3 100644 (file)
@@ -233,7 +233,7 @@ rewrite_rule_compile(
                        }
 
                        d[ 0 ] = strtol( &p[ 2 ], &next, 0 );
-                       if ( next == NULL || next == &p[ 2 ] || next[0] != '}' ) {
+                       if ( next == &p[ 2 ] || next[0] != '}' ) {
                                /* XXX Need to free stuff */
                                return REWRITE_ERR;
                        }
@@ -275,7 +275,7 @@ rewrite_rule_compile(
                        }
 
                        max_passes = strtol( &p[ 2 ], &next, 0 );
-                       if ( next == NULL || next == &p[ 2 ] || next[0] != '}' ) {
+                       if ( next == &p[ 2 ] || next[0] != '}' ) {
                                /* XXX Need to free stuff */
                                return REWRITE_ERR;
                        }
index 5b84f9e3045225dffff4faf4f8a8c9fa63fdf41d..423f1c92cdedf04d273cc4ccb303a6ab796dc0d6 100644 (file)
@@ -1603,12 +1603,9 @@ slap_acl_mask(
 
                                                port = strrchr( ip.bv_val, ':' );
                                                if ( port ) {
-                                                       char    *next;
-                                                       
                                                        ip.bv_len = port - ip.bv_val;
                                                        ++port;
-                                                       port_number = strtol( port, &next, 10 );
-                                                       if ( next[0] != '\0' )
+                                                       if ( lutil_atoi( &port_number, port ) != 0 )
                                                                continue;
                                                }
                                                
index 3c52759f7033aa55afc9b13438d3c3ac99913ec7..3cd2d5c9c9429ca4a8e985d3fb52f57722f4913a 100644 (file)
@@ -778,8 +778,7 @@ parse_acl(
                                {
                                        char    *next;
 
-                                       level = strtol( style_level, &next, 10 );
-                                       if ( next[0] != '\0' ) {
+                                       if ( lutil_atoi( &level, style_level ) != 0 ) {
                                                Debug( LDAP_DEBUG_ANY,
                                                        "%s: line %d: unable to parse level "
                                                        "in \"level{n}\"\n",
@@ -1385,7 +1384,7 @@ parse_acl(
                                                                char    *end = NULL;
 
                                                                b->a_peername_port = strtol( port, &end, 10 );
-                                                               if ( end[0] != '}' ) {
+                                                               if ( end == port || end[0] != '}' ) {
                                                                        /* illegal port */
                                                                        Debug( LDAP_DEBUG_ANY, "%s: line %d: "
                                                                                "illegal peername port specification "
@@ -1700,8 +1699,7 @@ parse_acl(
                                                return acl_usage();
                                        }
 
-                                       b->a_authz.sai_ssf = strtol( right, &next, 10 );
-                                       if ( next == NULL || next[0] != '\0' ) {
+                                       if ( lutil_atou( &b->a_authz.sai_ssf, right ) != 0 ) {
                                                Debug( LDAP_DEBUG_ANY,
                                                        "%s: line %d: unable to parse ssf value (%s).\n",
                                                        fname, lineno, right );
@@ -1739,8 +1737,7 @@ parse_acl(
                                                return acl_usage();
                                        }
 
-                                       b->a_authz.sai_transport_ssf = strtol( right, &next, 10 );
-                                       if ( next == NULL || next[0] != '\0' ) {
+                                       if ( lutil_atou( &b->a_authz.sai_transport_ssf, right ) != 0 ) {
                                                Debug( LDAP_DEBUG_ANY, "%s: line %d: "
                                                        "unable to parse transport_ssf value (%s).\n",
                                                        fname, lineno, right );
@@ -1778,8 +1775,7 @@ parse_acl(
                                                return acl_usage();
                                        }
 
-                                       b->a_authz.sai_tls_ssf = strtol( right, &next, 10 );
-                                       if ( next == NULL || next[0] != '\0' ) {
+                                       if ( lutil_atou( &b->a_authz.sai_tls_ssf, right ) != 0 ) {
                                                Debug( LDAP_DEBUG_ANY, "%s: line %d: "
                                                        "unable to parse tls_ssf value (%s).\n",
                                                        fname, lineno, right );
@@ -1817,8 +1813,7 @@ parse_acl(
                                                return acl_usage();
                                        }
 
-                                       b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 );
-                                       if ( next == NULL || next[0] != '\0' ) {
+                                       if ( lutil_atou( &b->a_authz.sai_sasl_ssf, right ) != 0 ) {
                                                Debug( LDAP_DEBUG_ANY, "%s: line %d: "
                                                        "unable to parse sasl_ssf value (%s).\n",
                                                        fname, lineno, right );
index fa2bf98de5432a7c3f50e06bc12319a3a5a9da23..637bc027acc71a537b53d7b4c6d0f980d2a20200 100644 (file)
@@ -484,10 +484,23 @@ bdb_cf_gen(ConfigArgs *c)
        }
 
        switch( c->type ) {
-       case BDB_CHKPT:
+       case BDB_CHKPT: {
+               long    l;
                bdb->bi_txn_cp = 1;
-               bdb->bi_txn_cp_kbyte = strtol( c->argv[1], NULL, 0 );
-               bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 );
+               if ( lutil_atolx( &l, c->argv[1], 0 ) != 0 ) {
+                       fprintf( stderr, "%s: "
+                               "invalid kbyte \"%s\" in \"checkpoint\".\n",
+                               c->log, c->argv[1] );
+                       return 1;
+               }
+               bdb->bi_txn_cp_kbyte = l;
+               if ( lutil_atolx( &l, c->argv[2], 0 ) != 0 ) {
+                       fprintf( stderr, "%s: "
+                               "invalid minutes \"%s\" in \"checkpoint\".\n",
+                               c->log, c->argv[2] );
+                       return 1;
+               }
+               bdb->bi_txn_cp_min = l;
                /* If we're in server mode and time-based checkpointing is enabled,
                 * submit a task to perform periodic checkpoints.
                 */
@@ -507,7 +520,7 @@ bdb_cf_gen(ConfigArgs *c)
                                        LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val );
                        }
                }
-               break;
+               break;
 
        case BDB_CONFIG: {
                char *ptr = c->line;
index da838e3c6c718dbe726788d0611c08374d2b1597..b3ef34d0e8e8e7dcbfdb60af38a8f173c75a36fb 100644 (file)
@@ -1090,12 +1090,10 @@ done_url:;
 
                for ( i = 1; i < c->argc; i++ ) {
                        if ( isdigit( c->argv[ i ][ 0 ] ) ) {
-                               char            *next;
                                int             j;
                                unsigned        u;
 
-                               u = strtoul( c->argv[ i ], &next, 0 );
-                               if ( next == c->argv[ i ] || next[ 0 ] != '\0' ) {
+                               if ( lutil_atoux( &u, c->argv[ i ], 0 ) != 0 ) {
                                        return 1;
                                }
 
index 2a0a5759ee2ebf6ca9567dcd006b84f068613dbe..5309f2e0c39adf623fd1ef0e2b8eaf5c509dd739 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "slap.h"
 #include "back-ldbm.h"
+#include "lutil.h"
 
 int
 ldbm_back_db_config(
@@ -62,7 +63,12 @@ ldbm_back_db_config(
                            fname, lineno );
                        return( 1 );
                }
-               li->li_mode = strtol( argv[1], NULL, 0 );
+               if ( lutil_atoix( &li->li_mode, argv[1], 0 ) != 0 ) {
+                       fprintf( stderr,
+                       "%s: line %d: unable to parse mode=\"%s\" in \"mode <mode>\" line\n",
+                           fname, lineno, argv[1] );
+                       return( 1 );
+               }
 
        /* attribute to index */
        } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
@@ -91,7 +97,12 @@ ldbm_back_db_config(
                            fname, lineno );
                        return( 1 );
                }
-               li->li_cache.c_maxsize = atoi( argv[1] );
+               if ( lutil_atoi( &li->li_cache.c_maxsize, argv[1] ) != 0 ) {
+                       fprintf( stderr,
+               "%s: line %d: unable to parse cachesize \"%s\"\n",
+                           fname, lineno, argv[1] );
+                       return( 1 );
+               }
 
        /* size of each dbcache in bytes */
        } else if ( strcasecmp( argv[0], "dbcachesize" ) == 0 ) {
@@ -101,7 +112,12 @@ ldbm_back_db_config(
                            fname, lineno );
                        return( 1 );
                }
-               li->li_dbcachesize = atoi( argv[1] );
+               if ( lutil_atoi( &li->li_dbcachesize, argv[1] ) ) {
+                       fprintf( stderr,
+               "%s: line %d: unable to parse dbcachesize \"%s\"\n",
+                           fname, lineno, argv[1] );
+                       return( 1 );
+               }
 
        /* no locking (not safe) */
        } else if ( strcasecmp( argv[0], "dbnolocking" ) == 0 ) {
@@ -124,9 +140,7 @@ ldbm_back_db_config(
                        return 1;
                }
 
-               i = atoi( argv[1] );
-
-               if( i < 0 ) {
+               if ( lutil_atoi( &i, argv[1] ) != 0 || i < 0 ) {
                        Debug( LDAP_DEBUG_ANY,
     "%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
                            fname, lineno, i );
@@ -136,8 +150,7 @@ ldbm_back_db_config(
                li->li_dbsyncfreq = i;
 
                if ( argc > 2 ) {
-                       i = atoi( argv[2] );
-                       if ( i < 0 ) {
+                       if ( lutil_atoi( &i, argv[2] ) != 0 || i < 0 ) {
                                Debug( LDAP_DEBUG_ANY,
            "%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
                                    fname, lineno, i );
@@ -147,8 +160,7 @@ ldbm_back_db_config(
                }
 
                if ( argc > 3 ) {
-                       i = atoi( argv[3] );
-                       if ( i <= 0 ) {
+                       if ( lutil_atoi( &i, argv[3] ) != 0 || i <= 0 ) {
                                Debug( LDAP_DEBUG_ANY,
            "%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
                                    fname, lineno, i );
index 89f21d8b310823df13455bd2fec2facfaef25d5a..8ac932bb9996585ff2ebf15b3f8bda0929675444 100644 (file)
@@ -236,8 +236,8 @@ typedef struct metadncache_t {
        Avlnode                 *tree;
 
 #define META_DNCACHE_DISABLED   (0)
-#define META_DNCACHE_FOREVER    (-1)
-       long int                ttl;  /* seconds; 0: no cache, -1: no expiry */
+#define META_DNCACHE_FOREVER    ((time_t)(-1))
+       time_t                  ttl;  /* seconds; 0: no cache, -1: no expiry */
 } metadncache_t;
 
 typedef struct metacandidates_t {
index 213fd7096c06c407333458d1610d051d1254f94f..9d33b9df729ef27ff0800eeb7d25603e819ac5e5 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/types.h>
 #include "ac/string.h"
 
+#include "lutil.h"
 #include "slap.h"
 #include "proto-sql.h"
 
@@ -250,43 +251,52 @@ backsql_dn2id(
                if ( id != NULL ) {
                        struct berval   dn;
 
+                       id->eid_next = NULL;
+
 #ifdef BACKSQL_ARBITRARY_KEY
                        ber_str2bv_x( row.cols[ 0 ], 0, 1, &id->eid_id,
                                        op->o_tmpmemctx );
                        ber_str2bv_x( row.cols[ 1 ], 0, 1, &id->eid_keyval,
                                        op->o_tmpmemctx );
 #else /* ! BACKSQL_ARBITRARY_KEY */
-                       id->eid_id = strtol( row.cols[ 0 ], NULL, 0 );
-                       id->eid_keyval = strtol( row.cols[ 1 ], NULL, 0 );
+                       if ( lutil_atoulx( &id->eid_id, row.cols[ 0 ], 0 ) != 0 ) {
+                               res = LDAP_OTHER;
+                               goto done;
+                       }
+                       if ( lutil_atoulx( &id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) {
+                               res = LDAP_OTHER;
+                               goto done;
+                       }
 #endif /* ! BACKSQL_ARBITRARY_KEY */
-                       id->eid_oc_id = strtol( row.cols[ 2 ], NULL, 0 );
+                       if ( lutil_atoulx( &id->eid_oc_id, row.cols[ 2 ], 0 ) != 0 ) {
+                               res = LDAP_OTHER;
+                               goto done;
+                       }
 
                        ber_str2bv( row.cols[ 3 ], 0, 0, &dn );
 
                        if ( backsql_api_odbc2dn( op, rs, &dn ) ) {
                                res = LDAP_OTHER;
-
-                       } else {
-                               res = dnPrettyNormal( NULL, &dn,
-                                               &id->eid_dn, &id->eid_ndn,
-                                               op->o_tmpmemctx );
-                               if ( res != LDAP_SUCCESS ) {
-                                       Debug( LDAP_DEBUG_TRACE,
-                                               "   backsql_dn2id(\"%s\"): "
-                                               "dnPrettyNormal failed (%d: %s)\n",
-                                               realndn.bv_val, res,
-                                               ldap_err2string( res ) );
-
-                                       /* cleanup... */
-                                       (void)backsql_free_entryID( op, id, 0 );
-                               }
-
-                               if ( dn.bv_val != row.cols[ 3 ] ) {
-                                       free( dn.bv_val );
-                               }
+                               goto done;
+                       }
+                       
+                       res = dnPrettyNormal( NULL, &dn,
+                                       &id->eid_dn, &id->eid_ndn,
+                                       op->o_tmpmemctx );
+                       if ( res != LDAP_SUCCESS ) {
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "   backsql_dn2id(\"%s\"): "
+                                       "dnPrettyNormal failed (%d: %s)\n",
+                                       realndn.bv_val, res,
+                                       ldap_err2string( res ) );
+
+                               /* cleanup... */
+                               (void)backsql_free_entryID( op, id, 0 );
                        }
 
-                       id->eid_next = NULL;
+                       if ( dn.bv_val != row.cols[ 3 ] ) {
+                               free( dn.bv_val );
+                       }
                }
 
        } else {
@@ -408,11 +418,28 @@ backsql_count_children(
                char *end;
 
                *nchildren = strtol( row.cols[ 0 ], &end, 0 );
-               if ( end[ 0 ] != '\0' && end[0] != '.' ) {
-                       /* FIXME: braindead RDBMSes return
-                        * a fractional number from COUNT!
-                        */
+               if ( end == row.cols[ 0 ] ) {
                        res = LDAP_OTHER;
+
+               } else {
+                       switch ( end[ 0 ] ) {
+                       case '\0':
+                               break;
+
+                       case '.': {
+                               unsigned long   ul;
+
+                               /* FIXME: braindead RDBMSes return
+                                * a fractional number from COUNT!
+                                */
+                               if ( lutil_atoul( &ul, end + 1 ) != 0 || ul != 0 ) {
+                                       res = LDAP_OTHER;
+                               }
+                               } break;
+
+                       default:
+                               res = LDAP_OTHER;
+                       }
                }
 
        } else {
index 11056f039e7dc044ddf6cee04e9246f40ac24feb..24342fcc665d988023e4deb02e1c13b41c809ab1 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/types.h>
 #include "ac/string.h"
 
+#include "lutil.h"
 #include "slap.h"
 #include "proto-sql.h"
 
@@ -316,7 +317,6 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
        backsql_BindRowAsStrings( bas->bas_sth, &at_row );
        for ( ; rc = SQLFetch( bas->bas_sth ), BACKSQL_SUCCESS( rc ); ) {
                const char      *text = NULL;
-               char            *next = NULL;
                struct berval   bv;
                struct berbuf   bb = BB_NULL;
 
@@ -377,14 +377,10 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
                if ( at_row.value_len[ 5 ] > 0 ) {
                        at_map->bam_delete_proc = ch_strdup( at_row.cols[ 5 ] );
                }
-               at_map->bam_param_order = strtol( at_row.cols[ 6 ], 
-                               &next, 0 );
-               if ( next == at_row.cols[ 6 ] || next[0] != '\0' ) {
+               if ( lutil_atoix( &at_map->bam_param_order, at_row.cols[ 6 ], 0 ) != 0 ) {
                        /* error */
                }
-               at_map->bam_expect_return = strtol( at_row.cols[ 7 ],
-                               &next, 0 );
-               if ( next == at_row.cols[ 7 ] || next[0] != '\0' ) {
+               if ( lutil_atoix( &at_map->bam_expect_return, at_row.cols[ 7 ], 0 ) != 0 ) {
                        /* error */
                }
                backsql_make_attr_query( bas->bas_bi, oc_map, at_map );
@@ -485,7 +481,12 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh )
                oc_map = (backsql_oc_map_rec *)ch_calloc( 1,
                                sizeof( backsql_oc_map_rec ) );
 
-               oc_map->bom_id = strtol( oc_row.cols[ 0 ], NULL, 0 );
+               if ( lutil_atoulx( &oc_map->bom_id, oc_row.cols[ 0 ], 0 ) != 0 ) {
+                       Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
+                               "unable to parse id=\"%s\"\n", 
+                               oc_row.cols[ 0 ], 0, 0 );
+                       return LDAP_OTHER;
+               }
 
                oc_map->bom_oc = oc_find( oc_row.cols[ 1 ] );
                if ( oc_map->bom_oc == NULL ) {
@@ -508,8 +509,12 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh )
                }
                oc_map->bom_delete_proc = ( oc_row.value_len[ colnum ] < 0 ) ? NULL 
                        : ch_strdup( oc_row.cols[ colnum ] );
-               oc_map->bom_expect_return = strtol( oc_row.cols[ colnum + 1 ], 
-                               NULL, 0 );
+               if ( lutil_atoix( &oc_map->bom_expect_return, oc_row.cols[ colnum + 1 ], 0 ) != 0 ) {
+                       Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
+                               "unable to parse expect_return=\"%s\" for objectClass \"%s\"\n", 
+                               oc_row.cols[ colnum + 1 ], oc_row.cols[ 1 ], 0 );
+                       return LDAP_OTHER;
+               }
 
                colnum += 2;
                if ( ( oc_row.ncols > colnum ) &&
index 2fe00acb2c6ffbcedccde806ba178bdac33f725a..6045fa9bfec8d689a7a0ee3c077c58e947a01317 100644 (file)
@@ -28,6 +28,7 @@
 #include "ac/string.h"
 #include "ac/ctype.h"
 
+#include "lutil.h"
 #include "slap.h"
 #include "proto-sql.h"
 
@@ -1828,21 +1829,23 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
                }
 
                if ( bi->sql_baseObject && dn_match( &ndn, &bi->sql_baseObject->e_nname ) ) {
-                       op->o_tmpfree( pdn.bv_val, op->o_tmpmemctx );
-                       op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
-                       continue;
+                       goto cleanup;
                }
 
-               c_id = (backsql_entryID *)ch_calloc( 1, 
-                               sizeof( backsql_entryID ) );
+               c_id = (backsql_entryID *)op->o_tmpcalloc( 1, 
+                               sizeof( backsql_entryID ), op->o_tmpmemctx );
 #ifdef BACKSQL_ARBITRARY_KEY
                ber_str2bv_x( row.cols[ 0 ], 0, 1, &c_id->eid_id,
                                op->o_tmpmemctx );
                ber_str2bv_x( row.cols[ 1 ], 0, 1, &c_id->eid_keyval,
                                op->o_tmpmemctx );
 #else /* ! BACKSQL_ARBITRARY_KEY */
-               c_id->eid_id = strtol( row.cols[ 0 ], NULL, 0 );
-               c_id->eid_keyval = strtol( row.cols[ 1 ], NULL, 0 );
+               if ( lutil_atoulx( &c_id->eid_id, row.cols[ 0 ], 0 ) != 0 ) {
+                       goto cleanup;
+               }
+               if ( lutil_atoulx( &c_id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) {
+                       goto cleanup;
+               }
 #endif /* ! BACKSQL_ARBITRARY_KEY */
                c_id->eid_oc_id = bsi->bsi_oc->bom_id;
 
@@ -1870,6 +1873,18 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
                if ( bsi->bsi_n_candidates == -1 ) {
                        break;
                }
+               continue;
+
+cleanup:;
+               if ( !BER_BVISNULL( &pdn ) ) {
+                       op->o_tmpfree( pdn.bv_val, op->o_tmpmemctx );
+               }
+               if ( !BER_BVISNULL( &ndn ) ) {
+                       op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
+               }
+               if ( c_id != NULL ) {
+                       ch_free( c_id );
+               }
        }
        backsql_FreeRow_x( &row, bsi->bsi_op->o_tmpmemctx );
        SQLFreeStmt( sth, SQL_DROP );
index d02a5816cebde73094fd6e38961d47a7594cad98..267823b73cae2788ed08334fc7f685fc2fc8bb36 100644 (file)
@@ -1525,20 +1525,11 @@ config_sizelimit(ConfigArgs *c) {
                        if(!strcasecmp(c->argv[i], "unlimited")) {
                                lim->lms_s_soft = -1;
                        } else {
-                               lim->lms_s_soft = strtol(c->argv[i], &next, 0);
-                               if(next == c->argv[i]) {
+                               if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
                                        snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]);
                                        Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
                                                c->log, c->msg, c->argv[i]);
                                        return(1);
-                               } else if(next[0] != '\0') {
-                                       Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
-                                               "trailing chars \"%s\" in \"sizelimit <limit>\" line"
-                                               SLAPD_CONF_UNKNOWN_IGNORED ".\n",
-                                               c->log, next, 0);
-#ifdef SLAPD_CONF_UNKNOWN_BAILOUT
-                                       return 1;
-#endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
                                }
                        }
                        lim->lms_s_hard = 0;
@@ -1582,20 +1573,11 @@ config_timelimit(ConfigArgs *c) {
                        if(!strcasecmp(c->argv[i], "unlimited")) {
                                lim->lms_t_soft = -1;
                        } else {
-                               lim->lms_t_soft = strtol(c->argv[i], &next, 0);
-                               if(next == c->argv[i]) {
+                               if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
                                        snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]);
                                        Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
                                                c->log, c->msg, c->argv[i]);
                                        return(1);
-                               } else if(next[0] != '\0') {
-                                       Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
-                                               "trailing chars \"%s\" in \"timelimit <limit>\" line"
-                                               SLAPD_CONF_UNKNOWN_IGNORED ".\n",
-                                               c->log, next, 0);
-#ifdef SLAPD_CONF_UNKNOWN_BAILOUT
-                                       return 1;
-#endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
                                }
                        }
                        lim->lms_t_hard = 0;
@@ -2186,8 +2168,7 @@ config_loglevel(ConfigArgs *c) {
                int     level;
 
                if ( isdigit( c->argv[i][0] ) || c->argv[i][0] == '-' ) {
-                       level = strtol( c->argv[i], &next, 10 );
-                       if ( next == NULL || next[0] != '\0' ) {
+                       if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
                                snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse level", c->argv[0] );
                                Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
                                        c->log, c->msg, c->argv[i]);
@@ -2308,8 +2289,7 @@ config_security(ConfigArgs *c) {
                        return(1);
                }
 
-               *tgt = strtol(src, &next, 10);
-               if(next == NULL || next[0] != '\0' ) {
+               if ( lutil_atou( tgt, src ) != 0 ) {
                        snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse factor", c->argv[0] );
                        Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
                                c->log, c->msg, c->argv[i]);
@@ -2718,8 +2698,13 @@ config_tls_config(ConfigArgs *c) {
                return ldap_pvt_tls_set_option( NULL, flag, &i );
        }
        ch_free( c->value_string );
-       if(isdigit((unsigned char)c->argv[1][0])) {
-               i = atoi(c->argv[1]);
+       if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
+               if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
+                       Debug(LDAP_DEBUG_ANY, "%s: "
+                               "unable to parse %s \"%s\"\n",
+                               c->log, c->argv[0], c->argv[1] );
+                       return 1;
+               }
                return(ldap_pvt_tls_set_option(NULL, flag, &i));
        } else {
                return(ldap_int_tls_config(NULL, flag, c->argv[1]));
@@ -3202,7 +3187,9 @@ check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
                if ( ptr2-ptr1 == 1)
                        return LDAP_NAMING_VIOLATION;
                gotindex = 1;
-               index = atoi(ptr1+1);
+               if ( lutil_atoi( &index, ptr1 + 1 ) != 0 ) {
+                       return LDAP_NAMING_VIOLATION;
+               }
                if ( index < 0 ) {
                        /* Special case, we allow -1 for the frontendDB */
                        if ( index != -1 || ce_type != Cft_Database ||
@@ -3750,9 +3737,13 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
                                }
                                for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
                                        if ( ml->sml_values[i].bv_val[0] == '{' &&
-                                               navals >= 0 ) {
-                                               int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 );
-                                               if ( j < navals ) {
+                                               navals >= 0 )
+                                       {
+                                               char    *next, *val = ml->sml_values[i].bv_val + 1;
+                                               int     j;
+
+                                               j = strtol( val, &next, 0 );
+                                               if ( next == val || next[ 0 ] != '}' || j < navals ) {
                                                        rc = LDAP_OTHER;
                                                        snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
                                                                ml->sml_desc->ad_cname.bv_val );
@@ -3870,10 +3861,17 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
                                        ca->line = ml->sml_values[i].bv_val;
                                        ca->valx = -1;
                                        if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
-                                               ca->line[0] == '{' ) {
-                                               ptr = strchr( ca->line, '}' );
+                                               ca->line[0] == '{' )
+                                       {
+                                               ptr = strchr( ca->line + 1, '}' );
                                                if ( ptr ) {
-                                                       ca->valx = strtol( ca->line+1, NULL, 0 );
+                                                       char    *next;
+
+                                                       ca->valx = strtol( ca->line + 1, &next, 0 );
+                                                       if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
+                                                               rc = LDAP_OTHER;
+                                                               goto out;
+                                                       }
                                                        ca->line = ptr+1;
                                                }
                                        }
index 0c9fc587981c786ab1aa1599b34c2bc20ba0f215..5e57b2703c761b02cd543e5edc8da3b6549316e9 100644 (file)
@@ -191,20 +191,49 @@ int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
                int j;
                iarg = 0; larg = 0; barg = 0;
                switch(arg_type & ARGS_NUMERIC) {
-                       case ARG_INT:           iarg = strtol(c->argv[1], NULL, 0); break;
-                       case ARG_LONG:          larg = strtol(c->argv[1], NULL, 0);     break;
-                       case ARG_BER_LEN_T:     barg = (ber_len_t)atol(c->argv[1]);     break;
+                       case ARG_INT:
+                               if ( lutil_atoi( &iarg, c->argv[1] ) != 0 ) {
+                                       snprintf( c->msg, sizeof( c->msg ),
+                                               "<%s> unable to parse \"%s\" as int",
+                                               c->argv[0], c->argv[1] );
+                                       Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
+                                               c->log, c->msg, 0);
+                                       return(ARG_BAD_CONF);
+                               }
+                               break;
+                       case ARG_LONG:
+                               if ( lutil_atol( &larg, c->argv[1] ) != 0 ) {
+                                       snprintf( c->msg, sizeof( c->msg ),
+                                               "<%s> unable to parse \"%s\" as long",
+                                               c->argv[0], c->argv[1] );
+                                       Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
+                                               c->log, c->msg, 0);
+                                       return(ARG_BAD_CONF);
+                               }
+                               break;
+                       case ARG_BER_LEN_T: {
+                               unsigned long   l;
+                               if ( lutil_atoul( &l, c->argv[1] ) != 0 ) {
+                                       snprintf( c->msg, sizeof( c->msg ),
+                                               "<%s> unable to parse \"%s\" as ber_len_t",
+                                               c->argv[0], c->argv[1] );
+                                       Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
+                                               c->log, c->msg, 0);
+                                       return(ARG_BAD_CONF);
+                               }
+                               barg = (ber_len_t)l;
+                               } break;
                        case ARG_ON_OFF:
-                               if(c->argc == 1) {
+                               if (c->argc == 1) {
                                        iarg = 1;
-                               } else if(!strcasecmp(c->argv[1], "on") ||
+                               } else if ( !strcasecmp(c->argv[1], "on") ||
                                        !strcasecmp(c->argv[1], "true") ||
-                                       !strcasecmp(c->argv[1], "yes"))
+                                       !strcasecmp(c->argv[1], "yes") )
                                {
                                        iarg = 1;
-                               } else if(!strcasecmp(c->argv[1], "off") ||
+                               } else if ( !strcasecmp(c->argv[1], "off") ||
                                        !strcasecmp(c->argv[1], "false") ||
-                                       !strcasecmp(c->argv[1], "no"))
+                                       !strcasecmp(c->argv[1], "no") )
                                {
                                        iarg = 0;
                                } else {
@@ -1018,9 +1047,11 @@ slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, L
 
        for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
                if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
-                       char **cptr, *next;
+                       char **cptr;
                        int *iptr, j;
                        unsigned *uptr;
+                       long *lptr;
+                       unsigned long *ulptr;
                        struct berval *bptr;
                        const char *val = word + tab->key.bv_len;
 
@@ -1051,19 +1082,25 @@ slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, L
                        case 'i':
                                iptr = (int *)((char *)dst + tab->off);
 
-                               *iptr = strtol( val, &next, 0 );
-                               if ( next == val || next[ 0 ] != '\0' ) {
-                                       rc = 1;
-                               }
+                               rc = lutil_atoix( iptr, val, 0 );
                                break;
 
                        case 'u':
                                uptr = (unsigned *)((char *)dst + tab->off);
 
-                               *uptr = strtoul( val, &next, 0 );
-                               if ( next == val || next[ 0 ] != '\0' ) {
-                                       rc = 1;
-                               }
+                               rc = lutil_atoux( uptr, val, 0 );
+                               break;
+
+                       case 'I':
+                               lptr = (long *)((char *)dst + tab->off);
+
+                               rc = lutil_atolx( lptr, val, 0 );
+                               break;
+
+                       case 'U':
+                               ulptr = (unsigned long *)((char *)dst + tab->off);
+
+                               rc = lutil_atoulx( ulptr, val, 0 );
                                break;
                        }
 
@@ -1091,6 +1128,8 @@ slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0
                char **cptr;
                int *iptr, i;
                unsigned *uptr;
+               long *lptr;
+               unsigned long *ulptr;
                struct berval *bptr;
 
                cptr = (char **)((char *)src + tab->off);
@@ -1136,6 +1175,23 @@ slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0
                        ptr = lutil_strcopy( ptr, tab->key.bv_val );
                        ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%u", *uptr );
                        break;
+
+               case 'I':
+                       lptr = (long *)((char *)src + tab->off);
+                       *ptr++ = ' ';
+                       ptr = lutil_strcopy( ptr, tab->key.bv_val );
+                       ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%ld", *lptr );
+                       break;
+
+               case 'U':
+                       ulptr = (unsigned long *)((char *)src + tab->off);
+                       *ptr++ = ' ';
+                       ptr = lutil_strcopy( ptr, tab->key.bv_val );
+                       ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%lu", *ulptr );
+                       break;
+
+               default:
+                       assert( 0 );
                }
        }
        tmp.bv_val = buf;
index e2037811910ce622db318fd55ae87e720fb0cb0c..f4e80ac873efdbcae87dd429bdb0e3210b4cb187 100644 (file)
@@ -112,7 +112,6 @@ slap_parse_sync_cookie(
                || rid_ptr > &cookie->octet_str.bv_val[ cookie->octet_str.bv_len - STRLENOF( "rid=" ) ] )
        {
                return -1;
-
        }
 
        cookie->rid = strtoul( &rid_ptr[ STRLENOF( "rid=" ) ], &next, 10 );
index 691a1163661659fb730db628a721666d26ea3c45..053efd90bd3116dd19bb942dd7896f7fe5277166 100644 (file)
@@ -650,14 +650,9 @@ limits_parse_one(
                                        limit->lms_t_soft = -1;
 
                                } else {
-                                       char    *next = NULL;
-                                       int     soft = strtol( arg, &next, 10 );
+                                       int     soft;
 
-                                       if ( next == arg || next[ 0 ] != '\0' ) {
-                                               return( 1 );
-                                       }
-
-                                       if ( soft < -1 ) {
+                                       if ( lutil_atoi( &soft, arg ) != 0 || soft < -1 ) {
                                                return( 1 );
                                        }
 
@@ -677,14 +672,9 @@ limits_parse_one(
                                        limit->lms_t_hard = -1;
 
                                } else {
-                                       char    *next = NULL;
-                                       int     hard = strtol( arg, &next, 10 );
-
-                                       if ( next == arg || next[ 0 ] != '\0' ) {
-                                               return( 1 );
-                                       }
+                                       int     hard;
 
-                                       if ( hard < -1 ) {
+                                       if ( lutil_atoi( &hard, arg ) != 0 || hard < -1 ) {
                                                return( 1 );
                                        }
 
@@ -709,10 +699,9 @@ limits_parse_one(
                                limit->lms_t_soft = -1;
 
                        } else {
-                               char    *next = NULL;
-
-                               limit->lms_t_soft = strtol( arg, &next, 10 );
-                               if ( next == arg || limit->lms_t_soft < -1 ) {
+                               if ( lutil_atoi( &limit->lms_t_soft, arg ) != 0 
+                                       || limit->lms_t_soft < -1 )
+                               {
                                        return( 1 );
                                }
                        }
@@ -733,14 +722,9 @@ limits_parse_one(
                                        limit->lms_s_soft = -1;
 
                                } else {
-                                       char    *next = NULL;
-                                       int     soft = strtol( arg, &next, 10 );
-
-                                       if ( next == arg || next[ 0 ] != '\0' ) {
-                                               return( 1 );
-                                       }
+                                       int     soft;
 
-                                       if ( soft < -1 ) {
+                                       if ( lutil_atoi( &soft, arg ) != 0 || soft < -1 ) {
                                                return( 1 );
                                        }
 
@@ -760,14 +744,9 @@ limits_parse_one(
                                        limit->lms_s_hard = -1;
 
                                } else {
-                                       char    *next = NULL;
-                                       int     hard = strtol( arg, &next, 10 );
+                                       int     hard;
 
-                                       if ( next == arg || next[ 0 ] != '\0' ) {
-                                               return( 1 );
-                                       }
-
-                                       if ( hard < -1 ) {
+                                       if ( lutil_atoi( &hard, arg ) != 0 || hard < -1 ) {
                                                return( 1 );
                                        }
 
@@ -791,14 +770,9 @@ limits_parse_one(
                                        limit->lms_s_unchecked = 0;
 
                                } else {
-                                       char    *next = NULL;
-                                       int     unchecked = strtol( arg, &next, 10 );
-
-                                       if ( next == arg || next[ 0 ] != '\0' ) {
-                                               return( 1 );
-                                       }
+                                       int     unchecked;
 
-                                       if ( unchecked < -1 ) {
+                                       if ( lutil_atoi( &unchecked, arg ) != 0 || unchecked < -1 ) {
                                                return( 1 );
                                        }
 
@@ -818,14 +792,9 @@ limits_parse_one(
                                        limit->lms_s_pr = -1;
 
                                } else {
-                                       char    *next = NULL;
-                                       int     pr = strtol( arg, &next, 10 );
+                                       int     pr;
 
-                                       if ( next == arg || next[ 0 ] != '\0' ) {
-                                               return( 1 );
-                                       }
-
-                                       if ( pr < -1 ) {
+                                       if ( lutil_atoi( &pr, arg ) != 0 || pr < -1 ) {
                                                return( 1 );
                                        }
 
@@ -849,15 +818,9 @@ limits_parse_one(
                                        limit->lms_s_pr_total = 0;
 
                                } else {
-                                       char    *next = NULL;
                                        int     total;
 
-                                       total = strtol( arg, &next, 10 );
-                                       if ( next == arg || next[ 0 ] != '\0' ) {
-                                               return( 1 );
-                                       }
-
-                                       if ( total < -1 ) {
+                                       if ( lutil_atoi( &total, arg ) != 0 || total < -1 ) {
                                                return( 1 );
                                        }
 
@@ -882,10 +845,9 @@ limits_parse_one(
                                limit->lms_s_soft = -1;
 
                        } else {
-                               char    *next = NULL;
-
-                               limit->lms_s_soft = strtol( arg, &next, 10 );
-                               if ( next == arg || limit->lms_s_soft < -1 ) {
+                               if ( lutil_atoi( &limit->lms_s_soft, arg ) != 0
+                                       || limit->lms_s_soft < -1 )
+                               {
                                        return( 1 );
                                }
                        }
index fa88c285ee133861383e1531d1f1d7f11eed9660..c47f477893e0ed665ea504d4a6b2a2afd105ba05 100644 (file)
@@ -406,10 +406,8 @@ int main( int argc, char **argv )
                                slap_debug |= level;
                        } else {
                                int     level;
-                               char    *next = NULL;
 
-                               level = strtol( optarg, &next, 0 );
-                               if ( next == NULL || next[ 0 ] != '\0' ) {
+                               if ( lutil_atoix( &level, optarg, 0 ) != 0 ) {
                                        fprintf( stderr,
                                                "unrecognized log level "
                                                "\"%s\"\n", optarg );
index 40945fd21fbc9c5ab5c39b752eba3c00cb243b18..f6ef580d2d52faeb5132dd1694df4b94246d76ef 100644 (file)
@@ -28,6 +28,7 @@
 #include <ac/string.h>
 
 #include "slap.h"
+#include "lutil.h"
 
 int
 modify_add_values(
@@ -386,7 +387,12 @@ modify_increment_values(
        if ( !strcmp( a->a_desc->ad_type->sat_syntax_oid, SLAPD_INTEGER_SYNTAX )) {
                int i;
                char str[sizeof(long)*3 + 2]; /* overly long */
-               long incr = atol( mod->sm_values[0].bv_val );
+               long incr;
+
+               if ( lutil_atol( &incr, mod->sm_values[0].bv_val ) != 0 ) {
+                       *text = "modify/increment: invalid syntax of increment";
+                       return LDAP_INVALID_SYNTAX;
+               }
 
                /* treat zero and errors as a no-op */
                if( incr == 0 ) {
@@ -395,13 +401,17 @@ modify_increment_values(
 
                for( i = 0; !BER_BVISNULL( &a->a_nvals[i] ); i++ ) {
                        char *tmp;
-                       long value = atol( a->a_nvals[i].bv_val );
+                       long value;
+                       if ( lutil_atol( &value, a->a_nvals[i].bv_val ) != 0 ) {
+                               *text = "modify/increment: invalid syntax of original value";
+                               return LDAP_INVALID_SYNTAX;
+                       }
                        size_t strln = snprintf( str, sizeof(str), "%ld", value+incr );
 
                        tmp = SLAP_REALLOC( a->a_nvals[i].bv_val, strln+1 );
                        if( tmp == NULL ) {
                                *text = "modify/increment: reallocation error";
-                               return LDAP_OTHER;;
+                               return LDAP_OTHER;
                        }
                        a->a_nvals[i].bv_val = tmp;
                        a->a_nvals[i].bv_len = strln;
index 2a5568add9ed8b9372b3cf2b66725c2d329e894d..a13c406746f1a98eea29edd08be2ed6a97ef27b1 100644 (file)
@@ -357,30 +357,40 @@ ppolicy_get( Operation *op, Entry *e, PassPolicy *pp )
        pp->ad = slap_schema.si_ad_userPassword;
 #endif
 
-       if ((a = attr_find( pe->e_attrs, ad_pwdMinAge )))
-               pp->pwdMinAge = atoi(a->a_vals[0].bv_val );
-       if ((a = attr_find( pe->e_attrs, ad_pwdMaxAge )))
-               pp->pwdMaxAge = atoi(a->a_vals[0].bv_val );
-       if ((a = attr_find( pe->e_attrs, ad_pwdInHistory )))
-               pp->pwdInHistory = atoi(a->a_vals[0].bv_val );
-       if ((a = attr_find( pe->e_attrs, ad_pwdCheckQuality )))
-               pp->pwdCheckQuality = atoi(a->a_vals[0].bv_val );
-       if ((a = attr_find( pe->e_attrs, ad_pwdMinLength )))
-               pp->pwdMinLength = atoi(a->a_vals[0].bv_val );
-       if ((a = attr_find( pe->e_attrs, ad_pwdMaxFailure )))
-               pp->pwdMaxFailure = atoi(a->a_vals[0].bv_val );
-       if ((a = attr_find( pe->e_attrs, ad_pwdGraceAuthNLimit )))
-               pp->pwdGraceAuthNLimit = atoi(a->a_vals[0].bv_val );
-       if ((a = attr_find( pe->e_attrs, ad_pwdExpireWarning )))
-               pp->pwdExpireWarning = atoi(a->a_vals[0].bv_val );
-       if ((a = attr_find( pe->e_attrs, ad_pwdFailureCountInterval )))
-               pp->pwdFailureCountInterval = atoi(a->a_vals[0].bv_val );
-       if ((a = attr_find( pe->e_attrs, ad_pwdLockoutDuration )))
-               pp->pwdLockoutDuration = atoi(a->a_vals[0].bv_val );
-
-       if ((a = attr_find( pe->e_attrs, ad_pwdCheckModule ))) {
-               strncpy(pp->pwdCheckModule, a->a_vals[0].bv_val,
-                       sizeof(pp->pwdCheckModule));
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdMinAge ) )
+                       && lutil_atoi( &pp->pwdMinAge, a->a_vals[0].bv_val ) != 0 )
+               goto defaultpol;
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdMaxAge ) )
+                       && lutil_atoi( &pp->pwdMaxAge, a->a_vals[0].bv_val ) != 0 )
+               goto defaultpol;
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdInHistory ) )
+                       && lutil_atoi( &pp->pwdInHistory, a->a_vals[0].bv_val ) != 0 )
+               goto defaultpol;
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdCheckQuality ) )
+                       && lutil_atoi( &pp->pwdCheckQuality, a->a_vals[0].bv_val ) != 0 )
+               goto defaultpol;
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdMinLength ) )
+                       && lutil_atoi( &pp->pwdMinLength, a->a_vals[0].bv_val ) != 0 )
+               goto defaultpol;
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdMaxFailure ) )
+                       && lutil_atoi( &pp->pwdMaxFailure, a->a_vals[0].bv_val ) != 0 )
+               goto defaultpol;
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdGraceAuthNLimit ) )
+                       && lutil_atoi( &pp->pwdGraceAuthNLimit, a->a_vals[0].bv_val ) != 0 )
+               goto defaultpol;
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdExpireWarning ) )
+                       && lutil_atoi( &pp->pwdExpireWarning, a->a_vals[0].bv_val ) != 0 )
+               goto defaultpol;
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdFailureCountInterval ) )
+                       && lutil_atoi( &pp->pwdFailureCountInterval, a->a_vals[0].bv_val ) != 0 )
+               goto defaultpol;
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdLockoutDuration ) )
+                       && lutil_atoi( &pp->pwdLockoutDuration, a->a_vals[0].bv_val ) != 0 )
+               goto defaultpol;
+
+       if ( ( a = attr_find( pe->e_attrs, ad_pwdCheckModule ) ) ) {
+               strncpy( pp->pwdCheckModule, a->a_vals[0].bv_val,
+                       sizeof(pp->pwdCheckModule) );
                pp->pwdCheckModule[sizeof(pp->pwdCheckModule)-1] = '\0';
        }
 
index 70dc6ff9e83f092a9440bbbecbb1f37d74d1c39f..eafb6bf12b6a9193566ac3762a07d57c37be46cf 100644 (file)
@@ -2195,8 +2195,31 @@ sp_cf_gen(ConfigArgs *c)
        }
        switch ( c->type ) {
        case SP_CHKPT:
-               si->si_chkops = atoi( c->argv[1] );
-               si->si_chktime = atoi( c->argv[2] ) * 60;
+               if ( lutil_atoi( &si->si_chkops, c->argv[1] ) != 0 ) {
+                       sprintf( c->msg, "%s unable to parse checkpoint ops # \"%s\"",
+                               c->argv[0], c->argv[1] );
+                       Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
+                       return ARG_BAD_CONF;
+               }
+               if ( si->si_chkops <= 0 ) {
+                       sprintf( c->msg, "%s invalid checkpoint ops # \"%d\"",
+                               c->argv[0], si->si_chkops );
+                       Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
+                       return ARG_BAD_CONF;
+               }
+               if ( lutil_atoi( &si->si_chktime, c->argv[2] ) != 0 ) {
+                       sprintf( c->msg, "%s unable to parse checkpoint time \"%s\"",
+                               c->argv[0], c->argv[1] );
+                       Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
+                       return ARG_BAD_CONF;
+               }
+               if ( si->si_chktime <= 0 ) {
+                       sprintf( c->msg, "%s invalid checkpoint time \"%d\"",
+                               c->argv[0], si->si_chkops );
+                       Debug( LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
+                       return ARG_BAD_CONF;
+               }
+               si->si_chktime *= 60;
                break;
        case SP_SESSL: {
                sessionlog *sl;
index 13e37ff9be714ff3a53e75b3f07bb5181f5640ad..1686df02150e6e3eed86075838d62d4256f828b3 100644 (file)
@@ -29,6 +29,7 @@
 #include <ac/socket.h>
 
 #include "slap.h"
+#include "lutil.h"
 
 /* config block */
 
@@ -620,7 +621,11 @@ static int translucent_config(
                        ov->config->debug = 0xFFFF;
                        rc = 0;
                } else if(argc == 2) {
-                       ov->config->debug = atoi(argv[1]);
+                       if ( lutil_atoi( &ov->config->debug, argv[1]) != 0 ) {
+                               fprintf(stderr, "%s: line %d: unable to parse debug \"%s\"\n",
+                                       fname, lineno, argv[1]);
+                               return 1;
+                       }
                        rc = 0;
                } else {
                        fprintf(stderr, "%s: line %d: too many arguments (%d) to debug\n",
index 52a67ea2f8cd9e59aeb7bc3beeeea10198b59fc5..cb9e25ad7010cefb35d8cc36e86cef8c41814044 100644 (file)
@@ -36,6 +36,7 @@
 #include <ac/unistd.h>
 
 #include "slap.h"
+#include "lutil.h"
 
 const struct berval slap_dummy_bv = BER_BVNULL;
 
@@ -1397,8 +1398,8 @@ str2result(
                }
 
                if ( strncasecmp( s, "code", STRLENOF( "code" ) ) == 0 ) {
-                       if ( c != NULL ) {
-                               *code = atoi( c );
+                       if ( c != NULL && lutil_atoi( code, c ) != 0 ) {
+                               goto bailout;
                        }
                } else if ( strncasecmp( s, "matched", STRLENOF( "matched" ) ) == 0 ) {
                        if ( c != NULL ) {
@@ -1409,6 +1410,7 @@ str2result(
                                *info = c;
                        }
                } else {
+bailout:;
                        Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
                            s, 0, 0 );
 
index 2731b52b8676a3b55814d68e8b5c4de10c6ed99a..b519cf4d5c60b82200228244f877d60e6f8963f3 100644 (file)
@@ -185,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 ) {
+                   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 );
index 5026e41de48cb3d38702655e240087ccf6882737..ec36850cc6ad14227e02507989141ecc50f5d0c8 100644 (file)
@@ -276,16 +276,11 @@ slap_tool_init(
                                        exit( EXIT_FAILURE );
                                }
 
-                       } else {
-                               char    *next = NULL;
-
-                               level = strtol( optarg, &next, 0 );
-                               if ( next == NULL || next[ 0 ] != '\0' ) {
-                                       fprintf( stderr,
-                                               "unrecognized log level "
-                                               "\"%s\"\n", optarg );
-                                       exit( EXIT_FAILURE );
-                               }
+                       } else if ( lutil_atoi( &level, optarg ) != 0 ) {
+                               fprintf( stderr,
+                                       "unrecognized log level "
+                                       "\"%s\"\n", optarg );
+                               exit( EXIT_FAILURE );
                        }
 
                        if ( level ) {
index 29aa25b4298e9f2f5fd05610e4f390c3f00da87c..7143802f3172ce781914842bcef77fdda12f33eb 100644 (file)
@@ -34,6 +34,7 @@
 #include <ac/unistd.h>
 
 #include "slap.h"
+#include "lutil.h"
 
 /*
  * Set real and effective user id and group id, and group access list
@@ -49,9 +50,17 @@ slap_init_user( char *user, char *group )
 
     if ( user ) {
        struct passwd *pwd;
-       if ( isdigit( (unsigned char) *user )) {
+       if ( isdigit( (unsigned char) *user ) ) {
+           unsigned u;
+
            got_uid = 1;
-           uid = atoi( user );
+           if ( lutil_atou( &u, user ) != 0 ) {
+               Debug( LDAP_DEBUG_ANY, "Unble to parse user %s\n",
+                      user, 0, 0 );
+
+               exit( EXIT_FAILURE );
+           }
+           uid = (uid_t)u;
 #ifdef HAVE_GETPWUID
            pwd = getpwuid( uid );
            goto did_getpw;
@@ -86,7 +95,15 @@ slap_init_user( char *user, char *group )
     if ( group ) {
        struct group *grp;
        if ( isdigit( (unsigned char) *group )) {
-           gid = atoi( group );
+           unsigned g;
+
+           if ( lutil_atou( &g, group ) != 0 ) {
+               Debug( LDAP_DEBUG_ANY, "Unble to parse group %s\n",
+                      group, 0, 0 );
+
+               exit( EXIT_FAILURE );
+           }
+           gid = (uid_t)g;
 #ifdef HAVE_GETGRGID
            grp = getgrgid( gid );
            goto did_group;
index cf2d73075e8b16c4cc4039f46a1252502d938d67..2a544c050c0bcaba7538c50e94973d0610ce8f93 100644 (file)
@@ -700,7 +700,7 @@ ordered_value_add(
 
                k = -1;
                if ( vals[i].bv_val[0] == '{' ) {
-                       k = strtol( vals[i].bv_val+1, &next, 0 );
+                       k = strtol( vals[i].bv_val + 1, &next, 0 );
                        if ( next == vals[i].bv_val + 1 ||
                                next[ 0 ] != '}' ||
                                next - vals[i].bv_val > vals[i].bv_len )
index 4faaadab552c0869a9dcb73c6ee852fc6d49274e..9d9a6baa2e3ac7edc4f5ab6fa380319a13dd76b5 100644 (file)
@@ -79,7 +79,8 @@ doargs(
 
     while ( (i = getopt( argc, argv, "d:f:n:or:t:V" )) != EOF ) {
        switch ( i ) {
-       case 'd':       /* set debug level and 'do not detach' flag */
+       case 'd': {     /* set debug level and 'do not detach' flag */
+           int level;
            g->no_detach = 1;
            if ( optarg[0] == '?' ) {
 #ifdef LDAP_DEBUG
@@ -108,14 +109,19 @@ doargs(
                return( -1 );
            }
 #ifdef LDAP_DEBUG
-           ldap_debug |= atoi( optarg );
+           if ( lutil_atoi( &level, optarg ) != 0 ) {
+               fprintf( stderr, "unable to parse debug flag \"%s\".\n", optarg );
+               usage( g->myname );
+               return( -1 );
+           }
+           ldap_debug |= level;
 #else /* !LDAP_DEBUG */
-           if ( atoi( optarg ) != 0 )
+           if ( lutil_atoi( &level, optarg ) != 0 || level != 0 )
                /* can't enable debugging - not built with debug code */
                fputs( "must compile with LDAP_DEBUG for debugging\n",
                       stderr );
 #endif /* LDAP_DEBUG */
-           break;
+           break;
        case 'f':       /* slapd config file */
            LUTIL_SLASHPATH( optarg );
            g->slapd_configfile = strdup( optarg );
index be39480cf50da4ab310f65b03f5a430cd0f1ad79..5e91f405b05e294a0a4e535fce8e18d4e50dcf91 100644 (file)
@@ -193,8 +193,7 @@ slurpd_read_config(
                                return( 1 );
                        }
 
-                       c = atoi( cargv[1] );
-                       if( c < 1 ) {
+                       if ( lutil_atoi( &c, cargv[1] ) != 0 || c < 1 ) {
                                Debug( LDAP_DEBUG_ANY, "%s: line %d: invalid interval "
                                        "(%d) in \"replicationinterval <seconds>\" line\n",
                                        fname, lineno, c );
@@ -456,7 +455,11 @@ parse_replica_line(
            if (( hp = strchr( val, ':' )) != NULL ) {
                *hp = '\0';
                hp++;
-               ri->ri_port = atoi( hp );
+               if ( lutil_atoi( &ri->ri_port, hp ) != 0 ) {
+                   fprintf( stderr, "unable to parse port \"%s\", line %d\n",
+                           hp, lineno );
+                   return -1;
+               }
            }
            if ( ri->ri_port <= 0 ) {
                ri->ri_port = LDAP_PORT;
index 3633732e5f6cf8a4bc968bef09a7b81a598143c2..eaee503cb227d2e8910ac07788fa8d173838ea42 100644 (file)
@@ -49,6 +49,7 @@
 
 #include "slurp.h"
 #include "globals.h"
+#include "lutil.h"
 
 /* Forward references */
 static Rh      *get_repl_hosts LDAP_P(( char *, int *, char ** ));
@@ -187,17 +188,30 @@ Re_parse(
            re->re_changetype = getchangetype( value );
            state |= GOT_CHANGETYPE;
            break;
-       case T_TIME:
+       case T_TIME: {
+           unsigned long       t;
+
            if (( p = strchr( value, '.' )) != NULL ) {
                /* there was a sequence number */
                *p++ = '\0';
            }
-           re->re_timestamp = atol( value );
-           if ( p != NULL && isdigit( (unsigned char) *p )) {
-               re->re_seq = atoi( p );
+           if ( lutil_atoul( &t, value ) != 0 ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "Error: Re_parse: unable to parse timestamp \"%s\"\n",
+                       value, 0, 0 );
+               return -1;
+           }
+           re->re_timestamp = (time_t)t;
+           if ( p != NULL && isdigit( (unsigned char) *p )
+               && lutil_atoi( &re->re_seq, p ) != 0 )
+           {
+               Debug( LDAP_DEBUG_ANY,
+                       "Error: Re_parse: unable to parse sequence number \"%s\"\n",
+                       p, 0, 0 );
+               return -1;
            }
            state |= GOT_TIME;
-           break;
+           break;
        case T_DN:
            re->re_dn = ch_malloc( len + 1 );
                AC_MEMCPY( re->re_dn, value, len );
@@ -325,8 +339,8 @@ get_repl_hosts(
        if (( p = strchr( value, ':' )) != NULL ) {
            *p = '\0';
            p++;
-           if ( *p != '\0' ) {
-               port = atoi( p );
+           if ( *p != '\0' && lutil_atoi( &port, p ) != 0 ) {
+               return( NULL );
            }
        }
 
index cb78c2d9c90b4a7d3cce6d8d687c242995befab7..5b31dfb8d5a00f0c1ddda806050ac67c875a3786 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "slurp.h"
 #include "globals.h"
+#include "lutil.h"
 
 /*
  * Add information about replica host specified by Ri to list
@@ -230,11 +231,16 @@ St_read(
 
        found = 0;
        for ( i = 0; i < sglob->st->st_nreplicas; i++ ) {
+           int p;
            if ( !strcmp( hostname, sglob->st->st_data[ i ]->hostname ) &&
-                   atoi( port ) == sglob->st->st_data[ i ]->port ) {
+                   lutil_atoi( &p, port ) == 0 && p == sglob->st->st_data[ i ]->port )
+           {
                found = 1;
-               sglob->st->st_data[ i ]->last = atol( timestamp );
-               sglob->st->st_data[ i ]->seq = atoi( seq );
+               if ( lutil_atol( &sglob->st->st_data[ i ]->last, timestamp ) != 0
+                       || lutil_atoi( &sglob->st->st_data[ i ]->seq, seq ) != 0 )
+               {
+                   found = 0;
+               }
                break;
            }
        }
index 8acd88a810cc3f43eda130e59b82125a139e0650..07c0d175f02bc251b2210bfbda2ba4cfe168698a 100644 (file)
@@ -32,6 +32,7 @@
 
 #define LDAP_DEPRECATED 1
 #include <ldap.h>
+#include <lutil.h>
 
 #define LOOPS  100
 #define RETRIES        0
@@ -93,7 +94,9 @@ main( int argc, char **argv )
                        break;
 
                case 'p':               /* the servers port */
-                       port = atoi( optarg );
+                       if ( lutil_atoi( &port, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'D':               /* the servers manager */
@@ -109,15 +112,21 @@ main( int argc, char **argv )
                        break;
 
                case 'l':               /* the number of loops */
-                       loops = atoi( optarg );
+                       if ( lutil_atoi( &loops, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'r':               /* number of retries */
-                       retries = atoi( optarg );
+                       if ( lutil_atoi( &retries, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 't':               /* delay in seconds */
-                       delay = atoi( optarg );
+                       if ( lutil_atoi( &delay, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                default:
index 25175590f8ab8841fb6f25d7d25eceff965158d0..be604834a2bab6284d8b9b0389c75e80108b1191 100644 (file)
@@ -90,7 +90,9 @@ main( int argc, char **argv )
                        break;
 
                        case 'p':               /* the servers port */
-                               port = atoi( optarg );
+                               if ( lutil_atoi( &port, optarg ) != 0 ) {
+                                       usage( argv[0] );
+                               }
                                break;
 
                        case 'D':
@@ -102,7 +104,9 @@ main( int argc, char **argv )
                                break;
 
                        case 'l':               /* the number of loops */
-                               loops = atoi( optarg );
+                               if ( lutil_atoi( &loops, optarg ) != 0 ) {
+                                       usage( argv[0] );
+                               }
                                break;
 
                        case 'f':
index 727f1c741e43a7d5eb7e9c35d1499f03856fbfe2..cfda8b67e37d02ab7fb0409233fa2fce3bd5e66a 100644 (file)
@@ -28,6 +28,7 @@
 
 #define LDAP_DEPRECATED 1
 #include <ldap.h>
+#include <lutil.h>
 
 #define LOOPS  100
 #define RETRIES 0
@@ -87,7 +88,9 @@ main( int argc, char **argv )
                        break;
 
                case 'p':               /* the servers port */
-                       port = atoi( optarg );
+                       if ( lutil_atoi( &port, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'D':               /* the servers manager */
@@ -107,15 +110,21 @@ main( int argc, char **argv )
                        break;
 
                case 'l':               /* the number of loops */
-                       loops = atoi( optarg );
+                       if ( lutil_atoi( &loops, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'r':               /* number of retries */
-                       retries = atoi( optarg );
+                       if ( lutil_atoi( &retries, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 't':               /* delay in seconds */
-                       delay = atoi( optarg );
+                       if ( lutil_atoi( &delay, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                default:
index d6c5f9257f01e4ba8a003a37f1d10f7584993858..908d1892517457cd32bb7b174629f51a7a8fa142 100644 (file)
@@ -32,6 +32,7 @@
 
 #define LDAP_DEPRECATED 1
 #include <ldap.h>
+#include <lutil.h>
 
 #define LOOPS  100
 #define RETRIES        0
@@ -88,7 +89,9 @@ main( int argc, char **argv )
                        break;
 
                case 'p':               /* the servers port */
-                       port = atoi( optarg );
+                       if ( lutil_atoi( &port, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'D':               /* the servers manager */
@@ -104,15 +107,21 @@ main( int argc, char **argv )
                        break;
 
                case 'l':               /* the number of loops */
-                       loops = atoi( optarg );
+                       if ( lutil_atoi( &loops, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'r':               /* the number of retries */
-                       retries = atoi( optarg );
+                       if ( lutil_atoi( &retries, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 't':               /* delay in seconds */
-                       delay = atoi( optarg );
+                       if ( lutil_atoi( &delay, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                default:
index c5cb56ce33bd87d9ece5e3acdaa198eeb4a141f2..b70ace580f0bcd578bca3ae28a2e935b1349fbc7 100644 (file)
@@ -32,6 +32,7 @@
 
 #define LDAP_DEPRECATED 1
 #include <ldap.h>
+#include <lutil.h>
 
 #define LOOPS  100
 #define RETRIES        0
@@ -77,7 +78,9 @@ main( int argc, char **argv )
                        break;
 
                case 'p':               /* the servers port */
-                       port = atoi( optarg );
+                       if ( lutil_atoi( &port, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'e':               /* DN to search for */
@@ -85,15 +88,21 @@ main( int argc, char **argv )
                        break;
 
                case 'l':               /* the number of loops */
-                       loops = atoi( optarg );
+                       if ( lutil_atoi( &loops, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'r':               /* the number of retries */
-                       retries = atoi( optarg );
+                       if ( lutil_atoi( &retries, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 't':               /* delay in seconds */
-                       delay = atoi( optarg );
+                       if ( lutil_atoi( &delay, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                default:
index 9d9afe1e4fd39b144c1484fd72eca9066edbc585..0f3c1e63a006a51172ae4031ac83742da8e6728d 100644 (file)
@@ -32,6 +32,7 @@
 
 #define LDAP_DEPRECATED 1
 #include <ldap.h>
+#include <lutil.h>
 
 #define LOOPS  100
 #define RETRIES        0
@@ -83,7 +84,9 @@ main( int argc, char **argv )
                        break;
 
                case 'p':               /* the servers port */
-                       port = atoi( optarg );
+                       if ( lutil_atoi( &port, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'D':               /* the servers manager */
@@ -103,15 +106,21 @@ main( int argc, char **argv )
                        break;
 
                case 'l':               /* number of loops */
-                       loops = atoi( optarg );
+                       if ( lutil_atoi( &loops, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'r':               /* number of retries */
-                       retries = atoi( optarg );
+                       if ( lutil_atoi( &retries, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 't':               /* delay in seconds */
-                       delay = atoi( optarg );
+                       if ( lutil_atoi( &delay, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                default:
index e49947198b51ad57de3bee0af1b31a5ee680cc95..8cf65ef9e732a6a7dde6f0ba9cf2b21356541262 100644 (file)
@@ -33,6 +33,7 @@
 
 
 #include "ldap_defaults.h"
+#include "lutil.h"
 
 
 #define SEARCHCMD              "slapd-search"
@@ -159,7 +160,9 @@ main( int argc, char **argv )
                        break;
 
                case 'j':               /* the number of parallel clients */
-                       maxkids = atoi( optarg );
+                       if ( lutil_atoi( &maxkids, optarg ) != 0 ) {
+                               usage( argv[0] );
+                       }
                        break;
 
                case 'l':               /* the number of loops per client */