Ldap Auth
-
Hi, I'm developing a tool to show several graphs. But only the users that have been succesfully authentificated by LDAP should see those graphs. I'm developing with MFC+Visual Studio 2003. I'm not really sure how to do this. I've been reading for a while about LDAP but I'm not sure how to implement authentification by LDAP in my App. This is just a test I have done doing copy&paste from other code, but it always returns err=0x31.
LDAP* ld = NULL; INT iRtn = 0; INT connectSuccess = 0; PCHAR pHost = NULL; PCHAR userDN = NULL; PCHAR pw = NULL; ULONG version = LDAP_VERSION3; // SecPkgContext_ConnectionInfo sslInfo; LONG lv = 0; CString strDomain; CString strName; CString strPass; // Verify that the user passed a hostname. GetDlgItem(IDC_DOMAIN)->GetWindowText(strDomain); GetDlgItem(IDC_PASSWORD)->GetWindowText(strPass); GetDlgItem(IDC_NAME)->GetWindowText(strName); CString dn = "CN=" + strName +",DM=" + strDomain; // Create an LDAP session. ld = ldap_open(pHost,0); if (ld == NULL) GetDlgItem(IDC_EDIT4)->SetWindowText("ldap_open failed"); else { GetDlgItem(IDC_EDIT4)->SetWindowText("ldap_open OK"); ld->ld_lberoptions = 0; pw = new char [strPass.GetLength()+1]; strcpy (pw,(LPCTSTR)strPass); userDN = new char [dn.GetLength()+1]; strcpy (userDN,(LPCTSTR)dn); INT err = ldap_simple_bind_s( ld, userDN, pw ); CString error; error.Format("%d", err); GetDlgItem(IDC_EDIT4)->SetWindowText("simple bind returned " + error); } if (ld != NULL) ldap_unbind_s(ld); if(pHost!=NULL) delete pHost; if(userDN != NULL) delete userDN; if(pw != NULL) delete pw;
Regards and sorry for my poor english