static void Main() { DCOMAuth.CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, (uint)DCOMAuth.RpcAuthnLevel.Connect, (uint)DCOMAuth.RpcImpLevel.Impersonate, IntPtr.Zero, (uint)DCOMAuth.EoAuthnCap.DynamicCloaking, IntPtr.Zero); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); }
private Int32 PerformAuthentication() { //is the target the same as last time? if (TargetHost.Equals(TargetTextBox.Text.Trim())) { //were already authenticated if ((WNetAuthRadioButton.Checked) && (isWNetAuthenticated == true)) { return(0); } if ((DCOMAuthRadioButton.Checked) && (isDCOMAuthenicated == true)) { return(0); } } else { isWNetAuthenticated = false; isDCOMAuthenicated = false; }//end of if-else (TargetHost.Equals(TargetTextBox.Text.Trim())) if ((WNetAuthRadioButton.Checked) && (isWNetAuthenticated == false)) { WNetAuth _wnetAuth = new WNetAuth(); WNetAuth.SMB_RESULT_CODE _Result = WNetAuth.SMB_RESULT_CODE.UNKNOWN; _Result = _wnetAuth.MapIPCDrive(DomainTextBox.Text, UsernameTextBox.Text, PasswordTextBox.Text, TargetTextBox.Text); if (_Result == WNetAuth.SMB_RESULT_CODE.AUTH_SUCCESS) { isWNetAuthenticated = true; return(0); } else { return((Int32)_Result); } } else if ((WNetAuthRadioButton.Checked) && (isWNetAuthenticated == true)) // are we already authenticated. { return(0); }//end of if-else ((WNetAuthRadioButton.Checked) && (isWNetAuthenticated == false)) if ((DCOMAuthRadioButton.Checked) && (isDCOMAuthenicated == false)) { DCOMAuth.LogOnProvider _LogonProvider = DCOMAuth.LogOnProvider.Default; DCOMAuth.LogOnType _LogonType = DCOMAuth.LogOnType.Network; switch (LogOnTypeComboBox.SelectedIndex) { case 0: _LogonType = DCOMAuth.LogOnType.None; break; case 1: _LogonType = DCOMAuth.LogOnType.Interactive; break; case 2: _LogonType = DCOMAuth.LogOnType.Network; break; case 3: _LogonType = DCOMAuth.LogOnType.Batch; break; case 4: _LogonType = DCOMAuth.LogOnType.Service; break; case 5: _LogonType = DCOMAuth.LogOnType.Unlock; break; case 6: _LogonType = DCOMAuth.LogOnType.NetworkClearText; break; case 7: _LogonType = DCOMAuth.LogOnType.NewCredentials; break; default: _LogonType = DCOMAuth.LogOnType.NewCredentials; // this option is required for remote auth so its the default. break; }//end of switch switch (LogonProviderCombo.SelectedIndex) { case 0: _LogonProvider = DCOMAuth.LogOnProvider.Default; break; case 1: _LogonProvider = DCOMAuth.LogOnProvider.WinNT40; break; case 2: _LogonProvider = DCOMAuth.LogOnProvider.WinNT50; break; case 3: _LogonProvider = DCOMAuth.LogOnProvider.Virtual; break; default: _LogonProvider = DCOMAuth.LogOnProvider.Default; break; } DCOMAuth _DCOMAuth = new DCOMAuth(); Int32 _Result = _DCOMAuth.Authenticate(UsernameTextBox.Text, PasswordTextBox.Text, DomainTextBox.Text, _LogonType, _LogonProvider); //did we auth ok? if (_Result == 0) { //we need to record the auth options just in case the change and we have to re-authenticate. this.LogOnTypeIndex = LogOnTypeComboBox.SelectedIndex; this.LogonProviderIndex = LogonProviderCombo.SelectedIndex; isDCOMAuthenicated = true; return(0); } else { return(_Result); }//end of if-else (_Result == 0) } else if ((DCOMAuthRadioButton.Checked) && (isDCOMAuthenicated == true)) // are we already authenticated? { //are the DCOM options the same as lasttime? if ((LogonProviderIndex == LogonProviderCombo.SelectedIndex) && (LogOnTypeIndex == LogOnTypeComboBox.SelectedIndex)) { return(0); } else // one of the options has changed so we need to re-authenticate { //we need to re-authenticate this.isDCOMAuthenicated = false; //recursivley call the auth method to go through the auth process again return(PerformAuthentication()); } }//end of if ((DCOMAuthRadioButton.Checked) && (isDCOMAuthenicated == false)) //default catch all return(-1); }