KFW_initialize(void)
{
static int inited = 0;
+
if ( !inited ) {
- inited = 1;
- LoadFuncs(KRB5_DLL, k5_fi, &hKrb5, 0, 1, 0, 0);
- LoadFuncs(KRB4_DLL, k4_fi, &hKrb5, 0, 1, 0, 0);
- LoadFuncs(COMERR_DLL, ce_fi, &hComErr, 0, 0, 1, 0);
- LoadFuncs(SERVICE_DLL, service_fi, &hService, 0, 1, 0, 0);
+ char mutexName[MAX_PATH];
+ HANDLE hMutex = NULL;
+
+ sprintf(mutexName, "AFS KFW Init pid=%d", getpid());
+
+ hMutex = CreateMutex( NULL, TRUE, mutexName );
+ if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
+ if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {
+ return;
+ }
+ }
+ if ( !inited ) {
+ inited = 1;
+ LoadFuncs(KRB5_DLL, k5_fi, &hKrb5, 0, 1, 0, 0);
+ LoadFuncs(KRB4_DLL, k4_fi, &hKrb4, 0, 1, 0, 0);
+ LoadFuncs(COMERR_DLL, ce_fi, &hComErr, 0, 0, 1, 0);
+ LoadFuncs(SERVICE_DLL, service_fi, &hService, 0, 1, 0, 0);
#ifdef USE_MS2MIT
- LoadFuncs(SECUR32_DLL, lsa_fi, &hSecur32, 0, 1, 1, 1);
+ LoadFuncs(SECUR32_DLL, lsa_fi, &hSecur32, 0, 1, 1, 1);
#endif /* USE_MS2MIT */
- LoadFuncs(KRB524_DLL, k524_fi, &hKrb524, 0, 1, 1, 1);
- LoadFuncs(PROFILE_DLL, profile_fi, &hProfile, 0, 1, 0, 0);
- LoadFuncs(AFSTOKENS_DLL, afst_fi, &hAfsTokens, 0, 1, 0, 0);
- LoadFuncs(AFSCONF_DLL, afsc_fi, &hAfsConf, 0, 1, 0, 0);
- LoadFuncs(LEASH_DLL, leash_fi, &hLeash, 0, 1, 0, 0);
- LoadFuncs(CCAPI_DLL, ccapi_fi, &hCCAPI, 0, 1, 0, 0);
-
- if ( KFW_is_available() ) {
- char rootcell[MAXCELLCHARS+1];
+ LoadFuncs(KRB524_DLL, k524_fi, &hKrb524, 0, 1, 1, 1);
+ LoadFuncs(PROFILE_DLL, profile_fi, &hProfile, 0, 1, 0, 0);
+ LoadFuncs(AFSTOKENS_DLL, afst_fi, &hAfsTokens, 0, 1, 0, 0);
+ LoadFuncs(AFSCONF_DLL, afsc_fi, &hAfsConf, 0, 1, 0, 0);
+ LoadFuncs(LEASH_DLL, leash_fi, &hLeash, 0, 1, 0, 0);
+ LoadFuncs(CCAPI_DLL, ccapi_fi, &hCCAPI, 0, 1, 0, 0);
+
+ if ( KFW_is_available() ) {
+ char rootcell[MAXCELLCHARS+1];
#ifdef USE_MS2MIT
- KFW_import_windows_lsa();
+ KFW_import_windows_lsa();
#endif /* USE_MS2MIT */
- KFW_import_ccache_data();
- KFW_AFS_renew_expiring_tokens();
+ KFW_import_ccache_data();
+ KFW_AFS_renew_expiring_tokens();
- /* WIN32 NOTE: no way to get max chars */
- if (!pcm_GetRootCellName(rootcell))
- KFW_AFS_renew_token_for_cell(rootcell);
+ /* WIN32 NOTE: no way to get max chars */
+ if (!pcm_GetRootCellName(rootcell))
+ KFW_AFS_renew_token_for_cell(rootcell);
+ }
}
+ ReleaseMutex(hMutex);
+ CloseHandle(hMutex);
}
}
hSecur32 &&
#endif /* USE_MS2MIT */
hKrb524 &&
- hProfile && hAfsTokens && hAfsConf )
+ hProfile && hAfsTokens && hAfsConf && hLeash && hCCAPI )
return TRUE;
return FALSE;
}
char * ccname = 0;
krb5_error_code code;
+ if (!pkrb5_init_context)
+ return 0;
+
if ( alt_ctx ) {
ctx = alt_ctx;
} else {
char cell[128]="";
int i;
+ if (!pkrb5_init_context)
+ return;
+
if ( !MSLSA_IsKerberosLogon() )
return;
int cell_count=0;
afsconf_cell cellconfig;
+ if (!pkrb5_init_context)
+ return 0;
+
if ( IsDebuggerPresent() ) {
OutputDebugString("KFW_AFS_get_cred for token ");
OutputDebugString(username);
int count;
char ** principals = NULL;
+ if (!pkrb5_init_context)
+ return 0;
+
if ( IsDebuggerPresent() ) {
OutputDebugString("KFW_AFS_destroy_ticets_for_cell: ");
OutputDebugString(cell);
char local_cell[MAXCELLCHARS+1]="";
afsconf_cell cellconfig;
+ if (!pkrb5_init_context)
+ return 0;
+
if ( pcc_next == NULL ) // nothing to do
return 0;
int count;
char ** principals = NULL;
+ if (!pkrb5_init_context)
+ return 0;
+
if ( IsDebuggerPresent() ) {
OutputDebugString("KFW_AFS_renew_token_for_cell:");
OutputDebugString(cell);
if ( count > 0 ) {
krb5_principal princ = 0;
krb5_principal service = 0;
+#ifdef COMMENT
krb5_creds mcreds, creds;
+#endif /* COMMENT */
krb5_ccache cc = 0;
const char * realm = NULL;
afsconf_cell cellconfig;
krb5_creds my_creds;
krb5_data *realm = 0;
+ if (!pkrb5_init_context)
+ return 0;
+
memset(&my_creds, 0, sizeof(krb5_creds));
if ( alt_ctx ) {
krb5_ccache cc;
krb5_error_code code;
+ if (!pkrb5_init_context)
+ return 0;
+
if (alt_ctx)
{
ctx = alt_ctx;
return(-2);
}
+ if (!pkrb5_init_context)
+ return 0;
+
memset(RealmName, '\0', sizeof(RealmName));
memset(CellName, '\0', sizeof(CellName));
memset(ServiceName, '\0', sizeof(ServiceName));
if (!cellconfig)
return 0;
+ if (!pkrb5_init_context)
+ return 0;
+
r = pkrb5_init_context(&ctx);
if ( !r )
r = pkrb5_get_host_realm(ctx, cellconfig->hostName[0], &realmlist);
return;
}
+ if (!pkrb5_init_context)
+ return;
+
if ( use_kfw ) {
code = pkrb5_init_context(&ctx);
if ( code ) goto cleanup;
if (code == ERROR_INSUFFICIENT_BUFFER) {
pIpAddrTable = malloc(dwSize);
code = GetIpAddrTable(pIpAddrTable, &dwSize, 0);
- for ( index=0; index < pIpAddrTable->dwNumEntries; index++ ) {
- if (pIpAddrTable->table[index].dwAddr != 0)
- validAddrs++;
+ if ( code == NO_ERROR ) {
+ for ( index=0; index < pIpAddrTable->dwNumEntries; index++ ) {
+ if (pIpAddrTable->table[index].dwAddr != 0)
+ validAddrs++;
+ }
}
free(pIpAddrTable);
}
IpAddrChangeMonitor(void * hWnd)
{
#ifdef USE_OVERLAPPED
- HANDLE Handle = INVALID_HANDLE_VALUE;
+ HANDLE Handle = INVALID_HANDLE_VALUE; /* Do Not Close This Handle */
OVERLAPPED Ovlap;
#endif /* USE_OVERLAPPED */
DWORD Result;
DWORD prevNumOfAddrs = GetNumOfIpAddrs();
DWORD NumOfAddrs;
+ char message[256];
if ( !hWnd )
return;
Result = NotifyAddrChange(&Handle,&Ovlap);
if (Result != ERROR_IO_PENDING)
{
- printf("NotifyAddrChange() failed with error %d \n", Result);
+ if ( IsDebuggerPresent() ) {
+ sprintf(message, "NotifyAddrChange() failed with error %d \n", Result);
+ OutputDebugString(message);
+ }
break;
}
- if ((Result = WaitForSingleObject(Handle,INFINITE)) == WAIT_FAILED)
+ if ((Result = WaitForSingleObject(Handle,INFINITE)) != WAIT_OBJECT_0)
{
- printf("WaitForSingleObject() failed with error %d\n",
- GetLastError());
+ if ( IsDebuggerPresent() ) {
+ sprintf(message, "WaitForSingleObject() failed with error %d\n",
+ GetLastError());
+ OutputDebugString(message);
+ }
continue;
}
if (GetOverlappedResult(Handle, &Ovlap,
&DataTransfered, TRUE) == 0)
{
- printf("GetOverlapped result failed %d \n",
- GetLastError());
+ if ( IsDebuggerPresent() ) {
+ sprintf(message, "GetOverlapped result failed %d \n",
+ GetLastError());
+ OutputDebugString(message);
+ }
break;
}
-
#else
Result = NotifyAddrChange(NULL,NULL);
+ if (Result != NO_ERROR)
+ {
+ if ( IsDebuggerPresent() ) {
+ sprintf(message, "NotifyAddrChange() failed with error %d \n", Result);
+ OutputDebugString(message);
+ }
+ break;
+ }
#endif
NumOfAddrs = GetNumOfIpAddrs();
if ( IsDebuggerPresent() ) {
- char message[256];
sprintf(message,"IPAddrChangeMonitor() NumOfAddrs: now %d was %d\n",
NumOfAddrs, prevNumOfAddrs);
OutputDebugString(message);
}
prevNumOfAddrs = NumOfAddrs;
}
-
-#ifdef USE_OVERLAPPED
- if (Handle != INVALID_HANDLE_VALUE)
- CloseHandle(Handle);
-#endif
}