2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/param.h>
15 #include "TaAfsAdmSvrClientInternal.h"
19 * VARIABLES __________________________________________________________________
25 BOOL fInitializedSockets;
26 size_t cReqForAdminServer;
31 * ROUTINES ___________________________________________________________________
35 extern "C" void __RPC_FAR * __RPC_USER MIDL_user_allocate (size_t cbAllocate)
37 return (void __RPC_FAR *)Allocate (cbAllocate);
40 extern "C" void __RPC_USER MIDL_user_free (void __RPC_FAR *pData)
47 * DATA STRUCTURES ____________________________________________________________
51 BOOL ADMINAPI asc_AsidListCreate (LPASIDLIST *ppList)
53 return ((*ppList = AfsAdmSvr_CreateAsidList()) != NULL);
56 BOOL ADMINAPI asc_AsidListCopy (LPASIDLIST *ppListTarget, LPASIDLIST *ppListSource)
58 return ((*ppListTarget = AfsAdmSvr_CopyAsidList (*ppListSource)) != NULL);
61 BOOL ADMINAPI asc_AsidListAddEntry (LPASIDLIST *ppList, ASID idObject, LPARAM lp)
63 return AfsAdmSvr_AddToAsidList (ppList, idObject, lp);
66 BOOL ADMINAPI asc_AsidListRemoveEntry (LPASIDLIST *ppList, ASID idObject)
68 return AfsAdmSvr_RemoveFromAsidList (ppList, idObject);
71 BOOL ADMINAPI asc_AsidListRemoveEntryByIndex (LPASIDLIST *ppList, size_t iIndex)
73 return AfsAdmSvr_RemoveFromAsidListByIndex (ppList, iIndex);
76 BOOL ADMINAPI asc_AsidListSetEntryParam (LPASIDLIST *ppList, ASID idObject, LPARAM lp)
78 return AfsAdmSvr_SetAsidListParam (ppList, idObject, lp);
81 BOOL ADMINAPI asc_AsidListSetEntryParamByIndex (LPASIDLIST *ppList, size_t iIndex, LPARAM lp)
83 return AfsAdmSvr_SetAsidListParamByIndex (ppList, iIndex, lp);
86 BOOL ADMINAPI asc_AsidListTest (LPASIDLIST *ppList, ASID idObject, LPARAM *pParam)
88 return AfsAdmSvr_IsInAsidList (ppList, idObject, pParam);
91 BOOL ADMINAPI asc_AsidListFree (LPASIDLIST *ppList)
93 AfsAdmSvr_FreeAsidList (ppList);
98 BOOL ADMINAPI asc_ObjPropListCreate (LPASOBJPROPLIST *ppList)
100 return ((*ppList = AfsAdmSvr_CreateObjPropList()) != NULL);
103 BOOL ADMINAPI asc_ObjPropListCopy (LPASOBJPROPLIST *ppListTarget, LPASOBJPROPLIST *ppListSource)
105 return ((*ppListTarget = AfsAdmSvr_CopyObjPropList (*ppListSource)) != NULL);
108 BOOL ADMINAPI asc_ObjPropListAddEntry (LPASOBJPROPLIST *ppList, LPASOBJPROP pProperties, LPARAM lp)
110 return AfsAdmSvr_AddToObjPropList (ppList, pProperties, lp);
113 BOOL ADMINAPI asc_ObjPropListRemoveEntry (LPASOBJPROPLIST *ppList, ASID idObject)
115 return AfsAdmSvr_RemoveFromObjPropList (ppList, idObject);
118 BOOL ADMINAPI asc_ObjPropListTest (LPASOBJPROPLIST *ppList, ASID idObject, LPASOBJPROP pProperties, LPARAM *pParam)
120 return AfsAdmSvr_IsInObjPropList (ppList, idObject, pProperties, pParam);
123 BOOL ADMINAPI asc_ObjPropListFree (LPASOBJPROPLIST *ppList)
125 AfsAdmSvr_FreeObjPropList (ppList);
130 BOOL ADMINAPI asc_ActionListCreate (LPASACTIONLIST *ppList)
132 return ((*ppList = AfsAdmSvr_CreateActionList()) != NULL);
135 BOOL ADMINAPI asc_ActionListCopy (LPASACTIONLIST *ppListTarget, LPASACTIONLIST *ppListSource)
137 return ((*ppListTarget = AfsAdmSvr_CopyActionList (*ppListSource)) != NULL);
140 BOOL ADMINAPI asc_ActionListAddEntry (LPASACTIONLIST *ppList, LPASACTION pAction)
142 return AfsAdmSvr_AddToActionList (ppList, pAction);
145 BOOL ADMINAPI asc_ActionListRemoveEntry (LPASACTIONLIST *ppList, DWORD idAction)
147 return AfsAdmSvr_RemoveFromActionList (ppList, idAction);
150 BOOL ADMINAPI asc_ActionListTest (LPASACTIONLIST *ppList, DWORD idAction, LPASACTION pAction)
152 return AfsAdmSvr_IsInActionList (ppList, idAction, pAction);
155 BOOL ADMINAPI asc_ActionListFree (LPASACTIONLIST *ppList)
157 AfsAdmSvr_FreeActionList (ppList);
163 * ROUTINES ___________________________________________________________________
167 BOOL ADMINAPI asc_AdminServerOpen (LPCTSTR pszAddress, UINT_PTR *pidClient, ULONG *pStatus)
172 if (!l.fInitializedSockets)
175 WSAStartup (0x0101, &Data);
176 l.fInitializedSockets = TRUE;
179 if ((++l.cReqForAdminServer) == 1)
181 LPCTSTR pszResolvedAddress = ResolveAddress (pszAddress);
182 if (!BindToAdminServer (pszResolvedAddress, FALSE, pidClient, &status))
184 if (status != RPC_S_CALL_FAILED_DNE) // server rejected us?
186 else if (pszResolvedAddress || !ForkNewAdminServer (&status))
189 rc = BindToAdminServer (pszResolvedAddress, TRUE, pidClient, &status);
194 StartPingThread (*pidClient);
196 StartCallbackThread();
203 BOOL ADMINAPI asc_AdminServerClose (UINT_PTR idClient, ULONG *pStatus)
208 StopCallbackThread();
209 StopPingThread (idClient);
211 if (l.cReqForAdminServer && ((--l.cReqForAdminServer) == 0))
213 UnbindFromAdminServer (idClient, &status);
223 BOOL ADMINAPI asc_CredentialsCrack (UINT_PTR idClient, PVOID hCreds, LPTSTR pszCell, LPTSTR pszUser, SYSTEMTIME *pstExpiration, ULONG *pStatus)
230 STRING szCell = TEXT("");
231 STRING szUser = TEXT("");
233 if ((rc = AfsAdmSvr_CrackCredentials (idClient, (UINT_PTR)hCreds, szCell, szUser, pstExpiration, &status)) != FALSE)
235 lstrcpy (pszCell, szCell);
236 lstrcpy (pszUser, szUser);
242 status = RPC_S_CALL_FAILED_DNE;
252 UINT_PTR ADMINAPI asc_CredentialsGet (UINT_PTR idClient, LPCTSTR pszCell, ULONG *pStatus)
262 lstrcpy (szCell, pszCell);
264 rc = AfsAdmSvr_GetCredentials (idClient, szCell, &status);
270 status = RPC_S_CALL_FAILED_DNE;
280 UINT_PTR ADMINAPI asc_CredentialsSet (UINT_PTR idClient, LPCTSTR pszCell, LPCTSTR pszUser, LPCTSTR pszPassword, ULONG *pStatus)
288 lstrcpy (szCell, pszCell);
291 lstrcpy (szUser, pszUser);
294 lstrcpy (szPassword, pszPassword);
296 // TODO: Ensure we do some encryption here, or using an
297 // encrypted socket, or something... can't just be pushing
298 // the user's unencrypted password across the wire.
300 rc = AfsAdmSvr_SetCredentials (idClient, szCell, szUser, szPassword, &status);
305 status = RPC_S_CALL_FAILED_DNE;
315 BOOL ADMINAPI asc_CredentialsPush (UINT_PTR idClient, PVOID hCreds, ASID idCell, ULONG *pStatus)
322 rc = (AfsAdmSvr_PushCredentials (idClient, PtrToUlong(hCreds), idCell, &status)?TRUE:FALSE);
327 status = RPC_S_CALL_FAILED_DNE;
337 BOOL ADMINAPI asc_LocalCellGet (UINT_PTR idClient, LPTSTR pszCell, ULONG *pStatus)
345 if ((rc = AfsAdmSvr_GetLocalCell (idClient, szCell, &status)) != FALSE)
347 lstrcpy (pszCell, szCell);
353 status = RPC_S_CALL_FAILED_DNE;
363 BOOL ADMINAPI asc_ErrorCodeTranslate (UINT_PTR idClient, ULONG code, LANGID idLanguage, STRING pszErrorText, ULONG *pStatus)
371 if ((rc = AfsAdmSvr_ErrorCodeTranslate (idClient, code, idLanguage, szText, &status)) != FALSE)
373 lstrcpy (pszErrorText, szText);
379 status = RPC_S_CALL_FAILED_DNE;
389 BOOL ADMINAPI asc_CellOpen (UINT_PTR idClient, PVOID hCreds, LPCTSTR pszCell, DWORD dwScope, ASID *pidCell, ULONG *pStatus)
397 lstrcpy (szCell, pszCell);
399 if ((rc = (AfsAdmSvr_OpenCell (idClient, PtrToUlong(hCreds), szCell, dwScope, pidCell, &status)?TRUE:FALSE)) != FALSE)
401 if (!CreateCellCache (*pidCell))
403 (void)AfsAdmSvr_CloseCell (idClient, *pidCell, &status);
405 status = ERROR_NOT_ENOUGH_MEMORY;
407 else // get rudimentary properties about the cell
409 rc = RefreshCachedProperties (idClient, *pidCell, *pidCell, GET_RUDIMENTARY_DATA, &status);
416 status = RPC_S_CALL_FAILED_DNE;
426 BOOL ADMINAPI asc_CellClose (UINT_PTR idClient, ASID idCell, ULONG *pStatus)
433 rc = AfsAdmSvr_CloseCell (idClient, idCell, &status);
434 DestroyCellCache (idCell);
439 status = RPC_S_CALL_FAILED_DNE;
449 BOOL ADMINAPI asc_ObjectFind (UINT_PTR idClient, ASID idSearchScope, ASOBJTYPE ObjectType, LPCTSTR pszName, ASID *pidObject, ULONG *pStatus)
456 STRING szName = TEXT("");
458 lstrcpy (szName, pszName);
459 rc = AfsAdmSvr_FindObject (idClient, idSearchScope, ObjectType, SEARCH_ALL_OBJECTS, szName, pidObject, &status);
464 status = RPC_S_CALL_FAILED_DNE;
474 BOOL ADMINAPI asc_ObjectFindMultiple (UINT_PTR idClient, ASID idSearchScope, ASOBJTYPE ObjectType, LPCTSTR pszPattern, LPAFSADMSVR_SEARCH_PARAMS pSearchParams, LPASIDLIST *ppList, ULONG *pStatus)
483 STRING szPattern = TEXT("");
485 lstrcpy (szPattern, pszPattern);
487 AFSADMSVR_SEARCH_PARAMS SearchParams;
489 memcpy (&SearchParams, pSearchParams, sizeof(AFSADMSVR_SEARCH_PARAMS));
492 memset (&SearchParams, 0x00, sizeof(AFSADMSVR_SEARCH_PARAMS));
493 SearchParams.SearchType = SEARCH_NO_LIMITATIONS;
496 rc = AfsAdmSvr_FindObjects (idClient, idSearchScope, ObjectType, SEARCH_ALL_OBJECTS, szPattern, &SearchParams, ppList, &status);
501 status = RPC_S_CALL_FAILED_DNE;
511 BOOL ADMINAPI asc_ObjectPropertiesGet (UINT_PTR idClient, AFSADMSVR_GET_LEVEL GetLevel, ASID idCell, ASID idObject, LPASOBJPROP pProperties, ULONG *pStatus)
516 if (!RefreshCachedProperties (idClient, idCell, idObject, GetLevel, &status))
523 if ((pFound = GetCachedProperties (idCell, idObject)) == NULL)
525 status = ERROR_NOT_ENOUGH_MEMORY;
530 memcpy (pProperties, pFound, sizeof(ASOBJPROP));
540 BOOL ADMINAPI asc_ObjectPropertiesGetMultiple (UINT_PTR idClient, AFSADMSVR_GET_LEVEL GetLevel, ASID idCell, LPASIDLIST pAsidList, LPASOBJPROPLIST *ppPropertiesList, ULONG *pStatus)
545 if (!RefreshCachedProperties (idClient, idCell, pAsidList, GetLevel, &status))
551 *ppPropertiesList = NULL;
552 for (size_t iAsidList = 0; iAsidList < pAsidList->cEntries; ++iAsidList)
555 if ((pFound = GetCachedProperties (idCell, pAsidList->aEntries[ iAsidList ].idObject)) != NULL)
557 if (!*ppPropertiesList)
558 asc_ObjPropListCreate(ppPropertiesList);
559 if (*ppPropertiesList)
560 AfsAdmSvr_AddToObjPropList (ppPropertiesList, pFound, pAsidList->aEntries[ iAsidList ].lParam);
565 if (!rc && *ppPropertiesList)
566 AfsAdmSvr_FreeObjPropList (ppPropertiesList);
573 BOOL ADMINAPI asc_ObjectListen (UINT_PTR idClient, ASID idCell, ASID idObject, HWND hNotify, ULONG *pStatus)
578 *pStatus = ERROR_INVALID_PARAMETER;
582 if (!AddObjectNotification (hNotify, idCell, idObject))
585 *pStatus = ERROR_NOT_ENOUGH_MEMORY;
589 TestForNotifications (idClient, idCell, idObject);
594 BOOL ADMINAPI asc_ObjectListenClear (UINT_PTR idClient, HWND hNotify, ULONG *pStatus)
596 ClearObjectNotifications (hNotify);
601 BOOL ADMINAPI asc_ObjectListenMultiple (UINT_PTR idClient, ASID idCell, LPASIDLIST pAsidList, HWND hNotify, ULONG *pStatus)
606 *pStatus = ERROR_INVALID_PARAMETER;
610 for (size_t ii = 0; ii < pAsidList->cEntriesAllocated; ++ii)
612 if (!pAsidList->aEntries[ ii ].idObject)
615 if (!AddObjectNotification (hNotify, idCell, pAsidList->aEntries[ ii ].idObject))
618 *pStatus = ERROR_NOT_ENOUGH_MEMORY;
622 TestForNotifications (idClient, idCell, pAsidList->aEntries[ ii ].idObject);
629 BOOL ADMINAPI asc_ObjectRefresh (UINT_PTR idClient, ASID idCell, ASID idObject, ULONG *pStatus)
634 // First have the server invalidate its cache of information; regardless
635 // of the name, this is actually just an Invalidate call, not a Refresh call
639 rc = AfsAdmSvr_RefreshObject (idClient, idObject, &status);
644 status = RPC_S_CALL_FAILED_DNE;
648 // If that suceeded, see if there is anyone listening for changes
649 // in this object or any of its children. If so, this call
650 // will requery the server for the latest properties for all
651 // listened-for objects, which will make us post notifications if
652 // we get new data back.
656 TestForNotifications (idClient, idCell);
665 BOOL ADMINAPI asc_ObjectRefreshMultiple (UINT_PTR idClient, ASID idCell, LPASIDLIST pAsidList, ULONG *pStatus)
670 // First have the server invalidate its cache of information; regardless
671 // of the name, this is actually just an Invalidate call, not a Refresh call
675 rc = AfsAdmSvr_RefreshObjects (idClient, pAsidList, &status);
680 status = RPC_S_CALL_FAILED_DNE;
684 // If that suceeded, see if there is anyone listening for changes
685 // in any of these objects or their children. If so, this call
686 // will requery the server for the latest properties for all
687 // listened-for objects, which will make us post notifications if
688 // we get new data back.
692 TestForNotifications (idClient, idCell);
701 BOOL ADMINAPI asc_RandomKeyGet (UINT_PTR idClient, ASID idCell, PBYTE key, ULONG *pStatus)
708 memset (key, 0x00, sizeof(BYTE) * ENCRYPTIONKEYLENGTH);
709 rc = AfsAdmSvr_GetRandomKey (idClient, idCell, key, &status);
714 status = RPC_S_CALL_FAILED_DNE;
724 BOOL ADMINAPI asc_CellNameGet_Fast (UINT_PTR idClient, ASID idCell, LPTSTR pszCell, ULONG *pStatus)
726 return asc_ObjectNameGet_Fast (idClient, idCell, idCell, pszCell, pStatus);
730 BOOL ADMINAPI asc_ObjectNameGet_Fast (UINT_PTR idClient, ASID idCell, ASID idObject, LPTSTR pszObject, ULONG *pStatus)
735 LPASOBJPROP pProperties;
736 if ((pProperties = GetCachedProperties (idCell, idObject)) == NULL)
739 status = ERROR_NO_DATA;
741 else if (pProperties->verProperties == verPROP_NO_OBJECT)
744 status = ERROR_NO_DATA;
748 lstrcpy (pszObject, pProperties->szName);
757 BOOL ADMINAPI asc_ObjectTypeGet_Fast (UINT_PTR idClient, ASID idCell, ASID idObject, ASOBJTYPE *pObjectType, ULONG *pStatus)
762 LPASOBJPROP pProperties;
763 if ((pProperties = GetCachedProperties (idCell, idObject)) == NULL)
766 status = ERROR_NO_DATA;
768 else if (pProperties->verProperties == verPROP_NO_OBJECT)
771 status = ERROR_NO_DATA;
775 *pObjectType = pProperties->Type;
784 BOOL ADMINAPI asc_ObjectPropertiesGet_Fast (UINT_PTR idClient, ASID idCell, ASID idObject, LPASOBJPROP pProperties, ULONG *pStatus)
789 LPASOBJPROP pPropFound;
790 if ((pPropFound = GetCachedProperties (idCell, idObject)) == NULL)
793 status = ERROR_NO_DATA;
795 else if (pPropFound->verProperties == verPROP_NO_OBJECT)
798 status = ERROR_NO_DATA;
800 else if (pProperties)
802 memcpy (pProperties, pPropFound, sizeof(ASOBJPROP));
811 BOOL ADMINAPI asc_ActionGet (UINT_PTR idClient, DWORD idAction, LPASACTION pAction, ULONG *pStatus)
818 memset (pAction, 0x00, sizeof(ASACTION));
819 rc = AfsAdmSvr_GetAction (idClient, idAction, pAction, &status);
824 status = RPC_S_CALL_FAILED_DNE;
834 BOOL ADMINAPI asc_ActionGetMultiple (UINT_PTR idClient, UINT_PTR idClientSearch, ASID idCellSearch, LPASACTIONLIST *ppList, ULONG *pStatus)
842 rc = AfsAdmSvr_GetActions (idClient, idClientSearch, idCellSearch, ppList, &status);
847 status = RPC_S_CALL_FAILED_DNE;
857 BOOL ADMINAPI asc_ActionListen (UINT_PTR idClient, HWND hNotify, ULONG *pStatus)
859 if (!SetActionNotification (hNotify, TRUE))
862 *pStatus = ERROR_NOT_ENOUGH_MEMORY;
869 BOOL ADMINAPI asc_ActionListenClear (UINT_PTR idClient, HWND hNotify, ULONG *pStatus)
871 if (!SetActionNotification (hNotify, FALSE))
874 *pStatus = ERROR_NOT_ENOUGH_MEMORY;
881 // AfsAdmSvrCallback_Action
882 // ...called by the server in the context of the CallbackHost() routine;
883 // this routine is used to notify the client whenever an action is
884 // initiated or completed.
886 extern "C" void AfsAdmSvrCallback_Action (LPASACTION pAction, BOOL fFinished)
888 NotifyActionListeners (pAction, fFinished);