7 #include "TaAfsAdmSvrClientInternal.h"
11 * VARIABLES __________________________________________________________________
17 BOOL fInitializedSockets;
18 size_t cReqForAdminServer;
23 * ROUTINES ___________________________________________________________________
27 void __RPC_FAR * __RPC_USER MIDL_user_allocate (size_t cbAllocate)
29 return (void __RPC_FAR *)Allocate (cbAllocate);
32 void __RPC_USER MIDL_user_free (void __RPC_FAR *pData)
39 * DATA STRUCTURES ____________________________________________________________
43 BOOL ADMINAPI asc_AsidListCreate (LPASIDLIST *ppList)
45 return ((*ppList = AfsAdmSvr_CreateAsidList()) != NULL);
48 BOOL ADMINAPI asc_AsidListCopy (LPASIDLIST *ppListTarget, LPASIDLIST *ppListSource)
50 return ((*ppListTarget = AfsAdmSvr_CopyAsidList (*ppListSource)) != NULL);
53 BOOL ADMINAPI asc_AsidListAddEntry (LPASIDLIST *ppList, ASID idObject, LPARAM lp)
55 return AfsAdmSvr_AddToAsidList (ppList, idObject, lp);
58 BOOL ADMINAPI asc_AsidListRemoveEntry (LPASIDLIST *ppList, ASID idObject)
60 return AfsAdmSvr_RemoveFromAsidList (ppList, idObject);
63 BOOL ADMINAPI asc_AsidListRemoveEntryByIndex (LPASIDLIST *ppList, size_t iIndex)
65 return AfsAdmSvr_RemoveFromAsidListByIndex (ppList, iIndex);
68 BOOL ADMINAPI asc_AsidListSetEntryParam (LPASIDLIST *ppList, ASID idObject, LPARAM lp)
70 return AfsAdmSvr_SetAsidListParam (ppList, idObject, lp);
73 BOOL ADMINAPI asc_AsidListSetEntryParamByIndex (LPASIDLIST *ppList, size_t iIndex, LPARAM lp)
75 return AfsAdmSvr_SetAsidListParamByIndex (ppList, iIndex, lp);
78 BOOL ADMINAPI asc_AsidListTest (LPASIDLIST *ppList, ASID idObject, LPARAM *pParam)
80 return AfsAdmSvr_IsInAsidList (ppList, idObject, pParam);
83 BOOL ADMINAPI asc_AsidListFree (LPASIDLIST *ppList)
85 AfsAdmSvr_FreeAsidList (ppList);
90 BOOL ADMINAPI asc_ObjPropListCreate (LPASOBJPROPLIST *ppList)
92 return ((*ppList = AfsAdmSvr_CreateObjPropList()) != NULL);
95 BOOL ADMINAPI asc_ObjPropListCopy (LPASOBJPROPLIST *ppListTarget, LPASOBJPROPLIST *ppListSource)
97 return ((*ppListTarget = AfsAdmSvr_CopyObjPropList (*ppListSource)) != NULL);
100 BOOL ADMINAPI asc_ObjPropListAddEntry (LPASOBJPROPLIST *ppList, LPASOBJPROP pProperties, LPARAM lp)
102 return AfsAdmSvr_AddToObjPropList (ppList, pProperties, lp);
105 BOOL ADMINAPI asc_ObjPropListRemoveEntry (LPASOBJPROPLIST *ppList, ASID idObject)
107 return AfsAdmSvr_RemoveFromObjPropList (ppList, idObject);
110 BOOL ADMINAPI asc_ObjPropListTest (LPASOBJPROPLIST *ppList, ASID idObject, LPASOBJPROP pProperties, LPARAM *pParam)
112 return AfsAdmSvr_IsInObjPropList (ppList, idObject, pProperties, pParam);
115 BOOL ADMINAPI asc_ObjPropListFree (LPASOBJPROPLIST *ppList)
117 AfsAdmSvr_FreeObjPropList (ppList);
122 BOOL ADMINAPI asc_ActionListCreate (LPASACTIONLIST *ppList)
124 return ((*ppList = AfsAdmSvr_CreateActionList()) != NULL);
127 BOOL ADMINAPI asc_ActionListCopy (LPASACTIONLIST *ppListTarget, LPASACTIONLIST *ppListSource)
129 return ((*ppListTarget = AfsAdmSvr_CopyActionList (*ppListSource)) != NULL);
132 BOOL ADMINAPI asc_ActionListAddEntry (LPASACTIONLIST *ppList, LPASACTION pAction)
134 return AfsAdmSvr_AddToActionList (ppList, pAction);
137 BOOL ADMINAPI asc_ActionListRemoveEntry (LPASACTIONLIST *ppList, DWORD idAction)
139 return AfsAdmSvr_RemoveFromActionList (ppList, idAction);
142 BOOL ADMINAPI asc_ActionListTest (LPASACTIONLIST *ppList, DWORD idAction, LPASACTION pAction)
144 return AfsAdmSvr_IsInActionList (ppList, idAction, pAction);
147 BOOL ADMINAPI asc_ActionListFree (LPASACTIONLIST *ppList)
149 AfsAdmSvr_FreeActionList (ppList);
155 * ROUTINES ___________________________________________________________________
159 BOOL ADMINAPI asc_AdminServerOpen (LPCTSTR pszAddress, DWORD *pidClient, ULONG *pStatus)
164 if (!l.fInitializedSockets)
167 WSAStartup (0x0101, &Data);
168 l.fInitializedSockets = TRUE;
171 if ((++l.cReqForAdminServer) == 1)
173 LPCTSTR pszResolvedAddress = ResolveAddress (pszAddress);
174 if (!BindToAdminServer (pszResolvedAddress, FALSE, pidClient, &status))
176 if (status != RPC_S_CALL_FAILED_DNE) // server rejected us?
178 else if (pszResolvedAddress || !ForkNewAdminServer (&status))
181 rc = BindToAdminServer (pszResolvedAddress, TRUE, pidClient, &status);
186 StartPingThread (*pidClient);
188 StartCallbackThread();
195 BOOL ADMINAPI asc_AdminServerClose (DWORD idClient, ULONG *pStatus)
200 StopCallbackThread();
201 StopPingThread (idClient);
203 if (l.cReqForAdminServer && ((--l.cReqForAdminServer) == 0))
205 UnbindFromAdminServer (idClient, &status);
215 BOOL ADMINAPI asc_CredentialsCrack (DWORD idClient, PVOID hCreds, LPTSTR pszCell, LPTSTR pszUser, SYSTEMTIME *pstExpiration, ULONG *pStatus)
222 STRING szCell = TEXT("");
223 STRING szUser = TEXT("");
225 if ((rc = AfsAdmSvr_CrackCredentials (idClient, (DWORD)hCreds, szCell, szUser, pstExpiration, &status)) != FALSE)
227 lstrcpy (pszCell, szCell);
228 lstrcpy (pszUser, szUser);
234 status = RPC_S_CALL_FAILED_DNE;
244 PVOID ADMINAPI asc_CredentialsGet (DWORD idClient, LPCTSTR pszCell, ULONG *pStatus)
254 lstrcpy (szCell, pszCell);
256 rc = (PVOID)AfsAdmSvr_GetCredentials (idClient, szCell, &status);
262 status = RPC_S_CALL_FAILED_DNE;
272 PVOID ADMINAPI asc_CredentialsSet (DWORD idClient, LPCTSTR pszCell, LPCTSTR pszUser, LPCTSTR pszPassword, ULONG *pStatus)
280 lstrcpy (szCell, pszCell);
283 lstrcpy (szUser, pszUser);
286 lstrcpy (szPassword, pszPassword);
288 // TODO: Ensure we do some encryption here, or using an
289 // encrypted socket, or something... can't just be pushing
290 // the user's unencrypted password across the wire.
292 rc = (PVOID)AfsAdmSvr_SetCredentials (idClient, szCell, szUser, szPassword, &status);
297 status = RPC_S_CALL_FAILED_DNE;
307 BOOL ADMINAPI asc_CredentialsPush (DWORD idClient, PVOID hCreds, ASID idCell, ULONG *pStatus)
314 rc = AfsAdmSvr_PushCredentials (idClient, (DWORD)hCreds, idCell, &status);
319 status = RPC_S_CALL_FAILED_DNE;
329 BOOL ADMINAPI asc_LocalCellGet (DWORD idClient, LPTSTR pszCell, ULONG *pStatus)
337 if ((rc = AfsAdmSvr_GetLocalCell (idClient, szCell, &status)) != FALSE)
339 lstrcpy (pszCell, szCell);
345 status = RPC_S_CALL_FAILED_DNE;
355 BOOL ADMINAPI asc_ErrorCodeTranslate (DWORD idClient, ULONG code, LANGID idLanguage, STRING pszErrorText, ULONG *pStatus)
363 if ((rc = AfsAdmSvr_ErrorCodeTranslate (idClient, code, idLanguage, szText, &status)) != FALSE)
365 lstrcpy (pszErrorText, szText);
371 status = RPC_S_CALL_FAILED_DNE;
381 BOOL ADMINAPI asc_CellOpen (DWORD idClient, PVOID hCreds, LPCTSTR pszCell, DWORD dwScope, ASID *pidCell, ULONG *pStatus)
389 lstrcpy (szCell, pszCell);
391 if ((rc = AfsAdmSvr_OpenCell (idClient, (DWORD)hCreds, szCell, dwScope, pidCell, &status)) != FALSE)
393 if (!CreateCellCache (*pidCell))
395 (void)AfsAdmSvr_CloseCell (idClient, *pidCell, &status);
397 status = ERROR_NOT_ENOUGH_MEMORY;
399 else // get rudimentary properties about the cell
401 rc = RefreshCachedProperties (idClient, *pidCell, *pidCell, GET_RUDIMENTARY_DATA, &status);
408 status = RPC_S_CALL_FAILED_DNE;
418 BOOL ADMINAPI asc_CellClose (DWORD idClient, ASID idCell, ULONG *pStatus)
425 rc = AfsAdmSvr_CloseCell (idClient, idCell, &status);
426 DestroyCellCache (idCell);
431 status = RPC_S_CALL_FAILED_DNE;
441 BOOL ADMINAPI asc_ObjectFind (DWORD idClient, ASID idSearchScope, ASOBJTYPE ObjectType, LPCTSTR pszName, ASID *pidObject, ULONG *pStatus)
448 STRING szName = TEXT("");
450 lstrcpy (szName, pszName);
451 rc = AfsAdmSvr_FindObject (idClient, idSearchScope, ObjectType, SEARCH_ALL_OBJECTS, szName, pidObject, &status);
456 status = RPC_S_CALL_FAILED_DNE;
466 BOOL ADMINAPI asc_ObjectFindMultiple (DWORD idClient, ASID idSearchScope, ASOBJTYPE ObjectType, LPCTSTR pszPattern, LPAFSADMSVR_SEARCH_PARAMS pSearchParams, LPASIDLIST *ppList, ULONG *pStatus)
475 STRING szPattern = TEXT("");
477 lstrcpy (szPattern, pszPattern);
479 AFSADMSVR_SEARCH_PARAMS SearchParams;
481 memcpy (&SearchParams, pSearchParams, sizeof(AFSADMSVR_SEARCH_PARAMS));
484 memset (&SearchParams, 0x00, sizeof(AFSADMSVR_SEARCH_PARAMS));
485 SearchParams.SearchType = SEARCH_NO_LIMITATIONS;
488 rc = AfsAdmSvr_FindObjects (idClient, idSearchScope, ObjectType, SEARCH_ALL_OBJECTS, szPattern, &SearchParams, ppList, &status);
493 status = RPC_S_CALL_FAILED_DNE;
503 BOOL ADMINAPI asc_ObjectPropertiesGet (DWORD idClient, AFSADMSVR_GET_LEVEL GetLevel, ASID idCell, ASID idObject, LPASOBJPROP pProperties, ULONG *pStatus)
508 if (!RefreshCachedProperties (idClient, idCell, idObject, GetLevel, &status))
515 if ((pFound = GetCachedProperties (idCell, idObject)) == NULL)
517 status = ERROR_NOT_ENOUGH_MEMORY;
522 memcpy (pProperties, pFound, sizeof(ASOBJPROP));
532 BOOL ADMINAPI asc_ObjectPropertiesGetMultiple (DWORD idClient, AFSADMSVR_GET_LEVEL GetLevel, ASID idCell, LPASIDLIST pAsidList, LPASOBJPROPLIST *ppPropertiesList, ULONG *pStatus)
537 if (!RefreshCachedProperties (idClient, idCell, pAsidList, GetLevel, &status))
543 *ppPropertiesList = NULL;
544 for (size_t iAsidList = 0; iAsidList < pAsidList->cEntries; ++iAsidList)
547 if ((pFound = GetCachedProperties (idCell, pAsidList->aEntries[ iAsidList ].idObject)) != NULL)
549 if (!*ppPropertiesList)
550 asc_ObjPropListCreate(ppPropertiesList);
551 if (*ppPropertiesList)
552 AfsAdmSvr_AddToObjPropList (ppPropertiesList, pFound, pAsidList->aEntries[ iAsidList ].lParam);
557 if (!rc && *ppPropertiesList)
558 AfsAdmSvr_FreeObjPropList (ppPropertiesList);
565 BOOL ADMINAPI asc_ObjectListen (DWORD idClient, ASID idCell, ASID idObject, HWND hNotify, ULONG *pStatus)
570 *pStatus = ERROR_INVALID_PARAMETER;
574 if (!AddObjectNotification (hNotify, idCell, idObject))
577 *pStatus = ERROR_NOT_ENOUGH_MEMORY;
581 TestForNotifications (idClient, idCell, idObject);
586 BOOL ADMINAPI asc_ObjectListenClear (DWORD idClient, HWND hNotify, ULONG *pStatus)
588 ClearObjectNotifications (hNotify);
593 BOOL ADMINAPI asc_ObjectListenMultiple (DWORD idClient, ASID idCell, LPASIDLIST pAsidList, HWND hNotify, ULONG *pStatus)
598 *pStatus = ERROR_INVALID_PARAMETER;
602 for (size_t ii = 0; ii < pAsidList->cEntriesAllocated; ++ii)
604 if (!pAsidList->aEntries[ ii ].idObject)
607 if (!AddObjectNotification (hNotify, idCell, pAsidList->aEntries[ ii ].idObject))
610 *pStatus = ERROR_NOT_ENOUGH_MEMORY;
614 TestForNotifications (idClient, idCell, pAsidList->aEntries[ ii ].idObject);
621 BOOL ADMINAPI asc_ObjectRefresh (DWORD idClient, ASID idCell, ASID idObject, ULONG *pStatus)
626 // First have the server invalidate its cache of information; regardless
627 // of the name, this is actually just an Invalidate call, not a Refresh call
631 rc = AfsAdmSvr_RefreshObject (idClient, idObject, &status);
636 status = RPC_S_CALL_FAILED_DNE;
640 // If that suceeded, see if there is anyone listening for changes
641 // in this object or any of its children. If so, this call
642 // will requery the server for the latest properties for all
643 // listened-for objects, which will make us post notifications if
644 // we get new data back.
648 TestForNotifications (idClient, idCell);
657 BOOL ADMINAPI asc_ObjectRefreshMultiple (DWORD idClient, ASID idCell, LPASIDLIST pAsidList, ULONG *pStatus)
662 // First have the server invalidate its cache of information; regardless
663 // of the name, this is actually just an Invalidate call, not a Refresh call
667 rc = AfsAdmSvr_RefreshObjects (idClient, pAsidList, &status);
672 status = RPC_S_CALL_FAILED_DNE;
676 // If that suceeded, see if there is anyone listening for changes
677 // in any of these objects or their children. If so, this call
678 // will requery the server for the latest properties for all
679 // listened-for objects, which will make us post notifications if
680 // we get new data back.
684 TestForNotifications (idClient, idCell);
693 BOOL ADMINAPI asc_RandomKeyGet (DWORD idClient, ASID idCell, PBYTE key, ULONG *pStatus)
700 memset (key, 0x00, sizeof(BYTE) * ENCRYPTIONKEYLENGTH);
701 rc = AfsAdmSvr_GetRandomKey (idClient, idCell, key, &status);
706 status = RPC_S_CALL_FAILED_DNE;
716 BOOL ADMINAPI asc_CellNameGet_Fast (DWORD idClient, ASID idCell, LPTSTR pszCell, ULONG *pStatus)
718 return asc_ObjectNameGet_Fast (idClient, idCell, idCell, pszCell, pStatus);
722 BOOL ADMINAPI asc_ObjectNameGet_Fast (DWORD idClient, ASID idCell, ASID idObject, LPTSTR pszObject, ULONG *pStatus)
727 LPASOBJPROP pProperties;
728 if ((pProperties = GetCachedProperties (idCell, idObject)) == NULL)
731 status = ERROR_NO_DATA;
733 else if (pProperties->verProperties == verPROP_NO_OBJECT)
736 status = ERROR_NO_DATA;
740 lstrcpy (pszObject, pProperties->szName);
749 BOOL ADMINAPI asc_ObjectTypeGet_Fast (DWORD idClient, ASID idCell, ASID idObject, ASOBJTYPE *pObjectType, ULONG *pStatus)
754 LPASOBJPROP pProperties;
755 if ((pProperties = GetCachedProperties (idCell, idObject)) == NULL)
758 status = ERROR_NO_DATA;
760 else if (pProperties->verProperties == verPROP_NO_OBJECT)
763 status = ERROR_NO_DATA;
767 *pObjectType = pProperties->Type;
776 BOOL ADMINAPI asc_ObjectPropertiesGet_Fast (DWORD idClient, ASID idCell, ASID idObject, LPASOBJPROP pProperties, ULONG *pStatus)
781 LPASOBJPROP pPropFound;
782 if ((pPropFound = GetCachedProperties (idCell, idObject)) == NULL)
785 status = ERROR_NO_DATA;
787 else if (pPropFound->verProperties == verPROP_NO_OBJECT)
790 status = ERROR_NO_DATA;
792 else if (pProperties)
794 memcpy (pProperties, pPropFound, sizeof(ASOBJPROP));
803 BOOL ADMINAPI asc_ActionGet (DWORD idClient, DWORD idAction, LPASACTION pAction, ULONG *pStatus)
810 memset (pAction, 0x00, sizeof(ASACTION));
811 rc = AfsAdmSvr_GetAction (idClient, idAction, pAction, &status);
816 status = RPC_S_CALL_FAILED_DNE;
826 BOOL ADMINAPI asc_ActionGetMultiple (DWORD idClient, DWORD idClientSearch, ASID idCellSearch, LPASACTIONLIST *ppList, ULONG *pStatus)
834 rc = AfsAdmSvr_GetActions (idClient, idClientSearch, idCellSearch, ppList, &status);
839 status = RPC_S_CALL_FAILED_DNE;
849 BOOL ADMINAPI asc_ActionListen (DWORD idClient, HWND hNotify, ULONG *pStatus)
851 if (!SetActionNotification (hNotify, TRUE))
854 *pStatus = ERROR_NOT_ENOUGH_MEMORY;
861 BOOL ADMINAPI asc_ActionListenClear (DWORD idClient, HWND hNotify, ULONG *pStatus)
863 if (!SetActionNotification (hNotify, FALSE))
866 *pStatus = ERROR_NOT_ENOUGH_MEMORY;
873 // AfsAdmSvrCallback_Action
874 // ...called by the server in the context of the CallbackHost() routine;
875 // this routine is used to notify the client whenever an action is
876 // initiated or completed.
878 void AfsAdmSvrCallback_Action (LPASACTION pAction, BOOL fFinished)
880 NotifyActionListeners (pAction, fFinished);