qpw->rs_mods = ml;
keys = ch_malloc( 2 * sizeof(struct berval) );
- keys[0].bv_val = ch_malloc( STRLENOF( "9223372036854775807L" ) + 1 );
+ keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
keys[0].bv_len = snprintf(keys[0].bv_val,
- STRLENOF( "9223372036854775807L" ) + 1,
+ LDAP_PVT_INTTYPE_CHARS(long),
"%ld", slap_get_time());
BER_BVZERO( &keys[1] );
qpw->rs_mods = ml;
keys = ch_malloc( 2 * sizeof(struct berval) );
- keys[0].bv_val = ch_malloc( STRLENOF( "9223372036854775807L" ) + 1 );
+ keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
keys[0].bv_len = snprintf(keys[0].bv_val,
- STRLENOF( "9223372036854775807L" ) + 1,
+ LDAP_PVT_INTTYPE_CHARS(long),
"%ld", slap_get_time() + pi->smb_must_change);
BER_BVZERO( &keys[1] );
qpw->rs_mods = ml;
keys = ch_malloc( 2 * sizeof(struct berval) );
- keys[0].bv_val = ch_malloc( STRLENOF( "9223372036854775807L" ) + 1 );
+ keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
keys[0].bv_len = snprintf(keys[0].bv_val,
- STRLENOF( "9223372036854775807L" ) + 1,
+ LDAP_PVT_INTTYPE_CHARS(long),
"%ld", slap_get_time() + pi->smb_can_change);
BER_BVZERO( &keys[1] );
struct berval *, LDAPRDN *, char **, unsigned flags, void *ctx ));
LDAP_F( int ) ldap_rdn2bv_x LDAP_P((
LDAPRDN rdn, struct berval *bv, unsigned flags, void *ctx ));
-#endif
+#endif /* LDAP_AVA_NULL */
/* url.c */
LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
#ifndef LDAP_PVT_SASL_LOCAL_SSF
#define LDAP_PVT_SASL_LOCAL_SSF 71 /* SSF for Unix Domain Sockets */
-#endif
+#endif /* ! LDAP_PVT_SASL_LOCAL_SSF */
struct ldap;
struct ldapmsg;
* If none is available, unsigned long data is used.
*/
+LDAP_BEGIN_DECL
+
#ifdef USE_MP_BIGNUM
/*
* Use OpenSSL's BIGNUM
#include "ldap_pvt_uc.h"
+LDAP_END_DECL
+
+LDAP_BEGIN_DECL
+
+#include <limits.h> /* get CHAR_BIT */
+
+/* Buffer space for sign, decimal digits and \0. Note: log10(2) < 146/485. */
+#define LDAP_PVT_INTTYPE_CHARS(type) (((sizeof(type)*CHAR_BIT-1)*146)/485 + 3)
+
+LDAP_END_DECL
+
#endif /* _LDAP_PVT_H */
len += sep;
if ( u->lud_port ) {
- char buf[] = ":65535";
+ char buf[ STRLENOF(":65535") + 1 ];
len += snprintf( buf, sizeof( buf ), ":%d", u->lud_port );
if ( u->lud_host && u->lud_host[0] ) {
#include <stdio.h>
#include <ac/stdlib.h>
+#include <ac/stdarg.h>
#include <ac/string.h>
#include <ac/ctype.h>
#include <ac/unistd.h>
return 0;
}
+/*
+ * formatted print to string
+ *
+ * - if return code < 0, the error code returned by vsnprintf(3) is returned
+ *
+ * - if return code > 0, the buffer was not long enough;
+ * - if next is not NULL, *next will be set to buf + bufsize - 1
+ * - if len is not NULL, *len will contain the required buffer length
+ *
+ * - if return code == 0, the buffer was long enough;
+ * - if next is not NULL, *next will point to the end of the string printed so far
+ * - if len is not NULL, *len will contain the length of the string printed so far
+ */
+int
+lutil_snprintf( char *buf, ber_len_t bufsize, char **next, ber_len_t *len, LDAP_CONST char *fmt, ... )
+{
+ va_list ap;
+ int ret;
+
+ assert( buf != NULL );
+ assert( bufsize > 0 );
+ assert( fmt != NULL );
+
+ va_start( ap, fmt );
+ ret = vsnprintf( buf, bufsize, fmt, ap );
+ va_end( ap );
+
+ if ( ret < 0 ) {
+ return ret;
+ }
+
+ if ( len ) {
+ *len = ret;
+ }
+
+ if ( ret >= bufsize ) {
+ if ( next ) {
+ *next = &buf[ bufsize - 1 ];
+ }
+
+ return 1;
+ }
+
+ if ( next ) {
+ *next = &buf[ ret ];
+ }
+
+ return 0;
+}
+
/* extract IP and try exact match */
} else if ( b->a_peername_style == ACL_STYLE_IP ) {
char *port;
- char buf[] = "255.255.255.255";
+ char buf[STRLENOF("255.255.255.255") + 1];
struct berval ip;
unsigned long addr;
int port_number = -1;
/* extract IPv6 and try exact match */
} else if ( b->a_peername_style == ACL_STYLE_IPV6 ) {
char *port;
- char buf[] = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
+ char buf[STRLENOF("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF") + 1];
struct berval ip;
struct in6_addr addr;
int port_number = -1;
#include "lutil.h"
static const char style_base[] = "base";
-char *style_strings[] = {
+const char *style_strings[] = {
"regex",
"expand",
"exact",
if ( n != -1 ) {
Attribute *a;
- char buf[] = "+9223372036854775807L";
+ char buf[LDAP_PVT_INTTYPE_CHARS(long)];
ber_len_t len;
a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
struct berval nrdn;
Attribute *a;
- char buf[] = "+9223372036854775807L";
+ char buf[LDAP_PVT_INTTYPE_CHARS(long)];
long num = 0;
ber_len_t len;
int prc = LDAP_SUCCESS;
/* first parameter #, parameter order */
SQLUSMALLINT pno, po;
- char logbuf[] = "val[18446744073709551615UL], id=18446744073709551615UL";
+ char logbuf[ STRLENOF("val[], id=") + 2*LDAP_PVT_INTTYPE_CHARS(unsigned long)];
/*
* Do not deal with the objectClass that is used
0, 0 );
} else if ( !strcasecmp( argv[ 0 ], "fetch_attrs" ) ) {
- char *str, *s, *next;
- char delimstr[] = ",";
+ char *str, *s, *next;
+ const char *delimstr = ",";
if ( argc < 2 ) {
Debug( LDAP_DEBUG_TRACE,
"objectClass: extensibleObject\n"
"description: builtin baseObject for back-sql\n"
"description: all entries mapped "
- "in the \"ldap_entries\" table\n"
- "description: must have "
- "\"" BACKSQL_BASEOBJECT_IDSTR "\" "
- "in the \"parent\" column",
+ "in table \"ldap_entries\" "
+ "must have "
+ "\"" BACKSQL_BASEOBJECT_IDSTR "\" "
+ "in the \"parent\" column",
be->be_suffix[0].bv_val );
bi->sql_baseObject = str2entry( buf );
* util.c
*/
-extern char
+extern const char
backsql_def_oc_query[],
backsql_def_needs_select_oc_query[],
backsql_def_at_query[],
backsql_def_subtree_cond[],
backsql_def_upper_subtree_cond[],
backsql_id_query[],
- backsql_def_concat_func[];
-extern char
+ backsql_def_concat_func[],
backsql_check_dn_ru_query[];
struct berbuf * backsql_strcat_x( struct berbuf *dest, void *memctx, ... );
backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map )
{
backsql_at_map_rec *at_map;
- char s[] = "+9223372036854775807L";
+ char s[LDAP_PVT_INTTYPE_CHARS(long)];
struct berval sbv;
struct berbuf bb;
at_map->bam_add_proc = NULL;
{
- char tmp[] =
- "INSERT INTO ldap_entry_objclasses "
+ char tmp[STRLENOF("INSERT INTO ldap_entry_objclasses "
"(entry_id,oc_name) VALUES "
"((SELECT id FROM ldap_entries "
- "WHERE oc_map_id="
- "18446744073709551615UL " /* 64 bit ULONG */
- "AND keyval=?),?)";
+ "WHERE oc_map_id= "
+ "AND keyval=?),?)") + LDAP_PVT_INTTYPE_CHARS(unsigned long)];
snprintf( tmp, sizeof(tmp),
"INSERT INTO ldap_entry_objclasses "
"(entry_id,oc_name) VALUES "
at_map->bam_delete_proc = NULL;
{
- char tmp[] =
- "DELETE FROM ldap_entry_objclasses "
+ char tmp[STRLENOF("DELETE FROM ldap_entry_objclasses "
"WHERE entry_id=(SELECT id FROM ldap_entries "
- "WHERE oc_map_id="
- "18446744073709551615UL " /* 64 bit ULONG */
- "AND keyval=?) AND oc_name=?";
+ "WHERE oc_map_id= "
+ "AND keyval=?) AND oc_name=?") + LDAP_PVT_INTTYPE_CHARS(unsigned long)];
snprintf( tmp, sizeof(tmp),
"DELETE FROM ldap_entry_objclasses "
"WHERE entry_id=(SELECT id FROM ldap_entries "
struct berval keyval;
#else /* ! BACKSQL_ARBITRARY_KEY */
unsigned long keyval;
- char keyvalbuf[] = "18446744073709551615";
+ char keyvalbuf[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
#endif /* ! BACKSQL_ARBITRARY_KEY */
switch ( f->f_choice ) {
#define BACKSQL_STR_GROW 256
-char backsql_def_oc_query[] =
+const char backsql_def_oc_query[] =
"SELECT id,name,keytbl,keycol,create_proc,delete_proc,expect_return "
"FROM ldap_oc_mappings";
-char backsql_def_needs_select_oc_query[] =
+const char backsql_def_needs_select_oc_query[] =
"SELECT id,name,keytbl,keycol,create_proc,create_keyval,delete_proc,"
"expect_return FROM ldap_oc_mappings";
-char backsql_def_at_query[] =
+const char backsql_def_at_query[] =
"SELECT name,sel_expr,from_tbls,join_where,add_proc,delete_proc,"
"param_order,expect_return,sel_expr_u FROM ldap_attr_mappings "
"WHERE oc_map_id=?";
-char backsql_def_delentry_stmt[] = "DELETE FROM ldap_entries WHERE id=?";
-char backsql_def_renentry_stmt[] =
+const char backsql_def_delentry_stmt[] = "DELETE FROM ldap_entries WHERE id=?";
+const char backsql_def_renentry_stmt[] =
"UPDATE ldap_entries SET dn=?,parent=?,keyval=? WHERE id=?";
-char backsql_def_insentry_stmt[] =
+const char backsql_def_insentry_stmt[] =
"INSERT INTO ldap_entries (dn,oc_map_id,parent,keyval) "
"VALUES (?,?,?,?)";
-char backsql_def_delobjclasses_stmt[] = "DELETE FROM ldap_entry_objclasses "
+const char backsql_def_delobjclasses_stmt[] = "DELETE FROM ldap_entry_objclasses "
"WHERE entry_id=?";
-char backsql_def_subtree_cond[] = "ldap_entries.dn LIKE CONCAT('%',?)";
-char backsql_def_upper_subtree_cond[] = "(ldap_entries.dn) LIKE CONCAT('%',?)";
-char backsql_id_query[] = "SELECT id,keyval,oc_map_id,dn FROM ldap_entries WHERE ";
+const char backsql_def_subtree_cond[] = "ldap_entries.dn LIKE CONCAT('%',?)";
+const char backsql_def_upper_subtree_cond[] = "(ldap_entries.dn) LIKE CONCAT('%',?)";
+const char backsql_id_query[] = "SELECT id,keyval,oc_map_id,dn FROM ldap_entries WHERE ";
/* better ?||? or cast(?||? as varchar) */
-char backsql_def_concat_func[] = "CONCAT(?,?)";
+const char backsql_def_concat_func[] = "CONCAT(?,?)";
/* TimesTen */
-char backsql_check_dn_ru_query[] = "SELECT dn_ru FROM ldap_entries";
+const char backsql_check_dn_ru_query[] = "SELECT dn_ru FROM ldap_entries";
struct berbuf *
backsql_strcat_x( struct berbuf *dest, void *memctx, ... )
char *tline;
const char *fname;
int lineno;
- char log[MAXPATHLEN + STRLENOF(": line 18446744073709551615") + 1];
+ char log[MAXPATHLEN + STRLENOF(": line ") + LDAP_PVT_INTTYPE_CHARS(unsigned long)];
#define cr_msg reply.msg
ConfigReply reply;
int depth;
S_IRGRP, S_IWGRP, S_IXGRP,
S_IROTH, S_IWOTH, S_IXOTH
};
- static char c[] = "-rwxrwxrwx";
+ static const char c[] = "-rwxrwxrwx";
if ( value[ j ] == c[ j ] ) {
p |= m[ j ];
/* handle dynamic object operational attr(s) */
if ( is_dynamicObject ) {
time_t ttl, expire;
- char ttlbuf[] = "31557600";
+ char ttlbuf[STRLENOF("31557600") + 1];
char tsbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
struct berval bv;
ttl = DDS_DEFAULT_TTL( di );
+ /* assert because should be checked at configure */
assert( ttl <= DDS_RF2589_MAX_TTL );
bv.bv_val = ttlbuf;
bv.bv_len = snprintf( ttlbuf, sizeof( ttlbuf ), "%ld", ttl );
+ assert( bv.bv_len < sizeof( ttlbuf ) );
/* FIXME: apparently, values in op->ora_e are malloc'ed
* on the thread's slab; works fine by chance,
slap_callback sc = { 0 };
Modifications ttlmod = { { 0 } };
struct berval ttlvalues[ 2 ];
- char ttlbuf[] = "31557600";
+ char ttlbuf[STRLENOF("31557600") + 1];
rs->sr_err = slap_parse_refresh( op->ore_reqdata, NULL, &ttl,
&rs->sr_text, NULL );
/*
* aclparse.c
*/
-LDAP_SLAPD_V (char *) style_strings[];
+LDAP_SLAPD_V (LDAP_CONST char *) style_strings[];
LDAP_SLAPD_F (int) parse_acl LDAP_P(( Backend *be,
const char *fname, int lineno,
# define UI2BVX(bv,ui,ctx) \
do { \
- char buf[] = "+9223372036854775807L"; \
+ char buf[LDAP_PVT_INTTYPE_CHARS(long)]; \
ber_len_t len; \
len = snprintf( buf, sizeof( buf ), UI2BV_FORMAT, (ui) ); \
if ( len > (bv)->bv_len ) { \
slap_counters_t *oh_counters;
- char oh_log_prefix[ /* sizeof("conn=18446744073709551615 op=18446744073709551615") */ SLAP_TEXT_BUFLEN ];
+ char oh_log_prefix[ /* sizeof("conn= op=") + 2*LDAP_PVT_INTTYPE_CHARS(unsigned long) */ SLAP_TEXT_BUFLEN ];
#ifdef LDAP_SLAPI
void *oh_extensions; /* NS-SLAPI plugin */
si->si_anfile = attr_fname;
} else {
char *str, *s, *next;
- char delimstr[] = " ,\t";
+ const char *delimstr = " ,\t";
str = ch_strdup( val );
for ( s = ldap_pvt_strtok( str, delimstr, &next );
s != NULL;
int sextra_args = 0;
char scmd[MAXPATHLEN];
/* static so that its address can be used in initializer below. */
- static char sloops[] = "18446744073709551615UL";
+ static char sloops[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
/* read */
char *rfile = NULL;
char *rreqs[MAXREQS];
int ranum;
int rextra_args = 0;
char rcmd[MAXPATHLEN];
- static char rloops[] = "18446744073709551615UL";
+ static char rloops[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
/* addel */
char *afiles[MAXREQS];
int anum = 0;
char *aargs[MAXARGS];
int aanum;
char acmd[MAXPATHLEN];
- static char aloops[] = "18446744073709551615UL";
+ static char aloops[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
/* modrdn */
char *nfile = NULL;
char *nreqs[MAXREQS];
char *nargs[MAXARGS];
int nanum;
char ncmd[MAXPATHLEN];
- static char nloops[] = "18446744073709551615UL";
+ static char nloops[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
/* modify */
char *mfile = NULL;
char *mreqs[MAXREQS];
char *margs[MAXARGS];
int manum;
char mcmd[MAXPATHLEN];
- static char mloops[] = "18446744073709551615UL";
+ static char mloops[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
/* bind */
char *bfile = NULL;
char *breqs[MAXREQS];
char *bargs[MAXARGS];
int banum;
char bcmd[MAXPATHLEN];
- static char bloops[] = "18446744073709551615UL";
+ static char bloops[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
char **bargs_extra = NULL;
char *friendlyOpt = NULL;