From 15db20917ad5dbbeff593155874f6aff0f6fe1f8 Mon Sep 17 00:00:00 2001 From: Quanah Gibson-Mount Date: Wed, 22 Dec 2010 00:28:50 +0000 Subject: [PATCH] ITS#6617 --- CHANGES | 1 + servers/slapd/back-sql/add.c | 30 +++++++++++++++-------------- servers/slapd/back-sql/back-sql.h | 26 ++++++++++++++++++++----- servers/slapd/back-sql/entry-id.c | 8 ++++---- servers/slapd/back-sql/proto-sql.h | 7 ++++++- servers/slapd/back-sql/schema-map.c | 22 +++++++++++---------- servers/slapd/back-sql/search.c | 11 ++++++----- 7 files changed, 66 insertions(+), 39 deletions(-) diff --git a/CHANGES b/CHANGES index 422f3f0956..08c1c85a0b 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ OpenLDAP 2.4 Change Log OpenLDAP 2.4.24 Engineering Added slapd-null back-config support (ITS#6624) Added slapd-sql autocommit support (ITS#6612) + Addes slapd-sql support for long long keys (ITS#6617) Fixed liblber to not close invalid sockets (ITS#6585) Fixed libldap dnssrv port format specifier (ITS#6644) Fixed libldap EOF handling (ITS#6723) diff --git a/servers/slapd/back-sql/add.c b/servers/slapd/back-sql/add.c index 0bc7fb5d71..94d00732fe 100644 --- a/servers/slapd/back-sql/add.c +++ b/servers/slapd/back-sql/add.c @@ -724,7 +724,7 @@ backsql_add_attr( SQLHDBC dbh, backsql_oc_map_rec *oc, Attribute *at, - unsigned long new_keyval ) + backsql_key_t new_keyval ) { backsql_info *bi = (backsql_info*)op->o_bd->be_private; backsql_at_map_rec *at_rec = NULL; @@ -820,7 +820,7 @@ backsql_add_attr( po = ( BACKSQL_IS_ADD( at_rec->bam_param_order ) ) > 0; currpos = pno + 1 + po; - rc = backsql_BindParamInt( sth, currpos, + rc = backsql_BindParamNumID( sth, currpos, SQL_PARAM_INPUT, &new_keyval ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, @@ -857,12 +857,14 @@ backsql_add_attr( } #ifdef LDAP_DEBUG - snprintf( logbuf, sizeof( logbuf ), "val[%lu], id=%lu", - i, new_keyval ); - Debug( LDAP_DEBUG_TRACE, " backsql_add_attr(\"%s\"): " - "executing \"%s\" %s\n", - op->ora_e->e_name.bv_val, - at_rec->bam_add_proc, logbuf ); + if ( LogTest( LDAP_DEBUG_TRACE ) ) { + snprintf( logbuf, sizeof( logbuf ), "val[%lu], id=" BACKSQL_IDNUMFMT, + i, new_keyval ); + Debug( LDAP_DEBUG_TRACE, " backsql_add_attr(\"%s\"): " + "executing \"%s\" %s\n", + op->ora_e->e_name.bv_val, + at_rec->bam_add_proc, logbuf ); + } #endif rc = SQLExecute( sth ); if ( rc == SQL_SUCCESS && prc == LDAP_SUCCESS ) { @@ -902,7 +904,7 @@ backsql_add( Operation *op, SlapReply *rs ) backsql_info *bi = (backsql_info*)op->o_bd->be_private; SQLHDBC dbh = SQL_NULL_HDBC; SQLHSTMT sth = SQL_NULL_HSTMT; - unsigned long new_keyval = 0; + backsql_key_t new_keyval = 0; RETCODE rc; backsql_oc_map_rec *oc = NULL; backsql_srch_info bsi = { 0 }; @@ -1155,7 +1157,7 @@ backsql_add( Operation *op, SlapReply *rs ) colnum = 1; if ( BACKSQL_IS_ADD( oc->bom_expect_return ) ) { - rc = backsql_BindParamInt( sth, 1, SQL_PARAM_OUTPUT, &new_keyval ); + rc = backsql_BindParamNumID( sth, 1, SQL_PARAM_OUTPUT, &new_keyval ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): " "error binding keyval parameter " @@ -1306,7 +1308,7 @@ backsql_add( Operation *op, SlapReply *rs ) SQLFreeStmt( sth, SQL_DROP ); Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): " - "create_proc returned keyval=%ld\n", + "create_proc returned keyval=" BACKSQL_IDNUMFMT "\n", op->ora_e->e_name.bv_val, new_keyval, 0 ); rc = backsql_Prepare( dbh, &sth, bi->sql_insentry_stmt, 0 ); @@ -1333,7 +1335,7 @@ backsql_add( Operation *op, SlapReply *rs ) goto done; } - rc = backsql_BindParamInt( sth, 2, SQL_PARAM_INPUT, &oc->bom_id ); + rc = backsql_BindParamNumID( sth, 2, SQL_PARAM_INPUT, &oc->bom_id ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): " "error binding objectClass ID parameter " @@ -1367,7 +1369,7 @@ backsql_add( Operation *op, SlapReply *rs ) goto done; } - rc = backsql_BindParamInt( sth, 4, SQL_PARAM_INPUT, &new_keyval ); + rc = backsql_BindParamNumID( sth, 4, SQL_PARAM_INPUT, &new_keyval ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): " "error binding entry ID parameter " @@ -1388,7 +1390,7 @@ backsql_add( Operation *op, SlapReply *rs ) char buf[ SLAP_TEXT_BUFLEN ]; snprintf( buf, sizeof(buf), - "executing \"%s\" for dn=\"%s\" oc_map_id=%ld p_id=" BACKSQL_IDFMT " keyval=%ld", + "executing \"%s\" for dn=\"%s\" oc_map_id=" BACKSQL_IDNUMFMT " p_id=" BACKSQL_IDFMT " keyval=" BACKSQL_IDNUMFMT, bi->sql_insentry_stmt, op->ora_e->e_name.bv_val, oc->bom_id, BACKSQL_IDARG(bsi.bsi_base_id.eid_id), new_keyval ); diff --git a/servers/slapd/back-sql/back-sql.h b/servers/slapd/back-sql/back-sql.h index 7c30046769..b6b02f5c0c 100644 --- a/servers/slapd/back-sql/back-sql.h +++ b/servers/slapd/back-sql/back-sql.h @@ -223,6 +223,22 @@ typedef struct { */ #undef BACKSQL_ARBITRARY_KEY +/* + * type used for keys + */ +#if defined(HAVE_LONG_LONG) && defined(SQL_C_UBIGINT) && \ + ( defined(HAVE_STRTOULL) || defined(HAVE_STRTOUQ) ) +typedef unsigned long long backsql_key_t; +#define BACKSQL_C_NUMID SQL_C_UBIGINT +#define BACKSQL_IDNUMFMT "%llu" +#define BACKSQL_STR2ID lutil_atoullx +#else /* ! HAVE_LONG_LONG || ! SQL_C_UBIGINT */ +typedef unsigned long backsql_key_t; +#define BACKSQL_C_NUMID SQL_C_ULONG +#define BACKSQL_IDNUMFMT "%lu" +#define BACKSQL_STR2ID lutil_atoulx +#endif /* ! HAVE_LONG_LONG */ + /* * define to enable support for syncprov overlay */ @@ -289,7 +305,7 @@ typedef struct backsql_oc_map_rec { /* flags whether delete_proc is a function (whether back-sql * should bind first parameter as output for return code) */ int bom_expect_return; - unsigned long bom_id; + backsql_key_t bom_id; Avlnode *bom_attrs; AttributeDescription *bom_create_hint; } backsql_oc_map_rec; @@ -381,11 +397,11 @@ typedef struct backsql_entryID { #define BACKSQL_MAX_KEY_LEN 64 #else /* ! BACKSQL_ARBITRARY_KEY */ /* The original numeric key is maintained as default. */ - unsigned long eid_id; - unsigned long eid_keyval; + backsql_key_t eid_id; + backsql_key_t eid_keyval; #endif /* ! BACKSQL_ARBITRARY_KEY */ - unsigned long eid_oc_id; + backsql_key_t eid_oc_id; backsql_oc_map_rec *eid_oc; struct berval eid_dn; struct berval eid_ndn; @@ -603,7 +619,7 @@ typedef struct backsql_info { #define BACKSQL_IDFMT "%s" #define BACKSQL_IDARG(arg) ((arg).bv_val) #else /* ! BACKSQL_ARBITRARY_KEY */ -#define BACKSQL_IDFMT "%lu" +#define BACKSQL_IDFMT BACKSQL_IDNUMFMT #define BACKSQL_IDARG(arg) (arg) #endif /* ! BACKSQL_ARBITRARY_KEY */ diff --git a/servers/slapd/back-sql/entry-id.c b/servers/slapd/back-sql/entry-id.c index 6cef98dde6..926d5bef45 100644 --- a/servers/slapd/back-sql/entry-id.c +++ b/servers/slapd/back-sql/entry-id.c @@ -288,16 +288,16 @@ backsql_dn2id( ber_str2bv_x( row.cols[ 1 ], 0, 1, &id->eid_keyval, op->o_tmpmemctx ); #else /* ! BACKSQL_ARBITRARY_KEY */ - if ( lutil_atoulx( &id->eid_id, row.cols[ 0 ], 0 ) != 0 ) { + if ( BACKSQL_STR2ID( &id->eid_id, row.cols[ 0 ], 0 ) != 0 ) { res = LDAP_OTHER; goto done; } - if ( lutil_atoulx( &id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) { + if ( BACKSQL_STR2ID( &id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) { res = LDAP_OTHER; goto done; } #endif /* ! BACKSQL_ARBITRARY_KEY */ - if ( lutil_atoulx( &id->eid_oc_id, row.cols[ 2 ], 0 ) != 0 ) { + if ( BACKSQL_STR2ID( &id->eid_oc_id, row.cols[ 2 ], 0 ) != 0 ) { res = LDAP_OTHER; goto done; } @@ -933,7 +933,7 @@ backsql_id2entry( backsql_srch_info *bsi, backsql_entryID *eid ) eid->eid_oc_id ); if ( eid->eid_oc == NULL ) { Debug( LDAP_DEBUG_TRACE, - "backsql_id2entry(): unable to fetch objectClass with id=%lu for entry id=" BACKSQL_IDFMT " dn=\"%s\"\n", + "backsql_id2entry(): unable to fetch objectClass with id=" BACKSQL_IDNUMFMT " for entry id=" BACKSQL_IDFMT " dn=\"%s\"\n", eid->eid_oc_id, BACKSQL_IDARG(eid->eid_id), eid->eid_dn.bv_val ); return LDAP_OTHER; diff --git a/servers/slapd/back-sql/proto-sql.h b/servers/slapd/back-sql/proto-sql.h index ba8fd4ecbe..ac4ae5baa1 100644 --- a/servers/slapd/back-sql/proto-sql.h +++ b/servers/slapd/back-sql/proto-sql.h @@ -204,12 +204,17 @@ RETCODE backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, const char* query, int time (io), SQL_C_ULONG, SQL_INTEGER, \ 0, 0, (SQLPOINTER)(val), 0, (SQLINTEGER*)NULL ) +#define backsql_BindParamNumID( sth, par_ind, io, val ) \ + SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind), \ + (io), BACKSQL_C_NUMID, SQL_INTEGER, \ + 0, 0, (SQLPOINTER)(val), 0, (SQLINTEGER*)NULL ) + #ifdef BACKSQL_ARBITRARY_KEY #define backsql_BindParamID( sth, par_ind, io, id ) \ backsql_BindParamBerVal( (sth), (par_ind), (io), (id) ) #else /* ! BACKSQL_ARBITRARY_KEY */ #define backsql_BindParamID( sth, par_ind, io, id ) \ - backsql_BindParamInt( (sth), (par_ind), (io), (id) ) + backsql_BindParamNumID( (sth), (par_ind), (io), (id) ) #endif /* ! BACKSQL_ARBITRARY_KEY */ RETCODE backsql_BindRowAsStrings_x( SQLHSTMT sth, BACKSQL_ROW_NTS *row, void *ctx ); diff --git a/servers/slapd/back-sql/schema-map.c b/servers/slapd/back-sql/schema-map.c index 87a069ba56..9c8d771a9d 100644 --- a/servers/slapd/back-sql/schema-map.c +++ b/servers/slapd/back-sql/schema-map.c @@ -199,7 +199,7 @@ backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map ) struct berbuf bb; sbv.bv_val = s; - sbv.bv_len = snprintf( s, sizeof( s ), "%ld", oc_map->bom_id ); + sbv.bv_len = snprintf( s, sizeof( s ), BACKSQL_IDNUMFMT, oc_map->bom_id ); /* extra objectClasses */ at_map = (backsql_at_map_rec *)ch_calloc(1, @@ -242,7 +242,7 @@ backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map ) "INSERT INTO ldap_entry_objclasses " "(entry_id,oc_name) VALUES " "((SELECT id FROM ldap_entries " - "WHERE oc_map_id=%lu " + "WHERE oc_map_id=" BACKSQL_IDNUMFMT " " "AND keyval=?),?)", oc_map->bom_id ); at_map->bam_add_proc = ch_strdup( tmp ); } @@ -256,7 +256,7 @@ backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map ) snprintf( tmp, sizeof(tmp), "DELETE FROM ldap_entry_objclasses " "WHERE entry_id=(SELECT id FROM ldap_entries " - "WHERE oc_map_id=%lu " + "WHERE oc_map_id=" BACKSQL_IDNUMFMT " " "AND keyval=?) AND oc_name=?", oc_map->bom_id ); at_map->bam_delete_proc = ch_strdup( tmp ); @@ -297,7 +297,7 @@ struct backsql_attr_schema_info { backsql_info *bas_bi; SQLHDBC bas_dbh; SQLHSTMT bas_sth; - unsigned long *bas_oc_id; + backsql_key_t *bas_oc_id; int bas_rc; }; @@ -317,7 +317,7 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas ) "executing at_query\n" " \"%s\"\n" " for objectClass \"%s\"\n" - " with param oc_id=\"%lu\"\n", + " with param oc_id=" BACKSQL_IDNUMFMT "\n", bas->bas_bi->sql_at_query, BACKSQL_OC_NAME( oc_map ), *bas->bas_oc_id ); @@ -328,7 +328,7 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas ) "error executing at_query\n" " \"%s\"\n" " for objectClass \"%s\"\n" - " with param oc_id=\"%lu\"\n", + " with param oc_id=" BACKSQL_IDNUMFMT "\n", bas->bas_bi->sql_at_query, BACKSQL_OC_NAME( oc_map ), *bas->bas_oc_id ); @@ -503,7 +503,7 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh ) SQLHSTMT sth = SQL_NULL_HSTMT; RETCODE rc; BACKSQL_ROW_NTS oc_row; - unsigned long oc_id; + backsql_key_t oc_id; backsql_oc_map_rec *oc_map; struct backsql_attr_schema_info bas; @@ -569,11 +569,13 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh ) { 1, "name" }, { 2, "keytbl" }, { 3, "keycol" }, - { delete_proc_idx + 1, "expect_return" }, + { -1, "expect_return" }, { -1, NULL }, }; int i; + required[4].idx = delete_proc_idx + 1; + for ( i = 0; required[ i ].name != NULL; i++ ) { if ( oc_row.value_len[ required[ i ].idx ] <= 0 ) { Debug( LDAP_DEBUG_ANY, @@ -614,7 +616,7 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh ) oc_map = (backsql_oc_map_rec *)ch_calloc( 1, sizeof( backsql_oc_map_rec ) ); - if ( lutil_atoulx( &oc_map->bom_id, oc_row.cols[ 0 ], 0 ) != 0 ) { + if ( BACKSQL_STR2ID( &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 ); @@ -730,7 +732,7 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh ) return LDAP_OTHER; } - rc = backsql_BindParamInt( sth, 1, SQL_PARAM_INPUT, &oc_id ); + rc = backsql_BindParamNumID( sth, 1, SQL_PARAM_INPUT, &oc_id ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): " "error binding param \"oc_id\" for at_query\n", 0, 0, 0 ); diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 21adfed7ee..8ab839d177 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -1746,9 +1746,10 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) return BACKSQL_AVL_CONTINUE; } - Debug( LDAP_DEBUG_TRACE, "id: '%ld'\n", bsi->bsi_oc->bom_id, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "id: '" BACKSQL_IDNUMFMT "'\n", + bsi->bsi_oc->bom_id, 0, 0 ); - rc = backsql_BindParamInt( sth, 1, SQL_PARAM_INPUT, + rc = backsql_BindParamNumID( sth, 1, SQL_PARAM_INPUT, &bsi->bsi_oc->bom_id ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " @@ -1940,10 +1941,10 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) ber_str2bv_x( row.cols[ 1 ], 0, 1, &c_id->eid_keyval, op->o_tmpmemctx ); #else /* ! BACKSQL_ARBITRARY_KEY */ - if ( lutil_atoulx( &c_id->eid_id, row.cols[ 0 ], 0 ) != 0 ) { + if ( BACKSQL_STR2ID( &c_id->eid_id, row.cols[ 0 ], 0 ) != 0 ) { goto cleanup; } - if ( lutil_atoulx( &c_id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) { + if ( BACKSQL_STR2ID( &c_id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) { goto cleanup; } #endif /* ! BACKSQL_ARBITRARY_KEY */ @@ -2237,7 +2238,7 @@ backsql_search( Operation *op, SlapReply *rs ) } Debug(LDAP_DEBUG_TRACE, "backsql_search(): loading data " - "for entry id=" BACKSQL_IDFMT " oc_id=%ld, keyval=" BACKSQL_IDFMT "\n", + "for entry id=" BACKSQL_IDFMT " oc_id=" BACKSQL_IDNUMFMT ", keyval=" BACKSQL_IDFMT "\n", BACKSQL_IDARG(eid->eid_id), eid->eid_oc_id, BACKSQL_IDARG(eid->eid_keyval) ); -- 2.39.5