STABLE14-windows-misc-20050102

link to afsutil.lib for hostutil functions


(cherry picked from commit 635abf2d8fb4cfb94ecb396f125e8b65af1d7813)
This commit is contained in:
Jeffrey Altman 2005-01-31 04:05:00 +00:00 committed by Derrick Brashear
parent b6cd0c1acc
commit ae2b17e1eb
15 changed files with 2488 additions and 1425 deletions

View File

@ -622,7 +622,7 @@ int afsd_InitCM(char **reasonP)
}
afsi_log("Cache path %s", cm_CachePath);
} else {
dummyLen = ExpandEnvironmentStrings("%TEMP%\AFSCache", cm_CachePath, sizeof(cm_CachePath));
dummyLen = ExpandEnvironmentStrings("%TEMP%\\AFSCache", cm_CachePath, sizeof(cm_CachePath));
if (dummyLen > sizeof(cm_CachePath)) {
afsi_log("Cache path [%%TEMP%%\\AFSCache] longer than %d after expanding env strings",
sizeof(cm_CachePath));

View File

@ -171,10 +171,8 @@ afsd_ServiceControlHandler(DWORD ctrlCode)
long code;
switch (ctrlCode) {
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_STOP:
/* Shutdown RPC */
RpcMgmtStopServerListening(NULL);
/* Force trace if requested */
code = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
AFSConfigKeyName,
@ -199,7 +197,7 @@ afsd_ServiceControlHandler(DWORD ctrlCode)
ServiceStatus.dwWin32ExitCode = NO_ERROR;
ServiceStatus.dwCheckPoint = 1;
ServiceStatus.dwWaitHint = 10000;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
SetServiceStatus(StatusHandle, &ServiceStatus);
SetEvent(WaitToTerminate);
break;
@ -208,7 +206,7 @@ afsd_ServiceControlHandler(DWORD ctrlCode)
ServiceStatus.dwWin32ExitCode = NO_ERROR;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
SetServiceStatus(StatusHandle, &ServiceStatus);
break;
/* XXX handle system shutdown */
@ -237,9 +235,6 @@ afsd_ServiceControlHandlerEx(
switch (ctrlCode)
{
case SERVICE_CONTROL_STOP:
/* Shutdown RPC */
RpcMgmtStopServerListening(NULL);
/* Force trace if requested */
code = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
AFSConfigKeyName,
@ -275,7 +270,7 @@ afsd_ServiceControlHandlerEx(
ServiceStatus.dwWin32ExitCode = NO_ERROR;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_POWEREVENT;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_POWEREVENT;
SetServiceStatus(StatusHandle, &ServiceStatus);
dwRet = NO_ERROR;
break;
@ -1155,7 +1150,7 @@ void afsd_Main(DWORD argc, LPTSTR *argv)
ServiceStatus.dwWaitHint = 0;
/* accept Power events */
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_POWEREVENT;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_POWEREVENT;
SetServiceStatus(StatusHandle, &ServiceStatus);
#endif
{
@ -1181,6 +1176,7 @@ void afsd_Main(DWORD argc, LPTSTR *argv)
DismountGlobalDrives();
smb_Shutdown();
rx_Finalize();
RpcShutdown();
buf_Shutdown();
#ifdef REGISTER_POWER_NOTIFICATIONS

View File

@ -63,6 +63,7 @@
#include <osilog.h>
#include <rxkad_prototypes.h> /* for life_to_time */
#include <afs/ptserver.h>
#include <afs/ptuser.h>
/*
* TIMING _____________________________________________________________________

View File

@ -254,6 +254,28 @@ BOOL IsServiceRunning (void)
return (Status.dwCurrentState == SERVICE_RUNNING);
}
BOOL IsServiceStartPending (void)
{
SERVICE_STATUS Status;
SC_HANDLE hManager;
memset (&Status, 0x00, sizeof(Status));
Status.dwCurrentState = SERVICE_STOPPED;
if ((hManager = OpenSCManager (NULL, NULL, GENERIC_READ)) != NULL)
{
SC_HANDLE hService;
if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), GENERIC_READ)) != NULL)
{
QueryServiceStatus (hService, &Status);
CloseServiceHandle (hService);
}
CloseServiceHandle (hManager);
}
DebugEvent("AFS AfsLogon - Test Service Start Pending","Return Code[%x] ?Start Pending[%d]",Status.dwCurrentState,(Status.dwCurrentState == SERVICE_START_PENDING));
return (Status.dwCurrentState == SERVICE_RUNNING);
}
/* LOOKUPKEYCHAIN: macro to look up the value in the list of keys in order until it's found
v:variable to receive value (reference type)
t:type
@ -550,6 +572,10 @@ UnicodeStringToANSI(UNICODE_STRING uInputString, LPSTR lpszOutputString, int nOu
GetCPInfo(CP_ACP, &CodePageInfo);
if (CodePageInfo.MaxCharSize > 1)
// Only supporting non-Unicode strings
return FALSE;
if (uInputString.Buffer && ((LPBYTE) uInputString.Buffer)[1] == '\0')
{
// Looks like unicode, better translate it
@ -561,7 +587,6 @@ UnicodeStringToANSI(UNICODE_STRING uInputString, LPSTR lpszOutputString, int nOu
}
else
lpszOutputString[0] = '\0';
return FALSE;
} // UnicodeStringToANSI
@ -654,6 +679,9 @@ DWORD APIENTRY NPLogonNotify(
sleepInterval = opt.sleepInterval;
*lpLogonScript = opt.logonScript;
if (retryInterval < sleepInterval)
sleepInterval = retryInterval;
DebugEvent("Got logon script: %S",opt.logonScript);
afsWillAutoStart = AFSWillAutoStart();
@ -687,7 +715,7 @@ DWORD APIENTRY NPLogonNotify(
/* 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)) {
if (ISREMOTE(opt.flags)) {
DebugEvent("Is Remote");
GetAdHomePath(homePath,MAX_PATH,lpLogonId,&opt);
}
@ -698,9 +726,9 @@ DWORD APIENTRY NPLogonNotify(
DebugEvent("while(TRUE) LogonOption[%x], Service AutoStart[%d]",
opt.LogonOption,afsWillAutoStart);
if(ISADREALM(opt.flags)) {
if (ISADREALM(opt.flags)) {
code = GetFileCellName(homePath,cell,256);
if(!code) {
if (!code) {
DebugEvent("profile path [%s] is in cell [%s]",homePath,cell);
}
/* Don't bail out if GetFileCellName failed.
@ -728,29 +756,31 @@ DWORD APIENTRY NPLogonNotify(
*ctemp = tolower(*ctemp);
}
uppercased_name = FALSE;
continue;
goto sleeping;
}
/* 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;
}
else {
/*JUST check to see if its running*/
if (IsServiceRunning())
break;
code = KTC_NOCM;
if (!afsWillAutoStart)
if (afsWillAutoStart && !IsServiceStartPending()) {
code = KTC_NOCMRPC;
reason = "AFS Service start failed";
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
@ -767,14 +797,11 @@ DWORD APIENTRY NPLogonNotify(
break;
/* Wait just a little while and try again */
retryInterval = sleepInterval = DEFAULT_SLEEP_INTERVAL;
retryInterval = opt.retryInterval;
}
if (retryInterval < sleepInterval)
sleepInterval = retryInterval;
sleeping:
Sleep(sleepInterval * 1000);
retryInterval -= sleepInterval;
}
@ -809,7 +836,6 @@ DWORD APIENTRY NPLogonNotify(
*lpLogonScript = NULL;
if (!afsWillAutoStart) // its not running, so if not autostart or integrated logon then just skip
code = 0;
}
}

View File

@ -41,7 +41,7 @@ SOFTWARE.
#define REG_CLIENT_TRACE_OPTION_PARM "TraceOption"
#define REG_CLIENT_LOGON_OPTION_PARM "LogonOptions"
#define REG_CLIENT_LOGON_SCRIPT_PARMW L"LogonScript"
#define DEFAULT_RETRY_INTERVAL 30 /* seconds*/
#define DEFAULT_RETRY_INTERVAL 60 /* seconds*/
#define DEFAULT_FAIL_SILENTLY FALSE
#define DEFAULT_SLEEP_INTERVAL 5 /* seconds*/
#define DEFAULT_LOGON_OPTION 1

View File

@ -95,12 +95,25 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, long flags)
memset(cp, 0, sizeof(cm_cell_t));
}
else {
cm_cell_t **cpp;
dns_expired = 1;
/* must empty cp->vlServersp */
lock_ObtainWrite(&cp->mx);
cm_FreeServerList(&cp->vlServersp);
cp->vlServersp = NULL;
lock_ReleaseWrite(&cp->mx);
if (cp->vlServersp) {
/* must empty cp->vlServersp */
lock_ObtainMutex(&cp->mx);
cm_FreeServerList(&cp->vlServersp);
cp->vlServersp = NULL;
lock_ReleaseMutex(&cp->mx);
}
/* remove the entry from the allCells list
* we will re-insert it later
*/
for (cpp = &cm_data.allCellsp; *cpp; cpp=&(*cpp)->nextp) {
if (*cpp == cp) {
(*cpp) = cp->nextp;
break;
}
}
}
code = cm_SearchCellFile(namep, fullname, cm_AddCellProc, cp);

View File

@ -1182,7 +1182,7 @@ long cm_GetBuffer(cm_scache_t *scp, cm_buf_t *bufp, int *cpffp, cm_user_t *up,
afsStatus.FileType = 0x2;
afsStatus.LinkCount = scp->linkCount;
afsStatus.Length = cm_fakeDirSize;
afsStatus.DataVersion = cm_fakeDirVersion;
afsStatus.DataVersion = scp->dataVersion;
afsStatus.Author = 0x1;
afsStatus.Owner = 0x0;
afsStatus.CallerAccess = 0x9;

View File

@ -40,15 +40,17 @@
extern void afsi_log(char *pattern, ...);
typedef struct tokenEvent {
afs_uuid_t uuid;
char sessionKey[8];
struct tokenEvent *next;
afs_uuid_t uuid;
char sessionKey[8];
struct tokenEvent *next;
} tokenEvent_t;
tokenEvent_t *tokenEvents = NULL;
osi_mutex_t tokenEventLock;
EVENT_HANDLE rpc_ShutdownEvent = NULL;
/*
* Add a new uuid and session key to the list.
*/
@ -56,13 +58,13 @@ void cm_RegisterNewTokenEvent(
afs_uuid_t uuid,
char sessionKey[8])
{
tokenEvent_t *te = malloc(sizeof(tokenEvent_t));
te->uuid = uuid;
memcpy(te->sessionKey, sessionKey, sizeof(te->sessionKey));
lock_ObtainMutex(&tokenEventLock);
te->next = tokenEvents;
tokenEvents = te;
lock_ReleaseMutex(&tokenEventLock);
tokenEvent_t *te = malloc(sizeof(tokenEvent_t));
te->uuid = uuid;
memcpy(te->sessionKey, sessionKey, sizeof(te->sessionKey));
lock_ObtainMutex(&tokenEventLock);
te->next = tokenEvents;
tokenEvents = te;
lock_ReleaseMutex(&tokenEventLock);
}
/*
@ -73,27 +75,27 @@ void cm_RegisterNewTokenEvent(
*/
BOOL cm_FindTokenEvent(afs_uuid_t uuid, char sessionKey[8])
{
RPC_STATUS status;
tokenEvent_t *te;
tokenEvent_t **ltep;
RPC_STATUS status;
tokenEvent_t *te;
tokenEvent_t **ltep;
lock_ObtainMutex(&tokenEventLock);
te = tokenEvents;
ltep = &tokenEvents;
while (te) {
if (UuidEqual((UUID *)&uuid, (UUID *)&te->uuid, &status)) {
*ltep = te->next;
lock_ReleaseMutex(&tokenEventLock);
memcpy(sessionKey, te->sessionKey,
sizeof(te->sessionKey));
free(te);
return TRUE;
}
ltep = &te->next;
te = te->next;
}
lock_ReleaseMutex(&tokenEventLock);
return FALSE;
lock_ObtainMutex(&tokenEventLock);
te = tokenEvents;
ltep = &tokenEvents;
while (te) {
if (UuidEqual((UUID *)&uuid, (UUID *)&te->uuid, &status)) {
*ltep = te->next;
lock_ReleaseMutex(&tokenEventLock);
memcpy(sessionKey, te->sessionKey,
sizeof(te->sessionKey));
free(te);
return TRUE;
}
ltep = &te->next;
te = te->next;
}
lock_ReleaseMutex(&tokenEventLock);
return FALSE;
}
/*
@ -104,117 +106,137 @@ long AFSRPC_SetToken(
afs_uuid_t uuid,
unsigned char __RPC_FAR sessionKey[8])
{
cm_RegisterNewTokenEvent(uuid, sessionKey);
return 0;
cm_RegisterNewTokenEvent(uuid, sessionKey);
return 0;
}
long AFSRPC_GetToken(
afs_uuid_t uuid,
unsigned char __RPC_FAR sessionKey[8])
{
BOOL found;
BOOL found;
found = cm_FindTokenEvent(uuid, sessionKey);
if (!found)
return 1;
found = cm_FindTokenEvent(uuid, sessionKey);
if (!found)
return 1;
return 0;
return 0;
}
void __RPC_FAR * __RPC_USER midl_user_allocate (size_t cBytes)
{
return ((void __RPC_FAR *) malloc(cBytes));
return ((void __RPC_FAR *) malloc(cBytes));
}
void __RPC_USER midl_user_free(void __RPC_FAR * p)
{
free(p);
free(p);
}
void RpcListen()
{
RPC_STATUS status;
char *task;
RPC_BINDING_VECTOR *ptrBindingVector = NULL;
BOOLEAN ifaceRegistered = FALSE;
BOOLEAN epRegistered = FALSE;
RPC_STATUS status;
char *task;
RPC_BINDING_VECTOR *ptrBindingVector = NULL;
BOOLEAN ifaceRegistered = FALSE;
BOOLEAN epRegistered = FALSE;
#ifdef NOOSIDEBUGSERVER /* Use All Protseqs already done in OSI */
status = RpcServerUseAllProtseqs(1, NULL);
if (status != RPC_S_OK) {
task = "Use All Protocol Sequences";
goto cleanup;
}
status = RpcServerUseAllProtseqs(1, NULL);
if (status != RPC_S_OK) {
task = "Use All Protocol Sequences";
goto cleanup;
}
#endif /* NOOSIDEBUGSERVER */
status = RpcServerRegisterIf(afsrpc_v1_0_s_ifspec, NULL, NULL);
if (status != RPC_S_OK) {
task = "Register Interface";
goto cleanup;
}
ifaceRegistered = TRUE;
status = RpcServerRegisterIf(afsrpc_v1_0_s_ifspec, NULL, NULL);
if (status != RPC_S_OK) {
task = "Register Interface";
goto cleanup;
}
ifaceRegistered = TRUE;
status = RpcServerInqBindings(&ptrBindingVector);
if (status != RPC_S_OK) {
task = "Inquire Bindings";
goto cleanup;
}
status = RpcServerInqBindings(&ptrBindingVector);
if (status != RPC_S_OK) {
task = "Inquire Bindings";
goto cleanup;
}
status = RpcServerRegisterAuthInfo(NULL, RPC_C_AUTHN_WINNT, NULL, NULL);
if (status != RPC_S_OK) {
task = "Register Authentication Info";
goto cleanup;
}
status = RpcServerRegisterAuthInfo(NULL, RPC_C_AUTHN_WINNT, NULL, NULL);
if (status != RPC_S_OK) {
task = "Register Authentication Info";
goto cleanup;
}
status = RpcEpRegister(afsrpc_v1_0_s_ifspec, ptrBindingVector,
NULL, "AFS session key interface");
if (status != RPC_S_OK) {
task = "Register Endpoints";
goto cleanup;
}
epRegistered = TRUE;
status = RpcEpRegister(afsrpc_v1_0_s_ifspec, ptrBindingVector,
NULL, "AFS session key interface");
if (status != RPC_S_OK) {
task = "Register Endpoints";
goto cleanup;
}
epRegistered = TRUE;
afsi_log("RPC server listening");
afsi_log("RPC server listening");
status = RpcServerListen(OSI_MAXRPCCALLS, OSI_MAXRPCCALLS, 0);
if (status != RPC_S_OK) {
task = "Server Listen";
}
status = RpcServerListen(OSI_MAXRPCCALLS, OSI_MAXRPCCALLS, 0);
if (status != RPC_S_OK) {
task = "Server Listen";
}
cleanup:
if (epRegistered)
(void) RpcEpUnregister(afsrpc_v1_0_s_ifspec, ptrBindingVector,
NULL);
if (epRegistered)
(void) RpcEpUnregister(afsrpc_v1_0_s_ifspec, ptrBindingVector,
NULL);
if (ptrBindingVector)
(void) RpcBindingVectorFree(&ptrBindingVector);
if (ptrBindingVector)
(void) RpcBindingVectorFree(&ptrBindingVector);
if (ifaceRegistered)
(void) RpcServerUnregisterIf(afsrpc_v1_0_s_ifspec, NULL, FALSE);
if (ifaceRegistered)
(void) RpcServerUnregisterIf(afsrpc_v1_0_s_ifspec, NULL, FALSE);
if (status != RPC_S_OK)
afsi_log("RPC problem, code %d for %s", status, task);
if (status != RPC_S_OK)
afsi_log("RPC problem, code %d for %s", status, task);
else
afsi_log("RPC shutdown");
return;
if (rpc_ShutdownEvent != NULL)
thrd_SetEvent(rpc_ShutdownEvent);
return;
}
long RpcInit()
{
LONG status = ERROR_SUCCESS;
HANDLE listenThread;
ULONG listenThreadID = 0;
LONG status = ERROR_SUCCESS;
HANDLE listenThread;
ULONG listenThreadID = 0;
char * name = "afsd_rpc_ShutdownEvent";
lock_InitializeMutex(&tokenEventLock, "token event lock");
lock_InitializeMutex(&tokenEventLock, "token event lock");
listenThread = CreateThread(NULL, 0, (PTHREAD_START_ROUTINE)RpcListen,
0, 0, &listenThreadID);
rpc_ShutdownEvent = thrd_CreateEvent(NULL, FALSE, FALSE, name);
if ( GetLastError() == ERROR_ALREADY_EXISTS )
afsi_log("Event Object Already Exists: %s", name);
if (listenThread == NULL) {
status = GetLastError();
}
CloseHandle(listenThread);
listenThread = CreateThread(NULL, 0, (PTHREAD_START_ROUTINE)RpcListen,
0, 0, &listenThreadID);
return status;
if (listenThread == NULL) {
status = GetLastError();
}
CloseHandle(listenThread);
return status;
}
void RpcShutdown(void)
{
RpcMgmtStopServerListening(NULL);
if (rpc_ShutdownEvent != NULL) {
thrd_WaitForSingleObject_Event(rpc_ShutdownEvent, INFINITE);
CloseHandle(rpc_ShutdownEvent);
}
}

View File

@ -19,6 +19,6 @@
void cm_RegisterNewTokenEvent(afs_uuid_t uuid, char sessionKey[8]);
BOOL cm_FindTokenEvent(afs_uuid_t uuid, char sessionKey[8]);
extern long RpcInit();
extern long RpcInit(void);
extern void RpcShutdown(void);
#endif /* __CM_RPC_H__ */

View File

@ -844,7 +844,7 @@ void cm_MergeStatus(cm_scache_t *scp, AFSFetchStatus *statusp, AFSVolSync *volp,
statusp->FileType = CM_SCACHETYPE_DIRECTORY;
statusp->LinkCount = scp->linkCount;
statusp->Length = cm_fakeDirSize;
statusp->DataVersion = cm_fakeDirVersion;
statusp->DataVersion = scp->dataVersion;
statusp->Author = 0x1;
statusp->Owner = 0x0;
statusp->CallerAccess = 0x9;

File diff suppressed because it is too large Load Diff

View File

@ -11,18 +11,17 @@
#define __FS_H_ENV__ 1
/* some forward references */
extern void ZapList(struct AclEntry *);
static void ZapList (struct AclEntry *alist);
extern void ZapAcl(struct Acl *);
static int PruneList (struct AclEntry **ae, int dfs);
extern int PruneList (struct AclEntry **, int);
static int CleanAcl(struct Acl *aa, char *fname);
extern void ChangeList(struct Acl *, afs_int32, char *, afs_int32);
static int SetVolCmd(struct cmd_syndesc *as, char *arock);
extern int CleanAcl(struct Acl *);
static int GetCellName(char *cellNamep, struct afsconf_cell *infop);
extern void Die(int, char *);
static SetVolCmd(struct cmd_syndesc *);
static int VLDBInit(int noAuthFlag, struct afsconf_cell *infop);
static void Die(int code, char *filename);
#endif /* FS_H_ENV */

View File

@ -121,6 +121,7 @@ long fs_GetFullPath(char *pathp, char *outPathp, long outSize)
return 0;
}
#ifdef COMMENT
struct hostent *hostutil_GetHostByName(char *namep)
{
struct hostent *thp;
@ -149,6 +150,7 @@ char *hostutil_GetNameByINet(afs_uint32 addr)
/* return static buffer */
return hostNameBuffer;
}
#endif
/* is this a digit or a digit-like thing? */
static int ismeta(ac, abase)

View File

@ -24,6 +24,7 @@
#include <krb.h>
#include <krb5.h>
#include <afs/ptserver.h>
#include <afs/ptuser.h>
#ifdef WIN32
#include <windows.h>

View File

@ -59,7 +59,8 @@ DLLLIBS =\
$(DESTDIR)\lib\afsauthent.lib \
$(DESTDIR)\lib\libafsconf.lib \
$(DESTDIR)\lib\libosi.lib \
$(DESTDIR)\lib\afs\TaLocale.lib
$(DESTDIR)\lib\afs\TaLocale.lib \
$(DESTDIR)\lib\afs\afsutil.lib
$(DLLFILE): $(DLLOBJS) $(DLLLIBS)
$(DLLCONLINK) /DEF:afs_shl_ext.def $(DLLSDKLIBS)