随手写了一段C++访问LDAP, 并且获取sid的代码

本文分享了一段C++代码,用于访问LDAP并获取SID,代码虽然未经精细优化,但作为Demo可以正常运行,展示了基本的LDAP操作流程。
摘要由CSDN通过智能技术生成

直接上代码,获取sid,并且转换成字符串形式。没有仔细优化代码,这只能是一段demo代码,但是能跑成功。跟大家share一下。

// LDAPTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <windows.h>
#include "Winldap.h"
#include <Dsgetdc.h>
#include <Sddl.h>
#include <string>
#include <algorithm>
//#include <locale>

#define MAX_NAME 1024


std::string ConvertToStringSid(const unsigned char* bsid, const int len);
namespace myldap
{
    std::wstring LogInWithLdap(const std::wstring& strLdapServer, const std::wstring& strDomain, const std::wstring& strUserName, const std::wstring& strPwd)
    {
        const WCHAR* kSAMAccountName = L"sAMAccountName";
        const WCHAR* kObjectSid = L"objectSid";

        ULONG rt;

        LDAP* ld = ldap_initW((PWSTR)strLdapServer.c_str(), 0);
        rt = ldap_set_option(ld, LDAP_OPT_PROTOCOL_
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值