#include <time.h>
#include <shellapi.h>
#include <WINNT/al_wizard.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include <osithrdnt.h>
+#include <osisleep.h>
+#include <osibasel.h>
+#ifdef __cplusplus
+}
+#endif
#include "resource.h"
#include "checklist.h"
#include "window.h"
BOOL fStartup;
BOOL fIsWinNT;
TCHAR szHelpFile[ MAX_PATH ];
+ osi_mutex_t expirationCheckLock;
+ osi_mutex_t credsLock;
} GLOBALS;
extern GLOBALS g;
*
*/
-#define cminREMIND_TEST 3 // test every minute for expired creds
+#define cminREMIND_TEST 1 // test every minute for expired creds
#define cminREMIND_WARN 15 // warn if creds expire in 15 minutes
#define cmsecMOUSEOVER 1000 // retest freq when mouse is over tray icon
{
QueryServiceStatus (hService, &Status);
CloseServiceHandle (hService);
- }
+ } else if ( IsDebuggerPresent() )
+ OutputDebugString("Unable to open Transarc AFS Daemon Service\n");
CloseServiceHandle (hManager);
- }
+ } else if ( IsDebuggerPresent() )
+ OutputDebugString("Unable to open SC Manager\n");
return (Status.dwCurrentState == SERVICE_RUNNING);
}
{
int rc = KTC_NOCM;
+ lock_ObtainMutex(&g.credsLock);
+
// Free any knowledge we currently have about the user's credentials
//
if (g.aCreds)
}
}
+ lock_ReleaseMutex(&g.credsLock);
+
// We've finished updating g.aCreds. Update the tray icon to reflect
// whether the user currently has any credentials at all, and
// re-enable the Remind timer.
#ifndef CREDS_H
#define CREDS_H
+#ifdef __cplusplus
+extern "C" {
+#endif
/*
* PROTOTYPES _________________________________________________________________
BOOL Creds_OpenLibraries (void);
void Creds_CloseLibraries (void);
-
+#ifdef __cplusplus
+}
+#endif
#endif
void Creds_OnCheckRemind (HWND hDlg)
{
LPTSTR pszCell = (LPTSTR)GetWindowLong (hDlg, DWL_USER);
+ lock_ObtainMutex(&g.credsLock);
for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds)
{
if (!lstrcmpi (g.aCreds[ iCreds ].szCell, pszCell))
g.aCreds[ iCreds ].fRemind = IsDlgButtonChecked (hDlg, IDC_CREDS_REMIND);
SaveRemind (iCreds);
}
+ lock_ReleaseMutex(&g.credsLock);
}
return;
}
+ lock_ObtainMutex(&g.credsLock);
for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds)
{
if (!lstrcmpi (g.aCreds[ iCreds ].szCell, pszCell))
FreeString (pszCreds);
}
+ lock_ReleaseMutex(&g.credsLock);
CheckDlgButton (hDlg, IDC_CREDS_REMIND, (iCreds == g.cCreds) ? FALSE : g.aCreds[iCreds].fRemind);
EnableWindow (GetDlgItem (hDlg, IDC_CREDS_OBTAIN), IsServiceRunning());
}
-void ShowObtainCreds (BOOL fExpiring, LPTSTR pszCell)
+struct _obtaincreds {
+ DWORD type;
+ HWND parent;
+ char * cell;
+};
+
+void ObtainCredsThread(void * data)
{
- HWND hParent = (IsWindowVisible (g.hMain)) ? g.hMain : NULL;
+ struct _obtaincreds * oc = (struct _obtaincreds *)data;
- if (fExpiring)
- {
- ModalDialogParam (IDD_NEWCREDS_EXPIRE, hParent, (DLGPROC)NewCreds_DlgProc, (LPARAM)pszCell);
- }
- else // (!fExpiring)
- {
- ModalDialogParam (IDD_NEWCREDS, hParent, (DLGPROC)NewCreds_DlgProc, (LPARAM)pszCell);
- }
+ ModalDialogParam (oc->type, oc->parent, (DLGPROC)NewCreds_DlgProc, (LPARAM)oc->cell);
+ free(oc->cell);
+ free(oc);
+}
+
+void ShowObtainCreds (BOOL fExpiring, LPTSTR pszCell)
+{
+ struct _obtaincreds * oc = (struct _obtaincreds *)malloc(sizeof(struct _obtaincreds));
+ if ( !oc )
+ return;
+ oc->parent = (IsWindowVisible (g.hMain)) ? g.hMain : NULL;
+ oc->type = fExpiring ? IDD_NEWCREDS_EXPIRE : IDD_NEWCREDS;
+ oc->cell = _strdup(pszCell);
+
+ HANDLE thread = 0;
+ ULONG threadID = 123;
+
+ thread = CreateThread(NULL, 0, (PTHREAD_START_ROUTINE)ObtainCredsThread,
+ oc, 0, &threadID);
+ if (thread != NULL)
+ CloseHandle(thread);
+ else {
+ free(oc->cell);
+ free(oc);
+ }
}
case WM_DESTROY:
InterlockedDecrement (&g.fShowingMessage);
- Main_EnableRemindTimer (TRUE);
break;
case WM_COMMAND:
SetDlgItemText (hDlg, IDC_NEWCREDS_CELL, szCell);
}
+ lock_ObtainMutex(&g.credsLock);
for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds)
{
if (*pszCell && !lstrcmpi (g.aCreds[ iCreds ].szCell, pszCell))
SetDlgItemText (hDlg, IDC_NEWCREDS_USER, g.aCreds[ iCreds ].szUser);
PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (hDlg, IDC_NEWCREDS_PASSWORD), TRUE);
}
+ lock_ReleaseMutex(&g.credsLock);
NewCreds_OnEnable (hDlg);
+ SetForegroundWindow(hDlg);
KillTimer (g.hMain, ID_SERVICE_TIMER);
}
void NewCreds_OnCancel (HWND hDlg)
{
- LPTSTR pszCell = (LPTSTR)GetWindowLong (hDlg, DWL_USER);
+ TCHAR szText[ cchRESOURCE ] = "";
+ LPTSTR pszCell = NULL;
+
+ if (GetDlgItem (hDlg, IDC_NEWCREDS_CELL))
+ {
+ GetDlgItemText (hDlg, IDC_NEWCREDS_CELL, szText, cchRESOURCE);
+ if ( szText[0] )
+ pszCell = szText;
+ }
+
+ if ( !pszCell )
+ pszCell = (LPTSTR)GetWindowLong (hDlg, DWL_USER);
if (pszCell)
{
+ lock_ObtainMutex(&g.credsLock);
for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds)
{
if (!lstrcmpi (g.aCreds[ iCreds ].szCell, pszCell))
}
}
}
+ lock_ReleaseMutex(&g.credsLock);
}
}
break;
case 'x':
case 'X':
- DWORD LogonOption;
- DWORD LSPtype, LSPsize;
- HKEY NPKey;
- LSPsize=sizeof(LogonOption);
- (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PROVIDER_KEY,
- 0, KEY_QUERY_VALUE, &NPKey);
- RegQueryValueEx(NPKey, "LogonOptions", NULL,
- &LSPtype, (LPBYTE)&LogonOption, &LSPsize);
- RegCloseKey (NPKey);
- if (ISHIGHSECURITY(LogonOption))
- DoMapShare();
- GlobalMountDrive();
+ TestAndDoMapShare(SERVICE_START_PENDING);
+ TestAndDoMapShare(SERVICE_RUNNING);
return 0;
}
InitCommonControls();
RegisterCheckListClass();
+ osi_Init();
+ lock_InitializeMutex(&g.expirationCheckLock, "expiration check lock");
+ lock_InitializeMutex(&g.credsLock, "global creds lock");
+
+ if ( IsDebuggerPresent() ) {
+ if ( !g.fIsWinNT )
+ OutputDebugString("No Service Present on non-NT systems\n");
+ else {
+ if ( IsServiceRunning() )
+ OutputDebugString("AFSD Service started\n");
+ else {
+ OutputDebugString("AFSD Service stopped\n");
+ if ( !IsServiceConfigured() )
+ OutputDebugString("AFSD Service not configured\n");
+ }
+ }
+ }
// Create a main window. All further initialization will be done during
// processing of WM_INITDIALOG.
else if (!IsServerInstalled())
Message (MB_ICONHAND, IDS_UNCONFIG_TITLE, IDS_UNCONFIG_DESC);
}
- if (IsServiceRunning() && fShow)
+ if (IsServiceRunning()) {
+ if (fShow)
{
+ if ( IsDebuggerPresent() )
+ OutputDebugString("Displaying Main window\n");
Main_Show (TRUE);
}
-
- return TRUE;
+ } else if ( IsDebuggerPresent() )
+ OutputDebugString("Displaying Main window\n");
+ return TRUE;
}
void Mount_OnUpdate (HWND hDlg, BOOL fOnInitDialog)
{
DRIVEMAPLIST List;
+ memset(&List, 0, sizeof(DRIVEMAPLIST));
QueryDriveMapList (&List);
HWND hList = GetDlgItem (hDlg, IDC_LIST);
#define IDD_WIZ_FINISH 119
#define IDD_MAPPING 120
#define IDD_TERMINATE_SMALL_95 121
+#define IDD_AUTH 122
#define M_TERMINATE 3000
#define M_ACTIVATE 3001
#define M_REMIND 3002
#include <initguid.h>
#include <windows.h>
#include <windowsx.h>
+#undef INITGUID
#include <shlobj.h>
#include <shellapi.h>
#include <shobjidl.h>
}
-BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc)
+BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc, LPTSTR pszArgs)
{
IShellLink *psl;
HRESULT rc = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
rc = psl->SetDescription (pszDesc ? pszDesc : pszSource);
if (SUCCEEDED (rc))
{
+ if ( pszArgs )
+ rc = psl->SetArguments (pszArgs);
+ if (SUCCEEDED (rc))
+ {
#ifdef UNICODE
- rc = ppf->Save (pszTarget, TRUE);
+ rc = ppf->Save (pszTarget, TRUE);
#else
- WORD wsz[ MAX_PATH ];
- MultiByteToWideChar (CP_ACP, 0, pszTarget, -1, wsz, MAX_PATH);
- rc = ppf->Save (wsz, TRUE);
+ WORD wsz[ MAX_PATH ];
+ MultiByteToWideChar (CP_ACP, 0, pszTarget, -1, wsz, MAX_PATH);
+ rc = ppf->Save (wsz, TRUE);
#endif
+ }
}
}
ppf->Release ();
void Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart)
{
- TCHAR szShortcut[ MAX_PATH ] = TEXT("");
+ TCHAR szShortcut[ MAX_PATH + 10 ] = TEXT("");
HKEY hk;
if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"), &hk) == 0)
if (fAutoStart)
{
- Shortcut_Create (szShortcut, szSource);
+ Shortcut_Create (szShortcut, szSource, "Autostart Authentication Agent");
}
else // (!g.fAutoStart)
{
void Shortcut_Init (void);
void Shortcut_Exit (void);
-BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc = NULL);
+BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc = NULL, LPTSTR pszArgs = NULL);
void Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart);
nid.uID = 0;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_TRAYICON;
+ lock_ObtainMutex(&g.credsLock);
nid.hIcon = ((g.cCreds != 0) && (iExpired == (size_t)-1)) ? ICON_CREDS_YES : ICON_CREDS_NO;
+ lock_ReleaseMutex(&g.credsLock);
GetString (nid.szTip, (g.fIsWinNT) ? IDS_TOOLTIP : IDS_TOOLTIP_95);
Shell_NotifyIcon (nim, &nid);
}
InsertMenu (hmDummy, 0, MF_POPUP, (UINT)hm, NULL);
BOOL fRemind = FALSE;
+ lock_ObtainMutex(&g.credsLock);
for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds)
{
if (g.aCreds[ iCreds ].fRemind)
fRemind = TRUE;
}
+ lock_ReleaseMutex(&g.credsLock);
CheckMenuItem (hm, M_REMIND, MF_BYCOMMAND | ((fRemind) ? MF_CHECKED : MF_UNCHECKED));
TrackPopupMenu (GetSubMenu (hmDummy, 0),
void Main_OnCheckMenuRemind (void)
{
BOOL fRemind = FALSE;
+ lock_ObtainMutex(&g.credsLock);
for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds)
{
if (g.aCreds[ iCreds ].fRemind)
SaveRemind (iCreds);
}
}
+ lock_ReleaseMutex(&g.credsLock);
// Check the active tab, and fix its checkbox if necessary
//
// Make sure the reminder timer is going
//
- Main_EnableRemindTimer (TRUE);
+ Main_EnableRemindTimer (fRemind);
}
if (IsWindowVisible (g.hMain))
fDestroyInvalid = FALSE;
- Main_EnableRemindTimer (FALSE);
// First we'll have to look around and see what credentials we currently
// have. This call just updates g.aCreds[]; it doesn't do anything else.
size_t iTabOut = 0;
size_t nCreds = 0;
+ lock_ObtainMutex(&g.credsLock);
for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds)
{
if (g.aCreds[ iCreds ].szCell[0])
}
}
}
+ lock_ReleaseMutex(&g.credsLock);
if (REALLOC (aTabs, cTabs, 1+iTabOut, cREALLOC_TABS))
aTabs[ iTabOut++ ] = dwTABPARAM_MOUNT;
TabCtrl_SetCurSel (hTab, iTabSel);
Main_OnSelectTab ();
- Main_EnableRemindTimer (TRUE);
fInHere = FALSE;
}
void Main_EnableRemindTimer (BOOL fEnable)
{
- KillTimer (g.hMain, ID_REMIND_TIMER);
+ static BOOL bEnabled = FALSE;
- if (fEnable)
+ if ( fEnable == FALSE && bEnabled == TRUE ) {
+ KillTimer (g.hMain, ID_REMIND_TIMER);
+ bEnabled = FALSE;
+ } else if ( fEnable == TRUE && bEnabled == FALSE ) {
SetTimer (g.hMain, ID_REMIND_TIMER, (ULONG)cmsec1MINUTE * cminREMIND_TEST, NULL);
+ bEnabled = TRUE;
+ }
}
size_t Main_FindExpiredCreds (void)
{
+ size_t retval = (size_t) -1;
+ lock_ObtainMutex(&g.expirationCheckLock);
+ lock_ObtainMutex(&g.credsLock);
for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds)
{
if (!g.aCreds[ iCreds ].szCell[0])
llExpires /= c100ns1SECOND;
if (llExpires <= (llNow + (LONGLONG)cminREMIND_WARN * csec1MINUTE))
- return iCreds;
+ retval = (size_t) iCreds;
+ break;
}
+
+ lock_ReleaseMutex(&g.credsLock);
+ lock_ReleaseMutex(&g.expirationCheckLock);
- return (size_t)-1;
+ return retval;
}