2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
14 #include <afs/param.h>
18 #include <WINNT/afsapplib.h>
19 #include "al_dynlink.h"
20 #include <WINNT/TaAfsAdmSvrClient.h>
24 * DEFINITIONS ________________________________________________________________
30 * VARIABLES __________________________________________________________________
36 * PROTOTYPES _________________________________________________________________
40 void OnExpiredCredentials (WPARAM wp
, LPARAM lp
);
42 HRESULT CALLBACK
OpenCell_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
43 void OpenCell_OnInitDialog (HWND hDlg
, LPOPENCELLDLG_PARAMS lpp
);
44 BOOL
OpenCell_OnOK (HWND hDlg
, LPOPENCELLDLG_PARAMS lpp
);
45 void OpenCell_OnCell (HWND hDlg
);
46 void OpenCell_Enable (HWND hDlg
, BOOL fEnable
);
47 void OpenCell_OnGotCreds (HWND hDlg
, LPARAM lp
);
49 HRESULT CALLBACK
NewCreds_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
50 void NewCreds_OnInitDialog (HWND hDlg
, LPCREDENTIALSDLG_PARAMS lpp
);
51 BOOL
NewCreds_OnOK (HWND hDlg
, LPCREDENTIALSDLG_PARAMS lpp
);
52 void NewCreds_OnLogin (HWND hDlg
);
53 void NewCreds_Enable (HWND hDlg
, BOOL fEnable
);
54 void NewCreds_GetOutParams (HWND hDlg
, LPCREDENTIALSDLG_PARAMS lpp
);
56 HRESULT CALLBACK
BadCreds_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
60 * ROUTINES ___________________________________________________________________
64 BOOL
AfsAppLib_CrackCredentials (UINT_PTR hCreds
, LPTSTR pszCell
, LPTSTR pszUser
, LPSYSTEMTIME pst
, ULONG
*pStatus
)
70 if ((idClient
= AfsAppLib_GetAdminServerClientID()) != 0)
72 rc
= asc_CredentialsCrack (idClient
, (PVOID
) hCreds
, pszCell
, pszUser
, pst
, &status
);
75 if (OpenClientLibrary())
77 char szUserA
[ cchRESOURCE
], szUser2A
[ cchRESOURCE
];
78 char szCellA
[ cchRESOURCE
];
79 unsigned long dateExpire
;
82 if (afsclient_TokenQuery ((PVOID
)hCreds
, &dateExpire
, szUserA
, szUser2A
, szCellA
, &fHasKasToken
, (afs_status_p
)&status
))
85 CopyAnsiToString (pszUser
, szUserA
);
86 CopyAnsiToString (pszCell
, szCellA
);
87 AfsAppLib_UnixTimeToSystemTime (pst
, dateExpire
);
93 if (!hCreds
&& pStatus
)
99 UINT_PTR
AfsAppLib_GetCredentials (LPCTSTR pszCell
, ULONG
*pStatus
)
105 if ((idClient
= AfsAppLib_GetAdminServerClientID()) != 0)
107 hCreds
= asc_CredentialsGet (idClient
, pszCell
, &status
);
110 if (OpenClientLibrary())
112 LPSTR pszCellA
= StringToAnsi (pszCell
);
114 afsclient_TokenGetExisting (pszCellA
, (PVOID
*)&hCreds
, (afs_status_p
)&status
);
116 FreeString (pszCellA
, pszCell
);
117 CloseClientLibrary();
120 if (!hCreds
&& pStatus
)
126 UINT_PTR
AfsAppLib_SetCredentials (LPCTSTR pszCell
, LPCTSTR pszUser
, LPCTSTR pszPassword
, ULONG
*pStatus
)
132 if ((idClient
= AfsAppLib_GetAdminServerClientID()) != 0)
134 hCreds
= asc_CredentialsSet (idClient
, pszCell
, pszUser
, pszPassword
, &status
);
137 if (OpenClientLibrary())
139 char szCellA
[ cchRESOURCE
];
140 char szUserA
[ cchRESOURCE
];
141 char szPasswordA
[ cchRESOURCE
];
142 CopyStringToAnsi (szCellA
, pszCell
);
143 CopyStringToAnsi (szUserA
, pszUser
);
144 CopyStringToAnsi (szPasswordA
, pszPassword
);
146 afsclient_TokenGetNew (szCellA
, szUserA
, szPasswordA
, (PVOID
*)&hCreds
, (afs_status_p
)&status
);
148 CloseClientLibrary();
153 PostMessage (AfsAppLib_GetMainWindow(), WM_REFRESHED_CREDENTIALS
, 0, (LPARAM
)hCreds
);
156 if (!hCreds
&& pStatus
)
163 * OPEN CELL DIALOG ___________________________________________________________
167 BOOL
AfsAppLib_ShowOpenCellDialog (LPOPENCELLDLG_PARAMS lpp
)
169 HINSTANCE hInst
= APP_HINST
;
172 hInst
= APPLIB_HINST
;
173 lpp
->idd
= IDD_APPLIB_OPENCELL
;
175 if (lpp
->hCreds
== 0)
178 lpp
->hCreds
= AfsAppLib_GetCredentials (lpp
->szCell
);
180 lpp
->hCreds
= AfsAppLib_GetCredentials (NULL
);
183 INT_PTR rc
= ModalDialogParam (lpp
->idd
, lpp
->hParent
, (DLGPROC
)OpenCell_DlgProc
, (LPARAM
)lpp
);
185 return (rc
== IDOK
) ? TRUE
: FALSE
;
189 HRESULT CALLBACK
OpenCell_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
191 LPOPENCELLDLG_PARAMS lpp
;
192 if (msg
== WM_INITDIALOG
)
193 SetWindowLongPtr (hDlg
, DWLP_USER
, lp
);
195 if ((lpp
= (LPOPENCELLDLG_PARAMS
)GetWindowLongPtr (hDlg
, DWLP_USER
)) != NULL
)
199 if (CallWindowProc ((WNDPROC
)lpp
->hookproc
, hDlg
, msg
, wp
, lp
))
206 if (AfsAppLib_HandleHelp (lpp
->idd
, hDlg
, msg
, wp
, lp
))
213 OpenCell_OnInitDialog (hDlg
, lpp
);
220 EndDialog (hDlg
, IDCANCEL
);
224 if (OpenCell_OnOK (hDlg
, lpp
))
225 EndDialog (hDlg
, IDOK
);
228 case IDC_OPENCELL_CELL
:
232 TCHAR szCell
[ cchNAME
];
233 SendDlgItemMessage (hDlg
, IDC_OPENCELL_CELL
, CB_GETLBTEXT
, CB_GetSelected(GetDlgItem (hDlg
, IDC_OPENCELL_CELL
)), (LPARAM
)szCell
);
234 SetDlgItemText (hDlg
, IDC_OPENCELL_CELL
, szCell
);
235 OpenCell_OnCell (hDlg
);
239 OpenCell_OnCell (hDlg
);
246 case WM_REFRESHED_CREDENTIALS
:
247 OpenCell_OnGotCreds (hDlg
, lp
);
255 void OpenCell_OnInitDialog (HWND hDlg
, LPOPENCELLDLG_PARAMS lpp
)
257 // Fix the title of the dialog (unless the caller has supplied a
258 // custom dialog template)
260 if (lpp
&& (lpp
->idd
== IDD_APPLIB_OPENCELL
))
262 TCHAR szApplication
[ cchNAME
];
263 AfsAppLib_GetAppName (szApplication
);
264 if (szApplication
[0] != TEXT('\0'))
266 TCHAR szTitle
[ cchRESOURCE
];
267 GetWindowText (hDlg
, szTitle
, cchRESOURCE
);
268 lstrcat (szTitle
, TEXT(" - "));
269 lstrcat (szTitle
, szApplication
);
270 SetWindowText (hDlg
, szTitle
);
274 // Fill in the 'Cell:' combobox; we'll list the default cell, and any
275 // cell which the user has specified before.
277 CB_StartChange (GetDlgItem (hDlg
, IDC_OPENCELL_CELL
), TRUE
);
281 TCHAR szDefCell
[ cchNAME
];
282 if (AfsAppLib_GetLocalCell (szDefCell
) && *szDefCell
)
284 CB_AddItem (GetDlgItem (hDlg
, IDC_OPENCELL_CELL
), szDefCell
, 1);
287 else for (size_t ii
= 0; ii
< lpp
->lpcl
->nCells
; ++ii
)
289 CB_AddItem (GetDlgItem (hDlg
, IDC_OPENCELL_CELL
), lpp
->lpcl
->aCells
[ii
], 1+ii
);
292 CB_EndChange (GetDlgItem (hDlg
, IDC_OPENCELL_CELL
), 1);
294 // Set up the "Credentials" box; if the user needs credentials to edit
295 // this default cell, jump the cursor to the appropriate field
297 SetDlgItemText (hDlg
, IDC_OPENCELL_ID
, TEXT("admin"));
299 OpenCell_OnCell (hDlg
);
303 BOOL
OpenCell_OnOK (HWND hDlg
, LPOPENCELLDLG_PARAMS lpp
)
306 OpenCell_Enable (hDlg
, FALSE
);
309 // Remember what cell the user chose to edit
311 GetDlgItemText (hDlg
, IDC_OPENCELL_CELL
, lpp
->szCell
, cchNAME
);
313 // Try to obtain the credentials specified by the user.
315 TCHAR szCell
[ cchNAME
];
316 GetDlgItemText (hDlg
, IDC_OPENCELL_CELL
, szCell
, cchNAME
);
318 TCHAR szUser
[ cchRESOURCE
];
319 GetDlgItemText (hDlg
, IDC_OPENCELL_ID
, szUser
, cchNAME
);
321 TCHAR szPassword
[ cchRESOURCE
];
322 GetDlgItemText (hDlg
, IDC_OPENCELL_PASSWORD
, szPassword
, cchNAME
);
325 if ((lpp
->hCreds
= AfsAppLib_SetCredentials (lpp
->szCell
, szUser
, szPassword
, &status
)) == NULL
)
327 ErrorDialog (status
, IDS_ERROR_BAD_CREDENTIALS
);
331 // See if those credentials are sufficient
333 CHECKCREDS_PARAMS pp
;
334 memset (&pp
, 0x00, sizeof(pp
));
335 memcpy (&pp
.bcdp
, &lpp
->bcdp
, sizeof(BADCREDSDLG_PARAMS
));
336 pp
.bcdp
.hParent
= hDlg
;
337 pp
.hCreds
= lpp
->hCreds
;
338 pp
.fShowWarning
= TRUE
;
340 if ((rc
= AfsAppLib_CheckCredentials (&pp
)) == FALSE
)
342 SetDlgItemText (hDlg
, IDC_OPENCELL_ID
, TEXT("admin"));
343 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)GetDlgItem(hDlg
,IDC_OPENCELL_PASSWORD
), TRUE
);
348 OpenCell_Enable (hDlg
, TRUE
);
357 TCHAR szCell
[ cchNAME
];
358 TCHAR szUser
[ cchNAME
];
362 } OPENCELL_ONCELL_PARAMS
, *LPOPENCELL_ONCELL_PARAMS
;
364 DWORD WINAPI
OpenCell_OnCell_ThreadProc (PVOID lp
)
366 LPOPENCELL_ONCELL_PARAMS lpp
;
367 if ((lpp
= (LPOPENCELL_ONCELL_PARAMS
)lp
) != NULL
)
369 UINT_PTR hCreds
= AfsAppLib_GetCredentials (lpp
->szCell
);
370 lpp
->fGotCreds
= AfsAppLib_CrackCredentials (hCreds
, lpp
->szCell
, lpp
->szUser
, &lpp
->stExpire
)?TRUE
:FALSE
;
371 lpp
->fValidCreds
= FALSE
;
373 if (lpp
->fGotCreds
&& AfsAppLib_IsTimeInFuture (&lpp
->stExpire
))
375 CHECKCREDS_PARAMS pp
;
376 memset (&pp
, 0x00, sizeof(pp
));
378 lpp
->fValidCreds
= AfsAppLib_CheckCredentials(&pp
);
381 // Post our results; we'll return the same packet we got.
383 if (IsWindow (lpp
->hDlg
))
384 PostMessage (lpp
->hDlg
, WM_REFRESHED_CREDENTIALS
, 0, (LPARAM
)lpp
);
393 void OpenCell_OnCell (HWND hDlg
)
395 // Fire up a background thread to query our current credentials in the
398 LPOPENCELL_ONCELL_PARAMS lpp
= New (OPENCELL_ONCELL_PARAMS
);
399 memset (lpp
, 0x00, sizeof(lpp
));
400 GetDlgItemText (hDlg
, IDC_OPENCELL_CELL
, lpp
->szCell
, cchNAME
);
404 CreateThread (NULL
, 0, (LPTHREAD_START_ROUTINE
)OpenCell_OnCell_ThreadProc
, lpp
, 0, &dwThreadID
);
408 void OpenCell_OnGotCreds (HWND hDlg
, LPARAM lp
)
410 LPOPENCELL_ONCELL_PARAMS lpp
;
411 if ((lpp
= (LPOPENCELL_ONCELL_PARAMS
)lp
) != NULL
)
413 // Don't do anything to the dialog if the user has chosen a different
414 // cell than that for which we just queried credentials.
416 TCHAR szCell
[ cchNAME
];
417 GetDlgItemText (hDlg
, IDC_OPENCELL_CELL
, szCell
, cchNAME
);
419 if (!lstrcmpi (szCell
, lpp
->szCell
))
421 TCHAR szPrevCreds
[ cchRESOURCE
];
422 GetDlgItemText (hDlg
, IDC_OPENCELL_OLDCREDS
, szPrevCreds
, cchRESOURCE
);
426 LPTSTR psz
= FormatString (IDS_CREDS_NONE
, TEXT("%s"), lpp
->szCell
);
427 SetDlgItemText (hDlg
, IDC_OPENCELL_OLDCREDS
, psz
);
430 else if (!AfsAppLib_IsTimeInFuture (&lpp
->stExpire
))
432 LPTSTR pszCreds
= FormatString (IDS_CREDS_EXPIRED
, TEXT("%s%s%t"), lpp
->szCell
, lpp
->szUser
, &lpp
->stExpire
);
433 SetDlgItemText (hDlg
, IDC_OPENCELL_OLDCREDS
, pszCreds
);
434 FreeString (pszCreds
);
438 LPTSTR pszCreds
= FormatString (IDS_CREDS_VALID
, TEXT("%s%s%t"), lpp
->szCell
, lpp
->szUser
, &lpp
->stExpire
);
439 SetDlgItemText (hDlg
, IDC_OPENCELL_OLDCREDS
, pszCreds
);
440 FreeString (pszCreds
);
443 SetDlgItemText (hDlg
, IDC_OPENCELL_ID
, (lpp
->fGotCreds
) ? lpp
->szUser
: TEXT("admin"));
445 if (!lpp
->fValidCreds
&& !szPrevCreds
[0])
446 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)GetDlgItem(hDlg
,IDC_OPENCELL_PASSWORD
), TRUE
);
454 void OpenCell_Enable (HWND hDlg
, BOOL fEnable
)
456 EnableWindow (GetDlgItem (hDlg
, IDOK
), fEnable
);
457 EnableWindow (GetDlgItem (hDlg
, IDCANCEL
), fEnable
);
458 EnableWindow (GetDlgItem (hDlg
, IDHELP
), fEnable
);
459 EnableWindow (GetDlgItem (hDlg
, IDC_OPENCELL_CELL
), fEnable
);
460 EnableWindow (GetDlgItem (hDlg
, IDC_OPENCELL_ID
), fEnable
);
461 EnableWindow (GetDlgItem (hDlg
, IDC_OPENCELL_PASSWORD
), fEnable
);
466 * NEW CREDENTIALS DIALOG _____________________________________________________
470 BOOL
AfsAppLib_ShowCredentialsDialog (LPCREDENTIALSDLG_PARAMS lpp
)
472 HINSTANCE hInst
= APP_HINST
;
475 hInst
= APPLIB_HINST
;
476 lpp
->idd
= IDD_APPLIB_CREDENTIALS
;
478 if (lpp
->hCreds
== 0)
481 lpp
->hCreds
= AfsAppLib_GetCredentials (lpp
->szCell
);
483 lpp
->hCreds
= AfsAppLib_GetCredentials (NULL
);
486 INT_PTR rc
= ModalDialogParam (lpp
->idd
, lpp
->hParent
, (DLGPROC
)NewCreds_DlgProc
, (LPARAM
)lpp
);
488 return (rc
== IDOK
) ? TRUE
: FALSE
;
492 HRESULT CALLBACK
NewCreds_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
494 LPCREDENTIALSDLG_PARAMS lpp
;
495 if (msg
== WM_INITDIALOG
)
496 SetWindowLongPtr (hDlg
, DWLP_USER
, lp
);
498 if ((lpp
= (LPCREDENTIALSDLG_PARAMS
)GetWindowLongPtr (hDlg
, DWLP_USER
)) != NULL
)
502 if (CallWindowProc ((WNDPROC
)lpp
->hookproc
, hDlg
, msg
, wp
, lp
))
509 if (AfsAppLib_HandleHelp (lpp
->idd
, hDlg
, msg
, wp
, lp
))
516 NewCreds_OnInitDialog (hDlg
, lpp
);
523 EndDialog (hDlg
, IDCANCEL
);
527 if (NewCreds_OnOK (hDlg
, lpp
))
528 EndDialog (hDlg
, IDOK
);
531 case IDC_CREDS_LOGIN
:
532 NewCreds_OnLogin (hDlg
);
542 void NewCreds_OnInitDialog (HWND hDlg
, LPCREDENTIALSDLG_PARAMS lpp
)
544 // Fix the title of the dialog (unless the caller has supplied a
545 // custom dialog template)
547 if (lpp
&& (lpp
->idd
== IDD_APPLIB_CREDENTIALS
))
549 TCHAR szApplication
[ cchNAME
];
550 AfsAppLib_GetAppName (szApplication
);
551 if (szApplication
[0] != TEXT('\0'))
553 TCHAR szTitle
[ cchRESOURCE
];
554 GetWindowText (hDlg
, szTitle
, cchRESOURCE
);
555 lstrcat (szTitle
, TEXT(" - "));
556 lstrcat (szTitle
, szApplication
);
557 SetWindowText (hDlg
, szTitle
);
561 // Set up the "Credentials" boxes
563 TCHAR szUser
[ cchRESOURCE
];
566 BOOL fValidCreds
= TRUE
;
567 BOOL fShowCreds
= TRUE
;
568 CHECKCREDS_PARAMS pp
;
569 memset (&pp
, 0x00, sizeof(pp
));
570 pp
.hCreds
= lpp
->hCreds
;
571 pp
.fShowWarning
= FALSE
;
572 memcpy (&pp
.bcdp
, &lpp
->bcdp
, sizeof(BADCREDSDLG_PARAMS
));
573 pp
.bcdp
.hParent
= hDlg
;
575 if (!AfsAppLib_CrackCredentials (lpp
->hCreds
, lpp
->szCell
, szUser
, &st
))
580 if (!AfsAppLib_IsTimeInFuture (&st
))
585 if (!AfsAppLib_CheckCredentials (&pp
))
590 CheckDlgButton (hDlg
, IDC_CREDS_LOGIN
, !fValidCreds
);
592 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)GetDlgItem(hDlg
,IDC_CREDS_PASSWORD
), TRUE
);
594 SetDlgItemText (hDlg
, IDC_CREDS_CELL
, lpp
->szCell
);
598 SetDlgItemText (hDlg
, IDC_CREDS_CURRENTID
, szUser
);
600 LPTSTR pszDate
= FormatString (TEXT("%1"), TEXT("%t"), &st
);
601 SetDlgItemText (hDlg
, IDC_CREDS_EXPDATE
, pszDate
);
602 FreeString (pszDate
);
605 SetDlgItemText (hDlg
, IDC_CREDS_ID
, TEXT("admin"));
607 NewCreds_OnLogin (hDlg
);
611 BOOL
NewCreds_OnOK (HWND hDlg
, LPCREDENTIALSDLG_PARAMS lpp
)
613 NewCreds_GetOutParams (hDlg
, lpp
);
614 if (!IsDlgButtonChecked (hDlg
, IDC_CREDS_LOGIN
))
619 NewCreds_Enable (hDlg
, FALSE
);
621 // Try to obtain the credentials specified by the user.
623 TCHAR szUser
[ cchRESOURCE
];
624 GetDlgItemText (hDlg
, IDC_CREDS_ID
, szUser
, cchNAME
);
626 TCHAR szPassword
[ cchRESOURCE
];
627 GetDlgItemText (hDlg
, IDC_CREDS_PASSWORD
, szPassword
, cchNAME
);
630 if ((lpp
->hCreds
= AfsAppLib_SetCredentials (lpp
->szCell
, szUser
, szPassword
, &status
)) == NULL
)
632 ErrorDialog (status
, IDS_ERROR_BAD_CREDENTIALS
);
636 // See if those credentials are sufficient
638 CHECKCREDS_PARAMS pp
;
639 memset (&pp
, 0x00, sizeof(pp
));
640 memcpy (&pp
.bcdp
, &lpp
->bcdp
, sizeof(BADCREDSDLG_PARAMS
));
641 pp
.bcdp
.hParent
= hDlg
;
642 pp
.hCreds
= lpp
->hCreds
;
643 pp
.fShowWarning
= TRUE
;
645 if ((rc
= AfsAppLib_CheckCredentials (&pp
)) == FALSE
)
647 SetDlgItemText (hDlg
, IDC_CREDS_ID
, TEXT("admin"));
648 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)GetDlgItem(hDlg
,IDC_CREDS_PASSWORD
), TRUE
);
653 NewCreds_Enable (hDlg
, TRUE
);
659 void NewCreds_OnLogin (HWND hDlg
)
661 BOOL fEnable
= IsDlgButtonChecked (hDlg
, IDC_CREDS_LOGIN
);
663 EnableWindow (GetDlgItem (hDlg
, IDC_CREDS_ID
), fEnable
);
664 EnableWindow (GetDlgItem (hDlg
, IDC_CREDS_PASSWORD
), fEnable
);
668 void NewCreds_Enable (HWND hDlg
, BOOL fEnable
)
670 EnableWindow (GetDlgItem (hDlg
, IDOK
), fEnable
);
671 EnableWindow (GetDlgItem (hDlg
, IDCANCEL
), fEnable
);
672 EnableWindow (GetDlgItem (hDlg
, IDHELP
), fEnable
);
673 EnableWindow (GetDlgItem (hDlg
, IDC_CREDS_LOGIN
), fEnable
);
676 NewCreds_OnLogin (hDlg
);
679 EnableWindow (GetDlgItem (hDlg
, IDC_CREDS_ID
), fEnable
);
680 EnableWindow (GetDlgItem (hDlg
, IDC_CREDS_PASSWORD
), fEnable
);
685 void NewCreds_GetOutParams (HWND hDlg
, LPCREDENTIALSDLG_PARAMS lpp
)
687 if (!IsDlgButtonChecked (hDlg
, IDC_CREDS_LOGIN
))
689 lpp
->szIdentity
[0] = TEXT('\0');
690 lpp
->szPassword
[0] = TEXT('\0');
694 GetDlgItemText (hDlg
, IDC_CREDS_ID
, lpp
->szIdentity
, cchNAME
);
695 GetDlgItemText (hDlg
, IDC_CREDS_PASSWORD
, lpp
->szPassword
, cchNAME
);
701 * TEST CREDENTIALS ___________________________________________________________
706 BOOL
AfsAppLib_IsUserAdmin (UINT_PTR hCreds
, LPTSTR pszUser
)
715 if ((idClient
= AfsAppLib_GetAdminServerClientID()) != 0)
717 TCHAR szCell
[ cchRESOURCE
];
718 TCHAR szUser
[ cchRESOURCE
];
720 if (asc_CredentialsCrack (idClient
, hCreds
, szCell
, szUser
, &stExpire
, (ULONG
*)&status
))
723 if (asc_CellOpen (idClient
, hCreds
, szCell
, AFSADMSVR_SCOPE_USERS
, &idCell
, (ULONG
*)&status
))
726 if (asc_ObjectFind (idClient
, idCell
, TYPE_USER
, pszUser
, &idUser
, (ULONG
*)&status
))
729 if (asc_ObjectPropertiesGet (idClient
, GET_ALL_DATA
, idCell
, idUser
, &Info
, (ULONG
*)&status
))
731 if (Info
.u
.UserProperties
.fHaveKasInfo
)
733 rc
= Info
.u
.UserProperties
.KASINFO
.fIsAdmin
;
737 asc_CellClose (idClient
, idCell
, (ULONG
*)&status
);
741 else if (OpenClientLibrary())
743 if (OpenKasLibrary())
745 char szUserA
[ cchRESOURCE
], szUser2A
[ cchRESOURCE
];
746 char szCellA
[ cchRESOURCE
];
747 unsigned long dateExpire
;
750 if (afsclient_TokenQuery (hCreds
, &dateExpire
, szUserA
, szUser2A
, szCellA
, &fHasKasToken
, (afs_status_p
)&status
))
753 if (afsclient_CellOpen (szCellA
, hCreds
, &hCell
, &status
))
755 kas_identity_t Identity
;
756 memset (&Identity
, 0x00, sizeof(Identity
));
757 CopyStringToAnsi (Identity
.principal
, pszUser
);
759 kas_principalEntry_t Entry
;
760 if (kas_PrincipalGet (hCell
, NULL
, &Identity
, &Entry
, &status
))
762 if (Entry
.adminSetting
== KAS_ADMIN
)
766 afsclient_CellClose (hCell
, (afs_status_p
)&status
);
773 CloseClientLibrary();
777 #endif /* USE_KASERVER */
783 BADCREDSDLG_PARAMS bcdp
;
786 } REALBADCREDSDLG_PARAMS
, *LPREALBADCREDSDLG_PARAMS
;
788 BOOL
AfsAppLib_CheckCredentials (LPCHECKCREDS_PARAMS lpp
)
790 BOOL fCredsOK
= TRUE
;
791 int idsWarning
= IDS_BADCREDS_DESC_GENERAL
;
793 TCHAR szCell
[ cchNAME
];
794 TCHAR szUser
[ cchNAME
];
797 if (!AfsAppLib_CrackCredentials (lpp
->hCreds
, szCell
, szUser
, &stExpire
))
801 else if (!AfsAppLib_IsUserAdmin (lpp
->hCreds
, szUser
))
804 idsWarning
= IDS_BADCREDS_DESC_BADCHOICE
;
806 else if (!AfsAppLib_IsTimeInFuture (&stExpire
))
809 idsWarning
= IDS_BADCREDS_DESC_EXPIRED
;
812 if (!fCredsOK
&& lpp
->fShowWarning
)
814 if (lpp
->bcdp
.pfShowWarningEver
&& !(*lpp
->bcdp
.pfShowWarningEver
))
816 fCredsOK
= TRUE
; // user says always ignore bad credentials.
821 AfsAppLib_GetLocalCell (szCell
);
823 int idsDesc
= (lpp
->bcdp
.idsDesc
) ? lpp
->bcdp
.idsDesc
: IDS_BADCREDS_DESC2
;
824 LPTSTR pszDesc
= FormatString (idsDesc
, TEXT("%s"), szCell
);
825 LPTSTR pszFullText
= FormatString (idsWarning
, TEXT("%s%s%m"), szCell
, pszDesc
, IDS_BADCREDS_DESC3
);
826 FreeString (pszDesc
);
828 REALBADCREDSDLG_PARAMS pp
;
829 memset (&pp
, 0x00, sizeof(pp
));
830 pp
.pszFullText
= pszFullText
;
831 memcpy (&pp
.bcdp
, &lpp
->bcdp
, sizeof(BADCREDSDLG_PARAMS
));
833 HINSTANCE hInst
= APP_HINST
;
834 if (pp
.bcdp
.idd
== 0)
836 hInst
= APPLIB_HINST
;
837 pp
.bcdp
.idd
= IDD_APPLIB_BADCREDS
;
840 INT_PTR rc
= ModalDialogParam (pp
.bcdp
.idd
, pp
.bcdp
.hParent
, (DLGPROC
)BadCreds_DlgProc
, (LPARAM
)&pp
);
843 fCredsOK
= TRUE
; // user says ignore bad credentials this time.
846 FreeString (pszFullText
);
854 HRESULT CALLBACK
BadCreds_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
856 LPREALBADCREDSDLG_PARAMS lpp
;
857 if (msg
== WM_INITDIALOG
)
858 SetWindowLongPtr (hDlg
, DWLP_USER
, lp
);
859 if ((lpp
= (LPREALBADCREDSDLG_PARAMS
)GetWindowLongPtr (hDlg
, DWLP_USER
)) != NULL
)
861 if (lpp
->bcdp
.hookproc
)
863 if (CallWindowProc ((WNDPROC
)lpp
->bcdp
.hookproc
, hDlg
, msg
, wp
, lp
))
866 if (AfsAppLib_HandleHelp (lpp
->bcdp
.idd
, hDlg
, msg
, wp
, lp
))
873 TCHAR szApplication
[ cchNAME
];
874 AfsAppLib_GetAppName (szApplication
);
875 if (szApplication
[0] != TEXT('\0'))
877 TCHAR szTitle
[ cchRESOURCE
];
878 GetWindowText (hDlg
, szTitle
, cchRESOURCE
);
879 lstrcat (szTitle
, TEXT(" - "));
880 lstrcat (szTitle
, szApplication
);
881 SetWindowText (hDlg
, szTitle
);
883 if (!lpp
|| !lpp
->bcdp
.pfShowWarningEver
)
884 DestroyWindow (GetWindow (hDlg
, IDC_BADCREDS_SHUTUP
));
886 SetDlgItemText (hDlg
, IDC_BADCREDS_DESC
, lpp
->pszFullText
);
894 if (lpp
&& lpp
->bcdp
.pfShowWarningEver
)
895 *lpp
->bcdp
.pfShowWarningEver
= !IsDlgButtonChecked (hDlg
, IDC_BADCREDS_SHUTUP
);
896 EndDialog (hDlg
, LOWORD(wp
));
907 * EXPIRED CREDENTIALS ________________________________________________________
911 void AfsAppLib_CheckForExpiredCredentials (LPCREDENTIALSDLG_PARAMS lpp
)
913 static UINT_PTR hCredsPrevious
= 0;
914 static BOOL fHadGoodCredentials
;
916 TCHAR szCell
[ cchNAME
];
917 TCHAR szUser
[ cchNAME
];
920 BOOL fHaveCredentials
;
921 fHaveCredentials
= AfsAppLib_CrackCredentials (lpp
->hCreds
, szCell
, szUser
, &stExpire
)?TRUE
:FALSE
;
923 if (hCredsPrevious
&& (hCredsPrevious
!= lpp
->hCreds
))
925 if (!fHaveCredentials
)
926 fHadGoodCredentials
= FALSE
;
927 else if (!AfsAppLib_IsTimeInFuture (&stExpire
))
928 fHadGoodCredentials
= FALSE
;
930 fHadGoodCredentials
= TRUE
;
931 hCredsPrevious
= lpp
->hCreds
;
933 else if (fHaveCredentials
&& AfsAppLib_IsTimeInFuture (&stExpire
))
935 fHadGoodCredentials
= TRUE
;
937 else if (fHadGoodCredentials
) // used to have good credentials, but now don't
939 fHadGoodCredentials
= FALSE
;
941 LPCREDENTIALSDLG_PARAMS lppCopy
= New (CREDENTIALSDLG_PARAMS
);
942 memcpy (lppCopy
, lpp
, sizeof(CREDENTIALSDLG_PARAMS
));
944 if (!AfsAppLib_GetMainWindow())
945 OnExpiredCredentials ((WPARAM
)(!AfsAppLib_IsTimeInFuture(&stExpire
)), (LPARAM
)lppCopy
);
947 PostMessage (AfsAppLib_GetMainWindow(), WM_EXPIRED_CREDENTIALS
, (WPARAM
)(!AfsAppLib_IsTimeInFuture(&stExpire
)), (LPARAM
)lppCopy
);
952 void OnExpiredCredentials (WPARAM wp
, LPARAM lp
)
954 BOOL fExpired
= (BOOL
)wp
;
955 LPCREDENTIALSDLG_PARAMS lpp
= (LPCREDENTIALSDLG_PARAMS
)lp
;
957 if (lpp
&& lpp
->bcdp
.pfShowWarningEver
&& *(lpp
->bcdp
.pfShowWarningEver
))
959 int idsWarning
= (wp
) ? IDS_BADCREDS_DESC_EXPIRED
: IDS_BADCREDS_DESC_DESTROYED
;
961 int idsDesc
= (lpp
->bcdp
.idsDesc
) ? lpp
->bcdp
.idsDesc
: IDS_BADCREDS_DESC2
;
962 LPTSTR pszDesc
= FormatString (idsDesc
, TEXT("%s"), lpp
->szCell
);
963 LPTSTR pszFullText
= FormatString (idsWarning
, TEXT("%s%s%m"), lpp
->szCell
, pszDesc
, IDS_BADCREDS_DESC3
);
964 FreeString (pszDesc
);
966 REALBADCREDSDLG_PARAMS pp
;
967 memset (&pp
, 0x00, sizeof(pp
));
968 pp
.pszFullText
= pszFullText
;
969 memcpy (&pp
.bcdp
, &lpp
->bcdp
, sizeof(BADCREDSDLG_PARAMS
));
971 if (ModalDialogParam (IDD_APPLIB_BADCREDS
, NULL
, (DLGPROC
)BadCreds_DlgProc
, (LPARAM
)&pp
) != IDCANCEL
)
973 AfsAppLib_ShowCredentialsDialog (lpp
);
976 FreeString (pszFullText
);