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
14 #include <afs/param.h>
18 #include "TaAfsAdmSvrClientInternal.h"
22 * VARIABLES __________________________________________________________________
28 BOOL fInitializedSockets
;
29 size_t cReqForAdminServer
;
34 * ROUTINES ___________________________________________________________________
38 extern "C" void __RPC_FAR
* __RPC_USER
MIDL_user_allocate (size_t cbAllocate
)
40 return (void __RPC_FAR
*)Allocate (cbAllocate
);
43 extern "C" void __RPC_USER
MIDL_user_free (void __RPC_FAR
*pData
)
50 * DATA STRUCTURES ____________________________________________________________
54 BOOL ADMINAPI
asc_AsidListCreate (LPASIDLIST
*ppList
)
56 return ((*ppList
= AfsAdmSvr_CreateAsidList()) != NULL
);
59 BOOL ADMINAPI
asc_AsidListCopy (LPASIDLIST
*ppListTarget
, LPASIDLIST
*ppListSource
)
61 return ((*ppListTarget
= AfsAdmSvr_CopyAsidList (*ppListSource
)) != NULL
);
64 BOOL ADMINAPI
asc_AsidListAddEntry (LPASIDLIST
*ppList
, ASID idObject
, LPARAM lp
)
66 return AfsAdmSvr_AddToAsidList (ppList
, idObject
, lp
);
69 BOOL ADMINAPI
asc_AsidListRemoveEntry (LPASIDLIST
*ppList
, ASID idObject
)
71 return AfsAdmSvr_RemoveFromAsidList (ppList
, idObject
);
74 BOOL ADMINAPI
asc_AsidListRemoveEntryByIndex (LPASIDLIST
*ppList
, size_t iIndex
)
76 return AfsAdmSvr_RemoveFromAsidListByIndex (ppList
, iIndex
);
79 BOOL ADMINAPI
asc_AsidListSetEntryParam (LPASIDLIST
*ppList
, ASID idObject
, LPARAM lp
)
81 return AfsAdmSvr_SetAsidListParam (ppList
, idObject
, lp
);
84 BOOL ADMINAPI
asc_AsidListSetEntryParamByIndex (LPASIDLIST
*ppList
, size_t iIndex
, LPARAM lp
)
86 return AfsAdmSvr_SetAsidListParamByIndex (ppList
, iIndex
, lp
);
89 BOOL ADMINAPI
asc_AsidListTest (LPASIDLIST
*ppList
, ASID idObject
, LPARAM
*pParam
)
91 return AfsAdmSvr_IsInAsidList (ppList
, idObject
, pParam
);
94 BOOL ADMINAPI
asc_AsidListFree (LPASIDLIST
*ppList
)
96 AfsAdmSvr_FreeAsidList (ppList
);
101 BOOL ADMINAPI
asc_ObjPropListCreate (LPASOBJPROPLIST
*ppList
)
103 return ((*ppList
= AfsAdmSvr_CreateObjPropList()) != NULL
);
106 BOOL ADMINAPI
asc_ObjPropListCopy (LPASOBJPROPLIST
*ppListTarget
, LPASOBJPROPLIST
*ppListSource
)
108 return ((*ppListTarget
= AfsAdmSvr_CopyObjPropList (*ppListSource
)) != NULL
);
111 BOOL ADMINAPI
asc_ObjPropListAddEntry (LPASOBJPROPLIST
*ppList
, LPASOBJPROP pProperties
, LPARAM lp
)
113 return AfsAdmSvr_AddToObjPropList (ppList
, pProperties
, lp
);
116 BOOL ADMINAPI
asc_ObjPropListRemoveEntry (LPASOBJPROPLIST
*ppList
, ASID idObject
)
118 return AfsAdmSvr_RemoveFromObjPropList (ppList
, idObject
);
121 BOOL ADMINAPI
asc_ObjPropListTest (LPASOBJPROPLIST
*ppList
, ASID idObject
, LPASOBJPROP pProperties
, LPARAM
*pParam
)
123 return AfsAdmSvr_IsInObjPropList (ppList
, idObject
, pProperties
, pParam
);
126 BOOL ADMINAPI
asc_ObjPropListFree (LPASOBJPROPLIST
*ppList
)
128 AfsAdmSvr_FreeObjPropList (ppList
);
133 BOOL ADMINAPI
asc_ActionListCreate (LPASACTIONLIST
*ppList
)
135 return ((*ppList
= AfsAdmSvr_CreateActionList()) != NULL
);
138 BOOL ADMINAPI
asc_ActionListCopy (LPASACTIONLIST
*ppListTarget
, LPASACTIONLIST
*ppListSource
)
140 return ((*ppListTarget
= AfsAdmSvr_CopyActionList (*ppListSource
)) != NULL
);
143 BOOL ADMINAPI
asc_ActionListAddEntry (LPASACTIONLIST
*ppList
, LPASACTION pAction
)
145 return AfsAdmSvr_AddToActionList (ppList
, pAction
);
148 BOOL ADMINAPI
asc_ActionListRemoveEntry (LPASACTIONLIST
*ppList
, DWORD idAction
)
150 return AfsAdmSvr_RemoveFromActionList (ppList
, idAction
);
153 BOOL ADMINAPI
asc_ActionListTest (LPASACTIONLIST
*ppList
, DWORD idAction
, LPASACTION pAction
)
155 return AfsAdmSvr_IsInActionList (ppList
, idAction
, pAction
);
158 BOOL ADMINAPI
asc_ActionListFree (LPASACTIONLIST
*ppList
)
160 AfsAdmSvr_FreeActionList (ppList
);
166 * ROUTINES ___________________________________________________________________
170 BOOL ADMINAPI
asc_AdminServerOpen (LPCTSTR pszAddress
, UINT_PTR
*pidClient
, ULONG
*pStatus
)
175 if (!l
.fInitializedSockets
)
178 WSAStartup (0x0101, &Data
);
179 l
.fInitializedSockets
= TRUE
;
182 if ((++l
.cReqForAdminServer
) == 1)
184 LPCTSTR pszResolvedAddress
= ResolveAddress (pszAddress
);
185 if (!BindToAdminServer (pszResolvedAddress
, FALSE
, pidClient
, &status
))
187 if (status
!= RPC_S_CALL_FAILED_DNE
) // server rejected us?
189 else if (pszResolvedAddress
|| !ForkNewAdminServer (&status
))
192 rc
= BindToAdminServer (pszResolvedAddress
, TRUE
, pidClient
, &status
);
197 StartPingThread (*pidClient
);
199 StartCallbackThread();
206 BOOL ADMINAPI
asc_AdminServerClose (UINT_PTR idClient
, ULONG
*pStatus
)
211 StopCallbackThread();
212 StopPingThread (idClient
);
214 if (l
.cReqForAdminServer
&& ((--l
.cReqForAdminServer
) == 0))
216 UnbindFromAdminServer (idClient
, &status
);
226 BOOL ADMINAPI
asc_CredentialsCrack (UINT_PTR idClient
, PVOID hCreds
, LPTSTR pszCell
, LPTSTR pszUser
, SYSTEMTIME
*pstExpiration
, ULONG
*pStatus
)
233 STRING szCell
= TEXT("");
234 STRING szUser
= TEXT("");
236 if ((rc
= AfsAdmSvr_CrackCredentials (idClient
, (UINT_PTR
)hCreds
, szCell
, szUser
, pstExpiration
, &status
)) != FALSE
)
238 lstrcpy (pszCell
, szCell
);
239 lstrcpy (pszUser
, szUser
);
245 status
= RPC_S_CALL_FAILED_DNE
;
255 UINT_PTR ADMINAPI
asc_CredentialsGet (UINT_PTR idClient
, LPCTSTR pszCell
, ULONG
*pStatus
)
265 lstrcpy (szCell
, pszCell
);
267 rc
= AfsAdmSvr_GetCredentials (idClient
, szCell
, &status
);
273 status
= RPC_S_CALL_FAILED_DNE
;
283 UINT_PTR ADMINAPI
asc_CredentialsSet (UINT_PTR idClient
, LPCTSTR pszCell
, LPCTSTR pszUser
, LPCTSTR pszPassword
, ULONG
*pStatus
)
291 lstrcpy (szCell
, pszCell
);
294 lstrcpy (szUser
, pszUser
);
297 lstrcpy (szPassword
, pszPassword
);
299 // TODO: Ensure we do some encryption here, or using an
300 // encrypted socket, or something... can't just be pushing
301 // the user's unencrypted password across the wire.
303 rc
= AfsAdmSvr_SetCredentials (idClient
, szCell
, szUser
, szPassword
, &status
);
308 status
= RPC_S_CALL_FAILED_DNE
;
318 BOOL ADMINAPI
asc_CredentialsPush (UINT_PTR idClient
, PVOID hCreds
, ASID idCell
, ULONG
*pStatus
)
325 rc
= (AfsAdmSvr_PushCredentials (idClient
, PtrToUlong(hCreds
), idCell
, &status
)?TRUE
:FALSE
);
330 status
= RPC_S_CALL_FAILED_DNE
;
340 BOOL ADMINAPI
asc_LocalCellGet (UINT_PTR idClient
, LPTSTR pszCell
, ULONG
*pStatus
)
348 if ((rc
= AfsAdmSvr_GetLocalCell (idClient
, szCell
, &status
)) != FALSE
)
350 lstrcpy (pszCell
, szCell
);
356 status
= RPC_S_CALL_FAILED_DNE
;
366 BOOL ADMINAPI
asc_ErrorCodeTranslate (UINT_PTR idClient
, ULONG code
, LANGID idLanguage
, STRING pszErrorText
, ULONG
*pStatus
)
374 if ((rc
= AfsAdmSvr_ErrorCodeTranslate (idClient
, code
, idLanguage
, szText
, &status
)) != FALSE
)
376 lstrcpy (pszErrorText
, szText
);
382 status
= RPC_S_CALL_FAILED_DNE
;
392 BOOL ADMINAPI
asc_CellOpen (UINT_PTR idClient
, PVOID hCreds
, LPCTSTR pszCell
, DWORD dwScope
, ASID
*pidCell
, ULONG
*pStatus
)
400 lstrcpy (szCell
, pszCell
);
402 if ((rc
= (AfsAdmSvr_OpenCell (idClient
, PtrToUlong(hCreds
), szCell
, dwScope
, pidCell
, &status
)?TRUE
:FALSE
)) != FALSE
)
404 if (!CreateCellCache (*pidCell
))
406 (void)AfsAdmSvr_CloseCell (idClient
, *pidCell
, &status
);
408 status
= ERROR_NOT_ENOUGH_MEMORY
;
410 else // get rudimentary properties about the cell
412 rc
= RefreshCachedProperties (idClient
, *pidCell
, *pidCell
, GET_RUDIMENTARY_DATA
, &status
);
419 status
= RPC_S_CALL_FAILED_DNE
;
429 BOOL ADMINAPI
asc_CellClose (UINT_PTR idClient
, ASID idCell
, ULONG
*pStatus
)
436 rc
= AfsAdmSvr_CloseCell (idClient
, idCell
, &status
);
437 DestroyCellCache (idCell
);
442 status
= RPC_S_CALL_FAILED_DNE
;
452 BOOL ADMINAPI
asc_ObjectFind (UINT_PTR idClient
, ASID idSearchScope
, ASOBJTYPE ObjectType
, LPCTSTR pszName
, ASID
*pidObject
, ULONG
*pStatus
)
459 STRING szName
= TEXT("");
461 lstrcpy (szName
, pszName
);
462 rc
= AfsAdmSvr_FindObject (idClient
, idSearchScope
, ObjectType
, SEARCH_ALL_OBJECTS
, szName
, pidObject
, &status
);
467 status
= RPC_S_CALL_FAILED_DNE
;
477 BOOL ADMINAPI
asc_ObjectFindMultiple (UINT_PTR idClient
, ASID idSearchScope
, ASOBJTYPE ObjectType
, LPCTSTR pszPattern
, LPAFSADMSVR_SEARCH_PARAMS pSearchParams
, LPASIDLIST
*ppList
, ULONG
*pStatus
)
486 STRING szPattern
= TEXT("");
488 lstrcpy (szPattern
, pszPattern
);
490 AFSADMSVR_SEARCH_PARAMS SearchParams
;
492 memcpy (&SearchParams
, pSearchParams
, sizeof(AFSADMSVR_SEARCH_PARAMS
));
495 memset (&SearchParams
, 0x00, sizeof(AFSADMSVR_SEARCH_PARAMS
));
496 SearchParams
.SearchType
= SEARCH_NO_LIMITATIONS
;
499 rc
= AfsAdmSvr_FindObjects (idClient
, idSearchScope
, ObjectType
, SEARCH_ALL_OBJECTS
, szPattern
, &SearchParams
, ppList
, &status
);
504 status
= RPC_S_CALL_FAILED_DNE
;
514 BOOL ADMINAPI
asc_ObjectPropertiesGet (UINT_PTR idClient
, AFSADMSVR_GET_LEVEL GetLevel
, ASID idCell
, ASID idObject
, LPASOBJPROP pProperties
, ULONG
*pStatus
)
519 if (!RefreshCachedProperties (idClient
, idCell
, idObject
, GetLevel
, &status
))
526 if ((pFound
= GetCachedProperties (idCell
, idObject
)) == NULL
)
528 status
= ERROR_NOT_ENOUGH_MEMORY
;
533 memcpy (pProperties
, pFound
, sizeof(ASOBJPROP
));
543 BOOL ADMINAPI
asc_ObjectPropertiesGetMultiple (UINT_PTR idClient
, AFSADMSVR_GET_LEVEL GetLevel
, ASID idCell
, LPASIDLIST pAsidList
, LPASOBJPROPLIST
*ppPropertiesList
, ULONG
*pStatus
)
548 if (!RefreshCachedProperties (idClient
, idCell
, pAsidList
, GetLevel
, &status
))
554 *ppPropertiesList
= NULL
;
555 for (size_t iAsidList
= 0; iAsidList
< pAsidList
->cEntries
; ++iAsidList
)
558 if ((pFound
= GetCachedProperties (idCell
, pAsidList
->aEntries
[ iAsidList
].idObject
)) != NULL
)
560 if (!*ppPropertiesList
)
561 asc_ObjPropListCreate(ppPropertiesList
);
562 if (*ppPropertiesList
)
563 AfsAdmSvr_AddToObjPropList (ppPropertiesList
, pFound
, pAsidList
->aEntries
[ iAsidList
].lParam
);
568 if (!rc
&& *ppPropertiesList
)
569 AfsAdmSvr_FreeObjPropList (ppPropertiesList
);
576 BOOL ADMINAPI
asc_ObjectListen (UINT_PTR idClient
, ASID idCell
, ASID idObject
, HWND hNotify
, ULONG
*pStatus
)
581 *pStatus
= ERROR_INVALID_PARAMETER
;
585 if (!AddObjectNotification (hNotify
, idCell
, idObject
))
588 *pStatus
= ERROR_NOT_ENOUGH_MEMORY
;
592 TestForNotifications (idClient
, idCell
, idObject
);
597 BOOL ADMINAPI
asc_ObjectListenClear (UINT_PTR idClient
, HWND hNotify
, ULONG
*pStatus
)
599 ClearObjectNotifications (hNotify
);
604 BOOL ADMINAPI
asc_ObjectListenMultiple (UINT_PTR idClient
, ASID idCell
, LPASIDLIST pAsidList
, HWND hNotify
, ULONG
*pStatus
)
609 *pStatus
= ERROR_INVALID_PARAMETER
;
613 for (size_t ii
= 0; ii
< pAsidList
->cEntriesAllocated
; ++ii
)
615 if (!pAsidList
->aEntries
[ ii
].idObject
)
618 if (!AddObjectNotification (hNotify
, idCell
, pAsidList
->aEntries
[ ii
].idObject
))
621 *pStatus
= ERROR_NOT_ENOUGH_MEMORY
;
625 TestForNotifications (idClient
, idCell
, pAsidList
->aEntries
[ ii
].idObject
);
632 BOOL ADMINAPI
asc_ObjectRefresh (UINT_PTR idClient
, ASID idCell
, ASID idObject
, ULONG
*pStatus
)
637 // First have the server invalidate its cache of information; regardless
638 // of the name, this is actually just an Invalidate call, not a Refresh call
642 rc
= AfsAdmSvr_RefreshObject (idClient
, idObject
, &status
);
647 status
= RPC_S_CALL_FAILED_DNE
;
651 // If that suceeded, see if there is anyone listening for changes
652 // in this object or any of its children. If so, this call
653 // will requery the server for the latest properties for all
654 // listened-for objects, which will make us post notifications if
655 // we get new data back.
659 TestForNotifications (idClient
, idCell
);
668 BOOL ADMINAPI
asc_ObjectRefreshMultiple (UINT_PTR idClient
, ASID idCell
, LPASIDLIST pAsidList
, ULONG
*pStatus
)
673 // First have the server invalidate its cache of information; regardless
674 // of the name, this is actually just an Invalidate call, not a Refresh call
678 rc
= AfsAdmSvr_RefreshObjects (idClient
, pAsidList
, &status
);
683 status
= RPC_S_CALL_FAILED_DNE
;
687 // If that suceeded, see if there is anyone listening for changes
688 // in any of these objects or their children. If so, this call
689 // will requery the server for the latest properties for all
690 // listened-for objects, which will make us post notifications if
691 // we get new data back.
695 TestForNotifications (idClient
, idCell
);
704 BOOL ADMINAPI
asc_RandomKeyGet (UINT_PTR idClient
, ASID idCell
, PBYTE key
, ULONG
*pStatus
)
711 memset (key
, 0x00, sizeof(BYTE
) * ENCRYPTIONKEYLENGTH
);
712 rc
= AfsAdmSvr_GetRandomKey (idClient
, idCell
, key
, &status
);
717 status
= RPC_S_CALL_FAILED_DNE
;
727 BOOL ADMINAPI
asc_CellNameGet_Fast (UINT_PTR idClient
, ASID idCell
, LPTSTR pszCell
, ULONG
*pStatus
)
729 return asc_ObjectNameGet_Fast (idClient
, idCell
, idCell
, pszCell
, pStatus
);
733 BOOL ADMINAPI
asc_ObjectNameGet_Fast (UINT_PTR idClient
, ASID idCell
, ASID idObject
, LPTSTR pszObject
, ULONG
*pStatus
)
738 LPASOBJPROP pProperties
;
739 if ((pProperties
= GetCachedProperties (idCell
, idObject
)) == NULL
)
742 status
= ERROR_NO_DATA
;
744 else if (pProperties
->verProperties
== verPROP_NO_OBJECT
)
747 status
= ERROR_NO_DATA
;
751 lstrcpy (pszObject
, pProperties
->szName
);
760 BOOL ADMINAPI
asc_ObjectTypeGet_Fast (UINT_PTR idClient
, ASID idCell
, ASID idObject
, ASOBJTYPE
*pObjectType
, ULONG
*pStatus
)
765 LPASOBJPROP pProperties
;
766 if ((pProperties
= GetCachedProperties (idCell
, idObject
)) == NULL
)
769 status
= ERROR_NO_DATA
;
771 else if (pProperties
->verProperties
== verPROP_NO_OBJECT
)
774 status
= ERROR_NO_DATA
;
778 *pObjectType
= pProperties
->Type
;
787 BOOL ADMINAPI
asc_ObjectPropertiesGet_Fast (UINT_PTR idClient
, ASID idCell
, ASID idObject
, LPASOBJPROP pProperties
, ULONG
*pStatus
)
792 LPASOBJPROP pPropFound
;
793 if ((pPropFound
= GetCachedProperties (idCell
, idObject
)) == NULL
)
796 status
= ERROR_NO_DATA
;
798 else if (pPropFound
->verProperties
== verPROP_NO_OBJECT
)
801 status
= ERROR_NO_DATA
;
803 else if (pProperties
)
805 memcpy (pProperties
, pPropFound
, sizeof(ASOBJPROP
));
814 BOOL ADMINAPI
asc_ActionGet (UINT_PTR idClient
, DWORD idAction
, LPASACTION pAction
, ULONG
*pStatus
)
821 memset (pAction
, 0x00, sizeof(ASACTION
));
822 rc
= AfsAdmSvr_GetAction (idClient
, idAction
, pAction
, &status
);
827 status
= RPC_S_CALL_FAILED_DNE
;
837 BOOL ADMINAPI
asc_ActionGetMultiple (UINT_PTR idClient
, UINT_PTR idClientSearch
, ASID idCellSearch
, LPASACTIONLIST
*ppList
, ULONG
*pStatus
)
845 rc
= AfsAdmSvr_GetActions (idClient
, idClientSearch
, idCellSearch
, ppList
, &status
);
850 status
= RPC_S_CALL_FAILED_DNE
;
860 BOOL ADMINAPI
asc_ActionListen (UINT_PTR idClient
, HWND hNotify
, ULONG
*pStatus
)
862 if (!SetActionNotification (hNotify
, TRUE
))
865 *pStatus
= ERROR_NOT_ENOUGH_MEMORY
;
872 BOOL ADMINAPI
asc_ActionListenClear (UINT_PTR idClient
, HWND hNotify
, ULONG
*pStatus
)
874 if (!SetActionNotification (hNotify
, FALSE
))
877 *pStatus
= ERROR_NOT_ENOUGH_MEMORY
;
884 // AfsAdmSvrCallback_Action
885 // ...called by the server in the context of the CallbackHost() routine;
886 // this routine is used to notify the client whenever an action is
887 // initiated or completed.
889 extern "C" void AfsAdmSvrCallback_Action (LPASACTION pAction
, BOOL fFinished
)
891 NotifyActionListeners (pAction
, fFinished
);