Path: blob/main/crypto/krb5/src/windows/leashdll/lsh_pwd.c
34914 views
#define SCALE_FACTOR 31/2012/* LSH_PWD.C34Jason Hunter58/2/946DCNS/IS MIT78Re-written for KFW 2.6 by Jeffrey Altman <[email protected]>910Contains the callback functions for the EnterPassword an11ChangePassword dialog boxes and well as the API function12calls:1314Lsh_Enter_Password_Dialog15Lsh_Change_Password_Dialog1617for calling the dialogs.1819Also contains the callback for the MITPasswordControl.2021*/2223/* Standard Include files */24#include <windows.h>25#include <windowsx.h>26#include <stdio.h>27#include <string.h>2829/* Private Inlclude files */30#include "leashdll.h"31#include <leashwin.h>32#include "leash-int.h"33#include "leashids.h"34#include <leasherr.h>35#include <krb5.h>36#include <commctrl.h>3738extern void * Leash_pec_create(HWND hEditCtl);39extern void Leash_pec_destroy(void *pAutoComplete);40extern void Leash_pec_add_principal(char *principal);41extern void Leash_pec_clear_history(void *pec);4243/* Global Variables. */44static long lsh_errno;45static char *err_context; /* error context */46extern HINSTANCE hLeashInst;47extern HINSTANCE hKrb5;484950INT_PTR51CALLBACK52PasswordProc(53HWND hwndDlg,54UINT uMsg,55WPARAM wParam,56LPARAM lParam57);5859INT_PTR60CALLBACK61AuthenticateProc(62HWND hwndDlg,63UINT uMsg,64WPARAM wParam,65LPARAM lParam66);6768INT_PTR69CALLBACK70NewPasswordProc(71HWND hwndDlg,72UINT uMsg,73WPARAM wParam,74LPARAM lParam75);767778long Leash_get_lsh_errno(LONG *err_val)79{80return lsh_errno;81}8283/*/////// ******** API Calls follow here. ******** /////////*/8485static int86NetId_dialog(LPLSH_DLGINFO lpdlginfo)87{88LRESULT lrc;89HWND hNetIdMgr;90HWND hForeground;9192hNetIdMgr = FindWindow("IDMgrRequestDaemonCls", "IDMgrRequestDaemon");93if (hNetIdMgr != NULL) {94char desiredPrincipal[512];95NETID_DLGINFO *dlginfo;96char *desiredName = 0;97char *desiredRealm = 0;98HANDLE hMap;99DWORD tid = GetCurrentThreadId();100char mapname[256];101102strcpy(desiredPrincipal, lpdlginfo->principal);103104/* do we want a specific client principal? */105if (desiredPrincipal[0]) {106char * p;107desiredName = desiredPrincipal;108for (p = desiredName; *p && *p != '@'; p++);109if ( *p == '@' ) {110*p = '\0';111desiredRealm = ++p;112}113}114115sprintf(mapname,"Local\\NetIDMgr_DlgInfo_%lu",tid);116117hMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,1180, 4096, mapname);119if (hMap == NULL) {120return -1;121} else if (hMap != NULL && GetLastError() == ERROR_ALREADY_EXISTS) {122CloseHandle(hMap);123return -1;124}125126dlginfo = (NETID_DLGINFO *)MapViewOfFileEx(hMap, FILE_MAP_READ|FILE_MAP_WRITE,1270, 0, 4096, NULL);128if (dlginfo == NULL) {129CloseHandle(hMap);130return -1;131}132133hForeground = GetForegroundWindow();134135memset(dlginfo, 0, sizeof(NETID_DLGINFO));136137dlginfo->size = sizeof(NETID_DLGINFO);138if (lpdlginfo->dlgtype == DLGTYPE_PASSWD)139dlginfo->dlgtype = NETID_DLGTYPE_TGT;140else141dlginfo->dlgtype = NETID_DLGTYPE_CHPASSWD;142dlginfo->in.use_defaults = 1;143144if (lpdlginfo->title) {145MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,146lpdlginfo->title, -1,147dlginfo->in.title, NETID_TITLE_SZ);148} else if (desiredName && (strlen(desiredName) + strlen(desiredRealm) + 32 < NETID_TITLE_SZ)) {149char mytitle[NETID_TITLE_SZ];150sprintf(mytitle, "Obtain Kerberos TGT for %s@%s",desiredName,desiredRealm);151MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,152mytitle, -1,153dlginfo->in.title, NETID_TITLE_SZ);154} else {155MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,156"Obtain Kerberos TGT", -1,157dlginfo->in.title, NETID_TITLE_SZ);158}159if (desiredName)160MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,161desiredName, -1,162dlginfo->in.username, NETID_USERNAME_SZ);163if (desiredRealm)164MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,165desiredRealm, -1,166dlginfo->in.realm, NETID_REALM_SZ);167lrc = SendMessage(hNetIdMgr, 32810, 0, (LPARAM) tid);168169UnmapViewOfFile(dlginfo);170CloseHandle(hMap);171172SetForegroundWindow(hForeground);173return lrc;174}175return -1;176}177178static int179NetId_dialog_ex(LPLSH_DLGINFO_EX lpdlginfo)180{181HWND hNetIdMgr;182HWND hForeground;183184hNetIdMgr = FindWindow("IDMgrRequestDaemonCls", "IDMgrRequestDaemon");185if (hNetIdMgr != NULL) {186NETID_DLGINFO *dlginfo;187char *desiredName = lpdlginfo->username;188char *desiredRealm = lpdlginfo->realm;189LPSTR title;190char *ccache;191LRESULT lrc;192HANDLE hMap;193DWORD tid = GetCurrentThreadId();194char mapname[256];195196sprintf(mapname,"Local\\NetIDMgr_DlgInfo_%lu",tid);197198hMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,1990, 4096, mapname);200if (hMap == NULL) {201return -1;202} else if (hMap != NULL && GetLastError() == ERROR_ALREADY_EXISTS) {203CloseHandle(hMap);204return -1;205}206207dlginfo = (NETID_DLGINFO *)MapViewOfFileEx(hMap, FILE_MAP_READ|FILE_MAP_WRITE,2080, 0, 4096, NULL);209if (dlginfo == NULL) {210CloseHandle(hMap);211return -1;212}213214hForeground = GetForegroundWindow();215216if (lpdlginfo->size == LSH_DLGINFO_EX_V1_SZ ||217lpdlginfo->size == LSH_DLGINFO_EX_V2_SZ)218{219title = lpdlginfo->title;220desiredName = lpdlginfo->username;221desiredRealm = lpdlginfo->realm;222ccache = NULL;223} else {224title = lpdlginfo->in.title;225desiredName = lpdlginfo->in.username;226desiredRealm = lpdlginfo->in.realm;227ccache = lpdlginfo->in.ccache;228}229230memset(dlginfo, 0, sizeof(NETID_DLGINFO));231232dlginfo->size = sizeof(NETID_DLGINFO);233if (lpdlginfo->dlgtype == DLGTYPE_PASSWD)234dlginfo->dlgtype = NETID_DLGTYPE_TGT;235else236dlginfo->dlgtype = NETID_DLGTYPE_CHPASSWD;237238dlginfo->in.use_defaults = lpdlginfo->use_defaults;239dlginfo->in.forwardable = lpdlginfo->forwardable;240dlginfo->in.noaddresses = lpdlginfo->noaddresses;241dlginfo->in.lifetime = lpdlginfo->lifetime;242dlginfo->in.renew_till = lpdlginfo->renew_till;243dlginfo->in.proxiable = lpdlginfo->proxiable;244dlginfo->in.publicip = lpdlginfo->publicip;245246if (title) {247MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,248title, -1,249dlginfo->in.title, NETID_TITLE_SZ);250} else if (desiredName && (strlen(desiredName) + strlen(desiredRealm) + 32 < NETID_TITLE_SZ)) {251char mytitle[NETID_TITLE_SZ];252sprintf(mytitle, "Obtain Kerberos TGT for %s@%s",desiredName,desiredRealm);253MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,254mytitle, -1,255dlginfo->in.title, NETID_TITLE_SZ);256} else {257MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,258"Obtain Kerberos TGT", -1,259dlginfo->in.title, NETID_TITLE_SZ);260}261if (desiredName)262MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,263desiredName, -1,264dlginfo->in.username, NETID_USERNAME_SZ);265if (desiredRealm)266MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,267desiredRealm, -1,268dlginfo->in.realm, NETID_REALM_SZ);269if (ccache)270MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,271ccache, -1,272dlginfo->in.ccache, NETID_CCACHE_NAME_SZ);273lrc = SendMessage(hNetIdMgr, 32810, 0, (LPARAM) tid);274275if (lrc > 0) {276if (lpdlginfo->size == LSH_DLGINFO_EX_V2_SZ)277{278WideCharToMultiByte(CP_ACP, 0, dlginfo->out.username, -1,279lpdlginfo->out.username, LEASH_USERNAME_SZ,280NULL, NULL);281WideCharToMultiByte(CP_ACP, 0, dlginfo->out.realm, -1,282lpdlginfo->out.realm, LEASH_REALM_SZ,283NULL, NULL);284}285if (lpdlginfo->size == LSH_DLGINFO_EX_V3_SZ)286{287WideCharToMultiByte(CP_ACP, 0, dlginfo->out.ccache, -1,288lpdlginfo->out.ccache, LEASH_CCACHE_NAME_SZ,289NULL, NULL);290}291}292293UnmapViewOfFile(dlginfo);294CloseHandle(hMap);295296SetForegroundWindow(hForeground);297return lrc;298}299return -1;300}301302303#define LEASH_DLG_MUTEX_NAME TEXT("Leash_Dialog_Mutex")304int Leash_kinit_dlg(HWND hParent, LPLSH_DLGINFO lpdlginfo)305{306int rc;307HANDLE hMutex;308309rc = NetId_dialog(lpdlginfo);310if (rc > -1)311return rc;312313hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);314if ( GetLastError() == ERROR_ALREADY_EXISTS ) {315if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {316return -1;317}318ReleaseMutex(hMutex);319CloseHandle(hMutex);320return 1; /* pretend the dialog was displayed and succeeded */321}322323lpdlginfo->dlgtype = DLGTYPE_PASSWD;324325/* set the help file */326Leash_set_help_file(NULL);327328/* Call the Dialog box with the DLL's Password Callback and the329DLL's instance handle. */330rc = DialogBoxParam(hLeashInst, "EnterPasswordDlg", hParent,331PasswordProc, (LPARAM)lpdlginfo);332333ReleaseMutex(hMutex);334CloseHandle(hMutex);335return rc;336}337338339int Leash_kinit_dlg_ex(HWND hParent, LPLSH_DLGINFO_EX lpdlginfo)340{341int rc;342HANDLE hMutex;343344rc = NetId_dialog_ex(lpdlginfo);345if (rc > -1)346return rc;347348hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);349if ( GetLastError() == ERROR_ALREADY_EXISTS ) {350if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {351return -1;352}353ReleaseMutex(hMutex);354CloseHandle(hMutex);355return 1; /* pretend the dialog was displayed and succeeded */356}357358/* set the help file */359Leash_set_help_file(NULL);360361/* Call the Dialog box with the DLL's Password Callback and the362DLL's instance handle. */363rc = DialogBoxParam(hLeashInst, MAKEINTRESOURCE(IDD_AUTHENTICATE), hParent,364AuthenticateProc, (LPARAM)lpdlginfo);365ReleaseMutex(hMutex);366CloseHandle(hMutex);367return rc;368}369370371int Leash_changepwd_dlg(HWND hParent, LPLSH_DLGINFO lpdlginfo)372{373int rc;374HANDLE hMutex;375376rc = NetId_dialog(lpdlginfo);377if (rc > -1)378return rc;379380hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);381if ( GetLastError() == ERROR_ALREADY_EXISTS ) {382if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {383return -1;384}385ReleaseMutex(hMutex);386CloseHandle(hMutex);387return 1; /* pretend the dialog was displayed and succeeded */388}389390lpdlginfo->dlgtype = DLGTYPE_CHPASSWD;391392/* Call the Dialog box with the DLL's Password Callback and the393DLL's instance handle. */394rc = DialogBoxParam(hLeashInst, "CHANGEPASSWORDDLG", hParent,395PasswordProc, (LPARAM)lpdlginfo);396ReleaseMutex(hMutex);397CloseHandle(hMutex);398return rc;399}400401int Leash_changepwd_dlg_ex(HWND hParent, LPLSH_DLGINFO_EX lpdlginfo)402{403int rc;404HANDLE hMutex;405406rc = NetId_dialog_ex(lpdlginfo);407if (rc > -1)408return rc;409410hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);411if ( GetLastError() == ERROR_ALREADY_EXISTS ) {412if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {413return -1;414}415ReleaseMutex(hMutex);416CloseHandle(hMutex);417return 1; /* pretend the dialog was displayed and succeeded */418}419420lpdlginfo->dlgtype = DLGTYPE_CHPASSWD;421422/* Call the Dialog box with the DLL's Password Callback and the423DLL's instance handle. */424rc = DialogBoxParam(hLeashInst, MAKEINTRESOURCE(IDD_PASSWORD), hParent,425NewPasswordProc, (LPARAM)lpdlginfo);426ReleaseMutex(hMutex);427CloseHandle(hMutex);428return rc;429}430431432/* These little utils are taken from lshutil.c433they are added here for the Call back function.434****** beginning of added utils from lshutil.c ******/435436BOOL IsDlgItem(HWND hWnd, WORD id)437{438HWND hChild;439440hChild = GetDlgItem(hWnd, id);441return hChild ? IsWindow(hChild) : 0;442}443444int lsh_getkeystate(WORD keyid)445{446static BYTE keys[256];447448GetKeyboardState((LPBYTE) &keys);449return (int) keys[keyid];450}451452LPSTR krb_err_func(int offset, long code)453{454return(NULL);455}456457/****** End of Added utils from leash.c ******/458459460int PaintLogoBitmap( HANDLE hPicFrame )461{462HBITMAP hBitmap;463HBITMAP hOldBitmap;464BITMAP Bitmap;465HDC hdc, hdcMem;466RECT rect;467468/* Invalidate the drawing space of the picframe. */469InvalidateRect( hPicFrame, NULL, TRUE);470UpdateWindow( hPicFrame );471472hdc = GetDC(hPicFrame);473hdcMem = CreateCompatibleDC(hdc);474GetClientRect(hPicFrame, &rect);475hBitmap = LoadBitmap(hLeashInst, "LOGOBITMAP");476hOldBitmap = SelectObject(hdcMem, hBitmap);477GetObject(hBitmap, sizeof(Bitmap), (LPSTR) &Bitmap);478StretchBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0,479Bitmap.bmWidth, Bitmap.bmHeight, SRCCOPY);480481SelectObject(hdcMem, hOldBitmap); /* pbh 8-15-94 */482ReleaseDC(hPicFrame, hdc);483DeleteObject( hBitmap ); /* pbh 8-15-94 */484DeleteDC( hdcMem ); /* pbh 8-15-94 */485486return 0;487}488489490/* Callback function for the Password Dialog box that initilializes and491renews tickets. */492493INT_PTR494CALLBACK495PasswordProc(496HWND hDialog,497UINT message,498WPARAM wParam,499LPARAM lParam500)501{502static POINT Position = { -1, -1 };503static short state;504int lifetime;505#define ISCHPASSWD (lpdi->dlgtype == DLGTYPE_CHPASSWD)506#define STATE_INIT 0507#define STATE_PRINCIPAL 1508#define STATE_OLDPWD 2509#define STATE_NEWPWD1 3510#define STATE_NEWPWD2 4511#define STATE_CLOSED 5512#define NEXTSTATE(newstate) SendMessage(hDialog, WM_COMMAND, ID_NEXTSTATE, newstate)513static int ids[STATE_NEWPWD2 + 1] = {5140,515ID_PRINCIPAL, ID_OLDPASSWORD, ID_CONFIRMPASSWORD1,516ID_CONFIRMPASSWORD2};517static char principal[255], oldpassword[255], newpassword[255],518newpassword2[255];519static char *strings[STATE_NEWPWD2 + 1] = {520NULL, principal, oldpassword, newpassword, newpassword2};521static LPLSH_DLGINFO lpdi;522char gbuf[200]; /* global buffer for random stuff. */523524525#define checkfirst(id, stuff) IsDlgItem(hDialog, id) ? stuff : 0526#define CGetDlgItemText(hDlg, id, cp, len) checkfirst(id, GetDlgItemText(hDlg, id, cp, len))527#define CSetDlgItemText(hDlg, id, cp) checkfirst(id, SetDlgItemText(hDlg, id, cp))528#define CSetDlgItemInt(hDlg, id, i, b) checkfirst(id, SetDlgItemInt(hDlg, id, i, b))529#define CSendDlgItemMessage(hDlg, id, m, w, l) checkfirst(id, SendDlgItemMessage(hDlg, id, m, w, l))530#define CSendMessage(hwnd, m, w, l) IsWindow(hwnd) ? SendMessage(hwnd, m, w, l) : 0531#define CShowWindow(hwnd, state) IsWindow(hwnd) ? ShowWindow(hwnd, state) : 0532533#define GETITEMTEXT(id, cp, maxlen) \534GetDlgItemText(hDialog, id, (LPSTR)(cp), maxlen)535#define CloseMe(x) SendMessage(hDialog, WM_COMMAND, ID_CLOSEME, x)536537538#define EDITFRAMEIDOFFSET 500539540switch (message) {541542case WM_INITDIALOG:543544*( (LPLSH_DLGINFO far *)(&lpdi) ) = (LPLSH_DLGINFO)(LPSTR)lParam;545lpdi->dlgstatemax = ISCHPASSWD ? STATE_NEWPWD2546: STATE_OLDPWD;547SetWindowText(hDialog, lpdi->title);548/* stop at old password for normal password dlg */549550SetProp(hDialog, "HANDLES_HELP", (HANDLE)1);551552if (lpdi->principal)553lstrcpy(principal, lpdi->principal);554else555{556principal[0] = '\0';557/* is there a principal already being used? if so, use it. */558}559560CSetDlgItemText(hDialog, ID_PRINCIPAL, principal);561562lifetime = Leash_get_default_lifetime();563if (lifetime <= 0)564lifetime = 600; /* 10 hours */565566CSetDlgItemInt(hDialog, ID_DURATION, lifetime, FALSE);567568/* setup text of stuff. */569570if (Position.x > 0 && Position.y > 0 &&571Position.x < GetSystemMetrics(SM_CXSCREEN) &&572Position.y < GetSystemMetrics(SM_CYSCREEN))573SetWindowPos(hDialog, 0, Position.x, Position.y, 0, 0,574SWP_NOSIZE | SWP_NOZORDER);575576/* set window pos to last saved window pos */577578579/* replace standard edit control with our own password edit580control for password entry. */581{582RECT r;583POINT pxy, psz;584HWND hwnd;585int i;586587for (i = ID_OLDPASSWORD; i <= ids[lpdi->dlgstatemax]; i++)588{589hwnd = GetDlgItem(hDialog, i);590GetWindowRect(hwnd, &r);591psz.x = r.right - r.left;592psz.y = r.bottom - r.top;593594pxy.x = r.left; pxy.y = r.top;595ScreenToClient(hDialog, &pxy);596597/* create a substitute window: */598599DestroyWindow(hwnd);600/* kill off old edit window. */601602CreateWindow(MIT_PWD_DLL_CLASS, /* our password window :o] */603"", /* no text */604WS_CHILD | WS_VISIBLE | WS_TABSTOP, /* child window, visible,tabstop */605pxy.x, pxy.y, /* x, y coords */606psz.x, psz.y, /* width, height */607hDialog, /* the parent */608(HMENU)i, /* same id *//* id offset for the frames */609(HANDLE)hLeashInst,/* instance handles */610NULL); /* createstruct */611}612}613614state = STATE_INIT;615NEXTSTATE(STATE_PRINCIPAL);616break;617618case WM_PAINT:619PaintLogoBitmap( GetDlgItem(hDialog, ID_PICFRAME) );620break;621622case WM_COMMAND:623switch (wParam) {624case ID_HELP:625{626WinHelp(GetWindow(hDialog,GW_OWNER), KRB_HelpFile, HELP_CONTEXT,627ISCHPASSWD ? ID_CHANGEPASSWORD : ID_INITTICKETS);628}629break;630case ID_CLOSEME:631{632int i;633634for (i = STATE_PRINCIPAL; i <= lpdi->dlgstatemax; i++)635{636memset(strings[i], '\0', 255);637SetDlgItemText(hDialog, ids[i], "");638}639/* I claim these passwords in the name640of planet '\0'... */641642RemoveProp(hDialog, "HANDLES_HELP");643state = STATE_CLOSED;644EndDialog(hDialog, (int)lParam);645return TRUE;646}647break;648case ID_DURATION:649break;650case ID_PRINCIPAL:651case ID_OLDPASSWORD:652case ID_CONFIRMPASSWORD1:653case ID_CONFIRMPASSWORD2:654if (HIWORD(lParam) == EN_SETFOCUS)655{656/* nothing, for now. */657}658break;659case ID_NEXTSTATE:660{661RECT rbtn, redit;662POINT p;663int idfocus, i, s;664HWND hfocus, hbtn;665int oldstate = state;666667state = (int)lParam;668idfocus = ids[state];669670#ifdef ONE_NEWPWDBOX671if (state == STATE_NEWPWD2)672SendDlgItemMessage(hDialog, ID_CONFIRMPASSWORD1, WM_SETTEXT,6730, (LONG)(LPSTR)"");674#endif675676for (s = STATE_PRINCIPAL; s <= lpdi->dlgstatemax; s++)677{678i = ids[s];679680if (s > state)681SendDlgItemMessage(hDialog, i, WM_SETTEXT, 0,682(LONG)(LPSTR)"");683EnableWindow(GetDlgItem(hDialog, i), i == idfocus);684ShowWindow(GetDlgItem(hDialog, i),685(i <= idfocus ? SW_SHOW : SW_HIDE));686/* ShowWindow(GetDlgItem(hDialog, i + CAPTION_OFFSET),687(i <= idfocus ? SW_SHOW : SW_HIDE));*/688/* show caption? */689}690#ifdef ONE_NEWPWDBOX691CSetDlgItemText(hDialog, ID_CONFIRMCAPTION1,692state < STATE_NEWPWD2 ?693"Enter new password:" :694"Enter new password again:");695if (state == STATE_NEWPWD2)696{697HWND htext;698htext = GetDlgItem(hDialog, ID_CONFIRMCAPTION1);699FlashAnyWindow(htext);700WinSleep(50);701FlashAnyWindow(htext);702}703#endif704705hfocus = GetDlgItem(hDialog, idfocus);706if ( hfocus != (HWND)NULL ){707SetFocus(hfocus); /* switch focus */708if (idfocus >= ID_OLDPASSWORD)709SendMessage(hfocus, WM_SETTEXT, 0, (LPARAM) (LPSTR) "");710else711{712SendMessage(hfocus, EM_SETSEL, 0, MAKELONG(0, -1));713}714GetWindowRect(hfocus, &redit);715}716717hbtn = GetDlgItem(hDialog, IDOK);718if( IsWindow(hbtn) ){719GetWindowRect(hbtn, &rbtn);720p.x = rbtn.left; p.y = redit.top;721ScreenToClient(hDialog, &p);722723SetWindowPos(hbtn, 0, p.x, p.y, 0, 0,724SWP_NOSIZE | SWP_NOZORDER);725}726}727break;728case IDOK:729{730char* p_Principal;731DWORD value = 0;732733GETITEMTEXT(ids[state], (LPSTR)strings[state], 255);734735switch(state)736{737case STATE_PRINCIPAL:738{739if (!principal[0])740{741MessageBox(hDialog,742"You are not allowed to enter a blank principal.",743"Invalid Principal",744MB_OK | MB_ICONSTOP);745NEXTSTATE(STATE_PRINCIPAL);746return TRUE;747}748749// Change 'principal' to upper case after checking750// "UpperCase" value in the Registry751p_Principal = strchr(principal, '@');752753if (p_Principal && Leash_get_default_uppercaserealm())754strupr(p_Principal);755break;756}757case STATE_OLDPWD:758{759int duration;760761if (!ISCHPASSWD)762duration = GetDlgItemInt(hDialog, ID_DURATION, 0, FALSE);763if (!oldpassword[0])764{765MessageBox(hDialog, "You are not allowed to enter a "766"blank password.",767"Invalid Password",768MB_OK | MB_ICONSTOP);769NEXTSTATE(STATE_OLDPWD);770return TRUE;771}772if (lpdi->dlgtype == DLGTYPE_CHPASSWD)773lsh_errno = Leash_int_checkpwd(principal, oldpassword, 1);774else775{776lsh_errno = Leash_int_kinit_ex( 0,777hDialog,778principal,779oldpassword,780duration,781Leash_get_default_forwardable(),782Leash_get_default_proxiable(),783Leash_get_default_renew_till(),784Leash_get_default_noaddresses(),785Leash_get_default_publicip(),7861787);788}789if (lsh_errno != 0)790{791int next_state = state;792int capslock;793char *cp;794795err_context = "";796797switch(lsh_errno)798{799case LSH_INVPRINCIPAL:800case LSH_INVINSTANCE:801case LSH_INVREALM:802next_state = STATE_PRINCIPAL;803break;804}805capslock = lsh_getkeystate(VK_CAPITAL);806/* low-order bit means caps lock is807toggled; if so, warn user since there's808been an error. */809if (capslock & 1)810{811lstrcpy((LPSTR)gbuf, (LPSTR)err_context);812cp = gbuf + lstrlen((LPSTR)gbuf);813if (cp != gbuf)814*cp++ = ' ';815lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");816err_context = gbuf;817}818819// XXX DoNiftyErrorReport(lsh_errno, ISCHPASSWD ? ""820// XXX : "Ticket initialization failed.");821NEXTSTATE(next_state);822return TRUE;823}824if (ISCHPASSWD)825break;826CloseMe(TRUE); /* success */827}828break;829case STATE_NEWPWD1:830{831int i = 0;832int bit8 = 0;833834for( i = 0; i < 255; i++ ){835if( newpassword[i] == '\0' ){836if ( bit8 ) {837MessageBox(hDialog,838"Passwords should not contain non-ASCII characters.",839"Internationalization Warning",840MB_OK | MB_ICONINFORMATION);841}842i = 255;843break;844} else if( !isprint(newpassword[i]) ){845memset(newpassword, '\0', 255);846/* I claim these passwords in the name of planet '\0'... */847MessageBox(hDialog,848"Passwords may not contain non-printable characters.",849"Invalid Password",850MB_OK | MB_ICONSTOP);851NEXTSTATE(STATE_NEWPWD1);852return TRUE;853} else if ( newpassword[i] > 127 )854bit8 = 1;855}856}857break;858case STATE_NEWPWD2:859if (lstrcmp(newpassword, newpassword2))860{861NEXTSTATE(STATE_NEWPWD1);862MessageBox(hDialog,863"The new password was not entered the same way twice.",864"Password validation error",865MB_OK | MB_ICONSTOP);866return TRUE;867}868else869{870/* make them type both pwds again if error */871int next_state = STATE_NEWPWD1;872int capslock;873char *cp;874875capslock = lsh_getkeystate(VK_CAPITAL);876/* low-order bit means caps lock is877toggled; if so, warn user since there's878been an error. */879if (capslock & 1)880{881lstrcpy((LPSTR)gbuf, (LPSTR)err_context);882cp = gbuf + lstrlen((LPSTR)gbuf);883if (cp != gbuf)884*cp++ = ' ';885lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");886err_context = gbuf;887}888889if ((lsh_errno =890Leash_int_changepwd(principal, oldpassword,891newpassword, 0, 1))892== 0){893CloseMe(TRUE);894}895else {896// XXX - DoNiftyErrorReport(lsh_errno, "Error while changing password.");897NEXTSTATE(next_state);898return TRUE;899900}901}902break;903}904/* increment state, but send the old state as a905parameter */906SendMessage(hDialog, WM_COMMAND, ID_NEXTSTATE, state + 1);907}908break;909case IDCANCEL:910CloseMe(FALSE);911break;912case ID_RESTART:913{914int i;915916for (i = ID_OLDPASSWORD; i <= ids[lpdi->dlgstatemax]; i++)917SetDlgItemText(hDialog, i, "");918SendMessage(hDialog, WM_COMMAND, ID_NEXTSTATE,919STATE_PRINCIPAL);920}921break;922}923break;924925case WM_MOVE:926if (state != STATE_CLOSED)927#ifdef _WIN32928#define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), \929(pt).y=(SHORT)HIWORD(l))930LONG2POINT(lParam,Position);931#else932Position = MAKEPOINT(lParam);933#endif934break;935}936return FALSE;937}938939940#define KRB_FILE "KRB.CON"941#define KRBREALM_FILE "KRBREALM.CON"942#define KRB5_FILE "KRB5.INI"943944BOOL945GetProfileFile(946LPSTR confname,947UINT szConfname948)949{950char **configFile = NULL;951if (hKrb5 &&952pkrb5_get_default_config_files(&configFile))953{954GetWindowsDirectory(confname,szConfname);955confname[szConfname-1] = '\0';956strncat(confname, "\\",sizeof(confname)-strlen(confname));957confname[szConfname-1] = '\0';958strncat(confname, KRB5_FILE,sizeof(confname)-strlen(confname));959confname[szConfname-1] = '\0';960return FALSE;961}962963*confname = 0;964965if (hKrb5 && configFile)966{967strncpy(confname, *configFile, szConfname);968pkrb5_free_config_files(configFile);969}970971if (!*confname)972{973GetWindowsDirectory(confname,szConfname);974confname[szConfname-1] = '\0';975strncat(confname, "\\",sizeof(confname)-strlen(confname));976confname[szConfname-1] = '\0';977strncat(confname, KRB5_FILE,sizeof(confname)-strlen(confname));978confname[szConfname-1] = '\0';979}980981return FALSE;982}983984int985readstring(FILE * file, char * buf, int len)986{987int c,i;988memset(buf, '\0', sizeof(buf));989for (i=0, c=fgetc(file); c != EOF ; c=fgetc(file), i++)990{991if (i < sizeof(buf)) {992if (c == '\n') {993buf[i] = '\0';994return i;995} else {996buf[i] = c;997}998} else {999if (c == '\n') {1000buf[len-1] = '\0';1001return(i);1002}1003}1004}1005if (c == EOF) {1006if (i > 0 && i < len) {1007buf[i] = '\0';1008return(i);1009} else {1010buf[len-1] = '\0';1011return(-1);1012}1013}1014return(-1);1015}10161017typedef struct _slider_info {1018int slider_id;1019int text_id;1020int min;1021int max;1022int increment;1023struct _slider_info * next;1024} slider_info;1025static slider_info * sliders = NULL;10261027static slider_info *1028FreeSlider(slider_info * s)1029{1030slider_info * n = NULL;10311032if (s) {1033n = s->next;1034free(s);1035}1036return n;1037}10381039static void1040CleanupSliders(void)1041{1042while(sliders)1043sliders = FreeSlider(sliders);1044}104510461047static unsigned short1048NewSliderValue(HWND hDialog, int id)1049{1050int value = 0;1051slider_info * s = sliders;1052while(s) {1053if (s->slider_id == id) {1054int pos = CSendDlgItemMessage( hDialog, id,1055TBM_GETPOS,1056(WPARAM) 0, (LPARAM) 0);1057value = s->min + (pos * s->increment);1058break;1059}1060s = s->next;1061}1062return(value);1063}10641065static const char *1066NewSliderString(int id, int pos)1067{1068static char buf[64]="";1069char * p = buf;1070int value = 0;1071int must_hours = 0;1072slider_info * s = sliders;1073while(s) {1074if (s->slider_id == id) {1075value = s->min + pos * s->increment;1076*p = 0;1077if (value >= 60 * 24) {1078sprintf(p,"%d day(s) ",value / (60 * 24));1079value %= (60 * 24);1080p += strlen(p);1081must_hours = 1;1082}1083if (must_hours || value >= 60) {1084sprintf(p,"%d hour(s) ",value / 60);1085value %= 60;1086p += strlen(p);1087}1088sprintf(p,"%d minute(s) ",value);1089break;1090}1091s = s->next;1092}1093return(buf);1094}10951096static void1097SetupSlider( HWND hDialog,1098int sliderID,1099int textFieldID,1100int minimum,1101int maximum,1102int value)1103{1104int min = minimum;1105int max = maximum;1106int increment = 0;1107int range;1108int roundedMinimum;1109int roundedMaximum;1110int roundedValue;1111slider_info * new_info;11121113if (max < min) {1114// swap values1115int temp = max;1116max = min;1117min = temp;1118}1119range = max - min;11201121if (range < 5*60) { increment = 1; // 1 s if under 5 m1122} else if (range < 30*60) { increment = 5; // 5 s if under 30 m1123} else if (range < 60*60) { increment = 15; // 15 s if under 1 h1124} else if (range < 2*60*60) { increment = 30; // 30 s if under 2 h1125} else if (range < 5*60*60) { increment = 60; // 1 m if under 5 h1126} else if (range < 50*60*60) { increment = 5*60; // 5 m if under 50 h1127} else if (range < 200*60*60) { increment = 15*60; // 15 m if under 200 h1128} else if (range < 500*60*60) { increment = 30*60; // 30 m if under 500 h1129} else { increment = 60*60; } // 1 h otherwise11301131roundedMinimum = (min / increment) * increment;1132if (roundedMinimum > min) { roundedMinimum -= increment; }1133if (roundedMinimum <= 0) { roundedMinimum += increment; } // make positive11341135roundedMaximum = (max / increment) * increment;1136if (roundedMaximum < max) { roundedMaximum += increment; }11371138roundedValue = (value / increment) * increment;1139if (roundedValue < roundedMinimum) { roundedValue = roundedMinimum; }1140if (roundedValue > roundedMaximum) { roundedValue = roundedMaximum; }11411142if (roundedMinimum == roundedMaximum) {1143// [textField setTextColor: [NSColor grayColor]];1144EnableWindow(GetDlgItem(hDialog,sliderID),FALSE);1145} else {1146// [textField setTextColor: [NSColor blackColor]];1147EnableWindow(GetDlgItem(hDialog,sliderID),TRUE);1148}11491150CSendDlgItemMessage( hDialog, sliderID,1151TBM_SETRANGEMIN,1152(WPARAM) FALSE,1153(LPARAM) 0 );1154CSendDlgItemMessage( hDialog, sliderID,1155TBM_SETRANGEMAX,1156(WPARAM) FALSE,1157(LPARAM) (roundedMaximum - roundedMinimum) / increment );1158CSendDlgItemMessage( hDialog, sliderID,1159TBM_SETPOS,1160(WPARAM) TRUE,1161(LPARAM) (roundedValue - roundedMinimum) / increment);11621163new_info = (slider_info *) malloc(sizeof(slider_info));1164new_info->slider_id = sliderID;1165new_info->text_id = textFieldID;1166new_info->min = roundedMinimum;1167new_info->max = roundedMaximum;1168new_info->increment = increment;1169new_info->next = sliders;1170sliders = new_info;11711172SetWindowText(GetDlgItem(hDialog, textFieldID),1173NewSliderString(sliderID,(roundedValue - roundedMinimum) / increment));1174}117511761177static void1178AdjustOptions(HWND hDialog, int show, int hideDiff)1179{1180RECT rect;1181RECT dlgRect;1182HWND hwnd;1183int diff;11841185Leash_set_hide_kinit_options(!show);11861187ShowWindow(GetDlgItem(hDialog,IDC_STATIC_LIFETIME),show);1188ShowWindow(GetDlgItem(hDialog,IDC_STATIC_LIFETIME_VALUE),show);1189ShowWindow(GetDlgItem(hDialog,IDC_SLIDER_LIFETIME),show);1190ShowWindow(GetDlgItem(hDialog,IDC_SLIDER_RENEWLIFE),show);1191ShowWindow(GetDlgItem(hDialog,IDC_STATIC_RENEW),show);1192ShowWindow(GetDlgItem(hDialog,IDC_STATIC_RENEW_TILL_VALUE),show);1193ShowWindow(GetDlgItem(hDialog,IDC_CHECK_FORWARDABLE),show);1194ShowWindow(GetDlgItem(hDialog,IDC_CHECK_NOADDRESS),show);1195ShowWindow(GetDlgItem(hDialog,IDC_CHECK_RENEWABLE),show);1196ShowWindow(GetDlgItem(hDialog,IDC_STATIC_KRB5),show);1197ShowWindow(GetDlgItem(hDialog,IDC_BUTTON_CLEAR_HISTORY),show);11981199GetWindowRect( hDialog, &dlgRect );1200diff = dlgRect.top + GetSystemMetrics(SM_CYCAPTION)1201+ GetSystemMetrics(SM_CYDLGFRAME) + (show ? -1 : 1) * hideDiff;12021203hwnd = GetDlgItem(hDialog,IDOK);1204GetWindowRect(hwnd,&rect);1205SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);1206hwnd = GetDlgItem(hDialog,IDCANCEL);1207GetWindowRect(hwnd,&rect);1208SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);1209hwnd = GetDlgItem(hDialog,IDC_BUTTON_OPTIONS);1210GetWindowRect(hwnd,&rect);1211SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);1212hwnd = GetDlgItem(hDialog,IDC_STATIC_VERSION);1213GetWindowRect(hwnd,&rect);1214SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);1215hwnd = GetDlgItem(hDialog,IDC_STATIC_COPYRIGHT);1216GetWindowRect(hwnd,&rect);1217SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);1218SetWindowPos(hDialog,0,0,0,1219dlgRect.right-dlgRect.left,1220dlgRect.bottom-dlgRect.top+(show ? 1 : - 1) * hideDiff,1221SWP_NOZORDER|SWP_NOMOVE);12221223CSetDlgItemText(hDialog, IDC_BUTTON_OPTIONS,1224show ? "Hide Advanced" : "Show Advanced");12251226}12271228/* Callback function for the Authentication Dialog box that initializes and1229renews tickets. */12301231INT_PTR1232CALLBACK1233AuthenticateProc(1234HWND hDialog,1235UINT message,1236WPARAM wParam,1237LPARAM lParam1238)1239{1240static POINT Position = { -1, -1 };1241static char principal[256]="";1242static char password[256]="";1243static int lifetime=0;1244static int renew_till=0;1245static int forwardable=0;1246static int noaddresses=0;1247static int proxiable=0;1248static int publicip=0;1249static LPLSH_DLGINFO_EX lpdi;1250static HWND hDlg=0;1251static HWND hSliderLifetime=0;1252static HWND hSliderRenew=0;1253static RECT dlgRect;1254static int hideDiff = 0;1255static void *pAutoComplete = 0;1256long realm_count = 0;1257int disable_noaddresses = 0;1258HWND hEditCtrl=0;1259HWND hFocusCtrl=0;1260BOOL bReadOnlyPrinc=0;12611262switch (message) {12631264case WM_INITDIALOG:1265hDlg = hDialog;12661267hEditCtrl = GetDlgItem(hDialog, IDC_EDIT_PRINCIPAL);1268if (hEditCtrl)1269pAutoComplete = Leash_pec_create(hEditCtrl);1270hSliderLifetime = GetDlgItem(hDialog, IDC_STATIC_LIFETIME_VALUE);1271hSliderRenew = GetDlgItem(hDialog, IDC_STATIC_RENEW_TILL_VALUE);12721273*( (LPLSH_DLGINFO_EX far *)(&lpdi) ) = (LPLSH_DLGINFO_EX)(LPSTR)lParam;12741275if ((lpdi->size != LSH_DLGINFO_EX_V1_SZ &&1276lpdi->size != LSH_DLGINFO_EX_V2_SZ &&1277lpdi->size < LSH_DLGINFO_EX_V3_SZ) ||1278(lpdi->dlgtype & DLGTYPE_MASK) != DLGTYPE_PASSWD) {12791280MessageBox(hDialog, "An incorrect initialization data structure was provided.",1281"AuthenticateProc()",1282MB_OK | MB_ICONSTOP);1283return FALSE;1284}1285bReadOnlyPrinc = (lpdi->dlgtype & DLGFLAG_READONLYPRINC) ?1286TRUE : FALSE;12871288if ( lpdi->size >= LSH_DLGINFO_EX_V2_SZ ) {1289lpdi->out.username[0] = 0;1290lpdi->out.realm[0] = 0;1291}1292if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ ) {1293lpdi->out.ccache[0] = 0;1294}12951296if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ )1297SetWindowText(hDialog, lpdi->in.title);1298else1299SetWindowText(hDialog, lpdi->title);13001301SetProp(hDialog, "HANDLES_HELP", (HANDLE)1);1302if (lpdi->use_defaults) {1303lifetime = Leash_get_default_lifetime();1304if (lifetime <= 0)1305lifetime = 600; /* 10 hours */1306if (Leash_get_default_renewable()) {1307renew_till = Leash_get_default_renew_till();1308if (renew_till < 0)1309renew_till = 10800; /* 7 days */1310} else1311renew_till = 0;1312forwardable = Leash_get_default_forwardable();1313if (forwardable < 0)1314forwardable = 0;1315noaddresses = Leash_get_default_noaddresses();1316if (noaddresses < 0)1317noaddresses = 0;1318proxiable = Leash_get_default_proxiable();1319if (proxiable < 0)1320proxiable = 0;1321publicip = Leash_get_default_publicip();1322if (publicip < 0)1323publicip = 0;1324} else {1325forwardable = lpdi->forwardable;1326noaddresses = lpdi->noaddresses;1327lifetime = lpdi->lifetime;1328renew_till = lpdi->renew_till;1329proxiable = lpdi->proxiable;1330publicip = lpdi->publicip;1331}1332if (lpdi->username && (strlen(lpdi->username) > 0) &&1333lpdi->realm && (strlen(lpdi->realm) > 0)) {1334sprintf_s(principal, sizeof(principal), "%s@%s", lpdi->username,1335lpdi->realm);1336} else {1337principal[0] = 0;1338}1339Edit_SetReadOnly(hEditCtrl, bReadOnlyPrinc);1340CSetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal);1341CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD, "");13421343/* Set Lifetime Slider1344* min value = 51345* max value = 14401346* current value1347*/13481349SetupSlider( hDialog,1350IDC_SLIDER_LIFETIME,1351IDC_STATIC_LIFETIME_VALUE,1352Leash_get_default_life_min(),1353Leash_get_default_life_max(),1354lifetime );13551356CheckDlgButton(hDialog, IDC_CHECK_REMEMBER_PRINCIPAL, TRUE);1357/* Set Forwardable checkbox */1358CheckDlgButton(hDialog, IDC_CHECK_FORWARDABLE, forwardable);1359/* Set NoAddress checkbox */1360CheckDlgButton(hDialog, IDC_CHECK_NOADDRESS, noaddresses);1361if ( disable_noaddresses )1362EnableWindow(GetDlgItem(hDialog,IDC_CHECK_NOADDRESS),FALSE);1363/* Set Renewable checkbox */1364CheckDlgButton(hDialog, IDC_CHECK_RENEWABLE, renew_till);1365/* if not renewable, disable Renew Till slider */1366/* if renewable, set Renew Till slider1367* min value1368* max value1369* current value1370*/1371SetupSlider( hDialog,1372IDC_SLIDER_RENEWLIFE,1373IDC_STATIC_RENEW_TILL_VALUE,1374Leash_get_default_renew_min(),1375Leash_get_default_renew_max(),1376renew_till);1377if (renew_till) {1378EnableWindow(GetDlgItem(hDialog,IDC_SLIDER_RENEWLIFE),TRUE);1379} else {1380EnableWindow(GetDlgItem(hDialog,IDC_SLIDER_RENEWLIFE),FALSE);1381}13821383// Compute sizes of items necessary to show/hide the advanced options1384GetWindowRect( hDialog, &dlgRect );1385{1386RECT okRect, staticRect;1387GetWindowRect(GetDlgItem(hDialog,IDC_STATIC_LIFETIME),&staticRect);1388GetWindowRect(GetDlgItem(hDialog,IDOK),&okRect);1389hideDiff = okRect.top - staticRect.top;1390}13911392if ( hKrb5 ) {1393if (Leash_get_hide_kinit_options())1394AdjustOptions(hDialog,0,hideDiff);1395} else {1396AdjustOptions(hDialog,0,hideDiff);1397EnableWindow(GetDlgItem(hDialog,IDC_BUTTON_OPTIONS),FALSE);1398ShowWindow(GetDlgItem(hDialog,IDC_BUTTON_OPTIONS),SW_HIDE);1399}14001401/* setup text of stuff. */14021403if (Position.x > 0 && Position.y > 0 &&1404Position.x < GetSystemMetrics(SM_CXSCREEN) &&1405Position.y < GetSystemMetrics(SM_CYSCREEN))1406SetWindowPos(hDialog, HWND_TOP, Position.x, Position.y, 0, 0, SWP_NOSIZE);1407else /* Center the window on the desktop */1408SetWindowPos(hDialog, HWND_TOP,1409(GetSystemMetrics(SM_CXSCREEN) - dlgRect.right + dlgRect.left)/2,1410(GetSystemMetrics(SM_CYSCREEN) - dlgRect.bottom + dlgRect.top)/2,14110, 0,1412SWP_NOSIZE);14131414/* Take keyboard focus */1415SetActiveWindow(hDialog);1416SetForegroundWindow(hDialog);1417/* put focus on password if princ is read-only */1418hFocusCtrl = (bReadOnlyPrinc || principal[0] != '\0') ?1419GetDlgItem(hDialog, IDC_EDIT_PASSWORD) : hEditCtrl;1420if (((HWND)wParam) != hFocusCtrl) {1421SetFocus(hFocusCtrl);1422}1423break;14241425case WM_HSCROLL:1426switch (LOWORD(wParam)) {1427case TB_THUMBTRACK:1428case TB_THUMBPOSITION:1429{1430long pos = HIWORD(wParam); // the position of the slider1431int ctrlID = GetDlgCtrlID((HWND)lParam);14321433if (ctrlID == IDC_SLIDER_RENEWLIFE) {1434SetWindowText(GetDlgItem(hDialog, IDC_STATIC_RENEW_TILL_VALUE),1435NewSliderString(IDC_SLIDER_RENEWLIFE,pos));1436}1437if (ctrlID == IDC_SLIDER_LIFETIME) {1438SetWindowText(GetDlgItem(hDialog, IDC_STATIC_LIFETIME_VALUE),1439NewSliderString(IDC_SLIDER_LIFETIME,pos));1440}1441}1442break;1443case TB_BOTTOM:1444case TB_TOP:1445case TB_ENDTRACK:1446case TB_LINEDOWN:1447case TB_LINEUP:1448case TB_PAGEDOWN:1449case TB_PAGEUP:1450default:1451{1452int ctrlID = GetDlgCtrlID((HWND)lParam);1453long pos = SendMessage(GetDlgItem(hDialog,ctrlID), TBM_GETPOS, 0, 0); // the position of the slider14541455if (ctrlID == IDC_SLIDER_RENEWLIFE) {1456SetWindowText(GetDlgItem(hDialog, IDC_STATIC_RENEW_TILL_VALUE),1457NewSliderString(IDC_SLIDER_RENEWLIFE,pos));1458}1459if (ctrlID == IDC_SLIDER_LIFETIME) {1460SetWindowText(GetDlgItem(hDialog, IDC_STATIC_LIFETIME_VALUE),1461NewSliderString(IDC_SLIDER_LIFETIME,pos));1462}1463}1464}1465break;14661467case WM_COMMAND:1468switch (wParam) {1469case IDC_BUTTON_OPTIONS:1470{1471AdjustOptions(hDialog,Leash_get_hide_kinit_options(),hideDiff);1472GetWindowRect(hDialog,&dlgRect);1473if ( dlgRect.bottom > GetSystemMetrics(SM_CYSCREEN))1474SetWindowPos( hDialog,0,1475dlgRect.left,1476GetSystemMetrics(SM_CYSCREEN) - dlgRect.bottom + dlgRect.top,14770,0,1478SWP_NOZORDER|SWP_NOSIZE);14791480}1481break;1482case IDC_BUTTON_CLEAR_HISTORY:1483Leash_pec_clear_history(pAutoComplete);1484break;1485case IDC_CHECK_RENEWABLE:1486{1487if (IsDlgButtonChecked(hDialog, IDC_CHECK_RENEWABLE)) {1488EnableWindow(hSliderRenew,TRUE);1489} else {1490EnableWindow(hSliderRenew,FALSE);1491}1492}1493break;1494case ID_HELP:1495{1496WinHelp(GetWindow(hDialog,GW_OWNER), KRB_HelpFile, HELP_CONTEXT,1497ID_INITTICKETS);1498}1499break;1500case ID_CLOSEME:1501{1502CleanupSliders();1503memset(password,0,sizeof(password));1504RemoveProp(hDialog, "HANDLES_HELP");1505if (pAutoComplete) {1506Leash_pec_destroy(pAutoComplete);1507pAutoComplete = NULL;1508}1509EndDialog(hDialog, (int)lParam);1510return TRUE;1511}1512break;1513case IDOK:1514{1515DWORD value = 0;15161517CGetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal, sizeof(principal));1518CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD, password, sizeof(password));15191520if (!principal[0]) {1521MessageBox(hDialog,1522"You are not allowed to enter a blank principal.",1523"Invalid Principal",1524MB_OK | MB_ICONSTOP);1525return TRUE;1526}1527// @TODO: parse realm portion and auto-uppercase1528/*1529if (Leash_get_default_uppercaserealm())1530{1531// found1532strupr(realm);1533}1534*/15351536if (!password[0])1537{1538MessageBox(hDialog,1539"You are not allowed to enter a blank password.",1540"Invalid Password",1541MB_OK | MB_ICONSTOP);1542return TRUE;1543}15441545lifetime = NewSliderValue(hDialog, IDC_SLIDER_LIFETIME);15461547forwardable = proxiable =1548IsDlgButtonChecked(hDialog, IDC_CHECK_FORWARDABLE);1549noaddresses = IsDlgButtonChecked(hDialog, IDC_CHECK_NOADDRESS);1550if (IsDlgButtonChecked(hDialog, IDC_CHECK_RENEWABLE)) {1551renew_till = NewSliderValue(hDialog, IDC_SLIDER_RENEWLIFE);1552} else {1553renew_till= 0;1554}15551556lsh_errno = Leash_int_kinit_ex( 0,1557hDialog,1558principal, password, lifetime,1559forwardable,1560proxiable,1561renew_till,1562noaddresses,1563publicip,156411565);1566if (lsh_errno != 0)1567{1568#ifdef COMMENT1569char gbuf[256];1570int capslock;1571char *cp;1572#endif1573err_context = "";1574switch(lsh_errno)1575{1576case LSH_INVPRINCIPAL:1577case LSH_INVINSTANCE:1578CSendDlgItemMessage(hDialog, IDC_EDIT_PRINCIPAL, EM_SETSEL, 0, 256);1579SetFocus(GetDlgItem(hDialog,IDC_EDIT_PRINCIPAL));1580break;1581case LSH_INVREALM:1582CSendDlgItemMessage(hDialog, IDC_COMBO_REALM, EM_SETSEL, 0, 256);1583SetFocus(GetDlgItem(hDialog,IDC_COMBO_REALM));1584break;1585default:1586CSendDlgItemMessage(hDialog, IDC_EDIT_PASSWORD, EM_SETSEL, 0, 256);1587SetFocus(GetDlgItem(hDialog,IDC_EDIT_PASSWORD));1588return(TRUE);1589}1590#ifdef COMMENT1591capslock = lsh_getkeystate(VK_CAPITAL);1592/* low-order bit means caps lock is1593toggled; if so, warn user since there's1594been an error. */1595if (capslock & 1)1596{1597lstrcpy((LPSTR)gbuf, (LPSTR)err_context);1598cp = gbuf + lstrlen((LPSTR)gbuf);1599if (cp != gbuf)1600*cp++ = ' ';1601lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");1602err_context = gbuf;1603}16041605// XXX DoNiftyErrorReport(lsh_errno, ISCHPASSWD ? ""1606// XXX : "Ticket initialization failed.");1607#endif /* COMMENT */1608return TRUE;1609}16101611if ( Leash_get_default_preserve_kinit_settings() )1612{1613Leash_set_default_lifetime(lifetime);1614if ( renew_till > 0 ) {1615Leash_set_default_renew_till(renew_till);1616Leash_set_default_renewable(1);1617} else {1618Leash_set_default_renewable(0);1619}1620Leash_set_default_forwardable(forwardable);1621Leash_set_default_noaddresses(noaddresses);1622}1623/* @TODO: out username/realm1624if ( lpdi->size >= LSH_DLGINFO_EX_V2_SZ ) {1625strncpy(lpdi->out.username, username, LEASH_USERNAME_SZ);1626lpdi->out.username[LEASH_USERNAME_SZ-1] = 0;1627strncpy(lpdi->out.realm, realm, LEASH_REALM_SZ);1628lpdi->out.realm[LEASH_REALM_SZ-1] = 0;1629}1630*/1631if (IsDlgButtonChecked(hDialog, IDC_CHECK_REMEMBER_PRINCIPAL))1632Leash_pec_add_principal(principal);16331634CloseMe(TRUE); /* success */1635return FALSE;1636}1637break;1638case IDCANCEL:1639CloseMe(FALSE);1640break;1641}1642break;16431644case WM_MOVE:1645#ifdef _WIN321646#define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), \1647(pt).y=(SHORT)HIWORD(l))1648LONG2POINT(lParam,Position);1649#else1650Position = MAKEPOINT(lParam);1651#endif1652break;1653}1654return FALSE;1655}16561657/* Callback function for the Change Password Dialog box */16581659INT_PTR1660CALLBACK1661NewPasswordProc(1662HWND hDialog,1663UINT message,1664WPARAM wParam,1665LPARAM lParam1666)1667{1668static POINT Position = { -1, -1 };1669static char password[256]="";1670static char password2[256]="";1671static char password3[256]="";1672static LPLSH_DLGINFO_EX lpdi;1673static HWND hDlg=0;1674static void *pAutoComplete = NULL;1675char principal[256];1676long realm_count = 0;1677HWND hEditCtrl = NULL;16781679switch (message) {16801681case WM_INITDIALOG:1682hDlg = hDialog;16831684*( (LPLSH_DLGINFO_EX far *)(&lpdi) ) = (LPLSH_DLGINFO_EX)(LPSTR)lParam;16851686if ((lpdi->size < LSH_DLGINFO_EX_V3_SZ &&1687lpdi->size != LSH_DLGINFO_EX_V1_SZ &&1688lpdi->size != LSH_DLGINFO_EX_V2_SZ) ||1689lpdi->dlgtype != DLGTYPE_CHPASSWD) {16901691MessageBox(hDialog, "An incorrect initialization data structure was provided.",1692"PasswordProc()",1693MB_OK | MB_ICONSTOP);1694return FALSE;1695}16961697if ( lpdi->size >= LSH_DLGINFO_EX_V2_SZ ) {1698lpdi->out.username[0] = 0;1699lpdi->out.realm[0] = 0;1700}1701if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ ) {1702lpdi->out.ccache[0] = 0;1703}17041705if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ )1706SetWindowText(hDialog, lpdi->in.title);1707else1708SetWindowText(hDialog, lpdi->title);17091710SetProp(hDialog, "HANDLES_HELP", (HANDLE)1);17111712if (lpdi->username != NULL && (strlen(lpdi->username) > 0) &&1713lpdi->realm != NULL && (strlen(lpdi->realm) > 0)) {1714sprintf_s(principal,1715sizeof(principal), "%s@%s", lpdi->username, lpdi->realm);1716} else {1717principal[0] = 0;1718}17191720CSetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal);1721CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD, "");1722CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD2, "");1723CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD3, "");17241725hEditCtrl = GetDlgItem(hDialog, IDC_EDIT_PRINCIPAL);1726if (hEditCtrl)1727pAutoComplete = Leash_pec_create(hEditCtrl);17281729/* setup text of stuff. */17301731if (Position.x > 0 && Position.y > 0 &&1732Position.x < GetSystemMetrics(SM_CXSCREEN) &&1733Position.y < GetSystemMetrics(SM_CYSCREEN))1734SetWindowPos(hDialog, 0, Position.x, Position.y, 0, 0,1735SWP_NOSIZE | SWP_NOZORDER);1736else { /* Center the window on the desktop */1737RECT dlgRect;1738GetWindowRect( hDialog, &dlgRect );1739SetWindowPos(hDialog, 0,1740(GetSystemMetrics(SM_CXSCREEN) - dlgRect.right + dlgRect.left)/2,1741(GetSystemMetrics(SM_CYSCREEN) - dlgRect.bottom + dlgRect.top)/2,17420, 0,1743SWP_NOSIZE | SWP_NOZORDER);1744}1745/* set window pos to last saved window pos */1746break;17471748case WM_COMMAND:1749switch (wParam) {1750case ID_HELP:1751{1752WinHelp(GetWindow(hDialog,GW_OWNER), KRB_HelpFile, HELP_CONTEXT,1753ID_INITTICKETS);1754}1755break;1756case ID_CLOSEME:1757{1758CleanupSliders();1759memset(password,0,sizeof(password));1760memset(password2,0,sizeof(password2));1761memset(password3,0,sizeof(password3));1762RemoveProp(hDialog, "HANDLES_HELP");1763EndDialog(hDialog, (int)lParam);1764if (pAutoComplete != NULL) {1765Leash_pec_destroy(pAutoComplete);1766pAutoComplete = NULL;1767}1768return TRUE;1769}1770break;1771case IDOK:1772{1773DWORD value = 0;1774int i = 0;1775int bit8 = 0;17761777CGetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal, sizeof(principal));1778CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD, password, sizeof(password));1779CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD2, password2, sizeof(password2));1780CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD3, password3, sizeof(password3));17811782if (!principal[0])1783{1784MessageBox(hDialog, "You are not allowed to enter a "1785"blank username.",1786"Invalid Principal",1787MB_OK | MB_ICONSTOP);1788return TRUE;1789}17901791if (!password[0] || !password2[0] || !password3[0])1792{1793MessageBox(hDialog, "You are not allowed to enter a "1794"blank password.",1795"Invalid Password",1796MB_OK | MB_ICONSTOP);1797return TRUE;1798}17991800for( i = 0; i < 255; i++ ){1801if( password2[i] == '\0' ){1802if ( bit8 ) {1803MessageBox(hDialog,1804"Passwords should not contain non-ASCII characters.",1805"Internationalization Warning",1806MB_OK | MB_ICONINFORMATION);1807}1808i = 255;1809break;1810} else if( !isprint(password2[i]) ){1811memset(password2, '\0', sizeof(password2));1812memset(password3, '\0', sizeof(password3));1813/* I claim these passwords in the name of planet '\0'... */1814MessageBox(hDialog,1815"Passwords may not contain non-printable characters.",1816"Invalid Password",1817MB_OK | MB_ICONSTOP);1818return TRUE;1819} else if ( password2[i] > 127 )1820bit8 = 1;1821}18221823if (lstrcmp(password2, password3))1824{1825MessageBox(hDialog,1826"The new password was not entered the same way twice.",1827"Password validation error",1828MB_OK | MB_ICONSTOP);1829return TRUE;1830}18311832lsh_errno = Leash_int_changepwd(principal, password, password2, 0, 1);1833if (lsh_errno != 0)1834{1835#ifdef COMMENT1836char gbuf[256];1837int capslock;1838char *cp;1839#endif /* COMMENT */18401841err_context = "";1842switch(lsh_errno)1843{1844case LSH_INVPRINCIPAL:1845case LSH_INVINSTANCE:1846case LSH_INVREALM:1847break;1848default:1849return(TRUE);1850}1851#ifdef COMMENT1852capslock = lsh_getkeystate(VK_CAPITAL);1853/* low-order bit means caps lock is1854toggled; if so, warn user since there's1855been an error. */1856if (capslock & 1)1857{1858lstrcpy((LPSTR)gbuf, (LPSTR)err_context);1859cp = gbuf + lstrlen((LPSTR)gbuf);1860if (cp != gbuf)1861*cp++ = ' ';1862lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");1863err_context = gbuf;1864}18651866// XXX DoNiftyErrorReport(lsh_errno, ISCHPASSWD ? ""1867// XXX : "Ticket initialization failed.");1868#endif /* COMMENT */1869return TRUE;1870}1871Leash_pec_add_principal(principal);1872MessageBox(NULL, "Password successfully changed.",1873"Password change", MB_OK);1874CloseMe(TRUE); /* success */1875}1876break;1877case IDCANCEL:1878CloseMe(FALSE);1879break;1880}1881break;18821883case WM_MOVE:1884#ifdef _WIN321885#define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), \1886(pt).y=(SHORT)HIWORD(l))1887LONG2POINT(lParam,Position);1888#else1889Position = MAKEPOINT(lParam);1890#endif1891break;1892}1893return FALSE;1894}189518961897