GinaDLL2

本文介绍了一个Windows登录验证过程的实现细节,包括对话框创建、用户凭证获取、LSA登录用户调用及错误处理等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



  int WINAPI WlxLoggedOutSAS(PVOID pWlxContext, DWORD dwSasType, PLUID pAuthenticationId, PSID pLogonSid, PDWORD pdwOptions, PHANDLE phToken, PWLX_MPR_NOTIFY_INFO pNprNotifyInfo, PVOID *pProfile)
  {
  Clogin login;
  CString str;
  wchar_t pwszUser[255];
  wchar_t pwszDomain[255];
  wchar_t pwszPassword[255];
  //PGINA_CONTEXT pgContext = (PGINA_CONTEXT) pWlxContext;
  INT_PTR nRet = login.DoModal();
  // if we get this far, the login succeeded, but there are a few minor things that could still fail
  int action = WLX_SAS_ACTION_NONE;
  bool success = false;
  switch ( nRet )
  {
  case -1:
  AfxMessageBox(_T("Dialog box could not be created!"));
  return WLX_SAS_ACTION_NONE;
  break;
  case IDOK:
  theApp.MyUser=login.m_user;
  theApp.MyPass =login.m_pass;
  theApp.MyDomain =login.m_domain;
  if(theApp.MyDomain=="")theApp.MyDomain=".";
  wcscpy(pwszUser,theApp.MyUser);
  wcscpy(pwszPassword,theApp.MyPass);
  wcscpy(pwszDomain,theApp.MyDomain);
  ZeroMemory(pNprNotifyInfo, sizeof *pNprNotifyInfo);
  *pdwOptions = 0; // we always let WinLogon load the user profile for us
  *pProfile = 0; // simple kiosk example doesn't worry about custom profile paths
  if (WLX_SAS_TYPE_CTRL_ALT_DEL == dwSasType) {
  // attempt the login
  DWORD win32Error;
  MSV1_0_INTERACTIVE_PROFILE* pProfile = 0;
  if (!SecurityHelper::CallLsaLogonUser(theApp.hLsa,
  pwszDomain, pwszUser, pwszPassword,
  Interactive,
  pAuthenticationId, phToken,
  &pProfile, &win32Error)) {
  // as soon as we're done with the password, zero out the buffer
  // to reduce the window of time it's in memory as plaintext
  SecureZeroMemory(pwszPassword, lstrlen(pwszPassword) * sizeof *pwszPassword);
  // logon shouldn't fail at runtime, but if it does,
  // let somebody know instead of just cycling forever
  wchar_t msg[256];
  Log:ookupErrorMessage(msg, sizeof msg / sizeof *msg, win32Error);
  MessageBox(0, msg, L"Logon Message", MB_ICONEXCLAMATION);
  return WLX_SAS_ACTION_NONE;
  }
  }
  else {
  LDB1(L"WARNING: Unrecognized SAS type: %d", dwSasType);
  return WLX_SAS_ACTION_NONE;
  }
  // Assume that WinLogon provides a buffer large enough to hold a logon SID,
  // which is of fixed length. It'd be nice if WinLogon would tell us how big
  // its buffer actually was, but it appears this is assumed.
  if (SecurityHelper::GetLogonSid(*phToken, pLogonSid, LOGON_SID_SIZE)) {
  // copy login information for network providers
  pNprNotifyInfo->pszUserName = _localAllocString(pwszUser);
  pNprNotifyInfo->pszDomain = _localAllocString(pwszDomain);
  pNprNotifyInfo->pszPassword = _localAllocString(pwszPassword);
  if (pNprNotifyInfo->pszUserName &&
  pNprNotifyInfo->pszDomain &&
  pNprNotifyInfo->pszPassword) {
  success = true;
  action = WLX_SAS_ACTION_LOGON;
  }
  }
  if (success) {
  // GINA caches a copy of the interactive user's token
  theApp._hToken = *phToken;
  }
  else {
  CloseHandle(*phToken);
  *phToken = 0;
  }
  return action;
  break;
  case IDCANCEL:
  return WLX_SAS_ACTION_NONE;
  break;
  default:
  if(login.bCLOSE==TRUE)
  {
  return WLX_SAS_ACTION_SHUTDOWN;
  }
  return WLX_SAS_ACTION_NONE;
  break;
  };
  }

本文转自
http://www.fdu.org.cn/viewthread-2492.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值