Active Directory/Connect: Difference between revisions

Content added Content deleted
(→‎{{header|Wren}}: Sigh, more errors.)
m (syntax highlighting fixup automation)
Line 6: Line 6:
{{works with|AutoHotkey_L}}
{{works with|AutoHotkey_L}}
{{trans|VBScript}}
{{trans|VBScript}}
<lang AutoHotkey>objConn := CreateObject("ADODB.Connection")
<syntaxhighlight lang=AutoHotkey>objConn := CreateObject("ADODB.Connection")
objCmd := CreateObject("ADODB.Command")
objCmd := CreateObject("ADODB.Command")
objConn.Provider := "ADsDSOObject"
objConn.Provider := "ADsDSOObject"
objConn.Open()</lang>
objConn.Open()</syntaxhighlight>


=={{header|AutoIt}}==
=={{header|AutoIt}}==
{{works with|AutoIt}}
{{works with|AutoIt}}
<lang AutoIt> #include <AD.au3>
<syntaxhighlight lang=AutoIt> #include <AD.au3>
_AD_Open()</lang>
_AD_Open()</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
With OpenLDAP:
With OpenLDAP:
<lang C>#include <ldap.h>
<syntaxhighlight lang=C>#include <ldap.h>
...
...
char *name, *password;
char *name, *password;
Line 25: Line 25:
ldap_simple_bind_s(ld, name, password);
ldap_simple_bind_s(ld, name, password);
... after done with it...
... after done with it...
ldap_unbind(ld);</lang>
ldap_unbind(ld);</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>
<syntaxhighlight lang=csharp>
// Requires adding a reference to System.DirectoryServices
// Requires adding a reference to System.DirectoryServices
var objDE = new System.DirectoryServices.DirectoryEntry("LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com");
var objDE = new System.DirectoryServices.DirectoryEntry("LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com");
</syntaxhighlight>
</lang>


=={{header|ColdFusion}}==
=={{header|ColdFusion}}==
<lang cfm>
<syntaxhighlight lang=cfm>
<cfldap
<cfldap
server = "#someip#"
server = "#someip#"
Line 45: Line 45:
attributes = "#attributeslist#"
attributes = "#attributeslist#"
>
>
</syntaxhighlight>
</lang>


=={{header|D}}==
=={{header|D}}==
Based on dopenldap.
Based on dopenldap.
<syntaxhighlight lang=d>
<lang d>
import openldap;
import openldap;
import std.stdio;
import std.stdio;
Line 68: Line 68:
}
}
</syntaxhighlight>
</lang>


=={{header|Erlang}}==
=={{header|Erlang}}==
This needs a test case. Is there a LDAP server available?
This needs a test case. Is there a LDAP server available?
<lang Erlang>
<syntaxhighlight lang=Erlang>
-module(ldap_example).
-module(ldap_example).
-export( [main/1] ).
-export( [main/1] ).
Line 80: Line 80:
ok = eldap:simple_bind( Handle, DN, Password ),
ok = eldap:simple_bind( Handle, DN, Password ),
eldap:close( Handle ).
eldap:close( Handle ).
</syntaxhighlight>
</lang>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
{{trans|C_sharp}}
{{trans|C_sharp}}
<p>For Active Directory we use the library System.DirectoryServices</p>
<p>For Active Directory we use the library System.DirectoryServices</p>
<lang fsharp>let adObject = new System.DirectoryServices.DirectoryEntry("LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com")</lang>
<syntaxhighlight lang=fsharp>let adObject = new System.DirectoryServices.DirectoryEntry("LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com")</syntaxhighlight>
<p>For your average LDAP server we use System.DirectoryServices.Protocol</p>
<p>For your average LDAP server we use System.DirectoryServices.Protocol</p>
<p>For a minimal example we make an anonymous connect to the local machine on the well-known LDAP port 389
<p>For a minimal example we make an anonymous connect to the local machine on the well-known LDAP port 389
<lang fsharp>let ldapServer = new System.DirectoryServices.Protocols.LdapDirectoryIdentifier("127.0.0.1")
<syntaxhighlight lang=fsharp>let ldapServer = new System.DirectoryServices.Protocols.LdapDirectoryIdentifier("127.0.0.1")
let connect = new System.DirectoryServices.Protocols.LdapConnection(ldapServer)
let connect = new System.DirectoryServices.Protocols.LdapConnection(ldapServer)
connect.Bind()</lang>
connect.Bind()</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
Line 96: Line 96:
<br>
<br>
There are a large number of third-party LDAP libraries for Go. This uses one of the simpler ones and the code below is largely taken from the example on its main page.
There are a large number of third-party LDAP libraries for Go. This uses one of the simpler ones and the code below is largely taken from the example on its main page.
<lang go>package main
<syntaxhighlight lang=go>package main


