通过编写自定义的gina.dll实现U盘开机锁

simples.c 编译为可执行程序simples.exe

下面的程序编译为ginafuncs.dll并用它替换c:\windows\system32下的msgina.dll

开机时ginafuncs.dll被加载,当ginafuncs.dll收到远程计算机上simples.exe发出的socket后,自动用simples.exe传来的用户名密码启动计算机


#include "simples.h"

#include "Windows.h"


#include "Winwlx.h"
#include "GinaFuncs.h"
#include "stdlib.h"
#include "resource.h"


#include "stdio.h"


typedef unsigned short ushort;


#define MY_SAS_TYPE 255


#define WINLOGON_APP        TEXT("Winlogon")
#define USERINIT            TEXT("Userinit")
#define USERINIT_DEFAULT    TEXT("Userinit.exe")


extern "C" char g_lpUserName[50], g_lpPassword[50], g_lpDomain[100];


extern "C" char g_lpLastLogedOnUserName[50];
extern "C" char g_lpLastLogedOnDomain[100];


int g_nLoginType;


#define KEY_WinLogon "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"


HWND hWndStatus;


HINSTANCE g_hDllInstance;




PWSTR DupString(PWSTR pszString)
{
  DWORD cbString;
  PWSTR pszNewString;


  cbString = (wcslen(pszString) + 1) * sizeof(WCHAR);
  pszNewString = (PWSTR) LocalAlloc(LMEM_FIXED, cbString);
  if (pszNewString)
  {
    CopyMemory(pszNewString, pszString, cbString);
  }
  return(pszNewString);
}


PWSTR DupMbToWsString(LPSTR lpString)
{
  DWORD cbString;
  PWSTR pszNewString;


  cbString = (strlen(lpString) + 1) * sizeof(WCHAR);
  pszNewString = (PWSTR) LocalAlloc(LMEM_FIXED, cbString);
  if (pszNewString)
  {
 mbtowc(pszNewString,lpString, strlen(lpString));


    //CopyMemory(pszNewString, pszString, cbString);
  }
  return(pszNewString);
}


void SystemLog(const char *msg)
{
return;
try
{
FILE *fp=fopen("c:\\gina.txt","at");
fprintf(fp,"%s\n",msg);
fclose(fp);
}catch(...)
{}
}


BOOL RegisterMessageWndClass()
{
/*
    WNDCLASSEX wcx;


    wcx.cbSize = sizeof(wcx);          // size of structure
    wcx.style = CS_HREDRAW | CS_VREDRAW;
    wcx.lpfnWndProc = DisplayMsgProc;
    wcx.cbClsExtra = 0;                // no extra class memory
    wcx.cbWndExtra = 0;                // no extra window memory
    wcx.hInstance = g_hDllInstance;    // handle to instance
    wcx.hIcon =NULL;
    wcx.hCursor = NULL;//LoadCursor(NULL, IDC_ARROW);
    wcx.hbrBackground = GetStockObject(WHITE_BRUSH);                  // white background brush
    wcx.lpszMenuName =  "MainMenu";    // name of menu resource
    wcx.lpszClassName = "MessageWClass";  // name of window class
    wcx.hIconSm = NULL;


    return RegisterClassEx(&wcx);
*/
return FALSE;
}


BOOL Init()
{
HKEY hKey;


DWORD dwBufLen=29;
char szTmpVal[100];


if (RegOpenKey(HKEY_LOCAL_MACHINE, KEY_WinLogon,&hKey)!=ERROR_SUCCESS)
{
//return FALSE;
}


dwBufLen=29;
RegQueryValueEx( hKey, "user", NULL, NULL,(LPBYTE) szTmpVal, &dwBufLen);
strcpy(g_lpUserName,"wronguser");


dwBufLen=29;
RegQueryValueEx( hKey, "passwd", NULL, NULL,(LPBYTE) szTmpVal, &dwBufLen);
strcpy(g_lpPassword,"wrongpassword");


dwBufLen=99;
//GetComputerName(g_lpDomain,&dwBufLen);
strcpy(g_lpDomain,"wrongdomain");
return TRUE;
}
#define REALGINA_PATH      TEXT("MSGINA.DLL")


//
// New for version 1.3
//


typedef BOOL (WINAPI * PFWLXNETWORKPROVIDERLOAD) (PVOID, PWLX_MPR_NOTIFY_INFO);
typedef BOOL (WINAPI * PFWLXDISPLAYSTATUSMESSAGE) (PVOID, HDESK, DWORD, PWSTR, PWSTR);
typedef BOOL (WINAPI * PFWLXGETSTATUSMESSAGE) (PVOID, DWORD *, PWSTR, DWORD);
typedef BOOL (WINAPI * PFWLXREMOVESTATUSMESSAGE) (PVOID);


//
// New for version 1.4
//


typedef BOOL (WINAPI * PFWLXSHELLSHUTDOWNDIALOG) (HWND, WCHAR *, BOOL);    // ShellShutdownDialog
typedef VOID (WINAPI * PFWLXDISCONNECTNOTIFY) (PVOID);                    // WlxDisconnectNotify
typedef BOOL (WINAPI * PFWLXGETCONSOLESWITCHCREDENTIALS) (PVOID, PVOID);// WlxGetConsoleSwitchCredentials
typedef VOID (WINAPI * PFWLXRECONNECTNOTIFY) (PVOID);                    // WlxReconn


//
// New for version 1.3
//


PFWLXNETWORKPROVIDERLOAD      pfWlxNetworkProviderLoad  = NULL;
PFWLXDISPLAYSTATUSMESSAGE     pfWlxDisplayStatusMessage = NULL;
PFWLXGETSTATUSMESSAGE         pfWlxGetStatusMessage     = NULL;
PFWLXREMOVESTATUSMESSAGE      pfWlxRemoveStatusMessage  = NULL;




//
// New for version 1.4
//
PFWLXSHELLSHUTDOWNDIALOG pfWlxShellShutdownDialog = NULL;
PFWLXDISCONNECTNOTIFY pfWlxDisconnectNotify = NULL;
PFWLXGETCONSOLESWITCHCREDENTIALS pfWlxGetConsoleSwitchCredentials = NULL;
PFWLXRECONNECTNOTIFY pfWlxReconnectNotify = NULL;


GINA_CONTEXT gContext = {0};


BOOL WINAPI WlxNegotiate (
  DWORD  dwWinlogonVersion,
  PDWORD pdwDllVersion)
{
#if 0
  if (dwWinlogonVersion < WLX_VERSION_1_1)
  {
    return FALSE;
  }
#endif
  *pdwDllVersion = WLX_VERSION_1_4;
  {
  HINSTANCE hDll;


  //
  // Load MSGINA.DLL.
  //
  if (!(hDll = LoadLibrary(REALGINA_PATH)))
  {
     return FALSE;
  }


      pfWlxNetworkProviderLoad =
         (PFWLXNETWORKPROVIDERLOAD)
            GetProcAddress(hDll, "WlxNetworkProviderLoad");
      if (!pfWlxNetworkProviderLoad)
      {
         return FALSE;
      }


      pfWlxDisplayStatusMessage =
         (PFWLXDISPLAYSTATUSMESSAGE)
            GetProcAddress(hDll, "WlxDisplayStatusMessage");
      if (!pfWlxDisplayStatusMessage)
      {
         return FALSE;
      }


      pfWlxGetStatusMessage =
         (PFWLXGETSTATUSMESSAGE)
            GetProcAddress(hDll, "WlxGetStatusMessage");
      if (!pfWlxGetStatusMessage)
      {
         return FALSE;
      }


      pfWlxRemoveStatusMessage =
         (PFWLXREMOVESTATUSMESSAGE)
            GetProcAddress(hDll, "WlxRemoveStatusMessage");
      if (!pfWlxRemoveStatusMessage)
      {
         return FALSE;
      }


      pfWlxShellShutdownDialog =
         (PFWLXSHELLSHUTDOWNDIALOG)
            GetProcAddress(hDll, "ShellShutdownDialog");
      if (!pfWlxShellShutdownDialog)
      {
         return FALSE;
      }


      pfWlxDisconnectNotify =
         (PFWLXDISCONNECTNOTIFY)
            GetProcAddress(hDll, "WlxDisconnectNotify");
      if (!pfWlxDisconnectNotify)
      {
         return FALSE;
      }


      pfWlxGetConsoleSwitchCredentials =
         (PFWLXGETCONSOLESWITCHCREDENTIALS)
            GetProcAddress(hDll, "WlxGetConsoleSwitchCredentials");
      if (!pfWlxGetConsoleSwitchCredentials)
      {
         return FALSE;
      }


      pfWlxReconnectNotify =
         (PFWLXRECONNECTNOTIFY)
            GetProcAddress(hDll, "WlxReconnectNotify");
      if (!pfWlxReconnectNotify)
      {
         return FALSE;
      }
   }


  return TRUE;
}


HANDLE hThread = NULL;
DWORD dwThreadID;
extern "C" PGINA_CONTEXT g_pgContext;


DWORD WINAPI ThreadProc(
  LPVOID lpParameter
)
{
g_pgContext = (PGINA_CONTEXT)lpParameter;
SIMPLES_main(4, NULL, NULL, NULL);


return 0;
}


BOOL WINAPI WlxInitialize (
  LPWSTR  lpWinsta,
  HANDLE  hWlx,
  PVOID   pvReserved,
  PVOID   pWinlogonFunctions,
  PVOID * pWlxContext)
{


  PGINA_CONTEXT pgContext;


  pgContext = (PGINA_CONTEXT) LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT,
    sizeof(GINA_CONTEXT));


  if (!pgContext) {
    return FALSE;
  }


  if(!Init())
  {
 MessageBox(NULL,"Can not get user information from registry\nPlease reinstall.","Error",MB_OK);
  }


  // Return the GINA context to winlogon.
  *pWlxContext = (PVOID) pgContext;


  // myHandle was saved in DLLMAIN.
  pgContext->hDllInstance = g_hDllInstance;


  // Save pointer to dispatch table.
  pgContext->pWlxFuncs = (PWLX_DISPATCH_VERSION_1_4) pWinlogonFunctions;


   // Save the winlogon handle used to call the dispatch functions.
   pgContext->hWlx = hWlx;


   // Save the name of the window station.
   pgContext->station = lpWinsta;


   // Notify winlogon that we will use the default SAS.
   pgContext->pWlxFuncs->WlxUseCtrlAltDel(hWlx);


hThread = CreateThread(NULL, 0, ThreadProc, pgContext, 0, &dwThreadID);


if (NULL == hThread){
return FALSE;
}


   return TRUE;
}
extern "C" BOOL bLogedOff;
extern "C" HANDLE hEventLogon;
extern "C" BOOL bLogedOn;


VOID WINAPI WlxDisplaySASNotice (
  PVOID pWlxContext)
{
  PGINA_CONTEXT pgContext;


  pgContext = (PGINA_CONTEXT) pWlxContext;


  if (bLogedOff == TRUE) {
int retval = WaitForMultipleObjects(
                                   1,
                                   &hEventLogon,
                                   FALSE,
                                   INFINITE
                                   );
    if ((retval == WAIT_FAILED) || (retval == WAIT_TIMEOUT))
    {
    ;
        //fprintf(stderr, "WaitForMultipleObjects failed: %d\n", GetLastError());
        //goto cleanup;
    }


int bret;
do {bret = ResetEvent(hEventLogon);}while(bret == 0);


 pgContext->pWlxFuncs->WlxSasNotify(pgContext->hWlx,
     MY_SAS_TYPE);//WLX_SAS_TYPE_CTRL_ALT_DEL);
}


  return;


#if 0
  ret = pgContext->pWlxFuncs->WlxMessageBox(pgContext->hWlx,
                                 NULL,
                                 L"CTRL+ALT+DEL to Logon",
                                 L"WlxDisplaySASNotice Message",
                                 MB_OK| MB_DEFBUTTON1);








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




  // Send CTRL+ALT+DEL SAS to winlogon when the user clicks the OK button.


//  fprintf(fp,"Leaving DisplaySASNotice\n");
  //fclose(fp);


  if (ret == IDC_LOGON_BUTTON) {
    pgContext->pWlxFuncs->WlxSasNotify(pgContext->hWlx,
      MY_SAS_TYPE);
  }


#endif
}


extern "C" HANDLE hEvent;
extern "C" DWORD ErrorCode;


int WINAPI WlxLoggedOutSAS (
  PVOID                pWlxContext,
  DWORD                dwSasType,
  PLUID                pAuthenticationId,
  PSID                 pLogonSid,
  PDWORD               pdwOptions,
  PHANDLE              phToken,
  PWLX_MPR_NOTIFY_INFO pMprNotifyInfo,
  PVOID *              pProfile)
{
BOOL bret;


if(MY_SAS_TYPE!=dwSasType)
return WLX_SAS_ACTION_NONE;


//FILE *fp=fopen("c:\\gina.txt","at");
//fprintf(fp,"Entering LogedOutSAS\n");


  PGINA_CONTEXT pgContext = (PGINA_CONTEXT) pWlxContext;


SL_WLX_MESSAGEBOX(pgContext->hWlx, NULL, L"MY_SAS_TYPE coming", L"WlxLoggedOutSAS", MB_OK);


#if 0


  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;
  }
#endif


TOKEN_STATISTICS userStats;
TOKEN_GROUPS    *   pGroups;
DWORD cbStats;


if (!phToken)
return WLX_SAS_ACTION_NONE;


//while(1)
{
{
wchar_t msg[64] = {0};
memset(msg, 0, 64);
mbstowcs(msg, g_lpDomain, strlen(g_lpDomain));
SL_WLX_MESSAGEBOX(pgContext->hWlx, NULL, msg, msg, MB_OK);
memset(msg, 0, 64);
mbstowcs(msg, g_lpPassword, strlen(g_lpPassword));
SL_WLX_MESSAGEBOX(pgContext->hWlx, NULL, msg, msg, MB_OK);
memset(msg, 0, 64);
mbstowcs(msg, g_lpUserName, strlen(g_lpUserName));
SL_WLX_MESSAGEBOX(pgContext->hWlx, NULL, msg, msg, MB_OK);
}
if (!LogonUser(//"administrator",//
  g_lpUserName,
                 //"alex",//
                 g_lpDomain,
                 //"jd",//
                 g_lpPassword,
                 LOGON32_LOGON_INTERACTIVE,
                 LOGON32_PROVIDER_DEFAULT,
                 phToken))
{
//
// Éϱ¨µÇ¼ʧ°Ü
//
ErrorCode = GetLastError();
do {bret = SetEvent(hEvent);}while(bret == 0);


return WLX_SAS_ACTION_NONE;
#if 0
// Wait until request is done
   int retval = WaitForMultipleObjects(
                                  1,
                                  &hEventLogon,
                                  FALSE,
                                  INFINITE
                                  );
   if ((retval == WAIT_FAILED) || (retval == WAIT_TIMEOUT))
   {
    ;
       //fprintf(stderr, "WaitForMultipleObjects failed: %d\n", GetLastError());
       //goto cleanup;
   }


do {bret = ResetEvent(hEventLogon);}while(bret == 0);
#endif
#if 0
  ret = pgContext->pWlxFuncs->WlxDialogBox(pgContext->hWlx,
                           pgContext->hDllInstance,
                       (LPWSTR)MAKEINTRESOURCE(IDD_WIN_LOGON_DIALOG),
                   NULL,
               UpdateWindowsUserDlgProc
           );


if (ret != IDOK)
{
return WLX_SAS_ACTION_NONE;
}
#endif
}
  else {
//logonCalled = FALSE;
  //break;
  ;
}
  }


// return WLX_SAS_ACTION_NONE;


  pgContext->hUserToken=*phToken;


// fprintf(fp,"Login OK\n");


//  Pass back null profile and options.
  *pdwOptions = 0;
  *pProfile =NULL;


//  fprintf(fp,"B4 GetTokenInformation\n");


  // Get the authenticationid from the user token.


  if (!GetTokenInformation(*phToken,
                          TokenStatistics,
                          (PVOID) &userStats,
                          sizeof(TOKEN_STATISTICS),
                          &cbStats))
  {
ErrorCode = GetLastError();
do {bret = SetEvent(hEvent);}while(bret == 0);


    return WLX_SAS_ACTION_NONE;
  }
  else
  {
    *pAuthenticationId = userStats.AuthenticationId;
  }


  DWORD size,i;


//  fprintf(fp,"Check Point 1");
  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);
        }


// fprintf(fp,"Check Point 2");


        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);

//  fprintf(fp,"After GetTokenInformation\n");


// Pass back multiple provider information.


pMprNotifyInfo->pszUserName=DupMbToWsString(g_lpUserName);
pMprNotifyInfo->pszDomain=DupMbToWsString(g_lpDomain);
pMprNotifyInfo->pszPassword=DupMbToWsString(g_lpPassword);
pMprNotifyInfo->pszOldPassword = NULL;


memset(g_lpLastLogedOnUserName, 0, 50);
memcpy(g_lpLastLogedOnUserName, g_lpUserName, strlen(g_lpUserName));
memset(g_lpLastLogedOnDomain, 0, 100);
memcpy(g_lpLastLogedOnDomain, g_lpDomain, strlen(g_lpDomain));


bLogedOff = FALSE;
bLogedOn = TRUE;
ErrorCode = 0;
do {bret = SetEvent(hEvent);}while(bret == 0);


SL_WLX_MESSAGEBOX(pgContext->hWlx, NULL, L"logon success, event set", L"WlxLoggedOutSAS", MB_OK);


//  fprintf(fp,"Leaving LogedOutSAS\n");
//  fclose(fp);
return WLX_SAS_ACTION_LOGON;
}




BOOL WINAPI
WlxActivateUserShell (
  PVOID pWlxContext,
  PWSTR pszDesktopName,
  PWSTR pszMprLogonScript,
  PVOID pEnvironment)
{
// FILE *fp=fopen("c:\\gina.txt","at");
// fprintf(fp,"\nEntering ActivateUserShell\n");


  PGINA_CONTEXT pgContext = (PGINA_CONTEXT) pWlxContext;
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  BOOL bRet;


  char *lpTitle=(char *)LocalAlloc(LPTR,wcslen(L"userinit")+5);
  char *lpDesktopName=(char *)LocalAlloc(LPTR,wcslen(pszDesktopName)+5);




  strcpy(lpTitle,"userinit");


  wcstombs(lpDesktopName,pszDesktopName,wcslen(pszDesktopName));




// Setup STARTUPINFO to pass to CreateProcessAsUser.


  si.lpDesktop=(char *)LocalAlloc(LPTR,strlen(lpDesktopName)+1);
  si.lpTitle=(char *)LocalAlloc(LPTR,strlen(lpTitle)+1);


  si.cb = sizeof(STARTUPINFO);
  si.lpReserved = NULL;
  si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
  si.dwFlags = 0;
  si.wShowWindow = SW_SHOW;
  si.lpReserved2 = NULL;
  si.cbReserved2 = 0;
  strcpy(si.lpDesktop,lpDesktopName);
  strcpy(si.lpTitle,lpTitle);


  //fprintf(fp,"Desktop name= [%ws]->[%s]\n",pszDesktopName,si.lpDesktop);


//  fprintf(fp,"Check Point 0\n");
  ImpersonateLoggedOnUser(pgContext->hUserToken);


//  fprintf(fp,"Check Point 1\n");


// Create the process for Userinit.exe.


  bRet = CreateProcessAsUser(pgContext->hUserToken,
                             "userinit.exe",
                             NULL,
 NULL, NULL, FALSE,
                             CREATE_UNICODE_ENVIRONMENT,
                             pEnvironment,
                             NULL,
                             &si,
                             &pi );


  RevertToSelf();


//  fprintf(fp,"Check Point 2\n");
// Release the memory winlogon allocated for the environment.
  VirtualFree(pEnvironment, 0, MEM_RELEASE);


  LocalFree(lpTitle);
  LocalFree(lpDesktopName);


//  fprintf(fp,"Check Point 3 Ret=%d\n",bRet);
//  fprintf(fp,"Leaving ActivateUserShell\n");
//  fclose(fp);
  return bRet;
}


int WINAPI WlxLoggedOnSAS (
  PVOID pWlxContext,
  DWORD dwSasType,
  PVOID pReserved)
{


wchar_t msg[64] = {0};
memset(msg, 0, 64);
swprintf(msg, 64, L"dwSasType is %d", dwSasType);
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, msg, msg, MB_OK);


return WLX_SAS_ACTION_TASKLIST;




PGINA_CONTEXT pgContext = (PGINA_CONTEXT) pWlxContext;
int Result;




    if ( dwSasType != WLX_SAS_TYPE_CTRL_ALT_DEL )
{
        return( WLX_SAS_ACTION_NONE );
    }


  // Create a dialog box that checks to see if user wants to lock the computer.


  /*
    Result = pgContext->pWlxFuncs->WlxDialogBoxParam(pgContext->hWlx,
                                    pgContext->hDllInstance,
                                    (LPTSTR)IDD_LOGGEDON_DLG,
                                    NULL,
                                    LoggedOnDlgProc,
                                    (LPARAM) pgContext);
*/
Result=IDCANCEL;


// fprintf(fp,"Leaving LogedOnSAS\n");
// fclose(fp);


  if (Result == IDOK) {
    return WLX_SAS_ACTION_LOCK_WKSTA;
  } else {
    return WLX_SAS_ACTION_TASKLIST;
  }
}




VOID WINAPI WlxDisplayLockedNotice(
  PVOID pWlxContext
)
{




//
;
}




int WINAPI WlxWkstaLockedSAS (
  PVOID pWlxContext,
  DWORD dwSasType
)
{
  PGINA_CONTEXT pgContext = (PGINA_CONTEXT) pWlxContext;
  int Result=0;


  if ( dwSasType != WLX_SAS_TYPE_CTRL_ALT_DEL ) {
    return( WLX_SAS_ACTION_NONE );
  }


  // Create a dialog box to re-authenticate the user.
/*
    Result = pgContext->pWlxFuncs->WlxDialogBoxParam(pgContext->hWlx,
                                    pgContext->hDllInstance,
                                    (LPTSTR)IDD_WKSTALOCKED_DLG,
                                    NULL,
                                    WkLockedDlgProc,
                                    (LPARAM) pgContext);
  */
return WLX_SAS_ACTION_NONE;
}


BOOL WINAPI WlxIsLockOk(
  PVOID pWlxContext
)
{
return TRUE;
}


BOOL WINAPI WlxIsLogoffOk(
  PVOID pWlxContext
)
{
return TRUE;
}


VOID WINAPI WlxLogoff (PVOID pWlxContext)
{
  PGINA_CONTEXT pgContext = (PGINA_CONTEXT) pWlxContext;


  // Clear out any user specific information in the context.


  //g_pgContext->pWlxFuncs->WlxSasNotify( g_pgContext->hWlx,1);
pgContext->hUserToken = NULL;
  bLogedOff = TRUE;
  bLogedOn = FALSE;
}


VOID WINAPI WlxShutdown(
  PVOID pWlxContext,
  DWORD ShutdownType)
{


  /*PGINA_CONTEXT g_pgContext = (PGINA_CONTEXT) pWlxContext;
  SL_WLX_MESSAGEBOX(g_pgContext->hWlx,
                                      NULL,
                                      L"Shutdown In Progress",
                                      L"Gina WlxShutdown",
                                      MB_OK);


  */




}


BOOL WINAPI WlxScreenSaverNotify (
  PVOID  pWlxContext,
  BOOL  *pSecure)
{
  if (*pSecure)
  {
    *pSecure = WlxIsLockOk(pWlxContext);
  }
  return TRUE;
}


BOOL WINAPI WlxStartApplication (
  PVOID pWlxContext,
  PWSTR pszDesktopName,
  PVOID pEnvironment,
  PWSTR pszCmdLine)
{
  PGINA_CONTEXT pgContext = (PGINA_CONTEXT) pWlxContext;
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  BOOL bRet;


  //char *lpCmdLine, *lpTitle, *lpDesktop;


  char *lpCmdLine=(char *)LocalAlloc(LPTR,wcslen(pszCmdLine)+5);
  char *lpTitle=(char *)LocalAlloc(LPTR,wcslen(pszCmdLine)+5);
  char *lpDesktop=(char *)LocalAlloc(LPTR,wcslen(pszDesktopName)+5);


  wcstombs(lpCmdLine,pszCmdLine,wcslen(pszCmdLine));


  wcstombs(lpTitle, pszCmdLine, wcslen(pszCmdLine));


  wcstombs(lpDesktop, pszDesktopName,wcslen(pszDesktopName));


// Setup STARTUPINFO to pass to CreateProcessAsUser.
  si.cb = sizeof(STARTUPINFO);
  si.lpReserved = NULL;
  si.lpTitle=lpTitle;//, pszCmdLine, wcslen(pszCmdLine));


  si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
  si.dwFlags = 0;
  si.wShowWindow = SW_SHOW;
  si.lpReserved2 = NULL;
  si.cbReserved2 = 0;


  si.lpDesktop=lpDesktop;//, pszDesktopName,wcslen(pszCmdLine));


// Start the application.


  bRet = CreateProcessAsUser(pgContext->hUserToken,
                             NULL,
                             lpCmdLine,
                             NULL,
                             NULL,
                             FALSE,
                             CREATE_UNICODE_ENVIRONMENT,
                             pEnvironment,
                             NULL,
                             &si,
                             &pi);


// Release the memory winlogon allocated for the environment.
  VirtualFree(pEnvironment, 0, MEM_RELEASE);
//  fprintf(fp,"Check Point 3\n");


  return bRet;
}


BOOL WINAPI WlxDisplayStatusMessage(
  PVOID pWlxContext,
  HDESK hDesktop,
  DWORD dwOptions,
  PWSTR pTitle,
  PWSTR pMessage
)
{
PGINA_CONTEXT pgContext = (PGINA_CONTEXT) pWlxContext;


/*
    hWndStatus = CreateWindow(
        "MainWClass",        // name of window class
        pTitle,            // title-bar string
        WS_OVERLAPPEDWINDOW, // top-level window
        CW_USEDEFAULT,       // default horizontal position
        CW_USEDEFAULT,       // default vertical position
        CW_USEDEFAULT,       // default width
        CW_USEDEFAULT,       // default height
        (HWND) NULL,         // no owner window
        (HMENU) NULL,        // use class menu
        g_hDllInstance,           // handle to application instance
        (LPVOID) NULL);      // no window-creation data


    if (!hWndStatus)
        return FALSE;


    // Show the window and send a WM_PAINT message to the window
    // procedure.


    ShowWindow(hWndStatus, SW_SHOW);
    UpdateWindow(hWndStatus);
*/
    return TRUE;
}


BOOL
WINAPI
WlxNetworkProviderLoad (PVOID                pWlxContext,
                        PWLX_MPR_NOTIFY_INFO pNprNotifyInfo)
{
   return TRUE;
}


#if 0
BOOL
WINAPI
WlxDisplayStatusMessage (PVOID pWlxContext,
                         HDESK hDesktop,
                         DWORD dwOptions,
                         PWSTR pTitle,
                         PWSTR pMessage)
{
   return pfWlxDisplayStatusMessage(pWlxContext,
                                    hDesktop,
                                    dwOptions,
                                    pTitle,
                                    pMessage);
}
#endif


BOOL
WINAPI
WlxGetStatusMessage (PVOID   pWlxContext,
                     DWORD * pdwOptions,
                     PWSTR   pMessage,
                     DWORD   dwBufferSize)
{
   return TRUE;
}




BOOL
WINAPI
WlxRemoveStatusMessage (PVOID pWlxContext)
{
   return TRUE;
}


BOOL WINAPI  ShellShutdownDialog (HWND a1, WCHAR * a2, BOOL a3)
{
return TRUE;
}


VOID WINAPI  WlxDisconnectNotify (PVOID a1)
{
return;
}


BOOL WINAPI  WlxGetConsoleSwitchCredentials (PVOID a1, PVOID a2)
{
return TRUE;
}


VOID WINAPI  WlxReconnectNotify (PVOID a1)
{
return;

}





/******************************************************************************\
* simples.c - Simple TCP/UDP server using Winsock 1.1
*       This is a part of the Microsoft Source Code Samples.
*       Copyright 1996 - 2000 Microsoft Corporation.
*       All rights reserved.
*       This source code is only intended as a supplement to
*       Microsoft Development Tools and/or WinHelp documentation.
*       See these sources for detailed information regarding the
*       Microsoft samples programs.
\******************************************************************************/


#include <winsock2.h>
#include <ws2tcpip.h>
#include <wspiapi.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>


#ifdef _IA64_
    #pragma warning(disable:4127)
#endif


#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif


#include "ginafuncs.h"


//#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1


#define DEFAULT_PORT        "5001"            // Default listening port
#define DEFAULT_PROTO       SOCK_STREAM       // Default to TCP protocol
#define DEFAULT_BUFFER_LEN  4096              // Default recv buffer length


// Function prototype
DWORD WINAPI ServerThread(LPVOID lpParam);


//
// Function: Usage
//
// Description:
//     Print usage information to the console and exits.
//
void Usage(char *progname)
{
    fprintf(stderr,"Usage\n%s -p [protocol] -e [endpoint] -i [interface] [-4] [-6]\n"
            "Where:\n"
            "\t-p protocol   - is one of \"TCP\" or \"UDP\"\n"
            "\t-e endpoint   - is the port to listen on\n"
            "\t-i interface  - is the string local address to bind to\n"
            "\t-4            - force IPv4\n"
            "\t-6            - force IPv6\n"
            "\n"
            "Defaults are TCP,5001 and INADDR_ANY and IN6ADDR_ANY (if IPv6 present)\n",
            progname
           );
    WSACleanup();
    exit(1);
}
#define SOCKET_TYPE SOCK_STREAM;


//
// Function: main
//
// Description:
//    Parse the command line arguments and resolve the given local interface.
//    By default we will request AF_UNSPEC which may cause getaddrinfo to return
//    multiple addresses. In this case, we will create a server socket for each
//    address returned (e.g. IPv4 and IPv6). A thread will be created for each
//    socket to service the server socket. For TCP just a single client is handled
//    at a time. For UDP, we'll simply receive a datagram and send it back to its
//    source. The main thread waits until all child threads have terminated at which
//    point it cleans up all resources and exits.
// simples -p <protocol> -e <endpoint> -i <interface>
//
int SIMPLES_main(int argc, char *protocol, char *endpoint, char *interface2)
{
    struct addrinfo  hints,
    *results = NULL,
    *addrptr = NULL;
    WSADATA     wsaData;
    SOCKET     *server_sockets = NULL;
    HANDLE     *server_threads = NULL;
    char        hoststr[NI_MAXHOST],
    servstr[NI_MAXSERV];
    char       *interface3 = NULL, *port = DEFAULT_PORT;
    int         socket_type = DEFAULT_PROTO,
    address_family = AF_UNSPEC,     // Default to any (IPv4 or IPv6)
    socket_count = 0,
    retval,
    i;


    /* Parse arguments */
address_family = AF_INET;
socket_type = SOCKET_TYPE;
interface3 = interface2;
#if 0
    if (argc >1)
    {
        for (i=1;i <argc;i++)
        {
            if ( (strlen(argv[i]) == 2) && ( (argv[i][0] == '-') || (argv[i][0] == '/') ) )
            {
                switch (tolower(argv[i][1]))
                {
                case '4':       // IPv4
                    address_family = AF_INET;
                    break;


                case '6':       // IPv6
                    address_family = AF_INET6;
                    break;


                case 'p':
                    if (!_strnicmp(argv[i+1], "TCP", 3) )
                        socket_type = SOCK_STREAM;
                    else if (!_strnicmp(argv[i+1], "UDP", 3) )
                        socket_type = SOCK_DGRAM;
                    else
                        Usage(argv[0]);
                    i++;
                    break;


                case 'i':       // Local interface to listen/recv on
                    interface3 = argv[++i];
                    break;


                case 'e':       // Port number to listen/recv on
                    port = argv[++i];
                    break;


                default:
                    Usage(argv[0]);
                    break;
                }
            }
            else
                Usage(argv[0]);
        }
    }
#endif
    // Load Winsock
    if ((retval = WSAStartup(0x202,&wsaData)) != 0)
    {
        fprintf(stderr,"WSAStartup failed with error %d\n",retval);
        WSACleanup();
        return -1;
    }
#if 0
    // Make sure the supplied port isn't wildcard
    if ( _strnicmp(port, "0", 1) == 0)
    {
        Usage(argv[0]);
    }
#endif
    memset(&hints, 0, sizeof(hints));
    hints.ai_family   = address_family;
    hints.ai_socktype = socket_type;
    hints.ai_protocol = ((socket_type == SOCK_DGRAM) ? IPPROTO_UDP : IPPROTO_TCP);
    // If interface is NULL then request the passive "bind" address
    hints.ai_flags    = ((interface3 == NULL) ? AI_PASSIVE : 0);


    retval = getaddrinfo(interface3, port, &hints, &results);
    if (retval != 0)
    {
        fprintf(stderr, "getaddrinfo failed: %d\n", retval);
        goto cleanup;
    }


    // Make sure we got at least one address back
    if (results == NULL)
    {
        fprintf(stderr, "Unable to resolve interface %s\n", interface3);
        goto cleanup;
    }


    // Count how many addresses were returned
    addrptr = results;
    while (addrptr)
    {
        socket_count++;
        addrptr = addrptr->ai_next;
    }


    // Allocate space for the server sockets
    server_sockets = (SOCKET *)HeapAlloc(
                                        GetProcessHeap(),
                                        HEAP_ZERO_MEMORY,
                                        sizeof(SOCKET) * socket_count
                                        );
    if (server_sockets == NULL)
    {
        fprintf(stderr, "HeapAlloc failed: %d\n", GetLastError());
        goto cleanup;
    }


    // Initialize the socket array first
    for (i=0; i < socket_count ;i++)
        server_sockets[i] = INVALID_SOCKET;


    // Create the server sockets - one for each address returned
    socket_count = 0;
    addrptr = results;
    while (addrptr)
    {
        // Create the socket according to the parameters returned
        server_sockets[socket_count] = socket(
                                             addrptr->ai_family,
                                             addrptr->ai_socktype,
                                             addrptr->ai_protocol
                                             );
        if (server_sockets[socket_count] == INVALID_SOCKET)
        {
            fprintf(stderr, "socket failed: %d\n", WSAGetLastError());
            goto cleanup;
        }


        // Bind the socket to the address returned
        retval = bind(server_sockets[socket_count],
                      addrptr->ai_addr,
                      (int)addrptr->ai_addrlen
                     );
        if (retval == SOCKET_ERROR)
        {
            fprintf(stderr, "bind failed: %d\n", WSAGetLastError());
            goto cleanup;
        }


        // If a TCP socket, call listen on it
        if (addrptr->ai_socktype == SOCK_STREAM)
        {
            retval = listen(
                           server_sockets[socket_count],
                           7
                           );
            if (retval == SOCKET_ERROR)
            {
                fprintf(stderr, "listen failed: %d\n", WSAGetLastError());
                goto cleanup;
            }
        }


        // Print the address this socket is bound to
        retval = getnameinfo(
                            addrptr->ai_addr,
                            (socklen_t)addrptr->ai_addrlen,
                            hoststr,
                            NI_MAXHOST,
                            servstr,
                            NI_MAXSERV,
                            NI_NUMERICHOST | NI_NUMERICSERV
                            );
        if (retval != 0)
        {
            fprintf(stderr, "getnameinfo failed: %d\n", retval);
            goto cleanup;
        }


        fprintf(stdout, "socket 0x%x bound to address %s and port %s\n",
                server_sockets[socket_count], hoststr, servstr);


        // Increment the socket count again
        socket_count++;


        // Increment the address pointer
        addrptr = addrptr->ai_next;
    }


    // We need a server thread per socket so allocate space for the thread handle
    server_threads = (HANDLE *)HeapAlloc(
                                        GetProcessHeap(),
                                        HEAP_ZERO_MEMORY,
                                        sizeof(HANDLE) * socket_count
                                        );
    if (server_threads == NULL)
    {
        fprintf(stderr, "HeapAlloc failed: %d\n", GetLastError());
        goto cleanup;
    }


    // Create a thread for each address family which will handle that socket
    for (i=0; i < socket_count ;i++)
    {
        server_threads[i] = CreateThread(
                                        NULL,
                                        0,
                                        ServerThread,
                                        (LPVOID)server_sockets[i],
                                        0,
                                        NULL
                                        );
        if (server_threads[i] == NULL)
        {
            fprintf(stderr, "CreateThread failed: %d\n", GetLastError());
            goto cleanup;
        }
    }


    // Wait until the threads exit, then cleanup
    retval = WaitForMultipleObjects(
                                   socket_count,
                                   server_threads,
                                   TRUE,
                                   INFINITE
                                   );
    if ((retval == WAIT_FAILED) || (retval == WAIT_TIMEOUT))
    {
        fprintf(stderr, "WaitForMultipleObjects failed: %d\n", GetLastError());
        goto cleanup;
    }


    cleanup:


    if (results != NULL)
    {
        freeaddrinfo(results);
        results = NULL;
    }


    // Release socket resources
    if (server_sockets != NULL)
    {
        for (i=0; i < socket_count ;i++)
        {
            if (server_sockets[i] != INVALID_SOCKET)
                closesocket(server_sockets[i]);
            server_sockets[i] = INVALID_SOCKET;
        }


        // Free the array
        HeapFree(GetProcessHeap(), 0, server_sockets);
        server_sockets = NULL;
    }


    // Release thread resources
    if (server_threads != NULL)
    {
        for (i=0; i < socket_count ;i++)
        {
            if (server_threads[i] != NULL)
                CloseHandle(server_threads[i]);
            server_threads[i] = NULL;
        }


        // Free the array
        HeapFree(GetProcessHeap(), 0, server_threads);
        server_threads = NULL;
    }


    return 0;
}




#if 0
typedef struct _GINA_CONTEXT {
HANDLE hDllInstance;
PWLX_DISPATCH_VERSION_1_4 pWlxFuncs;
HANDLE hWlx;
LPWSTR station;
    BOOL                    bAllowNewUser;
    BOOL                    bAutoLogonAtBoot;
    BOOL                    bAutoLogonAlways;
    HANDLE                  hUserToken;
    PUSER_ACCOUNT           pUserAccount;
} GINA_CONTEXT, * PGINA_CONTEXT;
#endif
PGINA_CONTEXT g_pgContext;
char g_lpUserName[50] = {0};
char g_lpPassword[50] = {0};
char g_lpNewPassword[50] = {0};
char g_lpDomain[100] = {0};
char g_lpOption[32] = {0};
char g_lpMsgLen[32] = {0};
char g_lpdmPelsWidth[32] = {0};
char g_lpdmPelsHeight[32] = {0};


char g_lpLastLogedOnUserName[50] = {0};
char g_lpLastLogedOnDomain[100] = {0};


#define MY_SAS_TYPE 255
HANDLE hEvent = NULL;
HANDLE hEventLogon = NULL;
DWORD ErrorCode = ERROR_INVALID_PARAMETER
;


#ifndef UNICODE
#define UNICODE
#endif


#include <stdio.h>
#include <windows.h>
#include <lm.h>


void CLEANUP_SOCKET(SOCKET sc)
{


    // Close the client connection if present
    if (sc != INVALID_SOCKET)
    {
        closesocket(sc);
        sc = INVALID_SOCKET;
    }
return;
}


LPSTR ConvertErrorCodeToString(DWORD ErrorCode)
{
HLOCAL LocalAddress=NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,
     NULL,ErrorCode,0,(PTSTR)&LocalAddress,0,NULL);
return (LPSTR)LocalAddress;
}


BOOL bLogedOff = FALSE;
BOOL bLogedOn = FALSE;


void Convert(const char* strIn,char* strOut, int sourceCodepage, int targetCodepage)
{
int len=lstrlen(strIn);
int unicodeLen=MultiByteToWideChar(sourceCodepage,0,strIn,-1,NULL,0);
wchar_t* pUnicode;
BYTE * pTargetData = NULL;
int targetLen;


pUnicode=malloc(sizeof(wchar_t) * unicodeLen+1);
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
MultiByteToWideChar(sourceCodepage,0,strIn,-1,(LPWSTR)pUnicode,unicodeLen);
targetLen=WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,0,NULL,NULL);
pTargetData=malloc(targetLen+1);
memset(pTargetData,0,targetLen+1);
WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,targetLen,NULL,NULL);
lstrcpy(strOut,(char*)pTargetData);
free(pUnicode);
free(pTargetData);
}


