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; )
85 for (LPTSTR pszNext = psz; *pszNext && (*pszNext != TEXT('\r')) && (*pszNext != TEXT('\n')); ++pszNext)
89 if ((cbWrite = pszNext - psz) != 0)
90 WriteFile (fh, psz, cbWrite, &cbWrote, NULL);
91 WriteFile (fh, TEXT("\r\n"), 2, &cbWrote, NULL);
92 psz = (*pszNext == TEXT('\r')) ? (2+pszNext) : (*pszNext == TEXT('\n')) ? (1+pszNext) : NULL;
97 Free (wp.wpBosLogGet.pszLogData);
103 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
105 lpServer->CloseBosObject();
109 NOTIFYCALLBACK::SendNotificationToAll (evtGetServerLogFileEnd, lpiServer, pszRemote, status);
118 BOOL AfsClass_SetServerAuth (LPIDENT lpiServer, BOOL fEnabled, ULONG *pStatus)
124 NOTIFYCALLBACK::SendNotificationToAll (evtSetServerAuthBegin, lpiServer);
129 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
133 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
141 wp.wpBosAuthSet.hServer = hBOS;
142 wp.wpBosAuthSet.fEnableAuth = fEnabled;
145 rc = Worker_DoTask (wtaskBosAuthSet, &wp, &status);
149 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
151 lpServer->CloseBosObject();
155 NOTIFYCALLBACK::SendNotificationToAll (evtSetServerAuthEnd, lpiServer, status);
164 BOOL AfsClass_StartService (LPIDENT lpiStart, BOOL fTemporary, ULONG *pStatus)
170 NOTIFYCALLBACK::SendNotificationToAll (evtStartServiceBegin, lpiStart);
175 if ((lpServer = lpiStart->OpenServer (&status)) == NULL)
179 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
186 if (lpiStart->fIsService())
188 TCHAR szName[ cchNAME ];
189 lpiStart->GetServiceName (szName);
194 wp.wpBosProcessExecutionStateSetTemporary.hServer = hBOS;
195 wp.wpBosProcessExecutionStateSetTemporary.pszService = szName;
196 wp.wpBosProcessExecutionStateSetTemporary.state = SERVICESTATE_RUNNING;
199 rc = Worker_DoTask (wtaskBosProcessExecutionStateSetTemporary, &wp, &status);
205 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
206 wp.wpBosProcessExecutionStateSet.pszService = szName;
207 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_RUNNING;
210 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
217 wp.wpBosProcessAllStart.hServer = hBOS;
219 rc = Worker_DoTask (wtaskBosProcessAllStart, &wp, &status);
226 if (lpiStart->fIsService())
229 if ((lpService = lpiStart->OpenService (&status)) == NULL)
233 lpService->Invalidate();
234 lpService->RefreshStatus();
240 if ((lpServer = lpiStart->OpenServer (&status)) == NULL)
244 lpServer->Invalidate();
245 lpServer->RefreshAll();
251 if ((lpServer = lpiStart->OpenServer (&status)) != NULL)
253 lpServer->CloseBosObject();
257 NOTIFYCALLBACK::SendNotificationToAll (evtStartServiceEnd, lpiStart, status);
266 BOOL AfsClass_StopService (LPIDENT lpiStop, BOOL fTemporary, BOOL fWait, ULONG *pStatus)
272 NOTIFYCALLBACK::SendNotificationToAll (evtStopServiceBegin, lpiStop);
277 if ((lpServer = lpiStop->OpenServer (&status)) == NULL)
281 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
288 if (lpiStop->fIsService())
290 TCHAR szName[ cchNAME ];
291 lpiStop->GetServiceName (szName);
296 wp.wpBosProcessExecutionStateSetTemporary.hServer = hBOS;
297 wp.wpBosProcessExecutionStateSetTemporary.pszService = szName;
298 wp.wpBosProcessExecutionStateSetTemporary.state = SERVICESTATE_STOPPED;
299 // TODO: wp.wpStopBosProcessTemporary.fWait = TRUE;
302 rc = Worker_DoTask (wtaskBosProcessExecutionStateSetTemporary, &wp, &status);
308 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
309 wp.wpBosProcessExecutionStateSet.pszService = szName;
310 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
311 // TODO: wp.wpStopBosProcess.fWait = TRUE;
314 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
321 wp.wpBosProcessAllWaitStop.hServer = hBOS;
324 rc = Worker_DoTask (wtaskBosProcessAllWaitStop, &wp, &status);
330 wp.wpBosProcessAllStop.hServer = hBOS;
333 rc = Worker_DoTask (wtaskBosProcessAllStop, &wp, &status);
340 if (lpiStop->fIsService())
343 if ((lpService = lpiStop->OpenService (&status)) == NULL)
347 lpService->Invalidate();
348 lpService->RefreshStatus();
355 if ((lpServer = lpiStop->OpenServer (&status)) == NULL)
359 lpServer->Invalidate();
360 lpServer->RefreshAll();
366 if ((lpServer = lpiStop->OpenServer (&status)) != NULL)
368 lpServer->CloseBosObject();
372 NOTIFYCALLBACK::SendNotificationToAll (evtStopServiceEnd, lpiStop, status);
381 BOOL AfsClass_RestartService (LPIDENT lpiRestart, ULONG *pStatus)
387 NOTIFYCALLBACK::SendNotificationToAll (evtRestartServiceBegin, lpiRestart);
392 if ((lpServer = lpiRestart->OpenServer (&status)) == NULL)
396 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
402 if (!lpiRestart->fIsService())
405 TCHAR szServiceRestart[ cchNAME ];
406 if (lpiRestart->fIsService())
408 lpiRestart->GetServiceName (szServiceRestart);
409 if (!lstrcmpi (szServiceRestart, TEXT("BOS")))
418 wp.wpBosProcessRestart.hServer = hBOS;
419 wp.wpBosProcessRestart.pszService = szServiceRestart;
422 rc = Worker_DoTask (wtaskBosProcessRestart, &wp, &status);
425 else // (fRestartAll)
428 wp.wpBosProcessAllStopAndRestart.hServer = hBOS;
429 wp.wpBosProcessAllStopAndRestart.fRestartBOS = TRUE;
432 rc = Worker_DoTask (wtaskBosProcessAllStopAndRestart, &wp, &status);
442 if ((lpService = lpiRestart->OpenService (&status)) == NULL)
446 lpService->Invalidate();
447 lpService->RefreshStatus();
451 else // (fRestartAll)
454 if ((lpServer = lpiRestart->OpenServer (&status)) == NULL)
458 lpServer->Invalidate();
459 lpServer->RefreshAll();
465 if ((lpServer = lpiRestart->OpenServer (&status)) != NULL)
467 lpServer->CloseBosObject();
471 NOTIFYCALLBACK::SendNotificationToAll (evtRestartServiceEnd, lpiRestart, status);
480 LPIDENT AfsClass_CreateFileset (LPIDENT lpiAggregate, LPTSTR pszFileset, ULONG ckQuota, ULONG *pStatus)
482 LPIDENT lpiFileset = NULL;
487 NOTIFYCALLBACK::SendNotificationToAll (evtCreateFilesetBegin, lpiAggregate, pszFileset, 0);
489 // Obtain hCell and hVOS
494 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
498 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
503 // Obtain idPartition
506 LPAGGREGATE lpAggregate;
507 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
511 idPartition = lpAggregate->GetID();
512 lpAggregate->Close();
515 // Perform the actual operation
520 wp.wpVosVolumeCreate.hCell = hCell;
521 wp.wpVosVolumeCreate.hServer = hVOS;
522 wp.wpVosVolumeCreate.idPartition = idPartition;
523 wp.wpVosVolumeCreate.pszVolume = pszFileset;
524 wp.wpVosVolumeCreate.ckQuota = ckQuota;
527 rc = Worker_DoTask (wtaskVosVolumeCreate, &wp, &status);
535 LPAGGREGATE lpAggregate;
536 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
540 lpAggregate->Invalidate();
541 lpAggregate->RefreshFilesets (TRUE, &status);
542 lpAggregate->Close();
549 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
553 lpCell->RefreshVLDB (lpiAggregate);
560 LPAGGREGATE lpAggregate;
561 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
566 if ((lpFileset = lpAggregate->OpenFileset (pszFileset, &status)) == NULL)
570 lpiFileset = lpFileset->GetIdentifier();
573 lpAggregate->Close();
579 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
581 lpServer->CloseVosObject();
586 NOTIFYCALLBACK::SendNotificationToAll (evtCreateFilesetEnd, lpiAggregate, pszFileset, status);
591 return (rc) ? lpiFileset : NULL;
595 BOOL AfsClass_DeleteFileset (LPIDENT lpiFileset, BOOL fVLDB, BOOL fServer, ULONG *pStatus)
601 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiFileset);
603 // Obtain hCell and hVOS
608 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
612 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
617 // Does the fileset have a VLDB entry? Does it actually exist on the server?
618 // What's its volume ID? Its R/W ID? Its partition ID?
621 VOLUMEID vidReadWrite;
624 // Obtain the ID of the fileset's parent aggregate.
627 LPAGGREGATE lpAggregate;
628 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
632 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
634 lpAggregate->Close();
640 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
644 wFilesetGhost = lpFileset->GetGhostStatus();
645 lpiFileset->GetFilesetID (&vidFileset);
648 if (!lpFileset->GetStatus (&fs))
649 vidReadWrite = vidFileset;
651 vidReadWrite = fs.idReadWrite;
657 if (!(wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
659 if (!(wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
662 if (rc && fVLDB && fServer)
665 wp.wpVosVolumeDelete.hCell = hCell;
666 wp.wpVosVolumeDelete.hServer = hVOS;
667 wp.wpVosVolumeDelete.idPartition = idPartition;
668 wp.wpVosVolumeDelete.idVolume = vidFileset;
671 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
674 else if (rc && fVLDB)
677 wp.wpVosVLDBEntryRemove.hCell = hCell;
678 wp.wpVosVLDBEntryRemove.hServer = hVOS;
679 wp.wpVosVLDBEntryRemove.idPartition = idPartition;
680 wp.wpVosVLDBEntryRemove.idVolume = vidReadWrite;
683 rc = Worker_DoTask (wtaskVosVLDBEntryRemove, &wp, &status);
686 else if (rc && fServer)
689 wp.wpVosVolumeZap.hCell = hCell;
690 wp.wpVosVolumeZap.hServer = hVOS;
691 wp.wpVosVolumeZap.idPartition = idPartition;
692 wp.wpVosVolumeZap.idVolume = vidFileset;
693 wp.wpVosVolumeZap.fForce = TRUE;
696 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
702 LPAGGREGATE lpAggregate;
703 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
707 lpAggregate->Invalidate();
708 lpAggregate->RefreshFilesets (TRUE);
709 lpAggregate->Close();
716 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
720 lpCell->RefreshVLDB (lpiFileset->GetAggregate(), TRUE);
727 if ((lpServer = lpiFileset->OpenServer()) != NULL)
729 lpServer->CloseVosObject();
734 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiFileset, status);
743 BOOL AfsClass_MoveFileset (LPIDENT lpiFileset, LPIDENT lpiAggregateTarget, ULONG *pStatus)
749 NOTIFYCALLBACK::SendNotificationToAll (evtMoveFilesetBegin, lpiFileset, lpiAggregateTarget, NULL, NULL, 0, 0);
751 LPIDENT lpiAggregateSource = lpiFileset->GetAggregate();
753 // Obtain hCell, hVOS and the aggregate name for the source
756 PVOID hVOSSource = NULL;
758 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
762 if ((hVOSSource = lpServer->OpenVosObject (&hCell, &status)) == NULL)
767 // Obtain the ID of the source aggregate
769 int idPartitionSource;
770 LPAGGREGATE lpAggregate;
771 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
775 if ((idPartitionSource = lpAggregate->GetID()) == NO_PARTITION)
777 lpAggregate->Close();
780 // Obtain hCell, hVOS and the aggregate name for the target
782 PVOID hVOSTarget = NULL;
783 if ((lpServer = lpiAggregateTarget->OpenServer (&status)) == NULL)
787 if ((hVOSTarget = lpServer->OpenVosObject (NULL, &status)) == NULL)
792 // Obtain the ID of the target aggregate
794 int idPartitionTarget;
795 if ((lpAggregate = lpiAggregateTarget->OpenAggregate (&status)) == NULL)
799 if ((idPartitionTarget = lpAggregate->GetID()) == NO_PARTITION)
801 lpAggregate->Close();
807 wp.wpVosVolumeMove.hCell = hCell;
808 wp.wpVosVolumeMove.hServerFrom = hVOSSource;
809 wp.wpVosVolumeMove.idPartitionFrom = idPartitionSource;
810 wp.wpVosVolumeMove.hServerTo = hVOSTarget;
811 wp.wpVosVolumeMove.idPartitionTo = idPartitionTarget;
812 lpiFileset->GetFilesetID (&wp.wpVosVolumeMove.idVolume);
815 rc = Worker_DoTask (wtaskVosVolumeMove, &wp, &status);
821 LPAGGREGATE lpAggregate;
822 if ((lpAggregate = lpiAggregateSource->OpenAggregate (&status)) == NULL)
826 lpAggregate->Invalidate();
827 lpAggregate->RefreshFilesets();
828 lpAggregate->Close();
834 LPAGGREGATE lpAggregate;
835 if ((lpAggregate = lpiAggregateTarget->OpenAggregate (&status)) == NULL)
839 lpAggregate->Invalidate();
840 lpAggregate->RefreshFilesets();
841 lpAggregate->Close();
848 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
852 lpFileset->Invalidate();
853 lpFileset->RefreshStatus();
861 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
865 lpCell->RefreshVLDB (lpiAggregateSource, TRUE);
866 lpCell->RefreshVLDB (lpiAggregateTarget, TRUE);
873 if ((lpServer = lpiAggregateSource->OpenServer()) != NULL)
875 lpServer->CloseVosObject();
881 if ((lpServer = lpiAggregateTarget->OpenServer()) != NULL)
883 lpServer->CloseVosObject();
888 NOTIFYCALLBACK::SendNotificationToAll (evtMoveFilesetEnd, lpiFileset, lpiAggregateTarget, NULL, NULL, 0, status);
897 BOOL AfsClass_SetFilesetQuota (LPIDENT lpiFileset, size_t ckQuotaNew, ULONG *pStatus)
903 NOTIFYCALLBACK::SendNotificationToAll (evtSetFilesetQuotaBegin, lpiFileset);
905 // Obtain hCell and hVOS for the server where this fileset lives
910 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
914 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
919 // Obtain the ID of the fileset's parent aggregate.
924 LPAGGREGATE lpAggregate;
925 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
929 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
931 lpAggregate->Close();
935 // Change the fileset's quota.
940 wp.wpVosVolumeQuotaChange.hCell = hCell;
941 wp.wpVosVolumeQuotaChange.hServer = hVOS;
942 wp.wpVosVolumeQuotaChange.idPartition = idPartition;
943 lpiFileset->GetFilesetID (&wp.wpVosVolumeQuotaChange.idVolume);
944 wp.wpVosVolumeQuotaChange.ckQuota = ckQuotaNew;
947 rc = Worker_DoTask (wtaskVosVolumeQuotaChange, &wp, &status);
954 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
958 lpFileset->Invalidate();
959 lpFileset->RefreshStatus();
966 LPAGGREGATE lpAggregate;
967 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
971 lpAggregate->RefreshStatus();
972 lpAggregate->Close();
978 if ((lpServer = lpiFileset->OpenServer()) != NULL)
980 lpServer->CloseVosObject();
985 NOTIFYCALLBACK::SendNotificationToAll (evtSetFilesetQuotaEnd, lpiFileset, status);
994 BOOL AfsClass_SyncVLDB (LPIDENT lpiSync, BOOL fForce, ULONG *pStatus)
1000 NOTIFYCALLBACK::SendNotificationToAll (evtSyncVLDBBegin, lpiSync);
1002 // Obtain hCell and hVOS
1007 if ((lpServer = lpiSync->OpenServer (&status)) == NULL)
1011 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1016 // Obtain the ID of the target aggregate.
1018 int idPartition = NO_PARTITION;
1019 if (rc && (lpiSync->fIsAggregate() || lpiSync->fIsFileset()))
1021 LPAGGREGATE lpAggregate;
1022 if ((lpAggregate = lpiSync->OpenAggregate (&status)) == NULL)
1026 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1028 lpAggregate->Close();
1035 wp.wpVosVLDBSync.hCell = hCell;
1036 wp.wpVosVLDBSync.hServer = hVOS;
1037 wp.wpVosVLDBSync.idPartition = idPartition;
1038 wp.wpVosVLDBSync.fForce = fForce;
1041 rc = Worker_DoTask (wtaskVosVLDBSync, &wp, &status);
1047 if (lpiSync->fIsServer())
1050 if ((lpServer = lpiSync->OpenServer (&status)) == NULL)
1054 lpServer->Invalidate();
1055 rc = lpServer->RefreshAll (&status);
1059 else // (lpiSync->fIsAggregate())
1061 LPAGGREGATE lpAggregate;
1062 if ((lpAggregate = lpiSync->OpenAggregate (&status)) == NULL)
1066 lpAggregate->Invalidate();
1067 lpAggregate->RefreshStatus();
1068 lpAggregate->RefreshFilesets();
1069 lpAggregate->Close();
1072 if ((lpCell = lpiSync->OpenCell()) == NULL)
1076 lpCell->RefreshVLDB (lpiSync);
1085 if ((lpServer = lpiSync->OpenServer()) != NULL)
1087 lpServer->CloseVosObject();
1092 NOTIFYCALLBACK::SendNotificationToAll (evtSyncVLDBEnd, lpiSync, status);
1101 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSOCKADDR_IN pAddrOld, LPSOCKADDR_IN pAddrNew, ULONG *pStatus)
1107 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1113 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1117 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1125 wp.wpVosFileServerAddressChange.hCell = hCell;
1126 wp.wpVosFileServerAddressChange.addrOld = *pAddrOld;
1127 wp.wpVosFileServerAddressChange.addrNew = *pAddrNew;
1130 rc = Worker_DoTask (wtaskVosFileServerAddressChange, &wp, &status);
1133 else if (rc && !pAddrNew)
1136 wp.wpVosFileServerAddressRemove.hCell = hCell;
1137 wp.wpVosFileServerAddressRemove.addr = *pAddrOld;
1140 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1147 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1149 lpServer->InvalidateStatus();
1154 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1158 lpCell->InvalidateServers ();
1159 rc = lpCell->RefreshServers (TRUE, &status);
1164 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1173 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSERVERSTATUS pStatusOld, LPSERVERSTATUS pStatusNew, ULONG *pStatus)
1179 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1185 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1189 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1198 for (size_t iAddr = 0; rc && (iAddr < AFSCLASS_MAX_ADDRESSES_PER_SITE); ++iAddr)
1202 AfsClass_AddressToInt (&oldAddress, &pStatusOld->aAddresses[ iAddr ]);
1203 AfsClass_AddressToInt (&newAddress, &pStatusNew->aAddresses[ iAddr ]);
1205 if (oldAddress && newAddress && (oldAddress != newAddress))
1208 wp.wpVosFileServerAddressChange.hCell = hCell;
1209 wp.wpVosFileServerAddressChange.addrOld = pStatusOld->aAddresses[ iAddr ];
1210 wp.wpVosFileServerAddressChange.addrNew = pStatusNew->aAddresses[ iAddr ];
1212 rc = Worker_DoTask (wtaskVosFileServerAddressChange, &wp, &status);
1214 else if (oldAddress && !newAddress)
1217 wp.wpVosFileServerAddressRemove.hCell = hCell;
1218 wp.wpVosFileServerAddressRemove.addr = pStatusOld->aAddresses[ iAddr ];
1220 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1230 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1232 lpServer->InvalidateStatus();
1237 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1241 lpCell->InvalidateServers ();
1242 rc = lpCell->RefreshServers (TRUE, &status);
1247 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1256 BOOL AfsClass_LockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1262 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetBegin, lpiFileset);
1268 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1272 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1277 // Obtain the fileset's read-write identifier
1279 LPIDENT lpiRW = NULL;
1280 LPFILESET lpFileset;
1281 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1285 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1290 // Perform the lock operation
1295 wp.wpVosVLDBEntryLock.hCell = hCell;
1296 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryLock.idVolume);
1299 rc = Worker_DoTask (wtaskVosVLDBEntryLock, &wp, &status);
1306 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1311 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1313 lpCell->RefreshVLDB (lpiFileset->GetCell());
1318 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetEnd, lpiFileset, status);
1327 BOOL AfsClass_UnlockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1333 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetBegin, lpiFileset);
1339 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1343 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1348 // Obtain the fileset's read-write identifier
1350 LPIDENT lpiRW = NULL;
1351 LPFILESET lpFileset;
1352 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1356 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1361 // Perform the unlock operation
1366 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1367 wp.wpVosVLDBEntryUnlock.hServer = NULL;
1368 wp.wpVosVLDBEntryUnlock.idPartition = NO_PARTITION;
1369 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryUnlock.idVolume);
1372 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1379 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1384 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1386 lpCell->RefreshVLDB (lpiFileset->GetCell());
1391 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetEnd, lpiFileset, status);
1400 BOOL AfsClass_UnlockAllFilesets (LPIDENT lpi, ULONG *pStatus)
1406 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsBegin, lpi);
1412 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1416 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1421 // Obtain hServer if appropriate
1424 if (lpi && (!lpi->fIsCell()))
1427 if ((lpServer = lpi->OpenServer (&status)) == NULL)
1431 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
1437 // Obtain the ID of the scope aggregate.
1439 int idPartition = NO_PARTITION;
1440 if (rc && (lpi->fIsFileset() || (lpi->fIsAggregate())))
1442 LPAGGREGATE lpAggregate;
1443 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
1447 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1449 lpAggregate->Close();
1453 // Perform the unlock operation
1458 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1459 wp.wpVosVLDBEntryUnlock.hServer = hVOS;
1460 wp.wpVosVLDBEntryUnlock.idPartition = idPartition;
1461 wp.wpVosVLDBEntryUnlock.idVolume = NO_VOLUME;
1464 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1471 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1475 lpCell->RefreshVLDB (lpi);
1483 if ((lpServer = lpi->OpenServer (&status)) != NULL)
1485 lpServer->CloseVosObject();
1490 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsEnd, lpi);
1499 LPIDENT AfsClass_CreateReplica (LPIDENT lpiFileset, LPIDENT lpiAggregate, ULONG *pStatus)
1503 LPIDENT lpiReplica = NULL;
1506 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaBegin, lpiFileset, lpiAggregate, NULL, NULL, 0, 0);
1508 // Obtain hCell and hVOS for the target server
1513 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
1517 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1522 // Obtain idPartition
1525 LPAGGREGATE lpAggregate;
1526 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1530 idPartition = lpAggregate->GetID();
1531 lpAggregate->Close();
1534 // Modify VLDB to create mention of a new replica
1539 wp.wpVosVLDBReadOnlySiteCreate.hCell = hCell;
1540 wp.wpVosVLDBReadOnlySiteCreate.hServer = hVOS;
1541 wp.wpVosVLDBReadOnlySiteCreate.idPartition = idPartition;
1542 lpiFileset->GetFilesetID (&wp.wpVosVLDBReadOnlySiteCreate.idVolume);
1545 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteCreate, &wp, &status);
1553 LPAGGREGATE lpAggregate;
1554 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1558 lpAggregate->Invalidate();
1559 lpAggregate->RefreshFilesets (TRUE, &status);
1560 lpAggregate->Close();
1567 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
1571 lpCell->RefreshVLDB (lpiAggregate);
1578 LPFILESET lpFileset;
1579 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1583 if ((lpiReplica = lpFileset->GetReadOnlyIdentifier (lpiAggregate, &status)) == NULL)
1591 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
1593 lpServer->CloseVosObject();
1598 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaEnd, lpiFileset, lpiAggregate, NULL, NULL, 0, status);
1603 return (rc) ? lpiReplica : FALSE;
1607 BOOL AfsClass_DeleteReplica (LPIDENT lpiReplica, ULONG *pStatus)
1613 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiReplica);
1615 // Obtain hCell and hVOS for the server
1620 if ((lpServer = lpiReplica->OpenServer (&status)) == NULL)
1624 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1629 // Get the read/write fileset identifier and Ghost status
1631 LPIDENT lpiRW = NULL;
1632 int wFilesetGhost = 0;
1633 LPFILESET lpFileset;
1634 if ((lpFileset = lpiReplica->OpenFileset (&status)) == NULL)
1638 wFilesetGhost = lpFileset->GetGhostStatus();
1639 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1644 TCHAR szAggregateName[ cchNAME ];
1645 lpiReplica->GetAggregateName (szAggregateName);
1647 // Obtain the ID of the replica's partition
1650 LPAGGREGATE lpAggregate;
1651 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1655 idPartition = lpAggregate->GetID();
1656 lpAggregate->Close();
1659 // If the volume exists in both VLDB and on the server, just delete it
1661 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY) && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1664 wp.wpVosVolumeDelete.hCell = hCell;
1665 wp.wpVosVolumeDelete.hServer = hVOS;
1666 wp.wpVosVolumeDelete.idPartition = idPartition;
1667 lpiReplica->GetFilesetID (&wp.wpVosVolumeDelete.idVolume);
1670 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
1675 // If necessary, modify VLDB to remove mention of this replica
1677 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
1680 wp.wpVosVLDBReadOnlySiteDelete.hCell = hCell;
1681 wp.wpVosVLDBReadOnlySiteDelete.hServer = hVOS;
1682 wp.wpVosVLDBReadOnlySiteDelete.idPartition = idPartition;
1683 lpiRW->GetFilesetID (&wp.wpVosVLDBReadOnlySiteDelete.idVolume);
1686 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteDelete, &wp, &status);
1690 // If necessary, zap the volume
1692 if (rc && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1695 wp.wpVosVolumeZap.hCell = hCell;
1696 wp.wpVosVolumeZap.hServer = hVOS;
1697 wp.wpVosVolumeZap.idPartition = idPartition;
1698 lpiReplica->GetFilesetID (&wp.wpVosVolumeZap.idVolume);
1699 wp.wpVosVolumeZap.fForce = TRUE;
1702 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
1711 LPAGGREGATE lpAggregate;
1712 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1716 lpAggregate->Invalidate();
1717 lpAggregate->RefreshFilesets (TRUE, &status);
1718 lpAggregate->Close();
1725 if ((lpCell = lpiReplica->OpenCell()) == NULL)
1729 lpCell->RefreshVLDB (lpiReplica->GetAggregate());
1736 if ((lpServer = lpiReplica->OpenServer (&status)) != NULL)
1738 lpServer->CloseVosObject();
1743 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiReplica, status);
1752 BOOL AfsClass_DeleteClone (LPIDENT lpiClone, ULONG *pStatus)
1754 return AfsClass_DeleteFileset (lpiClone, TRUE, TRUE, pStatus);
1758 BOOL AfsClass_InstallFile (LPIDENT lpiServer, LPTSTR pszTarget, LPTSTR pszSource, ULONG *pStatus)
1764 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileBegin, lpiServer, pszSource, 0);
1769 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1773 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1781 wp.wpBosExecutableCreate.hServer = hBOS;
1782 wp.wpBosExecutableCreate.pszLocal = pszSource;
1783 wp.wpBosExecutableCreate.pszRemoteDir = pszTarget;
1786 rc = Worker_DoTask (wtaskBosExecutableCreate, &wp, &status);
1790 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1792 lpServer->CloseBosObject();
1796 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileEnd, lpiServer, pszSource, status);
1805 BOOL AfsClass_UninstallFile (LPIDENT lpiServer, LPTSTR pszUninstall, ULONG *pStatus)
1811 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileBegin, lpiServer, pszUninstall, 0);
1816 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1820 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1828 wp.wpBosExecutableRevert.hServer = hBOS;
1829 wp.wpBosExecutableRevert.pszFilename = pszUninstall;
1832 rc = Worker_DoTask (wtaskBosExecutableRevert, &wp, &status);
1836 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1838 lpServer->CloseBosObject();
1842 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileEnd, lpiServer, pszUninstall, status);
1851 BOOL AfsClass_PruneOldFiles (LPIDENT lpiServer, BOOL fBAK, BOOL fOLD, BOOL fCore, ULONG *pStatus)
1857 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesBegin, lpiServer);
1862 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1866 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1874 wp.wpBosExecutablePrune.hServer = hBOS;
1875 wp.wpBosExecutablePrune.fPruneBak = fBAK;
1876 wp.wpBosExecutablePrune.fPruneOld = fOLD;
1877 wp.wpBosExecutablePrune.fPruneCore = fCore;
1880 rc = Worker_DoTask (wtaskBosExecutablePrune, &wp, &status);
1884 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1886 lpServer->CloseBosObject();
1890 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesEnd, lpiServer, status);
1899 BOOL AfsClass_RenameFileset (LPIDENT lpiFileset, LPTSTR pszNewName, ULONG *pStatus)
1905 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetBegin, lpiFileset, pszNewName, 0);
1909 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1913 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1921 wp.wpVosVolumeRename.hCell = hCell;
1922 lpiFileset->GetFilesetID (&wp.wpVosVolumeRename.idVolume);
1923 wp.wpVosVolumeRename.pszVolume = pszNewName;
1926 rc = Worker_DoTask (wtaskVosVolumeRename, &wp, &status);
1933 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1937 lpCell->Invalidate();
1938 rc = lpCell->RefreshAll (&status);
1944 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetEnd, lpiFileset, pszNewName, status);
1953 #define iswhite(_ch) ((_ch)==TEXT(' ') || (_ch)==TEXT('\t'))
1955 LPIDENT AfsClass_CreateService (LPIDENT lpiServer, LPTSTR pszService, LPTSTR pszCommand, LPTSTR pszParams, LPTSTR pszNotifier, AFSSERVICETYPE type, SYSTEMTIME *pstIfCron, ULONG *pStatus)
1959 LPIDENT lpiService = NULL;
1962 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceBegin, lpiServer, pszService, 0);
1967 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1971 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1979 wp.wpBosProcessCreate.hServer = hBOS;
1980 wp.wpBosProcessCreate.pszService = pszService;
1981 wp.wpBosProcessCreate.type = type;
1982 wp.wpBosProcessCreate.pszNotifier = pszNotifier;
1984 TCHAR szFullCommand[ MAX_PATH + MAX_PATH ];
1985 wsprintf (szFullCommand, TEXT("%s %s"), pszCommand, pszParams);
1986 wp.wpBosProcessCreate.pszCommand = szFullCommand;
1988 TCHAR szCronTime[ 256 ] = TEXT("");
1989 wp.wpBosProcessCreate.pszTimeCron = szCronTime;
1991 if (type == SERVICETYPE_CRON)
1992 AfsClass_FormatRecurringTime (szCronTime, pstIfCron);
1994 wp.wpBosProcessCreate.pszTimeCron = NULL;
1997 rc = Worker_DoTask (wtaskBosProcessCreate, &wp, &status);
2003 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2007 lpServer->InvalidateServices();
2008 if (!lpServer->RefreshServices (TRUE, &status))
2012 LPSERVICE lpService;
2013 if ((lpService = lpServer->OpenService (pszService, &status)) == NULL)
2017 lpiService = lpService->GetIdentifier();
2025 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2027 lpServer->CloseBosObject();
2031 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceEnd, lpiServer, pszService, status);
2036 return (rc) ? lpiService : NULL;
2040 BOOL AfsClass_DeleteService (LPIDENT lpiService, ULONG *pStatus)
2046 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceBegin, lpiService);
2051 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2055 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2060 // Before a service can be deleted, it must be stopped (otherwise, on NT,
2061 // the Delete operation won't block for the required Stop to complete--
2062 // so our wtaskDeleteBosProcess would return before the service really
2067 TCHAR szService[ cchNAME ];
2068 lpiService->GetServiceName (szService);
2071 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
2072 wp.wpBosProcessExecutionStateSet.pszService = szService;
2073 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
2074 // TODO: wp.wpStopBosProcess.fWait = TRUE;
2077 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
2081 // Delete the service
2085 TCHAR szService[ cchNAME ];
2086 lpiService->GetServiceName (szService);
2089 wp.wpBosProcessDelete.hServer = hBOS;
2090 wp.wpBosProcessDelete.pszService = szService;
2093 rc = Worker_DoTask (wtaskBosProcessDelete, &wp, &status);
2099 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2103 lpServer->InvalidateServices();
2104 if (!lpServer->RefreshServices (TRUE, &status))
2110 if ((lpServer = lpiService->OpenServer (&status)) != NULL)
2112 lpServer->CloseBosObject();
2116 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceEnd, lpiService, status);
2125 BOOL AfsClass_ReleaseFileset (LPIDENT lpiFilesetRW, BOOL fForce, ULONG *pStatus)
2131 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetBegin, lpiFilesetRW);
2133 // Obtain hCell and hVOS
2138 if ((lpServer = lpiFilesetRW->OpenServer (&status)) == NULL)
2142 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2147 // Perform the actual operation
2152 wp.wpVosVolumeRelease.hCell = hCell;
2153 wp.wpVosVolumeRelease.fForce = fForce;
2154 lpiFilesetRW->GetFilesetID (&wp.wpVosVolumeRelease.idVolume);
2157 rc = Worker_DoTask (wtaskVosVolumeRelease, &wp, &status);
2166 if ((lpCell = lpiFilesetRW->OpenCell (&status)) == NULL)
2170 lpCell->Invalidate();
2171 rc = lpCell->RefreshAll (&status);
2178 if ((lpServer = lpiFilesetRW->OpenServer (&status)) != NULL)
2180 lpServer->CloseVosObject();
2185 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetEnd, lpiFilesetRW, status);
2194 BOOL AfsClass_GetFileDates (LPIDENT lpiServer, LPTSTR pszFilename, SYSTEMTIME *pstFile, SYSTEMTIME *pstBAK, SYSTEMTIME *pstOLD, ULONG *pStatus)
2200 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesBegin, lpiServer, pszFilename, 0);
2205 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2209 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2217 wp.wpBosExecutableTimestampGet.hServer = hBOS;
2218 wp.wpBosExecutableTimestampGet.pszFilename = pszFilename;
2221 if ((rc = Worker_DoTask (wtaskBosExecutableTimestampGet, &wp, &status)) == TRUE)
2223 *pstFile = wp.wpBosExecutableTimestampGet.timeNew;
2224 *pstBAK = wp.wpBosExecutableTimestampGet.timeBak;
2225 *pstOLD = wp.wpBosExecutableTimestampGet.timeOld;
2231 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2233 lpServer->CloseBosObject();
2237 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesEnd, lpiServer, pszFilename, status);
2246 BOOL AfsClass_ExecuteCommand (LPIDENT lpiServer, LPTSTR pszCommand, ULONG *pStatus)
2252 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandBegin, lpiServer, pszCommand, 0);
2257 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2261 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2269 wp.wpBosCommandExecute.hServer = hBOS;
2270 wp.wpBosCommandExecute.pszCommand = pszCommand;
2273 rc = Worker_DoTask (wtaskBosCommandExecute, &wp, &status);
2277 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2279 lpServer->CloseBosObject();
2283 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandEnd, lpiServer, pszCommand, status);
2292 LPADMINLIST AfsClass_AdminList_Load (LPIDENT lpiServer, ULONG *pStatus)
2296 LPADMINLIST lpList = NULL;
2299 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadBegin, lpiServer);
2304 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2308 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2315 lpList = New(ADMINLIST);
2316 memset (lpList, 0x00, sizeof(ADMINLIST));
2318 lpList->lpiServer = lpiServer;
2320 WORKERPACKET wpBegin;
2321 wpBegin.wpBosAdminGetBegin.hServer = hBOS;
2322 if (!Worker_DoTask (wtaskBosAdminGetBegin, &wpBegin, &status))
2328 TCHAR szAdmin[ cchNAME ];
2330 WORKERPACKET wpNext;
2331 wpNext.wpBosAdminGetNext.hEnum = wpBegin.wpBosAdminGetBegin.hEnum;
2332 wpNext.wpBosAdminGetNext.pszAdmin = szAdmin;
2334 if (!Worker_DoTask (wtaskBosAdminGetNext, &wpNext, &status))
2336 if (status == ADMITERATORDONE)
2344 if ((iAdded = AfsClass_AdminList_AddEntry (lpList, szAdmin)) != (size_t)-1)
2346 lpList->aEntries[ iAdded ].fAdded = FALSE;
2350 WORKERPACKET wpDone;
2351 wpDone.wpBosAdminGetDone.hEnum = wpBegin.wpBosAdminGetBegin.hEnum;
2352 Worker_DoTask (wtaskBosAdminGetDone, &wpDone);
2356 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2358 lpServer->CloseBosObject();
2362 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadEnd, lpiServer, status);
2367 return (rc) ? lpList : NULL;
2371 LPADMINLIST AfsClass_AdminList_Copy (LPADMINLIST lpOld)
2373 LPADMINLIST lpNew = NULL;
2377 lpNew = New(ADMINLIST);
2378 memcpy (lpNew, lpOld, sizeof(ADMINLIST));
2381 lpNew->aEntries = 0;
2382 lpNew->cEntries = 0;
2384 if (REALLOC (lpNew->aEntries, lpNew->cEntries, lpOld->cEntries, cREALLOC_ADMINLISTENTRIES))
2386 size_t cb = lpOld->cEntries * sizeof(ADMINLISTENTRY);
2387 memcpy (lpNew->aEntries, lpOld->aEntries, cb);
2395 BOOL AfsClass_AdminList_Save (LPADMINLIST lpList, ULONG *pStatus)
2401 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveBegin, lpList->lpiServer);
2406 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
2410 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2417 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2419 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2422 // are we supposed to add this entry?
2424 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
2427 wp.wpBosAdminCreate.hServer = hBOS;
2428 wp.wpBosAdminCreate.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2431 if (!Worker_DoTask (wtaskBosAdminCreate, &wp, &thisstatus))
2434 status = thisstatus;
2438 lpList->aEntries[ iEntry ].fAdded = FALSE;
2442 // are we supposed to delete this entry?
2444 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
2447 wp.wpBosAdminDelete.hServer = hBOS;
2448 wp.wpBosAdminDelete.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2451 if (!Worker_DoTask (wtaskBosAdminDelete, &wp, &thisstatus))
2454 status = thisstatus;
2458 lpList->aEntries[ iEntry ].szAdmin[0] = TEXT('\0');
2459 lpList->aEntries[ iEntry ].fDeleted = FALSE;
2465 if ((lpServer = lpList->lpiServer->OpenServer (&status)) != NULL)
2467 lpServer->CloseBosObject();
2471 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveEnd, lpList->lpiServer, status);
2480 void AfsClass_AdminList_Free (LPADMINLIST lpList)
2482 if (lpList && !InterlockedDecrement (&lpList->cRef))
2484 if (lpList->aEntries)
2485 Free (lpList->aEntries);
2486 memset (lpList, 0x00, sizeof(ADMINLIST));
2492 size_t AfsClass_AdminList_AddEntry (LPADMINLIST lpList, LPTSTR pszAdmin)
2494 size_t iAdded = (size_t)-1;
2498 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2500 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2503 if (iEntry >= lpList->cEntries)
2505 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_ADMINLISTENTRIES);
2507 if (iEntry < lpList->cEntries)
2510 lstrcpy (lpList->aEntries[ iAdded ].szAdmin, pszAdmin);
2511 lpList->aEntries[ iAdded ].fAdded = TRUE;
2512 lpList->aEntries[ iAdded ].fDeleted = FALSE;
2520 BOOL AfsClass_AdminList_DelEntry (LPADMINLIST lpList, size_t iIndex)
2525 (iIndex < lpList->cEntries) &&
2526 (lpList->aEntries[ iIndex ].szAdmin[0]) &&
2527 (!lpList->aEntries[ iIndex ].fDeleted) )
2529 if (lpList->aEntries[ iIndex ].fAdded)
2530 lpList->aEntries[ iIndex ].szAdmin[0] = TEXT('\0');
2532 lpList->aEntries[ iIndex ].fDeleted = TRUE;
2541 LPKEYLIST AfsClass_KeyList_Load (LPIDENT lpiServer, ULONG *pStatus)
2545 LPKEYLIST lpList = NULL;
2548 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadBegin, lpiServer);
2553 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2557 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2564 lpList = New(KEYLIST);
2565 memset (lpList, 0x00, sizeof(KEYLIST));
2566 lpList->lpiServer = lpiServer;
2568 WORKERPACKET wpBegin;
2569 wpBegin.wpBosKeyGetBegin.hServer = hBOS;
2570 if (!Worker_DoTask (wtaskBosKeyGetBegin, &wpBegin, &status))
2574 for (size_t iEnum = 0; ; ++iEnum)
2576 WORKERPACKET wpNext;
2577 wpNext.wpBosKeyGetNext.hEnum = wpBegin.wpBosKeyGetBegin.hEnum;
2579 if (!Worker_DoTask (wtaskBosKeyGetNext, &wpNext, &status))
2581 if (status == ADMITERATORDONE)
2588 if (REALLOC (lpList->aKeys, lpList->cKeys, 1+iEnum, cREALLOC_SERVERKEYS))
2590 lpList->aKeys[ iEnum ].keyVersion = wpNext.wpBosKeyGetNext.keyVersion;
2591 memcpy (&lpList->aKeys[ iEnum ].keyData, &wpNext.wpBosKeyGetNext.keyData, sizeof(ENCRYPTIONKEY));
2592 memcpy (&lpList->aKeys[ iEnum ].keyInfo, &wpNext.wpBosKeyGetNext.keyInfo, sizeof(ENCRYPTIONKEYINFO));
2596 WORKERPACKET wpDone;
2597 wpDone.wpBosKeyGetDone.hEnum = wpBegin.wpBosKeyGetBegin.hEnum;
2598 Worker_DoTask (wtaskBosKeyGetDone, &wpDone);
2602 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2604 lpServer->CloseBosObject();
2608 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadEnd, lpiServer, status);
2613 return (rc) ? lpList : NULL;
2617 void AfsClass_KeyList_Free (LPKEYLIST lpList)
2622 Free (lpList->aKeys);
2623 memset (lpList, 0x00, sizeof(KEYLIST));
2629 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPTSTR pszString, ULONG *pStatus)
2634 TCHAR szCell[ cchNAME ];
2635 lpiServer->GetCellName (szCell);
2638 wp.wpKasStringToKey.pszCell = szCell;
2639 wp.wpKasStringToKey.pszString = pszString;
2640 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
2644 else if (!AfsClass_AddKey (lpiServer, keyVersion, &wp.wpKasStringToKey.key, &status))
2655 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2663 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2667 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2675 wp.wpBosKeyCreate.hServer = hBOS;
2676 wp.wpBosKeyCreate.keyVersion = keyVersion;
2677 memcpy (&wp.wpBosKeyCreate.key, pKey, sizeof(ENCRYPTIONKEY));
2678 rc = Worker_DoTask (wtaskBosKeyCreate, &wp, &status);
2681 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2683 lpServer->CloseBosObject();
2693 BOOL AfsClass_DeleteKey (LPIDENT lpiServer, int keyVersion, ULONG *pStatus)
2701 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2705 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2713 wp.wpBosKeyDelete.hServer = hBOS;
2714 wp.wpBosKeyDelete.keyVersion = keyVersion;
2715 rc = Worker_DoTask (wtaskBosKeyDelete, &wp, &status);
2718 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2720 lpServer->CloseBosObject();
2730 BOOL AfsClass_GetRandomKey (LPIDENT lpi, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2738 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2742 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2745 hKAS = lpCell->GetKasObject (&status);
2752 wp.wpKasServerRandomKeyGet.hCell = hCell;
2753 wp.wpKasServerRandomKeyGet.hServer = hKAS;
2754 rc = Worker_DoTask (wtaskKasServerRandomKeyGet, &wp, &status);
2757 memcpy (pKey, &wp.wpKasServerRandomKeyGet.key, sizeof(ENCRYPTIONKEY));
2766 BOOL AfsClass_Clone (LPIDENT lpiRW, ULONG *pStatus)
2772 NOTIFYCALLBACK::SendNotificationToAll (evtCloneBegin, lpiRW, 0);
2778 if ((lpCell = lpiRW->OpenCell (&status)) == NULL)
2782 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2787 // Perform the actual operation
2792 wp.wpVosBackupVolumeCreate.hCell = hCell;
2793 lpiRW->GetFilesetID (&wp.wpVosBackupVolumeCreate.idVolume);
2796 rc = Worker_DoTask (wtaskVosBackupVolumeCreate, &wp, &status);
2805 if ((lpServer = lpiRW->OpenServer (&status)) == NULL)
2809 lpServer->Invalidate();
2810 rc = lpServer->RefreshAll (&status);
2815 NOTIFYCALLBACK::SendNotificationToAll (evtCloneEnd, lpiRW, status);
2824 BOOL AfsClass_CloneMultiple (LPIDENT lpi, LPTSTR pszPrefix, BOOL fExclude, ULONG *pStatus)
2830 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleBegin, lpi);
2836 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2840 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2845 // Obtain hServer if appropriate
2848 if (!lpi->fIsCell())
2851 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2855 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
2861 // If requested, obtain the appropriate aggregate ID
2863 int idPartition = NO_PARTITION;
2864 if (rc && (lpi->fIsFileset() || lpi->fIsAggregate()))
2866 LPAGGREGATE lpAggregate;
2867 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2871 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
2873 lpAggregate->Close();
2877 // Perform the actual operation
2882 wp.wpVosBackupVolumeCreateMultiple.hCell = hCell;
2883 wp.wpVosBackupVolumeCreateMultiple.hServer = hVOS;
2884 wp.wpVosBackupVolumeCreateMultiple.idPartition = idPartition;
2885 wp.wpVosBackupVolumeCreateMultiple.pszPrefix = pszPrefix;
2886 wp.wpVosBackupVolumeCreateMultiple.fExclude = fExclude;
2889 rc = Worker_DoTask (wtaskVosBackupVolumeCreateMultiple, &wp, &status);
2900 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2904 lpCell->Invalidate();
2905 rc = lpCell->RefreshAll (&status);
2912 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2916 lpServer->Invalidate();
2917 rc = lpServer->RefreshAll (&status);
2926 if ((lpServer = lpi->OpenServer (&status)) != NULL)
2928 lpServer->CloseVosObject();
2933 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleEnd, lpi, status);
2942 BOOL AfsClass_DumpFileset (LPIDENT lpi, LPTSTR pszFilename, LPSYSTEMTIME pstDate, ULONG *pStatus)
2948 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetBegin, lpi, pszFilename, 0);
2950 // Obtain hCell and hVOS
2955 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2959 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2964 // Obtain idPartition
2967 LPAGGREGATE lpAggregate;
2968 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2972 idPartition = lpAggregate->GetID();
2973 lpAggregate->Close();
2976 // Perform the actual operation
2981 wp.wpVosVolumeDump.hCell = hCell;
2982 wp.wpVosVolumeDump.hServer = hVOS;
2983 wp.wpVosVolumeDump.pszFilename = pszFilename;
2984 wp.wpVosVolumeDump.idPartition = idPartition;
2985 lpi->GetFilesetID (&wp.wpVosVolumeDump.idVolume);
2988 memcpy (&wp.wpVosVolumeDump.stStart, pstDate, sizeof(SYSTEMTIME));
2990 memset (&wp.wpVosVolumeDump.stStart, 0x00, sizeof(SYSTEMTIME));
2993 rc = Worker_DoTask (wtaskVosVolumeDump, &wp, &status);
2997 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetEnd, lpi, pszFilename, status);
3003 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3005 lpServer->CloseVosObject();
3016 BOOL AfsClass_RestoreFileset (LPIDENT lpi, LPTSTR pszFileset, LPTSTR pszFilename, BOOL fIncremental, ULONG *pStatus)
3022 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetBegin, lpi, NULL, pszFileset, pszFilename, 0, 0);
3024 // Obtain hCell and hVOS
3029 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3033 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
3038 // Obtain idPartition
3041 LPAGGREGATE lpAggregate;
3042 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
3046 idPartition = lpAggregate->GetID();
3047 lpAggregate->Close();
3050 // Perform the actual operation
3055 wp.wpVosVolumeRestore.hCell = hCell;
3056 wp.wpVosVolumeRestore.hServer = hVOS;
3057 wp.wpVosVolumeRestore.idPartition = idPartition;
3058 wp.wpVosVolumeRestore.pszVolume = pszFileset;
3059 wp.wpVosVolumeRestore.pszFilename = pszFilename;
3060 wp.wpVosVolumeRestore.fIncremental = fIncremental;
3062 if (lpi->fIsFileset())
3063 lpi->GetFilesetID (&wp.wpVosVolumeRestore.idVolume);
3065 wp.wpVosVolumeRestore.idVolume = NO_VOLUME;
3068 rc = Worker_DoTask (wtaskVosVolumeRestore, &wp, &status);
3076 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3080 lpServer->Invalidate();
3081 rc = lpServer->RefreshAll (&status);
3088 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3090 lpServer->CloseVosObject();
3095 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetEnd, lpi, NULL, pszFileset, pszFilename, 0, status);
3104 BOOL AfsClass_GetRestartTimes (LPIDENT lpiServer, BOOL *pfWeekly, LPSYSTEMTIME pstWeekly, BOOL *pfDaily, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3110 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesBegin, lpiServer);
3115 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3119 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3127 wp.wpBosExecutableRestartTimeGet.hServer = hBOS;
3130 rc = Worker_DoTask (wtaskBosExecutableRestartTimeGet, &wp, &status);
3135 *pfWeekly = wp.wpBosExecutableRestartTimeGet.fWeeklyRestart;
3136 *pstWeekly = wp.wpBosExecutableRestartTimeGet.timeWeekly;
3137 *pfDaily = wp.wpBosExecutableRestartTimeGet.fDailyRestart;
3138 *pstDaily = wp.wpBosExecutableRestartTimeGet.timeDaily;
3142 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3144 lpServer->CloseBosObject();
3148 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesEnd, lpiServer, status);
3157 BOOL AfsClass_SetRestartTimes (LPIDENT lpiServer, LPSYSTEMTIME pstWeekly, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3163 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesBegin, lpiServer);
3168 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3172 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3179 SYSTEMTIME timeNever;
3180 memset (&timeNever, 0x00, sizeof(SYSTEMTIME));
3183 wp.wpBosExecutableRestartTimeSet.hServer = hBOS;
3184 wp.wpBosExecutableRestartTimeSet.fWeeklyRestart = (pstWeekly != NULL) ? TRUE : FALSE;
3185 wp.wpBosExecutableRestartTimeSet.timeWeekly = (pstWeekly != NULL) ? *pstWeekly : timeNever;
3186 wp.wpBosExecutableRestartTimeSet.fDailyRestart = (pstDaily != NULL) ? TRUE : FALSE;
3187 wp.wpBosExecutableRestartTimeSet.timeDaily = (pstDaily != NULL) ? *pstDaily : timeNever;
3190 rc = Worker_DoTask (wtaskBosExecutableRestartTimeSet, &wp, &status);
3194 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3196 lpServer->CloseBosObject();
3200 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesEnd, lpiServer, status);
3209 BOOL AfsClass_MoveReplica (LPIDENT lpiReplica, LPIDENT lpiAggregateTarget, ULONG *pStatus)
3213 // Find the identifier for this replica's read/write fileset.
3215 LPIDENT lpiFilesetRW = NULL;
3216 LPFILESET lpFileset;
3217 if ((lpFileset = lpiReplica->OpenFileset (pStatus)) == NULL)
3221 if ((lpiFilesetRW = lpFileset->GetReadWriteIdentifier (pStatus)) == NULL)
3226 // If the fileset replica currently resides on the same server
3227 // as the target aggregate, we'll follow the following steps:
3229 // 1. Delete the old fileset replica -> on error, quit
3230 // 2. Create the new fileset replica -> on error, recreate old replica, quit
3232 // If the fileset replica instead currently resides on a different
3233 // server, we can follow the preferred steps:
3235 // 1. Create the new fileset replica -> on error, quit
3236 // 2. Delete the old fileset replica -> on error, delete the new replica, quit
3240 LPIDENT lpiReplicaNew;
3242 if (lpiReplica->GetServer() == lpiAggregateTarget->GetServer())
3244 LPIDENT lpiAggregateOriginal = lpiReplica->GetAggregate();
3246 if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3250 else if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3252 (void)AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateOriginal);
3256 else // different server?
3258 if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3262 else if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3264 (void)AfsClass_DeleteReplica (lpiReplicaNew, pStatus);
3274 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)
3280 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageBegin, lpiSalvage);
3285 if ((lpServer = lpiSalvage->OpenServer (&status)) == NULL)
3289 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3295 *ppszLogData = NULL;
3297 // Step one: perform the actual salvage. This will dump a log file onto
3298 // the target computer.
3302 LPTSTR pszAggregate = NULL;
3303 TCHAR szAggregate[ cchNAME ];
3304 if (lpiSalvage->fIsAggregate() || lpiSalvage->fIsFileset())
3306 lpiSalvage->GetAggregateName (szAggregate);
3307 pszAggregate = szAggregate;
3310 LPTSTR pszFileset = NULL;
3311 TCHAR szFileset[ cchNAME ];
3312 if (lpiSalvage->fIsFileset())
3315 lpiSalvage->GetFilesetID (&vid);
3316 wsprintf (szFileset, TEXT("%lu"), vid);
3317 pszFileset = szFileset;
3320 if (pszLogFile == NULL)
3321 pszLogFile = TEXT("SalvageLog");
3324 wp.wpBosSalvage.hCell = hCell;
3325 wp.wpBosSalvage.hServer = hBOS;
3326 wp.wpBosSalvage.pszAggregate = pszAggregate;
3327 wp.wpBosSalvage.pszFileset = pszFileset;
3328 wp.wpBosSalvage.nProcesses = nProcesses;
3329 wp.wpBosSalvage.pszTempDir = pszTempDir;
3330 wp.wpBosSalvage.pszLogFile = pszLogFile;
3331 wp.wpBosSalvage.fForce = fForce;
3332 wp.wpBosSalvage.fReadonly = fReadonly;
3333 wp.wpBosSalvage.fLogInodes = fLogInodes;
3334 wp.wpBosSalvage.fLogRootInodes = fLogRootInodes;
3335 wp.wpBosSalvage.fRebuildDirs = fRebuildDirs;
3336 wp.wpBosSalvage.fReadBlocks = fReadBlocks;
3339 rc = Worker_DoTask (wtaskBosSalvage, &wp, &status);
3343 // Step two: retrieve the log file from that salvage operation.
3344 // If we can't get the log file back, that's not fatal--just return
3345 // a NULL pointer for the log data.
3347 if (rc && ppszLogData)
3350 wp.wpBosLogGet.hServer = hBOS;
3351 wp.wpBosLogGet.pszLogName = pszLogFile;
3352 wp.wpBosLogGet.pszLogData = NULL;
3355 if ((rc = Worker_DoTask (wtaskBosLogGet, &wp, &status)) == TRUE)
3357 // Okay, well, we have the log in memory now. Problem is,
3358 // it has UNIX-style CR's... and so is missing the LF which
3359 // PCs expect before each CR. Wow--look at all the
3360 // acronyms! Count the CRs, alloc a larger buffer, and stuff
3361 // in the LFs before each CR.
3363 size_t cchRequired = 1;
3364 for (LPTSTR pchIn = wp.wpBosLogGet.pszLogData; *pchIn; ++pchIn)
3366 cchRequired += (*pchIn == TEXT('\r')) ? 0 : (*pchIn == TEXT('\n')) ? 2 : 1;
3369 if ((*ppszLogData = AllocateString (cchRequired)) != NULL)
3371 LPTSTR pszOut = *ppszLogData;
3372 for (LPTSTR pchIn = wp.wpBosLogGet.pszLogData; *pchIn; ++pchIn)
3374 if (*pchIn == TEXT('\n'))
3375 *pszOut++ = TEXT('\r');
3376 if (*pchIn != TEXT('\r'))
3379 *pszOut++ = TEXT('\0');
3385 if ((lpServer = lpiSalvage->OpenServer (&status)) != NULL)
3387 lpServer->CloseBosObject();
3391 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageEnd, lpiSalvage, status);
3400 void AfsClass_FreeSalvageLog (LPTSTR pszLogData)
3407 LPHOSTLIST AfsClass_HostList_Load (LPIDENT lpiServer, ULONG *pStatus)
3411 LPHOSTLIST lpList = NULL;
3414 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadBegin, lpiServer);
3419 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3423 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3430 lpList = New(HOSTLIST);
3431 memset (lpList, 0x00, sizeof(HOSTLIST));
3433 lpList->lpiServer = lpiServer;
3435 WORKERPACKET wpBegin;
3436 wpBegin.wpBosHostGetBegin.hServer = hBOS;
3437 if (!Worker_DoTask (wtaskBosHostGetBegin, &wpBegin, &status))
3443 TCHAR szHost[ cchNAME ];
3445 WORKERPACKET wpNext;
3446 wpNext.wpBosHostGetNext.hEnum = wpBegin.wpBosHostGetBegin.hEnum;
3447 wpNext.wpBosHostGetNext.pszServer = szHost;
3449 if (!Worker_DoTask (wtaskBosHostGetNext, &wpNext, &status))
3451 if (status == ADMITERATORDONE)
3459 if ((iAdded = AfsClass_HostList_AddEntry (lpList, szHost)) != (size_t)-1)
3461 lpList->aEntries[ iAdded ].fAdded = FALSE;
3465 WORKERPACKET wpDone;
3466 wpDone.wpBosHostGetDone.hEnum = wpBegin.wpBosHostGetBegin.hEnum;
3467 Worker_DoTask (wtaskBosHostGetDone, &wpDone);
3471 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3473 lpServer->CloseBosObject();
3477 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadEnd, lpiServer, status);
3482 return (rc) ? lpList : NULL;
3486 LPHOSTLIST AfsClass_HostList_Copy (LPHOSTLIST lpOld)
3488 LPHOSTLIST lpNew = NULL;
3492 lpNew = New(HOSTLIST);
3493 memcpy (lpNew, lpOld, sizeof(HOSTLIST));
3496 lpNew->aEntries = 0;
3497 lpNew->cEntries = 0;
3499 if (REALLOC (lpNew->aEntries, lpNew->cEntries, lpOld->cEntries, cREALLOC_HOSTLISTENTRIES))
3501 size_t cb = lpOld->cEntries * sizeof(HOSTLISTENTRY);
3502 memcpy (lpNew->aEntries, lpOld->aEntries, cb);
3510 BOOL AfsClass_HostList_Save (LPHOSTLIST lpList, ULONG *pStatus)
3516 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveBegin, lpList->lpiServer);
3521 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
3525 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3532 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3534 if (!lpList->aEntries[ iEntry ].szHost[0])
3537 // are we supposed to add this entry?
3539 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
3542 wp.wpBosHostCreate.hServer = hBOS;
3543 wp.wpBosHostCreate.pszServer = lpList->aEntries[ iEntry ].szHost;
3546 if (!Worker_DoTask (wtaskBosHostCreate, &wp, &thisstatus))
3549 status = thisstatus;
3553 lpList->aEntries[ iEntry ].fAdded = FALSE;
3557 // are we supposed to delete this entry?
3559 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
3562 wp.wpBosHostDelete.hServer = hBOS;
3563 wp.wpBosHostDelete.pszServer = lpList->aEntries[ iEntry ].szHost;
3566 if (!Worker_DoTask (wtaskBosHostDelete, &wp, &thisstatus))
3569 status = thisstatus;
3573 lpList->aEntries[ iEntry ].szHost[0] = TEXT('\0');
3574 lpList->aEntries[ iEntry ].fDeleted = FALSE;
3580 if ((lpServer = lpList->lpiServer->OpenServer (&status)) != NULL)
3582 lpServer->CloseBosObject();
3586 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveEnd, lpList->lpiServer, status);
3595 void AfsClass_HostList_Free (LPHOSTLIST lpList)
3597 if (lpList && !InterlockedDecrement (&lpList->cRef))
3599 if (lpList->aEntries)
3600 Free (lpList->aEntries);
3601 memset (lpList, 0x00, sizeof(HOSTLIST));
3607 size_t AfsClass_HostList_AddEntry (LPHOSTLIST lpList, LPTSTR pszHost)
3609 size_t iAdded = (size_t)-1;
3613 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3615 if (!lpList->aEntries[ iEntry ].szHost[0])
3618 if (iEntry >= lpList->cEntries)
3620 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_HOSTLISTENTRIES);
3622 if (iEntry < lpList->cEntries)
3625 lstrcpy (lpList->aEntries[ iAdded ].szHost, pszHost);
3626 lpList->aEntries[ iAdded ].fAdded = TRUE;
3627 lpList->aEntries[ iAdded ].fDeleted = FALSE;
3635 BOOL AfsClass_HostList_DelEntry (LPHOSTLIST lpList, size_t iIndex)
3640 (iIndex < lpList->cEntries) &&
3641 (lpList->aEntries[ iIndex ].szHost[0]) &&
3642 (!lpList->aEntries[ iIndex ].fDeleted) )
3644 if (lpList->aEntries[ iIndex ].fAdded)
3645 lpList->aEntries[ iIndex ].szHost[0] = TEXT('\0');
3647 lpList->aEntries[ iIndex ].fDeleted = TRUE;
3656 BOOL AfsClass_GetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3661 memset (pProperties, 0x00, sizeof(PTSPROPERTIES));
3667 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3671 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3676 // Go get the necessary properties
3681 wp.wpPtsUserMaxGet.hCell = hCell;
3683 if ((rc = Worker_DoTask (wtaskPtsUserMaxGet, &wp, &status)) == TRUE)
3684 pProperties->idUserMax = wp.wpPtsUserMaxGet.idUserMax;
3690 wp.wpPtsGroupMaxGet.hCell = hCell;
3692 if ((rc = Worker_DoTask (wtaskPtsGroupMaxGet, &wp, &status)) == TRUE)
3693 pProperties->idGroupMax = wp.wpPtsGroupMaxGet.idGroupMax;
3702 BOOL AfsClass_SetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3711 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3715 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3720 // Modify the specified properties
3725 wp.wpPtsUserMaxSet.hCell = hCell;
3726 wp.wpPtsUserMaxSet.idUserMax = pProperties->idUserMax;
3727 rc = Worker_DoTask (wtaskPtsUserMaxSet, &wp, &status);
3733 wp.wpPtsGroupMaxSet.hCell = hCell;
3734 wp.wpPtsGroupMaxSet.idGroupMax = pProperties->idGroupMax;
3735 Worker_DoTask (wtaskPtsGroupMaxSet, &wp, &status);
3744 LPIDENT AfsClass_CreateUser (LPIDENT lpiCell, LPTSTR pszUserName, LPTSTR pszInstance, LPTSTR pszPassword, int idUser, BOOL fCreateKAS, BOOL fCreatePTS, ULONG *pStatus)
3749 if (pszInstance && !*pszInstance)
3753 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserBegin, lpiCell, pszUserName, 0);
3755 // We'll need both hCell and hKAS.
3760 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3764 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3767 hKAS = lpCell->GetKasObject (&status);
3771 // First try to create a KAS entry.
3773 if (rc && fCreateKAS)
3776 wp.wpKasPrincipalCreate.hCell = hCell;
3777 wp.wpKasPrincipalCreate.hServer = hKAS;
3778 wp.wpKasPrincipalCreate.pszPrincipal = pszUserName;
3779 wp.wpKasPrincipalCreate.pszInstance = pszInstance;
3780 wp.wpKasPrincipalCreate.pszPassword = pszPassword;
3783 rc = Worker_DoTask (wtaskKasPrincipalCreate, &wp, &status);
3787 // If that succeeded, try to create a PTS entry as well.
3789 if (rc && fCreatePTS)
3791 TCHAR szUserName[ cchNAME ];
3792 lstrcpy (szUserName, pszUserName);
3794 wsprintf (&szUserName[ lstrlen(szUserName) ], TEXT(".%s"), pszInstance);
3797 wp.wpPtsUserCreate.hCell = hCell;
3798 wp.wpPtsUserCreate.pszUser = szUserName;
3799 wp.wpPtsUserCreate.idUser = idUser;
3803 if ((rc = Worker_DoTask (wtaskPtsUserCreate, &wp, &status)) == FALSE)
3805 if (status == PREXIST)
3811 // If we couldn't make a KAS entry as well, remove the KAS entry.
3816 wpDel.wpKasPrincipalDelete.hCell = hCell;
3817 wpDel.wpKasPrincipalDelete.hServer = hKAS;
3818 wpDel.wpKasPrincipalDelete.pszPrincipal = pszUserName;
3819 wpDel.wpKasPrincipalDelete.pszInstance = pszInstance;
3820 Worker_DoTask (wtaskKasPrincipalDelete, &wpDel);
3827 // If we were able to create the user's accounts successfully, refresh
3828 // the cell status and return the new user's ident.
3834 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3838 if (!lpCell->RefreshAccount (pszUserName, pszInstance, CELL_REFRESH_ACCOUNT_CREATED_USER, &lpiUser))
3846 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserEnd, lpiCell, pszUserName, status);
3851 return (rc) ? lpiUser : NULL;
3855 BOOL AfsClass_SetUserProperties (LPIDENT lpiUser, LPUSERPROPERTIES pProperties, ULONG *pStatus)
3861 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser);
3863 // We'll need both hCell and hKAS.
3868 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
3872 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3875 hKAS = lpCell->GetKasObject (&status);
3879 // We'll also need this user's current status
3883 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
3887 if (!lpUser->GetStatus (&us, TRUE, &status))
3892 // Modify the user's KAS entry (if necessary)
3894 DWORD dwKasMask = ( MASK_USERPROP_fAdmin |
3895 MASK_USERPROP_fGrantTickets |
3896 MASK_USERPROP_fCanEncrypt |
3897 MASK_USERPROP_fCanChangePassword |
3898 MASK_USERPROP_fCanReusePasswords |
3899 MASK_USERPROP_timeAccountExpires |
3900 MASK_USERPROP_cdayPwExpires |
3901 MASK_USERPROP_csecTicketLifetime |
3902 MASK_USERPROP_nFailureAttempts |
3903 MASK_USERPROP_csecFailedLoginLockTime );
3905 if (rc && (pProperties->dwMask & dwKasMask))
3907 TCHAR szPrincipal[ cchNAME ];
3908 TCHAR szInstance[ cchNAME ];
3909 lpiUser->GetUserName (szPrincipal, szInstance);
3912 wp.wpKasPrincipalFieldsSet.hCell = hCell;
3913 wp.wpKasPrincipalFieldsSet.hServer = hKAS;
3914 wp.wpKasPrincipalFieldsSet.pszPrincipal = szPrincipal;
3915 wp.wpKasPrincipalFieldsSet.pszInstance = szInstance;
3916 wp.wpKasPrincipalFieldsSet.fIsAdmin = (pProperties->dwMask & MASK_USERPROP_fAdmin) ? pProperties->fAdmin : us.KASINFO.fIsAdmin;
3917 wp.wpKasPrincipalFieldsSet.fGrantTickets = (pProperties->dwMask & MASK_USERPROP_fGrantTickets) ? pProperties->fGrantTickets : us.KASINFO.fCanGetTickets;
3918 wp.wpKasPrincipalFieldsSet.fCanEncrypt = (pProperties->dwMask & MASK_USERPROP_fCanEncrypt) ? pProperties->fCanEncrypt : us.KASINFO.fEncrypt;
3919 wp.wpKasPrincipalFieldsSet.fCanChangePassword = (pProperties->dwMask & MASK_USERPROP_fCanChangePassword) ? pProperties->fCanChangePassword : us.KASINFO.fCanChangePassword;
3920 wp.wpKasPrincipalFieldsSet.fCanReusePasswords = (pProperties->dwMask & MASK_USERPROP_fCanReusePasswords) ? pProperties->fCanReusePasswords : us.KASINFO.fCanReusePasswords;
3921 memcpy (&wp.wpKasPrincipalFieldsSet.timeExpires, (pProperties->dwMask & MASK_USERPROP_timeAccountExpires) ? &pProperties->timeAccountExpires : &us.KASINFO.timeExpires, sizeof(SYSTEMTIME));
3922 wp.wpKasPrincipalFieldsSet.cdayPwExpires = (pProperties->dwMask & MASK_USERPROP_cdayPwExpires) ? pProperties->cdayPwExpires : us.KASINFO.cdayPwExpire;
3923 wp.wpKasPrincipalFieldsSet.csecTicketLifetime = (pProperties->dwMask & MASK_USERPROP_csecTicketLifetime) ? pProperties->csecTicketLifetime : us.KASINFO.csecTicketLifetime;
3924 wp.wpKasPrincipalFieldsSet.nFailureAttempts = (pProperties->dwMask & MASK_USERPROP_nFailureAttempts) ? pProperties->nFailureAttempts : us.KASINFO.cFailLogin;
3925 wp.wpKasPrincipalFieldsSet.csecFailedLoginLockTime = (pProperties->dwMask & MASK_USERPROP_csecFailedLoginLockTime) ? pProperties->csecFailedLoginLockTime : us.KASINFO.csecFailLoginLock;
3928 rc = Worker_DoTask (wtaskKasPrincipalFieldsSet, &wp, &status);
3933 // Modify the user's PTS entry (if necessary)
3935 DWORD dwPtsMask = ( MASK_USERPROP_cGroupCreationQuota |
3936 MASK_USERPROP_aaListStatus |
3937 MASK_USERPROP_aaGroupsOwned |
3938 MASK_USERPROP_aaMembership );
3940 if (rc && (pProperties->dwMask & dwPtsMask))
3942 TCHAR szFullName[ cchNAME ];
3943 lpiUser->GetFullUserName (szFullName);
3946 wp.wpPtsUserModify.hCell = hCell;
3947 wp.wpPtsUserModify.pszUser = szFullName;
3948 memset (&wp.wpPtsUserModify.Delta, 0x00, sizeof(wp.wpPtsUserModify.Delta));
3950 if (pProperties->dwMask & MASK_USERPROP_cGroupCreationQuota)
3952 wp.wpPtsUserModify.Delta.flag = (pts_UserUpdateFlag_t)( (LONG)wp.wpPtsUserModify.Delta.flag | (LONG)PTS_USER_UPDATE_GROUP_CREATE_QUOTA );
3953 wp.wpPtsUserModify.Delta.groupCreationQuota = pProperties->cGroupCreationQuota;
3956 if (pProperties->dwMask & (MASK_USERPROP_aaListStatus | MASK_USERPROP_aaGroupsOwned | MASK_USERPROP_aaMembership))
3958 wp.wpPtsUserModify.Delta.flag = (pts_UserUpdateFlag_t)( (LONG)wp.wpPtsUserModify.Delta.flag | (LONG)PTS_USER_UPDATE_PERMISSIONS );
3959 wp.wpPtsUserModify.Delta.listStatus = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaListStatus) ? pProperties->aaListStatus : us.PTSINFO.aaListStatus );
3960 wp.wpPtsUserModify.Delta.listGroupsOwned = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaGroupsOwned) ? pProperties->aaGroupsOwned : us.PTSINFO.aaGroupsOwned );
3961 wp.wpPtsUserModify.Delta.listMembership = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaMembership) ? pProperties->aaMembership : us.PTSINFO.aaMembership );
3965 rc = Worker_DoTask (wtaskPtsUserModify, &wp, &status);
3969 // If we were able to modify the user's properties successfully, refresh
3970 // that user's status.
3972 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
3974 lpUser->Invalidate();
3975 lpUser->RefreshStatus();
3979 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser, status);
3988 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPTSTR pszPassword, ULONG *pStatus)
3993 TCHAR szCell[ cchNAME ];
3994 lpiUser->GetCellName (szCell);
3997 wp.wpKasStringToKey.pszCell = szCell;
3998 wp.wpKasStringToKey.pszString = pszPassword;
3999 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
4003 else if (!AfsClass_SetUserPassword (lpiUser, keyVersion, &wp.wpKasStringToKey.key, &status))
4014 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
4020 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordBegin, lpiUser);
4022 // We'll need both hCell and hKAS.
4027 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4031 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4034 hKAS = lpCell->GetKasObject (&status);
4038 // Change the user's password
4042 TCHAR szPrincipal[ cchNAME ];
4043 TCHAR szInstance[ cchNAME ];
4044 lpiUser->GetUserName (szPrincipal, szInstance);
4047 wp.wpKasPrincipalKeySet.hCell = hCell;
4048 wp.wpKasPrincipalKeySet.hServer = hKAS;
4049 wp.wpKasPrincipalKeySet.pszPrincipal = szPrincipal;
4050 wp.wpKasPrincipalKeySet.pszInstance = szInstance;
4051 wp.wpKasPrincipalKeySet.keyVersion = keyVersion;
4052 memcpy (&wp.wpKasPrincipalKeySet.key.key, &pKey->key, ENCRYPTIONKEY_LEN);
4055 rc = Worker_DoTask (wtaskKasPrincipalKeySet, &wp, &status);
4059 // If we were able to modify the user's password successfully, refresh
4060 // that user's status.
4063 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4065 lpUser->Invalidate();
4066 lpUser->RefreshStatus();
4070 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordEnd, lpiUser, status);
4079 BOOL AfsClass_DeleteUser (LPIDENT lpiUser, BOOL fDeleteKAS, BOOL fDeletePTS, ULONG *pStatus)
4085 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserBegin, lpiUser);
4087 // We'll need both hCell and hKAS.
4092 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4096 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4099 hKAS = lpCell->GetKasObject (&status);
4103 // Find out whether this user has KAS and/or PTS entries. Also
4104 // get the various lists of groups for this user...
4107 LPTSTR mszOwnerOf = NULL;
4108 LPTSTR mszMemberOf = NULL;
4109 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
4113 lpUser->GetOwnerOf (&mszOwnerOf);
4114 lpUser->GetMemberOf (&mszMemberOf);
4118 // Delete the user's PTS entry
4120 if (rc && fDeletePTS)
4122 TCHAR szFullName[ cchNAME ];
4123 lpiUser->GetFullUserName (szFullName);
4126 wp.wpPtsUserDelete.hCell = hCell;
4127 wp.wpPtsUserDelete.pszUser = szFullName;
4130 if ((rc = Worker_DoTask (wtaskPtsUserDelete, &wp, &status)) == FALSE)
4132 if (status == ADMPTSFAILEDNAMETRANSLATE) // User had no PTS entry?
4138 // Delete the user's KAS entry
4140 if (rc && fDeleteKAS)
4142 TCHAR szPrincipal[ cchNAME ];
4143 TCHAR szInstance[ cchNAME ];
4144 lpiUser->GetUserName (szPrincipal, szInstance);
4147 wp.wpKasPrincipalDelete.hCell = hCell;
4148 wp.wpKasPrincipalDelete.hServer = hKAS;
4149 wp.wpKasPrincipalDelete.pszPrincipal = szPrincipal;
4150 wp.wpKasPrincipalDelete.pszInstance = szInstance;
4153 if ((rc = Worker_DoTask (wtaskKasPrincipalDelete, &wp, &status)) == FALSE)
4155 if (status == KANOENT)
4161 // If we were able to delete the user's accounts successfully, refresh
4166 if ((lpCell = lpiUser->OpenCell (&status)) != NULL)
4168 TCHAR szPrincipal[ cchNAME ];
4169 TCHAR szInstance[ cchNAME ];
4170 lpiUser->GetUserName (szPrincipal, szInstance);
4172 lpCell->RefreshAccount (szPrincipal, szInstance, CELL_REFRESH_ACCOUNT_DELETED);
4173 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4174 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4179 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserEnd, lpiUser, status);
4183 FreeString (mszOwnerOf);
4185 FreeString (mszMemberOf);
4192 BOOL AfsClass_UnlockUser (LPIDENT lpiUser, ULONG *pStatus)
4198 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserBegin, lpiUser);
4200 // We'll need both hCell and hKAS.
4205 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4209 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4212 hKAS = lpCell->GetKasObject (&status);
4216 // Unlock the user's KAS entry
4220 TCHAR szPrincipal[ cchNAME ];
4221 TCHAR szInstance[ cchNAME ];
4222 lpiUser->GetUserName (szPrincipal, szInstance);
4225 wp.wpKasPrincipalUnlock.hCell = hCell;
4226 wp.wpKasPrincipalUnlock.hServer = hKAS;
4227 wp.wpKasPrincipalUnlock.pszPrincipal = szPrincipal;
4228 wp.wpKasPrincipalUnlock.pszInstance = szInstance;
4231 rc = Worker_DoTask (wtaskKasPrincipalUnlock, &wp, &status);
4235 // If we were able to unlock the user's accounts successfully, refresh
4236 // the user's properties.
4241 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4243 lpUser->Invalidate();
4244 lpUser->RefreshStatus();
4249 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserEnd, lpiUser, status);
4258 LPIDENT AfsClass_CreateGroup (LPIDENT lpiCell, LPTSTR pszGroupName, LPIDENT lpiOwner, int idGroup, ULONG *pStatus)
4264 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupBegin, lpiCell, pszGroupName, 0);
4270 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4274 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4279 // Create a PTS entry for the new group
4283 TCHAR szOwner[ cchNAME ] = TEXT("");
4284 if (lpiOwner && lpiOwner->fIsUser())
4285 lpiOwner->GetFullUserName (szOwner);
4286 else if (lpiOwner && lpiOwner->fIsGroup())
4287 lpiOwner->GetGroupName (szOwner);
4290 wp.wpPtsGroupCreate.hCell = hCell;
4291 wp.wpPtsGroupCreate.pszGroup = pszGroupName;
4292 wp.wpPtsGroupCreate.pszOwner = (szOwner[0]) ? szOwner : NULL;
4293 wp.wpPtsGroupCreate.idGroup = idGroup;
4296 rc = Worker_DoTask (wtaskPtsGroupCreate, &wp, &status);
4300 // If we were able to create the group successfully, refresh
4301 // the cell status and return the new group's ident.
4307 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4311 if (!lpCell->RefreshAccount (pszGroupName, NULL, CELL_REFRESH_ACCOUNT_CREATED_GROUP, &lpiGroup))
4319 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupEnd, lpiCell, pszGroupName, status);
4324 return (rc) ? lpiGroup : NULL;
4328 BOOL AfsClass_SetGroupProperties (LPIDENT lpiGroup, LPGROUPPROPERTIES pProperties, ULONG *pStatus)
4334 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup);
4340 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4344 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4349 // We'll also need this group's current status
4353 if ((lpGroup = lpiGroup->OpenGroup (&status)) == NULL)
4357 if (!lpGroup->GetStatus (&gs, TRUE, &status))
4362 // Modify the group's PTS entry (if requested)
4364 DWORD dwPtsMask = ( MASK_GROUPPROP_aaListStatus |
4365 MASK_GROUPPROP_aaListGroupsOwned |
4366 MASK_GROUPPROP_aaListMembers |
4367 MASK_GROUPPROP_aaAddMember |
4368 MASK_GROUPPROP_aaDeleteMember );
4370 if (rc && (pProperties->dwMask & dwPtsMask))
4372 TCHAR szGroup[ cchNAME ];
4373 lpiGroup->GetGroupName (szGroup);
4376 wp.wpPtsGroupModify.hCell = hCell;
4377 wp.wpPtsGroupModify.pszGroup = szGroup;
4378 memset (&wp.wpPtsGroupModify.Delta, 0x00, sizeof(wp.wpPtsGroupModify.Delta));
4379 wp.wpPtsGroupModify.Delta.listStatus = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListStatus) ? pProperties->aaListStatus : gs.aaListStatus );
4380 wp.wpPtsGroupModify.Delta.listGroupsOwned = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListGroupsOwned) ? pProperties->aaListGroupsOwned : gs.aaListGroupsOwned );
4381 wp.wpPtsGroupModify.Delta.listMembership = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListMembers) ? pProperties->aaListMembers : gs.aaListMembers );
4382 wp.wpPtsGroupModify.Delta.listAdd = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaAddMember) ? pProperties->aaAddMember : gs.aaAddMember );
4383 wp.wpPtsGroupModify.Delta.listDelete = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaDeleteMember) ? pProperties->aaDeleteMember : gs.aaDeleteMember );
4386 rc = Worker_DoTask (wtaskPtsGroupModify, &wp, &status);
4390 // Change the group's owner (if requested)
4392 if (rc && (pProperties->dwMask & MASK_GROUPPROP_szOwner))
4394 TCHAR szGroup[ cchNAME ];
4395 lpiGroup->GetGroupName (szGroup);
4398 wp.wpPtsGroupOwnerChange.hCell = hCell;
4399 wp.wpPtsGroupOwnerChange.pszGroup = szGroup;
4400 wp.wpPtsGroupOwnerChange.pszOwner = pProperties->szOwner;
4403 rc = Worker_DoTask (wtaskPtsGroupOwnerChange, &wp, &status);
4407 // If we were able to modify the group's properties successfully, refresh
4408 // either the group's status. If the group's owner changed, also refresh
4409 // the group's old and new owners.
4413 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4415 TCHAR szAccount[ cchNAME ];
4416 lpiGroup->GetGroupName (szAccount);
4417 lpCell->RefreshAccount (szAccount, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4419 if (pProperties->dwMask & MASK_GROUPPROP_szOwner)
4421 lpCell->RefreshAccount (gs.szOwner, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4422 lpCell->RefreshAccount (pProperties->szOwner, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4429 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup, status);
4438 BOOL AfsClass_RenameGroup (LPIDENT lpiGroup, LPTSTR pszNewName, ULONG *pStatus)
4444 NOTIFYCALLBACK::SendNotificationToAll (evtRenameGroupBegin, lpiGroup);
4450 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4454 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4459 // Get this group's list of members (etc)
4461 LPTSTR mszOwnerOf = NULL;
4462 LPTSTR mszMemberOf = NULL;
4463 LPTSTR mszMembers = NULL;
4466 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4468 lpGroup->GetOwnerOf (&mszOwnerOf);
4469 lpGroup->GetMemberOf (&mszMemberOf);
4470 lpGroup->GetMembers (&mszMembers);
4474 // Rename the group's PTS entry
4478 TCHAR szGroup[ cchNAME ];
4479 lpiGroup->GetGroupName (szGroup);
4482 wp.wpPtsGroupRename.hCell = hCell;
4483 wp.wpPtsGroupRename.pszGroup = szGroup;
4484 wp.wpPtsGroupRename.pszNewName = pszNewName;
4487 rc = Worker_DoTask (wtaskPtsGroupRename, &wp, &status);
4491 // If we were able to rename the group successfully, refresh the cell status.
4496 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4498 lpGroup->ChangeIdentName (pszNewName);
4501 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4503 lpCell->RefreshAccount (pszNewName, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4504 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4505 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4506 lpCell->RefreshAccounts (mszMembers, CELL_REFRESH_ACCOUNT_CHANGED);
4511 NOTIFYCALLBACK::SendNotificationToAll (evtRenameGroupEnd, lpiGroup, status);
4515 FreeString (mszOwnerOf);
4517 FreeString (mszMemberOf);
4519 FreeString (mszMembers);
4526 BOOL AfsClass_DeleteGroup (LPIDENT lpiGroup, ULONG *pStatus)
4532 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteGroupBegin, lpiGroup);
4538 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4542 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4547 // Get this group's list of members (etc)
4549 LPTSTR mszOwnerOf = NULL;
4550 LPTSTR mszMemberOf = NULL;
4551 LPTSTR mszMembers = NULL;
4554 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4556 lpGroup->GetOwnerOf (&mszOwnerOf);
4557 lpGroup->GetMemberOf (&mszMemberOf);
4558 lpGroup->GetMembers (&mszMembers);
4562 // Delete the group's PTS entry
4566 TCHAR szGroup[ cchNAME ];
4567 lpiGroup->GetGroupName (szGroup);
4570 wp.wpPtsGroupDelete.hCell = hCell;
4571 wp.wpPtsGroupDelete.pszGroup = szGroup;
4574 if ((rc = Worker_DoTask (wtaskPtsGroupDelete, &wp, &status)) == FALSE)
4576 if (status == ADMPTSFAILEDNAMETRANSLATE) // Group had no PTS entry?
4582 // If we were able to delete the group successfully, refresh the cell status.
4586 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4588 TCHAR szGroup[ cchNAME ];
4589 lpiGroup->GetGroupName (szGroup);
4590 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4591 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4592 lpCell->RefreshAccounts (mszMembers, CELL_REFRESH_ACCOUNT_CHANGED);
4593 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_DELETED);
4598 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteGroupEnd, lpiGroup, status);
4602 FreeString (mszOwnerOf);
4604 FreeString (mszMemberOf);
4606 FreeString (mszMembers);
4613 BOOL AfsClass_AddUserToGroup (LPIDENT lpiGroup, LPIDENT lpiUser, ULONG *pStatus)
4619 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberAddBegin, lpiGroup, lpiUser, NULL, NULL, 0, 0);
4625 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4629 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4634 TCHAR szGroup[ cchNAME ];
4635 lpiGroup->GetGroupName (szGroup);
4637 TCHAR szMember[ cchNAME ];
4638 if (lpiUser->fIsUser())
4639 lpiUser->GetFullUserName (szMember);
4640 else // (lpiUser->fIsGroup())
4641 lpiUser->GetGroupName (szMember);
4643 // Add this user to the specified group
4648 wp.wpPtsGroupMemberAdd.hCell = hCell;
4649 wp.wpPtsGroupMemberAdd.pszGroup = szGroup;
4650 wp.wpPtsGroupMemberAdd.pszUser = szMember;
4653 rc = Worker_DoTask (wtaskPtsGroupMemberAdd, &wp, &status);
4657 // If we were able to change the group successfully, update the group's
4658 // and user's properties.
4662 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4664 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4665 lpCell->RefreshAccount (szMember, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4670 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberAddEnd, lpiGroup, lpiUser, NULL, NULL, 0, status);
4679 BOOL AfsClass_RemoveUserFromGroup (LPIDENT lpiGroup, LPIDENT lpiUser, ULONG *pStatus)
4685 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberRemoveBegin, lpiGroup, lpiUser, NULL, NULL, 0, 0);
4691 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4695 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4700 TCHAR szGroup[ cchNAME ];
4701 lpiGroup->GetGroupName (szGroup);
4703 TCHAR szMember[ cchNAME ];
4704 if (lpiUser->fIsUser())
4705 lpiUser->GetFullUserName (szMember);
4706 else // (lpiUser->fIsGroup())
4707 lpiUser->GetGroupName (szMember);
4709 // Remove this user from the specified group
4714 wp.wpPtsGroupMemberRemove.hCell = hCell;
4715 wp.wpPtsGroupMemberRemove.pszGroup = szGroup;
4716 wp.wpPtsGroupMemberRemove.pszUser = szMember;
4719 rc = Worker_DoTask (wtaskPtsGroupMemberRemove, &wp, &status);
4723 // If we were able to change the group successfully, update the group's
4724 // and user's properties.
4728 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4730 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4731 lpCell->RefreshAccount (szMember, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4736 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberRemoveEnd, lpiGroup, lpiUser, NULL, NULL, 0, status);