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 &&
} 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 );
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);
#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 );
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;
}
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;
*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;
}
}
}
int
-lutil_atoi( int *v, const char *s )
+lutil_atoix( int *v, const char *s, int x )
{
char *next;
long i;
assert( s != NULL );
assert( v != NULL );
- i = strtol( s, &next, 10 );
+ i = strtol( s, &next, x );
if ( next == s || next[ 0 ] != '\0' ) {
return -1;
}
}
int
-lutil_atou( unsigned *v, const char *s )
+lutil_atoux( unsigned *v, const char *s, int x )
{
char *next;
unsigned long u;
assert( s != NULL );
assert( v != NULL );
- u = strtoul( s, &next, 10 );
+ u = strtoul( s, &next, x );
if ( next == s || next[ 0 ] != '\0' ) {
return -1;
}
}
int
-lutil_atol( long *v, const char *s )
+lutil_atolx( long *v, const char *s, int x )
{
char *next;
long l;
assert( s != NULL );
assert( v != NULL );
- l = strtol( s, &next, 10 );
+ l = strtol( s, &next, x );
if ( next == s || next[ 0 ] != '\0' ) {
return -1;
}
}
int
-lutil_atoul( unsigned long *v, const char *s )
+lutil_atoulx( unsigned long *v, const char *s, int x )
{
char *next;
unsigned long ul;
assert( s != NULL );
assert( v != NULL );
- ul = strtoul( s, &next, 10 );
+ ul = strtoul( s, &next, x );
if ( next == s || next[ 0 ] != '\0' ) {
return -1;
}
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 {
#include <lber.h>
#include <ldap.h>
#include "../libldap/ldap-int.h"
-
+#include <lutil.h>
#include <avl.h>
#include <rewrite.h>
#include <stdio.h>
#include <rewrite.h>
+#include <lutil.h>
#include <ldap.h>
int ldap_debug;
FILE *fin = NULL;
char *rewriteContext = REWRITE_DEFAULT_CONTEXT;
int debug = 0;
- char *next;
while ( 1 ) {
int opt = getopt( argc, argv, "d:f:hr:" );
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 );
}
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;
}
}
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;
}
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;
}
{
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",
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 "
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 );
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 );
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 );
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 );
}
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.
*/
LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val );
}
}
- break;
+ } break;
case BDB_CONFIG: {
char *ptr = c->line;
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;
}
#include "slap.h"
#include "back-ldbm.h"
+#include "lutil.h"
int
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 ) {
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 ) {
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 ) {
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 );
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 );
}
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 );
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 {
#include <sys/types.h>
#include "ac/string.h"
+#include "lutil.h"
#include "slap.h"
#include "proto-sql.h"
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 {
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 {
#include <sys/types.h>
#include "ac/string.h"
+#include "lutil.h"
#include "slap.h"
#include "proto-sql.h"
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;
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 );
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 ) {
}
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 ) &&
#include "ac/string.h"
#include "ac/ctype.h"
+#include "lutil.h"
#include "slap.h"
#include "proto-sql.h"
}
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;
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 );
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;
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;
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]);
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]);
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]));
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 ||
}
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 );
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;
}
}
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 {
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;
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;
}
char **cptr;
int *iptr, i;
unsigned *uptr;
+ long *lptr;
+ unsigned long *ulptr;
struct berval *bptr;
cptr = (char **)((char *)src + tab->off);
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;
|| 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 );
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 );
}
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 );
}
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 );
}
}
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
}
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 );
#include <ac/string.h>
#include "slap.h"
+#include "lutil.h"
int
modify_add_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 ) {
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;
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';
}
}
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;
#include <ac/socket.h>
#include "slap.h"
+#include "lutil.h"
/* config block */
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",
#include <ac/unistd.h>
#include "slap.h"
+#include "lutil.h"
const struct berval slap_dummy_bv = BER_BVNULL;
}
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 ) {
*info = c;
}
} else {
+bailout:;
Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
s, 0, 0 );
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 );
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 ) {
#include <ac/unistd.h>
#include "slap.h"
+#include "lutil.h"
/*
* Set real and effective user id and group id, and group access list
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;
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;
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 )
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
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 );
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 );
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;
#include "slurp.h"
#include "globals.h"
+#include "lutil.h"
/* Forward references */
static Rh *get_repl_hosts LDAP_P(( char *, int *, char ** ));
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 );
if (( p = strchr( value, ':' )) != NULL ) {
*p = '\0';
p++;
- if ( *p != '\0' ) {
- port = atoi( p );
+ if ( *p != '\0' && lutil_atoi( &port, p ) != 0 ) {
+ return( NULL );
}
}
#include "slurp.h"
#include "globals.h"
+#include "lutil.h"
/*
* Add information about replica host specified by Ri to list
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;
}
}
#define LDAP_DEPRECATED 1
#include <ldap.h>
+#include <lutil.h>
#define LOOPS 100
#define RETRIES 0
break;
case 'p': /* the servers port */
- port = atoi( optarg );
+ if ( lutil_atoi( &port, optarg ) != 0 ) {
+ usage( argv[0] );
+ }
break;
case 'D': /* the servers manager */
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:
break;
case 'p': /* the servers port */
- port = atoi( optarg );
+ if ( lutil_atoi( &port, optarg ) != 0 ) {
+ usage( argv[0] );
+ }
break;
case 'D':
break;
case 'l': /* the number of loops */
- loops = atoi( optarg );
+ if ( lutil_atoi( &loops, optarg ) != 0 ) {
+ usage( argv[0] );
+ }
break;
case 'f':
#define LDAP_DEPRECATED 1
#include <ldap.h>
+#include <lutil.h>
#define LOOPS 100
#define RETRIES 0
break;
case 'p': /* the servers port */
- port = atoi( optarg );
+ if ( lutil_atoi( &port, optarg ) != 0 ) {
+ usage( argv[0] );
+ }
break;
case 'D': /* the servers manager */
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:
#define LDAP_DEPRECATED 1
#include <ldap.h>
+#include <lutil.h>
#define LOOPS 100
#define RETRIES 0
break;
case 'p': /* the servers port */
- port = atoi( optarg );
+ if ( lutil_atoi( &port, optarg ) != 0 ) {
+ usage( argv[0] );
+ }
break;
case 'D': /* the servers manager */
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:
#define LDAP_DEPRECATED 1
#include <ldap.h>
+#include <lutil.h>
#define LOOPS 100
#define RETRIES 0
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 */
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:
#define LDAP_DEPRECATED 1
#include <ldap.h>
+#include <lutil.h>
#define LOOPS 100
#define RETRIES 0
break;
case 'p': /* the servers port */
- port = atoi( optarg );
+ if ( lutil_atoi( &port, optarg ) != 0 ) {
+ usage( argv[0] );
+ }
break;
case 'D': /* the servers manager */
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:
#include "ldap_defaults.h"
+#include "lutil.h"
#define SEARCHCMD "slapd-search"
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 */