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 "TaAfsAdmSvrInternal.h"
20 #define c100ns1SECOND ((LONGLONG)10000000)
24 * ROUTINES ___________________________________________________________________
28 BOOL IsValidTime (LPSYSTEMTIME pst)
30 return (pst->wYear > 1970) ? TRUE : FALSE;
34 BOOL AfsAdmSvr_Search_Compare (LPTSTR pszName, LPTSTR pszPattern)
36 // An empty pattern matches everyone
38 if (!pszPattern || !*pszPattern)
41 // Cache the expression so we only have to compile it when it changes.
42 // We also add a little convenience measure: you can prepend "!" to any
43 // regexp to negate the entire sense of the regexp--for instance, "!ri"
44 // matches every word which doesn't have "ri" in it.
46 static LPREGEXP pLastExpr = NULL;
47 static TCHAR szLastExpression[ 1024 ] = TEXT("");
48 static BOOL fLastInclusive = TRUE;
50 if (lstrcmp (pszPattern, szLastExpression))
54 lstrcpy (szLastExpression, pszPattern);
55 if ((fLastInclusive = (*pszPattern != TEXT('!'))) == FALSE)
57 pLastExpr = New2 (REGEXP,(pszPattern));
60 if (!pLastExpr) // this shouldn't happen, but be safe anyway
63 return ((pLastExpr->Matches (pszName)) == fLastInclusive);
67 BOOL AfsAdmSvr_Search_Compare (LPIDENT lpi, LPTSTR pszPattern)
69 if (lpi->GetRefCount() == 0)
72 TCHAR szName[ cchSTRING ];
73 switch (lpi->GetType())
76 lpi->GetCellName (szName);
79 lpi->GetLongServerName (szName);
82 lpi->GetServiceName (szName);
85 lpi->GetAggregateName (szName);
88 lpi->GetFilesetName (szName);
91 lpi->GetUserName (szName);
94 lpi->GetGroupName (szName);
100 return AfsAdmSvr_Search_Compare (szName, pszPattern);
104 BOOL AfsAdmSvr_SearchRefresh (ASID idSearchScope, ASOBJTYPE ObjectType, AFSADMSVR_SEARCH_REFRESH SearchRefresh, ULONG *pStatus)
109 if (SearchRefresh == SEARCH_ALL_OBJECTS)
111 if (GetAsidType (idSearchScope) == itCELL)
114 if ((lpCell = ((LPIDENT)idSearchScope)->OpenCell (&status)) == NULL)
118 lpCell->RefreshAll();
122 else // (GetAsidType (idSearchScope) != itCELL)
125 if ((lpServer = ((LPIDENT)idSearchScope)->OpenServer (&status)) == NULL)
129 // What do we need to refresh on this server?
133 lpServer->RefreshStatus();
134 lpServer->RefreshServices();
139 lpServer->RefreshStatus();
140 lpServer->RefreshAggregates();
144 lpServer->RefreshAll();
158 BOOL AfsAdmSvr_Search_AllInCell (LPASIDLIST *ppList, ASID idCell, LPTSTR pszPattern, ULONG *pStatus)
164 for (LPIDENT lpiFind = IDENT::FindFirst (&hEnum); lpiFind; lpiFind = IDENT::FindNext (&hEnum))
166 if (lpiFind->GetCell() != (LPIDENT)idCell)
168 if (!AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
170 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
172 IDENT::FindClose (&hEnum);
180 BOOL AfsAdmSvr_Search_ServersInCell (LPASIDLIST *ppList, ASID idCell, LPTSTR pszPattern, ULONG *pStatus)
186 if ((lpCell = ((LPIDENT)idCell)->OpenCell (&status)) == NULL)
191 for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum, TRUE, &status); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
193 LPIDENT lpiFind = lpServer->GetIdentifier();
194 if (AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
195 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
198 lpCell->ServerFindClose (&hEnum);
199 if (status && (status != ADMITERATORDONE))
210 BOOL AfsAdmSvr_Search_ServicesInCell (LPASIDLIST *ppList, ASID idCell, LPTSTR pszPattern, ULONG *pStatus)
216 for (LPIDENT lpiFind = IDENT::FindFirst (&hEnum); lpiFind; lpiFind = IDENT::FindNext (&hEnum))
218 if (lpiFind->GetType() != itSERVICE)
220 if (lpiFind->GetCell() != (LPIDENT)idCell)
222 if (!AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
224 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
226 IDENT::FindClose (&hEnum);
234 BOOL AfsAdmSvr_Search_PartitionsInCell (LPASIDLIST *ppList, ASID idCell, LPTSTR pszPattern, ULONG *pStatus)
240 for (LPIDENT lpiFind = IDENT::FindFirst (&hEnum); lpiFind; lpiFind = IDENT::FindNext (&hEnum))
242 if (lpiFind->GetType() != itAGGREGATE)
244 if (lpiFind->GetCell() != (LPIDENT)idCell)
246 if (!AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
248 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
250 IDENT::FindClose (&hEnum);
258 BOOL AfsAdmSvr_Search_VolumesInCell (LPASIDLIST *ppList, ASID idCell, LPTSTR pszPattern, ULONG *pStatus)
264 for (LPIDENT lpiFind = IDENT::FindFirst (&hEnum); lpiFind; lpiFind = IDENT::FindNext (&hEnum))
266 if (lpiFind->GetType() != itFILESET)
268 if (lpiFind->GetCell() != (LPIDENT)idCell)
270 if (!AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
272 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
274 IDENT::FindClose (&hEnum);
282 BOOL AfsAdmSvr_Search_UsersInCell (LPASIDLIST *ppList, ASID idCell, LPTSTR pszPattern, ULONG *pStatus)
288 if ((lpCell = ((LPIDENT)idCell)->OpenCell (&status)) == NULL)
293 for (LPUSER lpUser = lpCell->UserFindFirst (&hEnum, TRUE, &status); lpUser; lpUser = lpCell->UserFindNext (&hEnum))
295 LPIDENT lpiFind = lpUser->GetIdentifier();
296 if (AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
297 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
300 lpCell->UserFindClose (&hEnum);
301 if (status && (status != ADMITERATORDONE))
312 BOOL AfsAdmSvr_Search_GroupsInCell (LPASIDLIST *ppList, ASID idCell, LPTSTR pszPattern, ULONG *pStatus)
318 if ((lpCell = ((LPIDENT)idCell)->OpenCell (&status)) == NULL)
323 for (LPPTSGROUP lpGroup = lpCell->GroupFindFirst (&hEnum, TRUE, &status); lpGroup; lpGroup = lpCell->GroupFindNext (&hEnum))
325 LPIDENT lpiFind = lpGroup->GetIdentifier();
326 if (AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
327 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
330 lpCell->GroupFindClose (&hEnum);
331 if (status && (status != ADMITERATORDONE))
342 BOOL AfsAdmSvr_Search_AllInServer (LPASIDLIST *ppList, ASID idServer, LPTSTR pszPattern, ULONG *pStatus)
348 if ((lpServer = ((LPIDENT)idServer)->OpenServer (&status)) == NULL)
353 for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&hEnum, TRUE, &status); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&hEnum))
355 LPIDENT lpiFind = lpAggregate->GetIdentifier();
356 if (AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
357 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
358 lpAggregate->Close();
360 lpServer->AggregateFindClose (&hEnum);
361 if (status && (status != ADMITERATORDONE))
365 for (LPSERVICE lpService = lpServer->ServiceFindFirst (&hEnum, TRUE, &status); lpService; lpService = lpServer->ServiceFindNext (&hEnum))
367 LPIDENT lpiFind = lpService->GetIdentifier();
368 if (AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
369 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
372 lpServer->ServiceFindClose (&hEnum);
373 if (status && (status != ADMITERATORDONE))
385 BOOL AfsAdmSvr_Search_ServicesInServer (LPASIDLIST *ppList, ASID idServer, LPTSTR pszPattern, ULONG *pStatus)
391 if ((lpServer = ((LPIDENT)idServer)->OpenServer (&status)) == NULL)
396 for (LPSERVICE lpService = lpServer->ServiceFindFirst (&hEnum, TRUE, &status); lpService; lpService = lpServer->ServiceFindNext (&hEnum))
398 LPIDENT lpiFind = lpService->GetIdentifier();
399 if (AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
400 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
403 lpServer->ServiceFindClose (&hEnum);
404 if (status && (status != ADMITERATORDONE))
415 BOOL AfsAdmSvr_Search_PartitionsInServer (LPASIDLIST *ppList, ASID idServer, LPTSTR pszPattern, ULONG *pStatus)
421 if ((lpServer = ((LPIDENT)idServer)->OpenServer (&status)) == NULL)
426 for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&hEnum, TRUE, &status); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&hEnum))
428 LPIDENT lpiFind = lpAggregate->GetIdentifier();
429 if (AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
430 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
431 lpAggregate->Close();
433 lpServer->AggregateFindClose (&hEnum);
434 if (status && (status != ADMITERATORDONE))
445 BOOL AfsAdmSvr_Search_VolumesInServer (LPASIDLIST *ppList, ASID idServer, LPTSTR pszPattern, ULONG *pStatus)
451 for (LPIDENT lpiFind = IDENT::FindFirst (&hEnum); lpiFind; lpiFind = IDENT::FindNext (&hEnum))
453 if (lpiFind->GetType() != itFILESET)
455 if (lpiFind->GetServer() != (LPIDENT)idServer)
457 if (!AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
459 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
461 IDENT::FindClose (&hEnum);
469 BOOL AfsAdmSvr_Search_VolumesInPartition (LPASIDLIST *ppList, ASID idPartition, LPTSTR pszPattern, ULONG *pStatus)
474 LPAGGREGATE lpAggregate;
475 if ((lpAggregate = ((LPIDENT)idPartition)->OpenAggregate (&status)) == NULL)
480 for (LPFILESET lpFileset = lpAggregate->FilesetFindFirst (&hEnum, TRUE, &status); lpFileset; lpFileset = lpAggregate->FilesetFindNext (&hEnum))
482 LPIDENT lpiFind = lpFileset->GetIdentifier();
483 if (AfsAdmSvr_Search_Compare (lpiFind, pszPattern))
484 AfsAdmSvr_AddToAsidList (ppList, (ASID)lpiFind, 0);
487 lpAggregate->FilesetFindClose (&hEnum);
488 if (status && (status != ADMITERATORDONE))
490 lpAggregate->Close();
499 BOOL AfsAdmSvr_Search_ServerInCell (ASID *pidObject, ASID idCell, LPTSTR pszName, ULONG *pStatus)
505 if ((lpCell = ((LPIDENT)idCell)->OpenCell (&status)) == NULL)
510 if ((lpServer = lpCell->OpenServer (pszName, &status)) == NULL)
514 *pidObject = (ASID)(lpServer->GetIdentifier());
526 BOOL AfsAdmSvr_Search_ServiceInCell (ASID *pidObject, ASID idCell, LPTSTR pszName, ULONG *pStatus)
529 ULONG status = ERROR_INVALID_PARAMETER;
532 for (LPIDENT lpiFind = IDENT::FindFirst (&hEnum); lpiFind; lpiFind = IDENT::FindNext (&hEnum))
534 if (lpiFind->GetType() != itSERVICE)
536 if (lpiFind->GetCell() != (LPIDENT)idCell)
538 if (lpiFind->GetRefCount() == 0)
541 TCHAR szService[ cchNAME ];
542 lpiFind->GetServiceName (szService);
543 if (!lstrcmpi (pszName, szService))
545 *pidObject = (ASID)lpiFind;
550 IDENT::FindClose (&hEnum);
558 BOOL AfsAdmSvr_Search_PartitionInCell (ASID *pidObject, ASID idCell, LPTSTR pszName, ULONG *pStatus)
561 ULONG status = ERROR_INVALID_PARAMETER;
564 for (LPIDENT lpiFind = IDENT::FindFirst (&hEnum); lpiFind; lpiFind = IDENT::FindNext (&hEnum))
566 if (lpiFind->GetType() != itAGGREGATE)
568 if (lpiFind->GetCell() != (LPIDENT)idCell)
570 if (lpiFind->GetRefCount() == 0)
573 TCHAR szAggregate[ cchNAME ];
574 lpiFind->GetAggregateName (szAggregate);
575 if (!lstrcmpi (pszName, szAggregate))
577 *pidObject = (ASID)lpiFind;
582 IDENT::FindClose (&hEnum);
590 BOOL AfsAdmSvr_Search_VolumeInCell (ASID *pidObject, ASID idCell, LPTSTR pszName, ULONG *pStatus)
593 ULONG status = ERROR_INVALID_PARAMETER;
596 for (LPIDENT lpiFind = IDENT::FindFirst (&hEnum); lpiFind; lpiFind = IDENT::FindNext (&hEnum))
598 if (lpiFind->GetType() != itFILESET)
600 if (lpiFind->GetCell() != (LPIDENT)idCell)
602 if (lpiFind->GetRefCount() == 0)
605 TCHAR szFileset[ cchNAME ];
606 lpiFind->GetFilesetName (szFileset);
607 if (!lstrcmpi (szFileset, pszName))
609 *pidObject = (ASID)lpiFind;
614 IDENT::FindClose (&hEnum);
622 BOOL AfsAdmSvr_Search_UserInCell (ASID *pidObject, ASID idCell, LPTSTR pszName, ULONG *pStatus)
628 if ((lpCell = ((LPIDENT)idCell)->OpenCell (&status)) == NULL)
633 if ((lpUser = lpCell->OpenUser (pszName, NULL, &status)) == NULL)
637 *pidObject = (ASID)(lpUser->GetIdentifier());
649 BOOL AfsAdmSvr_Search_GroupInCell (ASID *pidObject, ASID idCell, LPTSTR pszName, ULONG *pStatus)
655 if ((lpCell = ((LPIDENT)idCell)->OpenCell (&status)) == NULL)
660 if ((lpGroup = lpCell->OpenGroup (pszName, &status)) == NULL)
664 *pidObject = (ASID)(lpGroup->GetIdentifier());
676 BOOL AfsAdmSvr_Search_ServiceInServer (ASID *pidObject, ASID idServer, LPTSTR pszName, ULONG *pStatus)
682 if ((lpServer = ((LPIDENT)idServer)->OpenServer (&status)) == NULL)
687 if ((lpService = lpServer->OpenService (pszName, &status)) == NULL)
691 *pidObject = (ASID)(lpService->GetIdentifier());
703 BOOL AfsAdmSvr_Search_PartitionInServer (ASID *pidObject, ASID idServer, LPTSTR pszName, ULONG *pStatus)
709 if ((lpServer = ((LPIDENT)idServer)->OpenServer (&status)) == NULL)
713 LPAGGREGATE lpAggregate;
714 if ((lpAggregate = lpServer->OpenAggregate (pszName, &status)) == NULL)
718 *pidObject = (ASID)(lpAggregate->GetIdentifier());
719 lpAggregate->Close();
730 BOOL AfsAdmSvr_Search_VolumeInServer (ASID *pidObject, ASID idServer, LPTSTR pszName, ULONG *pStatus)
733 ULONG status = ERROR_INVALID_PARAMETER;
736 for (LPIDENT lpiFind = IDENT::FindFirst (&hEnum); lpiFind; lpiFind = IDENT::FindNext (&hEnum))
738 if (lpiFind->GetType() != itFILESET)
740 if (lpiFind->GetServer() != (LPIDENT)idServer)
742 if (lpiFind->GetRefCount() == 0)
745 TCHAR szFileset[ cchNAME ];
746 lpiFind->GetFilesetName (szFileset);
747 if (!lstrcmpi (pszName, szFileset))
749 *pidObject = (ASID)lpiFind;
754 IDENT::FindClose (&hEnum);
762 BOOL AfsAdmSvr_Search_VolumeInPartition (ASID *pidObject, ASID idPartition, LPTSTR pszName, ULONG *pStatus)
767 LPAGGREGATE lpAggregate;
768 if ((lpAggregate = ((LPIDENT)idPartition)->OpenAggregate (&status)) == NULL)
773 if ((lpFileset = lpAggregate->OpenFileset (pszName, &status)) == NULL)
777 *pidObject = (ASID)(lpFileset->GetIdentifier());
780 lpAggregate->Close();
789 BOOL AfsAdmSvr_Search_OneUser (ASID *pidObject, ASID idScope, LPTSTR pszName, ULONG *pStatus)
795 if ((lpCell = ((LPIDENT)idScope)->OpenCell (&status)) == NULL)
800 if ((lpUser = lpCell->OpenUser (pszName, TEXT(""), &status)) == NULL)
804 *pidObject = (ASID)(lpUser->GetIdentifier());
816 BOOL AfsAdmSvr_Search_OneGroup (ASID *pidObject, ASID idScope, LPTSTR pszName, ULONG *pStatus)
822 if ((lpCell = ((LPIDENT)idScope)->OpenCell (&status)) == NULL)
827 if ((lpGroup = lpCell->OpenGroup (pszName, &status)) == NULL)
831 *pidObject = (ASID)(lpGroup->GetIdentifier());
844 void AfsAdmSvr_Search_Advanced (LPASIDLIST *ppList, LPAFSADMSVR_SEARCH_PARAMS pSearchParams)
848 if (ppList && (*ppList) && pSearchParams && (pSearchParams->SearchType != SEARCH_NO_LIMITATIONS))
850 for (size_t iEntry = 0; iEntry < (*ppList)->cEntries; )
854 // Try to grab the properties for this object. If we succeed,
855 // we can determine if the object matches the necessary criteria
856 // to indicate we should keep it in the list.
858 ASID idObject = (*ppList)->aEntries[ iEntry ].idObject;
860 LPASOBJPROP pProperties;
861 if ((pProperties = AfsAdmSvr_GetCurrentProperties (idObject, &status)) != NULL)
863 if ( (pProperties->verProperties >= verPROP_FIRST_SCAN) ||
864 (AfsAdmSvr_ObtainFullProperties (pProperties, &status)) )
866 // We managed to get the full properties for this object.
867 // Now check its properties against our search criteria--
868 // only if it has exactly the necessary criteria will we
871 switch (pSearchParams->SearchType)
873 case SEARCH_EXPIRES_BEFORE:
874 if ((pProperties->Type == TYPE_USER) && (pProperties->u.UserProperties.fHaveKasInfo))
876 if (IsValidTime (&pProperties->u.UserProperties.KASINFO.timeExpires))
879 SystemTimeToFileTime (&pProperties->u.UserProperties.KASINFO.timeExpires, &ftExpires);
881 FILETIME ftThreshhold;
882 SystemTimeToFileTime (&pSearchParams->SearchTime, &ftThreshhold);
884 if (CompareFileTime (&ftExpires, &ftThreshhold) <= 0)
890 case SEARCH_PASSWORD_EXPIRES_BEFORE:
891 if ((pProperties->Type == TYPE_USER) && (pProperties->u.UserProperties.fHaveKasInfo))
893 if (pProperties->u.UserProperties.KASINFO.cdayPwExpire)
895 FILETIME ftPwExpires;
896 SystemTimeToFileTime (&pProperties->u.UserProperties.KASINFO.timeLastPwChange, &ftPwExpires);
898 // A FILETIME is a count-of-100ns-intervals since 1601.
899 // We need to increase the {ftPwExpires} time by the
900 // number of days in KASINFO.cdayPwExpires, so we'll
901 // be adding a big number to our FILETIME structure.
904 ldw.HighPart = ftPwExpires.dwHighDateTime;
905 ldw.LowPart = ftPwExpires.dwLowDateTime;
906 ldw.QuadPart += c100ns1SECOND * (LONGLONG)csec1DAY * (LONGLONG)pProperties->u.UserProperties.KASINFO.cdayPwExpire;
907 ftPwExpires.dwHighDateTime = (DWORD)ldw.HighPart;
908 ftPwExpires.dwLowDateTime = (DWORD)ldw.LowPart;
910 FILETIME ftThreshhold;
911 SystemTimeToFileTime (&pSearchParams->SearchTime, &ftThreshhold);
913 if (CompareFileTime (&ftPwExpires, &ftThreshhold) <= 0)
922 // Okay, we've made our choice--remove it, or not.
925 AfsAdmSvr_RemoveFromAsidListByIndex (ppList, iEntry);