Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection.Start is deprecated without alternative #507

Closed
dornimaug opened this issue Apr 9, 2024 · 5 comments
Closed

Connection.Start is deprecated without alternative #507

dornimaug opened this issue Apr 9, 2024 · 5 comments
Labels

Comments

@dornimaug
Copy link

As discussed in #356 and implemented in #499 the Connection.Start function has been deprecated, but there is now no way to use net.DialContext instead of one of the ldap.Dial-functions. We currently initialize connections this way:

	dialer := tls.Dialer{
		...
	}
	netConn, err := dialer.DialContext(ctx, "tcp", server)
	if err != nil {
		...
	}
	c := ldap.NewConn(netConn, true)
	c.SetTimeout(readTimeout)
	c.Start()

How can the same (using DialContext and setting a timeout) be achieved through non-deprecated APIs of the ldap package?

Should ldap.NewConn not have been deprecated alongside Connection.Start or is there any legitimate way left to use it?

@cpuschma
Copy link
Member

cpuschma commented Apr 9, 2024

NewConn will be marked deprecated as well in the next release. You can use DialWithDialer to specify a custom dialer to use:

ldap/conn.go

Lines 130 to 135 in 2260012

// DialWithDialer updates net.Dialer in DialContext.
func DialWithDialer(d *net.Dialer) DialOpt {
return func(dc *DialContext) {
dc.dialer = d
}
}

You can use the connection option in Dial, DialTLS or DialURL:

ldap/v3/conn.go

Lines 225 to 229 in 2260012

// DialURL connects to the given ldap URL.
// The following schemas are supported: ldap://, ldaps://, ldapi://,
// and cldap:// (RFC1798, deprecated but used by Active Directory).
// On success a new Conn for the connection is returned.
func DialURL(addr string, opts ...DialOpt) (*Conn, error) {

@dornimaug
Copy link
Author

There is no DialOpt to provide a context.Context to be used together with a net.Dialer's DialContext function. go-ldap currently uses Dial functions and never DialContext. So there is still no way to implement the same functionality as in my code snippet using non-deprecated APIs.
The use of DialContext/context.Context is necessary to make cancellation of the dial operation possible.

@cpuschma
Copy link
Member

cpuschma commented Apr 9, 2024

Agreed. Context implementation is still open and mostly unfinished (see #406). I'll consider revertig the deprecation, as we didn't thought of this use case. Sorry for any inconveniences. The function should work just fine in the meantime.

@cpuschma cpuschma added bug and removed question labels Apr 9, 2024
@gustavoluvizotto
Copy link

Hi,
Please see #356 (comment)

@cpuschma
Copy link
Member

I just released a new version with the reverted commit: https://github.com/go-ldap/ldap/releases/tag/v3.4.8

Again, thank you for pointing this out, I'm sorry for any inconveniences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants