#include #include "CAcctP.h" #include "AccntWiz.h" #include #include #include #include #include #include BYTE g_ASCII128[128] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00-0F 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 10-1F 0,1,0,1,1,1,1,1,1,1,0,0,0,1,1,0, // 20-2F 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, // 30-3F 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 40-4F 1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1, // 50-5F 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 60-6F 1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1 // 70-7F }; BOOL ValidChar( TCHAR pszInput, BOOL bPOP3 ) { if( pszInput > 127 ) return !bPOP3; if( pszInput < 0) return FALSE; if( g_ASCII128[pszInput] == 1 ) return TRUE; return FALSE; } BOOL ValidString( LPCTSTR pszInput, BOOL bPOP3 ) { if( !pszInput ) return FALSE; for( int i = 0; i < _tcslen(pszInput); i++ ) { if( !ValidChar(pszInput[i], bPOP3) ) return FALSE; } return TRUE; } // -------------------------------------------------------------------------------------------------------------------------------- // CAcctPage class // -------------------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Constructor // ---------------------------------------------------------------------------- CAcctPage::CAcctPage (CAddUser_AccntWiz * pASW) : m_csUserOU(), m_csFirstName(), m_csLastName(), m_csTelephone(), m_csOffice(), m_csUName(), m_csUNamePre2k(), m_csUserCN(), m_csAlias() { m_pASW = pASW; m_psp.dwFlags |= PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE; m_psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_ACCT_INFO_TITLE); m_psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_ACCT_INFO_SUBTITLE); // Defaults m_fInit = TRUE; m_fSimpleMode = TRUE; m_bPOP3Installed = FALSE; m_bCreatePOP3MB = TRUE; m_bPOP3Valid = FALSE; m_dwAutoMode = 0; } // ---------------------------------------------------------------------------- // Destructor // ---------------------------------------------------------------------------- CAcctPage::~CAcctPage() { } // ---------------------------------------------------------------------------- // OnDestroy() // ---------------------------------------------------------------------------- LRESULT CAcctPage::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { // Detach all of our controls from the windows. m_ctrlFirstName.Detach(); m_ctrlLastName.Detach(); m_ctrlTelephone.Detach(); m_ctrlOffice.Detach(); m_ctrlUName.Detach(); m_ctrlUNameLoc.Detach(); m_ctrlUNamePre2k.Detach(); m_ctrlUNamePre2kLoc.Detach(); m_ctrlAlias.Detach(); return 0; } // ---------------------------------------------------------------------------- // OnInitDialog() // ---------------------------------------------------------------------------- LRESULT CAcctPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { // ------------------------------------------------------------------------ // Attach controls. // ------------------------------------------------------------------------ m_ctrlFirstName.Attach ( GetDlgItem(IDC_FIRST_NAME) ); m_ctrlLastName.Attach ( GetDlgItem(IDC_LAST_NAME) ); m_ctrlTelephone.Attach ( GetDlgItem(IDC_TELEPHONE) ); m_ctrlOffice.Attach ( GetDlgItem(IDC_OFFICE) ); m_ctrlUName.Attach ( GetDlgItem(IDC_UNAME) ); m_ctrlUNameLoc.Attach ( GetDlgItem(IDC_UNAME_LOC) ); m_ctrlUNamePre2k.Attach ( GetDlgItem(IDC_UNAME_PRE2K) ); m_ctrlUNamePre2kLoc.Attach ( GetDlgItem(IDC_UNAME_PRE2K_LOC) ); m_ctrlAlias.Attach ( GetDlgItem(IDC_EMAIL_ALIAS) ); HWND hWndAlias = GetDlgItem(IDC_EMAIL_ALIAS); if( hWndAlias && ::IsWindow( hWndAlias ) ) { m_ctrlImplAlias.SubclassWindow( hWndAlias ); } // ------------------------------------------------------------------------ // Other Stuff! :) // ------------------------------------------------------------------------ m_ctrlFirstName.SetLimitText ( 28 ); m_ctrlLastName.SetLimitText ( 29 ); m_ctrlUNamePre2k.SetLimitText( 20 ); m_ctrlTelephone.SetLimitText ( 32 ); m_ctrlOffice.SetLimitText ( 128 ); m_ctrlAlias.SetLimitText ( 64 ); return(0); } // ---------------------------------------------------------------------------- // Init() // // Initializes the controls on the page with the values from the property bag. // NOTE: This is called from OnSetActive(), but only on the first SetActive. // This is because even though the control attaching could be done in // the WM_INITDIALOG handler, setting the values of the controls from // the values read from the property bag can only safely be done in the // PSN_SETACTIVE. // ---------------------------------------------------------------------------- LRESULT CAcctPage::Init (void) { CString csDns = L""; CString csNetbios = L""; TCHAR *szPath = NULL; TCHAR *szTok = NULL; DWORD dwErr = 0; PDOMAIN_CONTROLLER_INFO pDCInfo = NULL; ULONG ulGetDcFlags = DS_DIRECTORY_SERVICE_REQUIRED | DS_IP_REQUIRED | DS_WRITABLE_REQUIRED | DS_RETURN_FLAT_NAME; // ------------------------------------------------------------------------ // Get the special values to put in the windows. // ------------------------------------------------------------------------ // DNS Name TCHAR szTmp[MAX_PATH*2] = {0}; LdapToDCName((LPCTSTR)m_csUserOU, szTmp, (MAX_PATH*2)); csDns = szTmp; m_csLogonDns = L"@" + csDns; // Pre-Windows2000 DNS name dwErr = DsGetDcName(NULL, (LPCWSTR)csDns, NULL, NULL, ulGetDcFlags, &pDCInfo); if( (dwErr == NO_ERROR) && pDCInfo ) { csNetbios = pDCInfo->DomainName; // Get the NT4 DNS name. } NetApiBufferFree(pDCInfo); // Free up the memory DsGetDcName() might have allocated. pDCInfo = NULL; if( dwErr != NO_ERROR ) // If there was a problem, try again. { ulGetDcFlags |= DS_FORCE_REDISCOVERY; dwErr = DsGetDcName(NULL, (LPCWSTR)csDns, NULL, NULL, ulGetDcFlags, &pDCInfo); if( (dwErr == NO_ERROR) && pDCInfo ) { csNetbios = pDCInfo->DomainName; // Get the NT4 DNS name. } NetApiBufferFree(pDCInfo); // Free up the memory DsGetDcName() might have allocated. pDCInfo = NULL; } csNetbios += L"\\"; // Covert from TEST to TEST\ // ------------------------------------------------------------------------ // Set the windows' values. // ------------------------------------------------------------------------ m_ctrlFirstName.SetWindowText ( (LPCWSTR) m_csFirstName ); m_ctrlLastName.SetWindowText ( (LPCWSTR) m_csLastName ); m_ctrlTelephone.SetWindowText ( (LPCWSTR) m_csTelephone ); m_ctrlOffice.SetWindowText ( (LPCWSTR) m_csOffice ); m_ctrlAlias.SetWindowText ( (LPCWSTR) m_csAlias ); m_ctrlUName.SetWindowText ( (LPCWSTR) m_csUName ); m_ctrlUNamePre2k.SetWindowText ( (LPCWSTR) m_csUNamePre2k ); m_ctrlUNameLoc.SetWindowText ( (LPCWSTR) m_csLogonDns ); m_ctrlUNamePre2kLoc.SetWindowText ( (LPCWSTR) csNetbios ); // Needs to be done here... m_ctrlUName.LimitText( m_bPOP3Valid ? 20 : 64 ); ::EnableWindow( GetDlgItem(IDC_EMAIL_CHECKBOX), m_bPOP3Valid); if( m_bPOP3Installed ) { COMBOBOXINFO cbi; ZeroMemory( &cbi, sizeof(cbi) ); cbi.cbSize = sizeof(cbi); if( ::SendMessage( GetDlgItem(IDC_UNAME), CB_GETCOMBOBOXINFO, 0, (LPARAM)&cbi ) ) { // If we are in POP3 mode, our criteria is much more strict for the logon name m_ctrlImplUName.SubclassWindow( cbi.hwndItem ); } // Default the checkbox. CheckDlgButton( IDC_EMAIL_CHECKBOX, (m_bCreatePOP3MB ? BST_CHECKED : BST_UNCHECKED) ); } return 0; } // ---------------------------------------------------------------------------- // ReadProperties() // ---------------------------------------------------------------------------- HRESULT CAcctPage::ReadProperties( IPropertyPagePropertyBag* pPPPBag ) { HRESULT hr; BOOL fTmp = FALSE; // POP3 mailbox ReadBool ( pPPPBag, PROP_POP3_CREATE_MB_GUID_STRING, &m_bCreatePOP3MB, &fTmp ); ReadBool ( pPPPBag, PROP_POP3_VALID_GUID_STRING, &m_bPOP3Valid, &fTmp ); ReadBool ( pPPPBag, PROP_POP3_INSTALLED_GUID_STRING, &m_bPOP3Installed, &fTmp ); // User settings ReadString( pPPPBag, PROP_USEROU_GUID_STRING, m_csUserOU, &fTmp ); ReadString( pPPPBag, PROP_USER_CN, m_csUserCN, &fTmp ); ReadString( pPPPBag, PROP_FIRSTNAME_GUID_STRING, m_csFirstName, &fTmp ); ReadString( pPPPBag, PROP_LASTNAME_GUID_STRING, m_csLastName, &fTmp ); ReadString( pPPPBag, PROP_TELEPHONE_GUID_STRING, m_csTelephone, &fTmp ); ReadString( pPPPBag, PROP_OFFICE_GUID_STRING, m_csOffice, &fTmp ); ReadString( pPPPBag, PROP_EX_ALIAS_GUID_STRING, m_csAlias, &fTmp ); ReadString( pPPPBag, PROP_USERNAME_GUID_STRING, m_csUName, &fTmp ); ReadString( pPPPBag, PROP_USERNAME_PRE2K_GUID_STRING, m_csUNamePre2k, &fTmp ); // Wizard settings ReadInt4 ( pPPPBag, PROP_AUTOCOMPLETE_MODE, (LONG*)&m_dwAutoMode, &fTmp ); // Validate / fix up the values. m_csFirstName.TrimLeft(); m_csFirstName.TrimRight(); m_csLastName.TrimLeft(); m_csLastName.TrimRight(); m_csTelephone.TrimLeft(); m_csTelephone.TrimRight(); m_csOffice.TrimLeft(); m_csOffice.TrimRight(); m_csUName.TrimLeft(); m_csUName.TrimRight(); m_csUNamePre2k.TrimLeft(); m_csUNamePre2k.TrimRight(); if ( !_tcslen((LPCTSTR)m_csUserOU) ) { CString csDns = _T(""); PDOMAIN_CONTROLLER_INFO pDCI = NULL; DWORD dwErr = DsGetDcName(NULL, NULL, NULL, NULL, DS_DIRECTORY_SERVICE_REQUIRED | DS_RETURN_DNS_NAME, &pDCI); if ((dwErr == NO_ERROR) && pDCI ) { csDns = pDCI->DomainName; NetApiBufferFree (pDCI); pDCI = NULL; } tstring strTemp = GetDomainPath((LPCTSTR)csDns); m_csUserOU = L"LDAP://CN=Users,"; m_csUserOU += strTemp.c_str(); } return S_OK; } // ---------------------------------------------------------------------------- // WriteProperties() // ---------------------------------------------------------------------------- HRESULT CAcctPage::WriteProperties( IPropertyPagePropertyBag* pPPPBag ) { if ( !m_fInit ) // IF the page has already been initialized... { // Get the values from the edit boxes. m_csFirstName = StrGetWindowText( m_ctrlFirstName.m_hWnd ).c_str(); m_csLastName = StrGetWindowText( m_ctrlLastName.m_hWnd ).c_str(); m_csTelephone = StrGetWindowText( m_ctrlTelephone.m_hWnd ).c_str(); m_csOffice = StrGetWindowText( m_ctrlOffice.m_hWnd ).c_str(); m_csUName = StrGetWindowText( m_ctrlUName.m_hWnd ).c_str(); m_csUNamePre2k = StrGetWindowText( m_ctrlUNamePre2k.m_hWnd ).c_str(); m_csAlias = StrGetWindowText( m_ctrlAlias.m_hWnd ).c_str(); // Trim the strings m_csFirstName.TrimLeft ( ); m_csFirstName.TrimRight ( ); m_csLastName.TrimLeft ( ); m_csLastName.TrimRight ( ); m_csTelephone.TrimLeft ( ); m_csTelephone.TrimRight ( ); m_csOffice.TrimLeft ( ); m_csOffice.TrimRight ( ); m_csUName.TrimLeft ( ); m_csUName.TrimRight ( ); m_csUNamePre2k.TrimLeft ( ); m_csUNamePre2k.TrimRight( ); m_csAlias.TrimLeft ( ); m_csAlias.TrimRight ( ); } CString csUserCN; csUserCN.FormatMessage(IDS_FULLNAME_FORMAT_STR, (LPCTSTR)m_csFirstName, (LPCTSTR)m_csLastName); csUserCN = L"CN=" + csUserCN; // Write the values to the property bag. WriteString( pPPPBag, PROP_FIRSTNAME_GUID_STRING, m_csFirstName, FALSE ); WriteString( pPPPBag, PROP_LASTNAME_GUID_STRING, m_csLastName, FALSE ); WriteString( pPPPBag, PROP_USER_CN, m_csUserCN, FALSE ); WriteString( pPPPBag, PROP_TELEPHONE_GUID_STRING, m_csTelephone, FALSE ); WriteString( pPPPBag, PROP_OFFICE_GUID_STRING, m_csOffice, FALSE ); WriteString( pPPPBag, PROP_USERNAME_GUID_STRING, m_csUName, FALSE ); WriteString( pPPPBag, PROP_USERNAME_PRE2K_GUID_STRING, m_csUNamePre2k, FALSE ); WriteString( pPPPBag, PROP_LOGON_DNS, m_csLogonDns, FALSE ); WriteString( pPPPBag, PROP_EX_ALIAS_GUID_STRING, m_csAlias, FALSE ); WriteInt4 ( pPPPBag, PROP_AUTOCOMPLETE_MODE, m_dwAutoMode, FALSE ); WriteBool ( pPPPBag, PROP_POP3_CREATE_MB_GUID_STRING, m_bCreatePOP3MB, FALSE ); return S_OK; } // ---------------------------------------------------------------------------- // ProvideFinishText() // ---------------------------------------------------------------------------- HRESULT CAcctPage::ProvideFinishText( CString &str ) { if ( m_fInit ) return E_FAIL; TCHAR szTmp[1024+1] = {0}; // Get the values from the edit boxes. m_csFirstName = StrGetWindowText( m_ctrlFirstName.m_hWnd ).c_str(); m_csLastName = StrGetWindowText( m_ctrlLastName.m_hWnd ).c_str(); m_csTelephone = StrGetWindowText( m_ctrlTelephone.m_hWnd ).c_str(); m_csOffice = StrGetWindowText( m_ctrlOffice.m_hWnd ).c_str(); m_csUName = StrGetWindowText( m_ctrlUName.m_hWnd ).c_str(); m_csUNamePre2k = StrGetWindowText( m_ctrlUNamePre2k.m_hWnd ).c_str(); m_csAlias = StrGetWindowText( m_ctrlAlias.m_hWnd ).c_str(); m_csFirstName.TrimLeft(); m_csFirstName.TrimRight(); m_csLastName.TrimLeft(); m_csLastName.TrimRight(); m_csTelephone.TrimLeft(); m_csTelephone.TrimRight(); m_csOffice.TrimLeft(); m_csOffice.TrimRight(); m_csUName.TrimLeft(); m_csUName.TrimRight(); m_csUNamePre2k.TrimLeft(); m_csUNamePre2k.TrimRight(); m_csAlias.TrimLeft(); m_csAlias.TrimRight(); CString csTmp; CString csFinFullname; csFinFullname.FormatMessage(IDS_FULLNAME_FORMAT_STR, (LPCTSTR)m_csFirstName, (LPCTSTR)m_csLastName); csTmp.FormatMessage(IDS_FIN_FULLNAME, csFinFullname); str += csTmp; csTmp.FormatMessage(IDS_FIN_LOGONNAME, m_csUName); str += csTmp; if( m_bPOP3Valid && m_csAlias.GetLength() ) { CString csDomainName = m_csLogonDns; if( m_bCreatePOP3MB ) { // Get the first domain name from POP3 HRESULT hr = S_OK; CComPtr spConfig = NULL; CComPtr spDomains = NULL; CComPtr spDomain = NULL; CComVariant cVar; CComBSTR bstrDomainName; // Open our Pop3 Admin Interface hr = CoCreateInstance(__uuidof(P3Config), NULL, CLSCTX_ALL, __uuidof(IP3Config), (LPVOID*)&spConfig); if( SUCCEEDED(hr) ) { // Get the Domains hr = spConfig->get_Domains( &spDomains ); } if( SUCCEEDED(hr) ) { // Get the first domain cVar = 1; hr = spDomains->get_Item( cVar, &spDomain ); } if( SUCCEEDED(hr) ) { hr = spDomain->get_Name( &bstrDomainName ); } if( SUCCEEDED(hr) ) { csDomainName = _T("@"); csDomainName += bstrDomainName; } } CString csEmailName = m_csAlias + csDomainName; csTmp.FormatMessage(IDS_FIN_EXCHANGE, csEmailName); str += csTmp; } return S_OK; } // ---------------------------------------------------------------------------- // DeleteProperties() // ---------------------------------------------------------------------------- HRESULT CAcctPage::DeleteProperties( IPropertyPagePropertyBag* pPPPBag ) { return S_OK; } // ---------------------------------------------------------------------------- // OnChangeEdit() // ---------------------------------------------------------------------------- LRESULT CAcctPage::OnChangeEdit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { if ( !m_fInit ) // IF the page has already been initialized... { m_csFirstName = StrGetWindowText( m_ctrlFirstName.m_hWnd ).c_str(); m_csLastName = StrGetWindowText( m_ctrlLastName.m_hWnd ).c_str(); m_csFirstName.TrimLeft(); m_csFirstName.TrimRight(); m_csLastName.TrimLeft(); m_csLastName.TrimRight(); } // Update the Logon Name field (which will in turn update the PreWin2000 Name). TCHAR ch; INT iLen = 0; CString csFirstName = _T(""); CString csLastName = _T(""); CString csOut = _T(""); // Clear invalid characters out of both first and last name csFirstName = m_csFirstName; iLen = csFirstName.GetLength(); for ( INT i=0; i spConfig = NULL; CComPtr spDomains = NULL; CComPtr spDomain = NULL; CComPtr spUsers = NULL; CComPtr spUser = NULL; CComVariant cVar; CComBSTR bstrDomainName; // Open our Pop3 Admin Interface hr = CoCreateInstance(__uuidof(P3Config), NULL, CLSCTX_ALL, __uuidof(IP3Config), (LPVOID*)&spConfig); if( SUCCEEDED(hr) ) { // Get the Domains hr = spConfig->get_Domains( &spDomains ); } if( SUCCEEDED(hr) ) { // Get the first domain cVar = 1; hr = spDomains->get_Item( cVar, &spDomain ); } if( SUCCEEDED(hr) ) { // get the users from the domain hr = spDomain->get_Users( &spUsers ); } if( SUCCEEDED(hr) ) { // Try and get this users email name CComVariant varUserName = m_csAlias; hr = spUsers->get_Item( varUserName, &spUser ); } if( SUCCEEDED(hr) && spUser ) { // It's a duplicate, sorry! ErrorMsg(IDS_ERROR_POP3DUP, IDS_TITLE); m_ctrlUName.SetFocus(); m_ctrlUName.SetEditSel(0, -1); return(-1); } } return 0; // Go next. } BOOL CAcctPage::NextCheck(void) { if ( ( _tcslen((LPCTSTR)m_csUName ) ) && ( _tcslen((LPCTSTR)m_csUNamePre2k ) ) && ( _tcslen((LPCTSTR)m_csFirstName) || _tcslen((LPCTSTR)m_csLastName) ) ) { ::SendMessage( GetParent(), PSM_SETWIZBUTTONS, 0, PSWIZB_BACK | PSWIZB_NEXT ); return(TRUE); } ::SendMessage( GetParent(), PSM_SETWIZBUTTONS, 0, PSWIZB_BACK ); return(FALSE); } LRESULT CAcctPage::OnEmailClicked( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled ) { m_bCreatePOP3MB = (IsDlgButtonChecked(IDC_EMAIL_CHECKBOX) == BST_CHECKED); m_csAlias = _T(""); m_ctrlAlias.SetWindowText( m_csAlias ); OnChangeUName( wNotifyCode, wID, hWndCtl, bHandled ); return 0; }