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 <WINNT/afsclass.h>
20 * DEFINITIONS ________________________________________________________________
24 #define cREALLOC_ADMINLISTENTRIES 32
26 #define cREALLOC_HOSTLISTENTRIES 16
28 #define cREALLOC_SERVERKEYS 16
30 #define ACCOUNTACCESS_TO_USERACCESS(_aa) ( ((_aa) == aaOWNER_ONLY) ? PTS_USER_OWNER_ACCESS : PTS_USER_ANYUSER_ACCESS )
32 #define ACCOUNTACCESS_TO_GROUPACCESS(_aa) ( ((_aa) == aaOWNER_ONLY) ? PTS_GROUP_OWNER_ACCESS : ((_aa) == aaGROUP_ONLY) ? PTS_GROUP_ACCESS : PTS_GROUP_ANYUSER_ACCESS )
36 * PROTOTYPES _________________________________________________________________
42 * ROUTINES ___________________________________________________________________
46 BOOL AfsClass_GetServerLogFile (LPIDENT lpiServer, LPTSTR pszLocal, LPTSTR pszRemote, ULONG *pStatus)
52 NOTIFYCALLBACK::SendNotificationToAll (evtGetServerLogFileBegin, lpiServer, pszRemote, 0);
57 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
61 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
69 wp.wpBosLogGet.hServer = hBOS;
70 wp.wpBosLogGet.pszLogName = pszRemote;
71 wp.wpBosLogGet.pszLogData = NULL;
74 if ((rc = Worker_DoTask (wtaskBosLogGet, &wp, &status)) == TRUE)
77 if ((fh = CreateFile (pszLocal, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL)) != INVALID_HANDLE_VALUE)
79 // Write the file a line at a time in order to make
80 // sure that each line ends with "\r\n". If we encounter
81 // a line which ends in \r\n already, well, leave it alone.
83 for (LPTSTR psz = wp.wpBosLogGet.pszLogData; psz && *psz; )
86 for (pszNext = psz; *pszNext && (*pszNext != TEXT('\r')) && (*pszNext != TEXT('\n')); ++pszNext)
90 if ((cbWrite = pszNext - psz) != 0)
91 WriteFile (fh, psz, cbWrite, &cbWrote, NULL);
92 WriteFile (fh, TEXT("\r\n"), 2, &cbWrote, NULL);
93 psz = (*pszNext == TEXT('\r')) ? (2+pszNext) : (*pszNext == TEXT('\n')) ? (1+pszNext) : NULL;
98 Free (wp.wpBosLogGet.pszLogData);
104 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
106 lpServer->CloseBosObject();
110 NOTIFYCALLBACK::SendNotificationToAll (evtGetServerLogFileEnd, lpiServer, pszRemote, status);
119 BOOL AfsClass_SetServerAuth (LPIDENT lpiServer, BOOL fEnabled, ULONG *pStatus)
125 NOTIFYCALLBACK::SendNotificationToAll (evtSetServerAuthBegin, lpiServer);
130 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
134 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
142 wp.wpBosAuthSet.hServer = hBOS;
143 wp.wpBosAuthSet.fEnableAuth = fEnabled;
146 rc = Worker_DoTask (wtaskBosAuthSet, &wp, &status);
150 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
152 lpServer->CloseBosObject();
156 NOTIFYCALLBACK::SendNotificationToAll (evtSetServerAuthEnd, lpiServer, status);
165 BOOL AfsClass_StartService (LPIDENT lpiStart, BOOL fTemporary, ULONG *pStatus)
171 NOTIFYCALLBACK::SendNotificationToAll (evtStartServiceBegin, lpiStart);
176 if ((lpServer = lpiStart->OpenServer (&status)) == NULL)
180 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
187 if (lpiStart->fIsService())
189 TCHAR szName[ cchNAME ];
190 lpiStart->GetServiceName (szName);
195 wp.wpBosProcessExecutionStateSetTemporary.hServer = hBOS;
196 wp.wpBosProcessExecutionStateSetTemporary.pszService = szName;
197 wp.wpBosProcessExecutionStateSetTemporary.state = SERVICESTATE_RUNNING;
200 rc = Worker_DoTask (wtaskBosProcessExecutionStateSetTemporary, &wp, &status);
206 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
207 wp.wpBosProcessExecutionStateSet.pszService = szName;
208 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_RUNNING;
211 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
218 wp.wpBosProcessAllStart.hServer = hBOS;
220 rc = Worker_DoTask (wtaskBosProcessAllStart, &wp, &status);
227 if (lpiStart->fIsService())
230 if ((lpService = lpiStart->OpenService (&status)) == NULL)
234 lpService->Invalidate();
235 lpService->RefreshStatus();
241 if ((lpServer = lpiStart->OpenServer (&status)) == NULL)
245 lpServer->Invalidate();
246 lpServer->RefreshAll();
252 if ((lpServer = lpiStart->OpenServer (&status)) != NULL)
254 lpServer->CloseBosObject();
258 NOTIFYCALLBACK::SendNotificationToAll (evtStartServiceEnd, lpiStart, status);
267 BOOL AfsClass_StopService (LPIDENT lpiStop, BOOL fTemporary, BOOL fWait, ULONG *pStatus)
273 NOTIFYCALLBACK::SendNotificationToAll (evtStopServiceBegin, lpiStop);
278 if ((lpServer = lpiStop->OpenServer (&status)) == NULL)
282 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
289 if (lpiStop->fIsService())
291 TCHAR szName[ cchNAME ];
292 lpiStop->GetServiceName (szName);
297 wp.wpBosProcessExecutionStateSetTemporary.hServer = hBOS;
298 wp.wpBosProcessExecutionStateSetTemporary.pszService = szName;
299 wp.wpBosProcessExecutionStateSetTemporary.state = SERVICESTATE_STOPPED;
300 // TODO: wp.wpStopBosProcessTemporary.fWait = TRUE;
303 rc = Worker_DoTask (wtaskBosProcessExecutionStateSetTemporary, &wp, &status);
309 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
310 wp.wpBosProcessExecutionStateSet.pszService = szName;
311 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
312 // TODO: wp.wpStopBosProcess.fWait = TRUE;
315 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
322 wp.wpBosProcessAllWaitStop.hServer = hBOS;
325 rc = Worker_DoTask (wtaskBosProcessAllWaitStop, &wp, &status);
331 wp.wpBosProcessAllStop.hServer = hBOS;
334 rc = Worker_DoTask (wtaskBosProcessAllStop, &wp, &status);
341 if (lpiStop->fIsService())
344 if ((lpService = lpiStop->OpenService (&status)) == NULL)
348 lpService->Invalidate();
349 lpService->RefreshStatus();
356 if ((lpServer = lpiStop->OpenServer (&status)) == NULL)
360 lpServer->Invalidate();
361 lpServer->RefreshAll();
367 if ((lpServer = lpiStop->OpenServer (&status)) != NULL)
369 lpServer->CloseBosObject();
373 NOTIFYCALLBACK::SendNotificationToAll (evtStopServiceEnd, lpiStop, status);
382 BOOL AfsClass_RestartService (LPIDENT lpiRestart, ULONG *pStatus)
388 NOTIFYCALLBACK::SendNotificationToAll (evtRestartServiceBegin, lpiRestart);
393 if ((lpServer = lpiRestart->OpenServer (&status)) == NULL)
397 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
402 BOOL fRestartAll = FALSE;
403 if (!lpiRestart->fIsService())
406 TCHAR szServiceRestart[ cchNAME ];
407 if (lpiRestart->fIsService())
409 lpiRestart->GetServiceName (szServiceRestart);
410 if (!lstrcmpi (szServiceRestart, TEXT("BOS")))
419 wp.wpBosProcessRestart.hServer = hBOS;
420 wp.wpBosProcessRestart.pszService = szServiceRestart;
423 rc = Worker_DoTask (wtaskBosProcessRestart, &wp, &status);
426 else // (fRestartAll)
429 wp.wpBosProcessAllStopAndRestart.hServer = hBOS;
430 wp.wpBosProcessAllStopAndRestart.fRestartBOS = TRUE;
433 rc = Worker_DoTask (wtaskBosProcessAllStopAndRestart, &wp, &status);
443 if ((lpService = lpiRestart->OpenService (&status)) == NULL)
447 lpService->Invalidate();
448 lpService->RefreshStatus();
452 else // (fRestartAll)
455 if ((lpServer = lpiRestart->OpenServer (&status)) == NULL)
459 lpServer->Invalidate();
460 lpServer->RefreshAll();
466 if ((lpServer = lpiRestart->OpenServer (&status)) != NULL)
468 lpServer->CloseBosObject();
472 NOTIFYCALLBACK::SendNotificationToAll (evtRestartServiceEnd, lpiRestart, status);
481 LPIDENT AfsClass_CreateFileset (LPIDENT lpiAggregate, LPTSTR pszFileset, ULONG ckQuota, ULONG *pStatus)
483 LPIDENT lpiFileset = NULL;
488 NOTIFYCALLBACK::SendNotificationToAll (evtCreateFilesetBegin, lpiAggregate, pszFileset, 0);
490 // Obtain hCell and hVOS
495 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
499 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
504 // Obtain idPartition
507 LPAGGREGATE lpAggregate;
508 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
512 idPartition = lpAggregate->GetID();
513 lpAggregate->Close();
516 // Perform the actual operation
521 wp.wpVosVolumeCreate.hCell = hCell;
522 wp.wpVosVolumeCreate.hServer = hVOS;
523 wp.wpVosVolumeCreate.idPartition = idPartition;
524 wp.wpVosVolumeCreate.pszVolume = pszFileset;
525 wp.wpVosVolumeCreate.ckQuota = ckQuota;
528 rc = Worker_DoTask (wtaskVosVolumeCreate, &wp, &status);
536 LPAGGREGATE lpAggregate;
537 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
541 lpAggregate->Invalidate();
542 lpAggregate->RefreshFilesets (TRUE, &status);
543 lpAggregate->Close();
550 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
554 lpCell->RefreshVLDB (lpiAggregate);
561 LPAGGREGATE lpAggregate;
562 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
567 if ((lpFileset = lpAggregate->OpenFileset (pszFileset, &status)) == NULL)
571 lpiFileset = lpFileset->GetIdentifier();
574 lpAggregate->Close();
580 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
582 lpServer->CloseVosObject();
587 NOTIFYCALLBACK::SendNotificationToAll (evtCreateFilesetEnd, lpiAggregate, pszFileset, status);
592 return (rc) ? lpiFileset : NULL;
596 BOOL AfsClass_DeleteFileset (LPIDENT lpiFileset, BOOL fVLDB, BOOL fServer, ULONG *pStatus)
602 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiFileset);
604 // Obtain hCell and hVOS
609 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
613 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
618 // Does the fileset have a VLDB entry? Does it actually exist on the server?
619 // What's its volume ID? Its R/W ID? Its partition ID?
622 VOLUMEID vidReadWrite;
625 // Obtain the ID of the fileset's parent aggregate.
628 LPAGGREGATE lpAggregate;
629 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
633 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
635 lpAggregate->Close();
641 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
645 wFilesetGhost = lpFileset->GetGhostStatus();
646 lpiFileset->GetFilesetID (&vidFileset);
649 if (!lpFileset->GetStatus (&fs))
650 vidReadWrite = vidFileset;
652 vidReadWrite = fs.idReadWrite;
658 if (!(wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
660 if (!(wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
663 if (rc && fVLDB && fServer)
666 wp.wpVosVolumeDelete.hCell = hCell;
667 wp.wpVosVolumeDelete.hServer = hVOS;
668 wp.wpVosVolumeDelete.idPartition = idPartition;
669 wp.wpVosVolumeDelete.idVolume = vidFileset;
672 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
675 else if (rc && fVLDB)
678 wp.wpVosVLDBEntryRemove.hCell = hCell;
679 wp.wpVosVLDBEntryRemove.hServer = hVOS;
680 wp.wpVosVLDBEntryRemove.idPartition = idPartition;
681 wp.wpVosVLDBEntryRemove.idVolume = vidReadWrite;
684 rc = Worker_DoTask (wtaskVosVLDBEntryRemove, &wp, &status);
687 else if (rc && fServer)
690 wp.wpVosVolumeZap.hCell = hCell;
691 wp.wpVosVolumeZap.hServer = hVOS;
692 wp.wpVosVolumeZap.idPartition = idPartition;
693 wp.wpVosVolumeZap.idVolume = vidFileset;
694 wp.wpVosVolumeZap.fForce = TRUE;
697 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
703 LPAGGREGATE lpAggregate;
704 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
708 lpAggregate->Invalidate();
709 lpAggregate->RefreshFilesets (TRUE);
710 lpAggregate->Close();
717 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
721 lpCell->RefreshVLDB (lpiFileset->GetAggregate(), TRUE);
728 if ((lpServer = lpiFileset->OpenServer()) != NULL)
730 lpServer->CloseVosObject();
735 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiFileset, status);
744 BOOL AfsClass_MoveFileset (LPIDENT lpiFileset, LPIDENT lpiAggregateTarget, ULONG *pStatus)
750 NOTIFYCALLBACK::SendNotificationToAll (evtMoveFilesetBegin, lpiFileset, lpiAggregateTarget, NULL, NULL, 0, 0);
752 LPIDENT lpiAggregateSource = lpiFileset->GetAggregate();
754 // Obtain hCell, hVOS and the aggregate name for the source
757 PVOID hVOSSource = NULL;
759 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
763 if ((hVOSSource = lpServer->OpenVosObject (&hCell, &status)) == NULL)
768 // Obtain the ID of the source aggregate
770 int idPartitionSource;
771 LPAGGREGATE lpAggregate;
772 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
776 if ((idPartitionSource = lpAggregate->GetID()) == NO_PARTITION)
778 lpAggregate->Close();
781 // Obtain hCell, hVOS and the aggregate name for the target
783 PVOID hVOSTarget = NULL;
784 if ((lpServer = lpiAggregateTarget->OpenServer (&status)) == NULL)
788 if ((hVOSTarget = lpServer->OpenVosObject (NULL, &status)) == NULL)
793 // Obtain the ID of the target aggregate
795 int idPartitionTarget;
796 if ((lpAggregate = lpiAggregateTarget->OpenAggregate (&status)) == NULL)
800 if ((idPartitionTarget = lpAggregate->GetID()) == NO_PARTITION)
802 lpAggregate->Close();
808 wp.wpVosVolumeMove.hCell = hCell;
809 wp.wpVosVolumeMove.hServerFrom = hVOSSource;
810 wp.wpVosVolumeMove.idPartitionFrom = idPartitionSource;
811 wp.wpVosVolumeMove.hServerTo = hVOSTarget;
812 wp.wpVosVolumeMove.idPartitionTo = idPartitionTarget;
813 lpiFileset->GetFilesetID (&wp.wpVosVolumeMove.idVolume);
816 rc = Worker_DoTask (wtaskVosVolumeMove, &wp, &status);
822 LPAGGREGATE lpAggregate;
823 if ((lpAggregate = lpiAggregateSource->OpenAggregate (&status)) == NULL)
827 lpAggregate->Invalidate();
828 lpAggregate->RefreshFilesets();
829 lpAggregate->Close();
835 LPAGGREGATE lpAggregate;
836 if ((lpAggregate = lpiAggregateTarget->OpenAggregate (&status)) == NULL)
840 lpAggregate->Invalidate();
841 lpAggregate->RefreshFilesets();
842 lpAggregate->Close();
849 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
853 lpFileset->Invalidate();
854 lpFileset->RefreshStatus();
862 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
866 lpCell->RefreshVLDB (lpiAggregateSource, TRUE);
867 lpCell->RefreshVLDB (lpiAggregateTarget, TRUE);
874 if ((lpServer = lpiAggregateSource->OpenServer()) != NULL)
876 lpServer->CloseVosObject();
882 if ((lpServer = lpiAggregateTarget->OpenServer()) != NULL)
884 lpServer->CloseVosObject();
889 NOTIFYCALLBACK::SendNotificationToAll (evtMoveFilesetEnd, lpiFileset, lpiAggregateTarget, NULL, NULL, 0, status);
898 BOOL AfsClass_SetFilesetQuota (LPIDENT lpiFileset, size_t ckQuotaNew, ULONG *pStatus)
904 NOTIFYCALLBACK::SendNotificationToAll (evtSetFilesetQuotaBegin, lpiFileset);
906 // Obtain hCell and hVOS for the server where this fileset lives
911 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
915 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
920 // Obtain the ID of the fileset's parent aggregate.
925 LPAGGREGATE lpAggregate;
926 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
930 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
932 lpAggregate->Close();
936 // Change the fileset's quota.
941 wp.wpVosVolumeQuotaChange.hCell = hCell;
942 wp.wpVosVolumeQuotaChange.hServer = hVOS;
943 wp.wpVosVolumeQuotaChange.idPartition = idPartition;
944 lpiFileset->GetFilesetID (&wp.wpVosVolumeQuotaChange.idVolume);
945 wp.wpVosVolumeQuotaChange.ckQuota = ckQuotaNew;
948 rc = Worker_DoTask (wtaskVosVolumeQuotaChange, &wp, &status);
955 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
959 lpFileset->Invalidate();
960 lpFileset->RefreshStatus();
967 LPAGGREGATE lpAggregate;
968 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
972 lpAggregate->RefreshStatus();
973 lpAggregate->Close();
979 if ((lpServer = lpiFileset->OpenServer()) != NULL)
981 lpServer->CloseVosObject();
986 NOTIFYCALLBACK::SendNotificationToAll (evtSetFilesetQuotaEnd, lpiFileset, status);
995 BOOL AfsClass_SyncVLDB (LPIDENT lpiSync, BOOL fForce, ULONG *pStatus)
1001 NOTIFYCALLBACK::SendNotificationToAll (evtSyncVLDBBegin, lpiSync);
1003 // Obtain hCell and hVOS
1008 if ((lpServer = lpiSync->OpenServer (&status)) == NULL)
1012 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1017 // Obtain the ID of the target aggregate.
1019 int idPartition = NO_PARTITION;
1020 if (rc && (lpiSync->fIsAggregate() || lpiSync->fIsFileset()))
1022 LPAGGREGATE lpAggregate;
1023 if ((lpAggregate = lpiSync->OpenAggregate (&status)) == NULL)
1027 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1029 lpAggregate->Close();
1036 wp.wpVosVLDBSync.hCell = hCell;
1037 wp.wpVosVLDBSync.hServer = hVOS;
1038 wp.wpVosVLDBSync.idPartition = idPartition;
1039 wp.wpVosVLDBSync.fForce = fForce;
1042 rc = Worker_DoTask (wtaskVosVLDBSync, &wp, &status);
1048 if (lpiSync->fIsServer())
1051 if ((lpServer = lpiSync->OpenServer (&status)) == NULL)
1055 lpServer->Invalidate();
1056 rc = lpServer->RefreshAll (&status);
1060 else // (lpiSync->fIsAggregate())
1062 LPAGGREGATE lpAggregate;
1063 if ((lpAggregate = lpiSync->OpenAggregate (&status)) == NULL)
1067 lpAggregate->Invalidate();
1068 lpAggregate->RefreshStatus();
1069 lpAggregate->RefreshFilesets();
1070 lpAggregate->Close();
1073 if ((lpCell = lpiSync->OpenCell()) == NULL)
1077 lpCell->RefreshVLDB (lpiSync);
1086 if ((lpServer = lpiSync->OpenServer()) != NULL)
1088 lpServer->CloseVosObject();
1093 NOTIFYCALLBACK::SendNotificationToAll (evtSyncVLDBEnd, lpiSync, status);
1102 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSOCKADDR_IN pAddrOld, LPSOCKADDR_IN pAddrNew, ULONG *pStatus)
1108 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1114 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1118 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1126 wp.wpVosFileServerAddressChange.hCell = hCell;
1127 wp.wpVosFileServerAddressChange.addrOld = *pAddrOld;
1128 wp.wpVosFileServerAddressChange.addrNew = *pAddrNew;
1131 rc = Worker_DoTask (wtaskVosFileServerAddressChange, &wp, &status);
1134 else if (rc && !pAddrNew)
1137 wp.wpVosFileServerAddressRemove.hCell = hCell;
1138 wp.wpVosFileServerAddressRemove.addr = *pAddrOld;
1141 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1148 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1150 lpServer->InvalidateStatus();
1155 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1159 lpCell->InvalidateServers ();
1160 rc = lpCell->RefreshServers (TRUE, &status);
1165 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1174 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSERVERSTATUS pStatusOld, LPSERVERSTATUS pStatusNew, ULONG *pStatus)
1180 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1186 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1190 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1199 for (size_t iAddr = 0; rc && (iAddr < AFSCLASS_MAX_ADDRESSES_PER_SITE); ++iAddr)
1203 AfsClass_AddressToInt (&oldAddress, &pStatusOld->aAddresses[ iAddr ]);
1204 AfsClass_AddressToInt (&newAddress, &pStatusNew->aAddresses[ iAddr ]);
1206 if (oldAddress && newAddress && (oldAddress != newAddress))
1209 wp.wpVosFileServerAddressChange.hCell = hCell;
1210 wp.wpVosFileServerAddressChange.addrOld = pStatusOld->aAddresses[ iAddr ];
1211 wp.wpVosFileServerAddressChange.addrNew = pStatusNew->aAddresses[ iAddr ];
1213 rc = Worker_DoTask (wtaskVosFileServerAddressChange, &wp, &status);
1215 else if (oldAddress && !newAddress)
1218 wp.wpVosFileServerAddressRemove.hCell = hCell;
1219 wp.wpVosFileServerAddressRemove.addr = pStatusOld->aAddresses[ iAddr ];
1221 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1231 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1233 lpServer->InvalidateStatus();
1238 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1242 lpCell->InvalidateServers ();
1243 rc = lpCell->RefreshServers (TRUE, &status);
1248 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1257 BOOL AfsClass_LockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1263 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetBegin, lpiFileset);
1269 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1273 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1278 // Obtain the fileset's read-write identifier
1280 LPIDENT lpiRW = NULL;
1281 LPFILESET lpFileset;
1282 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1286 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1291 // Perform the lock operation
1296 wp.wpVosVLDBEntryLock.hCell = hCell;
1297 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryLock.idVolume);
1300 rc = Worker_DoTask (wtaskVosVLDBEntryLock, &wp, &status);
1307 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1312 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1314 lpCell->RefreshVLDB (lpiFileset->GetCell());
1319 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetEnd, lpiFileset, status);
1328 BOOL AfsClass_UnlockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1334 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetBegin, lpiFileset);
1340 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1344 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1349 // Obtain the fileset's read-write identifier
1351 LPIDENT lpiRW = NULL;
1352 LPFILESET lpFileset;
1353 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1357 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1362 // Perform the unlock operation
1367 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1368 wp.wpVosVLDBEntryUnlock.hServer = NULL;
1369 wp.wpVosVLDBEntryUnlock.idPartition = NO_PARTITION;
1370 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryUnlock.idVolume);
1373 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1380 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1385 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1387 lpCell->RefreshVLDB (lpiFileset->GetCell());
1392 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetEnd, lpiFileset, status);
1401 BOOL AfsClass_UnlockAllFilesets (LPIDENT lpi, ULONG *pStatus)
1407 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsBegin, lpi);
1413 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1417 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1422 // Obtain hServer if appropriate
1425 if (lpi && (!lpi->fIsCell()))
1428 if ((lpServer = lpi->OpenServer (&status)) == NULL)
1432 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
1438 // Obtain the ID of the scope aggregate.
1440 int idPartition = NO_PARTITION;
1441 if (rc && (lpi->fIsFileset() || (lpi->fIsAggregate())))
1443 LPAGGREGATE lpAggregate;
1444 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
1448 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1450 lpAggregate->Close();
1454 // Perform the unlock operation
1459 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1460 wp.wpVosVLDBEntryUnlock.hServer = hVOS;
1461 wp.wpVosVLDBEntryUnlock.idPartition = idPartition;
1462 wp.wpVosVLDBEntryUnlock.idVolume = NO_VOLUME;
1465 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1472 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1476 lpCell->RefreshVLDB (lpi);
1484 if ((lpServer = lpi->OpenServer (&status)) != NULL)
1486 lpServer->CloseVosObject();
1491 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsEnd, lpi);
1500 LPIDENT AfsClass_CreateReplica (LPIDENT lpiFileset, LPIDENT lpiAggregate, ULONG *pStatus)
1504 LPIDENT lpiReplica = NULL;
1507 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaBegin, lpiFileset, lpiAggregate, NULL, NULL, 0, 0);
1509 // Obtain hCell and hVOS for the target server
1514 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
1518 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1523 // Obtain idPartition
1526 LPAGGREGATE lpAggregate;
1527 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1531 idPartition = lpAggregate->GetID();
1532 lpAggregate->Close();
1535 // Modify VLDB to create mention of a new replica
1540 wp.wpVosVLDBReadOnlySiteCreate.hCell = hCell;
1541 wp.wpVosVLDBReadOnlySiteCreate.hServer = hVOS;
1542 wp.wpVosVLDBReadOnlySiteCreate.idPartition = idPartition;
1543 lpiFileset->GetFilesetID (&wp.wpVosVLDBReadOnlySiteCreate.idVolume);
1546 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteCreate, &wp, &status);
1554 LPAGGREGATE lpAggregate;
1555 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1559 lpAggregate->Invalidate();
1560 lpAggregate->RefreshFilesets (TRUE, &status);
1561 lpAggregate->Close();
1568 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
1572 lpCell->RefreshVLDB (lpiAggregate);
1579 LPFILESET lpFileset;
1580 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1584 if ((lpiReplica = lpFileset->GetReadOnlyIdentifier (lpiAggregate, &status)) == NULL)
1592 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
1594 lpServer->CloseVosObject();
1599 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaEnd, lpiFileset, lpiAggregate, NULL, NULL, 0, status);
1604 return (rc) ? lpiReplica : FALSE;
1608 BOOL AfsClass_DeleteReplica (LPIDENT lpiReplica, ULONG *pStatus)
1614 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiReplica);
1616 // Obtain hCell and hVOS for the server
1621 if ((lpServer = lpiReplica->OpenServer (&status)) == NULL)
1625 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1630 // Get the read/write fileset identifier and Ghost status
1632 LPIDENT lpiRW = NULL;
1633 int wFilesetGhost = 0;
1634 LPFILESET lpFileset;
1635 if ((lpFileset = lpiReplica->OpenFileset (&status)) == NULL)
1639 wFilesetGhost = lpFileset->GetGhostStatus();
1640 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1645 TCHAR szAggregateName[ cchNAME ];
1646 lpiReplica->GetAggregateName (szAggregateName);
1648 // Obtain the ID of the replica's partition
1651 LPAGGREGATE lpAggregate;
1652 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1656 idPartition = lpAggregate->GetID();
1657 lpAggregate->Close();
1660 // If the volume exists in both VLDB and on the server, just delete it
1662 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY) && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1665 wp.wpVosVolumeDelete.hCell = hCell;
1666 wp.wpVosVolumeDelete.hServer = hVOS;
1667 wp.wpVosVolumeDelete.idPartition = idPartition;
1668 lpiReplica->GetFilesetID (&wp.wpVosVolumeDelete.idVolume);
1671 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
1676 // If necessary, modify VLDB to remove mention of this replica
1678 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
1681 wp.wpVosVLDBReadOnlySiteDelete.hCell = hCell;
1682 wp.wpVosVLDBReadOnlySiteDelete.hServer = hVOS;
1683 wp.wpVosVLDBReadOnlySiteDelete.idPartition = idPartition;
1684 lpiRW->GetFilesetID (&wp.wpVosVLDBReadOnlySiteDelete.idVolume);
1687 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteDelete, &wp, &status);
1691 // If necessary, zap the volume
1693 if (rc && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1696 wp.wpVosVolumeZap.hCell = hCell;
1697 wp.wpVosVolumeZap.hServer = hVOS;
1698 wp.wpVosVolumeZap.idPartition = idPartition;
1699 lpiReplica->GetFilesetID (&wp.wpVosVolumeZap.idVolume);
1700 wp.wpVosVolumeZap.fForce = TRUE;
1703 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
1712 LPAGGREGATE lpAggregate;
1713 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1717 lpAggregate->Invalidate();
1718 lpAggregate->RefreshFilesets (TRUE, &status);
1719 lpAggregate->Close();
1726 if ((lpCell = lpiReplica->OpenCell()) == NULL)
1730 lpCell->RefreshVLDB (lpiReplica->GetAggregate());
1737 if ((lpServer = lpiReplica->OpenServer (&status)) != NULL)
1739 lpServer->CloseVosObject();
1744 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiReplica, status);
1753 BOOL AfsClass_DeleteClone (LPIDENT lpiClone, ULONG *pStatus)
1755 return AfsClass_DeleteFileset (lpiClone, TRUE, TRUE, pStatus);
1759 BOOL AfsClass_InstallFile (LPIDENT lpiServer, LPTSTR pszTarget, LPTSTR pszSource, ULONG *pStatus)
1765 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileBegin, lpiServer, pszSource, 0);
1770 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1774 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1782 wp.wpBosExecutableCreate.hServer = hBOS;
1783 wp.wpBosExecutableCreate.pszLocal = pszSource;
1784 wp.wpBosExecutableCreate.pszRemoteDir = pszTarget;
1787 rc = Worker_DoTask (wtaskBosExecutableCreate, &wp, &status);
1791 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1793 lpServer->CloseBosObject();
1797 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileEnd, lpiServer, pszSource, status);
1806 BOOL AfsClass_UninstallFile (LPIDENT lpiServer, LPTSTR pszUninstall, ULONG *pStatus)
1812 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileBegin, lpiServer, pszUninstall, 0);
1817 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1821 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1829 wp.wpBosExecutableRevert.hServer = hBOS;
1830 wp.wpBosExecutableRevert.pszFilename = pszUninstall;
1833 rc = Worker_DoTask (wtaskBosExecutableRevert, &wp, &status);
1837 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1839 lpServer->CloseBosObject();
1843 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileEnd, lpiServer, pszUninstall, status);
1852 BOOL AfsClass_PruneOldFiles (LPIDENT lpiServer, BOOL fBAK, BOOL fOLD, BOOL fCore, ULONG *pStatus)
1858 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesBegin, lpiServer);
1863 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1867 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1875 wp.wpBosExecutablePrune.hServer = hBOS;
1876 wp.wpBosExecutablePrune.fPruneBak = fBAK;
1877 wp.wpBosExecutablePrune.fPruneOld = fOLD;
1878 wp.wpBosExecutablePrune.fPruneCore = fCore;
1881 rc = Worker_DoTask (wtaskBosExecutablePrune, &wp, &status);
1885 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1887 lpServer->CloseBosObject();
1891 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesEnd, lpiServer, status);
1900 BOOL AfsClass_RenameFileset (LPIDENT lpiFileset, LPTSTR pszNewName, ULONG *pStatus)
1906 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetBegin, lpiFileset, pszNewName, 0);
1910 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1914 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1922 wp.wpVosVolumeRename.hCell = hCell;
1923 lpiFileset->GetFilesetID (&wp.wpVosVolumeRename.idVolume);
1924 wp.wpVosVolumeRename.pszVolume = pszNewName;
1927 rc = Worker_DoTask (wtaskVosVolumeRename, &wp, &status);
1934 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1938 lpCell->Invalidate();
1939 rc = lpCell->RefreshAll (&status);
1945 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetEnd, lpiFileset, pszNewName, status);
1954 #define iswhite(_ch) ((_ch)==TEXT(' ') || (_ch)==TEXT('\t'))
1956 LPIDENT AfsClass_CreateService (LPIDENT lpiServer, LPTSTR pszService, LPTSTR pszCommand, LPTSTR pszParams, LPTSTR pszNotifier, AFSSERVICETYPE type, SYSTEMTIME *pstIfCron, ULONG *pStatus)
1960 LPIDENT lpiService = NULL;
1963 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceBegin, lpiServer, pszService, 0);
1968 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1972 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1980 wp.wpBosProcessCreate.hServer = hBOS;
1981 wp.wpBosProcessCreate.pszService = pszService;
1982 wp.wpBosProcessCreate.type = type;
1983 wp.wpBosProcessCreate.pszNotifier = pszNotifier;
1985 TCHAR szFullCommand[ MAX_PATH + MAX_PATH ];
1986 wsprintf (szFullCommand, TEXT("%s %s"), pszCommand, pszParams);
1987 wp.wpBosProcessCreate.pszCommand = szFullCommand;
1989 TCHAR szCronTime[ 256 ] = TEXT("");
1990 wp.wpBosProcessCreate.pszTimeCron = szCronTime;
1992 if (type == SERVICETYPE_CRON)
1993 AfsClass_FormatRecurringTime (szCronTime, pstIfCron);
1995 wp.wpBosProcessCreate.pszTimeCron = NULL;
1998 rc = Worker_DoTask (wtaskBosProcessCreate, &wp, &status);
2004 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2008 lpServer->InvalidateServices();
2009 if (!lpServer->RefreshServices (TRUE, &status))
2013 LPSERVICE lpService;
2014 if ((lpService = lpServer->OpenService (pszService, &status)) == NULL)
2018 lpiService = lpService->GetIdentifier();
2026 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2028 lpServer->CloseBosObject();
2032 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceEnd, lpiServer, pszService, status);
2037 return (rc) ? lpiService : NULL;
2041 BOOL AfsClass_DeleteService (LPIDENT lpiService, ULONG *pStatus)
2047 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceBegin, lpiService);
2052 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2056 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2061 // Before a service can be deleted, it must be stopped (otherwise, on NT,
2062 // the Delete operation won't block for the required Stop to complete--
2063 // so our wtaskDeleteBosProcess would return before the service really
2068 TCHAR szService[ cchNAME ];
2069 lpiService->GetServiceName (szService);
2072 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
2073 wp.wpBosProcessExecutionStateSet.pszService = szService;
2074 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
2075 // TODO: wp.wpStopBosProcess.fWait = TRUE;
2078 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
2082 // Delete the service
2086 TCHAR szService[ cchNAME ];
2087 lpiService->GetServiceName (szService);
2090 wp.wpBosProcessDelete.hServer = hBOS;
2091 wp.wpBosProcessDelete.pszService = szService;
2094 rc = Worker_DoTask (wtaskBosProcessDelete, &wp, &status);
2100 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2104 lpServer->InvalidateServices();
2105 if (!lpServer->RefreshServices (TRUE, &status))
2111 if ((lpServer = lpiService->OpenServer (&status)) != NULL)
2113 lpServer->CloseBosObject();
2117 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceEnd, lpiService, status);
2126 BOOL AfsClass_ReleaseFileset (LPIDENT lpiFilesetRW, BOOL fForce, ULONG *pStatus)
2132 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetBegin, lpiFilesetRW);
2134 // Obtain hCell and hVOS
2139 if ((lpServer = lpiFilesetRW->OpenServer (&status)) == NULL)
2143 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2148 // Perform the actual operation
2153 wp.wpVosVolumeRelease.hCell = hCell;
2154 wp.wpVosVolumeRelease.fForce = fForce;
2155 lpiFilesetRW->GetFilesetID (&wp.wpVosVolumeRelease.idVolume);
2158 rc = Worker_DoTask (wtaskVosVolumeRelease, &wp, &status);
2167 if ((lpCell = lpiFilesetRW->OpenCell (&status)) == NULL)
2171 lpCell->Invalidate();
2172 rc = lpCell->RefreshAll (&status);
2179 if ((lpServer = lpiFilesetRW->OpenServer (&status)) != NULL)
2181 lpServer->CloseVosObject();
2186 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetEnd, lpiFilesetRW, status);
2195 BOOL AfsClass_GetFileDates (LPIDENT lpiServer, LPTSTR pszFilename, SYSTEMTIME *pstFile, SYSTEMTIME *pstBAK, SYSTEMTIME *pstOLD, ULONG *pStatus)
2201 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesBegin, lpiServer, pszFilename, 0);
2206 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2210 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2218 wp.wpBosExecutableTimestampGet.hServer = hBOS;
2219 wp.wpBosExecutableTimestampGet.pszFilename = pszFilename;
2222 if ((rc = Worker_DoTask (wtaskBosExecutableTimestampGet, &wp, &status)) == TRUE)
2224 *pstFile = wp.wpBosExecutableTimestampGet.timeNew;
2225 *pstBAK = wp.wpBosExecutableTimestampGet.timeBak;
2226 *pstOLD = wp.wpBosExecutableTimestampGet.timeOld;
2232 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2234 lpServer->CloseBosObject();
2238 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesEnd, lpiServer, pszFilename, status);
2247 BOOL AfsClass_ExecuteCommand (LPIDENT lpiServer, LPTSTR pszCommand, ULONG *pStatus)
2253 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandBegin, lpiServer, pszCommand, 0);
2258 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2262 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2270 wp.wpBosCommandExecute.hServer = hBOS;
2271 wp.wpBosCommandExecute.pszCommand = pszCommand;
2274 rc = Worker_DoTask (wtaskBosCommandExecute, &wp, &status);
2278 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2280 lpServer->CloseBosObject();
2284 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandEnd, lpiServer, pszCommand, status);
2293 LPADMINLIST AfsClass_AdminList_Load (LPIDENT lpiServer, ULONG *pStatus)
2297 LPADMINLIST lpList = NULL;
2300 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadBegin, lpiServer);
2305 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2309 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2316 lpList = New(ADMINLIST);
2317 memset (lpList, 0x00, sizeof(ADMINLIST));
2319 lpList->lpiServer = lpiServer;
2321 WORKERPACKET wpBegin;
2322 wpBegin.wpBosAdminGetBegin.hServer = hBOS;
2323 if (!Worker_DoTask (wtaskBosAdminGetBegin, &wpBegin, &status))
2329 TCHAR szAdmin[ cchNAME ];
2331 WORKERPACKET wpNext;
2332 wpNext.wpBosAdminGetNext.hEnum = wpBegin.wpBosAdminGetBegin.hEnum;
2333 wpNext.wpBosAdminGetNext.pszAdmin = szAdmin;
2335 if (!Worker_DoTask (wtaskBosAdminGetNext, &wpNext, &status))
2337 if (status == ADMITERATORDONE)
2345 if ((iAdded = AfsClass_AdminList_AddEntry (lpList, szAdmin)) != (size_t)-1)
2347 lpList->aEntries[ iAdded ].fAdded = FALSE;
2351 WORKERPACKET wpDone;
2352 wpDone.wpBosAdminGetDone.hEnum = wpBegin.wpBosAdminGetBegin.hEnum;
2353 Worker_DoTask (wtaskBosAdminGetDone, &wpDone);
2357 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2359 lpServer->CloseBosObject();
2363 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadEnd, lpiServer, status);
2368 return (rc) ? lpList : NULL;
2372 LPADMINLIST AfsClass_AdminList_Copy (LPADMINLIST lpOld)
2374 LPADMINLIST lpNew = NULL;
2378 lpNew = New(ADMINLIST);
2379 memcpy (lpNew, lpOld, sizeof(ADMINLIST));
2382 lpNew->aEntries = 0;
2383 lpNew->cEntries = 0;
2385 if (REALLOC (lpNew->aEntries, lpNew->cEntries, lpOld->cEntries, cREALLOC_ADMINLISTENTRIES))
2387 size_t cb = lpOld->cEntries * sizeof(ADMINLISTENTRY);
2388 memcpy (lpNew->aEntries, lpOld->aEntries, cb);
2396 BOOL AfsClass_AdminList_Save (LPADMINLIST lpList, ULONG *pStatus)
2402 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveBegin, lpList->lpiServer);
2407 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
2411 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2418 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2420 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2423 // are we supposed to add this entry?
2425 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
2428 wp.wpBosAdminCreate.hServer = hBOS;
2429 wp.wpBosAdminCreate.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2432 if (!Worker_DoTask (wtaskBosAdminCreate, &wp, &thisstatus))
2435 status = thisstatus;
2439 lpList->aEntries[ iEntry ].fAdded = FALSE;
2443 // are we supposed to delete this entry?
2445 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
2448 wp.wpBosAdminDelete.hServer = hBOS;
2449 wp.wpBosAdminDelete.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2452 if (!Worker_DoTask (wtaskBosAdminDelete, &wp, &thisstatus))
2455 status = thisstatus;
2459 lpList->aEntries[ iEntry ].szAdmin[0] = TEXT('\0');
2460 lpList->aEntries[ iEntry ].fDeleted = FALSE;
2466 if ((lpServer = lpList->lpiServer->OpenServer (&status)) != NULL)
2468 lpServer->CloseBosObject();
2472 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveEnd, lpList->lpiServer, status);
2481 void AfsClass_AdminList_Free (LPADMINLIST lpList)
2483 if (lpList && !InterlockedDecrement (&lpList->cRef))
2485 if (lpList->aEntries)
2486 Free (lpList->aEntries);
2487 memset (lpList, 0x00, sizeof(ADMINLIST));
2493 size_t AfsClass_AdminList_AddEntry (LPADMINLIST lpList, LPTSTR pszAdmin)
2495 size_t iAdded = (size_t)-1;
2500 for (iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2502 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2505 if (iEntry >= lpList->cEntries)
2507 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_ADMINLISTENTRIES);
2509 if (iEntry < lpList->cEntries)
2512 lstrcpy (lpList->aEntries[ iAdded ].szAdmin, pszAdmin);
2513 lpList->aEntries[ iAdded ].fAdded = TRUE;
2514 lpList->aEntries[ iAdded ].fDeleted = FALSE;
2522 BOOL AfsClass_AdminList_DelEntry (LPADMINLIST lpList, size_t iIndex)
2527 (iIndex < lpList->cEntries) &&
2528 (lpList->aEntries[ iIndex ].szAdmin[0]) &&
2529 (!lpList->aEntries[ iIndex ].fDeleted) )
2531 if (lpList->aEntries[ iIndex ].fAdded)
2532 lpList->aEntries[ iIndex ].szAdmin[0] = TEXT('\0');
2534 lpList->aEntries[ iIndex ].fDeleted = TRUE;
2543 LPKEYLIST AfsClass_KeyList_Load (LPIDENT lpiServer, ULONG *pStatus)
2547 LPKEYLIST lpList = NULL;
2550 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadBegin, lpiServer);
2555 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2559 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2566 lpList = New(KEYLIST);
2567 memset (lpList, 0x00, sizeof(KEYLIST));
2568 lpList->lpiServer = lpiServer;
2570 WORKERPACKET wpBegin;
2571 wpBegin.wpBosKeyGetBegin.hServer = hBOS;
2572 if (!Worker_DoTask (wtaskBosKeyGetBegin, &wpBegin, &status))
2576 for (size_t iEnum = 0; ; ++iEnum)
2578 WORKERPACKET wpNext;
2579 wpNext.wpBosKeyGetNext.hEnum = wpBegin.wpBosKeyGetBegin.hEnum;
2581 if (!Worker_DoTask (wtaskBosKeyGetNext, &wpNext, &status))
2583 if (status == ADMITERATORDONE)
2590 if (REALLOC (lpList->aKeys, lpList->cKeys, 1+iEnum, cREALLOC_SERVERKEYS))
2592 lpList->aKeys[ iEnum ].keyVersion = wpNext.wpBosKeyGetNext.keyVersion;
2593 memcpy (&lpList->aKeys[ iEnum ].keyData, &wpNext.wpBosKeyGetNext.keyData, sizeof(ENCRYPTIONKEY));
2594 memcpy (&lpList->aKeys[ iEnum ].keyInfo, &wpNext.wpBosKeyGetNext.keyInfo, sizeof(ENCRYPTIONKEYINFO));
2598 WORKERPACKET wpDone;
2599 wpDone.wpBosKeyGetDone.hEnum = wpBegin.wpBosKeyGetBegin.hEnum;
2600 Worker_DoTask (wtaskBosKeyGetDone, &wpDone);
2604 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2606 lpServer->CloseBosObject();
2610 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadEnd, lpiServer, status);
2615 return (rc) ? lpList : NULL;
2619 void AfsClass_KeyList_Free (LPKEYLIST lpList)
2624 Free (lpList->aKeys);
2625 memset (lpList, 0x00, sizeof(KEYLIST));
2631 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPTSTR pszString, ULONG *pStatus)
2636 TCHAR szCell[ cchNAME ];
2637 lpiServer->GetCellName (szCell);
2640 wp.wpKasStringToKey.pszCell = szCell;
2641 wp.wpKasStringToKey.pszString = pszString;
2642 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
2646 else if (!AfsClass_AddKey (lpiServer, keyVersion, &wp.wpKasStringToKey.key, &status))
2657 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2665 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2669 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2677 wp.wpBosKeyCreate.hServer = hBOS;
2678 wp.wpBosKeyCreate.keyVersion = keyVersion;
2679 memcpy (&wp.wpBosKeyCreate.key, pKey, sizeof(ENCRYPTIONKEY));
2680 rc = Worker_DoTask (wtaskBosKeyCreate, &wp, &status);
2683 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2685 lpServer->CloseBosObject();
2695 BOOL AfsClass_DeleteKey (LPIDENT lpiServer, int keyVersion, ULONG *pStatus)
2703 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2707 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2715 wp.wpBosKeyDelete.hServer = hBOS;
2716 wp.wpBosKeyDelete.keyVersion = keyVersion;
2717 rc = Worker_DoTask (wtaskBosKeyDelete, &wp, &status);
2720 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2722 lpServer->CloseBosObject();
2732 BOOL AfsClass_GetRandomKey (LPIDENT lpi, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2740 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2744 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2747 hKAS = lpCell->GetKasObject (&status);
2754 wp.wpKasServerRandomKeyGet.hCell = hCell;
2755 wp.wpKasServerRandomKeyGet.hServer = hKAS;
2756 rc = Worker_DoTask (wtaskKasServerRandomKeyGet, &wp, &status);
2759 memcpy (pKey, &wp.wpKasServerRandomKeyGet.key, sizeof(ENCRYPTIONKEY));
2768 BOOL AfsClass_Clone (LPIDENT lpiRW, ULONG *pStatus)
2774 NOTIFYCALLBACK::SendNotificationToAll (evtCloneBegin, lpiRW, 0);
2780 if ((lpCell = lpiRW->OpenCell (&status)) == NULL)
2784 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2789 // Perform the actual operation
2794 wp.wpVosBackupVolumeCreate.hCell = hCell;
2795 lpiRW->GetFilesetID (&wp.wpVosBackupVolumeCreate.idVolume);
2798 rc = Worker_DoTask (wtaskVosBackupVolumeCreate, &wp, &status);
2807 if ((lpServer = lpiRW->OpenServer (&status)) == NULL)
2811 lpServer->Invalidate();
2812 rc = lpServer->RefreshAll (&status);
2817 NOTIFYCALLBACK::SendNotificationToAll (evtCloneEnd, lpiRW, status);
2826 BOOL AfsClass_CloneMultiple (LPIDENT lpi, LPTSTR pszPrefix, BOOL fExclude, ULONG *pStatus)
2832 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleBegin, lpi);
2838 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2842 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2847 // Obtain hServer if appropriate
2850 if (!lpi->fIsCell())
2853 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2857 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
2863 // If requested, obtain the appropriate aggregate ID
2865 int idPartition = NO_PARTITION;
2866 if (rc && (lpi->fIsFileset() || lpi->fIsAggregate()))
2868 LPAGGREGATE lpAggregate;
2869 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2873 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
2875 lpAggregate->Close();
2879 // Perform the actual operation
2884 wp.wpVosBackupVolumeCreateMultiple.hCell = hCell;
2885 wp.wpVosBackupVolumeCreateMultiple.hServer = hVOS;
2886 wp.wpVosBackupVolumeCreateMultiple.idPartition = idPartition;
2887 wp.wpVosBackupVolumeCreateMultiple.pszPrefix = pszPrefix;
2888 wp.wpVosBackupVolumeCreateMultiple.fExclude = fExclude;
2891 rc = Worker_DoTask (wtaskVosBackupVolumeCreateMultiple, &wp, &status);
2902 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2906 lpCell->Invalidate();
2907 rc = lpCell->RefreshAll (&status);
2914 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2918 lpServer->Invalidate();
2919 rc = lpServer->RefreshAll (&status);
2928 if ((lpServer = lpi->OpenServer (&status)) != NULL)
2930 lpServer->CloseVosObject();
2935 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleEnd, lpi, status);
2944 BOOL AfsClass_DumpFileset (LPIDENT lpi, LPTSTR pszFilename, LPSYSTEMTIME pstDate, ULONG *pStatus)
2950 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetBegin, lpi, pszFilename, 0);
2952 // Obtain hCell and hVOS
2957 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2961 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2966 // Obtain idPartition
2969 LPAGGREGATE lpAggregate;
2970 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2974 idPartition = lpAggregate->GetID();
2975 lpAggregate->Close();
2978 // Perform the actual operation
2983 wp.wpVosVolumeDump.hCell = hCell;
2984 wp.wpVosVolumeDump.hServer = hVOS;
2985 wp.wpVosVolumeDump.pszFilename = pszFilename;
2986 wp.wpVosVolumeDump.idPartition = idPartition;
2987 lpi->GetFilesetID (&wp.wpVosVolumeDump.idVolume);
2990 memcpy (&wp.wpVosVolumeDump.stStart, pstDate, sizeof(SYSTEMTIME));
2992 memset (&wp.wpVosVolumeDump.stStart, 0x00, sizeof(SYSTEMTIME));
2995 rc = Worker_DoTask (wtaskVosVolumeDump, &wp, &status);
2999 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetEnd, lpi, pszFilename, status);
3005 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3007 lpServer->CloseVosObject();
3018 BOOL AfsClass_RestoreFileset (LPIDENT lpi, LPTSTR pszFileset, LPTSTR pszFilename, BOOL fIncremental, ULONG *pStatus)
3024 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetBegin, lpi, NULL, pszFileset, pszFilename, 0, 0);
3026 // Obtain hCell and hVOS
3031 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3035 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
3040 // Obtain idPartition
3043 LPAGGREGATE lpAggregate;
3044 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
3048 idPartition = lpAggregate->GetID();
3049 lpAggregate->Close();
3052 // Perform the actual operation
3057 wp.wpVosVolumeRestore.hCell = hCell;
3058 wp.wpVosVolumeRestore.hServer = hVOS;
3059 wp.wpVosVolumeRestore.idPartition = idPartition;
3060 wp.wpVosVolumeRestore.pszVolume = pszFileset;
3061 wp.wpVosVolumeRestore.pszFilename = pszFilename;
3062 wp.wpVosVolumeRestore.fIncremental = fIncremental;
3064 if (lpi->fIsFileset())
3065 lpi->GetFilesetID (&wp.wpVosVolumeRestore.idVolume);
3067 wp.wpVosVolumeRestore.idVolume = NO_VOLUME;
3070 rc = Worker_DoTask (wtaskVosVolumeRestore, &wp, &status);
3078 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3082 lpServer->Invalidate();
3083 rc = lpServer->RefreshAll (&status);
3090 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3092 lpServer->CloseVosObject();
3097 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetEnd, lpi, NULL, pszFileset, pszFilename, 0, status);
3106 BOOL AfsClass_GetRestartTimes (LPIDENT lpiServer, BOOL *pfWeekly, LPSYSTEMTIME pstWeekly, BOOL *pfDaily, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3112 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesBegin, lpiServer);
3117 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3121 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3129 wp.wpBosExecutableRestartTimeGet.hServer = hBOS;
3132 rc = Worker_DoTask (wtaskBosExecutableRestartTimeGet, &wp, &status);
3137 *pfWeekly = wp.wpBosExecutableRestartTimeGet.fWeeklyRestart;
3138 *pstWeekly = wp.wpBosExecutableRestartTimeGet.timeWeekly;
3139 *pfDaily = wp.wpBosExecutableRestartTimeGet.fDailyRestart;
3140 *pstDaily = wp.wpBosExecutableRestartTimeGet.timeDaily;
3144 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3146 lpServer->CloseBosObject();
3150 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesEnd, lpiServer, status);
3159 BOOL AfsClass_SetRestartTimes (LPIDENT lpiServer, LPSYSTEMTIME pstWeekly, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3165 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesBegin, lpiServer);
3170 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3174 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3181 SYSTEMTIME timeNever;
3182 memset (&timeNever, 0x00, sizeof(SYSTEMTIME));
3185 wp.wpBosExecutableRestartTimeSet.hServer = hBOS;
3186 wp.wpBosExecutableRestartTimeSet.fWeeklyRestart = (pstWeekly != NULL) ? TRUE : FALSE;
3187 wp.wpBosExecutableRestartTimeSet.timeWeekly = (pstWeekly != NULL) ? *pstWeekly : timeNever;
3188 wp.wpBosExecutableRestartTimeSet.fDailyRestart = (pstDaily != NULL) ? TRUE : FALSE;
3189 wp.wpBosExecutableRestartTimeSet.timeDaily = (pstDaily != NULL) ? *pstDaily : timeNever;
3192 rc = Worker_DoTask (wtaskBosExecutableRestartTimeSet, &wp, &status);
3196 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3198 lpServer->CloseBosObject();
3202 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesEnd, lpiServer, status);
3211 BOOL AfsClass_MoveReplica (LPIDENT lpiReplica, LPIDENT lpiAggregateTarget, ULONG *pStatus)
3215 // Find the identifier for this replica's read/write fileset.
3217 LPIDENT lpiFilesetRW = NULL;
3218 LPFILESET lpFileset;
3219 if ((lpFileset = lpiReplica->OpenFileset (pStatus)) == NULL)
3223 if ((lpiFilesetRW = lpFileset->GetReadWriteIdentifier (pStatus)) == NULL)
3228 // If the fileset replica currently resides on the same server
3229 // as the target aggregate, we'll follow the following steps:
3231 // 1. Delete the old fileset replica -> on error, quit
3232 // 2. Create the new fileset replica -> on error, recreate old replica, quit
3234 // If the fileset replica instead currently resides on a different
3235 // server, we can follow the preferred steps:
3237 // 1. Create the new fileset replica -> on error, quit
3238 // 2. Delete the old fileset replica -> on error, delete the new replica, quit
3242 LPIDENT lpiReplicaNew;
3244 if (lpiReplica->GetServer() == lpiAggregateTarget->GetServer())
3246 LPIDENT lpiAggregateOriginal = lpiReplica->GetAggregate();
3248 if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3252 else if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3254 (void)AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateOriginal);
3258 else // different server?
3260 if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3264 else if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3266 (void)AfsClass_DeleteReplica (lpiReplicaNew, pStatus);
3276 BOOL AfsClass_Salvage (LPIDENT lpiSalvage, LPTSTR *ppszLogData, int nProcesses, LPTSTR pszTempDir, LPTSTR pszLogFile, BOOL fForce, BOOL fReadonly, BOOL fLogInodes, BOOL fLogRootInodes, BOOL fRebuildDirs, BOOL fReadBlocks, ULONG *pStatus)
3282 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageBegin, lpiSalvage);
3287 if ((lpServer = lpiSalvage->OpenServer (&status)) == NULL)
3291 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3297 *ppszLogData = NULL;
3299 // Step one: perform the actual salvage. This will dump a log file onto
3300 // the target computer.
3304 LPTSTR pszAggregate = NULL;
3305 TCHAR szAggregate[ cchNAME ];
3306 if (lpiSalvage->fIsAggregate() || lpiSalvage->fIsFileset())
3308 lpiSalvage->GetAggregateName (szAggregate);
3309 pszAggregate = szAggregate;
3312 LPTSTR pszFileset = NULL;
3313 TCHAR szFileset[ cchNAME ];
3314 if (lpiSalvage->fIsFileset())
3317 lpiSalvage->GetFilesetID (&vid);
3318 wsprintf (szFileset, TEXT("%lu"), vid);
3319 pszFileset = szFileset;
3322 if (pszLogFile == NULL)
3323 pszLogFile = TEXT("SalvageLog");
3326 wp.wpBosSalvage.hCell = hCell;
3327 wp.wpBosSalvage.hServer = hBOS;
3328 wp.wpBosSalvage.pszAggregate = pszAggregate;
3329 wp.wpBosSalvage.pszFileset = pszFileset;
3330 wp.wpBosSalvage.nProcesses = nProcesses;
3331 wp.wpBosSalvage.pszTempDir = pszTempDir;
3332 wp.wpBosSalvage.pszLogFile = pszLogFile;
3333 wp.wpBosSalvage.fForce = fForce;
3334 wp.wpBosSalvage.fReadonly = fReadonly;
3335 wp.wpBosSalvage.fLogInodes = fLogInodes;
3336 wp.wpBosSalvage.fLogRootInodes = fLogRootInodes;
3337 wp.wpBosSalvage.fRebuildDirs = fRebuildDirs;
3338 wp.wpBosSalvage.fReadBlocks = fReadBlocks;
3341 rc = Worker_DoTask (wtaskBosSalvage, &wp, &status);
3345 // Step two: retrieve the log file from that salvage operation.
3346 // If we can't get the log file back, that's not fatal--just return
3347 // a NULL pointer for the log data.
3349 if (rc && ppszLogData)
3352 wp.wpBosLogGet.hServer = hBOS;
3353 wp.wpBosLogGet.pszLogName = pszLogFile;
3354 wp.wpBosLogGet.pszLogData = NULL;
3357 if ((rc = Worker_DoTask (wtaskBosLogGet, &wp, &status)) == TRUE)
3359 // Okay, well, we have the log in memory now. Problem is,
3360 // it has UNIX-style CR's... and so is missing the LF which
3361 // PCs expect before each CR. Wow--look at all the
3362 // acronyms! Count the CRs, alloc a larger buffer, and stuff
3363 // in the LFs before each CR.
3365 size_t cchRequired = 1;
3366 for (LPTSTR pchIn = wp.wpBosLogGet.pszLogData; *pchIn; ++pchIn)
3368 cchRequired += (*pchIn == TEXT('\r')) ? 0 : (*pchIn == TEXT('\n')) ? 2 : 1;
3371 if ((*ppszLogData = AllocateString (cchRequired)) != NULL)
3373 LPTSTR pszOut = *ppszLogData;
3374 for (LPTSTR pchIn = wp.wpBosLogGet.pszLogData; *pchIn; ++pchIn)
3376 if (*pchIn == TEXT('\n'))
3377 *pszOut++ = TEXT('\r');
3378 if (*pchIn != TEXT('\r'))
3381 *pszOut++ = TEXT('\0');
3387 if ((lpServer = lpiSalvage->OpenServer (&status)) != NULL)
3389 lpServer->CloseBosObject();
3393 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageEnd, lpiSalvage, status);
3402 void AfsClass_FreeSalvageLog (LPTSTR pszLogData)
3409 LPHOSTLIST AfsClass_HostList_Load (LPIDENT lpiServer, ULONG *pStatus)
3413 LPHOSTLIST lpList = NULL;
3416 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadBegin, lpiServer);
3421 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3425 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3432 lpList = New(HOSTLIST);
3433 memset (lpList, 0x00, sizeof(HOSTLIST));
3435 lpList->lpiServer = lpiServer;
3437 WORKERPACKET wpBegin;
3438 wpBegin.wpBosHostGetBegin.hServer = hBOS;
3439 if (!Worker_DoTask (wtaskBosHostGetBegin, &wpBegin, &status))
3445 TCHAR szHost[ cchNAME ];
3447 WORKERPACKET wpNext;
3448 wpNext.wpBosHostGetNext.hEnum = wpBegin.wpBosHostGetBegin.hEnum;
3449 wpNext.wpBosHostGetNext.pszServer = szHost;
3451 if (!Worker_DoTask (wtaskBosHostGetNext, &wpNext, &status))
3453 if (status == ADMITERATORDONE)
3461 if ((iAdded = AfsClass_HostList_AddEntry (lpList, szHost)) != (size_t)-1)
3463 lpList->aEntries[ iAdded ].fAdded = FALSE;
3467 WORKERPACKET wpDone;
3468 wpDone.wpBosHostGetDone.hEnum = wpBegin.wpBosHostGetBegin.hEnum;
3469 Worker_DoTask (wtaskBosHostGetDone, &wpDone);
3473 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3475 lpServer->CloseBosObject();
3479 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadEnd, lpiServer, status);
3484 return (rc) ? lpList : NULL;
3488 LPHOSTLIST AfsClass_HostList_Copy (LPHOSTLIST lpOld)
3490 LPHOSTLIST lpNew = NULL;
3494 lpNew = New(HOSTLIST);
3495 memcpy (lpNew, lpOld, sizeof(HOSTLIST));
3498 lpNew->aEntries = 0;
3499 lpNew->cEntries = 0;
3501 if (REALLOC (lpNew->aEntries, lpNew->cEntries, lpOld->cEntries, cREALLOC_HOSTLISTENTRIES))
3503 size_t cb = lpOld->cEntries * sizeof(HOSTLISTENTRY);
3504 memcpy (lpNew->aEntries, lpOld->aEntries, cb);
3512 BOOL AfsClass_HostList_Save (LPHOSTLIST lpList, ULONG *pStatus)
3518 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveBegin, lpList->lpiServer);
3523 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
3527 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3534 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3536 if (!lpList->aEntries[ iEntry ].szHost[0])
3539 // are we supposed to add this entry?
3541 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
3544 wp.wpBosHostCreate.hServer = hBOS;
3545 wp.wpBosHostCreate.pszServer = lpList->aEntries[ iEntry ].szHost;
3548 if (!Worker_DoTask (wtaskBosHostCreate, &wp, &thisstatus))
3551 status = thisstatus;
3555 lpList->aEntries[ iEntry ].fAdded = FALSE;
3559 // are we supposed to delete this entry?
3561 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
3564 wp.wpBosHostDelete.hServer = hBOS;
3565 wp.wpBosHostDelete.pszServer = lpList->aEntries[ iEntry ].szHost;
3568 if (!Worker_DoTask (wtaskBosHostDelete, &wp, &thisstatus))
3571 status = thisstatus;
3575 lpList->aEntries[ iEntry ].szHost[0] = TEXT('\0');
3576 lpList->aEntries[ iEntry ].fDeleted = FALSE;
3582 if ((lpServer = lpList->lpiServer->OpenServer (&status)) != NULL)
3584 lpServer->CloseBosObject();
3588 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveEnd, lpList->lpiServer, status);
3597 void AfsClass_HostList_Free (LPHOSTLIST lpList)
3599 if (lpList && !InterlockedDecrement (&lpList->cRef))
3601 if (lpList->aEntries)
3602 Free (lpList->aEntries);
3603 memset (lpList, 0x00, sizeof(HOSTLIST));
3609 size_t AfsClass_HostList_AddEntry (LPHOSTLIST lpList, LPTSTR pszHost)
3611 size_t iAdded = (size_t)-1;
3616 for (iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3618 if (!lpList->aEntries[ iEntry ].szHost[0])
3621 if (iEntry >= lpList->cEntries)
3623 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_HOSTLISTENTRIES);
3625 if (iEntry < lpList->cEntries)
3628 lstrcpy (lpList->aEntries[ iAdded ].szHost, pszHost);
3629 lpList->aEntries[ iAdded ].fAdded = TRUE;
3630 lpList->aEntries[ iAdded ].fDeleted = FALSE;
3638 BOOL AfsClass_HostList_DelEntry (LPHOSTLIST lpList, size_t iIndex)
3643 (iIndex < lpList->cEntries) &&
3644 (lpList->aEntries[ iIndex ].szHost[0]) &&
3645 (!lpList->aEntries[ iIndex ].fDeleted) )
3647 if (lpList->aEntries[ iIndex ].fAdded)
3648 lpList->aEntries[ iIndex ].szHost[0] = TEXT('\0');
3650 lpList->aEntries[ iIndex ].fDeleted = TRUE;
3659 BOOL AfsClass_GetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3664 memset (pProperties, 0x00, sizeof(PTSPROPERTIES));
3670 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3674 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3679 // Go get the necessary properties
3684 wp.wpPtsUserMaxGet.hCell = hCell;
3686 if ((rc = Worker_DoTask (wtaskPtsUserMaxGet, &wp, &status)) == TRUE)
3687 pProperties->idUserMax = wp.wpPtsUserMaxGet.idUserMax;
3693 wp.wpPtsGroupMaxGet.hCell = hCell;
3695 if ((rc = Worker_DoTask (wtaskPtsGroupMaxGet, &wp, &status)) == TRUE)
3696 pProperties->idGroupMax = wp.wpPtsGroupMaxGet.idGroupMax;
3705 BOOL AfsClass_SetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3714 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3718 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3723 // Modify the specified properties
3728 wp.wpPtsUserMaxSet.hCell = hCell;
3729 wp.wpPtsUserMaxSet.idUserMax = pProperties->idUserMax;
3730 rc = Worker_DoTask (wtaskPtsUserMaxSet, &wp, &status);
3736 wp.wpPtsGroupMaxSet.hCell = hCell;
3737 wp.wpPtsGroupMaxSet.idGroupMax = pProperties->idGroupMax;
3738 Worker_DoTask (wtaskPtsGroupMaxSet, &wp, &status);
3747 LPIDENT AfsClass_CreateUser (LPIDENT lpiCell, LPTSTR pszUserName, LPTSTR pszInstance, LPTSTR pszPassword, int idUser, BOOL fCreateKAS, BOOL fCreatePTS, ULONG *pStatus)
3752 if (pszInstance && !*pszInstance)
3756 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserBegin, lpiCell, pszUserName, 0);
3758 // We'll need both hCell and hKAS.
3763 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3767 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3770 hKAS = lpCell->GetKasObject (&status);
3774 // First try to create a KAS entry.
3776 if (rc && fCreateKAS)
3779 wp.wpKasPrincipalCreate.hCell = hCell;
3780 wp.wpKasPrincipalCreate.hServer = hKAS;
3781 wp.wpKasPrincipalCreate.pszPrincipal = pszUserName;
3782 wp.wpKasPrincipalCreate.pszInstance = pszInstance;
3783 wp.wpKasPrincipalCreate.pszPassword = pszPassword;
3786 rc = Worker_DoTask (wtaskKasPrincipalCreate, &wp, &status);
3790 // If that succeeded, try to create a PTS entry as well.
3792 if (rc && fCreatePTS)
3794 TCHAR szUserName[ cchNAME ];
3795 lstrcpy (szUserName, pszUserName);
3797 wsprintf (&szUserName[ lstrlen(szUserName) ], TEXT(".%s"), pszInstance);
3800 wp.wpPtsUserCreate.hCell = hCell;
3801 wp.wpPtsUserCreate.pszUser = szUserName;
3802 wp.wpPtsUserCreate.idUser = idUser;
3806 if ((rc = Worker_DoTask (wtaskPtsUserCreate, &wp, &status)) == FALSE)
3808 if (status == PREXIST)
3814 // If we couldn't make a KAS entry as well, remove the KAS entry.
3819 wpDel.wpKasPrincipalDelete.hCell = hCell;
3820 wpDel.wpKasPrincipalDelete.hServer = hKAS;
3821 wpDel.wpKasPrincipalDelete.pszPrincipal = pszUserName;
3822 wpDel.wpKasPrincipalDelete.pszInstance = pszInstance;
3823 Worker_DoTask (wtaskKasPrincipalDelete, &wpDel);
3830 // If we were able to create the user's accounts successfully, refresh
3831 // the cell status and return the new user's ident.
3837 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3841 if (!lpCell->RefreshAccount (pszUserName, pszInstance, CELL_REFRESH_ACCOUNT_CREATED_USER, &lpiUser))
3849 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserEnd, lpiCell, pszUserName, status);
3854 return (rc) ? lpiUser : NULL;
3858 BOOL AfsClass_SetUserProperties (LPIDENT lpiUser, LPUSERPROPERTIES pProperties, ULONG *pStatus)
3864 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser);
3866 // We'll need both hCell and hKAS.
3871 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
3875 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3878 hKAS = lpCell->GetKasObject (&status);
3882 // We'll also need this user's current status
3886 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
3890 if (!lpUser->GetStatus (&us, TRUE, &status))
3895 // Modify the user's KAS entry (if necessary)
3897 DWORD dwKasMask = ( MASK_USERPROP_fAdmin |
3898 MASK_USERPROP_fGrantTickets |
3899 MASK_USERPROP_fCanEncrypt |
3900 MASK_USERPROP_fCanChangePassword |
3901 MASK_USERPROP_fCanReusePasswords |
3902 MASK_USERPROP_timeAccountExpires |
3903 MASK_USERPROP_cdayPwExpires |
3904 MASK_USERPROP_csecTicketLifetime |
3905 MASK_USERPROP_nFailureAttempts |
3906 MASK_USERPROP_csecFailedLoginLockTime );
3908 if (rc && (pProperties->dwMask & dwKasMask))
3910 TCHAR szPrincipal[ cchNAME ];
3911 TCHAR szInstance[ cchNAME ];
3912 lpiUser->GetUserName (szPrincipal, szInstance);
3915 wp.wpKasPrincipalFieldsSet.hCell = hCell;
3916 wp.wpKasPrincipalFieldsSet.hServer = hKAS;
3917 wp.wpKasPrincipalFieldsSet.pszPrincipal = szPrincipal;
3918 wp.wpKasPrincipalFieldsSet.pszInstance = szInstance;
3919 wp.wpKasPrincipalFieldsSet.fIsAdmin = (pProperties->dwMask & MASK_USERPROP_fAdmin) ? pProperties->fAdmin : us.KASINFO.fIsAdmin;
3920 wp.wpKasPrincipalFieldsSet.fGrantTickets = (pProperties->dwMask & MASK_USERPROP_fGrantTickets) ? pProperties->fGrantTickets : us.KASINFO.fCanGetTickets;
3921 wp.wpKasPrincipalFieldsSet.fCanEncrypt = (pProperties->dwMask & MASK_USERPROP_fCanEncrypt) ? pProperties->fCanEncrypt : us.KASINFO.fEncrypt;
3922 wp.wpKasPrincipalFieldsSet.fCanChangePassword = (pProperties->dwMask & MASK_USERPROP_fCanChangePassword) ? pProperties->fCanChangePassword : us.KASINFO.fCanChangePassword;
3923 wp.wpKasPrincipalFieldsSet.fCanReusePasswords = (pProperties->dwMask & MASK_USERPROP_fCanReusePasswords) ? pProperties->fCanReusePasswords : us.KASINFO.fCanReusePasswords;
3924 memcpy (&wp.wpKasPrincipalFieldsSet.timeExpires, (pProperties->dwMask & MASK_USERPROP_timeAccountExpires) ? &pProperties->timeAccountExpires : &us.KASINFO.timeExpires, sizeof(SYSTEMTIME));
3925 wp.wpKasPrincipalFieldsSet.cdayPwExpires = (pProperties->dwMask & MASK_USERPROP_cdayPwExpires) ? pProperties->cdayPwExpires : us.KASINFO.cdayPwExpire;
3926 wp.wpKasPrincipalFieldsSet.csecTicketLifetime = (pProperties->dwMask & MASK_USERPROP_csecTicketLifetime) ? pProperties->csecTicketLifetime : us.KASINFO.csecTicketLifetime;
3927 wp.wpKasPrincipalFieldsSet.nFailureAttempts = (pProperties->dwMask & MASK_USERPROP_nFailureAttempts) ? pProperties->nFailureAttempts : us.KASINFO.cFailLogin;
3928 wp.wpKasPrincipalFieldsSet.csecFailedLoginLockTime = (pProperties->dwMask & MASK_USERPROP_csecFailedLoginLockTime) ? pProperties->csecFailedLoginLockTime : us.KASINFO.csecFailLoginLock;
3931 rc = Worker_DoTask (wtaskKasPrincipalFieldsSet, &wp, &status);
3936 // Modify the user's PTS entry (if necessary)
3938 DWORD dwPtsMask = ( MASK_USERPROP_cGroupCreationQuota |
3939 MASK_USERPROP_aaListStatus |
3940 MASK_USERPROP_aaGroupsOwned |
3941 MASK_USERPROP_aaMembership );
3943 if (rc && (pProperties->dwMask & dwPtsMask))
3945 TCHAR szFullName[ cchNAME ];
3946 lpiUser->GetFullUserName (szFullName);
3949 wp.wpPtsUserModify.hCell = hCell;
3950 wp.wpPtsUserModify.pszUser = szFullName;
3951 memset (&wp.wpPtsUserModify.Delta, 0x00, sizeof(wp.wpPtsUserModify.Delta));
3953 if (pProperties->dwMask & MASK_USERPROP_cGroupCreationQuota)
3955 wp.wpPtsUserModify.Delta.flag = (pts_UserUpdateFlag_t)( (LONG)wp.wpPtsUserModify.Delta.flag | (LONG)PTS_USER_UPDATE_GROUP_CREATE_QUOTA );
3956 wp.wpPtsUserModify.Delta.groupCreationQuota = pProperties->cGroupCreationQuota;
3959 if (pProperties->dwMask & (MASK_USERPROP_aaListStatus | MASK_USERPROP_aaGroupsOwned | MASK_USERPROP_aaMembership))
3961 wp.wpPtsUserModify.Delta.flag = (pts_UserUpdateFlag_t)( (LONG)wp.wpPtsUserModify.Delta.flag | (LONG)PTS_USER_UPDATE_PERMISSIONS );
3962 wp.wpPtsUserModify.Delta.listStatus = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaListStatus) ? pProperties->aaListStatus : us.PTSINFO.aaListStatus );
3963 wp.wpPtsUserModify.Delta.listGroupsOwned = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaGroupsOwned) ? pProperties->aaGroupsOwned : us.PTSINFO.aaGroupsOwned );
3964 wp.wpPtsUserModify.Delta.listMembership = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaMembership) ? pProperties->aaMembership : us.PTSINFO.aaMembership );
3968 rc = Worker_DoTask (wtaskPtsUserModify, &wp, &status);
3972 // If we were able to modify the user's properties successfully, refresh
3973 // that user's status.
3975 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
3977 lpUser->Invalidate();
3978 lpUser->RefreshStatus();
3982 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser, status);
3991 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPTSTR pszPassword, ULONG *pStatus)
3996 TCHAR szCell[ cchNAME ];
3997 lpiUser->GetCellName (szCell);
4000 wp.wpKasStringToKey.pszCell = szCell;
4001 wp.wpKasStringToKey.pszString = pszPassword;
4002 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
4006 else if (!AfsClass_SetUserPassword (lpiUser, keyVersion, &wp.wpKasStringToKey.key, &status))
4017 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
4023 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordBegin, lpiUser);
4025 // We'll need both hCell and hKAS.
4030 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4034 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4037 hKAS = lpCell->GetKasObject (&status);
4041 // Change the user's password
4045 TCHAR szPrincipal[ cchNAME ];
4046 TCHAR szInstance[ cchNAME ];
4047 lpiUser->GetUserName (szPrincipal, szInstance);
4050 wp.wpKasPrincipalKeySet.hCell = hCell;
4051 wp.wpKasPrincipalKeySet.hServer = hKAS;
4052 wp.wpKasPrincipalKeySet.pszPrincipal = szPrincipal;
4053 wp.wpKasPrincipalKeySet.pszInstance = szInstance;
4054 wp.wpKasPrincipalKeySet.keyVersion = keyVersion;
4055 memcpy (&wp.wpKasPrincipalKeySet.key.key, &pKey->key, ENCRYPTIONKEY_LEN);
4058 rc = Worker_DoTask (wtaskKasPrincipalKeySet, &wp, &status);
4062 // If we were able to modify the user's password successfully, refresh
4063 // that user's status.
4066 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4068 lpUser->Invalidate();
4069 lpUser->RefreshStatus();
4073 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordEnd, lpiUser, status);
4082 BOOL AfsClass_DeleteUser (LPIDENT lpiUser, BOOL fDeleteKAS, BOOL fDeletePTS, ULONG *pStatus)
4088 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserBegin, lpiUser);
4090 // We'll need both hCell and hKAS.
4095 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4099 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4102 hKAS = lpCell->GetKasObject (&status);
4106 // Find out whether this user has KAS and/or PTS entries. Also
4107 // get the various lists of groups for this user...
4110 LPTSTR mszOwnerOf = NULL;
4111 LPTSTR mszMemberOf = NULL;
4112 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
4116 lpUser->GetOwnerOf (&mszOwnerOf);
4117 lpUser->GetMemberOf (&mszMemberOf);
4121 // Delete the user's PTS entry
4123 if (rc && fDeletePTS)
4125 TCHAR szFullName[ cchNAME ];
4126 lpiUser->GetFullUserName (szFullName);
4129 wp.wpPtsUserDelete.hCell = hCell;
4130 wp.wpPtsUserDelete.pszUser = szFullName;
4133 if ((rc = Worker_DoTask (wtaskPtsUserDelete, &wp, &status)) == FALSE)
4135 if (status == ADMPTSFAILEDNAMETRANSLATE) // User had no PTS entry?
4141 // Delete the user's KAS entry
4143 if (rc && fDeleteKAS)
4145 TCHAR szPrincipal[ cchNAME ];
4146 TCHAR szInstance[ cchNAME ];
4147 lpiUser->GetUserName (szPrincipal, szInstance);
4150 wp.wpKasPrincipalDelete.hCell = hCell;
4151 wp.wpKasPrincipalDelete.hServer = hKAS;
4152 wp.wpKasPrincipalDelete.pszPrincipal = szPrincipal;
4153 wp.wpKasPrincipalDelete.pszInstance = szInstance;
4156 if ((rc = Worker_DoTask (wtaskKasPrincipalDelete, &wp, &status)) == FALSE)
4158 if (status == KANOENT)
4164 // If we were able to delete the user's accounts successfully, refresh
4169 if ((lpCell = lpiUser->OpenCell (&status)) != NULL)
4171 TCHAR szPrincipal[ cchNAME ];
4172 TCHAR szInstance[ cchNAME ];
4173 lpiUser->GetUserName (szPrincipal, szInstance);
4175 lpCell->RefreshAccount (szPrincipal, szInstance, CELL_REFRESH_ACCOUNT_DELETED);
4176 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4177 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4182 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserEnd, lpiUser, status);
4186 FreeString (mszOwnerOf);
4188 FreeString (mszMemberOf);
4195 BOOL AfsClass_UnlockUser (LPIDENT lpiUser, ULONG *pStatus)
4201 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserBegin, lpiUser);
4203 // We'll need both hCell and hKAS.
4208 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4212 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4215 hKAS = lpCell->GetKasObject (&status);
4219 // Unlock the user's KAS entry
4223 TCHAR szPrincipal[ cchNAME ];
4224 TCHAR szInstance[ cchNAME ];
4225 lpiUser->GetUserName (szPrincipal, szInstance);
4228 wp.wpKasPrincipalUnlock.hCell = hCell;
4229 wp.wpKasPrincipalUnlock.hServer = hKAS;
4230 wp.wpKasPrincipalUnlock.pszPrincipal = szPrincipal;
4231 wp.wpKasPrincipalUnlock.pszInstance = szInstance;
4234 rc = Worker_DoTask (wtaskKasPrincipalUnlock, &wp, &status);
4238 // If we were able to unlock the user's accounts successfully, refresh
4239 // the user's properties.
4244 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4246 lpUser->Invalidate();
4247 lpUser->RefreshStatus();
4252 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserEnd, lpiUser, status);
4261 LPIDENT AfsClass_CreateGroup (LPIDENT lpiCell, LPTSTR pszGroupName, LPIDENT lpiOwner, int idGroup, ULONG *pStatus)
4267 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupBegin, lpiCell, pszGroupName, 0);
4273 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4277 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4282 // Create a PTS entry for the new group
4286 TCHAR szOwner[ cchNAME ] = TEXT("");
4287 if (lpiOwner && lpiOwner->fIsUser())
4288 lpiOwner->GetFullUserName (szOwner);
4289 else if (lpiOwner && lpiOwner->fIsGroup())
4290 lpiOwner->GetGroupName (szOwner);
4293 wp.wpPtsGroupCreate.hCell = hCell;
4294 wp.wpPtsGroupCreate.pszGroup = pszGroupName;
4295 wp.wpPtsGroupCreate.pszOwner = (szOwner[0]) ? szOwner : NULL;
4296 wp.wpPtsGroupCreate.idGroup = idGroup;
4299 rc = Worker_DoTask (wtaskPtsGroupCreate, &wp, &status);
4303 // If we were able to create the group successfully, refresh
4304 // the cell status and return the new group's ident.
4310 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4314 if (!lpCell->RefreshAccount (pszGroupName, NULL, CELL_REFRESH_ACCOUNT_CREATED_GROUP, &lpiGroup))
4322 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupEnd, lpiCell, pszGroupName, status);
4327 return (rc) ? lpiGroup : NULL;
4331 BOOL AfsClass_SetGroupProperties (LPIDENT lpiGroup, LPGROUPPROPERTIES pProperties, ULONG *pStatus)
4337 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup);
4343 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4347 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4352 // We'll also need this group's current status
4356 if ((lpGroup = lpiGroup->OpenGroup (&status)) == NULL)
4360 if (!lpGroup->GetStatus (&gs, TRUE, &status))
4365 // Modify the group's PTS entry (if requested)
4367 DWORD dwPtsMask = ( MASK_GROUPPROP_aaListStatus |
4368 MASK_GROUPPROP_aaListGroupsOwned |
4369 MASK_GROUPPROP_aaListMembers |
4370 MASK_GROUPPROP_aaAddMember |
4371 MASK_GROUPPROP_aaDeleteMember );
4373 if (rc && (pProperties->dwMask & dwPtsMask))
4375 TCHAR szGroup[ cchNAME ];
4376 lpiGroup->GetGroupName (szGroup);
4379 wp.wpPtsGroupModify.hCell = hCell;
4380 wp.wpPtsGroupModify.pszGroup = szGroup;
4381 memset (&wp.wpPtsGroupModify.Delta, 0x00, sizeof(wp.wpPtsGroupModify.Delta));
4382 wp.wpPtsGroupModify.Delta.listStatus = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListStatus) ? pProperties->aaListStatus : gs.aaListStatus );
4383 wp.wpPtsGroupModify.Delta.listGroupsOwned = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListGroupsOwned) ? pProperties->aaListGroupsOwned : gs.aaListGroupsOwned );
4384 wp.wpPtsGroupModify.Delta.listMembership = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListMembers) ? pProperties->aaListMembers : gs.aaListMembers );
4385 wp.wpPtsGroupModify.Delta.listAdd = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaAddMember) ? pProperties->aaAddMember : gs.aaAddMember );
4386 wp.wpPtsGroupModify.Delta.listDelete = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaDeleteMember) ? pProperties->aaDeleteMember : gs.aaDeleteMember );
4389 rc = Worker_DoTask (wtaskPtsGroupModify, &wp, &status);
4393 // Change the group's owner (if requested)
4395 if (rc && (pProperties->dwMask & MASK_GROUPPROP_szOwner))
4397 TCHAR szGroup[ cchNAME ];
4398 lpiGroup->GetGroupName (szGroup);
4401 wp.wpPtsGroupOwnerChange.hCell = hCell;
4402 wp.wpPtsGroupOwnerChange.pszGroup = szGroup;
4403 wp.wpPtsGroupOwnerChange.pszOwner = pProperties->szOwner;
4406 rc = Worker_DoTask (wtaskPtsGroupOwnerChange, &wp, &status);
4410 // If we were able to modify the group's properties successfully, refresh
4411 // either the group's status. If the group's owner changed, also refresh
4412 // the group's old and new owners.
4416 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4418 TCHAR szAccount[ cchNAME ];
4419 lpiGroup->GetGroupName (szAccount);
4420 lpCell->RefreshAccount (szAccount, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4422 if (pProperties->dwMask & MASK_GROUPPROP_szOwner)
4424 lpCell->RefreshAccount (gs.szOwner, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4425 lpCell->RefreshAccount (pProperties->szOwner, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4432 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup, status);
4441 BOOL AfsClass_RenameGroup (LPIDENT lpiGroup, LPTSTR pszNewName, ULONG *pStatus)
4447 NOTIFYCALLBACK::SendNotificationToAll (evtRenameGroupBegin, lpiGroup);
4453 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4457 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4462 // Get this group's list of members (etc)
4464 LPTSTR mszOwnerOf = NULL;
4465 LPTSTR mszMemberOf = NULL;
4466 LPTSTR mszMembers = NULL;
4469 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4471 lpGroup->GetOwnerOf (&mszOwnerOf);
4472 lpGroup->GetMemberOf (&mszMemberOf);
4473 lpGroup->GetMembers (&mszMembers);
4477 // Rename the group's PTS entry
4481 TCHAR szGroup[ cchNAME ];
4482 lpiGroup->GetGroupName (szGroup);
4485 wp.wpPtsGroupRename.hCell = hCell;
4486 wp.wpPtsGroupRename.pszGroup = szGroup;
4487 wp.wpPtsGroupRename.pszNewName = pszNewName;
4490 rc = Worker_DoTask (wtaskPtsGroupRename, &wp, &status);
4494 // If we were able to rename the group successfully, refresh the cell status.
4499 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4501 lpGroup->ChangeIdentName (pszNewName);
4504 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4506 lpCell->RefreshAccount (pszNewName, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4507 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4508 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4509 lpCell->RefreshAccounts (mszMembers, CELL_REFRESH_ACCOUNT_CHANGED);
4514 NOTIFYCALLBACK::SendNotificationToAll (evtRenameGroupEnd, lpiGroup, status);
4518 FreeString (mszOwnerOf);
4520 FreeString (mszMemberOf);
4522 FreeString (mszMembers);
4529 BOOL AfsClass_DeleteGroup (LPIDENT lpiGroup, ULONG *pStatus)
4535 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteGroupBegin, lpiGroup);
4541 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4545 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4550 // Get this group's list of members (etc)
4552 LPTSTR mszOwnerOf = NULL;
4553 LPTSTR mszMemberOf = NULL;
4554 LPTSTR mszMembers = NULL;
4557 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4559 lpGroup->GetOwnerOf (&mszOwnerOf);
4560 lpGroup->GetMemberOf (&mszMemberOf);
4561 lpGroup->GetMembers (&mszMembers);
4565 // Delete the group's PTS entry
4569 TCHAR szGroup[ cchNAME ];
4570 lpiGroup->GetGroupName (szGroup);
4573 wp.wpPtsGroupDelete.hCell = hCell;
4574 wp.wpPtsGroupDelete.pszGroup = szGroup;
4577 if ((rc = Worker_DoTask (wtaskPtsGroupDelete, &wp, &status)) == FALSE)
4579 if (status == ADMPTSFAILEDNAMETRANSLATE) // Group had no PTS entry?
4585 // If we were able to delete the group successfully, refresh the cell status.
4589 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4591 TCHAR szGroup[ cchNAME ];
4592 lpiGroup->GetGroupName (szGroup);
4593 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4594 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4595 lpCell->RefreshAccounts (mszMembers, CELL_REFRESH_ACCOUNT_CHANGED);
4596 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_DELETED);
4601 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteGroupEnd, lpiGroup, status);
4605 FreeString (mszOwnerOf);
4607 FreeString (mszMemberOf);
4609 FreeString (mszMembers);
4616 BOOL AfsClass_AddUserToGroup (LPIDENT lpiGroup, LPIDENT lpiUser, ULONG *pStatus)
4622 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberAddBegin, lpiGroup, lpiUser, NULL, NULL, 0, 0);
4628 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4632 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4637 TCHAR szGroup[ cchNAME ];
4638 lpiGroup->GetGroupName (szGroup);
4640 TCHAR szMember[ cchNAME ];
4641 if (lpiUser->fIsUser())
4642 lpiUser->GetFullUserName (szMember);
4643 else // (lpiUser->fIsGroup())
4644 lpiUser->GetGroupName (szMember);
4646 // Add this user to the specified group
4651 wp.wpPtsGroupMemberAdd.hCell = hCell;
4652 wp.wpPtsGroupMemberAdd.pszGroup = szGroup;
4653 wp.wpPtsGroupMemberAdd.pszUser = szMember;
4656 rc = Worker_DoTask (wtaskPtsGroupMemberAdd, &wp, &status);
4660 // If we were able to change the group successfully, update the group's
4661 // and user's properties.
4665 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4667 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4668 lpCell->RefreshAccount (szMember, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4673 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberAddEnd, lpiGroup, lpiUser, NULL, NULL, 0, status);
4682 BOOL AfsClass_RemoveUserFromGroup (LPIDENT lpiGroup, LPIDENT lpiUser, ULONG *pStatus)
4688 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberRemoveBegin, lpiGroup, lpiUser, NULL, NULL, 0, 0);
4694 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4698 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4703 TCHAR szGroup[ cchNAME ];
4704 lpiGroup->GetGroupName (szGroup);
4706 TCHAR szMember[ cchNAME ];
4707 if (lpiUser->fIsUser())
4708 lpiUser->GetFullUserName (szMember);
4709 else // (lpiUser->fIsGroup())
4710 lpiUser->GetGroupName (szMember);
4712 // Remove this user from the specified group
4717 wp.wpPtsGroupMemberRemove.hCell = hCell;
4718 wp.wpPtsGroupMemberRemove.pszGroup = szGroup;
4719 wp.wpPtsGroupMemberRemove.pszUser = szMember;
4722 rc = Worker_DoTask (wtaskPtsGroupMemberRemove, &wp, &status);
4726 // If we were able to change the group successfully, update the group's
4727 // and user's properties.
4731 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4733 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4734 lpCell->RefreshAccount (szMember, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4739 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberRemoveEnd, lpiGroup, lpiUser, NULL, NULL, 0, status);