Active Directory/Search for a user: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 25: Line 25:
ldap_msgfree(*result); /* free messages */
ldap_msgfree(*result); /* free messages */
ldap_unbind(ld); /* disconnect */</lang>
ldap_unbind(ld); /* disconnect */</lang>



=={{header|D}}==
=={{header|D}}==
Line 182: Line 181:
}
}
}</lang>
}</lang>

=={{header|ooRexx}}==
Using LDAP connecting to a local [http://directory.apache.org/apacheds/1.5/ ApacheDS] LDAP directory server.

This program drives the <tt>ldapsearch</tt> command and captures the output into an external data queue via ooRexx <tt>rxqueue</tt> facility. The contents of the queue are then read into program variables for further processing.

<lang ooRexx>/* Rexx */
do
LDAP_URL = 'ldap://localhost:11389'
LDAP_DN_STR = 'uid=admin,ou=system'
LDAP_CREDS = '********'
LDAP_BASE_DN = 'ou=users,o=mojo'
LDAP_SCOPE = 'sub'
LDAP_FILTER = '"(&(objectClass=person)(&(uid=*mil*)))"'
LDAP_ATTRIBUTES = '"dn" "cn" "sn" "uid"'

ldapCommand = ,
'ldapsearch' ,
'-s base' ,
'-H' LDAP_URL ,
'-LLL' ,
'-x' ,
'-v' ,
'-s' LDAP_SCOPE ,
'-D' LDAP_DN_STR ,
'-w' LDAP_CREDS ,
'-b' LDAP_BASE_DN ,
LDAP_FILTER ,
LDAP_ATTRIBUTES ,
'2>&1' ,
'|' ,
'rxqueue' ,
''

address command,
ldapCommand

ldapResult. = ''
loop ln = 1 to queued()
parse pull line
ldapResult.0 = ln
ldapResult.ln = line
end ln

loop ln = 1 to ldapResult.0
parse var ldapResult.ln 'dn:' dn_ ,
0 'uid:' uid_ ,
0 'sn:' sn_ ,
0 'cn:' cn_
select
when length(strip(dn_, 'b')) > 0 then dn = dn_
when length(strip(uid_, 'b')) > 0 then uid = uid_
when length(strip(sn_, 'b')) > 0 then sn = sn_
when length(strip(cn_, 'b')) > 0 then cn = cn_
otherwise nop
end
end ln

say 'Distiguished Name:' dn
say ' Common Name:' cn
say ' Surname:' sn
say ' userID:' uid

return
end
exit
</lang>
'''Output:'''
<pre>
Distiguished Name: cn=John Milton,ou=users,o=mojo
Common Name: John Milton
Surname: Milton
userID: jmilton
</pre>

=={{header|Perl 6}}==
<lang perl6>#!/usr/bin/env perl6

# 20190718 Perl 6 programming solution
# https://github.com/perl6/doc/issues/2898
# https://www.facebook.com/groups/perl6/permalink/2379873082279037/

# Reference:
# https://github.com/Altai-man/cro-ldap
# https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

use v6.d;
use Cro::LDAP::Client;

my $client = await Cro::LDAP::Client.connect('ldap://ldap.forumsys.com');

my $bind = await $client.bind(
name=>'cn=read-only-admin,dc=example,dc=com',password=>'password'
);
die $bind.error-message if $bind.result-code;

my $resp = $client.search(
:dn<dc=example,dc=com>, base=>"ou=mathematicians", filter=>'(&(uid=gauss))'
);

react {
whenever $resp -> $entry {
for $entry.attributes.kv -> $k, $v {
my $value-str = $v ~~ Blob ?? $v.decode !! $v.map(*.decode);
note "$k -> $value-str";
}
}
}</lang>
{{out}}
<pre>objectClass -> inetOrgPerson organizationalPerson top person
mail -> gauss@ldap.forumsys.com
uid -> gauss
cn -> Carl Friedrich Gauss
sn -> Gauss
</pre>

=={{header|PicoLisp}}==
<lang PicoLisp>(de ldapsearch (Sn)
(in
(list "ldapsearch" "-xH" "ldap://db.debian.org"
"-b" "dc=debian,dc=org"
(pack "sn=" Sn) )
(list
(cons 'cn (prog (from "cn: ") (line T)))
(cons 'uid (prog (from "uid: ") (line T))) ) ) )</lang>
Test:
<pre>: (ldapsearch "Fischer")
-> ((cn . "Mika") (uid . "mf"))</pre>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
Line 448: Line 319:
</pre>
</pre>


=={{header|ooRexx}}==
Using LDAP connecting to a local [http://directory.apache.org/apacheds/1.5/ ApacheDS] LDAP directory server.

This program drives the <tt>ldapsearch</tt> command and captures the output into an external data queue via ooRexx <tt>rxqueue</tt> facility. The contents of the queue are then read into program variables for further processing.

<lang ooRexx>/* Rexx */
do
LDAP_URL = 'ldap://localhost:11389'
LDAP_DN_STR = 'uid=admin,ou=system'
LDAP_CREDS = '********'
LDAP_BASE_DN = 'ou=users,o=mojo'
LDAP_SCOPE = 'sub'
LDAP_FILTER = '"(&(objectClass=person)(&(uid=*mil*)))"'
LDAP_ATTRIBUTES = '"dn" "cn" "sn" "uid"'

ldapCommand = ,
'ldapsearch' ,
'-s base' ,
'-H' LDAP_URL ,
'-LLL' ,
'-x' ,
'-v' ,
'-s' LDAP_SCOPE ,
'-D' LDAP_DN_STR ,
'-w' LDAP_CREDS ,
'-b' LDAP_BASE_DN ,
LDAP_FILTER ,
LDAP_ATTRIBUTES ,
'2>&1' ,
'|' ,
'rxqueue' ,
''

address command,
ldapCommand

ldapResult. = ''
loop ln = 1 to queued()
parse pull line
ldapResult.0 = ln
ldapResult.ln = line
end ln

loop ln = 1 to ldapResult.0
parse var ldapResult.ln 'dn:' dn_ ,
0 'uid:' uid_ ,
0 'sn:' sn_ ,
0 'cn:' cn_
select
when length(strip(dn_, 'b')) > 0 then dn = dn_
when length(strip(uid_, 'b')) > 0 then uid = uid_
when length(strip(sn_, 'b')) > 0 then sn = sn_
when length(strip(cn_, 'b')) > 0 then cn = cn_
otherwise nop
end
end ln

say 'Distiguished Name:' dn
say ' Common Name:' cn
say ' Surname:' sn
say ' userID:' uid

return
end
exit
</lang>
'''Output:'''
<pre>
Distiguished Name: cn=John Milton,ou=users,o=mojo
Common Name: John Milton
Surname: Milton
userID: jmilton
</pre>


=={{header|PHP}}==
=={{header|PHP}}==
Line 469: Line 413:


var_dump($entries);</lang>
var_dump($entries);</lang>

=={{header|PicoLisp}}==
<lang PicoLisp>(de ldapsearch (Sn)
(in
(list "ldapsearch" "-xH" "ldap://db.debian.org"
"-b" "dc=debian,dc=org"
(pack "sn=" Sn) )
(list
(cons 'cn (prog (from "cn: ") (line T)))
(cons 'uid (prog (from "uid: ") (line T))) ) ) )</lang>
Test:
<pre>: (ldapsearch "Fischer")
-> ((cn . "Mika") (uid . "mf"))</pre>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
Line 508: Line 465:
l.unbind()
l.unbind()
</lang>
</lang>

=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>#!/usr/bin/env perl6

# 20190718 Perl 6 programming solution
# https://github.com/perl6/doc/issues/2898
# https://www.facebook.com/groups/perl6/permalink/2379873082279037/

# Reference:
# https://github.com/Altai-man/cro-ldap
# https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

use v6.d;
use Cro::LDAP::Client;

my $client = await Cro::LDAP::Client.connect('ldap://ldap.forumsys.com');

my $bind = await $client.bind(
name=>'cn=read-only-admin,dc=example,dc=com',password=>'password'
);
die $bind.error-message if $bind.result-code;

my $resp = $client.search(
:dn<dc=example,dc=com>, base=>"ou=mathematicians", filter=>'(&(uid=gauss))'
);

react {
whenever $resp -> $entry {
for $entry.attributes.kv -> $k, $v {
my $value-str = $v ~~ Blob ?? $v.decode !! $v.map(*.decode);
note "$k -> $value-str";
}
}
}</lang>
{{out}}
<pre>objectClass -> inetOrgPerson organizationalPerson top person
mail -> gauss@ldap.forumsys.com
uid -> gauss
cn -> Carl Friedrich Gauss
sn -> Gauss
</pre>


=={{header|REXX}}==
=={{header|REXX}}==
Line 751: Line 750:


}</lang>
}</lang>

=={{header|Tcl}}==
=={{header|Tcl}}==
One can do it with the low level [[Connect to Active Directory]] based handle with this code:
One can do it with the low level [[Connect to Active Directory]] based handle with this code: