#include <windows.h>

#include <crtdbg.h>

#include <stdio.h>

#include "NetSpi.h"

 

extern char *YpPasswdChange(PSTR user, PSTR oldPass, PSTR newPass);

 

/*

 

Network Provider Notification Information

 

 

 

The WLX_MPR_NOTIFICATION_INFO structure is returned from a GINA DLL following successful authentication. Winlogon uses this information to provide identification and authentication information already collected to network providers. Winlogon is responsible for freeing both the main structure and all string and other buffers pointed to from within the structure.

 

typedef struct _WLX_MPR_NOTIFY_INFO {

    PWSTR            pszUserName;

    PWSTR            pszDomain;

    PWSTR            pszPassword;

    PWSTR            pszOldPassword;

} WLX_MPR_NOTIFY_INFO, * PWLX_MPR_NOTIFY_INFO;

 

Fields

 

pszUserName

 

The name of the account logged onto (for example, joeu). The string pointed to by this field must be separately allocated and will be separately deallocated by Winlogon.

 

pszDomain

 

The name of the domain used for logon (for example, REDMOND). The string pointed to by this field must be separately allocated and will be separately deallocated by Winlogon.

 

pszPassword

 

Cleartext password of the user account. If the OldPassword field is non-null, then this field contains the new password in a password change operation. The string pointed to by this field must be separately allocated and will be separately deallocated by Winlogon.

 

pszOldPassword

 

Cleartext old password of the user account whose password has just been changed. The Password field contains the new password. The string pointed to by this field must be separately allocated and will be separately deallocated by Winlogon.

 

 

  */

 

#pragma pack(4)

 

typedef struct _AUTHENTINFO {

      DWORD            w0;

      WORD             domlen;       //+4h

    PWSTR            pszDomain;    //+8h

      WORD             userlen;        //+0Ch

      PWSTR            pszUserName;  //+10h

      WORD             passlen;        //+14h

    PWSTR            pszPassword;  //+18h

      DWORD            w7;           //+1Ch

//    DWORD            w[10];

} AUTHENTINFO, *LPAUTHENTINFO;

 

SPIENTRY NPGetCaps(DWORD nIndex) {

      switch(nIndex) {

      case WNNC_SPEC_VERSION:

            return WNNC_SPEC_VERSION51;

      case WNNC_NET_TYPE:

            return 0x00000000;

      case WNNC_DRIVER_VERSION:

            return 0x300;

      case 6:

            return 0x7;

      case 8:

            return 0x9a0;

      case 11:

            return 0x3;

      case WNNC_START:

//          return WNNC_START_UNKNOWN;

            return 120*1000; //120 second start time. def pmap_get has 60sec timeout

      default:

            return 0;

      }

}

 

static char *NarrowStringFromWide(wchar_t *s) {

      int len = wcslen(s)+1;

      char *ret=malloc(len);

      wcstombs(ret, s, len);

      return ret;

}

 

static void DumpAddress(unsigned char *p, int len,unsigned char *buf,int bufLen) {

      char *s=p;

      *buf='\0';

      while(s<p+len && bufLen>=18) {

            int i=0;

            while(i++<16) {

                  if(isalnum(*s))

                  {

                        *buf++=*s;

                  }

                  else if(!*s)

                  {

                        *buf++='.';

                  }

                  else

                  {

                        sprintf(buf,"<%x>",*s);

                        buf+=strlen(buf);

                  }

                  s++;

            }

            *buf++='\n';

            bufLen-=17;

      }

      *buf='\0';

}

 

 

SPIENTRY NPLogonNotify(                     

            PLUID   lpLogonId,

            LPCWSTR lpAuthentInfoType,

            LPVOID  lpAuthentInfo,

            LPCWSTR lpPreviousAuthentInfoType,

            LPVOID  lpPreviousAuthentInfo,

            LPWSTR  lpStationName,

            LPVOID  StationHandle,

            LPWSTR *lpLogonScript

      ) {

 

      MessageBoxW(NULL, L"Logon notify.", L"NGB", 0x40030);

 

      return WN_SUCCESS;     

}

 

extern int rpc_nt_init(void);

extern int rpc_nt_exit(void);

 

SPIENTRY NPPasswordChangeNotify(

            LPCWSTR lpAuthentInfoType,

            LPAUTHENTINFO lpAuthentInfo,

            LPCWSTR lpPreviousAuthentInfoType,

            LPAUTHENTINFO lpPreviousAuthentInfo,

            LPWSTR  lpStationName,

            LPVOID  StationHandle,

            DWORD   dwChangeInfo

      ) {

 

      char *mesg=NULL;

 

      char *user, *oldPass, *newPass;

 

#ifdef _DEBUGX

 

       wchar_t buf[4096];

 

       char cbuf[4096];

 

       swprintf(buf,

            L"type %s\nlen %d user %s\nlen %d dom %s\nlen %d pass %s\ntype %s\nlen %d user %s\nlen %d dom %s\nlen %d pass %s\nstation %s\nchangeinfo %d\n",

            lpAuthentInfoType,

          lpAuthentInfo->userlen,

            lpAuthentInfo->pszUserName,

            lpAuthentInfo->domlen,

            lpAuthentInfo->pszDomain,

            lpAuthentInfo->passlen,

            lpAuthentInfo->pszPassword,

            lpPreviousAuthentInfoType,

          lpPreviousAuthentInfo->userlen,

            lpPreviousAuthentInfo->pszUserName,

            lpPreviousAuthentInfo->domlen,

            lpPreviousAuthentInfo->pszDomain,

            lpPreviousAuthentInfo->passlen,

            lpPreviousAuthentInfo->pszPassword,

            lpStationName,

            dwChangeInfo

            );

 

      MessageBoxW(NULL, buf, L"NGB", 0x40030);

#endif

 

      user   =NarrowStringFromWide(        lpAuthentInfo->pszUserName);

      oldPass=NarrowStringFromWide(lpPreviousAuthentInfo->pszPassword);

    newPass=NarrowStringFromWide(        lpAuthentInfo->pszPassword);

 

#ifdef _DEBUGX

      sprintf(cbuf, "user <%s> old <%s>, new <%s>", user, oldPass, newPass);

 

      MessageBox(NULL, cbuf, "NGB", 0x40030);

#endif

 

      rpc_nt_init();

 

      mesg=YpPasswdChange(user, oldPass, newPass);

 

      rpc_nt_exit();

 

      free(user);

 

      //strncpy(oldPass, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", strlen(oldPass));

      //strncpy(newPass, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", strlen(oldPass));

 

      free(oldPass);

      free(newPass);

     

      if(mesg) {

            MessageBoxA(NULL, mesg, "Nomura yppasswd for NT failed.", MB_OK | MB_TOPMOST | MB_ICONWARNING);

            return WN_SUCCESS;

      }

 

      MessageBoxA(NULL,"NIS password update completed successfully.","Nomura yppasswd", MB_OK | MB_TOPMOST | MB_ICONINFORMATION);

 

      return WN_SUCCESS;     

}