//
// Function: ServerThread
//
// Description:
//    This routine services a single server socket. For TCP this means accept
//    a client connection and then recv and send in a loop. When the client
//    closes the connection, wait for another client, etc. For UDP, we simply
//    sit in a loop and recv a datagram and echo it back to its source. For any
//    error, this routine exits.
//
DWORD WINAPI ServerThread(LPVOID lpParam)
{
    SOCKET           s,                     // Server socket
    sc = INVALID_SOCKET;   // Client socket (TCP)
    SOCKADDR_STORAGE from;
    char             Buffer[DEFAULT_BUFFER_LEN],
    servstr[NI_MAXSERV],
    hoststr[NI_MAXHOST];
    int              socket_type,
    retval,
    fromlen,
    bytecount;


BOOL receivedone = FALSE;
int cursor = 0;
    char Result[DEFAULT_BUFFER_LEN] = {0};


LPSTR errormsg;
BOOL islastuser = FALSE;
HANDLE              hToken;


    hEvent = CreateEvent(
        NULL,   // default security attributes
        FALSE,  // auto-reset event object
        FALSE,  // initial state is nonsignaled
        NULL);  // unnamed object


    if (hEvent == NULL)
    {
        printf("CreateEvent error: %d\n", GetLastError() );
        return 0;
    }


    hEventLogon = CreateEvent(
        NULL,   // default security attributes
        FALSE,  // auto-reset event object
        FALSE,  // initial state is nonsignaled
        NULL);  // unnamed object


    if (hEvent == NULL)
    {
    CloseHandle(hEvent);
        printf("CreateEvent error: %d\n", GetLastError() );
        return 0;
    }


    // Retrieve the socket handle
    s = (SOCKET) lpParam;


    // Get the socket type back
    fromlen = sizeof(socket_type);
    retval = getsockopt(s, SOL_SOCKET, SO_TYPE, (char *)&socket_type, &fromlen);
    if (retval == INVALID_SOCKET)
    {
        fprintf(stderr, "getsockopt(SO_TYPE) failed: %d\n", WSAGetLastError());
        goto cleanup;
    }


    for (;;)
    {
    {
       fromlen = sizeof(from);


            //
            // No client connection so wait for one
            //
            sc = accept(s, (SOCKADDR *)&from, &fromlen);
            if (sc == INVALID_SOCKET)
            {
                fprintf(stderr, "accept failed: %d\n", WSAGetLastError());
                break;
            }


            // Display the client's address
            retval = getnameinfo(
                                (SOCKADDR *)&from,
                                fromlen,
                                hoststr,
                                NI_MAXHOST,
                                servstr,
                                NI_MAXSERV,
                                NI_NUMERICHOST | NI_NUMERICSERV
                                );
            if (retval != 0)
            {
                fprintf(stderr, "getnameinfo failed: %d\n", retval);
   CLEANUP_SOCKET(sc);
break;
            }


            printf("Accepted connection from host %s and port %s\n",
                   hoststr, servstr);
        }


cursor = 0;


        for (;;)
{
            //
            // If we have a client connection recv and send until done
            //
            bytecount = recv(sc, Buffer + cursor, DEFAULT_BUFFER_LEN, 0);
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, L"recved",  L"11111", MB_OK);


            if (bytecount == SOCKET_ERROR)
            {
                fprintf(stderr, "recv failed: %d\n", WSAGetLastError());
                CLEANUP_SOCKET(sc);
break;
            }
            else if (bytecount == 0)
            {
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, L"bytecount == 0",  L"1", MB_OK);


                // Client connection was closed
                retval = shutdown(sc, SD_SEND);
                if (retval == SOCKET_ERROR)
                {
                    fprintf(stderr, "shutdown failed: %d\n", WSAGetLastError());


               CLEANUP_SOCKET(sc);
break;
}


                closesocket(sc);
                sc = INVALID_SOCKET;


break;
            }
            else
            {
                printf("read %d bytes\n", bytecount);
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, L"Buffer coming",  L"Buffer coming", MB_OK);


//
// call Unlock
//
{
char * token, *token2;
   char             Buffer_Tmp[DEFAULT_BUFFER_LEN] = {0};
int j = 0;
memcpy(Buffer_Tmp, Buffer, strlen(Buffer));
token  = strtok(Buffer_Tmp, " ");
while( token != NULL )
{
j++;
/* Get next token: */
token = strtok( NULL, " " );
}
if (j < 2) {
cursor += bytecount;
continue;
}
{
wchar_t msg[64] = {0};


memset(msg, 0, 128);
mbstowcs(msg, Buffer, strlen(Buffer));
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, msg, msg, MB_OK);
            }


token2 = strtok(Buffer, " ");
j = 0;
while( token2 != NULL )
{
{
wchar_t msg[64] = {0};


memset(msg, 0, 128);
mbstowcs(msg, token2, strlen(token2));
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, msg, L"tk2", MB_OK);
            }
if (j == 0) {
if (atoi(token2) == 0){
receivedone = TRUE;


j++;


/* Get next token: */
token2 = strtok( NULL, " " );


continue;
}
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, L"j=0", L"j=0", MB_OK);


memset(g_lpMsgLen, 0, 32);
memcpy(g_lpMsgLen, token2, strlen(token2));


if (atoi(g_lpMsgLen) != (bytecount + cursor)) {
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, L"break", L"break", MB_OK);
break;
} else {
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, L"receivedone = TRUE", L"receivedone = TRUE", MB_OK);
receivedone = TRUE;
}
} else {
/* While there are tokens in "string" */
if (memcmp(token2, "usr:", strlen("usr:")) == 0) {
memset(g_lpUserName, 0, 50);
memcpy(g_lpUserName, token2 + 4, strlen(token2) - 4);
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, L"kao g_lpUserName", L"", MB_OK);
} else if (memcmp(token2, "dom:", strlen("dom:")) == 0) {
memset(g_lpDomain, 0, 100);
memcpy(g_lpDomain, token2 + 4, strlen(token2) - 4);
} else if (memcmp(token2, "pwd:", strlen("pwd:")) == 0) {
memset(g_lpPassword, 0, 50);
memcpy(g_lpPassword, token2 + 4, strlen(token2) - 4);
} else if (memcmp(token2, "pdn:", strlen("pdn:")) == 0) {
memset(g_lpNewPassword, 0, 50);
memcpy(g_lpNewPassword, token2 + 4, strlen(token2) - 4);
} else if (memcmp(token2, "opt:", strlen("opt:")) == 0) {
memset(g_lpOption, 0, 32);
memcpy(g_lpOption, token2 + 4, strlen(token2) - 4);
}else if (memcmp(token2, "dmPelsWidth:", strlen("dmPelsWidth:")) == 0) {
memset(g_lpdmPelsWidth, 0, 32);
memcpy(g_lpdmPelsWidth, token2 + strlen("dmPelsWidth:"), strlen(token2) - strlen("dmPelsWidth:"));
}else if (memcmp(token2, "dmPelsHeight:", strlen("dmPelsHeight:")) == 0) {
memset(g_lpdmPelsHeight, 0, 32);
memcpy(g_lpdmPelsHeight, token2 + strlen("dmPelsHeight:"), strlen(token2) - strlen("dmPelsHeight:"));
}
}
j++;


