Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,81 @@
2026-02-25 Hisashi MINAMINO <minamino@iij.ad.jp>

* Ruby 3.4 / 4.0 compatibility: migrate deprecated C APIs.

All changes are guarded by #if RB_LDAP_RVC >= 30000 to preserve
backward compatibility with Ruby 2.x.

* rbldap.h: Replace DATA_PTR() with RTYPEDDATA_DATA() in
RLDAP_DATA_PTR macro (version-guarded).
* rbldap.h: Replace rb_time_interval() extern declaration with
rb_ldap_time_interval() static inline implementation.
rb_time_interval is a Ruby private API not guaranteed across
versions.
* rbldap.h: Add extern declarations for TypedData type structs:
rb_ldap_conn_data_type, rb_ldap_entry_data_type,
rb_ldap_mod_data_type, rb_ldap_control_data_type,
rb_ldap_control_nofree_data_type.
* rbldap.h: Version-guard GET_LDAP_DATA, Check_LDAPENTRY,
GET_LDAPENTRY_DATA, GET_LDAPMOD_DATA macros to use
TypedData_Get_Struct on Ruby >= 3.0, Data_Get_Struct otherwise.

* conn.c: Define rb_ldap_conn_data_type with mark/free functions.
* conn.c (rb_ldap_conn_new): Use TypedData_Make_Struct.
* conn.c (rb_ldap_conn_initialize, rb_ldap_conn_simple_bind_s,
rb_ldap_conn_bind_s, rb_ldap_conn_bound): Use
TypedData_Get_Struct.
* conn.c (rb_ldap_conn_rebind): Replace RARRAY_PTR(ary) used as
argv with ALLOCA_N + RARRAY_AREF loop.
* conn.c (rb_ldap_conn_set_option): Replace rb_time_interval()
with rb_ldap_time_interval().
* conn.c (rb_ldap_conn_search_i, rb_ldap_conn_search_ext_i,
rb_ldap_conn_add_s, rb_ldap_conn_add_ext_s,
rb_ldap_conn_modify_s, rb_ldap_conn_modify_ext_s): Replace
RARRAY_PTR(x)[i] with RARRAY_AREF(x, i).

* entry.c: Define rb_ldap_entry_data_type with mark/free
functions.
* entry.c (rb_ldap_entry_new): Add TypedData_Make_Struct branch
for Ruby >= 3.0, keeping Data_Make_Struct for older versions.
* entry.c (rb_ldap_entry_inspect): Use rb_sprintf() on
Ruby >= 3.0 instead of sprintf(RSTRING_PTR(...)).

* mod.c: Define rb_ldap_mod_data_type with free function.
* mod.c (rb_ldap_mod_new, rb_ldap_mod_new2,
rb_ldap_mod_s_allocate): Use TypedData_Make_Struct.
* mod.c (rb_ldap_mod_initialize): Use TypedData_Get_Struct.
Replace RARRAY_PTR(x)[i] with RARRAY_AREF(x, i).
* mod.c (rb_ldap_mod_inspect): Use rb_sprintf() on Ruby >= 3.0.

* misc.c: Define rb_ldap_control_data_type and
rb_ldap_control_nofree_data_type.
* misc.c (rb_ldap_control_new): Use TypedData_Wrap_Struct.
* misc.c (rb_ldap_control_new2): Use TypedData_Wrap_Struct with
nofree type.
* misc.c (rb_ldap_control_copy, rb_ldap_control_s_allocate,
rb_ldap_control_set_value, rb_ldap_control_get_value,
rb_ldap_control_set_oid, rb_ldap_control_get_oid,
rb_ldap_control_oid, rb_ldap_control_set_critical,
rb_ldap_control_get_critical, rb_ldap_control_critical,
rb_ldap_get_control): Use TypedData_Get_Struct.
* misc.c (rb_ldap_get_apiinfo): Replace RARRAY_PTR(x)[i] with
RARRAY_AREF(x, i).

* sslconn.c (rb_openldap_sslconn_initialize,
rb_nssldap_sslconn_initialize,
rb_wldap32_sslconn_initialize, rb_ldap_sslconn_bind_f): Use
TypedData_Get_Struct.

* saslconn.c (rb_ldap_conn_sasl_bind): Use TypedData_Get_Struct.

* clientauth.c (rb_ldap_sslauthconn_rebind): Replace
RARRAY_PTR(ary) used as argv with ALLOCA_N + RARRAY_AREF loop.
* clientauth.c (rb_ldap_sslauthconn_s_bind,
rb_ldap_sslauthconn_initialize): Use TypedData_Get_Struct.

* ruby-ldap.gemspec: Remove obsolete rubyforge_project and
has_rdoc. Add license 'BSD-2-Clause'.

