私は自分のオフィスで小さなアプリケーションを書いています。このアプリケーションでは、完全な UserName を取得する必要があります。Qt / C++で書かれています
LDAP 経由でこの情報を取得したいと考えています。これで、Active Directory サーバーに接続し、検索機能に接続できるようになりました。
この情報は、Microsoft が作成した例からのものです。
しかし、この時点で、例は私を混乱させます。このサーバーにユーザー名を付けてフルネームを受け取る方法がわかりません。
Microsoft の例へのリンク: http://msdn.microsoft.com/en-us/library/windows/desktop/aa367016(v=vs.85).aspx
この情報を入手する方法を教えてください。
ありがとう、よろしくクリス ;)
PS下手な英語でごめんなさい。PSS と、何かを見逃した場合、またはさらに情報が必要な場合は、それを言ってください。
LDAP_query.cpp:
#include <settings.h>
#include <ui_settings.h>
#include <mainwindow.h>
#include <ui_mainwindow.h>
#include <QtGui>
#include <QString>
//Header Files for LDAP Query
#include <windows.h>
#include <winldap.h>
#include <winber.h>
#include <rpc.h>
#include <rpcdce.h>
#include <stdio.h>
void MainWindow::LDAP_query(QString name)
{
//Name contains the username
PWCHAR hostName = NULL;
PWCHAR Domain = NULL;
PWCHAR pMyDN = NULL;
PWCHAR pUserName;
PWCHAR pPassword;
LDAP* pLdapConnection = NULL;
ULONG version = LDAP_VERSION3;
ULONG getOptSuccess = 0;
ULONG connectSuccess = 0;
INT returnCode = 0;
// Convert String hostname to a wchar_t*
char *hostName_2 = "Server.office.com";
QString Test = QString::fromAscii(hostName_2);
hostName = (WCHAR*)(Test.utf16());
//Connverting Char to WCHAR to connect to Directory
char *pMyDN_2 = "Ou=directory,Dc=Name,DC=office";
QString test2 = QString::fromAscii(pMyDN_2);
pMyDN = (WCHAR*)(test2.utf16());
//Open Connection
pLdapConnection = ldap_init(hostName, LDAP_PORT);
//Setting Connection Parm's
ldap_set_option(pLdapConnection, LDAP_OPT_PROTOCOL_VERSION, (void*)&version);
ldap_connect(pLdapConnection, NULL);
returnCode = ldap_bind_s(pLdapConnection, pMyDN, NULL, LDAP_AUTH_NEGOTIATE);
if(returnCode == LDAP_SUCCESS)
{
ui->InputA->setText("Connection sucessfull");
}
else
{
ui->InputA->setText("Connection unsucessfull");
}
//Variables for Search Results
LDAPMessage* pSearchResult;
PWCHAR pMyFilter = NULL;
char *pMyFilter_2 = "(&(objectCategory=person)(objectClass=user))";
QString Test7 = QString::fromAscii(pMyFilter_2);
pMyFilter = (WCHAR*)(Test7.utf16());
PWCHAR pMyAttributes[6];
ULONG errorCode = LDAP_SUCCESS;
pMyAttributes[0] = (WCHAR*)QString("cn").utf16();
pMyAttributes[1] = (WCHAR*)QString("company").utf16();
pMyAttributes[2] = (WCHAR*)QString("department").utf16();
pMyAttributes[3] = (WCHAR*)QString("telephoneNumber").utf16();
pMyAttributes[4] = (WCHAR*)QString("memberOf").utf16();
pMyAttributes[5] = NULL;
errorCode = ldap_search_s(
pLdapConnection, // Session handle
pMyDN, // DN to start search
LDAP_SCOPE_SUBTREE, // Scope
pMyFilter, // Filter
pMyAttributes, // Retrieve list of attributes
0, // Get both attributes and values
&pSearchResult); // [out] Search results
if (errorCode != LDAP_SUCCESS)
{
ui->InputB->setText("ldap_search_s failed with");
ldap_unbind_s(pLdapConnection);
if(pSearchResult != NULL)
ldap_msgfree(pSearchResult);
}
else
ui->InputB->setText("ldap_search succeeded \n");
//here i like to receive the user's full name
//Closing Connection
ldap_unbind(pLdapConnection);
ui->Test_Ausgabe -> setText(name);
}