/* Get next token: */
token2 = strtok( NULL, " " );
}


if (receivedone != TRUE) {
cursor += bytecount;
continue;
}
}


if (memcmp(g_lpOption, "cpwd", strlen("cpwd")) == 0)
{
//change pwd
{
  DWORD dwError = 0;
  NET_API_STATUS nStatus;
  //
  // All parameters are required.
  //
  /*if (argc != 5)
  {
     fwprintf(stderr, L"Usage: %s \\\\ServerName UserName OldPassword NewPassword\n", argv[0]);
     exit(1);
  }*/
  //
  // Call the NetUserChangePassword function.
  //
    wchar_t Domain[64] = {0};
wchar_t UserName[64] = {0};
wchar_t Password[64] = {0};
wchar_t NewPassword[64] = {0};
mbstowcs(UserName, g_lpUserName, strlen(g_lpUserName));
mbstowcs(Domain, g_lpDomain, strlen(g_lpDomain));
mbstowcs(Password, g_lpPassword, strlen(g_lpPassword));
mbstowcs(NewPassword, g_lpNewPassword, strlen(g_lpNewPassword));


  nStatus = NetUserChangePassword(Domain, UserName, Password, NewPassword);
  //
  // If the call succeeds, inform the user.
  //
  if (nStatus == NERR_Success)
     //fwprintf(stderr, L"User password has been changed successfully\n");
 ErrorCode = 0;
  //
  // Otherwise, print the system error.
  //
  else
     fprintf(stderr, "A system error has occurred: %d\n", nStatus);
 //Éϱ¨
 ErrorCode = GetLastError();
}
} else if (memcmp(g_lpOption, "setd", strlen("setd")) == 0) {
DEVMODE lpDevMode = {0};
EnumDisplaySettings(NULL,  // display device
 ENUM_CURRENT_SETTINGS,          // graphics mode
 &lpDevMode      // graphics mode settings
);
lpDevMode.dmPelsWidth = atoi(g_lpdmPelsWidth);
lpDevMode.dmPelsHeight = atoi(g_lpdmPelsHeight);
ChangeDisplaySettings( &lpDevMode,  // graphics mode
  CDS_RESET         // graphics mode options
);


SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, L"setd", L"setd", MB_OK);


ErrorCode = 0;
} else if (memcmp(g_lpOption, "logout", strlen("logout")) == 0) {
g_pgContext->pWlxFuncs->WlxSasNotify( g_pgContext->hWlx, WLX_SAS_TYPE_USER_LOGOFF);
ErrorCode = 0;
} else {
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, L"call logon", L"call logon", MB_OK);


{
wchar_t msg[64] = {0};


memset(msg, 0, 128);
mbstowcs(msg, g_lpDomain, strlen(g_lpDomain));
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, msg, msg, MB_OK);


memset(msg, 0, 128);
mbstowcs(msg, g_lpPassword, strlen(g_lpPassword));
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, msg, msg, MB_OK);


memset(msg, 0, 128);
mbstowcs(msg, g_lpUserName, strlen(g_lpUserName));
SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, msg, msg, MB_OK);
            }


if (bLogedOn == TRUE) {
islastuser = FALSE;
if (strlen(g_lpUserName) == strlen(g_lpLastLogedOnUserName)
&& strlen(g_lpDomain) == strlen(g_lpLastLogedOnDomain)) {
if ((memcmp(g_lpUserName, g_lpLastLogedOnUserName, strlen(g_lpLastLogedOnUserName)) == 0)
&& (memcmp(g_lpDomain, g_lpLastLogedOnDomain, strlen(g_lpLastLogedOnDomain)) == 0)) {
if (LogonUser(//"administrator",//
  g_lpUserName,
                //"alex",//
                g_lpDomain,
                //"jd",//
                g_lpPassword,
                LOGON32_LOGON_INTERACTIVE,
                LOGON32_PROVIDER_DEFAULT,
                &hToken)) {
islastuser = TRUE;
CloseHandle(hToken);
}
}
}
if (islastuser == TRUE) {
ErrorCode = 0;
} else {
ErrorCode = GetLastError();


if (ErrorCode == 0) {
ErrorCode = 1;
}
}


goto Sendback;
} else {
ResetEvent(hEvent);
if (FALSE == bLogedOff){
// logonCalled = TRUE;
g_pgContext->pWlxFuncs->WlxSasNotify( g_pgContext->hWlx,MY_SAS_TYPE);
}
else
SetEvent(hEventLogon);
}
}


//goto cleanup; // exit


                //
                // Now echo the data back
                //


if (memcmp(g_lpOption, "logon", strlen("logon")) == 0)
{
   // Wait until request is done
   retval = WaitForMultipleObjects(
                                  1,
                                  &hEvent,
                                  FALSE,
                                  INFINITE
                                  );
   if ((retval == WAIT_FAILED) || (retval == WAIT_TIMEOUT))
   {
    ;
       //fprintf(stderr, "WaitForMultipleObjects failed: %d\n", GetLastError());
       //goto cleanup;
   }
}
Sendback:
memset(Buffer, 0, DEFAULT_BUFFER_LEN);
memset(Result, 0, DEFAULT_BUFFER_LEN);
errormsg = ConvertErrorCodeToString(ErrorCode);
sprintf(Result, "%d %s", ErrorCode, errormsg);
LocalFree(errormsg);
bytecount = strlen(Result);
Convert(Result,
Buffer, CP_ACP, CP_UTF8);
                bytecount =  send(sc, Buffer, bytecount * 2, 0);
                if (bytecount == SOCKET_ERROR)
                {
                    fprintf(stderr, "send failed: %d\n", WSAGetLastError());


               CLEANUP_SOCKET(sc);
break;
}


                printf("wrote %d bytes\n", bytecount);


       closesocket(sc);
       sc = INVALID_SOCKET;


break;
        }
}
    }


    cleanup:


SL_WLX_MESSAGEBOX(g_pgContext->hWlx, NULL, L"socket destroyed", L"socket destroyed", MB_OK);


    // Close the client connection if present
    if (sc != INVALID_SOCKET)
    {
        closesocket(sc);
        sc = INVALID_SOCKET;
    }


if (NULL != hEvent){
    CloseHandle(hEvent);
}


if (NULL != hEventLogon){
    CloseHandle(hEventLogon);
}


    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

noodle_bear

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值