/// <summary> /// Method will be called when we try to connect to Host from the ADUC Plugin /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cm_OnConnect(object sender, EventArgs e) { bool initialConnect = true; SelectDomainDialog domainDlg = null; while (true) { if (initialConnect) { domainDlg = new SelectDomainDialog(_hn.domainName, _hn.creds.UserName); if (domainDlg.ShowDialog() == DialogResult.OK) { _hn.domainName = domainDlg.GetDomain(); _hn.domainControllerName = domainDlg.GetDomainControllerName(); if (!domainDlg.UseDefaultUserCreds()) { _hn.creds.UserName = domainDlg.GetUsername(); _hn.creds.Password = domainDlg.GetPassword(); } } else { if (!_hn.IsConnectionSuccess) { _hn.domainControllerName = _hn.domainName = _hn.creds.UserName = _hn.creds.Password = ""; } break; // Connection dialog close on cancel } } if (!ConnectToDomain()) { if (!domainDlg.UseDefaultUserCreds()) { CredentialsDialog credsDialog = new CredentialsDialog(_hn.creds.UserName); if (credsDialog.ShowDialog(domainDlg) == DialogResult.OK) { _hn.creds.UserName = credsDialog.GetUsername(); _hn.creds.Password = credsDialog.GetPassword(); initialConnect = false; continue; } else { _hn.domainControllerName = _hn.domainName = _hn.creds.UserName = _hn.creds.Password = ""; break; // Connection dialog close on cancel } } else { MessageBox.Show("Failed to connect to domain. Please use the alternate credentials", "Likewise Administrative Console", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); } } else { break; } } }
private void cm_OnConnectToShare(object sender, EventArgs e) { WinError error = WinError.ERROR_SUCCESS; bool determinePath = true; bool initialConnect = false; bool showPathError = false; string username = null; string path = null; while (true) { if (determinePath) { // Determine share path to connect to ConnectToShareDialog connectDialog = new ConnectToShareDialog(path, showPathError); if (connectDialog.ShowDialog() == DialogResult.OK) { showPathError = false; determinePath = false; path = connectDialog.GetPath(); if (connectDialog.UseAlternateUserCreds()) { error = WinError.ERROR_ACCESS_DENIED; } else { initialConnect = true; } } else { break; } } if (initialConnect) { Application.UseWaitCursor = true; error = FileClient.FileClient.CreateConnection(path, null, null); Application.UseWaitCursor = false; initialConnect = false; } if (error == WinError.ERROR_SUCCESS) { // Refresh RemoteShares list and exit RemoteShares.Add(path); break; } if (error == WinError.ERROR_BAD_NET_NAME) { // Show share path connect dialog to allow the user to correct the bad path //MessageBox.Show("The network path is unavailable", "File connection error", MessageBoxButtons.OK, MessageBoxIcon.Error); showPathError = true; determinePath = true; continue; } if (error == WinError.ERROR_DOWNGRADE_DETECTED || error == WinError.ERROR_ACCESS_DENIED || error == WinError.ERROR_SESSION_CREDENTIAL_CONFLICT || error == WinError.ERROR_BAD_USERNAME || error == WinError.ERROR_INVALID_PASSWORD || error == WinError.ERROR_LOGON_TYPE_NOT_GRANTED) { // Prompt for updated user credentials to access share CredentialsDialog credDialog = new CredentialsDialog(username); if (credDialog.ShowDialog() == DialogResult.OK) { if (credDialog.UseDefaultUserCreds()) { initialConnect = true; username = null; continue; } username = credDialog.GetUsername(); Application.UseWaitCursor = true; error = FileClient.FileClient.CreateConnection(path, username, credDialog.GetPassword()); Application.UseWaitCursor = false; continue; } else { // Cancel Connect To attempt break; } } else { // Encounter unexpected error break; } } RefreshNetworkTreeNode(); Application.UseWaitCursor = false; }