Wed Jul 11 21:58:38 UTC 2018 Alexey Chebotar <alexey.chebotar@gmail.com>
* Version 0.9.20
* Added support of LDAP_OPT_X_TLS_NEWCTX. Thanks to Kouhei Sutou.
Expand Down
16 changes: 14 additions & 2 deletions clientauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,12 @@ VALUE
rb_ldap_sslauthconn_rebind(VALUE self)
{
VALUE ary = rb_iv_get (self, "@args");

return rb_ldap_sslauthconn_initialize(RARRAY_LEN(ary), RARRAY_PTR(ary), self);
int _argc = (int)RARRAY_LEN(ary);
VALUE *_argv = ALLOCA_N(VALUE, _argc);
int i;
for (i = 0; i < _argc; i++)
_argv[i] = RARRAY_AREF(ary, i);
return rb_ldap_sslauthconn_initialize(_argc, _argv, self);
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -394,7 +398,11 @@ rb_ldap_sslauthconn_s_bind(int argc, VALUE argv[], VALUE self) {

LDAPControl **bindctrls = NULL;

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
TypedData_Get_Struct(self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata);
#else
Data_Get_Struct(self, RB_LDAP_DATA, ldapdata);
#endif

if (ldapdata->bind == 0) {
if (rb_iv_get(self, "@args") != Qnil) {
Expand Down Expand Up @@ -450,7 +458,11 @@ rb_ldap_sslauthconn_initialize(int argc, VALUE argv[], VALUE self)

VALUE host, port, tls, cp, cn, key_pw, sctrls, cctrls;

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
TypedData_Get_Struct(self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata);
#else
Data_Get_Struct(self, RB_LDAP_DATA, ldapdata);
#endif
if (ldapdata->ldap)
return Qnil;

Expand Down
69 changes: 56 additions & 13 deletions conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
* rb_mLDAP = rb_define_module ("LDAP");
*/

static void rb_ldap_conn_free (RB_LDAP_DATA *);
static void rb_ldap_conn_mark (RB_LDAP_DATA *);

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
const rb_data_type_t rb_ldap_conn_data_type = {
"LDAP::Conn",
{ (void (*)(void*))rb_ldap_conn_mark,
(void (*)(void*))rb_ldap_conn_free,
NULL },
NULL, NULL, 0
};
#endif

static VALUE rb_ldap_sort_obj = Qnil;
extern VALUE rb_ldap_control_new2 (LDAPControl * ctl);
extern VALUE rb_ldap_sslconn_initialize (int argc, VALUE argv[], VALUE self);
Expand Down Expand Up @@ -46,8 +59,13 @@ rb_ldap_conn_new (VALUE klass, LDAP * cldap)
VALUE conn;
RB_LDAP_DATA *ldapdata;

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
conn = TypedData_Make_Struct (klass, RB_LDAP_DATA,
&rb_ldap_conn_data_type, ldapdata);
#else
conn = Data_Make_Struct (klass, RB_LDAP_DATA,
rb_ldap_conn_mark, rb_ldap_conn_free, ldapdata);
#endif
ldapdata->ldap = cldap;
ldapdata->err = 0;
ldapdata->bind = 0;
Expand Down Expand Up @@ -78,7 +96,11 @@ rb_ldap_conn_initialize (int argc, VALUE argv[], VALUE self)

VALUE host, port;

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata);
#else
Data_Get_Struct (self, RB_LDAP_DATA, ldapdata);
#endif
if (ldapdata->ldap)
{
return Qnil;
Expand Down Expand Up @@ -229,13 +251,16 @@ VALUE
rb_ldap_conn_rebind (VALUE self)
{
VALUE ary = rb_iv_get (self, "@args");
int argc = (int)RARRAY_LEN (ary);
VALUE *argv = ALLOCA_N (VALUE, argc);
int j;
for (j = 0; j < argc; j++)
argv[j] = RARRAY_AREF (ary, j);

if (rb_obj_is_kind_of (self, rb_cLDAP_SSLConn) == Qtrue)
return rb_ldap_sslconn_initialize (RARRAY_LEN (ary), RARRAY_PTR (ary),
self);
return rb_ldap_sslconn_initialize (argc, argv, self);
else
return rb_ldap_conn_initialize (RARRAY_LEN (ary), RARRAY_PTR (ary),
self);
return rb_ldap_conn_initialize (argc, argv, self);
}

/*
Expand All @@ -255,7 +280,11 @@ rb_ldap_conn_simple_bind_s (int argc, VALUE argv[], VALUE self)
char *dn = NULL;
char *passwd = NULL;

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata);
#else
Data_Get_Struct (self, RB_LDAP_DATA, ldapdata);
#endif
if (!ldapdata->ldap)
{
if (rb_iv_get (self, "@args") != Qnil)
Expand Down Expand Up @@ -346,7 +375,11 @@ rb_ldap_conn_bind_s (int argc, VALUE argv[], VALUE self)
char *passwd = NULL;
int method = LDAP_AUTH_SIMPLE;

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata);
#else
Data_Get_Struct (self, RB_LDAP_DATA, ldapdata);
#endif
if (!ldapdata->ldap)
{
if (rb_iv_get (self, "@args") != Qnil)
Expand Down Expand Up @@ -431,7 +464,11 @@ rb_ldap_conn_bound (VALUE self)
{
RB_LDAP_DATA *ldapdata;

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
TypedData_Get_Struct (self, RB_LDAP_DATA, &rb_ldap_conn_data_type, ldapdata);
#else
Data_Get_Struct (self, RB_LDAP_DATA, ldapdata);
#endif

return ldapdata->bind == 0 ? Qfalse : Qtrue;
};
Expand Down Expand Up @@ -475,7 +512,7 @@ rb_ldap_conn_set_option (VALUE self, VALUE opt, VALUE data)
case LDAP_OPT_NETWORK_TIMEOUT:
{
struct timeval tv;
tv = rb_time_interval(data);
tv = rb_ldap_time_interval(data);
optdata = &tv;
}
break;
Expand Down Expand Up @@ -908,7 +945,7 @@ rb_ldap_conn_search_i (int argc, VALUE argv[], VALUE self,
cattrs = ALLOCA_N (char *, (RARRAY_LEN (attrs) + 1));
for (i = 0; i < RARRAY_LEN (attrs); i++)
{
cattrs[i] = StringValueCStr (RARRAY_PTR (attrs)[i]);
cattrs[i] = StringValueCStr (RARRAY_AREF (attrs, i));
};
cattrs[RARRAY_LEN (attrs)] = NULL;
}
Expand Down Expand Up @@ -1241,7 +1278,7 @@ rb_ldap_conn_search_ext_i (int argc, VALUE argv[], VALUE self,
cattrs = ALLOCA_N (char *, (RARRAY_LEN (attrs) + 1));
for (i = 0; i < RARRAY_LEN (attrs); i++)
{
cattrs[i] = StringValueCStr (RARRAY_PTR (attrs)[i]);
cattrs[i] = StringValueCStr (RARRAY_AREF (attrs, i));
};
cattrs[RARRAY_LEN (attrs)] = NULL;
}
Expand Down Expand Up @@ -1450,7 +1487,7 @@ rb_ldap_conn_add_s (VALUE self, VALUE dn, VALUE attrs)

for (i = 0; i < RARRAY_LEN (attrs); i++)
{
VALUE mod = RARRAY_PTR (attrs)[i];
VALUE mod = RARRAY_AREF (attrs, i);
RB_LDAPMOD_DATA *moddata;
Check_Kind (mod, rb_cLDAP_Mod);
GET_LDAPMOD_DATA (mod, moddata);
Expand Down Expand Up @@ -1505,7 +1542,7 @@ rb_ldap_conn_add_ext_s (VALUE self, VALUE dn, VALUE attrs,

for (i = 0; i < RARRAY_LEN (attrs); i++)
{
VALUE mod = RARRAY_PTR (attrs)[i];
VALUE mod = RARRAY_AREF (attrs, i);
RB_LDAPMOD_DATA *moddata;
Check_Kind (mod, rb_cLDAP_Mod);
GET_LDAPMOD_DATA (mod, moddata);
Expand Down Expand Up @@ -1557,7 +1594,7 @@ rb_ldap_conn_modify_s (VALUE self, VALUE dn, VALUE attrs)

for (i = 0; i < RARRAY_LEN (attrs); i++)
{
VALUE mod = RARRAY_PTR (attrs)[i];
VALUE mod = RARRAY_AREF (attrs, i);
RB_LDAPMOD_DATA *moddata;
Check_Kind (mod, rb_cLDAP_Mod);
GET_LDAPMOD_DATA (mod, moddata);
Expand Down Expand Up @@ -1614,7 +1651,7 @@ rb_ldap_conn_modify_ext_s (VALUE self, VALUE dn, VALUE attrs,

for (i = 0; i < RARRAY_LEN (attrs); i++)
{
VALUE mod = RARRAY_PTR (attrs)[i];
VALUE mod = RARRAY_AREF (attrs, i);
RB_LDAPMOD_DATA *moddata;
Check_Kind (mod, rb_cLDAP_Mod);
GET_LDAPMOD_DATA (mod, moddata);
Expand Down Expand Up @@ -1855,14 +1892,20 @@ Init_ldap_conn ()
{
rb_ldap_sort_obj = Qnil;

#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 30000
rb_cLDAP_Conn = rb_define_class_under (rb_mLDAP, "Conn", rb_cData);
#endif
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 30000
rb_cLDAP_Conn = rb_define_class_under (rb_mLDAP, "Conn", rb_cObject);
rb_undef_alloc_func(rb_cLDAP_Conn);
#endif
rb_define_attr (rb_cLDAP_Conn, "referrals", 1, 0);
rb_define_attr (rb_cLDAP_Conn, "controls", 1, 0);
rb_define_attr (rb_cLDAP_Conn, "sasl_quiet", 1, 1);
#if RUBY_VERSION_CODE < 170
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC < 10700
rb_define_singleton_method (rb_cLDAP_Conn, "new", rb_ldap_class_new, -1);
#endif
#if RUBY_VERSION_CODE >= 173
#if defined(RB_LDAP_RVC) && RB_LDAP_RVC >= 10703
rb_define_alloc_func (rb_cLDAP_Conn, rb_ldap_conn_s_allocate);
#else
rb_define_singleton_method (rb_cLDAP_Conn, "allocate",
Expand Down
Loading