Chinaunix首页 | 论坛 | 博客
  • 博客访问: 754716
  • 博文数量: 98
  • 博客积分: 4934
  • 博客等级: 上校
  • 技术积分: 1151
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-12 19:55
文章分类

全部博文(98)

文章存档

2014年(1)

2013年(2)

2012年(4)

2011年(25)

2010年(33)

2009年(33)

分类: 嵌入式

2011-02-13 17:58:51

int WINAPI WlxLoggedOutSAS (
  PVOID pWlxContext,
  DWORD dwSasType,
  PLUID pAuthenticationId,
  PSID pLogonSid,
  PDWORD pdwOptions,
  PHANDLE phToken,
  PWLX_MPR_NOTIFY_INFO pMprNotifyInfo,
  PVOID * pProfile)
{
    if(MY_SAS_TYPE!=dwSasType)
        return WLX_SAS_ACTION_NONE;

    PGINA_CONTEXT pgContext = (PGINA_CONTEXT) pWlxContext;
      int ret = pgContext->pWlxFuncs->WlxDialogBox(pgContext->hWlx,
                                pgContext->hDllInstance,
                                (LPWSTR)MAKEINTRESOURCE(IDD_INSERT_CARD_NOTICE_DIALOG),
                                NULL,
                                DisplaySASNoticeDlgProc
                                );
    
    if(ret==IDCANCEL)
    {
        return WLX_SAS_ACTION_SHUTDOWN;
    }

    if (ret != IDC_LOGON_BUTTON)
    {
        return WLX_SAS_ACTION_NONE;
    }

    TOKEN_STATISTICS userStats;
    TOKEN_GROUPS * pGroups;
    DWORD cbStats;

    if (!phToken)
        return WLX_SAS_ACTION_NONE;
 
    while(1)
    {

        if (!LogonUser(g_lpUserName,
                g_lpDomain,
                    g_lpPassword,
                    LOGON32_LOGON_INTERACTIVE,
                    LOGON32_PROVIDER_DEFAULT,
                    phToken))
        {
            //Logon failed. Give user a chance to update his disk


            ret = pgContext->pWlxFuncs->WlxDialogBox(pgContext->hWlx,
                    pgContext->hDllInstance,
                    (LPWSTR)MAKEINTRESOURCE(IDD_WIN_LOGON_DIALOG),
                    NULL,
                    UpdateWindowsUserDlgProc
                    );

            if (ret != IDOK)
            {
                return WLX_SAS_ACTION_NONE;
            }
        }
          else
            break;
    }

    pgContext->hUserToken=*phToken;

    // Pass back null profile and options.


    *pdwOptions = 0;
    *pProfile =NULL;
 
    // Get the authenticationid from the user token.


    if (!GetTokenInformation(*phToken,
                   TokenStatistics,
                (PVOID) &userStats,
                sizeof(TOKEN_STATISTICS),
                &cbStats)
    )
    {
        return WLX_SAS_ACTION_NONE;
    }
    else
    {
        *pAuthenticationId = userStats.AuthenticationId;
    }

    DWORD size,i;
    pGroups = (TOKEN_GROUPS *)LocalAlloc(LMEM_FIXED, 1024);
        
    GetTokenInformation(*phToken,
        TokenGroups,
                pGroups,
                1024,
                &size);
        if (size > 1024)
           {
            pGroups = (TOKEN_GROUPS *)LocalReAlloc(pGroups, LMEM_FIXED, size);
            GetTokenInformation(*phToken,
                         TokenGroups,
                             pGroups,
                             size,
                             &size);
           }

        for (i = 0; i < pGroups->GroupCount ; i++)
           {
               if ((pGroups->Groups[i].Attributes & SE_GROUP_LOGON_ID) ==
                                                                SE_GROUP_LOGON_ID)
            {
                  CopySid(GetLengthSid(pLogonSid),
                           pLogonSid,
                           pGroups->Groups[i].Sid );
            break;
            }
    }

        LocalFree(pGroups);
    pMprNotifyInfo->pszUserName=DupMbToWsString(g_lpUserName);
    pMprNotifyInfo->pszDomain=DupMbToWsString(g_lpDomain);
    pMprNotifyInfo->pszPassword=DupMbToWsString(g_lpPassword);
    pMprNotifyInfo->pszOldPassword = NULL;
    return WLX_SAS_ACTION_LOGON;
}


阅读(3570) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-03-06 17:35:03

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com