Index: openafs/src/WINNT/afsd/NTMakefile diff -c openafs/src/WINNT/afsd/NTMakefile:1.27 openafs/src/WINNT/afsd/NTMakefile:1.27.2.1 *** openafs/src/WINNT/afsd/NTMakefile:1.27 Thu Aug 5 12:31:34 2004 --- openafs/src/WINNT/afsd/NTMakefile Thu Aug 19 15:50:58 2004 *************** *** 221,227 **** $(AFSKFWLIB) LOGON_DLLSDKLIBS =\ ! dnsapi.lib mpr.lib \ advapi32.lib \ secur32.lib \ strsafe.lib \ --- 221,229 ---- $(AFSKFWLIB) LOGON_DLLSDKLIBS =\ ! dnsapi.lib \ ! netapi32.lib \ ! mpr.lib \ advapi32.lib \ secur32.lib \ strsafe.lib \ Index: openafs/src/WINNT/afsd/afsd_init.c diff -c openafs/src/WINNT/afsd/afsd_init.c:1.40.2.1 openafs/src/WINNT/afsd/afsd_init.c:1.40.2.2 *** openafs/src/WINNT/afsd/afsd_init.c:1.40.2.1 Mon Aug 9 16:57:11 2004 --- openafs/src/WINNT/afsd/afsd_init.c Tue Aug 17 00:28:38 2004 *************** *** 46,52 **** cm_volume_t *cm_rootVolumep = NULL; cm_cell_t *cm_rootCellp = NULL; cm_fid_t cm_rootFid; ! cm_scache_t *cm_rootSCachep; char cm_mountRoot[1024]; DWORD cm_mountRootLen; int cm_logChunkSize; --- 46,52 ---- cm_volume_t *cm_rootVolumep = NULL; cm_cell_t *cm_rootCellp = NULL; cm_fid_t cm_rootFid; ! cm_scache_t *cm_rootSCachep = NULL; char cm_mountRoot[1024]; DWORD cm_mountRootLen; int cm_logChunkSize; *************** *** 71,77 **** char cm_NetbiosName[MAX_NB_NAME_LENGTH] = ""; ! char cm_CachePath[200]; DWORD cm_CachePathLen; BOOL isGateway = FALSE; --- 71,77 ---- char cm_NetbiosName[MAX_NB_NAME_LENGTH] = ""; ! char cm_CachePath[MAX_PATH]; DWORD cm_CachePathLen; BOOL isGateway = FALSE; *************** *** 553,560 **** code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout", NULL, NULL, (BYTE *) <to, &dummyLen); if (code == ERROR_SUCCESS) ! afsi_log("Logoff token tranfer timeout %d seconds", ! ltto); else { ltto = 10; afsi_log("Default logoff token transfer timeout 10 seconds"); --- 553,559 ---- code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout", NULL, NULL, (BYTE *) <to, &dummyLen); if (code == ERROR_SUCCESS) ! afsi_log("Logoff token tranfer timeout %d seconds", ltto); else { ltto = 10; afsi_log("Default logoff token transfer timeout 10 seconds"); *************** *** 647,654 **** cm_sysName = cm_sysNameList[0]; dummyLen = MAXSYSNAME; ! code = RegQueryValueEx(parmKey, "SysName", NULL, NULL, ! cm_sysName, &dummyLen); if (code == ERROR_SUCCESS) afsi_log("Sys name %s", cm_sysName); else { --- 646,652 ---- cm_sysName = cm_sysNameList[0]; dummyLen = MAXSYSNAME; ! code = RegQueryValueEx(parmKey, "SysName", NULL, NULL, cm_sysName, &dummyLen); if (code == ERROR_SUCCESS) afsi_log("Sys name %s", cm_sysName); else { *************** *** 943,953 **** } } #ifdef AFS_FREELANCE_CLIENT if (cm_freelanceEnabled) cm_InitFreelance(); #endif - return 0; } --- 941,951 ---- } } + #ifdef AFS_FREELANCE_CLIENT if (cm_freelanceEnabled) cm_InitFreelance(); #endif return 0; } Index: openafs/src/WINNT/afsd/afskfw.c diff -c openafs/src/WINNT/afsd/afskfw.c:1.8 openafs/src/WINNT/afsd/afskfw.c:1.8.2.1 *** openafs/src/WINNT/afsd/afskfw.c:1.8 Sun Jul 11 17:23:07 2004 --- openafs/src/WINNT/afsd/afskfw.c Tue Aug 17 00:28:38 2004 *************** *** 62,67 **** --- 62,68 ---- #include #include /* for life_to_time */ + #include /* * TIMING _____________________________________________________________________ *************** *** 2378,2383 **** --- 2379,2492 ---- return(0); } + + #define ALLOW_REGISTER 1 + static int + ViceIDToUsername(char *username, + char *realm_of_user, + char *realm_of_cell, + char * cell_to_use, + struct ktc_principal *aclient, + struct ktc_principal *aserver, + struct ktc_token *atoken) + { + static char lastcell[MAXCELLCHARS+1] = { 0 }; + static char confname[512] = { 0 }; + char username_copy[BUFSIZ]; + long viceId; /* AFS uid of user */ + int status = 0; + #ifdef ALLOW_REGISTER + afs_int32 id; + #endif /* ALLOW_REGISTER */ + + if (confname[0] == '\0') { + strncpy(confname, AFSDIR_CLIENT_ETC_DIRPATH, sizeof(confname)); + confname[sizeof(confname) - 2] = '\0'; + } + + /* + * Talk about DUMB! It turns out that there is a bug in + * pr_Initialize -- even if you give a different cell name + * to it, it still uses a connection to a previous AFS server + * if one exists. The way to fix this is to change the + * _filename_ argument to pr_Initialize - that forces it to + * re-initialize the connection. We do this by adding and + * removing a "/" on the end of the configuration directory name. + */ + + if (lastcell[0] != '\0' && (strcmp(lastcell, aserver->cell) != 0)) { + int i = strlen(confname); + if (confname[i - 1] == '/') { + confname[i - 1] = '\0'; + } else { + confname[i] = '/'; + confname[i + 1] = '\0'; + } + } + + strcpy(lastcell, aserver->cell); + + if (!pr_Initialize (0, confname, aserver->cell)) + status = pr_SNameToId (username, &viceId); + + /* + * This is a crock, but it is Transarc's crock, so + * we have to play along in order to get the + * functionality. The way the afs id is stored is + * as a string in the username field of the token. + * Contrary to what you may think by looking at + * the code for tokens, this hack (AFS ID %d) will + * not work if you change %d to something else. + */ + + /* + * This code is taken from cklog -- it lets people + * automatically register with the ptserver in foreign cells + */ + + #ifdef ALLOW_REGISTER + if (status == 0) { + if (viceId != ANONYMOUSID) { + #else /* ALLOW_REGISTER */ + if ((status == 0) && (viceId != ANONYMOUSID)) + #endif /* ALLOW_REGISTER */ + { + #ifdef AFS_ID_TO_NAME + strncpy(username_copy, username, BUFSIZ); + snprintf (username, BUFSIZ, "%s (AFS ID %d)", username_copy, (int) viceId); + #endif /* AFS_ID_TO_NAME */ + } + #ifdef ALLOW_REGISTER + } else if (strcmp(realm_of_user, realm_of_cell) != 0) { + id = 0; + strncpy(aclient->name, username, MAXKTCNAMELEN - 1); + strcpy(aclient->instance, ""); + strncpy(aclient->cell, realm_of_user, MAXKTCREALMLEN - 1); + if (status = ktc_SetToken(aserver, atoken, aclient, 0)) + return status; + + /* + * In case you're wondering, we don't need to change the + * filename here because we're still connecting to the + * same cell -- we're just using a different authentication + * level + */ + + if (status = pr_Initialize(1L, confname, aserver->cell, 0)) + return status; + if (status = pr_CreateUser(username, &id)) + return status; + #ifdef AFS_ID_TO_NAME + strncpy(username_copy, username, BUFSIZ); + snprintf (username, BUFSIZ, "%s (AFS ID %d)", username_copy, (int) viceId); + #endif /* AFS_ID_TO_NAME */ + } + } + #endif /* ALLOW_REGISTER */ + return status; + } + + int KFW_AFS_klog( krb5_context alt_ctx, *************** *** 2717,2722 **** --- 2826,2834 ---- p[len] = '\0'; } + ViceIDToUsername(aclient.name, realm_of_user, realm_of_cell, CellName, + &aclient, &aserver, &atoken); + if ( smbname ) { strncpy(aclient.smbname, smbname, sizeof(aclient.smbname)); aclient.smbname[sizeof(aclient.smbname)-1] = '\0'; *************** *** 2835,2840 **** --- 2947,2955 ---- strcpy(aclient.cell, CellName); + ViceIDToUsername(aclient.name, realm_of_user, realm_of_cell, CellName, + &aclient, &aserver, &atoken); + if ( smbname ) { strncpy(aclient.smbname, smbname, sizeof(aclient.smbname)); aclient.smbname[sizeof(aclient.smbname)-1] = '\0'; Index: openafs/src/WINNT/afsd/afslogon.c diff -c openafs/src/WINNT/afsd/afslogon.c:1.24.2.1 openafs/src/WINNT/afsd/afslogon.c:1.24.2.3 *** openafs/src/WINNT/afsd/afslogon.c:1.24.2.1 Mon Aug 9 23:46:24 2004 --- openafs/src/WINNT/afsd/afslogon.c Fri Aug 20 16:17:00 2004 *************** *** 15,20 **** --- 15,21 ---- #include #include + #include #include #include *************** *** 35,66 **** void DebugEvent0(char *a) { ! HANDLE h; char *ptbuf[1]; ! if (!ISLOGONTRACE(TraceOption)) ! return; ! h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME); ! ptbuf[0] = a; ! ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL); ! DeregisterEventSource(h); } #define MAXBUF_ 512 void DebugEvent(char *b,...) { ! HANDLE h; char *ptbuf[1],buf[MAXBUF_+1]; ! va_list marker; ! if (!ISLOGONTRACE(TraceOption)) ! return; ! h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME); ! va_start(marker,b); ! StringCbVPrintf(buf, MAXBUF_+1,b,marker); buf[MAXBUF_] = '\0'; ! ptbuf[0] = buf; ! ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);\ ! DeregisterEventSource(h); ! va_end(marker); } static HANDLE hInitMutex = NULL; --- 36,67 ---- void DebugEvent0(char *a) { ! HANDLE h; char *ptbuf[1]; ! if (!ISLOGONTRACE(TraceOption)) ! return; ! h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME); ! ptbuf[0] = a; ! ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL); ! DeregisterEventSource(h); } #define MAXBUF_ 512 void DebugEvent(char *b,...) { ! HANDLE h; char *ptbuf[1],buf[MAXBUF_+1]; ! va_list marker; ! if (!ISLOGONTRACE(TraceOption)) ! return; ! h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME); ! va_start(marker,b); ! StringCbVPrintf(buf, MAXBUF_+1,b,marker); buf[MAXBUF_] = '\0'; ! ptbuf[0] = buf; ! ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL); ! DeregisterEventSource(h); ! va_end(marker); } static HANDLE hInitMutex = NULL; *************** *** 68,75 **** BOOLEAN APIENTRY DllEntryPoint(HANDLE dll, DWORD reason, PVOID reserved) { ! hDLL = dll; ! switch (reason) { case DLL_PROCESS_ATTACH: /* Initialization Mutex */ hInitMutex = CreateMutex(NULL, FALSE, NULL); --- 69,76 ---- BOOLEAN APIENTRY DllEntryPoint(HANDLE dll, DWORD reason, PVOID reserved) { ! hDLL = dll; ! switch (reason) { case DLL_PROCESS_ATTACH: /* Initialization Mutex */ hInitMutex = CreateMutex(NULL, FALSE, NULL); *************** *** 82,199 **** case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: default: ! /* Everything else succeeds but does nothing. */ break; ! } ! return TRUE; } void AfsLogonInit(void) { if ( bInit == FALSE ) { ! if ( WaitForSingleObject( hInitMutex, INFINITE ) == WAIT_OBJECT_0 ) { ! if ( bInit == FALSE ) { ! rx_Init(0); ! initAFSDirPath(); ! ka_Init(0); ! bInit = TRUE; ! } ! ReleaseMutex(hInitMutex); ! } } } CHAR *GenRandomName(CHAR *pbuf) { ! int i; ! srand( (unsigned)time( NULL ) ); ! for (i=0;idwStartType < SERVICE_DEMAND_START) ! result = TRUE; ! ! free_pConfig: ! GlobalFree(pConfig); ! close_svc: ! CloseServiceHandle(svc); ! close_scm: ! CloseServiceHandle(scm); ! return result; } DWORD MapAuthError(DWORD code) { ! switch (code) { ! /* Unfortunately, returning WN_NO_NETWORK results in the MPR abandoning ! * logon scripts for all credential managers, although they will still ! * receive logon notifications. Since we don't want this, we return ! * WN_SUCCESS. This is highly undesirable, but we also don't want to ! * break other network providers. ! */ ! /* case KTC_NOCM: ! case KTC_NOCMRPC: ! return WN_NO_NETWORK; */ ! default: return WN_SUCCESS; ! } } DWORD APIENTRY NPGetCaps(DWORD index) { ! switch (index) { ! case WNNC_NET_TYPE: ! /* Don't have our own type; use somebody else's. */ ! return WNNC_NET_SUN_PC_NFS; ! ! case WNNC_START: ! /* Say we are already started, even though we might wait after we receive NPLogonNotify */ ! return 1; ! ! default: ! return 0; ! } } BOOL IsServiceRunning (void) --- 83,235 ---- case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: default: ! /* Everything else succeeds but does nothing. */ break; ! } ! return TRUE; } void AfsLogonInit(void) { if ( bInit == FALSE ) { ! if ( WaitForSingleObject( hInitMutex, INFINITE ) == WAIT_OBJECT_0 ) { ! if ( bInit == FALSE ) { ! rx_Init(0); ! initAFSDirPath(); ! ka_Init(0); ! bInit = TRUE; ! } ! ReleaseMutex(hInitMutex); ! } } } CHAR *GenRandomName(CHAR *pbuf) { ! int i; ! srand( (unsigned)time( NULL ) ); ! for (i=0;idwStartType < SERVICE_DEMAND_START) ! result = TRUE; ! ! free_pConfig: ! GlobalFree(pConfig); ! close_svc: ! CloseServiceHandle(svc); ! close_scm: ! CloseServiceHandle(scm); ! return result; } DWORD MapAuthError(DWORD code) { ! switch (code) { ! /* Unfortunately, returning WN_NO_NETWORK results in the MPR abandoning ! * logon scripts for all credential managers, although they will still ! * receive logon notifications. Since we don't want this, we return ! * WN_SUCCESS. This is highly undesirable, but we also don't want to ! * break other network providers. ! */ ! /* case KTC_NOCM: ! case KTC_NOCMRPC: ! return WN_NO_NETWORK; */ ! default: return WN_SUCCESS; ! } } DWORD APIENTRY NPGetCaps(DWORD index) { ! switch (index) { ! case WNNC_NET_TYPE: ! /* Don't have our own type; use somebody else's. */ ! return WNNC_NET_SUN_PC_NFS; ! ! case WNNC_START: ! /* Say we are already started, even though we might wait after we receive NPLogonNotify */ ! return 1; ! ! default: ! return 0; ! } ! } ! ! NET_API_STATUS ! NetUserGetProfilePath( LPCWSTR Domain, LPCWSTR UserName, char * profilePath, ! DWORD profilePathLen ) ! { ! NET_API_STATUS code; ! LPWSTR ServerName = NULL; ! LPUSER_INFO_3 p3 = NULL; ! ! NetGetAnyDCName(NULL, Domain, (LPBYTE *)&ServerName); ! /* if NetGetAnyDCName fails, ServerName == NULL ! * NetUserGetInfo will obtain local user information ! */ ! code = NetUserGetInfo(ServerName, UserName, 3, (LPBYTE *)&p3); ! if (code == NERR_Success) ! { ! code = NERR_UserNotFound; ! if (p3) { ! if (p3->usri3_profile) { ! DWORD len = lstrlenW(p3->usri3_profile); ! if (len > 0) { ! /* Convert From Unicode to ANSI (UTF-8 for future) */ ! len = len < profilePathLen ? len : profilePathLen - 1; ! WideCharToMultiByte(CP_UTF8, 0, p3->usri3_profile, len, profilePath, len, NULL, NULL); ! profilePath[len] = '\0'; ! code = NERR_Success; ! } ! } ! NetApiBufferFree(p3); ! } ! } ! if (ServerName) ! NetApiBufferFree(ServerName); ! return code; } BOOL IsServiceRunning (void) *************** *** 251,485 **** /* Get domain specific configuration info. We are returning void because if anything goes wrong we just return defaults. */ ! void GetDomainLogonOptions( PLUID lpLogonId, char * username, char * domain, LogonOptions_t *opt ) { ! HKEY hkParm = NULL; /* Service parameter */ ! HKEY hkNp = NULL; /* network provider key */ ! HKEY hkDoms = NULL; /* domains key */ ! HKEY hkDom = NULL; /* DOMAINS/domain key */ ! HKEY hkTemp = NULL; ! LONG rv; ! DWORD dwSize; ! DWORD dwType; ! DWORD dwDummy; ! char computerName[MAX_COMPUTERNAME_LENGTH + 1]; ! char *effDomain; ! ! DebugEvent("In GetDomainLogonOptions for user [%s] in domain [%s]", username, domain); ! /* If the domain is the same as the Netbios computer name, we use the LOCALHOST domain name*/ ! opt->flags = LOGON_FLAG_REMOTE; ! if(domain) { ! dwSize = MAX_COMPUTERNAME_LENGTH; ! if(GetComputerName(computerName, &dwSize)) { ! if(!stricmp(computerName, domain)) { ! effDomain = "LOCALHOST"; ! opt->flags = LOGON_FLAG_LOCAL; ! } ! else ! effDomain = domain; ! } ! } else ! effDomain = NULL; ! ! rv = RegOpenKeyEx( HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, 0, KEY_READ, &hkParm ); ! if(rv != ERROR_SUCCESS) { ! hkParm = NULL; ! DebugEvent("GetDomainLogonOption: Can't open parms key [%d]", rv); ! } ! ! rv = RegOpenKeyEx( HKEY_LOCAL_MACHINE, REG_CLIENT_PROVIDER_KEY, 0, KEY_READ, &hkNp ); ! if(rv != ERROR_SUCCESS) { ! hkNp = NULL; ! DebugEvent("GetDomainLogonOptions: Can't open NP key [%d]", rv); ! } ! ! if(hkNp) { ! rv = RegOpenKeyEx( hkNp, REG_CLIENT_DOMAINS_SUBKEY, 0, KEY_READ, &hkDoms ); ! if( rv != ERROR_SUCCESS ) { ! hkDoms = NULL; ! DebugEvent("GetDomainLogonOptions: Can't open Domains key [%d]", rv); ! } ! } ! ! if(hkDoms && effDomain) { ! rv = RegOpenKeyEx( hkDoms, effDomain, 0, KEY_READ, &hkDom ); ! if( rv != ERROR_SUCCESS ) { ! hkDom = NULL; ! DebugEvent("GetDomainLogonOptions: Can't open domain key for [%s] [%d]", effDomain, rv); ! /* If none of the domains match, we shouldn't use the domain key either */ ! RegCloseKey(hkDoms); ! hkDoms = NULL; ! } ! } else ! DebugEvent("Not opening domain key for [%s]", effDomain); ! ! /* Each individual can either be specified on the domain key, the domains key or in the ! net provider key. They fail over in that order. If none is found, we just use the ! defaults. */ ! ! /* LogonOption */ ! LOOKUPKEYCHAIN(opt->LogonOption, REG_DWORD, DEFAULT_LOGON_OPTION, REG_CLIENT_LOGON_OPTION_PARM); ! ! /* FailLoginsSilently */ ! dwSize = sizeof(dwDummy); ! rv = RegQueryValueEx(hkParm, REG_CLIENT_FAIL_SILENTLY_PARM, 0, &dwType, (LPBYTE) &dwDummy, &dwSize); ! if(rv != ERROR_SUCCESS) ! LOOKUPKEYCHAIN(dwDummy, REG_DWORD, DEFAULT_FAIL_SILENTLY, REG_CLIENT_FAIL_SILENTLY_PARM); opt->failSilently = !!dwDummy; ! /* Retry interval */ ! LOOKUPKEYCHAIN(opt->retryInterval, REG_DWORD, DEFAULT_RETRY_INTERVAL, REG_CLIENT_RETRY_INTERVAL_PARM); ! /* Sleep interval */ ! LOOKUPKEYCHAIN(opt->sleepInterval, REG_DWORD, DEFAULT_SLEEP_INTERVAL, REG_CLIENT_SLEEP_INTERVAL_PARM); ! opt->logonScript = NULL; ! opt->smbName = NULL; ! if(!ISLOGONINTEGRATED(opt->LogonOption)) { ! goto cleanup; /* no need to lookup the logon script */ ! } ! /* come up with SMB username */ ! if(ISHIGHSECURITY(opt->LogonOption)) { opt->smbName = malloc( MAXRANDOMNAMELEN ); ! GenRandomName(opt->smbName); ! } else { ! /* username and domain for logon session is not necessarily the same as ! username and domain passed into network provider. */ ! PSECURITY_LOGON_SESSION_DATA plsd; ! char lsaUsername[MAX_USERNAME_LENGTH]; ! char lsaDomain[MAX_DOMAIN_LENGTH]; ! size_t len, tlen; LsaGetLogonSessionData(lpLogonId, &plsd); ! UnicodeStringToANSI(plsd->UserName, lsaUsername, MAX_USERNAME_LENGTH); ! UnicodeStringToANSI(plsd->LogonDomain, lsaDomain, MAX_DOMAIN_LENGTH); ! DebugEvent("PLSD username[%s] domain[%s]",lsaUsername,lsaDomain); ! if(SUCCEEDED(StringCbLength(lsaUsername, MAX_USERNAME_LENGTH, &tlen))) ! len = tlen; ! else ! goto bad_strings; ! ! if(SUCCEEDED(StringCbLength(lsaDomain, MAX_DOMAIN_LENGTH, &tlen))) ! len += tlen; ! else ! goto bad_strings; ! ! len += 2; ! ! opt->smbName = malloc(len); ! ! StringCbCopy(opt->smbName, len, lsaDomain); ! StringCbCat(opt->smbName, len, "\\"); ! StringCbCat(opt->smbName, len, lsaUsername); ! ! strlwr(opt->smbName); ! ! bad_strings: ! LsaFreeReturnBuffer(plsd); ! } ! ! DebugEvent("Looking up logon script"); ! /* Logon script */ ! /* First find out where the key is */ ! hkTemp = NULL; ! rv = ~ERROR_SUCCESS; ! dwType = 0; ! if(hkDom) ! rv = RegQueryValueExW(hkDom, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, NULL, &dwSize); ! if(rv == ERROR_SUCCESS && (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) { ! hkTemp = hkDom; ! DebugEvent("Located logon script in hkDom"); ! } ! else if(hkDoms) ! rv = RegQueryValueExW(hkDoms, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, NULL, &dwSize); ! if(rv == ERROR_SUCCESS && !hkTemp && (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) { ! hkTemp = hkDoms; ! DebugEvent("Located logon script in hkDoms"); ! } ! /* Note that the LogonScript in the NP key is only used if we are doing high security. */ ! else if(hkNp && ISHIGHSECURITY(opt->LogonOption)) ! rv = RegQueryValueExW(hkNp, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, NULL, &dwSize); ! if(rv == ERROR_SUCCESS && !hkTemp && (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) { ! hkTemp = hkNp; ! DebugEvent("Located logon script in hkNp"); ! } ! ! if(hkTemp) { ! WCHAR *regscript = NULL; ! WCHAR *regexscript = NULL; ! WCHAR *regexuscript = NULL; ! WCHAR *wuname = NULL; ! HRESULT hr; ! size_t len; ! ! StringCbLength(opt->smbName, MAX_USERNAME_LENGTH, &len); ! len ++; ! wuname = malloc(len * sizeof(WCHAR)); ! MultiByteToWideChar(CP_ACP,0,opt->smbName,-1,wuname,len*sizeof(WCHAR)); ! DebugEvent("Username is set for [%S]", wuname); ! /* dwSize still has the size of the required buffer in bytes. */ regscript = malloc(dwSize); ! rv = RegQueryValueExW(hkTemp, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, (LPBYTE) regscript, &dwSize); ! if(rv != ERROR_SUCCESS) {/* what the ..? */ ! DebugEvent("Can't look up logon script [%d]",rv); ! goto doneLogonScript; ! } ! ! DebugEvent("Found logon script [%S]", regscript); ! if(dwType == REG_EXPAND_SZ) { ! DWORD dwReq; ! dwSize += MAX_PATH * sizeof(WCHAR); /* make room for environment expansion. */ ! regexscript = malloc(dwSize); ! dwReq = ExpandEnvironmentStringsW(regscript, regexscript, dwSize / sizeof(WCHAR)); ! free(regscript); ! regscript = regexscript; ! regexscript = NULL; ! if(dwReq > (dwSize / sizeof(WCHAR))) { ! DebugEvent("Overflow while expanding environment strings."); ! goto doneLogonScript; ! } ! } ! ! DebugEvent("After expanding env strings [%S]", regscript); ! ! if(wcsstr(regscript, L"%s")) { ! dwSize += len * sizeof(WCHAR); /* make room for username expansion */ ! regexuscript = (WCHAR *) LocalAlloc(LMEM_FIXED, dwSize); ! hr = StringCbPrintfW(regexuscript, dwSize, regscript, wuname); ! } else { ! regexuscript = (WCHAR *) LocalAlloc(LMEM_FIXED, dwSize); ! hr = StringCbCopyW(regexuscript, dwSize, regscript); ! } ! ! DebugEvent("After expanding username [%S]", regexuscript); ! ! if(hr == S_OK) ! opt->logonScript = regexuscript; ! else ! LocalFree(regexuscript); ! ! doneLogonScript: ! if(wuname) free(wuname); ! if(regscript) free(regscript); ! if(regexscript) free(regexscript); ! } ! ! cleanup: ! if(hkNp) RegCloseKey(hkNp); ! if(hkDom) RegCloseKey(hkDom); ! if(hkDoms) RegCloseKey(hkDoms); ! if(hkParm) RegCloseKey(hkParm); ! } #undef LOOKUPKEYCHAIN --- 287,522 ---- /* Get domain specific configuration info. We are returning void because if anything goes wrong we just return defaults. */ ! void ! GetDomainLogonOptions( PLUID lpLogonId, char * username, char * domain, LogonOptions_t *opt ) { ! HKEY hkParm = NULL; /* Service parameter */ ! HKEY hkNp = NULL; /* network provider key */ ! HKEY hkDoms = NULL; /* domains key */ ! HKEY hkDom = NULL; /* DOMAINS/domain key */ ! HKEY hkTemp = NULL; ! LONG rv; ! DWORD dwSize; ! DWORD dwType; ! DWORD dwDummy; ! char computerName[MAX_COMPUTERNAME_LENGTH + 1]; ! char *effDomain; ! ! DebugEvent("In GetDomainLogonOptions for user [%s] in domain [%s]", username, domain); ! /* If the domain is the same as the Netbios computer name, we use the LOCALHOST domain name*/ ! opt->flags = LOGON_FLAG_REMOTE; ! if(domain) { ! dwSize = MAX_COMPUTERNAME_LENGTH; ! if(GetComputerName(computerName, &dwSize)) { ! if(!stricmp(computerName, domain)) { ! effDomain = "LOCALHOST"; ! opt->flags = LOGON_FLAG_LOCAL; ! } ! else ! effDomain = domain; ! } ! } else ! effDomain = NULL; ! ! rv = RegOpenKeyEx( HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, 0, KEY_READ, &hkParm ); ! if(rv != ERROR_SUCCESS) { ! hkParm = NULL; ! DebugEvent("GetDomainLogonOption: Can't open parms key [%d]", rv); ! } ! ! rv = RegOpenKeyEx( HKEY_LOCAL_MACHINE, REG_CLIENT_PROVIDER_KEY, 0, KEY_READ, &hkNp ); ! if(rv != ERROR_SUCCESS) { ! hkNp = NULL; ! DebugEvent("GetDomainLogonOptions: Can't open NP key [%d]", rv); ! } ! ! if(hkNp) { ! rv = RegOpenKeyEx( hkNp, REG_CLIENT_DOMAINS_SUBKEY, 0, KEY_READ, &hkDoms ); ! if( rv != ERROR_SUCCESS ) { ! hkDoms = NULL; ! DebugEvent("GetDomainLogonOptions: Can't open Domains key [%d]", rv); ! } ! } ! ! if(hkDoms && effDomain) { ! rv = RegOpenKeyEx( hkDoms, effDomain, 0, KEY_READ, &hkDom ); ! if( rv != ERROR_SUCCESS ) { ! hkDom = NULL; ! DebugEvent("GetDomainLogonOptions: Can't open domain key for [%s] [%d]", effDomain, rv); ! /* If none of the domains match, we shouldn't use the domain key either */ ! RegCloseKey(hkDoms); ! hkDoms = NULL; ! } ! } else ! DebugEvent("Not opening domain key for [%s]", effDomain); ! ! /* Each individual can either be specified on the domain key, the domains key or in the ! net provider key. They fail over in that order. If none is found, we just use the ! defaults. */ ! ! /* LogonOption */ ! LOOKUPKEYCHAIN(opt->LogonOption, REG_DWORD, DEFAULT_LOGON_OPTION, REG_CLIENT_LOGON_OPTION_PARM); ! ! /* FailLoginsSilently */ ! dwSize = sizeof(dwDummy); ! rv = RegQueryValueEx(hkParm, REG_CLIENT_FAIL_SILENTLY_PARM, 0, &dwType, (LPBYTE) &dwDummy, &dwSize); ! if (rv != ERROR_SUCCESS) ! LOOKUPKEYCHAIN(dwDummy, REG_DWORD, DEFAULT_FAIL_SILENTLY, REG_CLIENT_FAIL_SILENTLY_PARM); opt->failSilently = !!dwDummy; ! /* Retry interval */ ! LOOKUPKEYCHAIN(opt->retryInterval, REG_DWORD, DEFAULT_RETRY_INTERVAL, REG_CLIENT_RETRY_INTERVAL_PARM); ! /* Sleep interval */ ! LOOKUPKEYCHAIN(opt->sleepInterval, REG_DWORD, DEFAULT_SLEEP_INTERVAL, REG_CLIENT_SLEEP_INTERVAL_PARM); ! opt->logonScript = NULL; ! opt->smbName = NULL; ! if(!ISLOGONINTEGRATED(opt->LogonOption)) { ! goto cleanup; /* no need to lookup the logon script */ ! } ! /* come up with SMB username */ ! if(ISHIGHSECURITY(opt->LogonOption)) { opt->smbName = malloc( MAXRANDOMNAMELEN ); ! GenRandomName(opt->smbName); ! } else { ! /* username and domain for logon session is not necessarily the same as ! username and domain passed into network provider. */ ! PSECURITY_LOGON_SESSION_DATA plsd; ! char lsaUsername[MAX_USERNAME_LENGTH]; ! char lsaDomain[MAX_DOMAIN_LENGTH]; ! size_t len, tlen; LsaGetLogonSessionData(lpLogonId, &plsd); ! UnicodeStringToANSI(plsd->UserName, lsaUsername, MAX_USERNAME_LENGTH); ! UnicodeStringToANSI(plsd->LogonDomain, lsaDomain, MAX_DOMAIN_LENGTH); ! DebugEvent("PLSD username[%s] domain[%s]",lsaUsername,lsaDomain); ! if(SUCCEEDED(StringCbLength(lsaUsername, MAX_USERNAME_LENGTH, &tlen))) ! len = tlen; ! else ! goto bad_strings; ! if(SUCCEEDED(StringCbLength(lsaDomain, MAX_DOMAIN_LENGTH, &tlen))) ! len += tlen; ! else ! goto bad_strings; ! ! len += 2; ! ! opt->smbName = malloc(len); ! ! StringCbCopy(opt->smbName, len, lsaDomain); ! StringCbCat(opt->smbName, len, "\\"); ! StringCbCat(opt->smbName, len, lsaUsername); ! strlwr(opt->smbName); ! bad_strings: ! LsaFreeReturnBuffer(plsd); ! } ! ! DebugEvent("Looking up logon script"); ! /* Logon script */ ! /* First find out where the key is */ ! hkTemp = NULL; ! rv = ~ERROR_SUCCESS; ! dwType = 0; ! if(hkDom) ! rv = RegQueryValueExW(hkDom, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, NULL, &dwSize); ! if(rv == ERROR_SUCCESS && (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) { ! hkTemp = hkDom; ! DebugEvent("Located logon script in hkDom"); ! } ! else if(hkDoms) ! rv = RegQueryValueExW(hkDoms, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, NULL, &dwSize); ! if(rv == ERROR_SUCCESS && !hkTemp && (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) { ! hkTemp = hkDoms; ! DebugEvent("Located logon script in hkDoms"); ! } ! /* Note that the LogonScript in the NP key is only used if we are doing high security. */ ! else if(hkNp && ISHIGHSECURITY(opt->LogonOption)) ! rv = RegQueryValueExW(hkNp, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, NULL, &dwSize); ! if(rv == ERROR_SUCCESS && !hkTemp && (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) { ! hkTemp = hkNp; ! DebugEvent("Located logon script in hkNp"); ! } ! ! if(hkTemp) { ! WCHAR *regscript = NULL; ! WCHAR *regexscript = NULL; ! WCHAR *regexuscript = NULL; ! WCHAR *wuname = NULL; ! HRESULT hr; ! size_t len; ! ! StringCbLength(opt->smbName, MAX_USERNAME_LENGTH, &len); ! len ++; ! ! wuname = malloc(len * sizeof(WCHAR)); ! MultiByteToWideChar(CP_ACP,0,opt->smbName,-1,wuname,len*sizeof(WCHAR)); ! ! DebugEvent("Username is set for [%S]", wuname); ! ! /* dwSize still has the size of the required buffer in bytes. */ regscript = malloc(dwSize); ! rv = RegQueryValueExW(hkTemp, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, (LPBYTE) regscript, &dwSize); ! if(rv != ERROR_SUCCESS) {/* what the ..? */ ! DebugEvent("Can't look up logon script [%d]",rv); ! goto doneLogonScript; ! } ! DebugEvent("Found logon script [%S]", regscript); ! if(dwType == REG_EXPAND_SZ) { ! DWORD dwReq; ! ! dwSize += MAX_PATH * sizeof(WCHAR); /* make room for environment expansion. */ ! regexscript = malloc(dwSize); ! dwReq = ExpandEnvironmentStringsW(regscript, regexscript, dwSize / sizeof(WCHAR)); ! free(regscript); ! regscript = regexscript; ! regexscript = NULL; ! if(dwReq > (dwSize / sizeof(WCHAR))) { ! DebugEvent("Overflow while expanding environment strings."); ! goto doneLogonScript; ! } ! } ! ! DebugEvent("After expanding env strings [%S]", regscript); ! ! if(wcsstr(regscript, L"%s")) { ! dwSize += len * sizeof(WCHAR); /* make room for username expansion */ ! regexuscript = (WCHAR *) LocalAlloc(LMEM_FIXED, dwSize); ! hr = StringCbPrintfW(regexuscript, dwSize, regscript, wuname); ! } else { ! regexuscript = (WCHAR *) LocalAlloc(LMEM_FIXED, dwSize); ! hr = StringCbCopyW(regexuscript, dwSize, regscript); ! } ! ! DebugEvent("After expanding username [%S]", regexuscript); ! ! if(hr == S_OK) ! opt->logonScript = regexuscript; ! else ! LocalFree(regexuscript); ! ! doneLogonScript: ! if(wuname) free(wuname); ! if(regscript) free(regscript); ! if(regexscript) free(regexscript); ! } ! ! cleanup: ! if(hkNp) RegCloseKey(hkNp); ! if(hkDom) RegCloseKey(hkDom); ! if(hkDoms) RegCloseKey(hkDoms); ! if(hkParm) RegCloseKey(hkParm); ! } #undef LOOKUPKEYCHAIN *************** *** 487,508 **** the contents of *cell in case of failure. *cell is assumed to be at least cellLen chars */ DWORD GetFileCellName(char * path, char * cell, size_t cellLen) { ! struct ViceIoctl blob; ! char tcell[MAX_PATH]; ! DWORD code; ! ! blob.in_size = 0; ! blob.out_size = MAX_PATH; ! blob.out = tcell; ! ! code = pioctl(path, VIOC_FILE_CELL_NAME, &blob, 1); ! ! if(!code) { ! strncpy(cell, tcell, cellLen); ! cell[cellLen - 1] = '\0'; ! } ! return code; ! } static BOOL --- 524,545 ---- the contents of *cell in case of failure. *cell is assumed to be at least cellLen chars */ DWORD GetFileCellName(char * path, char * cell, size_t cellLen) { ! struct ViceIoctl blob; ! char tcell[MAX_PATH]; ! DWORD code; ! ! blob.in_size = 0; ! blob.out_size = MAX_PATH; ! blob.out = tcell; ! ! code = pioctl(path, VIOC_FILE_CELL_NAME, &blob, 1); ! ! if(!code) { ! strncpy(cell, tcell, cellLen); ! cell[cellLen - 1] = '\0'; ! } ! return code; ! } static BOOL *************** *** 526,533 **** lpszOutputString[min(uInputString.Length/2,nOutStringLen-1)] = '\0'; return TRUE; } ! else ! lpszOutputString[0] = '\0'; return FALSE; } // UnicodeStringToANSI --- 563,570 ---- lpszOutputString[min(uInputString.Length/2,nOutStringLen-1)] = '\0'; return TRUE; } ! else ! lpszOutputString[0] = '\0'; return FALSE; } // UnicodeStringToANSI *************** *** 541,597 **** LPVOID StationHandle, LPWSTR *lpLogonScript) { ! char uname[MAX_USERNAME_LENGTH]=""; ! char password[MAX_PASSWORD_LENGTH]=""; ! char logonDomain[MAX_DOMAIN_LENGTH]=""; ! char cell[256]=""; ! char homePath[MAX_PATH]=""; ! ! MSV1_0_INTERACTIVE_LOGON *IL; ! DWORD code; ! int pw_exp; ! char *reason; ! char *ctemp; ! BOOLEAN interactive; ! BOOLEAN flag; ! DWORD LSPtype, LSPsize; ! HKEY NPKey; ! HWND hwndOwner = (HWND)StationHandle; ! BOOLEAN afsWillAutoStart; BOOLEAN uppercased_name = TRUE; ! LogonOptions_t opt; /* domain specific logon options */ ! int retryInterval; ! int sleepInterval; /* Make sure the AFS Libraries are initialized */ AfsLogonInit(); /* Initialize Logon Script to none */ ! *lpLogonScript=NULL; ! /* TODO: We should check the value of lpAuthentInfoType before assuming that it is ! MSV1_0_INTERACTIVE_LOGON though for our purposes KERB_INTERACTIVE_LOGON is ! co-incidentally equivalent. */ ! IL = (MSV1_0_INTERACTIVE_LOGON *) lpAuthentInfo; ! ! /* Are we interactive? */ ! interactive = (wcscmp(lpStationName, L"WinSta0") == 0); ! ! /* Convert from Unicode to ANSI */ ! ! /*TODO: Use SecureZeroMemory to erase passwords */ ! UnicodeStringToANSI(IL->UserName, uname, MAX_USERNAME_LENGTH); ! UnicodeStringToANSI(IL->Password, password, MAX_PASSWORD_LENGTH); ! UnicodeStringToANSI(IL->LogonDomainName, logonDomain, MAX_DOMAIN_LENGTH); ! /* Make sure AD-DOMANS sent from login that is sent to us is striped */ ctemp = strchr(uname, '@'); if (ctemp) *ctemp = 0; --- 578,634 ---- LPVOID StationHandle, LPWSTR *lpLogonScript) { ! char uname[MAX_USERNAME_LENGTH]=""; ! char password[MAX_PASSWORD_LENGTH]=""; ! char logonDomain[MAX_DOMAIN_LENGTH]=""; ! char cell[256]=""; ! char homePath[MAX_PATH]=""; ! MSV1_0_INTERACTIVE_LOGON *IL; ! DWORD code; ! int pw_exp; ! char *reason; ! char *ctemp; ! ! BOOLEAN interactive; ! BOOLEAN flag; ! DWORD LSPtype, LSPsize; ! HKEY NPKey; ! HWND hwndOwner = (HWND)StationHandle; ! BOOLEAN afsWillAutoStart; BOOLEAN uppercased_name = TRUE; ! LogonOptions_t opt; /* domain specific logon options */ ! int retryInterval; ! int sleepInterval; /* Make sure the AFS Libraries are initialized */ AfsLogonInit(); /* Initialize Logon Script to none */ ! *lpLogonScript=NULL; ! /* TODO: We should check the value of lpAuthentInfoType before assuming that it is ! MSV1_0_INTERACTIVE_LOGON though for our purposes KERB_INTERACTIVE_LOGON is ! co-incidentally equivalent. */ ! IL = (MSV1_0_INTERACTIVE_LOGON *) lpAuthentInfo; ! ! /* Are we interactive? */ ! interactive = (wcscmp(lpStationName, L"WinSta0") == 0); ! ! /* Convert from Unicode to ANSI */ ! ! /*TODO: Use SecureZeroMemory to erase passwords */ ! UnicodeStringToANSI(IL->UserName, uname, MAX_USERNAME_LENGTH); ! UnicodeStringToANSI(IL->Password, password, MAX_PASSWORD_LENGTH); ! UnicodeStringToANSI(IL->LogonDomainName, logonDomain, MAX_DOMAIN_LENGTH); ! /* Make sure AD-DOMANS sent from login that is sent to us is striped */ ctemp = strchr(uname, '@'); if (ctemp) *ctemp = 0; *************** *** 603,662 **** } } ! (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, ! 0, KEY_QUERY_VALUE, &NPKey); ! LSPsize=sizeof(TraceOption); ! RegQueryValueEx(NPKey, REG_CLIENT_TRACE_OPTION_PARM, NULL, &LSPtype, (LPBYTE)&TraceOption, &LSPsize); ! RegCloseKey (NPKey); ! /* ! * Get Logon options ! */ ! GetDomainLogonOptions( lpLogonId, uname, logonDomain, &opt ); ! retryInterval = opt.retryInterval; ! sleepInterval = opt.sleepInterval; ! *lpLogonScript = opt.logonScript; ! DebugEvent("Got logon script: %S",opt.logonScript); ! afsWillAutoStart = AFSWillAutoStart(); ! DebugEvent("LogonOption[%x], Service AutoStart[%d]", opt.LogonOption,afsWillAutoStart); /* Check for zero length password if integrated logon*/ ! if ( ISLOGONINTEGRATED(opt.LogonOption) ) { if ( password[0] == 0 ) { DebugEvent("Password is the empty string"); code = GT_PW_NULL; reason = "zero length password is illegal"; code=0; ! } /* Get cell name if doing integrated logon. ! We might overwrite this if we are logging into an AD realm and we find out that ! the user's home dir is in some other cell. */ DebugEvent("About to call cm_GetRootCellName(%s)",cell); ! code = cm_GetRootCellName(cell); ! if (code < 0) { DebugEvent("Unable to obtain Root Cell"); ! code = KTC_NOCELL; ! reason = "unknown cell"; ! code=0; ! } else { DebugEvent("Cell is %s",cell); ! } ! /* We get the user's home directory path, if applicable, though we can't lookup the ! cell right away because the client service may not have started yet. This call ! also sets the AD_REALM flag in opt.flags if applicable. */ ! if(ISREMOTE(opt.flags)) { DebugEvent("Is Remote"); ! GetAdHomePath(homePath,MAX_PATH,lpLogonId,&opt); ! } } /* loop until AFS is started. */ --- 640,699 ---- } } ! (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, ! 0, KEY_QUERY_VALUE, &NPKey); ! LSPsize=sizeof(TraceOption); ! RegQueryValueEx(NPKey, REG_CLIENT_TRACE_OPTION_PARM, NULL, &LSPtype, (LPBYTE)&TraceOption, &LSPsize); ! RegCloseKey (NPKey); ! /* ! * Get Logon options ! */ ! GetDomainLogonOptions( lpLogonId, uname, logonDomain, &opt ); ! retryInterval = opt.retryInterval; ! sleepInterval = opt.sleepInterval; ! *lpLogonScript = opt.logonScript; ! DebugEvent("Got logon script: %S",opt.logonScript); ! afsWillAutoStart = AFSWillAutoStart(); ! DebugEvent("LogonOption[%x], Service AutoStart[%d]", opt.LogonOption,afsWillAutoStart); /* Check for zero length password if integrated logon*/ ! if ( ISLOGONINTEGRATED(opt.LogonOption) ) { if ( password[0] == 0 ) { DebugEvent("Password is the empty string"); code = GT_PW_NULL; reason = "zero length password is illegal"; code=0; ! } /* Get cell name if doing integrated logon. ! We might overwrite this if we are logging into an AD realm and we find out that ! the user's home dir is in some other cell. */ DebugEvent("About to call cm_GetRootCellName(%s)",cell); ! code = cm_GetRootCellName(cell); ! if (code < 0) { DebugEvent("Unable to obtain Root Cell"); ! code = KTC_NOCELL; ! reason = "unknown cell"; ! code=0; ! } else { DebugEvent("Cell is %s",cell); ! } ! /* We get the user's home directory path, if applicable, though we can't lookup the ! cell right away because the client service may not have started yet. This call ! also sets the AD_REALM flag in opt.flags if applicable. */ ! if(ISREMOTE(opt.flags)) { DebugEvent("Is Remote"); ! GetAdHomePath(homePath,MAX_PATH,lpLogonId,&opt); ! } } /* loop until AFS is started. */ *************** *** 665,694 **** opt.LogonOption,afsWillAutoStart); if(ISADREALM(opt.flags)) { ! code = GetFileCellName(homePath,cell,256); ! if(!code) { ! DebugEvent("profile path [%s] is in cell [%s]",homePath,cell); ! } ! /* Don't bail out if GetFileCellName failed. ! * The home dir may not be in AFS after all. ! */ ! } else ! code=0; /* if Integrated Logon */ if (ISLOGONINTEGRATED(opt.LogonOption)) ! { ! if ( KFW_is_available() ) { code = KFW_AFS_get_cred(uname, cell, password, 0, opt.smbName, &reason); ! DebugEvent("KFW_AFS_get_cred uname=[%s] smbname=[%s] cell=[%s] code=[%d]",uname,opt.smbName,cell,code); ! } ! else { code = ka_UserAuthenticateGeneral2(KA_USERAUTH_VERSION+KA_USERAUTH_AUTHENT_LOGON, ! uname, "", cell, password, opt.smbName, 0, &pw_exp, 0, ! &reason); ! DebugEvent("AFS AfsLogon - (INTEGRATED only)ka_UserAuthenticateGeneral2","Code[%x]", ! code); ! } if ( code && code != KTC_NOCM && code != KTC_NOCMRPC && uppercased_name ) { for ( ctemp = uname; *ctemp ; ctemp++) { *ctemp = tolower(*ctemp); --- 702,731 ---- opt.LogonOption,afsWillAutoStart); if(ISADREALM(opt.flags)) { ! code = GetFileCellName(homePath,cell,256); ! if(!code) { ! DebugEvent("profile path [%s] is in cell [%s]",homePath,cell); ! } ! /* Don't bail out if GetFileCellName failed. ! * The home dir may not be in AFS after all. ! */ ! } else ! code=0; /* if Integrated Logon */ if (ISLOGONINTEGRATED(opt.LogonOption)) ! { ! if ( KFW_is_available() ) { code = KFW_AFS_get_cred(uname, cell, password, 0, opt.smbName, &reason); ! DebugEvent("KFW_AFS_get_cred uname=[%s] smbname=[%s] cell=[%s] code=[%d]",uname,opt.smbName,cell,code); ! } ! else { code = ka_UserAuthenticateGeneral2(KA_USERAUTH_VERSION+KA_USERAUTH_AUTHENT_LOGON, ! uname, "", cell, password, opt.smbName, 0, &pw_exp, 0, ! &reason); ! DebugEvent("AFS AfsLogon - (INTEGRATED only)ka_UserAuthenticateGeneral2","Code[%x]", ! code); ! } if ( code && code != KTC_NOCM && code != KTC_NOCMRPC && uppercased_name ) { for ( ctemp = uname; *ctemp ; ctemp++) { *ctemp = tolower(*ctemp); *************** *** 696,722 **** uppercased_name = FALSE; continue; } ! } ! else { /*JUST check to see if its running*/ ! if (IsServiceRunning()) break; ! code = KTC_NOCM; ! if (!afsWillAutoStart) break; ! } ! /* is service started yet?*/ DebugEvent("AFS AfsLogon - ka_UserAuthenticateGeneral2","Code[%x] uname[%s] Cell[%s]", ! code,uname,cell); ! /* If we've failed because the client isn't running yet and the * client is set to autostart (and therefore it makes sense for * us to wait for it to start) then sleep a while and try again. * If the error was something else, then give up. */ ! if (code != KTC_NOCM && code != KTC_NOCMRPC || !afsWillAutoStart) ! break; ! /* If the retry interval has expired and we still aren't * logged in, then just give up if we are not in interactive * mode or the failSilently flag is set, otherwise let the --- 733,759 ---- uppercased_name = FALSE; continue; } ! } ! else { /*JUST check to see if its running*/ ! if (IsServiceRunning()) break; ! code = KTC_NOCM; ! if (!afsWillAutoStart) break; ! } ! /* is service started yet?*/ DebugEvent("AFS AfsLogon - ka_UserAuthenticateGeneral2","Code[%x] uname[%s] Cell[%s]", ! code,uname,cell); ! /* If we've failed because the client isn't running yet and the * client is set to autostart (and therefore it makes sense for * us to wait for it to start) then sleep a while and try again. * If the error was something else, then give up. */ ! if (code != KTC_NOCM && code != KTC_NOCMRPC || !afsWillAutoStart) ! break; ! /* If the retry interval has expired and we still aren't * logged in, then just give up if we are not in interactive * mode or the failSilently flag is set, otherwise let the *************** *** 725,735 **** reason = "AFS not running"; if (!interactive || opt.failSilently) break; ! flag = MessageBox(hwndOwner, "AFS is still starting. Retry?", "AFS Logon", MB_ICONQUESTION | MB_RETRYCANCEL); ! if (flag == IDCANCEL) break; /* Wait just a little while and try again */ --- 762,772 ---- reason = "AFS not running"; if (!interactive || opt.failSilently) break; ! flag = MessageBox(hwndOwner, "AFS is still starting. Retry?", "AFS Logon", MB_ICONQUESTION | MB_RETRYCANCEL); ! if (flag == IDCANCEL) break; /* Wait just a little while and try again */ *************** *** 737,745 **** } if (retryInterval < sleepInterval) ! sleepInterval = retryInterval; ! Sleep(sleepInterval * 1000); retryInterval -= sleepInterval; } --- 774,782 ---- } if (retryInterval < sleepInterval) ! sleepInterval = retryInterval; ! Sleep(sleepInterval * 1000); retryInterval -= sleepInterval; } *************** *** 749,763 **** if ( KFW_is_available() ) KFW_AFS_destroy_tickets_for_cell(cell); ! if (code) { char msg[128]; HANDLE h; char *ptbuf[1]; ! StringCbPrintf(msg, sizeof(msg), "Integrated login failed: %s", reason); ! if (ISLOGONINTEGRATED(opt.LogonOption) && interactive && !opt.failSilently) ! MessageBox(hwndOwner, msg, "AFS Logon", MB_OK); h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME); ptbuf[0] = msg; --- 786,800 ---- if ( KFW_is_available() ) KFW_AFS_destroy_tickets_for_cell(cell); ! if (code) { char msg[128]; HANDLE h; char *ptbuf[1]; ! StringCbPrintf(msg, sizeof(msg), "Integrated login failed: %s", reason); ! if (ISLOGONINTEGRATED(opt.LogonOption) && interactive && !opt.failSilently) ! MessageBox(hwndOwner, msg, "AFS Logon", MB_OK); h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME); ptbuf[0] = msg; *************** *** 766,789 **** DeregisterEventSource(h); code = MapAuthError(code); ! SetLastError(code); ! if (ISLOGONINTEGRATED(opt.LogonOption) && (code!=0)) ! { ! if (*lpLogonScript) ! LocalFree(*lpLogonScript); ! *lpLogonScript = NULL; ! if (!afsWillAutoStart) // its not running, so if not autostart or integrated logon then just skip ! code = 0; ! } ! } ! if(opt.smbName) free(opt.smbName); ! DebugEvent("AFS AfsLogon - Exit","Return Code[%x]",code); ! return code; ! } DWORD APIENTRY NPPasswordChangeNotify( LPCWSTR lpAuthentInfoType, --- 803,826 ---- DeregisterEventSource(h); code = MapAuthError(code); ! SetLastError(code); ! if (ISLOGONINTEGRATED(opt.LogonOption) && (code!=0)) ! { ! if (*lpLogonScript) ! LocalFree(*lpLogonScript); ! *lpLogonScript = NULL; ! if (!afsWillAutoStart) // its not running, so if not autostart or integrated logon then just skip ! code = 0; ! } ! } ! if(opt.smbName) free(opt.smbName); ! DebugEvent("AFS AfsLogon - Exit","Return Code[%x]",code); ! return code; ! } DWORD APIENTRY NPPasswordChangeNotify( LPCWSTR lpAuthentInfoType, *************** *** 797,804 **** /* Make sure the AFS Libraries are initialized */ AfsLogonInit(); ! DebugEvent0("AFS AfsLogon - NPPasswordChangeNotify"); ! return 0; } #include --- 834,841 ---- /* Make sure the AFS Libraries are initialized */ AfsLogonInit(); ! DebugEvent0("AFS AfsLogon - NPPasswordChangeNotify"); ! return 0; } #include *************** *** 837,863 **** VOID AFS_Startup_Event( PWLX_NOTIFICATION_INFO pInfo ) { ! DWORD LSPtype, LSPsize; ! HKEY NPKey; /* Make sure the AFS Libraries are initialized */ AfsLogonInit(); (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, 0, KEY_QUERY_VALUE, &NPKey); ! LSPsize=sizeof(TraceOption); ! RegQueryValueEx(NPKey, REG_CLIENT_TRACE_OPTION_PARM, NULL, &LSPtype, (LPBYTE)&TraceOption, &LSPsize); ! RegCloseKey (NPKey); DebugEvent0("AFS_Startup_Event"); } VOID AFS_Logoff_Event( PWLX_NOTIFICATION_INFO pInfo ) { DWORD code; ! TCHAR profileDir[256] = TEXT(""); ! DWORD len = 256; PTOKEN_USER tokenUser = NULL; DWORD retLen; HANDLE hToken; --- 874,900 ---- VOID AFS_Startup_Event( PWLX_NOTIFICATION_INFO pInfo ) { ! DWORD LSPtype, LSPsize; ! HKEY NPKey; /* Make sure the AFS Libraries are initialized */ AfsLogonInit(); (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, 0, KEY_QUERY_VALUE, &NPKey); ! LSPsize=sizeof(TraceOption); ! RegQueryValueEx(NPKey, REG_CLIENT_TRACE_OPTION_PARM, NULL, &LSPtype, (LPBYTE)&TraceOption, &LSPsize); ! RegCloseKey (NPKey); DebugEvent0("AFS_Startup_Event"); } VOID AFS_Logoff_Event( PWLX_NOTIFICATION_INFO pInfo ) { DWORD code; ! TCHAR profileDir[1024] = TEXT(""); ! DWORD len = 1024; PTOKEN_USER tokenUser = NULL; DWORD retLen; HANDLE hToken; *************** *** 885,892 **** if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, pInfo->Domain)) { WCHAR Domain[64]=L""; GetLocalShortDomain(Domain, sizeof(Domain)); ! if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, Domain)) ! GetUserProfileDirectory(pInfo->hToken, profileDir, &len); } if (strlen(profileDir)) { --- 922,931 ---- if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, pInfo->Domain)) { WCHAR Domain[64]=L""; GetLocalShortDomain(Domain, sizeof(Domain)); ! if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, Domain)) { ! if (NetUserGetProfilePath(pInfo->Domain, pInfo->UserName, profileDir, len)) ! GetUserProfileDirectory(pInfo->hToken, profileDir, &len); ! } } if (strlen(profileDir)) { Index: openafs/src/WINNT/afsd/cm_access.c diff -c openafs/src/WINNT/afsd/cm_access.c:1.4 openafs/src/WINNT/afsd/cm_access.c:1.4.2.1 *** openafs/src/WINNT/afsd/cm_access.c:1.4 Sun May 9 00:04:52 2004 --- openafs/src/WINNT/afsd/cm_access.c Tue Aug 17 00:28:38 2004 *************** *** 101,107 **** /* fall through */ done: ! if (didLock) lock_ReleaseMutex(&aclScp->mx); cm_ReleaseSCache(aclScp); return code; } --- 101,108 ---- /* fall through */ done: ! if (didLock) ! lock_ReleaseMutex(&aclScp->mx); cm_ReleaseSCache(aclScp); return code; } Index: openafs/src/WINNT/afsd/cm_buf.c diff -c openafs/src/WINNT/afsd/cm_buf.c:1.13 openafs/src/WINNT/afsd/cm_buf.c:1.13.2.1 *** openafs/src/WINNT/afsd/cm_buf.c:1.13 Thu Jul 29 10:34:21 2004 --- openafs/src/WINNT/afsd/cm_buf.c Tue Aug 17 00:28:38 2004 *************** *** 491,501 **** */ long buf_SetNBuffers(long nbuffers) { ! if (nbuffers < 10) return CM_ERROR_INVAL; ! if (nbuffers == buf_nbuffers) return 0; else if (nbuffers > buf_nbuffers) return buf_AddBuffers(nbuffers - buf_nbuffers); ! else return CM_ERROR_INVAL; } /* release a buffer. Buffer must be referenced, but unlocked. */ --- 491,504 ---- */ long buf_SetNBuffers(long nbuffers) { ! if (nbuffers < 10) ! return CM_ERROR_INVAL; ! if (nbuffers == buf_nbuffers) ! return 0; else if (nbuffers > buf_nbuffers) return buf_AddBuffers(nbuffers - buf_nbuffers); ! else ! return CM_ERROR_INVAL; } /* release a buffer. Buffer must be referenced, but unlocked. */ *************** *** 652,659 **** * have any lock conflicts, so we can grab the buffer lock out of * order in the locking hierarchy. */ ! osi_Log2(buf_logp, ! "buf_Recycle recycles 0x%x, off 0x%x", bp, bp->offset.LowPart); osi_assert(bp->refCount == 0); --- 655,661 ---- * have any lock conflicts, so we can grab the buffer lock out of * order in the locking hierarchy. */ ! osi_Log2( buf_logp, "buf_Recycle recycles 0x%x, off 0x%x", bp, bp->offset.LowPart); osi_assert(bp->refCount == 0); *************** *** 1296,1302 **** } lock_ReleaseWrite(&buf_globalLock); - } lock_ReleaseMutex(&scp->mx); --- 1298,1303 ---- Index: openafs/src/WINNT/afsd/cm_buf.h diff -c openafs/src/WINNT/afsd/cm_buf.h:1.4 openafs/src/WINNT/afsd/cm_buf.h:1.4.2.1 *** openafs/src/WINNT/afsd/cm_buf.h:1.4 Thu Jul 29 10:34:21 2004 --- openafs/src/WINNT/afsd/cm_buf.h Tue Aug 17 00:28:38 2004 *************** *** 72,78 **** */ struct cm_buf *allp; /* next in all list */ osi_mutex_t mx; /* mutex protecting structure except refcount */ ! int refCount; /* reference count */ long idCounter; /* counter for softrefs; bumped at each recycle */ long dirtyCounter; /* bumped at each dirty->clean transition */ #ifdef notdef --- 72,78 ---- */ struct cm_buf *allp; /* next in all list */ osi_mutex_t mx; /* mutex protecting structure except refcount */ ! int refCount; /* reference count (buf_globalLock) */ long idCounter; /* counter for softrefs; bumped at each recycle */ long dirtyCounter; /* bumped at each dirty->clean transition */ #ifdef notdef Index: openafs/src/WINNT/afsd/cm_callback.c diff -c openafs/src/WINNT/afsd/cm_callback.c:1.20 openafs/src/WINNT/afsd/cm_callback.c:1.20.2.3 *** openafs/src/WINNT/afsd/cm_callback.c:1.20 Tue Aug 3 16:10:36 2004 --- openafs/src/WINNT/afsd/cm_callback.c Thu Aug 19 15:51:23 2004 *************** *** 90,122 **** /* * When we lose a callback, may have to send change notification replies. */ void cm_CallbackNotifyChange(cm_scache_t *scp) { osi_Log2(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX", scp->fileType, scp->flags); ! if (scp->fileType == CM_SCACHETYPE_DIRECTORY) { ! if (scp->flags & CM_SCACHEFLAG_ANYWATCH) ! smb_NotifyChange(0, ! FILE_NOTIFY_GENERIC_DIRECTORY_FILTER, ! scp, NULL, NULL, TRUE); ! } else { ! cm_fid_t tfid; ! cm_scache_t *dscp; ! ! tfid.cell = scp->fid.cell; ! tfid.volume = scp->fid.volume; ! tfid.vnode = scp->parentVnode; ! tfid.unique = scp->parentUnique; ! dscp = cm_FindSCache(&tfid); ! if (dscp && ! dscp->flags & CM_SCACHEFLAG_ANYWATCH) ! smb_NotifyChange(0, ! FILE_NOTIFY_GENERIC_FILE_FILTER, ! dscp, NULL, NULL, TRUE); ! if (dscp) cm_ReleaseSCache(dscp); ! } } /* called with no locks held for every file ID that is revoked directly by --- 90,123 ---- /* * When we lose a callback, may have to send change notification replies. + * Do not call with a lock on the scp. */ void cm_CallbackNotifyChange(cm_scache_t *scp) { osi_Log2(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX", scp->fileType, scp->flags); ! if (scp->fileType == CM_SCACHETYPE_DIRECTORY) { ! if (scp->flags & CM_SCACHEFLAG_ANYWATCH) ! smb_NotifyChange(0, ! FILE_NOTIFY_GENERIC_DIRECTORY_FILTER, ! scp, NULL, NULL, TRUE); ! } else { ! cm_fid_t tfid; ! cm_scache_t *dscp; ! ! tfid.cell = scp->fid.cell; ! tfid.volume = scp->fid.volume; ! tfid.vnode = scp->parentVnode; ! tfid.unique = scp->parentUnique; ! dscp = cm_FindSCache(&tfid); ! if (dscp && ! dscp->flags & CM_SCACHEFLAG_ANYWATCH) ! smb_NotifyChange( 0, ! FILE_NOTIFY_GENERIC_FILE_FILTER, ! dscp, NULL, NULL, TRUE); ! if (dscp) cm_ReleaseSCache(dscp); ! } } /* called with no locks held for every file ID that is revoked directly by *************** *** 635,645 **** int fdc, fgc; if (cm_freelanceEnabled && ! scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && ! scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) { // if it's something on /afs ! if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) // if it's not root.afs return 1; ! else { lock_ObtainMutex(&cm_Freelance_Lock); fdc = cm_fakeDirCallback; fgc = cm_fakeGettingCallback; --- 636,648 ---- int fdc, fgc; if (cm_freelanceEnabled && ! scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) { ! /* if it's something on /afs */ ! if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) { ! /* if it's not root.afs */ return 1; ! } ! lock_ObtainMutex(&cm_Freelance_Lock); fdc = cm_fakeDirCallback; fgc = cm_fakeGettingCallback; *************** *** 659,670 **** } return 0; } - } #endif if (scp->cbServerp != NULL) return 1; ! else return 0; } /* need to detect a broken callback that races with our obtaining a callback. --- 662,673 ---- } return 0; } #endif if (scp->cbServerp != NULL) return 1; ! else ! return 0; } /* need to detect a broken callback that races with our obtaining a callback. *************** *** 708,713 **** --- 711,717 ---- cm_racingRevokes_t *revp; /* where we are */ cm_racingRevokes_t *nrevp; /* where we'll be next */ int freeFlag; + cm_server_t * serverp = 0; lock_ObtainWrite(&cm_callbackLock); if (flags & CM_CALLBACK_MAINTAINCOUNT) { *************** *** 716,728 **** else { osi_assert(cm_activeCallbackGrantingCalls-- > 0); } ! if (cm_activeCallbackGrantingCalls == 0) freeFlag = 1; ! else freeFlag = 0; /* record the callback; we'll clear it below if we really lose it */ if (scp) { scp->cbServerp = cbrp->serverp; scp->cbExpires = cbrp->startTime + cbp->ExpirationTime; } /* a callback was actually revoked during our granting call, so --- 720,742 ---- else { osi_assert(cm_activeCallbackGrantingCalls-- > 0); } ! if (cm_activeCallbackGrantingCalls == 0) ! freeFlag = 1; ! else ! freeFlag = 0; /* record the callback; we'll clear it below if we really lose it */ + if (cbrp) { if (scp) { + if (scp->cbServerp != cbrp->serverp) { + serverp = scp->cbServerp; + } scp->cbServerp = cbrp->serverp; scp->cbExpires = cbrp->startTime + cbp->ExpirationTime; + } else { + serverp = cbrp->serverp; + } + cbrp->serverp = NULL; } /* a callback was actually revoked during our granting call, so *************** *** 737,743 **** * callback-granting call, and if this fid is the right fid, * then clear the callback. */ ! if (scp && cbrp->callbackCount != cm_callbackCount && revp->callbackCount > cbrp->callbackCount && (( scp->fid.volume == revp->fid.volume && scp->fid.vnode == revp->fid.vnode && --- 751,757 ---- * callback-granting call, and if this fid is the right fid, * then clear the callback. */ ! if (scp && cbrp && cbrp->callbackCount != cm_callbackCount && revp->callbackCount > cbrp->callbackCount && (( scp->fid.volume == revp->fid.volume && scp->fid.vnode == revp->fid.vnode && *************** *** 769,774 **** --- 783,794 ---- if (freeFlag) cm_racingRevokesp = NULL; lock_ReleaseWrite(&cm_callbackLock); + + if ( serverp ) { + lock_ObtainWrite(&cm_serverLock); + cm_FreeServer(serverp); + lock_ReleaseWrite(&cm_serverLock); + } } /* if flags is 1, we want to force the code to make one call, anyway. *************** *** 799,808 **** scp->fid.volume==AFS_FAKE_ROOT_VOL_ID && scp->fid.unique==0x1 && scp->fid.vnode==0x1) { // Start by indicating that we're in the process // of fetching the callback - lock_ObtainMutex(&cm_Freelance_Lock); cm_fakeGettingCallback = 1; lock_ReleaseMutex(&cm_Freelance_Lock); --- 819,829 ---- scp->fid.volume==AFS_FAKE_ROOT_VOL_ID && scp->fid.unique==0x1 && scp->fid.vnode==0x1) { + // Start by indicating that we're in the process // of fetching the callback lock_ObtainMutex(&cm_Freelance_Lock); + osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1"); cm_fakeGettingCallback = 1; lock_ReleaseMutex(&cm_Freelance_Lock); *************** *** 811,818 **** --- 832,842 ---- // Indicate that the callback is not done lock_ObtainMutex(&cm_Freelance_Lock); + osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2"); cm_fakeDirCallback = 2; + // Indicate that we're no longer fetching the callback + osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0"); cm_fakeGettingCallback = 0; lock_ReleaseMutex(&cm_Freelance_Lock); *************** *** 861,867 **** cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0); } else ! cm_EndCallbackGrantingCall(NULL, NULL, NULL, 0); /* now check to see if we got an error */ if (code) return code; --- 885,891 ---- cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0); } else ! cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0); /* now check to see if we got an error */ if (code) return code; *************** *** 871,899 **** /* called periodically by cm_daemon to shut down use of expired callbacks */ void cm_CheckCBExpiration(void) { ! int i; ! cm_scache_t *scp; ! long now; osi_Log0(afsd_logp, "CheckCBExpiration"); ! now = osi_Time(); ! lock_ObtainWrite(&cm_scacheLock); ! for(i=0; inextp) { ! scp->refCount++; ! lock_ReleaseWrite(&cm_scacheLock); ! lock_ObtainMutex(&scp->mx); ! if (scp->cbServerp && now > scp->cbExpires) { ! osi_Log1(afsd_logp, "Discarding SCache scp %x", scp); ! cm_DiscardSCache(scp); ! } ! lock_ReleaseMutex(&scp->mx); ! lock_ObtainWrite(&cm_scacheLock); ! osi_assert(scp->refCount-- > 0); ! } } ! lock_ReleaseWrite(&cm_scacheLock); } /* debug interface: not implemented */ --- 895,924 ---- /* called periodically by cm_daemon to shut down use of expired callbacks */ void cm_CheckCBExpiration(void) { ! int i; ! cm_scache_t *scp; ! long now; osi_Log0(afsd_logp, "CheckCBExpiration"); ! now = osi_Time(); ! lock_ObtainWrite(&cm_scacheLock); ! for(i=0; inextp) { ! scp->refCount++; ! lock_ReleaseWrite(&cm_scacheLock); ! if (scp->cbExpires > 0 && (scp->cbServerp == NULL || now > scp->cbExpires)) { ! osi_Log1(afsd_logp, "Callback Expiration Discarding SCache scp %x", scp); ! cm_CallbackNotifyChange(scp); ! lock_ObtainMutex(&scp->mx); ! cm_DiscardSCache(scp); ! lock_ReleaseMutex(&scp->mx); ! } ! lock_ObtainWrite(&cm_scacheLock); ! osi_assert(scp->refCount-- > 0); } ! } ! lock_ReleaseWrite(&cm_scacheLock); } /* debug interface: not implemented */ Index: openafs/src/WINNT/afsd/cm_callback.h diff -c openafs/src/WINNT/afsd/cm_callback.h:1.3 openafs/src/WINNT/afsd/cm_callback.h:1.3.16.1 *** openafs/src/WINNT/afsd/cm_callback.h:1.3 Mon Apr 30 02:48:03 2001 --- openafs/src/WINNT/afsd/cm_callback.h Tue Aug 17 00:28:38 2004 *************** *** 64,67 **** --- 64,69 ---- extern void cm_CheckCBExpiration(void); + extern osi_rwlock_t cm_callbackLock; + #endif /* _CM_CALLBACK_H_ENV__ */ Index: openafs/src/WINNT/afsd/cm_cell.c diff -c openafs/src/WINNT/afsd/cm_cell.c:1.14 openafs/src/WINNT/afsd/cm_cell.c:1.14.2.1 *** openafs/src/WINNT/afsd/cm_cell.c:1.14 Wed Aug 4 11:52:56 2004 --- openafs/src/WINNT/afsd/cm_cell.c Tue Aug 17 13:16:02 2004 *************** *** 105,118 **** code = cm_SearchCellFile(namep, fullname, cm_AddCellProc, cp); if (code) { ! afsi_log("in cm_GetCell_gen cm_SearchCellFile(%s) returns code= %d fullname= %s", namep, code, fullname); #ifdef AFS_AFSDB_ENV if (cm_dnsEnabled /*&& cm_DomainValid(namep)*/) { code = cm_SearchCellByDNS(namep, fullname, &ttl, cm_AddCellProc, cp); if ( code ) { ! afsi_log("in cm_GetCell_gen cm_SearchCellByDNS(%s) returns code= %d fullname= %s", namep, code, fullname); if (dns_expired) { cp->flags |= CM_CELLFLAG_VLSERVER_INVALID; --- 105,118 ---- code = cm_SearchCellFile(namep, fullname, cm_AddCellProc, cp); if (code) { ! osi_Log3(afsd_logp,"in cm_GetCell_gen cm_SearchCellFile(%s) returns code= %d fullname= %s", namep, code, fullname); #ifdef AFS_AFSDB_ENV if (cm_dnsEnabled /*&& cm_DomainValid(namep)*/) { code = cm_SearchCellByDNS(namep, fullname, &ttl, cm_AddCellProc, cp); if ( code ) { ! osi_Log3(afsd_logp,"in cm_GetCell_gen cm_SearchCellByDNS(%s) returns code= %d fullname= %s", namep, code, fullname); if (dns_expired) { cp->flags |= CM_CELLFLAG_VLSERVER_INVALID; Index: openafs/src/WINNT/afsd/cm_conn.c diff -c openafs/src/WINNT/afsd/cm_conn.c:1.25 openafs/src/WINNT/afsd/cm_conn.c:1.25.2.1 *** openafs/src/WINNT/afsd/cm_conn.c:1.25 Wed Aug 4 11:52:56 2004 --- openafs/src/WINNT/afsd/cm_conn.c Tue Aug 17 00:28:38 2004 *************** *** 94,100 **** #else gettimeofday(&reqp->startTime, NULL); #endif - } static long cm_GetServerList(struct cm_fid *fidp, struct cm_user *userp, --- 94,99 ---- *************** *** 144,150 **** cm_serverRef_t * serversp, cm_callbackRequest_t *cbrp, long errorCode) { ! cm_server_t *serverp; cm_serverRef_t **serverspp = 0; cm_serverRef_t *tsrp; cm_ucell_t *ucellp; --- 143,149 ---- cm_serverRef_t * serversp, cm_callbackRequest_t *cbrp, long errorCode) { ! cm_server_t *serverp = 0; cm_serverRef_t **serverspp = 0; cm_serverRef_t *tsrp; cm_ucell_t *ucellp; *************** *** 163,170 **** serverp = connp->serverp; /* Update callback pointer */ ! if (cbrp && errorCode == 0) ! cbrp->serverp = connp->serverp; /* If not allowed to retry, don't */ if (reqp->flags & CM_REQ_NORETRY) --- 162,182 ---- serverp = connp->serverp; /* Update callback pointer */ ! if (cbrp && serverp && errorCode == 0) { ! if (cbrp->serverp) { ! if ( cbrp->serverp != serverp ) { ! lock_ObtainWrite(&cm_serverLock); ! cm_PutServerNoLock(cbrp->serverp); ! cm_GetServerNoLock(serverp); ! lock_ReleaseWrite(&cm_serverLock); ! } ! } else { ! cm_GetServer(serverp); ! } ! lock_ObtainWrite(&cm_callbackLock); ! cbrp->serverp = serverp; ! lock_ReleaseWrite(&cm_callbackLock); ! } /* If not allowed to retry, don't */ if (reqp->flags & CM_REQ_NORETRY) *************** *** 398,404 **** lock_ObtainWrite(&cm_serverLock); for (tsrp = serversp; tsrp; tsrp=tsrp->next) { tsp = tsrp->server; ! tsp->refCount++; lock_ReleaseWrite(&cm_serverLock); if (!(tsp->flags & CM_SERVERFLAG_DOWN)) { allDown = 0; --- 410,416 ---- lock_ObtainWrite(&cm_serverLock); for (tsrp = serversp; tsrp; tsrp=tsrp->next) { tsp = tsrp->server; ! cm_GetServerNoLock(tsp); lock_ReleaseWrite(&cm_serverLock); if (!(tsp->flags & CM_SERVERFLAG_DOWN)) { allDown = 0; *************** *** 422,428 **** rx_SetConnDeadTime((*connpp)->callp, timeLeft); rx_SetConnHardDeadTime((*connpp)->callp, (u_short) hardTimeLeft); lock_ReleaseMutex(&(*connpp)->mx); - return 0; } if (firstError == 0) --- 434,439 ---- *************** *** 430,436 **** } } lock_ObtainWrite(&cm_serverLock); ! osi_assert(tsp->refCount-- > 0); } lock_ReleaseWrite(&cm_serverLock); --- 441,447 ---- } } lock_ObtainWrite(&cm_serverLock); ! cm_PutServerNoLock(tsp); } lock_ReleaseWrite(&cm_serverLock); *************** *** 462,467 **** --- 473,479 ---- userp = tcp->userp; if (userp && tcp->refCount == 0 && (userp->vcRefs == 0)) { /* do the deletion of this guy */ + cm_PutServer(tcp->serverp); cm_ReleaseUser(userp); *lcpp = tcp->nextp; rx_DestroyConnection(tcp->callp); *************** *** 532,542 **** lock_ObtainMutex(&userp->mx); lock_ObtainWrite(&cm_connLock); for(tcp = serverp->connsp; tcp; tcp=tcp->nextp) { ! if (tcp->userp == userp) break; } /* find ucell structure */ ucellp = cm_GetUCell(userp, serverp->cellp); if (!tcp) { tcp = malloc(sizeof(*tcp)); memset(tcp, 0, sizeof(*tcp)); tcp->nextp = serverp->connsp; --- 544,557 ---- lock_ObtainMutex(&userp->mx); lock_ObtainWrite(&cm_connLock); for(tcp = serverp->connsp; tcp; tcp=tcp->nextp) { ! if (tcp->userp == userp) ! break; } + /* find ucell structure */ ucellp = cm_GetUCell(userp, serverp->cellp); if (!tcp) { + cm_GetServer(serverp); tcp = malloc(sizeof(*tcp)); memset(tcp, 0, sizeof(*tcp)); tcp->nextp = serverp->connsp; Index: openafs/src/WINNT/afsd/cm_daemon.c diff -c openafs/src/WINNT/afsd/cm_daemon.c:1.4 openafs/src/WINNT/afsd/cm_daemon.c:1.4.2.1 *** openafs/src/WINNT/afsd/cm_daemon.c:1.4 Sun Apr 4 22:16:11 2004 --- openafs/src/WINNT/afsd/cm_daemon.c Tue Aug 17 00:28:39 2004 *************** *** 95,109 **** /* periodic check daemon */ void cm_Daemon(long parm) { ! long now; ! long lastLockCheck; ! long lastVolCheck; ! long lastCBExpirationCheck; ! long lastDownServerCheck; ! long lastUpServerCheck; ! long lastTokenCacheCheck; char thostName[200]; ! long code; struct hostent *thp; /* ping all file servers, up or down, with unauthenticated connection, --- 95,109 ---- /* periodic check daemon */ void cm_Daemon(long parm) { ! unsigned long now; ! unsigned long lastLockCheck; ! unsigned long lastVolCheck; ! unsigned long lastCBExpirationCheck; ! unsigned long lastDownServerCheck; ! unsigned long lastUpServerCheck; ! unsigned long lastTokenCacheCheck; char thostName[200]; ! unsigned long code; struct hostent *thp; /* ping all file servers, up or down, with unauthenticated connection, Index: openafs/src/WINNT/afsd/cm_dcache.c diff -c openafs/src/WINNT/afsd/cm_dcache.c:1.11 openafs/src/WINNT/afsd/cm_dcache.c:1.11.2.1 *** openafs/src/WINNT/afsd/cm_dcache.c:1.11 Sat Aug 7 01:44:05 2004 --- openafs/src/WINNT/afsd/cm_dcache.c Tue Aug 17 00:28:39 2004 *************** *** 15,21 **** --- 15,23 ---- #include #include #endif /* !DJGPP */ + #ifdef COMMENT #include + #endif #include #include #include *************** *** 407,414 **** while(length > 0) { /* get callback so we can do a meaningful dataVersion comparison */ code = cm_SyncOp(scp, NULL, up, reqp, 0, ! CM_SCACHESYNC_NEEDCALLBACK ! | CM_SCACHESYNC_GETSTATUS); if (code) { scp->flags &= ~CM_SCACHEFLAG_PREFETCHING; lock_ReleaseMutex(&scp->mx); --- 409,415 ---- while(length > 0) { /* get callback so we can do a meaningful dataVersion comparison */ code = cm_SyncOp(scp, NULL, up, reqp, 0, ! CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); if (code) { scp->flags &= ~CM_SCACHEFLAG_PREFETCHING; lock_ReleaseMutex(&scp->mx); *************** *** 836,843 **** biop->reserved = 0; /* first lookup the file's length, so we know when to stop */ ! code = cm_SyncOp(scp, NULL, up, reqp, 0, CM_SCACHESYNC_NEEDCALLBACK ! | CM_SCACHESYNC_GETSTATUS); if (code) return code; --- 837,844 ---- biop->reserved = 0; /* first lookup the file's length, so we know when to stop */ ! code = cm_SyncOp(scp, NULL, up, reqp, 0, ! CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); if (code) return code; *************** *** 1073,1080 **** if (bufp->flags & CM_BUF_WAITING) { osi_Wakeup((long) bufp); } ! bufp->flags &= ~(CM_BUF_WAITING | CM_BUF_WRITING ! | CM_BUF_DIRTY); } lock_ReleaseMutex(&bufp->mx); --- 1074,1080 ---- if (bufp->flags & CM_BUF_WAITING) { osi_Wakeup((long) bufp); } ! bufp->flags &= ~(CM_BUF_WAITING | CM_BUF_WRITING | CM_BUF_DIRTY); } lock_ReleaseMutex(&bufp->mx); Index: openafs/src/WINNT/afsd/cm_dir.h diff -c openafs/src/WINNT/afsd/cm_dir.h:1.2 openafs/src/WINNT/afsd/cm_dir.h:1.2.20.1 *** openafs/src/WINNT/afsd/cm_dir.h:1.2 Sat Nov 4 05:01:38 2000 --- openafs/src/WINNT/afsd/cm_dir.h Tue Aug 17 00:28:39 2004 *************** *** 11,17 **** #define __CM_DIR_ENV__ 1 #define CM_DIR_PAGESIZE 2048 /* bytes per page */ ! #define CM_DIR_NHASHENT 128 /* entries in the hash tbl */ #define CM_DIR_MAXPAGES 128 /* max pages in a dir */ #define CM_DIR_BIGMAXPAGES 1023 /* new big max pages */ #define CM_DIR_EPP 64 /* dir entries per page */ --- 11,17 ---- #define __CM_DIR_ENV__ 1 #define CM_DIR_PAGESIZE 2048 /* bytes per page */ ! #define CM_DIR_NHASHENT 256 /* entries in the hash tbl == NHSIZE */ #define CM_DIR_MAXPAGES 128 /* max pages in a dir */ #define CM_DIR_BIGMAXPAGES 1023 /* new big max pages */ #define CM_DIR_EPP 64 /* dir entries per page */ *************** *** 63,68 **** --- 63,69 ---- char name[16]; } cm_dirEntry_t; + #ifdef UNUSED typedef struct cm_dirXEntry { /* A directory extension entry. */ char name[32]; *************** *** 79,84 **** --- 80,86 ---- cm_pageHeader_t header; cm_dirEntry_t entry[1]; } cm_dirPage1_t; + #endif /* UNUSED */ extern int cm_NameEntries(char *namep, size_t *lenp); Index: openafs/src/WINNT/afsd/cm_dnlc.c diff -c openafs/src/WINNT/afsd/cm_dnlc.c:1.5 openafs/src/WINNT/afsd/cm_dnlc.c:1.5.2.1 *** openafs/src/WINNT/afsd/cm_dnlc.c:1.5 Thu May 6 11:17:29 2004 --- openafs/src/WINNT/afsd/cm_dnlc.c Tue Aug 17 00:28:39 2004 *************** *** 27,47 **** #include #include "afsd.h" ! osi_rwlock_t cm_dnlcLock; ! cm_dnlcstats_t dnlcstats; /* dnlc statistics */ ! int cm_useDnlc = 1; /* yes, start using the dnlc */ ! int cm_debugDnlc = 0; /* debug dnlc */ /* Hash table invariants: * 1. If nameHash[i] is NULL, list is empty * 2. A single element in a hash bucket has itself as prev and next. */ ! struct nc *ncfreelist = (struct nc *)0; static struct nc nameCache[NCSIZE]; ! struct nc* nameHash[NHSIZE]; ! #ifndef DJGPP #define dnlcNotify(x,debug){ \ --- 27,46 ---- #include #include "afsd.h" ! static osi_rwlock_t cm_dnlcLock; ! static cm_dnlcstats_t dnlcstats; /* dnlc statistics */ ! static int cm_useDnlc = 1; /* yes, start using the dnlc */ ! static int cm_debugDnlc = 0; /* debug dnlc */ /* Hash table invariants: * 1. If nameHash[i] is NULL, list is empty * 2. A single element in a hash bucket has itself as prev and next. */ ! static struct nc *ncfreelist = (struct nc *)0; static struct nc nameCache[NCSIZE]; ! static struct nc *nameHash[NHSIZE]; #ifndef DJGPP #define dnlcNotify(x,debug){ \ *************** *** 59,65 **** #define dnlcNotify(x,debug) #endif /* !DJGPP */ - static struct nc * GetMeAnEntry() { --- 58,63 ---- Index: openafs/src/WINNT/afsd/cm_dnlc.h diff -c openafs/src/WINNT/afsd/cm_dnlc.h:1.2 openafs/src/WINNT/afsd/cm_dnlc.h:1.2.20.1 *** openafs/src/WINNT/afsd/cm_dnlc.h:1.2 Sat Nov 4 05:01:38 2000 --- openafs/src/WINNT/afsd/cm_dnlc.h Tue Aug 17 00:28:39 2004 *************** *** 9,17 **** #include ! #define CM_AFSNCNAMESIZE 36 /* multiple of 4 */ ! #define NCSIZE 300 ! #define NHSIZE 256 /* must be power of 2== NHASHENT */ struct nc { --- 9,17 ---- #include ! #define CM_AFSNCNAMESIZE 40 /* multiple of 8 (for 64-bit) */ ! #define NCSIZE 512 ! #define NHSIZE 256 /* must be power of 2 == CM_DIR_NHASHENT */ struct nc { Index: openafs/src/WINNT/afsd/cm_freelance.c diff -c openafs/src/WINNT/afsd/cm_freelance.c:1.15 openafs/src/WINNT/afsd/cm_freelance.c:1.15.2.1 *** openafs/src/WINNT/afsd/cm_freelance.c:1.15 Sat Aug 7 01:44:05 2004 --- openafs/src/WINNT/afsd/cm_freelance.c Tue Aug 17 00:28:39 2004 *************** *** 272,277 **** --- 272,278 ---- } // we know the fakeDir is setup properly, so we claim that we have callback + osi_Log0(afsd_logp,"cm_InitFakeRootDir fakeDirCallback=1"); cm_fakeDirCallback=1; // when we get here, we've set up everything! done! *************** *** 512,518 **** fprintf(fp,"%s#%s:root.cell.\n",rootCellName,rootCellName); fprintf(fp,".%s%%%s:root.cell.\n",rootCellName,rootCellName); fclose(fp); ! fopen(hdir, "r"); } else { fputs("0\n", fp); fclose(fp); --- 513,519 ---- fprintf(fp,"%s#%s:root.cell.\n",rootCellName,rootCellName); fprintf(fp,".%s%%%s:root.cell.\n",rootCellName,rootCellName); fclose(fp); ! fp = fopen(hdir, "r"); } else { fputs("0\n", fp); fclose(fp); Index: openafs/src/WINNT/afsd/cm_ioctl.c diff -c openafs/src/WINNT/afsd/cm_ioctl.c:1.33 openafs/src/WINNT/afsd/cm_ioctl.c:1.33.2.1 *** openafs/src/WINNT/afsd/cm_ioctl.c:1.33 Wed Aug 4 11:52:56 2004 --- openafs/src/WINNT/afsd/cm_ioctl.c Tue Aug 17 00:28:39 2004 *************** *** 1060,1067 **** ioctlp->outDatap = cp; } ! if (tcellp) return 0; ! else return CM_ERROR_NOMORETOKENS; /* mapped to EDOM */ } extern long cm_AddCellProc(void *rockp, struct sockaddr_in *addrp, char *namep); --- 1060,1069 ---- ioctlp->outDatap = cp; } ! if (tcellp) ! return 0; ! else ! return CM_ERROR_NOMORETOKENS; /* mapped to EDOM */ } extern long cm_AddCellProc(void *rockp, struct sockaddr_in *addrp, char *namep); Index: openafs/src/WINNT/afsd/cm_scache.c diff -c openafs/src/WINNT/afsd/cm_scache.c:1.14 openafs/src/WINNT/afsd/cm_scache.c:1.14.2.1 *** openafs/src/WINNT/afsd/cm_scache.c:1.14 Sat Aug 7 01:44:05 2004 --- openafs/src/WINNT/afsd/cm_scache.c Tue Aug 17 00:28:39 2004 *************** *** 56,62 **** cm_scacheLRULastp = (cm_scache_t *) osi_QPrev(&scp->q); osi_QRemove((osi_queue_t **) &cm_scacheLRUFirstp, &scp->q); osi_QAdd((osi_queue_t **) &cm_scacheLRUFirstp, &scp->q); ! if (!cm_scacheLRULastp) cm_scacheLRULastp = scp; } /* called with cm_scacheLock write-locked; find a vnode to recycle. --- 56,63 ---- cm_scacheLRULastp = (cm_scache_t *) osi_QPrev(&scp->q); osi_QRemove((osi_queue_t **) &cm_scacheLRUFirstp, &scp->q); osi_QAdd((osi_queue_t **) &cm_scacheLRUFirstp, &scp->q); ! if (!cm_scacheLRULastp) ! cm_scacheLRULastp = scp; } /* called with cm_scacheLock write-locked; find a vnode to recycle. *************** *** 73,79 **** for (scp = cm_scacheLRULastp; scp; scp = (cm_scache_t *) osi_QPrev(&scp->q)) { ! if (scp->refCount == 0) break; } if (scp) { --- 74,81 ---- for (scp = cm_scacheLRULastp; scp; scp = (cm_scache_t *) osi_QPrev(&scp->q)) { ! if (scp->refCount == 0) ! break; } if (scp) { *************** *** 85,91 **** for (tscp = *lscpp; tscp; lscpp = &tscp->nextp, tscp = *lscpp) { ! if (tscp == scp) break; } osi_assertx(tscp, "afsd: scache hash screwup"); *lscpp = scp->nextp; --- 87,94 ---- for (tscp = *lscpp; tscp; lscpp = &tscp->nextp, tscp = *lscpp) { ! if (tscp == scp) ! break; } osi_assertx(tscp, "afsd: scache hash screwup"); *lscpp = scp->nextp; *************** *** 108,114 **** --- 111,120 ---- scp->bulkStatProgress = hzero; /* discard callback */ + if (scp->cbServerp) { + cm_PutServer(scp->cbServerp); scp->cbServerp = NULL; + } scp->cbExpires = 0; /* remove from dnlc */ *************** *** 164,170 **** /* and put it in the LRU queue */ osi_QAdd((osi_queue_t **) &cm_scacheLRUFirstp, &scp->q); ! if (!cm_scacheLRULastp) cm_scacheLRULastp = scp; cm_currentSCaches++; cm_dnlcPurgedp(scp); /* make doubly sure that this is not in dnlc */ cm_dnlcPurgevp(scp); --- 170,177 ---- /* and put it in the LRU queue */ osi_QAdd((osi_queue_t **) &cm_scacheLRUFirstp, &scp->q); ! if (!cm_scacheLRULastp) ! cm_scacheLRULastp = scp; cm_currentSCaches++; cm_dnlcPurgedp(scp); /* make doubly sure that this is not in dnlc */ cm_dnlcPurgevp(scp); *************** *** 174,183 **** /* like strcmp, only for fids */ int cm_FidCmp(cm_fid_t *ap, cm_fid_t *bp) { ! if (ap->vnode != bp->vnode) return 1; ! if (ap->volume != bp->volume) return 1; ! if (ap->unique != bp->unique) return 1; ! if (ap->cell != bp->cell) return 1; return 0; } --- 181,194 ---- /* like strcmp, only for fids */ int cm_FidCmp(cm_fid_t *ap, cm_fid_t *bp) { ! if (ap->vnode != bp->vnode) ! return 1; ! if (ap->volume != bp->volume) ! return 1; ! if (ap->unique != bp->unique) ! return 1; ! if (ap->cell != bp->cell) ! return 1; return 0; } *************** *** 240,255 **** long hash; cm_scache_t *scp; long code; ! cm_volume_t *volp; cm_cell_t *cellp; ! char* mp; int special; // yj: boolean variable to test if file is on root.afs int isRoot; hash = CM_SCACHE_HASH(fidp); osi_assert(fidp->cell != 0); // yj: check if we have the scp, if so, we don't need // to do anything else lock_ObtainWrite(&cm_scacheLock); --- 251,274 ---- long hash; cm_scache_t *scp; long code; ! cm_volume_t *volp = 0; cm_cell_t *cellp; ! char* mp = 0; int special; // yj: boolean variable to test if file is on root.afs int isRoot; + extern cm_fid_t cm_rootFid; hash = CM_SCACHE_HASH(fidp); osi_assert(fidp->cell != 0); + if (fidp->cell== cm_rootFid.cell && + fidp->volume==cm_rootFid.volume && + fidp->vnode==0x0 && fidp->unique==0x0) + { + osi_Log0(afsd_logp,"cm_getSCache called with root cell/volume and vnode=0 and unique=0"); + } + // yj: check if we have the scp, if so, we don't need // to do anything else lock_ObtainWrite(&cm_scacheLock); *************** *** 281,296 **** if (cm_freelanceEnabled && isRoot) { osi_Log0(afsd_logp,"cm_getSCache Freelance and isRoot"); /* freelance: if we are trying to get the root scp for the first ! time, we will just put in a place holder entry. */ volp = NULL; } if (cm_freelanceEnabled && special) { osi_Log0(afsd_logp,"cm_getSCache Freelance and special"); lock_ObtainMutex(&cm_Freelance_Lock); mp =(cm_localMountPoints+fidp->vnode-2)->mountPointStringp; lock_ReleaseMutex(&cm_Freelance_Lock); ! scp = cm_GetNewSCache(); scp->fid = *fidp; --- 300,319 ---- if (cm_freelanceEnabled && isRoot) { osi_Log0(afsd_logp,"cm_getSCache Freelance and isRoot"); /* freelance: if we are trying to get the root scp for the first ! * time, we will just put in a place holder entry. ! */ volp = NULL; } if (cm_freelanceEnabled && special) { osi_Log0(afsd_logp,"cm_getSCache Freelance and special"); + if (fidp->vnode > 1) { lock_ObtainMutex(&cm_Freelance_Lock); mp =(cm_localMountPoints+fidp->vnode-2)->mountPointStringp; lock_ReleaseMutex(&cm_Freelance_Lock); ! } else { ! mp = ""; ! } scp = cm_GetNewSCache(); scp->fid = *fidp; *************** *** 326,332 **** lock_ReleaseWrite(&cm_scacheLock); /*afsi_log(" getscache done");*/ return 0; - } // end of yj code #endif /* AFS_FREELANCE_CLIENT */ --- 349,354 ---- *************** *** 352,357 **** --- 374,380 ---- scp->refCount++; cm_AdjustLRU(scp); lock_ReleaseWrite(&cm_scacheLock); + if (volp) cm_PutVolume(volp); *outScpp = scp; return 0; *************** *** 384,389 **** --- 407,419 ---- cm_hashTablep[hash] = scp; scp->flags |= CM_SCACHEFLAG_INHASH; scp->refCount = 1; + + /* XXX - The following fields in the cm_scache are + * uninitialized: + * fileType + * parentVnode + * parentUnique + */ lock_ReleaseWrite(&cm_scacheLock); /* now we have a held scache entry; just return it */ *************** *** 590,601 **** // yj: modified this so that callback only checked if we're // not checking something on /afs if ( (flags & CM_SCACHESYNC_NEEDCALLBACK) #ifdef AFS_FREELANCE_CLIENT ! && (!cm_freelanceEnabled || !(!(scp->fid.vnode==0x1 && ! scp->fid.unique==0x1) && ! scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && ! scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)) #endif /* AFS_FREELANCE_CLIENT */ ) { if (!cm_HaveCallback(scp)) { --- 620,633 ---- // yj: modified this so that callback only checked if we're // not checking something on /afs + /* fix the conditional to match the one in cm_HaveCallback */ if ( (flags & CM_SCACHESYNC_NEEDCALLBACK) #ifdef AFS_FREELANCE_CLIENT ! && (!cm_freelanceEnabled || ! !(scp->fid.vnode==0x1 && scp->fid.unique==0x1) || ! scp->fid.cell!=AFS_FAKE_ROOT_CELL_ID || ! scp->fid.volume!=AFS_FAKE_ROOT_VOL_ID || ! cm_fakeDirCallback < 2) #endif /* AFS_FREELANCE_CLIENT */ ) { if (!cm_HaveCallback(scp)) { *************** *** 656,662 **** if (bufLocked) lock_ReleaseMutex(&bufp->mx); osi_SleepM((long) &scp->flags, &scp->mx); osi_Log0(afsd_logp, "CM SyncOp woke!"); ! if (bufLocked) lock_ObtainMutex(&bufp->mx); lock_ObtainMutex(&scp->mx); } /* big while loop */ --- 688,695 ---- if (bufLocked) lock_ReleaseMutex(&bufp->mx); osi_SleepM((long) &scp->flags, &scp->mx); osi_Log0(afsd_logp, "CM SyncOp woke!"); ! if (bufLocked) ! lock_ObtainMutex(&bufp->mx); lock_ObtainMutex(&scp->mx); } /* big while loop */ *************** *** 807,813 **** if (cm_freelanceEnabled && scp == cm_rootSCachep) { osi_Log0(afsd_logp,"cm_MergeStatus Freelance cm_rootSCachep"); statusp->InterfaceVersion = 0x1; ! statusp->FileType = 0x2; statusp->LinkCount = scp->linkCount; statusp->Length = cm_fakeDirSize; statusp->DataVersion = cm_fakeDirVersion; --- 840,846 ---- if (cm_freelanceEnabled && scp == cm_rootSCachep) { osi_Log0(afsd_logp,"cm_MergeStatus Freelance cm_rootSCachep"); statusp->InterfaceVersion = 0x1; ! statusp->FileType = CM_SCACHETYPE_DIRECTORY; statusp->LinkCount = scp->linkCount; statusp->Length = cm_fakeDirSize; statusp->DataVersion = cm_fakeDirVersion; *************** *** 900,907 **** else scp->fileType = CM_SCACHETYPE_SYMLINK; } ! else scp->fileType = 0; /* invalid */ ! /* and other stuff */ scp->parentVnode = statusp->ParentVnode; scp->parentUnique = statusp->ParentUnique; --- 933,942 ---- else scp->fileType = CM_SCACHETYPE_SYMLINK; } ! else { ! osi_Log1(afsd_logp, "Merge, Invalid File Type, scp %x", scp); ! scp->fileType = 0; /* invalid */ ! } /* and other stuff */ scp->parentVnode = statusp->ParentVnode; scp->parentUnique = statusp->ParentUnique; *************** *** 927,933 **** --- 962,971 ---- void cm_DiscardSCache(cm_scache_t *scp) { lock_AssertMutex(&scp->mx); + if (scp->cbServerp) { + cm_PutServer(scp->cbServerp); scp->cbServerp = NULL; + } scp->cbExpires = 0; cm_dnlcPurgedp(scp); cm_FreeAllACLEnts(scp); Index: openafs/src/WINNT/afsd/cm_scache.h diff -c openafs/src/WINNT/afsd/cm_scache.h:1.4 openafs/src/WINNT/afsd/cm_scache.h:1.4.2.1 *** openafs/src/WINNT/afsd/cm_scache.h:1.4 Sat Jul 31 20:16:37 2004 --- openafs/src/WINNT/afsd/cm_scache.h Wed Aug 18 13:11:22 2004 *************** *** 72,79 **** /* file status */ int fileType; /* file type */ ! unsigned long clientModTime; /* mtime */ ! unsigned long serverModTime; /* at server, for concurrent call * comparisons */ osi_hyper_t length; /* file length */ cm_prefetch_t prefetch; /* prefetch info structure */ --- 72,79 ---- /* file status */ int fileType; /* file type */ ! time_t clientModTime; /* mtime */ ! time_t serverModTime; /* at server, for concurrent call * comparisons */ osi_hyper_t length; /* file length */ cm_prefetch_t prefetch; /* prefetch info structure */ *************** *** 97,108 **** * the link contents here. */ cm_fid_t *mountRootFidp; /* mounted on root */ ! unsigned int mountRootGen; /* time to update mountRootFidp? */ cm_fid_t *dotdotFidp; /* parent of volume root */ /* callback info */ struct cm_server *cbServerp; /* server granting callback */ ! long cbExpires; /* time callback expires */ /* access cache */ long anyAccess; /* anonymous user's access */ --- 97,108 ---- * the link contents here. */ cm_fid_t *mountRootFidp; /* mounted on root */ ! time_t mountRootGen; /* time to update mountRootFidp? */ cm_fid_t *dotdotFidp; /* parent of volume root */ /* callback info */ struct cm_server *cbServerp; /* server granting callback */ ! time_t cbExpires; /* time callback expires */ /* access cache */ long anyAccess; /* anonymous user's access */ Index: openafs/src/WINNT/afsd/cm_server.c diff -c openafs/src/WINNT/afsd/cm_server.c:1.13 openafs/src/WINNT/afsd/cm_server.c:1.13.2.2 *** openafs/src/WINNT/afsd/cm_server.c:1.13 Sat Aug 7 10:12:11 2004 --- openafs/src/WINNT/afsd/cm_server.c Tue Aug 17 11:26:04 2004 *************** *** 53,59 **** lock_ObtainWrite(&cm_serverLock); for(tsp = cm_allServersp; tsp; tsp = tsp->allNextp) { ! tsp->refCount++; lock_ReleaseWrite(&cm_serverLock); /* now process the server */ --- 53,59 ---- lock_ObtainWrite(&cm_serverLock); for(tsp = cm_allServersp; tsp; tsp = tsp->allNextp) { ! cm_GetServerNoLock(tsp); lock_ReleaseWrite(&cm_serverLock); /* now process the server */ *************** *** 120,126 **** cm_GCConnections(tsp); lock_ObtainWrite(&cm_serverLock); ! osi_assert(tsp->refCount-- > 0); } lock_ReleaseWrite(&cm_serverLock); } --- 120,126 ---- cm_GCConnections(tsp); lock_ObtainWrite(&cm_serverLock); ! cm_PutServerNoLock(tsp); } lock_ReleaseWrite(&cm_serverLock); } *************** *** 135,140 **** --- 135,152 ---- } } + void cm_GetServer(cm_server_t *serverp) + { + lock_ObtainWrite(&cm_serverLock); + serverp->refCount++; + lock_ReleaseWrite(&cm_serverLock); + } + + void cm_GetServerNoLock(cm_server_t *serverp) + { + serverp->refCount++; + } + void cm_PutServer(cm_server_t *serverp) { lock_ObtainWrite(&cm_serverLock); *************** *** 195,201 **** serverp->ipRank += min(serverp->ipRank, rand() % 0x000f); } /* and of for loop */ } ! else serverp->ipRank = 10000 + (rand() % 0x00ff); /* VL server */ } cm_server_t *cm_NewServer(struct sockaddr_in *socketp, int type, cm_cell_t *cellp) { --- 207,214 ---- serverp->ipRank += min(serverp->ipRank, rand() % 0x000f); } /* and of for loop */ } ! else ! serverp->ipRank = 10000 + (rand() % 0x00ff); /* VL server */ } cm_server_t *cm_NewServer(struct sockaddr_in *socketp, int type, cm_cell_t *cellp) { *************** *** 235,241 **** } /* bump ref count if we found the server */ ! if (tsp) tsp->refCount++; /* drop big table lock */ lock_ReleaseWrite(&cm_serverLock); --- 248,255 ---- } /* bump ref count if we found the server */ ! if (tsp) ! cm_GetServerNoLock(tsp); /* drop big table lock */ lock_ReleaseWrite(&cm_serverLock); *************** *** 248,256 **** { cm_serverRef_t *tsrp; ! lock_ObtainWrite(&cm_serverLock); ! serverp->refCount++; ! lock_ReleaseWrite(&cm_serverLock); tsrp = malloc(sizeof(*tsrp)); tsrp->server = serverp; tsrp->status = not_busy; --- 262,268 ---- { cm_serverRef_t *tsrp; ! cm_GetServer(serverp); tsrp = malloc(sizeof(*tsrp)); tsrp->server = serverp; tsrp->status = not_busy; *************** *** 404,428 **** } /* call cm_FreeServer while holding a write lock on cm_serverLock */ ! void cm_FreeServer(cm_server_t* server) { ! if (--(server->refCount) == 0) { /* we need to check to ensure that all of the connections * for this server have a 0 refCount; otherwise, they will * not be garbage collected */ ! cm_GCConnections(server); /* connsp */ ! lock_FinalizeMutex(&server->mx); ! if ( cm_allServersp == server ) ! cm_allServersp = server->allNextp; else { cm_server_t *tsp; for(tsp = cm_allServersp; tsp->allNextp; tsp=tsp->allNextp) { ! if ( tsp->allNextp == server ) { ! tsp->allNextp = server->allNextp; break; } } --- 416,441 ---- } /* call cm_FreeServer while holding a write lock on cm_serverLock */ ! void cm_FreeServer(cm_server_t* serverp) { ! cm_PutServerNoLock(serverp); ! if (serverp->refCount == 0) { /* we need to check to ensure that all of the connections * for this server have a 0 refCount; otherwise, they will * not be garbage collected */ ! cm_GCConnections(serverp); /* connsp */ ! lock_FinalizeMutex(&serverp->mx); ! if ( cm_allServersp == serverp ) ! cm_allServersp = serverp->allNextp; else { cm_server_t *tsp; for(tsp = cm_allServersp; tsp->allNextp; tsp=tsp->allNextp) { ! if ( tsp->allNextp == serverp ) { ! tsp->allNextp = serverp->allNextp; break; } } Index: openafs/src/WINNT/afsd/cm_server.h diff -c openafs/src/WINNT/afsd/cm_server.h:1.5 openafs/src/WINNT/afsd/cm_server.h:1.5.2.1 *** openafs/src/WINNT/afsd/cm_server.h:1.5 Fri Jul 30 16:02:58 2004 --- openafs/src/WINNT/afsd/cm_server.h Tue Aug 17 00:28:39 2004 *************** *** 74,79 **** --- 74,83 ---- extern long cm_ChecksumServerList(cm_serverRef_t *serversp); + extern void cm_GetServer(cm_server_t *); + + extern void cm_GetServerNoLock(cm_server_t *); + extern void cm_PutServer(cm_server_t *); extern void cm_PutServerNoLock(cm_server_t *); Index: openafs/src/WINNT/afsd/cm_vnodeops.c diff -c openafs/src/WINNT/afsd/cm_vnodeops.c:1.19 openafs/src/WINNT/afsd/cm_vnodeops.c:1.19.2.1 *** openafs/src/WINNT/afsd/cm_vnodeops.c:1.19 Fri Jul 30 16:02:58 2004 --- openafs/src/WINNT/afsd/cm_vnodeops.c Tue Aug 17 00:28:39 2004 *************** *** 1380,1386 **** psp = tempsp; tp = psp->data; cm_ReleaseSCache(tscp); ! tscp = linkScp; /* already held * by AssembleLink */ /* now, if linkScp is null, that's * AssembleLink's way of telling us that --- 1380,1387 ---- psp = tempsp; tp = psp->data; cm_ReleaseSCache(tscp); ! tscp = linkScp; ! /* already held * by AssembleLink */ /* now, if linkScp is null, that's * AssembleLink's way of telling us that *************** *** 1679,1685 **** } /* all files in the response */ /* now tell it to drop the count, * after doing the vnode processing above */ ! cm_EndCallbackGrantingCall(NULL, NULL, NULL, 0); filex += filesThisCall; } /* while there are still more files to process */ --- 1680,1686 ---- } /* all files in the response */ /* now tell it to drop the count, * after doing the vnode processing above */ ! cm_EndCallbackGrantingCall(NULL, &cbReq, NULL, 0); filex += filesThisCall; } /* while there are still more files to process */ *************** *** 1959,1965 **** /* make sure we end things properly */ if (!didEnd) ! cm_EndCallbackGrantingCall(NULL, NULL, NULL, 0); return code; } --- 1960,1966 ---- /* make sure we end things properly */ if (!didEnd) ! cm_EndCallbackGrantingCall(NULL, &cbReq, NULL, 0); return code; } *************** *** 2075,2081 **** /* make sure we end things properly */ if (!didEnd) ! cm_EndCallbackGrantingCall(NULL, NULL, NULL, 0); /* and return error code */ return code; --- 2076,2082 ---- /* make sure we end things properly */ if (!didEnd) ! cm_EndCallbackGrantingCall(NULL, &cbReq, NULL, 0); /* and return error code */ return code; Index: openafs/src/WINNT/afsd/cm_volume.c diff -c openafs/src/WINNT/afsd/cm_volume.c:1.8 openafs/src/WINNT/afsd/cm_volume.c:1.8.2.1 *** openafs/src/WINNT/afsd/cm_volume.c:1.8 Wed Aug 4 11:52:56 2004 --- openafs/src/WINNT/afsd/cm_volume.c Tue Aug 17 00:28:39 2004 *************** *** 175,181 **** } /* hold the volume if we found it */ ! if (volp) volp->refCount++; lock_ReleaseWrite(&cm_volumeLock); /* return it held */ --- 175,182 ---- } /* hold the volume if we found it */ ! if (volp) ! volp->refCount++; lock_ReleaseWrite(&cm_volumeLock); /* return it held */ *************** *** 316,322 **** serverspp = &volp->roServersp; else if (volume == volp->bkID) serverspp = &volp->bkServersp; ! else osi_panic("bad volume ID in cm_GetVolServers", __FILE__, __LINE__); for (current = *serverspp; current; current = current->next) current->refCount++; --- 317,324 ---- serverspp = &volp->roServersp; else if (volume == volp->bkID) serverspp = &volp->bkServersp; ! else ! osi_panic("bad volume ID in cm_GetVolServers", __FILE__, __LINE__); for (current = *serverspp; current; current = current->next) current->refCount++; *************** *** 370,376 **** lock_ReleaseWrite(&cm_volumeLock); /* We should also refresh cached mount points */ - } /* --- 372,377 ---- Index: openafs/src/WINNT/afsd/fs.c diff -c openafs/src/WINNT/afsd/fs.c:1.16 openafs/src/WINNT/afsd/fs.c:1.16.2.1 *** openafs/src/WINNT/afsd/fs.c:1.16 Tue Jul 13 23:28:42 2004 --- openafs/src/WINNT/afsd/fs.c Mon Aug 23 11:55:02 2004 *************** *** 583,588 **** --- 583,590 ---- return mydata; } + #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins" + BOOL IsAdmin (void) { static BOOL fAdmin = FALSE; *************** *** 590,609 **** if (!fTested) { ! /* Obtain the SID for BUILTIN\Administrators. If this is Windows NT, ! * expect this call to succeed; if it does not, we can presume that ! * it's not NT and therefore the user always has administrative ! * privileges. */ PSID psidAdmin = NULL; ! SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY; fTested = TRUE; ! if (!AllocateAndInitializeSid (&auth, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &psidAdmin)) fAdmin = TRUE; ! else ! { /* Then open our current ProcessToken */ HANDLE hToken; --- 592,645 ---- if (!fTested) { ! /* Obtain the SID for the AFS client admin group. If the group does ! * not exist, then assume we have AFS client admin privileges. */ PSID psidAdmin = NULL; ! DWORD dwSize, dwSize2; ! char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ]; ! char *pszRefDomain = NULL; ! SID_NAME_USE snu = SidTypeGroup; ! ! dwSize = sizeof(pszAdminGroup); ! ! if (!GetComputerName(pszAdminGroup, &dwSize)) { ! /* Can't get computer name. We return false in this case. ! Retain fAdmin and fTested. This shouldn't happen.*/ ! return FALSE; ! } fTested = TRUE; ! dwSize = 0; ! dwSize2 = 0; ! ! strcat(pszAdminGroup,"\\"); ! strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME); ! ! LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu); ! /* that should always fail. */ ! ! if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { ! /* if we can't find the group, then we allow the operation */ fAdmin = TRUE; ! return TRUE; ! } ! ! if (dwSize == 0 || dwSize2 == 0) { ! /* Paranoia */ ! fAdmin = TRUE; ! return TRUE; ! } ! ! psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize); ! pszRefDomain = (char *)malloc(dwSize2); ! ! if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) { ! /* We can't lookup the group now even though we looked it up earlier. ! Could this happen? */ ! fAdmin = TRUE; ! } else { /* Then open our current ProcessToken */ HANDLE hToken; *************** *** 624,636 **** if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize)) { /* Look through the list of group SIDs and see if any of them ! * matches the Administrator group SID. */ size_t iGroup = 0; for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup) { ! if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) fAdmin = TRUE; } } --- 660,673 ---- if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize)) { /* Look through the list of group SIDs and see if any of them ! * matches the AFS Client Admin group SID. */ size_t iGroup = 0; for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup) { ! if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) { fAdmin = TRUE; + } } } *************** *** 639,646 **** } } ! if (psidAdmin) ! FreeSid (psidAdmin); } return fAdmin; --- 676,683 ---- } } ! free(psidAdmin); ! free(pszRefDomain); } return fAdmin; *************** *** 1657,1663 **** if ( checkserv.tinterval != 0 ) { #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires Administrator access.\n"); return EACCES; } #else /* WIN32 */ --- 1694,1700 ---- if ( checkserv.tinterval != 0 ) { #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } #else /* WIN32 */ *************** *** 1769,1775 **** #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires Administrator access.\n"); return EACCES; } #else /* WIN32 */ --- 1806,1812 ---- #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } #else /* WIN32 */ *************** *** 1883,1889 **** #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires Administrator access.\n"); return EACCES; } #else /* WIN32 */ --- 1920,1926 ---- #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } #else /* WIN32 */ *************** *** 2104,2110 **** if (ti) { #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires Administrator access.\n"); return EACCES; } #else /* WIN32 */ --- 2141,2147 ---- if (ti) { #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } #else /* WIN32 */ *************** *** 2171,2177 **** #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires Administrator access.\n"); return EACCES; } #else /* WIN32 */ --- 2208,2214 ---- #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } #else /* WIN32 */ *************** *** 2311,2317 **** #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires Administrator access.\n"); return EACCES; } #else /* WIN32 */ --- 2348,2354 ---- #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } #else /* WIN32 */ *************** *** 2567,2573 **** #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires Administrator access.\n"); return EACCES; } #else /* WIN32 */ --- 2604,2610 ---- #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } #else /* WIN32 */ *************** *** 2724,2730 **** #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires Administrator access.\n"); return EACCES; } #else /* WIN32 */ --- 2761,2767 ---- #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } #else /* WIN32 */ *************** *** 2780,2786 **** #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires Administrator access.\n"); return EACCES; } #else /* WIN32 */ --- 2817,2823 ---- #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } #else /* WIN32 */ *************** *** 2845,2851 **** #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires Administrator access.\n"); return EACCES; } #else /* WIN32 */ --- 2882,2888 ---- #ifdef WIN32 if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); return EACCES; } #else /* WIN32 */ *************** *** 3239,3258 **** static CSCPolicyCmd(struct cmd_syndesc *asp) { ! struct cmd_item *ti; ! char *share = NULL; HKEY hkCSCPolicy; ! for(ti=asp->parms[0].items; ti;ti=ti->next) { ! share = ti->data; ! if (share) ! { ! break; ! } ! } ! if (share) ! { char *policy; RegCreateKeyEx( HKEY_LOCAL_MACHINE, --- 3276,3295 ---- static CSCPolicyCmd(struct cmd_syndesc *asp) { ! struct cmd_item *ti; ! char *share = NULL; HKEY hkCSCPolicy; ! for(ti=asp->parms[0].items; ti;ti=ti->next) { ! share = ti->data; ! if (share) ! { ! break; ! } ! } ! if (share) ! { char *policy; RegCreateKeyEx( HKEY_LOCAL_MACHINE, *************** *** 3265,3304 **** &hkCSCPolicy, NULL ); ! if ( !IsAdmin() || hkCSCPolicy == NULL ) { fprintf (stderr,"Permission denied: requires Administrator access.\n"); ! if ( hkCSCPolicy ) ! RegCloseKey(hkCSCPolicy); return EACCES; } policy = "manual"; ! if (asp->parms[1].items) ! policy = "manual"; ! if (asp->parms[2].items) ! policy = "programs"; ! if (asp->parms[3].items) ! policy = "documents"; ! if (asp->parms[4].items) ! policy = "disable"; RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, strlen(policy)+1); ! printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy); ! printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n"); ! } ! else ! { DWORD dwIndex, dwPolicies; ! char policyName[256]; ! DWORD policyNameLen; char policy[256]; DWORD policyLen; DWORD dwType; ! /* list current csc policies */ ! RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\OpenAFS\\Client\\CSCPolicy", 0, --- 3302,3345 ---- &hkCSCPolicy, NULL ); ! if ( hkCSCPolicy == NULL ) { fprintf (stderr,"Permission denied: requires Administrator access.\n"); ! return EACCES; ! } ! ! if ( !IsAdmin() ) { ! fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n"); ! RegCloseKey(hkCSCPolicy); return EACCES; } policy = "manual"; ! if (asp->parms[1].items) ! policy = "manual"; ! if (asp->parms[2].items) ! policy = "programs"; ! if (asp->parms[3].items) ! policy = "documents"; ! if (asp->parms[4].items) ! policy = "disable"; RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, strlen(policy)+1); ! printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy); ! printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n"); ! } ! else ! { DWORD dwIndex, dwPolicies; ! char policyName[256]; ! DWORD policyNameLen; char policy[256]; DWORD policyLen; DWORD dwType; ! /* list current csc policies */ ! RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\OpenAFS\\Client\\CSCPolicy", 0, *************** *** 3323,3329 **** NULL /* lpftLastWriteTime */ ); ! printf("Current CSC policies:\n"); for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) { policyNameLen = sizeof(policyName); --- 3364,3370 ---- NULL /* lpftLastWriteTime */ ); ! printf("Current CSC policies:\n"); for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) { policyNameLen = sizeof(policyName); *************** *** 3331,3340 **** RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL, &dwType, policy, &policyLen); ! printf(" %s = %s\n", policyName, policy); ! } ! } RegCloseKey(hkCSCPolicy); ! return (0); } --- 3372,3381 ---- RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL, &dwType, policy, &policyLen); ! printf(" %s = %s\n", policyName, policy); ! } ! } RegCloseKey(hkCSCPolicy); ! return (0); } Index: openafs/src/WINNT/afsd/smb.c diff -c openafs/src/WINNT/afsd/smb.c:1.55 openafs/src/WINNT/afsd/smb.c:1.55.2.1 *** openafs/src/WINNT/afsd/smb.c:1.55 Sun Aug 8 12:55:28 2004 --- openafs/src/WINNT/afsd/smb.c Wed Aug 18 13:11:22 2004 *************** *** 43,54 **** /* TODO; logout mechanism needs to be thread-safe */ char *loggedOutName = NULL; smb_user_t *loggedOutUserp = NULL; ! unsigned long loggedOutTime; int loggedOut = 0; int smbShutdownFlag = 0; int smb_LogoffTokenTransfer; ! unsigned long smb_LogoffTransferTimeout; DWORD last_msg_time = 0; --- 43,54 ---- /* TODO; logout mechanism needs to be thread-safe */ char *loggedOutName = NULL; smb_user_t *loggedOutUserp = NULL; ! time_t loggedOutTime; int loggedOut = 0; int smbShutdownFlag = 0; int smb_LogoffTokenTransfer; ! time_t smb_LogoffTransferTimeout; DWORD last_msg_time = 0; *************** *** 432,438 **** } #ifndef DJGPP ! void ShowUnixTime(char *FuncName, afs_uint32 unixTime) { FILETIME ft; WORD wDate, wTime; --- 432,438 ---- } #ifndef DJGPP ! void ShowUnixTime(char *FuncName, time_t unixTime) { FILETIME ft; WORD wDate, wTime; *************** *** 583,594 **** } #ifndef DJGPP ! void smb_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, afs_uint32 unixTime) { struct tm *ltp; SYSTEMTIME stm; struct tm localJunk; ! long ersatz_unixTime; /* * Must use kludge-GMT instead of real GMT. --- 583,594 ---- } #ifndef DJGPP ! void smb_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, time_t unixTime) { struct tm *ltp; SYSTEMTIME stm; struct tm localJunk; ! time_t ersatz_unixTime; /* * Must use kludge-GMT instead of real GMT. *************** *** 623,629 **** SystemTimeToFileTime(&stm, largeTimep); } #else /* DJGPP */ ! void smb_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, afs_uint32 unixTime) { /* unixTime: seconds since 1/1/1970 00:00:00 GMT */ /* FILETIME: 100ns intervals since 1/1/1601 00:00:00 ??? */ --- 623,629 ---- SystemTimeToFileTime(&stm, largeTimep); } #else /* DJGPP */ ! void smb_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, time_t unixTime) { /* unixTime: seconds since 1/1/1970 00:00:00 GMT */ /* FILETIME: 100ns intervals since 1/1/1601 00:00:00 ??? */ *************** *** 645,651 **** #endif /* !DJGPP */ #ifndef DJGPP ! void smb_UnixTimeFromLargeSearchTime(afs_uint32 *unixTimep, FILETIME *largeTimep) { SYSTEMTIME stm; struct tm lt; --- 645,651 ---- #endif /* !DJGPP */ #ifndef DJGPP ! void smb_UnixTimeFromLargeSearchTime(time_t *unixTimep, FILETIME *largeTimep) { SYSTEMTIME stm; struct tm lt; *************** *** 668,674 **** _timezone = save_timezone; } #else /* DJGPP */ ! void smb_UnixTimeFromLargeSearchTime(afs_uint32 *unixTimep, FILETIME *largeTimep) { /* unixTime: seconds since 1/1/1970 00:00:00 GMT */ /* FILETIME: 100ns intervals since 1/1/1601 00:00:00 GMT? */ --- 668,674 ---- _timezone = save_timezone; } #else /* DJGPP */ ! void smb_UnixTimeFromLargeSearchTime(time_t *unixTimep, FILETIME *largeTimep) { /* unixTime: seconds since 1/1/1970 00:00:00 GMT */ /* FILETIME: 100ns intervals since 1/1/1601 00:00:00 GMT? */ *************** *** 689,720 **** } #endif /* !DJGPP */ ! void smb_SearchTimeFromUnixTime(long *dosTimep, afs_uint32 unixTime) { ! struct tm *ltp; ! int dosDate; ! int dosTime; ! struct tm localJunk; ! ! ltp = localtime((time_t*) &unixTime); ! ! /* if we fail, make up something */ ! if (!ltp) { ! ltp = &localJunk; ! localJunk.tm_year = 89 - 20; ! localJunk.tm_mon = 4; ! localJunk.tm_mday = 12; ! localJunk.tm_hour = 0; ! localJunk.tm_min = 0; ! localJunk.tm_sec = 0; ! } ! ! dosDate = ((ltp->tm_year-80)<<9) | ((ltp->tm_mon+1) << 5) | (ltp->tm_mday); ! dosTime = (ltp->tm_hour<<11) | (ltp->tm_min << 5) | (ltp->tm_sec / 2); ! *dosTimep = (dosDate<<16) | dosTime; } ! void smb_UnixTimeFromSearchTime(afs_uint32 *unixTimep, long searchTime) { unsigned short dosDate; unsigned short dosTime; --- 689,721 ---- } #endif /* !DJGPP */ ! void smb_SearchTimeFromUnixTime(long *dosTimep, time_t unixTime) { ! struct tm *ltp; ! int dosDate; ! int dosTime; ! struct tm localJunk; ! time_t t = unixTime; ! ! ltp = localtime((time_t*) &t); ! ! /* if we fail, make up something */ ! if (!ltp) { ! ltp = &localJunk; ! localJunk.tm_year = 89 - 20; ! localJunk.tm_mon = 4; ! localJunk.tm_mday = 12; ! localJunk.tm_hour = 0; ! localJunk.tm_min = 0; ! localJunk.tm_sec = 0; ! } ! ! dosDate = ((ltp->tm_year-80)<<9) | ((ltp->tm_mon+1) << 5) | (ltp->tm_mday); ! dosTime = (ltp->tm_hour<<11) | (ltp->tm_min << 5) | (ltp->tm_sec / 2); ! *dosTimep = (dosDate<<16) | dosTime; } ! void smb_UnixTimeFromSearchTime(time_t *unixTimep, time_t searchTime) { unsigned short dosDate; unsigned short dosTime; *************** *** 734,745 **** *unixTimep = mktime(&localTm); } ! void smb_DosUTimeFromUnixTime(afs_uint32 *dosUTimep, afs_uint32 unixTime) { *dosUTimep = unixTime - smb_localZero; } ! void smb_UnixTimeFromDosUTime(afs_uint32 *unixTimep, afs_uint32 dosTime) { #ifndef DJGPP *unixTimep = dosTime + smb_localZero; --- 735,746 ---- *unixTimep = mktime(&localTm); } ! void smb_DosUTimeFromUnixTime(time_t *dosUTimep, time_t unixTime) { *dosUTimep = unixTime - smb_localZero; } ! void smb_UnixTimeFromDosUTime(time_t *unixTimep, time_t dosTime) { #ifndef DJGPP *unixTimep = dosTime + smb_localZero; *************** *** 2592,2598 **** char protocol_array[10][1024]; /* protocol signature of the client */ int caps; /* capabilities */ time_t unixTime; ! long dosTime; TIME_ZONE_INFORMATION tzi; osi_Log1(smb_logp, "SMB receive negotiate; %d + 1 ongoing ops", --- 2593,2599 ---- char protocol_array[10][1024]; /* protocol signature of the client */ int caps; /* capabilities */ time_t unixTime; ! time_t dosTime; TIME_ZONE_INFORMATION tzi; osi_Log1(smb_logp, "SMB receive negotiate; %d + 1 ongoing ops", *************** *** 3169,3175 **** long code = 0; cm_scache_t *scp; char *dptr; ! long dosTime; u_short shortTemp; char attr; smb_dirListPatch_t *patchp; --- 3170,3176 ---- long code = 0; cm_scache_t *scp; char *dptr; ! time_t dosTime; u_short shortTemp; char attr; smb_dirListPatch_t *patchp; *************** *** 3801,3807 **** unsigned short attribute; cm_attr_t attr; cm_scache_t *newScp; ! long dosTime; cm_user_t *userp; int caseFold; char *tidPathp; --- 3802,3808 ---- unsigned short attribute; cm_attr_t attr; cm_scache_t *newScp; ! time_t dosTime; cm_user_t *userp; int caseFold; char *tidPathp; *************** *** 3900,3906 **** long code = 0; cm_scache_t *rootScp; cm_scache_t *newScp, *dscp; ! long dosTime; int attrs; cm_user_t *userp; int caseFold; --- 3901,3907 ---- long code = 0; cm_scache_t *rootScp; cm_scache_t *newScp, *dscp; ! time_t dosTime; int attrs; cm_user_t *userp; int caseFold; *************** *** 4062,4068 **** long code = 0; cm_user_t *userp; cm_scache_t *scp; ! long dosTime; int caseFold; cm_space_t *spacep; char *tidPathp; --- 4063,4069 ---- long code = 0; cm_user_t *userp; cm_scache_t *scp; ! time_t dosTime; int caseFold; cm_space_t *spacep; char *tidPathp; Index: openafs/src/WINNT/afsd/smb.h diff -c openafs/src/WINNT/afsd/smb.h:1.14 openafs/src/WINNT/afsd/smb.h:1.14.2.2 *** openafs/src/WINNT/afsd/smb.h:1.14 Sat Aug 7 01:44:05 2004 --- openafs/src/WINNT/afsd/smb.h Wed Aug 18 13:11:22 2004 *************** *** 153,159 **** struct smb_user *usersp; /* the first child in the user session list */ struct smb_fid *fidsp; /* the first child in the open file list */ struct smb_user *justLoggedOut; /* ready for profile upload? */ ! unsigned long logoffTime; /* tick count when logged off */ /*struct cm_user *logonDLLUser; /* integrated logon user */ unsigned char errorCount; char rname[17]; --- 153,159 ---- struct smb