00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "stdafx.h"
00034 #include "ldapauth_plus.h"
00035 #include "ConfigLDAP.h"
00036 #include ".\configldap.h"
00037
00038
00039
00040
00041 IMPLEMENT_DYNAMIC(CConfigLDAP, CDialog)
00042 CConfigLDAP::CConfigLDAP(CWnd* pParent )
00043 : CDialog(CConfigLDAP::IDD, pParent)
00044 , m_server(_T(""))
00045 , m_ldapPrePend(_T(""))
00046 , m_ldapAppend(_T(""))
00047 , m_ldapAdminUsername(_T(""))
00048 , m_ldapAdminPassword(_T(""))
00049 , m_useSSL(FALSE)
00050 , m_port(_T(""))
00051 , m_timeout(_T(""))
00052 , m_ldapFilter(_T(""))
00053 , m_ldapGroupAttr(_T(""))
00054 , m_searchMode(FALSE)
00055 , m_multiMap(FALSE)
00056 , m_mapMode(FALSE)
00057 , m_newContext(_T(""))
00058 {
00059 CString temp;
00060 m_server = regReadString(L"ldapServer");
00061 m_ldapPrePend = regReadString(L"ldapPrePend");
00062 m_ldapAppend = regReadString(L"ldapAppend");
00063 m_ldapAdminUsername = regReadString(L"ldapAdminUsername");
00064 m_ldapAdminPassword = regReadString(L"ldapAdminPassword");
00065 m_port = regReadString(L"ldapPort");
00066 m_timeout.Format(L"%d",regReadDword(L"ldapTimeout"));
00067 m_ldapFilter = regReadString(L"ldapFilter");
00068 m_ldapGroupAttr = regReadString(L"ldapGroupAttr");
00069
00070 temp = regReadString(L"useSSL");
00071 if(temp.GetAt(0) == '1')
00072 m_useSSL = true;
00073 else
00074 m_useSSL = false;
00075
00076 temp = regReadString(L"ldapMethod");
00077 if(temp.GetAt(0) == '1') {
00078 m_multiMap = true;
00079 }
00080 else if(temp.GetAt(0) == '2') {
00081 m_searchMode = true;
00082 }
00083 else if(temp.GetAt(0) == '3') {
00084 m_mapMode = true;
00085 }
00086
00087 hasLoaded = false;
00088 }
00089
00090 BOOL CConfigLDAP::OnInitDialog()
00091 {
00092 CString temp;
00093 CDialog::OnInitDialog();
00094
00095 temp = regReadString(L"ldapMethod");
00096 if(temp.GetAt(0) == '1') {
00097 m_multiMap = true;
00098 c_ldapAppend.EnableWindow (false);
00099 c_ldapPrePend.EnableWindow (false);
00100
00101
00102 m_ContextList.EnableWindow (true);
00103 c_newcontext.EnableWindow(true);
00104 c_addcontext.EnableWindow(true);
00105 c_delcontext.EnableWindow(true);
00106 c_upcontext.EnableWindow(true);
00107 c_downcontext.EnableWindow(true);
00108 }
00109 else if(temp.GetAt(0) == '2') {
00110 m_searchMode = true;
00111 c_ldapAppend.EnableWindow (false);
00112 c_ldapPrePend.EnableWindow (false);
00113
00114
00115 m_ContextList.EnableWindow (true);
00116 c_newcontext.EnableWindow(true);
00117 c_addcontext.EnableWindow(true);
00118 c_delcontext.EnableWindow(true);
00119 c_upcontext.EnableWindow(true);
00120 c_downcontext.EnableWindow(true);
00121 }
00122 else if(temp.GetAt(0) == '3') {
00123 m_mapMode = true;
00124 c_ldapAppend.EnableWindow (true);
00125 c_ldapPrePend.EnableWindow (true);
00126
00127
00128 m_ContextList.EnableWindow (false);
00129 c_newcontext.EnableWindow(false);
00130 c_addcontext.EnableWindow(false);
00131 c_delcontext.EnableWindow(false);
00132 c_upcontext.EnableWindow(false);
00133 c_downcontext.EnableWindow(false);
00134 }
00135
00136 return TRUE;
00137
00138 }
00139
00140 CConfigLDAP::~CConfigLDAP()
00141 {
00142
00143 }
00144
00145 void CConfigLDAP::DoDataExchange(CDataExchange* pDX)
00146 {
00147 CDialog::DoDataExchange(pDX);
00148 DDX_Text(pDX, IDC_LDAPSERVER, m_server);
00149 DDX_Text(pDX, IDC_LDAPPREPEND, m_ldapPrePend);
00150 DDX_Text(pDX, IDC_LDAPAPPEND, m_ldapAppend);
00151 DDX_Text(pDX, IDC_ADMINUSERNAME, m_ldapAdminUsername);
00152 DDX_Text(pDX, IDC_ADMINPASSWORD, m_ldapAdminPassword);
00153 DDX_Check(pDX, IDC_USESSL, m_useSSL);
00154 DDX_Text(pDX, IDC_PORT, m_port);
00155 DDX_Text(pDX, IDC_LDAPFILTER, m_ldapFilter);
00156 DDX_Text(pDX, IDC_LDAPGROUPATTR, m_ldapGroupAttr);
00157 DDX_Check(pDX, IDC_SEARCH, m_searchMode);
00158 DDX_Check(pDX, IDC_MULTIMAP, m_multiMap);
00159 DDX_Check(pDX, IDC_MAP, m_mapMode);
00160 DDX_Control(pDX, IDC_CONTEXTLIST, m_ContextList);
00161 DDX_Text(pDX, IDC_NEWCONTEXT, m_newContext);
00162 DDX_Text(pDX, IDC_TIMEOUT, m_timeout);
00163
00164 if(!hasLoaded)
00165 {
00166 loadListsFromReg();
00167 hasLoaded = true;
00168 }
00169
00170 DDX_Control(pDX, IDC_LDAPPREPEND, c_ldapPrePend);
00171 DDX_Control(pDX, IDC_LDAPAPPEND, c_ldapAppend);
00172 DDX_Control(pDX, IDC_NEWCONTEXT, c_newcontext);
00173 DDX_Control(pDX, IDC_ADDCONTEXTBUTTON, c_addcontext);
00174 DDX_Control(pDX, IDC_DELCONTEXTBUTTON, c_delcontext);
00175 DDX_Control(pDX, IDC_MOVECTXUP, c_upcontext);
00176 DDX_Control(pDX, IDC_MOVECTXDWN, c_downcontext);
00177 DDX_Control(pDX, IDC_USESSL, c_usessl);
00178 }
00179
00180
00181 BEGIN_MESSAGE_MAP(CConfigLDAP, CDialog)
00182 ON_BN_CLICKED(IDC_ADDCONTEXTBUTTON, OnAddContext)
00183 ON_BN_CLICKED(IDC_DELCONTEXTBUTTON, OnRemoveContext)
00184 ON_BN_CLICKED(IDC_MOVECTXUP, OnMoveContextUp)
00185 ON_BN_CLICKED(IDC_MOVECTXDWN, OnMoveContextDown)
00186 ON_BN_CLICKED(IDC_SEARCH, OnChangeSearch)
00187 ON_BN_CLICKED(IDC_MULTIMAP, OnChangeMultimap)
00188 ON_BN_CLICKED(IDC_MAP, OnChangeMapMode)
00189 ON_EN_CHANGE(IDC_LDAPFILTER, OnEnChangeLdapfilter)
00190 END_MESSAGE_MAP()
00191
00192
00193
00194
00195 void CConfigLDAP::OnOK()
00196 {
00197 return;
00198 }
00199
00200 void CConfigLDAP::OnAddContext()
00201 {
00202
00203 UpdateData(TRUE);
00204 if (m_newContext == "") {
00205 MessageBox(L"Please enter a valid context.", L"LDAPAuth", MB_OK);
00206 return;
00207 }
00208 m_ContextList.AddString(m_newContext);
00209 m_newContext = TEXT("");
00210 UpdateData(FALSE);
00211 }
00212
00213 void CConfigLDAP::OnRemoveContext()
00214 {
00215
00216 if(m_ContextList.GetCurSel() >= 0)
00217 m_ContextList.DeleteString(m_ContextList.GetCurSel());
00218 }
00219
00220 void CConfigLDAP::OnMoveContextUp()
00221 {
00222
00223 UpdateData(TRUE);
00224
00225 if(m_ContextList.GetCurSel() > 0)
00226 swapItem(&m_ContextList,m_ContextList.GetCurSel(),m_ContextList.GetCurSel() - 1);
00227
00228 UpdateData(FALSE);
00229 }
00230
00231 void CConfigLDAP::OnMoveContextDown()
00232 {
00233
00234 UpdateData(TRUE);
00235
00236 if(m_ContextList.GetCurSel() >= 0 && m_ContextList.GetCurSel() < m_ContextList.GetCount() - 1)
00237 swapItem(&m_ContextList,m_ContextList.GetCurSel(),m_ContextList.GetCurSel() + 1);
00238
00239 UpdateData(FALSE);
00240 }
00241
00242 void CConfigLDAP::OnChangeSearch()
00243 {
00244
00245
00246
00247
00248 UpdateData(TRUE);
00249 if(m_searchMode)
00250 {
00251 m_multiMap = false;
00252 m_mapMode = false;
00253
00254
00255 c_ldapAppend.EnableWindow (false);
00256 c_ldapPrePend.EnableWindow (false);
00257
00258 m_ContextList.EnableWindow (true);
00259 c_newcontext.EnableWindow(true);
00260 c_addcontext.EnableWindow(true);
00261 c_delcontext.EnableWindow(true);
00262 c_upcontext.EnableWindow(true);
00263 c_downcontext.EnableWindow(true);
00264 }
00265 if(!m_searchMode)
00266 m_searchMode = true;
00267 UpdateData(FALSE);
00268 }
00269
00270 void CConfigLDAP::OnChangeMultimap()
00271 {
00272
00273 UpdateData(TRUE);
00274 if(m_multiMap)
00275 {
00276 m_searchMode = false;
00277 m_mapMode = false;
00278
00279
00280 c_ldapAppend.EnableWindow (false);
00281 c_ldapPrePend.EnableWindow (true);
00282
00283 m_ContextList.EnableWindow (true);
00284 c_newcontext.EnableWindow(true);
00285 c_addcontext.EnableWindow(true);
00286 c_delcontext.EnableWindow(true);
00287 c_upcontext.EnableWindow(true);
00288 c_downcontext.EnableWindow(true);
00289 }
00290 if(!m_multiMap)
00291 m_multiMap = true;
00292
00293 UpdateData(FALSE);
00294 }
00295
00296 void CConfigLDAP::OnChangeMapMode()
00297 {
00298
00299 UpdateData(TRUE);
00300 if(m_mapMode)
00301 {
00302 m_searchMode = false;
00303 m_multiMap = false;
00304
00305
00306 c_ldapAppend.EnableWindow (true);
00307 c_ldapPrePend.EnableWindow (true);
00308
00309 m_ContextList.EnableWindow (false);
00310 c_newcontext.EnableWindow(false);
00311 c_addcontext.EnableWindow(false);
00312 c_delcontext.EnableWindow(false);
00313 c_upcontext.EnableWindow(false);
00314 c_downcontext.EnableWindow(false);
00315 }
00316 if(!m_mapMode)
00317 m_mapMode = true;
00318
00319 UpdateData(FALSE);
00320 }
00321
00322 void CConfigLDAP::OnSave()
00323 {
00324 UpdateData(TRUE);
00325
00326
00327 CString temp;
00328
00329 if(m_server.GetLength() > 0)
00330 regWriteString(m_server.GetBuffer(m_server.GetLength()),L"ldapServer");
00331 else
00332 regDelValue(L"ldapServer");
00333
00334 if(m_ldapPrePend.GetLength() > 0)
00335 regWriteString(m_ldapPrePend.GetBuffer(m_ldapPrePend.GetLength()),L"ldapPrePend");
00336 else
00337 regDelValue(L"ldapPrePend");
00338
00339 if(m_ldapAppend.GetLength() > 0)
00340 regWriteString(m_ldapAppend.GetBuffer(m_ldapAppend.GetLength()),L"ldapAppend");
00341 else
00342 regDelValue(L"ldapAppend");
00343
00344 if(m_ldapAdminUsername.GetLength() > 0)
00345 regWriteString(m_ldapAdminUsername.GetBuffer(m_ldapAdminUsername.GetLength()),L"ldapAdminUsername");
00346 else
00347 regDelValue(L"ldapAdminUsername");
00348
00349 if(m_ldapAdminPassword.GetLength() > 0)
00350 regWriteString(m_ldapAdminPassword.GetBuffer(m_ldapAdminPassword.GetLength()),L"ldapAdminPassword");
00351 else
00352 regDelValue(L"ldapAdminPassword");
00353
00354 if(m_port.GetLength() > 0)
00355 regWriteString(m_port.GetBuffer(m_port.GetLength()),L"ldapPort");
00356 else
00357 regDelValue(L"ldapPort");
00358
00359 if(m_timeout.GetLength() > 0)
00360 regWriteDword(_wtoi(m_timeout.GetBuffer(m_port.GetLength())),L"ldapTimeout");
00361 else
00362 regDelValue(L"ldapPort");
00363
00364 if(m_ldapFilter.GetLength() > 0)
00365 regWriteString(m_ldapFilter.GetBuffer(m_ldapFilter.GetLength()),L"ldapFilter");
00366 else
00367 regDelValue(L"ldapFilter");
00368
00369 if(m_ldapGroupAttr.GetLength() > 0)
00370 regWriteString(m_ldapGroupAttr.GetBuffer(m_ldapGroupAttr.GetLength()),L"ldapGroupAttr");
00371 else
00372 regDelValue(L"ldapGroupAttr");
00373
00374 if(m_useSSL)
00375 regWriteString(TEXT("1"),L"useSSL");
00376 else
00377 regWriteString(TEXT("0"),L"useSSL");
00378
00379 if(m_multiMap)
00380 regWriteString(TEXT("1"),L"ldapMethod");
00381
00382 if(m_searchMode)
00383 regWriteString(TEXT("2"),L"ldapMethod");
00384
00385 if(m_mapMode)
00386 regWriteString(TEXT("3"),L"ldapMethod");
00387
00388 saveListsToReg();
00389 }
00390
00391 void CConfigLDAP::loadListsFromReg(void)
00392 {
00393
00394 WCHAR currentName[256];
00395 int x = 0;
00396 CString contextValue = NULL;
00397
00398
00399 swprintf(currentName,TEXT("ldapContext%d"),x);
00400 contextValue = regReadString(currentName);
00401 while(contextValue.GetLength() > 0)
00402 {
00403 m_ContextList.AddString(contextValue);
00404 x++;
00405 swprintf(currentName,TEXT("ldapContext%d"),x);
00406 contextValue = regReadString(currentName);
00407 }
00408 }
00409
00410 void CConfigLDAP::saveListsToReg(void)
00411 {
00412 WCHAR currentName[256];
00413 CString value = NULL;
00414 int x = 0;
00415
00416
00417 for(x = 0; x < m_ContextList.GetCount(); x++)
00418 {
00419 m_ContextList.GetText(x,value);
00420 swprintf(currentName,TEXT("ldapContext%d"),x);
00421 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00422 }
00423
00424
00425 x = m_ContextList.GetCount();
00426 swprintf(currentName,TEXT("ldapContext%d"),x);
00427 value = regReadString(currentName);
00428
00429 while(value.GetLength() > 0)
00430 {
00431 regDelValue(currentName);
00432 x++;
00433 swprintf(currentName,TEXT("ldapContext%d"),x);
00434 value = regReadString(currentName);
00435 }
00436 }
00437
00438 void CConfigLDAP::swapItem(CListBox *listbox,int old, int next)
00439 {
00440 CString valueA;
00441 CString valueB;
00442
00443
00444 listbox->GetText(old,valueA);
00445 listbox->DeleteString(old);
00446 listbox->InsertString(next,valueA);
00447 listbox->SetCurSel(next);
00448 }
00449
00450 void CConfigLDAP::OnEnChangeLdapfilter()
00451 {
00452
00453
00454
00455
00456
00457
00458 }
00459
00460