import (
import (
Line 121: Line 121:
}
}
// Do something
// Do something
}</lang>
}</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
Line 127: Line 127:
Example uses the [https://hackage.haskell.org/package/ldap-client <tt>ldap-client</tt>] package:
Example uses the [https://hackage.haskell.org/package/ldap-client <tt>ldap-client</tt>] package:


<lang haskell>{-# LANGUAGE OverloadedStrings #-}
<syntaxhighlight lang=haskell>{-# LANGUAGE OverloadedStrings #-}


module Main (main) where
module Main (main) where
Line 141: Line 141:
Ldap.search ldap (Ldap.Dn "o=example.com") (Ldap.typesOnly True) (Attr "uid" := Text.encodeUtf8 "user") []
Ldap.search ldap (Ldap.Dn "o=example.com") (Ldap.typesOnly True) (Attr "uid" := Text.encodeUtf8 "user") []
for_ entries $ \entry ->
for_ entries $ \entry ->
print entry</lang>
print entry</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
Line 147: Line 147:
This code uses the Apache Directory third-party library.
This code uses the Apache Directory third-party library.


<lang java>import java.io.IOException;
<syntaxhighlight lang=java>import java.io.IOException;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapConnection;
Line 160: Line 160:
}
}
}
}
}</lang>
}</syntaxhighlight>




=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using LDAPClient
<syntaxhighlight lang=julia>using LDAPClient


conn = LDAPClient.LDAPConnection("ldap://localhost:10389")
conn = LDAPClient.LDAPConnection("ldap://localhost:10389")
LDAPClient.simple_bind(conn, "user", "password")
LDAPClient.simple_bind(conn, "user", "password")
LDAPClient.unbind(conn)
LDAPClient.unbind(conn)
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>
<syntaxhighlight lang=scala>
import org.apache.directory.api.ldap.model.exception.LdapException
import org.apache.directory.api.ldap.model.exception.LdapException
import org.apache.directory.ldap.client.api.LdapNetworkConnection
import org.apache.directory.ldap.client.api.LdapNetworkConnection
Line 216: Line 216:


fun main(args: Array<String>) = LDAP(mapOf("hostname" to "localhost", "port" to "10389")).run()
fun main(args: Array<String>) = LDAP(mapOf("hostname" to "localhost", "port" to "10389")).run()
</syntaxhighlight>
</lang>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
Uses the [http://directory.apache.org/api/ Apache LDAP API], connecting to a local [http://directory.apache.org/apacheds/1.5/ ApacheDS] LDAP directory server.
Uses the [http://directory.apache.org/api/ Apache LDAP API], connecting to a local [http://directory.apache.org/apacheds/1.5/ ApacheDS] LDAP directory server.
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang=NetRexx>/* NetRexx */
options replace format comments java crossref symbols binary
options replace format comments java crossref symbols binary


Line 263: Line 263:


return
return
</syntaxhighlight>
</lang>


'''Sample <tt>log4j.xml</tt> configuration file:'''
'''Sample <tt>log4j.xml</tt> configuration file:'''
<lang xml><?xml version="1.0" encoding="UTF-8" ?>
<syntaxhighlight lang=xml><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
Line 292: Line 292:
</root>
</root>
</log4j:configuration>
</log4j:configuration>
</syntaxhighlight>
</lang>


'''Output:'''
'''Output:'''
Line 301: Line 301:
=={{header|Perl}}==
=={{header|Perl}}==
[http://search.cpan.org/dist/perl-ldap/|Perl LDAP Modules]
[http://search.cpan.org/dist/perl-ldap/|Perl LDAP Modules]
<lang perl>
<syntaxhighlight lang=perl>
use Net::LDAP;
use Net::LDAP;


my $ldap = Net::LDAP->new('ldap://ldap.example.com') or die $@;
my $ldap = Net::LDAP->new('ldap://ldap.example.com') or die $@;
my $mesg = $ldap->bind( $bind_dn, password => $bind_pass );
my $mesg = $ldap->bind( $bind_dn, password => $bind_pass );
</syntaxhighlight>
</lang>


=={{header|Phix}}==
=={{header|Phix}}==
Line 313: Line 313:
This has been tested against a random 7-year-old list of public ldap servers, getting mixed errors of
This has been tested against a random 7-year-old list of public ldap servers, getting mixed errors of
LDAP_SERVER_DOWN/LDAP_INVALID_CREDENTIALS/LDAP_INVALID_DN_SYNTAX/LDAP_CONFIDENTIALITY_REQUIRED.
LDAP_SERVER_DOWN/LDAP_INVALID_CREDENTIALS/LDAP_INVALID_DN_SYNTAX/LDAP_CONFIDENTIALITY_REQUIRED.
<!--<lang Phix>-->
<!--<syntaxhighlight lang=Phix>-->
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">/</span><span style="color: #000000;">ldap</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">/</span><span style="color: #000000;">ldap</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 329: Line 329:
<span style="color: #000000;">ldap_unbind</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ld</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ldap_unbind</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ld</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 337: Line 337:
=={{header|PHP}}==
=={{header|PHP}}==
[http://php.net/ldap PHP LDAP Reference]
[http://php.net/ldap PHP LDAP Reference]
<lang php><?php
<syntaxhighlight lang=php><?php
$ldap = ldap_connect($hostname, $port);
$ldap = ldap_connect($hostname, $port);
$success = ldap_bind($ldap, $username, $password);</lang>
$success = ldap_bind($ldap, $username, $password);</syntaxhighlight>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(unless (=0 (setq Ldap (native "libldap.so" "ldap_open" 'N "example.com" 389)))
<syntaxhighlight lang=PicoLisp>(unless (=0 (setq Ldap (native "libldap.so" "ldap_open" 'N "example.com" 389)))
(quit "Can't open LDAP") )
(quit "Can't open LDAP") )


(native "libldap.so" "ldap_simple_bind_s" 'I Ldap "user" "password")</lang>
(native "libldap.so" "ldap_simple_bind_s" 'I Ldap "user" "password")</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
Line 353: Line 353:
[http://www.python-ldap.org/doc/html/index.html python-ldap Documentation]
[http://www.python-ldap.org/doc/html/index.html python-ldap Documentation]


<lang python>import ldap
<syntaxhighlight lang=python>import ldap


l = ldap.initialize("ldap://ldap.example.com")
l = ldap.initialize("ldap://ldap.example.com")
Line 363: Line 363:
finally:
finally:
l.unbind()
l.unbind()
</syntaxhighlight>
</lang>


=={{header|Racket}}==
=={{header|Racket}}==
This version uses the ldap package, and was tested against OpenLDAP (with real values):
This version uses the ldap package, and was tested against OpenLDAP (with real values):
<lang racket>#lang racket
<syntaxhighlight lang=racket>#lang racket
(require net/ldap)
(require net/ldap)
(ldap-authenticate "ldap.somewhere.com" 389 "uid=username,ou=people,dc=somewhere,dc=com" password)</lang>
(ldap-authenticate "ldap.somewhere.com" 389 "uid=username,ou=people,dc=somewhere,dc=com" password)</syntaxhighlight>


{{trans|C}}
{{trans|C}}
Line 375: Line 375:
This is a direct translation of the C code -- I have no idea how to try it out since I don't have a working ldap server... So take it as a stub that waits for someone who can try it to do so. (And it's a low level thing anyway, there's an ldap package for Racket which I can't try for a similar reason.)
This is a direct translation of the C code -- I have no idea how to try it out since I don't have a working ldap server... So take it as a stub that waits for someone who can try it to do so. (And it's a low level thing anyway, there's an ldap package for Racket which I can't try for a similar reason.)


<lang racket>#lang racket
<syntaxhighlight lang=racket>#lang racket


(require ffi/unsafe ffi/unsafe/define)
(require ffi/unsafe ffi/unsafe/define)
Line 390: Line 390:
(ldap_simple_bind_s ld name password)
(ldap_simple_bind_s ld name password)


(ldap_unbind ld)</lang>
(ldap_unbind ld)</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
Line 397: Line 397:
Using module LMDB - bindings to the openLDAP library. Requires an LDAP instance.
Using module LMDB - bindings to the openLDAP library. Requires an LDAP instance.


<lang perl6>use LMDB;
<syntaxhighlight lang=perl6>use LMDB;


my %DB := LMDB::DB.open(:path<some-dir>, %connection-parameters);
my %DB := LMDB::DB.open(:path<some-dir>, %connection-parameters);
</syntaxhighlight>
</lang>


%DB may be accessed, read from and written to like a native hash.
%DB may be accessed, read from and written to like a native hash.
Line 410: Line 410:


{{libheader|RubyGems}}
{{libheader|RubyGems}}
<lang ruby>require 'rubygems'
<syntaxhighlight lang=ruby>require 'rubygems'
require 'net/ldap'
require 'net/ldap'
ldap = Net::LDAP.new(:host => 'ldap.example.com', :base => 'o=companyname')
ldap = Net::LDAP.new(:host => 'ldap.example.com', :base => 'o=companyname')
ldap.authenticate('bind_dn', 'bind_pass')</lang>
ldap.authenticate('bind_dn', 'bind_pass')</syntaxhighlight>


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
{{incorrect|Run BASIC|Active Directory has nothing to do with the local file system}}
{{incorrect|Run BASIC|Active Directory has nothing to do with the local file system}}
<lang runbasic>print shell$("dir") ' shell out to the os and print it</lang>
<syntaxhighlight lang=runbasic>print shell$("dir") ' shell out to the os and print it</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
This solution uses the popular [https://crates.io/crates/ldap3 ldap3] crate.
This solution uses the popular [https://crates.io/crates/ldap3 ldap3] crate.
<lang rust>
<syntaxhighlight lang=rust>
let conn = ldap3::LdapConn::new("ldap://ldap.example.com")?;
let conn = ldap3::LdapConn::new("ldap://ldap.example.com")?;
conn.simple_bind("bind_dn", "bind_pass")?.success()?;
conn.simple_bind("bind_dn", "bind_pass")?.success()?;
</syntaxhighlight>
</lang>


=={{header|Scala}}==
=={{header|Scala}}==
<lang scala>import java.io.IOException
<syntaxhighlight lang=scala>import java.io.IOException


import org.apache.directory.api.ldap.model.exception.LdapException
import org.apache.directory.api.ldap.model.exception.LdapException
Line 444: Line 444:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|smart BASIC}}==
=={{header|smart BASIC}}==
Line 450: Line 450:


smart BASIC uses three separate commands to list the current directory, folder and files respectively.
smart BASIC uses three separate commands to list the current directory, folder and files respectively.
<lang qbasic>PRINT "Current directory: ";CURRENT_DIR$()
<syntaxhighlight lang=qbasic>PRINT "Current directory: ";CURRENT_DIR$()
PRINT
PRINT
PRINT "Folders:"
PRINT "Folders:"
Line 464: Line 464:
FOR n = 0 TO c-1
FOR n = 0 TO c-1
PRINT ,a$(n)
PRINT ,a$(n)
NEXT n</lang>
NEXT n</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
This does not use SSPI/Kerberos yet, so your AD would need to allow simple ldap access.
This does not use SSPI/Kerberos yet, so your AD would need to allow simple ldap access.
<lang tcl>package require ldap
<syntaxhighlight lang=tcl>package require ldap
set conn [ldap::connect $host $port]
set conn [ldap::connect $host $port]
ldap::bind $conn $user $password</lang>
ldap::bind $conn $user $password</syntaxhighlight>


=={{header|VBScript}}==
=={{header|VBScript}}==
Creating the normal connection to AD
Creating the normal connection to AD
<lang vbscript>Set objConn = CreateObject("ADODB.Connection")
<syntaxhighlight lang=vbscript>Set objConn = CreateObject("ADODB.Connection")
Set objCmd = CreateObject("ADODB.Command")
Set objCmd = CreateObject("ADODB.Command")
objConn.Provider = "ADsDSOObject"
objConn.Provider = "ADsDSOObject"
objConn.Open</lang>
objConn.Open</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
Line 483: Line 483:
{{libheader|OpenLDAP}}
{{libheader|OpenLDAP}}
As it's not currently possible for Wren-cli to access OpenLDAP directly, we embed a Wren script in a C application to complete this task.
As it's not currently possible for Wren-cli to access OpenLDAP directly, we embed a Wren script in a C application to complete this task.
<lang ecmascript>/* active_directory_connect.wren */
<syntaxhighlight lang=ecmascript>/* active_directory_connect.wren */


foreign class LDAP {
foreign class LDAP {
Line 514: Line 514:
// do something here
// do something here


ld.unbind()</lang>
ld.unbind()</syntaxhighlight>
<br>
<br>
We now embed this in the following C program, compile and run it.
We now embed this in the following C program, compile and run it.
<lang c>#include <stdio.h>
<syntaxhighlight lang=c>#include <stdio.h>
#include <stdio_ext.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <stdlib.h>
Line 635: Line 635:
free(script);
free(script);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{omit from|Active Directory}}
{{omit from|Active Directory}}