home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pmvnc100.zip / auth.c < prev    next >
C/C++ Source or Header  |  1999-03-29  |  2KB  |  86 lines

  1. /*
  2.  * auth.c - PM VNC Viewer, authentication
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <memory.h>
  8.  
  9. #define INCL_PM
  10. #include <os2.h>
  11.  
  12. #include "pmvncdef.h"
  13. #include "pmvncres.h"
  14. #include "vncauth.h"
  15.  
  16. /*
  17.  * Password to encode challenge
  18.  */
  19.  
  20. static  UCHAR   authPass[MAXPWLEN+2] ;
  21.  
  22. /*
  23.  * procPass - window procedure for Password Dialog
  24.  */
  25.  
  26. static MRESULT EXPENTRY procPass(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 
  27. {
  28.     switch (msg) {
  29.     case WM_INITDLG :
  30.         if (SessDlgCenter) {
  31.         dialogAtCenter(hwnd) ;
  32.     } else {
  33.             dialogAtMouse(hwnd, DID_OK) ;
  34.         }
  35.         WinSendMsg(WinWindowFromID(hwnd, IDD_PEDIT),
  36.             EM_SETTEXTLIMIT, MPFROMSHORT(sizeof(authPass)), NULL) ;
  37.         WinSetWindowText(WinWindowFromID(hwnd, IDD_PEDIT), "") ;
  38.     return (MRESULT) 0 ;
  39.  
  40.     case WM_COMMAND :
  41.         switch (SHORT1FROMMP(mp1)) {
  42.         case DID_OK :
  43.         memset(authPass, 0, sizeof(authPass)) ;
  44.         WinQueryWindowText(
  45.             WinWindowFromID(hwnd, IDD_PEDIT), sizeof(authPass), authPass) ;
  46.         WinDismissDlg(hwnd, DID_OK) ;
  47.         return (MRESULT) 0 ;
  48.     case DID_CANCEL :
  49.         WinDismissDlg(hwnd, DID_CANCEL) ;
  50.         return (MRESULT) 0 ;
  51.         default :
  52.         return (MRESULT) 0 ;
  53.         }
  54.     }
  55.     return WinDefDlgProc(hwnd, msg, mp1, mp2) ;
  56. }
  57.  
  58. /*
  59.  * authCypher - encode challenge with password
  60.  */
  61.  
  62. BOOL    authCypher(HWND hwnd, PUCHAR key)
  63. {
  64.     ULONG   ret    ;
  65.     PUCHAR  passwd ;
  66.     
  67.     if (SessPasswdFile != NULL) {
  68.         passwd = vncDecryptPasswdFromFile(SessPasswdFile) ;
  69.     vncEncryptBytes(key, passwd) ;
  70.     memset(passwd, 0, 8) ;
  71.     free(passwd) ;
  72.     return TRUE ;
  73.     }
  74.     
  75.     ret = WinDlgBox(HWND_DESKTOP, hwnd,
  76.                 procPass, NULLHANDLE, IDD_PASS, NULL) ;
  77.     if (ret != DID_OK) {
  78.         memset(authPass, 0, sizeof(authPass)) ;
  79.         return FALSE ;
  80.     }
  81.     
  82.     vncEncryptBytes(key, authPass) ;
  83.     memset(authPass, 0, sizeof(authPass)) ;
  84.     return TRUE ;
  85. }
  86.