Active Directory/Search for a user: Difference between revisions

Added FreeBASIC
m (syntax highlighting fixup automation)
(Added FreeBASIC)
 
(3 intermediate revisions by 2 users not shown)
Line 1:
[[Category:Active Directory]]
{{task|Programming environment operations}}
 
Line 4 ⟶ 5:
 
=={{header|C}}==
<syntaxhighlight lang=C"c">#include <ldap.h>
 
char *name, *password;
Line 28 ⟶ 29:
=={{header|D}}==
Based on dopenldap.
<syntaxhighlight lang="d">
import openldap;
import std.stdio;
Line 63 ⟶ 64:
 
Moreover, strings in Eiffel are objects and cannot be directly passed to the Windows OS. As such, they need to undergo a format change through the facilities of a WEL_STRING, which makes the appropriate structure conversion.
<syntaxhighlight lang=Eiffel"eiffel">
feature -- Validation
 
Line 80 ⟶ 81:
Because Active Directory is a Windows OS facility, in Eiffel we must use the WEL (Windows Eiffel Library) components. Thus, the code above is not cross-platform. Moreover, the call to `cwel_is_credential_valid' is shown below:
 
<syntaxhighlight lang=Eiffel"eiffel">
cwel_is_credential_valid (a_domain, a_username, a_password: POINTER): BOOLEAN
external
Line 88 ⟶ 89:
end
</syntaxhighlight>
 
=={{header|FreeBASIC}}==
See [https://rosettacode.org/wiki/Active_Directory/Connect#FreeBASIC Active_Directory/Connect#FreeBASIC]
 
=={{header|Go}}==
Line 93 ⟶ 97:
<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.
<syntaxhighlight lang="go">package main
 
import (
Line 123 ⟶ 127:
Example uses the [https://hackage.haskell.org/package/ldap-client <tt>ldap-client</tt>] package:
 
<syntaxhighlight lang="haskell">{-# LANGUAGE OverloadedStrings #-}
 
module Main (main) where
Line 143 ⟶ 147:
The following code uses the Apache Directory project, version 1.0.0.
 
<syntaxhighlight lang="java">import java.io.IOException;
import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.cursor.EntryCursor;
Line 183 ⟶ 187:
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using LDAPClient
 
function searchLDAPusers(searchstring, uname, pword, host=["example", "com"])
Line 208 ⟶ 212:
=={{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.
<syntaxhighlight lang=NetRexx"netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
 
Line 348 ⟶ 352:
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.
 
<syntaxhighlight lang=ooRexx"oorexx">/* Rexx */
do
LDAP_URL = 'ldap://localhost:11389'
Line 419 ⟶ 423:
=={{header|Perl}}==
{{Trans|Raku}}
<syntaxhighlight lang="perl"># 20210306 Perl programming solution
 
use strict;
Line 458 ⟶ 462:
=={{header|Phix}}==
{{trans|C}}
<!--<syntaxhighlight lang=Phix"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>
Line 496 ⟶ 500:
{{libheader|php-ldap}}
 
<syntaxhighlight lang="php"><?php
 
$l = ldap_connect('ldap.example.com');
Line 514 ⟶ 518:
 
=={{header|PicoLisp}}==
<syntaxhighlight lang=PicoLisp"picolisp">(de ldapsearch (Sn)
(in
(list "ldapsearch" "-xH" "ldap://db.debian.org"
Line 528 ⟶ 532:
=={{header|PowerShell}}==
 
<syntaxhighlight lang="python">
Import-Module ActiveDirectory
 
Line 545 ⟶ 549:
[http://www.python-ldap.org/doc/html/index.html python-ldap Documentation]
 
<syntaxhighlight lang="python">import ldap
 
l = ldap.initialize("ldap://ldap.example.com")
Line 567 ⟶ 571:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang=perl6"raku" line>
 
# 20190718 Raku programming solution
Line 613 ⟶ 617:
 
A little contrived; this [[REXX]] program drives the <tt>ldapsearch</tt> command.
<syntaxhighlight lang=REXX"rexx">/* Rexx */
do
LDAP_URL = 'ldap://localhost:11389'
Line 663 ⟶ 667:
 
{{libheader|RubyGems}}
<syntaxhighlight lang="ruby">require 'rubygems'
require 'net/ldap'
 
Line 685 ⟶ 689:
[rename] files
[view] image files</pre>
<syntaxhighlight lang="runbasic">' ---------------------------------------------
' Directory maintenance
' ---------------------------------------------
Line 813 ⟶ 817:
 
=={{header|Scala}}==
<syntaxhighlight lang=Scala"scala">import org.apache.directory.api.ldap.model.message.SearchScope
import org.apache.directory.ldap.client.api.{LdapConnection, LdapNetworkConnection}
 
Line 854 ⟶ 858:
 
This is just the basic setup.
<syntaxhighlight lang="tcl">set Username "TestUser"
set Filter "((&objectClass=*)(sAMAccountName=$Username))"
set Base "dc=skycityauckland,dc=sceg,dc=com"
Line 860 ⟶ 864:
 
Now do the actual search.
<syntaxhighlight lang="tcl">set result [ldap::search $conn $Base $Filter $Attrs -scope subtree]</syntaxhighlight>
If we have only a single result its easy:
<syntaxhighlight lang="tcl">if {[llength $result] == 1} {
puts [dict get [lindex $result 0 1] distinguishedName]
}</syntaxhighlight>
 
Looping over the result set to output some values.
<syntaxhighlight lang="tcl">foreach pair $result {
lassign $pair cn attributes
puts [dict get $attributes distinguishedName]
Line 874 ⟶ 878:
 
If you're bored you can also use this instead:
<syntaxhighlight lang="tcl">package require ldapx
set conn [ldapx::connect $BindDN $Password]
$conn traverse $Base $Filter $Attrs e {
Line 884 ⟶ 888:
 
A shell script to drive the <tt>ldapsearch</tt> command.
<syntaxhighlight lang="bash">#!/bin/sh
 
LDAP_HOST="localhost"
Line 923 ⟶ 927:
=={{header|VBScript}}==
The search string and execution of the string
<syntaxhighlight lang="vbscript">strUsername = "TestUser"
strQuery = "<LDAP://dc=skycityauckland,dc=sceg,dc=com>;"_
& "(&(objectclass=*)(samaccountname=" & strUsername & "));distinguishedname;subtree"
Line 932 ⟶ 936:
 
Doing something with a single result (this will output the returned users full DN)
<syntaxhighlight lang="vbscript">If objRS.RecordCount = 1 Then
WScript.Echo objRS.Fields("DistinguishedName")
End If</syntaxhighlight>
 
Doing something with multiple results (this will output each returned users full DN)
<syntaxhighlight lang="vbscript">If objRS.RecordCount > 0 Then
For Each objUser in ObjRS
WScript.Echo objRS.Fields("DistinguishedName")
Line 949 ⟶ 953:
 
Note that, in an actual case, one would need to wrap more LDAP functions to process the search results.
<syntaxhighlight lang=ecmascript"wren">/* active_directory_search_for_userActive_Directory_Search_for_a_user.wren */
 
var LDAP_SCOPE_SUBTREE = 0x0002
Line 1,002 ⟶ 1,006:
<br>
We now embed this in the following C program, compile and run it.
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
Line 1,129 ⟶ 1,133:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "active_directory_search_for_userActive_Directory_Search_for_a_user.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 1,147 ⟶ 1,151:
}</syntaxhighlight>
 
{{omit from|ACL2}}
{{omit from|AWK}}
Line 1,156 ⟶ 1,161:
{{omit from|Mathematica}}
{{omit from|Maxima}}
{{omit from|MIPS Assembly|None of the commonly used implementations can access AD functions}}
{{omit from|ML/I}}
{{omit from|MIPS Assembly|None of the commonly used implementations can access AD functions}}
{{omit from|PARI/GP}}
{{omit from|PostScript}}
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have network access. -->
{{omit from|Retro}}
{{omit from|TI-83 BASIC}}
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have network access. -->
{{omit from|Yorick|Does not have network access.}}
{{omit from|ZX Spectrum Basic|Does not have network access.}}
 
[[Category:Active Directory]]
2,122

edits