How to get all the members in user group by using LDAP in Perl?

About LDAP:

LDAP stands for Lightweight Directory Access Protocol. It is usually used to fetch (and sometimes update) data in a directory of people.

Using Net::LDAP module in Perl can provide a way to interact with this database.

Perl script to get this:

#! /usr/bin/perl

# Owner: Rebecca

# Creation date: 2014-12-29

# Usage:

# ./script.pl > yourfile.scv

use strict;

use Win32;

use Win32::OLE;

use Net::LDAP;

use warnings;

sub getmembersingroup

{

(my $subldap, my $groupname) = @_;

#************************************Get distinguished name by using group name*****************************************

my $mesg = $subldap->search(

base => "dc=global,dc=ds,dc=company,dc=com",

filter => "(&(CN=".$groupname."))",

);

if($mesg->code)

{

print $mesg->error, "\n";

exit;

}

my @entries = $mesg->entries;

my $distinguishedName;

foreach my $entry(@entries)

{

$distinguishedName = $entry->get_value("distinguishedName");

}

#**********************Get members by using the newly got distinguished Name*********************************************

$mesg = $subldap->search(

base => $distinguishedName,

scope => "sub",

filter => "(&(objectClass=*))",

);

@entries = $mesg->entries;

my $entry;

foreach $entry(@entries)

{

my @member = $entry->get_value("member");

foreach (@member)

{

my $line = $_;

my $para = $line;

my $string_dl = "OU=Distribution Lists";

$line =~ /DC=(.*?),/;

my $str_domain = $1;

if (!/$string_dl/)

{

#--------------get the account name and domain name---------------------

my $str_obj = Win32::OLE->GetObject("LDAP://".$para) or die "[email protected]";

my $status_able = "disabled";

if ($str_obj->{accountdisabled} eq 0)

{

$status_able = "enabled";

}

$str_obj->{displayName} =~ s/\,//g; # remove the , in the name

print "$str_obj->{displayName},$str_obj->{sAMAccountName},$str_domain,$status_able \n" ;

}

else

{

#it is a DL need to get the members inside

$line = ~/CN=(.*?),/;

my $sub_group_name = $1;

&getmembersingroup($subldap,$sub_group_name);

}

}

}

}

my $ldap = Net::LDAP->new(‘global.ds.company.com‘) or die "[email protected]";

my $mesg = $ldap->bind(‘[email protected]‘,password =>"youraccountpassword");

if($mesg->code)

{

print $mesg->error, "\n";

}

&getmembersingroup($ldap, "GroupName");

时间: 2024-08-13 01:00:20

How to get all the members in user group by using LDAP in Perl?的相关文章

20、oracle用户管理恢复

下面会一一讲解控制文件.redo文件及非归档模式.归档模式数据文件丢失的情况下,如何恢复数据? (1)控制文件(controlfile)丢失 在做恢复实验之前,先备份好数据. 案例1.模拟一个控制文件丢失 select name from v$controlfile; SQL> select name from v$controlfile; NAME -------------------------------------------------------------------------

POJ 1611 The Suspects (并查集)

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 25130   Accepted: 12313 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. T

并查集 P - The Suspects

Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others. In the Not-Sprea

POJ--1611 The Suspects

Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others.  In the Not-Spre

The Suspects POJ1611

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 36417   Accepted: 17681 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. T

CentOS6.8中openvpn联动windows ldap做认证

使用 LDAP 的方式认证 1.实际上也有二种 一种用 openvpn-auth-ldap 即直接通过 LDAP 验证, 一种与 mysql 认证相似使用 pam-ldap -->通过 PAM -->然后再找 LDAP 验证. 这里主要用 openvpn-auth-ldap (另一方法,安装 yum install nss_ldap 包后找文件 /usr/local/etc/auth-ldap.conf 复制 /usr/share/doc/nss_ldap_253/ldap.conf.pam_

7 C++ Boost 序列化

1,关于序列化.png 2,关于序列化.png 3,关于序列化.png 将结构体写入文件 name存在空格,C++的序列化相当的脆弱 C++ 序列化 二进制版 C风格的 序列化,总是正常的 boost 序列化C风格 写入到文件simple boost 序列化C++风格 写入到文件simple  boost 序列化从文件中读取 非侵入式的 boost序列化 缺点:所有的成员必须是public 可序列化的成员 派生类的序列化,问题引出,父类的成员增删对序列化有影响.耦合度太高 派生类的序列化 问题解

Git服务器的Gitosis安装配置及gitignore的使用方法

Git服务器Gitosis安装设置 1.安装 openssh服务器 sudo apt-get install openssh-server openssh-client 2.创建个人公钥和私钥 在默认用户的主目录路径下,运行以下命令,按照提示创建公钥和私钥 ssh-keygen -t rsa 默认生成2048位,如果需要提高安全级别,也可以通过下面的命令创建公钥和私钥 ssh-keygen -t rsa -b 4096 默认情况下,公钥和私钥会保存在~/.ssh目录下,如下所示: id_rsa

OCP-V13-003

QUESTION 3 Your database is in ARCHIVELOG mode. You have two online redo log groups, each of which contains one redo member. When you attempt to start the database, you receive the following errors: ORA-00313: open failed for members of log group 1 o