2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
14 #include <afsconfig.h>
15 #include <afs/param.h>
20 #include <WINNT/afsclass.h>
25 * DEFINITIONS ________________________________________________________________
29 #define cREALLOC_ADMINLISTENTRIES 32
31 #define cREALLOC_HOSTLISTENTRIES 16
33 #define cREALLOC_SERVERKEYS 16
35 #define ACCOUNTACCESS_TO_USERACCESS(_aa) ( ((_aa) == aaOWNER_ONLY) ? PTS_USER_OWNER_ACCESS : PTS_USER_ANYUSER_ACCESS )
37 #define ACCOUNTACCESS_TO_GROUPACCESS(_aa) ( ((_aa) == aaOWNER_ONLY) ? PTS_GROUP_OWNER_ACCESS : ((_aa) == aaGROUP_ONLY) ? PTS_GROUP_ACCESS : PTS_GROUP_ANYUSER_ACCESS )
41 * PROTOTYPES _________________________________________________________________
47 * ROUTINES ___________________________________________________________________
51 BOOL AfsClass_GetServerLogFile (LPIDENT lpiServer, LPTSTR pszLocal, LPTSTR pszRemote, ULONG *pStatus)
57 NOTIFYCALLBACK::SendNotificationToAll (evtGetServerLogFileBegin, lpiServer, pszRemote, 0);
61 LPSERVER lpServer = NULL;
62 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
66 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
74 wp.wpBosLogGet.hServer = hBOS;
75 wp.wpBosLogGet.pszLogName = pszRemote;
76 wp.wpBosLogGet.pszLogData = NULL;
79 if ((rc = Worker_DoTask (wtaskBosLogGet, &wp, &status)) == TRUE)
82 if ((fh = CreateFile (pszLocal, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL)) != INVALID_HANDLE_VALUE)
84 // Write the file a line at a time in order to make
85 // sure that each line ends with "\r\n". If we encounter
86 // a line which ends in \r\n already, well, leave it alone.
88 for (LPTSTR psz = wp.wpBosLogGet.pszLogData; psz && *psz; )
91 for (pszNext = psz; *pszNext && (*pszNext != TEXT('\r')) && (*pszNext != TEXT('\n')); ++pszNext)
95 if ((cbWrite = (DWORD)(pszNext - psz)) != 0)
96 WriteFile (fh, psz, cbWrite, &cbWrote, NULL);
97 WriteFile (fh, TEXT("\r\n"), 2, &cbWrote, NULL);
98 psz = (*pszNext == TEXT('\r')) ? (2+pszNext) : (*pszNext == TEXT('\n')) ? (1+pszNext) : NULL;
103 Free (wp.wpBosLogGet.pszLogData);
109 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
111 lpServer->CloseBosObject();
115 NOTIFYCALLBACK::SendNotificationToAll (evtGetServerLogFileEnd, lpiServer, pszRemote, status);
124 BOOL AfsClass_SetServerAuth (LPIDENT lpiServer, BOOL fEnabled, ULONG *pStatus)
130 NOTIFYCALLBACK::SendNotificationToAll (evtSetServerAuthBegin, lpiServer);
135 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
139 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
147 wp.wpBosAuthSet.hServer = hBOS;
148 wp.wpBosAuthSet.fEnableAuth = fEnabled;
151 rc = Worker_DoTask (wtaskBosAuthSet, &wp, &status);
155 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
157 lpServer->CloseBosObject();
161 NOTIFYCALLBACK::SendNotificationToAll (evtSetServerAuthEnd, lpiServer, status);
170 BOOL AfsClass_StartService (LPIDENT lpiStart, BOOL fTemporary, ULONG *pStatus)
176 NOTIFYCALLBACK::SendNotificationToAll (evtStartServiceBegin, lpiStart);
181 if ((lpServer = lpiStart->OpenServer (&status)) == NULL)
185 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
192 if (lpiStart->fIsService())
194 TCHAR szName[ cchNAME ];
195 lpiStart->GetServiceName (szName);
200 wp.wpBosProcessExecutionStateSetTemporary.hServer = hBOS;
201 wp.wpBosProcessExecutionStateSetTemporary.pszService = szName;
202 wp.wpBosProcessExecutionStateSetTemporary.state = SERVICESTATE_RUNNING;
205 rc = Worker_DoTask (wtaskBosProcessExecutionStateSetTemporary, &wp, &status);
211 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
212 wp.wpBosProcessExecutionStateSet.pszService = szName;
213 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_RUNNING;
216 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
223 wp.wpBosProcessAllStart.hServer = hBOS;
225 rc = Worker_DoTask (wtaskBosProcessAllStart, &wp, &status);
232 if (lpiStart->fIsService())
235 if ((lpService = lpiStart->OpenService (&status)) == NULL)
239 lpService->Invalidate();
240 lpService->RefreshStatus();
246 if ((lpServer = lpiStart->OpenServer (&status)) == NULL)
250 lpServer->Invalidate();
251 lpServer->RefreshAll();
257 if ((lpServer = lpiStart->OpenServer (&status)) != NULL)
259 lpServer->CloseBosObject();
263 NOTIFYCALLBACK::SendNotificationToAll (evtStartServiceEnd, lpiStart, status);
272 BOOL AfsClass_StopService (LPIDENT lpiStop, BOOL fTemporary, BOOL fWait, ULONG *pStatus)
278 NOTIFYCALLBACK::SendNotificationToAll (evtStopServiceBegin, lpiStop);
283 if ((lpServer = lpiStop->OpenServer (&status)) == NULL)
287 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
294 if (lpiStop->fIsService())
296 TCHAR szName[ cchNAME ];
297 lpiStop->GetServiceName (szName);
302 wp.wpBosProcessExecutionStateSetTemporary.hServer = hBOS;
303 wp.wpBosProcessExecutionStateSetTemporary.pszService = szName;
304 wp.wpBosProcessExecutionStateSetTemporary.state = SERVICESTATE_STOPPED;
305 // TODO: wp.wpStopBosProcessTemporary.fWait = TRUE;
308 rc = Worker_DoTask (wtaskBosProcessExecutionStateSetTemporary, &wp, &status);
314 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
315 wp.wpBosProcessExecutionStateSet.pszService = szName;
316 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
317 // TODO: wp.wpStopBosProcess.fWait = TRUE;
320 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
327 wp.wpBosProcessAllWaitStop.hServer = hBOS;
330 rc = Worker_DoTask (wtaskBosProcessAllWaitStop, &wp, &status);
336 wp.wpBosProcessAllStop.hServer = hBOS;
339 rc = Worker_DoTask (wtaskBosProcessAllStop, &wp, &status);
346 if (lpiStop->fIsService())
349 if ((lpService = lpiStop->OpenService (&status)) == NULL)
353 lpService->Invalidate();
354 lpService->RefreshStatus();
361 if ((lpServer = lpiStop->OpenServer (&status)) == NULL)
365 lpServer->Invalidate();
366 lpServer->RefreshAll();
372 if ((lpServer = lpiStop->OpenServer (&status)) != NULL)
374 lpServer->CloseBosObject();
378 NOTIFYCALLBACK::SendNotificationToAll (evtStopServiceEnd, lpiStop, status);
387 BOOL AfsClass_RestartService (LPIDENT lpiRestart, ULONG *pStatus)
393 NOTIFYCALLBACK::SendNotificationToAll (evtRestartServiceBegin, lpiRestart);
398 if ((lpServer = lpiRestart->OpenServer (&status)) == NULL)
402 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
407 BOOL fRestartAll = FALSE;
408 if (!lpiRestart->fIsService())
411 TCHAR szServiceRestart[ cchNAME ];
412 if (lpiRestart->fIsService())
414 lpiRestart->GetServiceName (szServiceRestart);
415 if (!lstrcmpi (szServiceRestart, TEXT("BOS")))
424 wp.wpBosProcessRestart.hServer = hBOS;
425 wp.wpBosProcessRestart.pszService = szServiceRestart;
428 rc = Worker_DoTask (wtaskBosProcessRestart, &wp, &status);
431 else // (fRestartAll)
434 wp.wpBosProcessAllStopAndRestart.hServer = hBOS;
435 wp.wpBosProcessAllStopAndRestart.fRestartBOS = TRUE;
438 rc = Worker_DoTask (wtaskBosProcessAllStopAndRestart, &wp, &status);
448 if ((lpService = lpiRestart->OpenService (&status)) == NULL)
452 lpService->Invalidate();
453 lpService->RefreshStatus();
457 else // (fRestartAll)
460 if ((lpServer = lpiRestart->OpenServer (&status)) == NULL)
464 lpServer->Invalidate();
465 lpServer->RefreshAll();
471 if ((lpServer = lpiRestart->OpenServer (&status)) != NULL)
473 lpServer->CloseBosObject();
477 NOTIFYCALLBACK::SendNotificationToAll (evtRestartServiceEnd, lpiRestart, status);
486 LPIDENT AfsClass_CreateFileset (LPIDENT lpiAggregate, LPTSTR pszFileset, ULONG ckQuota, ULONG *pStatus)
488 LPIDENT lpiFileset = NULL;
493 NOTIFYCALLBACK::SendNotificationToAll (evtCreateFilesetBegin, lpiAggregate, pszFileset, 0);
495 // Obtain hCell and hVOS
499 LPSERVER lpServer = NULL;
500 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
504 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
509 // Obtain idPartition
512 LPAGGREGATE lpAggregate;
513 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
517 idPartition = lpAggregate->GetID();
518 lpAggregate->Close();
521 // Perform the actual operation
526 wp.wpVosVolumeCreate.hCell = hCell;
527 wp.wpVosVolumeCreate.hServer = hVOS;
528 wp.wpVosVolumeCreate.idPartition = idPartition;
529 wp.wpVosVolumeCreate.pszVolume = pszFileset;
530 wp.wpVosVolumeCreate.ckQuota = ckQuota;
533 rc = Worker_DoTask (wtaskVosVolumeCreate, &wp, &status);
541 LPAGGREGATE lpAggregate;
542 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
546 lpAggregate->Invalidate();
547 lpAggregate->RefreshFilesets (TRUE, &status);
548 lpAggregate->Close();
555 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
559 lpCell->RefreshVLDB (lpiAggregate);
566 LPAGGREGATE lpAggregate;
567 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
572 if ((lpFileset = lpAggregate->OpenFileset (pszFileset, &status)) == NULL)
576 lpiFileset = lpFileset->GetIdentifier();
579 lpAggregate->Close();
585 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
587 lpServer->CloseVosObject();
592 NOTIFYCALLBACK::SendNotificationToAll (evtCreateFilesetEnd, lpiAggregate, pszFileset, status);
597 return (rc) ? lpiFileset : NULL;
601 BOOL AfsClass_DeleteFileset (LPIDENT lpiFileset, BOOL fVLDB, BOOL fServer, ULONG *pStatus)
607 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiFileset);
609 // Obtain hCell and hVOS
613 LPSERVER lpServer = NULL;
614 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
618 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
623 // Does the fileset have a VLDB entry? Does it actually exist on the server?
624 // What's its volume ID? Its R/W ID? Its partition ID?
627 VOLUMEID vidReadWrite;
630 // Obtain the ID of the fileset's parent aggregate.
633 LPAGGREGATE lpAggregate;
634 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
638 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
640 lpAggregate->Close();
646 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
650 wFilesetGhost = lpFileset->GetGhostStatus();
651 lpiFileset->GetFilesetID (&vidFileset);
654 if (!lpFileset->GetStatus (&fs))
655 vidReadWrite = vidFileset;
657 vidReadWrite = fs.idReadWrite;
663 if (!(wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
665 if (!(wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
668 if (rc && fVLDB && fServer)
671 wp.wpVosVolumeDelete.hCell = hCell;
672 wp.wpVosVolumeDelete.hServer = hVOS;
673 wp.wpVosVolumeDelete.idPartition = idPartition;
674 wp.wpVosVolumeDelete.idVolume = vidFileset;
677 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
680 else if (rc && fVLDB)
683 wp.wpVosVLDBEntryRemove.hCell = hCell;
684 wp.wpVosVLDBEntryRemove.hServer = hVOS;
685 wp.wpVosVLDBEntryRemove.idPartition = idPartition;
686 wp.wpVosVLDBEntryRemove.idVolume = vidReadWrite;
689 rc = Worker_DoTask (wtaskVosVLDBEntryRemove, &wp, &status);
692 else if (rc && fServer)
695 wp.wpVosVolumeZap.hCell = hCell;
696 wp.wpVosVolumeZap.hServer = hVOS;
697 wp.wpVosVolumeZap.idPartition = idPartition;
698 wp.wpVosVolumeZap.idVolume = vidFileset;
699 wp.wpVosVolumeZap.fForce = TRUE;
702 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
708 LPAGGREGATE lpAggregate;
709 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
713 lpAggregate->Invalidate();
714 lpAggregate->RefreshFilesets (TRUE);
715 lpAggregate->Close();
722 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
726 lpCell->RefreshVLDB (lpiFileset->GetAggregate(), TRUE);
733 if ((lpServer = lpiFileset->OpenServer()) != NULL)
735 lpServer->CloseVosObject();
740 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiFileset, status);
749 BOOL AfsClass_MoveFileset (LPIDENT lpiFileset, LPIDENT lpiAggregateTarget, ULONG *pStatus)
755 NOTIFYCALLBACK::SendNotificationToAll (evtMoveFilesetBegin, lpiFileset, lpiAggregateTarget, NULL, NULL, 0, 0);
757 LPIDENT lpiAggregateSource = lpiFileset->GetAggregate();
759 // Obtain hCell, hVOS and the aggregate name for the source
762 PVOID hVOSSource = NULL;
764 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
768 if ((hVOSSource = lpServer->OpenVosObject (&hCell, &status)) == NULL)
773 // Obtain the ID of the source aggregate
775 int idPartitionSource;
776 LPAGGREGATE lpAggregate;
777 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
781 if ((idPartitionSource = lpAggregate->GetID()) == NO_PARTITION)
783 lpAggregate->Close();
786 // Obtain hCell, hVOS and the aggregate name for the target
788 PVOID hVOSTarget = NULL;
789 if ((lpServer = lpiAggregateTarget->OpenServer (&status)) == NULL)
793 if ((hVOSTarget = lpServer->OpenVosObject (NULL, &status)) == NULL)
798 // Obtain the ID of the target aggregate
800 int idPartitionTarget;
801 if ((lpAggregate = lpiAggregateTarget->OpenAggregate (&status)) == NULL)
805 if ((idPartitionTarget = lpAggregate->GetID()) == NO_PARTITION)
807 lpAggregate->Close();
813 wp.wpVosVolumeMove.hCell = hCell;
814 wp.wpVosVolumeMove.hServerFrom = hVOSSource;
815 wp.wpVosVolumeMove.idPartitionFrom = idPartitionSource;
816 wp.wpVosVolumeMove.hServerTo = hVOSTarget;
817 wp.wpVosVolumeMove.idPartitionTo = idPartitionTarget;
818 lpiFileset->GetFilesetID (&wp.wpVosVolumeMove.idVolume);
821 rc = Worker_DoTask (wtaskVosVolumeMove, &wp, &status);
827 LPAGGREGATE lpAggregate;
828 if ((lpAggregate = lpiAggregateSource->OpenAggregate (&status)) == NULL)
832 lpAggregate->Invalidate();
833 lpAggregate->RefreshFilesets();
834 lpAggregate->Close();
840 LPAGGREGATE lpAggregate;
841 if ((lpAggregate = lpiAggregateTarget->OpenAggregate (&status)) == NULL)
845 lpAggregate->Invalidate();
846 lpAggregate->RefreshFilesets();
847 lpAggregate->Close();
854 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
858 lpFileset->Invalidate();
859 lpFileset->RefreshStatus();
867 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
871 lpCell->RefreshVLDB (lpiAggregateSource, TRUE);
872 lpCell->RefreshVLDB (lpiAggregateTarget, TRUE);
879 if ((lpServer = lpiAggregateSource->OpenServer()) != NULL)
881 lpServer->CloseVosObject();
887 if ((lpServer = lpiAggregateTarget->OpenServer()) != NULL)
889 lpServer->CloseVosObject();
894 NOTIFYCALLBACK::SendNotificationToAll (evtMoveFilesetEnd, lpiFileset, lpiAggregateTarget, NULL, NULL, 0, status);
903 BOOL AfsClass_SetFilesetQuota (LPIDENT lpiFileset, size_t ckQuotaNew, ULONG *pStatus)
909 NOTIFYCALLBACK::SendNotificationToAll (evtSetFilesetQuotaBegin, lpiFileset);
911 // Obtain hCell and hVOS for the server where this fileset lives
916 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
920 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
925 // Obtain the ID of the fileset's parent aggregate.
930 LPAGGREGATE lpAggregate;
931 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
935 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
937 lpAggregate->Close();
941 // Change the fileset's quota.
946 wp.wpVosVolumeQuotaChange.hCell = hCell;
947 wp.wpVosVolumeQuotaChange.hServer = hVOS;
948 wp.wpVosVolumeQuotaChange.idPartition = idPartition;
949 lpiFileset->GetFilesetID (&wp.wpVosVolumeQuotaChange.idVolume);
950 wp.wpVosVolumeQuotaChange.ckQuota = ckQuotaNew;
953 rc = Worker_DoTask (wtaskVosVolumeQuotaChange, &wp, &status);
960 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
964 lpFileset->Invalidate();
965 lpFileset->RefreshStatus();
972 LPAGGREGATE lpAggregate;
973 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
977 lpAggregate->RefreshStatus();
978 lpAggregate->Close();
984 if ((lpServer = lpiFileset->OpenServer()) != NULL)
986 lpServer->CloseVosObject();
991 NOTIFYCALLBACK::SendNotificationToAll (evtSetFilesetQuotaEnd, lpiFileset, status);
1000 BOOL AfsClass_SyncVLDB (LPIDENT lpiSync, BOOL fForce, ULONG *pStatus)
1006 NOTIFYCALLBACK::SendNotificationToAll (evtSyncVLDBBegin, lpiSync);
1008 // Obtain hCell and hVOS
1013 if ((lpServer = lpiSync->OpenServer (&status)) == NULL)
1017 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1022 // Obtain the ID of the target aggregate.
1024 int idPartition = NO_PARTITION;
1025 if (rc && (lpiSync->fIsAggregate() || lpiSync->fIsFileset()))
1027 LPAGGREGATE lpAggregate;
1028 if ((lpAggregate = lpiSync->OpenAggregate (&status)) == NULL)
1032 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1034 lpAggregate->Close();
1041 wp.wpVosVLDBSync.hCell = hCell;
1042 wp.wpVosVLDBSync.hServer = hVOS;
1043 wp.wpVosVLDBSync.idPartition = idPartition;
1044 wp.wpVosVLDBSync.fForce = fForce;
1047 rc = Worker_DoTask (wtaskVosVLDBSync, &wp, &status);
1053 if (lpiSync->fIsServer())
1056 if ((lpServer = lpiSync->OpenServer (&status)) == NULL)
1060 lpServer->Invalidate();
1061 rc = lpServer->RefreshAll (&status);
1065 else // (lpiSync->fIsAggregate())
1067 LPAGGREGATE lpAggregate;
1068 if ((lpAggregate = lpiSync->OpenAggregate (&status)) == NULL)
1072 lpAggregate->Invalidate();
1073 lpAggregate->RefreshStatus();
1074 lpAggregate->RefreshFilesets();
1075 lpAggregate->Close();
1078 if ((lpCell = lpiSync->OpenCell()) == NULL)
1082 lpCell->RefreshVLDB (lpiSync);
1091 if ((lpServer = lpiSync->OpenServer()) != NULL)
1093 lpServer->CloseVosObject();
1098 NOTIFYCALLBACK::SendNotificationToAll (evtSyncVLDBEnd, lpiSync, status);
1107 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSOCKADDR_IN pAddrOld, LPSOCKADDR_IN pAddrNew, ULONG *pStatus)
1113 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1119 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1123 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1131 wp.wpVosFileServerAddressChange.hCell = hCell;
1132 wp.wpVosFileServerAddressChange.addrOld = *pAddrOld;
1133 wp.wpVosFileServerAddressChange.addrNew = *pAddrNew;
1136 rc = Worker_DoTask (wtaskVosFileServerAddressChange, &wp, &status);
1139 else if (rc && !pAddrNew)
1142 wp.wpVosFileServerAddressRemove.hCell = hCell;
1143 wp.wpVosFileServerAddressRemove.addr = *pAddrOld;
1146 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1153 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1155 lpServer->InvalidateStatus();
1159 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1163 lpCell->InvalidateServers ();
1164 rc = lpCell->RefreshServers (TRUE, &status);
1169 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1178 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSERVERSTATUS pStatusOld, LPSERVERSTATUS pStatusNew, ULONG *pStatus)
1184 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1190 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1194 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1203 for (size_t iAddr = 0; rc && (iAddr < AFSCLASS_MAX_ADDRESSES_PER_SITE); ++iAddr)
1207 AfsClass_AddressToInt (&oldAddress, &pStatusOld->aAddresses[ iAddr ]);
1208 AfsClass_AddressToInt (&newAddress, &pStatusNew->aAddresses[ iAddr ]);
1210 if (oldAddress && newAddress && (oldAddress != newAddress))
1213 wp.wpVosFileServerAddressChange.hCell = hCell;
1214 wp.wpVosFileServerAddressChange.addrOld = pStatusOld->aAddresses[ iAddr ];
1215 wp.wpVosFileServerAddressChange.addrNew = pStatusNew->aAddresses[ iAddr ];
1217 rc = Worker_DoTask (wtaskVosFileServerAddressChange, &wp, &status);
1219 else if (oldAddress && !newAddress)
1222 wp.wpVosFileServerAddressRemove.hCell = hCell;
1223 wp.wpVosFileServerAddressRemove.addr = pStatusOld->aAddresses[ iAddr ];
1225 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1235 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1237 lpServer->InvalidateStatus();
1242 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1246 lpCell->InvalidateServers ();
1247 rc = lpCell->RefreshServers (TRUE, &status);
1252 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1261 BOOL AfsClass_LockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1267 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetBegin, lpiFileset);
1273 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1277 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1282 // Obtain the fileset's read-write identifier
1284 LPIDENT lpiRW = NULL;
1285 LPFILESET lpFileset;
1286 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1290 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1295 // Perform the lock operation
1300 wp.wpVosVLDBEntryLock.hCell = hCell;
1301 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryLock.idVolume);
1304 rc = Worker_DoTask (wtaskVosVLDBEntryLock, &wp, &status);
1311 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1316 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1318 lpCell->RefreshVLDB (lpiFileset->GetCell());
1323 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetEnd, lpiFileset, status);
1332 BOOL AfsClass_UnlockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1338 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetBegin, lpiFileset);
1344 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1348 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1353 // Obtain the fileset's read-write identifier
1355 LPIDENT lpiRW = NULL;
1356 LPFILESET lpFileset;
1357 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1361 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1366 // Perform the unlock operation
1371 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1372 wp.wpVosVLDBEntryUnlock.hServer = NULL;
1373 wp.wpVosVLDBEntryUnlock.idPartition = NO_PARTITION;
1374 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryUnlock.idVolume);
1377 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1384 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1389 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1391 lpCell->RefreshVLDB (lpiFileset->GetCell());
1396 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetEnd, lpiFileset, status);
1405 BOOL AfsClass_UnlockAllFilesets (LPIDENT lpi, ULONG *pStatus)
1411 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsBegin, lpi);
1417 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1421 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1426 // Obtain hServer if appropriate
1429 if (lpi && (!lpi->fIsCell()))
1432 if ((lpServer = lpi->OpenServer (&status)) == NULL)
1436 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
1442 // Obtain the ID of the scope aggregate.
1444 int idPartition = NO_PARTITION;
1445 if (rc && (lpi->fIsFileset() || (lpi->fIsAggregate())))
1447 LPAGGREGATE lpAggregate;
1448 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
1452 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1454 lpAggregate->Close();
1458 // Perform the unlock operation
1463 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1464 wp.wpVosVLDBEntryUnlock.hServer = hVOS;
1465 wp.wpVosVLDBEntryUnlock.idPartition = idPartition;
1466 wp.wpVosVLDBEntryUnlock.idVolume = NO_VOLUME;
1469 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1476 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1480 lpCell->RefreshVLDB (lpi);
1488 if ((lpServer = lpi->OpenServer (&status)) != NULL)
1490 lpServer->CloseVosObject();
1495 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsEnd, lpi);
1504 LPIDENT AfsClass_CreateReplica (LPIDENT lpiFileset, LPIDENT lpiAggregate, ULONG *pStatus)
1508 LPIDENT lpiReplica = NULL;
1511 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaBegin, lpiFileset, lpiAggregate, NULL, NULL, 0, 0);
1513 // Obtain hCell and hVOS for the target server
1518 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
1522 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1527 // Obtain idPartition
1530 LPAGGREGATE lpAggregate;
1531 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1535 idPartition = lpAggregate->GetID();
1536 lpAggregate->Close();
1539 // Modify VLDB to create mention of a new replica
1544 wp.wpVosVLDBReadOnlySiteCreate.hCell = hCell;
1545 wp.wpVosVLDBReadOnlySiteCreate.hServer = hVOS;
1546 wp.wpVosVLDBReadOnlySiteCreate.idPartition = idPartition;
1547 lpiFileset->GetFilesetID (&wp.wpVosVLDBReadOnlySiteCreate.idVolume);
1550 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteCreate, &wp, &status);
1558 LPAGGREGATE lpAggregate;
1559 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1563 lpAggregate->Invalidate();
1564 lpAggregate->RefreshFilesets (TRUE, &status);
1565 lpAggregate->Close();
1572 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
1576 lpCell->RefreshVLDB (lpiAggregate);
1583 LPFILESET lpFileset;
1584 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1588 if ((lpiReplica = lpFileset->GetReadOnlyIdentifier (lpiAggregate, &status)) == NULL)
1596 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
1598 lpServer->CloseVosObject();
1603 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaEnd, lpiFileset, lpiAggregate, NULL, NULL, 0, status);
1608 return (rc) ? lpiReplica : FALSE;
1612 BOOL AfsClass_DeleteReplica (LPIDENT lpiReplica, ULONG *pStatus)
1618 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiReplica);
1620 // Obtain hCell and hVOS for the server
1625 if ((lpServer = lpiReplica->OpenServer (&status)) == NULL)
1629 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1634 // Get the read/write fileset identifier and Ghost status
1636 LPIDENT lpiRW = NULL;
1637 int wFilesetGhost = 0;
1638 LPFILESET lpFileset;
1639 if ((lpFileset = lpiReplica->OpenFileset (&status)) == NULL)
1643 wFilesetGhost = lpFileset->GetGhostStatus();
1644 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1649 TCHAR szAggregateName[ cchNAME ];
1650 lpiReplica->GetAggregateName (szAggregateName);
1652 // Obtain the ID of the replica's partition
1655 LPAGGREGATE lpAggregate;
1656 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1660 idPartition = lpAggregate->GetID();
1661 lpAggregate->Close();
1664 // If the volume exists in both VLDB and on the server, just delete it
1666 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY) && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1669 wp.wpVosVolumeDelete.hCell = hCell;
1670 wp.wpVosVolumeDelete.hServer = hVOS;
1671 wp.wpVosVolumeDelete.idPartition = idPartition;
1672 lpiReplica->GetFilesetID (&wp.wpVosVolumeDelete.idVolume);
1675 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
1680 // If necessary, modify VLDB to remove mention of this replica
1682 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
1685 wp.wpVosVLDBReadOnlySiteDelete.hCell = hCell;
1686 wp.wpVosVLDBReadOnlySiteDelete.hServer = hVOS;
1687 wp.wpVosVLDBReadOnlySiteDelete.idPartition = idPartition;
1688 lpiRW->GetFilesetID (&wp.wpVosVLDBReadOnlySiteDelete.idVolume);
1691 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteDelete, &wp, &status);
1695 // If necessary, zap the volume
1697 if (rc && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1700 wp.wpVosVolumeZap.hCell = hCell;
1701 wp.wpVosVolumeZap.hServer = hVOS;
1702 wp.wpVosVolumeZap.idPartition = idPartition;
1703 lpiReplica->GetFilesetID (&wp.wpVosVolumeZap.idVolume);
1704 wp.wpVosVolumeZap.fForce = TRUE;
1707 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
1716 LPAGGREGATE lpAggregate;
1717 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1721 lpAggregate->Invalidate();
1722 lpAggregate->RefreshFilesets (TRUE, &status);
1723 lpAggregate->Close();
1730 if ((lpCell = lpiReplica->OpenCell()) == NULL)
1734 lpCell->RefreshVLDB (lpiReplica->GetAggregate());
1741 if ((lpServer = lpiReplica->OpenServer (&status)) != NULL)
1743 lpServer->CloseVosObject();
1748 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiReplica, status);
1757 BOOL AfsClass_DeleteClone (LPIDENT lpiClone, ULONG *pStatus)
1759 return AfsClass_DeleteFileset (lpiClone, TRUE, TRUE, pStatus);
1763 BOOL AfsClass_InstallFile (LPIDENT lpiServer, LPTSTR pszTarget, LPTSTR pszSource, ULONG *pStatus)
1769 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileBegin, lpiServer, pszSource, 0);
1774 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1778 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1786 wp.wpBosExecutableCreate.hServer = hBOS;
1787 wp.wpBosExecutableCreate.pszLocal = pszSource;
1788 wp.wpBosExecutableCreate.pszRemoteDir = pszTarget;
1791 rc = Worker_DoTask (wtaskBosExecutableCreate, &wp, &status);
1795 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1797 lpServer->CloseBosObject();
1801 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileEnd, lpiServer, pszSource, status);
1810 BOOL AfsClass_UninstallFile (LPIDENT lpiServer, LPTSTR pszUninstall, ULONG *pStatus)
1816 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileBegin, lpiServer, pszUninstall, 0);
1821 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1825 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1833 wp.wpBosExecutableRevert.hServer = hBOS;
1834 wp.wpBosExecutableRevert.pszFilename = pszUninstall;
1837 rc = Worker_DoTask (wtaskBosExecutableRevert, &wp, &status);
1841 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1843 lpServer->CloseBosObject();
1847 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileEnd, lpiServer, pszUninstall, status);
1856 BOOL AfsClass_PruneOldFiles (LPIDENT lpiServer, BOOL fBAK, BOOL fOLD, BOOL fCore, ULONG *pStatus)
1862 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesBegin, lpiServer);
1867 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1871 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1879 wp.wpBosExecutablePrune.hServer = hBOS;
1880 wp.wpBosExecutablePrune.fPruneBak = fBAK;
1881 wp.wpBosExecutablePrune.fPruneOld = fOLD;
1882 wp.wpBosExecutablePrune.fPruneCore = fCore;
1885 rc = Worker_DoTask (wtaskBosExecutablePrune, &wp, &status);
1889 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1891 lpServer->CloseBosObject();
1895 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesEnd, lpiServer, status);
1904 BOOL AfsClass_RenameFileset (LPIDENT lpiFileset, LPTSTR pszNewName, ULONG *pStatus)
1910 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetBegin, lpiFileset, pszNewName, 0);
1914 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1918 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1926 wp.wpVosVolumeRename.hCell = hCell;
1927 lpiFileset->GetFilesetID (&wp.wpVosVolumeRename.idVolume);
1928 wp.wpVosVolumeRename.pszVolume = pszNewName;
1931 rc = Worker_DoTask (wtaskVosVolumeRename, &wp, &status);
1938 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1942 lpCell->Invalidate();
1943 rc = lpCell->RefreshAll (&status);
1949 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetEnd, lpiFileset, pszNewName, status);
1958 #define iswhite(_ch) ((_ch)==TEXT(' ') || (_ch)==TEXT('\t'))
1960 LPIDENT AfsClass_CreateService (LPIDENT lpiServer, LPTSTR pszService, LPTSTR pszCommand, LPTSTR pszParams, LPTSTR pszNotifier, AFSSERVICETYPE type, SYSTEMTIME *pstIfCron, ULONG *pStatus)
1964 LPIDENT lpiService = NULL;
1967 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceBegin, lpiServer, pszService, 0);
1972 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1976 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1984 wp.wpBosProcessCreate.hServer = hBOS;
1985 wp.wpBosProcessCreate.pszService = pszService;
1986 wp.wpBosProcessCreate.type = type;
1987 wp.wpBosProcessCreate.pszNotifier = pszNotifier;
1989 TCHAR szFullCommand[ MAX_PATH + MAX_PATH ];
1990 wsprintf (szFullCommand, TEXT("%s %s"), pszCommand, pszParams);
1991 wp.wpBosProcessCreate.pszCommand = szFullCommand;
1993 TCHAR szCronTime[ 256 ] = TEXT("");
1994 wp.wpBosProcessCreate.pszTimeCron = szCronTime;
1996 if (type == SERVICETYPE_CRON)
1997 AfsClass_FormatRecurringTime (szCronTime, pstIfCron);
1999 wp.wpBosProcessCreate.pszTimeCron = NULL;
2002 rc = Worker_DoTask (wtaskBosProcessCreate, &wp, &status);
2008 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2012 lpServer->InvalidateServices();
2013 if (!lpServer->RefreshServices (TRUE, &status))
2017 LPSERVICE lpService;
2018 if ((lpService = lpServer->OpenService (pszService, &status)) == NULL)
2022 lpiService = lpService->GetIdentifier();
2030 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2032 lpServer->CloseBosObject();
2036 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceEnd, lpiServer, pszService, status);
2041 return (rc) ? lpiService : NULL;
2045 BOOL AfsClass_DeleteService (LPIDENT lpiService, ULONG *pStatus)
2051 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceBegin, lpiService);
2056 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2060 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2065 // Before a service can be deleted, it must be stopped (otherwise, on NT,
2066 // the Delete operation won't block for the required Stop to complete--
2067 // so our wtaskDeleteBosProcess would return before the service really
2072 TCHAR szService[ cchNAME ];
2073 lpiService->GetServiceName (szService);
2076 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
2077 wp.wpBosProcessExecutionStateSet.pszService = szService;
2078 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
2079 // TODO: wp.wpStopBosProcess.fWait = TRUE;
2082 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
2086 // Delete the service
2090 TCHAR szService[ cchNAME ];
2091 lpiService->GetServiceName (szService);
2094 wp.wpBosProcessDelete.hServer = hBOS;
2095 wp.wpBosProcessDelete.pszService = szService;
2098 rc = Worker_DoTask (wtaskBosProcessDelete, &wp, &status);
2104 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2108 lpServer->InvalidateServices();
2109 if (!lpServer->RefreshServices (TRUE, &status))
2115 if ((lpServer = lpiService->OpenServer (&status)) != NULL)
2117 lpServer->CloseBosObject();
2121 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceEnd, lpiService, status);
2130 BOOL AfsClass_ReleaseFileset (LPIDENT lpiFilesetRW, BOOL fForce, ULONG *pStatus)
2136 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetBegin, lpiFilesetRW);
2138 // Obtain hCell and hVOS
2143 if ((lpServer = lpiFilesetRW->OpenServer (&status)) == NULL)
2147 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2152 // Perform the actual operation
2157 wp.wpVosVolumeRelease.hCell = hCell;
2158 wp.wpVosVolumeRelease.fForce = fForce;
2159 lpiFilesetRW->GetFilesetID (&wp.wpVosVolumeRelease.idVolume);
2162 rc = Worker_DoTask (wtaskVosVolumeRelease, &wp, &status);
2171 if ((lpCell = lpiFilesetRW->OpenCell (&status)) == NULL)
2175 lpCell->Invalidate();
2176 rc = lpCell->RefreshAll (&status);
2183 if ((lpServer = lpiFilesetRW->OpenServer (&status)) != NULL)
2185 lpServer->CloseVosObject();
2190 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetEnd, lpiFilesetRW, status);
2199 BOOL AfsClass_GetFileDates (LPIDENT lpiServer, LPTSTR pszFilename, SYSTEMTIME *pstFile, SYSTEMTIME *pstBAK, SYSTEMTIME *pstOLD, ULONG *pStatus)
2205 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesBegin, lpiServer, pszFilename, 0);
2210 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2214 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2222 wp.wpBosExecutableTimestampGet.hServer = hBOS;
2223 wp.wpBosExecutableTimestampGet.pszFilename = pszFilename;
2226 if ((rc = Worker_DoTask (wtaskBosExecutableTimestampGet, &wp, &status)) == TRUE)
2228 *pstFile = wp.wpBosExecutableTimestampGet.timeNew;
2229 *pstBAK = wp.wpBosExecutableTimestampGet.timeBak;
2230 *pstOLD = wp.wpBosExecutableTimestampGet.timeOld;
2236 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2238 lpServer->CloseBosObject();
2242 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesEnd, lpiServer, pszFilename, status);
2251 BOOL AfsClass_ExecuteCommand (LPIDENT lpiServer, LPTSTR pszCommand, ULONG *pStatus)
2257 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandBegin, lpiServer, pszCommand, 0);
2262 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2266 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2274 wp.wpBosCommandExecute.hServer = hBOS;
2275 wp.wpBosCommandExecute.pszCommand = pszCommand;
2278 rc = Worker_DoTask (wtaskBosCommandExecute, &wp, &status);
2282 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2284 lpServer->CloseBosObject();
2288 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandEnd, lpiServer, pszCommand, status);
2297 LPADMINLIST AfsClass_AdminList_Load (LPIDENT lpiServer, ULONG *pStatus)
2301 LPADMINLIST lpList = NULL;
2304 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadBegin, lpiServer);
2309 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2313 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2320 lpList = New(ADMINLIST);
2321 memset (lpList, 0x00, sizeof(ADMINLIST));
2323 lpList->lpiServer = lpiServer;
2325 WORKERPACKET wpBegin;
2326 wpBegin.wpBosAdminGetBegin.hServer = hBOS;
2327 if (!Worker_DoTask (wtaskBosAdminGetBegin, &wpBegin, &status))
2333 TCHAR szAdmin[ cchNAME ];
2335 WORKERPACKET wpNext;
2336 wpNext.wpBosAdminGetNext.hEnum = wpBegin.wpBosAdminGetBegin.hEnum;
2337 wpNext.wpBosAdminGetNext.pszAdmin = szAdmin;
2339 if (!Worker_DoTask (wtaskBosAdminGetNext, &wpNext, &status))
2341 if (status == ADMITERATORDONE)
2349 if ((iAdded = AfsClass_AdminList_AddEntry (lpList, szAdmin)) != (size_t)-1)
2351 lpList->aEntries[ iAdded ].fAdded = FALSE;
2355 WORKERPACKET wpDone;
2356 wpDone.wpBosAdminGetDone.hEnum = wpBegin.wpBosAdminGetBegin.hEnum;
2357 Worker_DoTask (wtaskBosAdminGetDone, &wpDone);
2361 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2363 lpServer->CloseBosObject();
2367 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadEnd, lpiServer, status);
2372 return (rc) ? lpList : NULL;
2376 LPADMINLIST AfsClass_AdminList_Copy (LPADMINLIST lpOld)
2378 LPADMINLIST lpNew = NULL;
2382 lpNew = New(ADMINLIST);
2383 memcpy (lpNew, lpOld, sizeof(ADMINLIST));
2386 lpNew->aEntries = 0;
2387 lpNew->cEntries = 0;
2389 if (REALLOC (lpNew->aEntries, lpNew->cEntries, lpOld->cEntries, cREALLOC_ADMINLISTENTRIES))
2391 size_t cb = lpOld->cEntries * sizeof(ADMINLISTENTRY);
2392 memcpy (lpNew->aEntries, lpOld->aEntries, cb);
2400 BOOL AfsClass_AdminList_Save (LPADMINLIST lpList, ULONG *pStatus)
2406 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveBegin, lpList->lpiServer);
2411 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
2415 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2422 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2424 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2427 // are we supposed to add this entry?
2429 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
2432 wp.wpBosAdminCreate.hServer = hBOS;
2433 wp.wpBosAdminCreate.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2436 if (!Worker_DoTask (wtaskBosAdminCreate, &wp, &thisstatus))
2439 status = thisstatus;
2443 lpList->aEntries[ iEntry ].fAdded = FALSE;
2447 // are we supposed to delete this entry?
2449 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
2452 wp.wpBosAdminDelete.hServer = hBOS;
2453 wp.wpBosAdminDelete.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2456 if (!Worker_DoTask (wtaskBosAdminDelete, &wp, &thisstatus))
2459 status = thisstatus;
2463 lpList->aEntries[ iEntry ].szAdmin[0] = TEXT('\0');
2464 lpList->aEntries[ iEntry ].fDeleted = FALSE;
2470 if ((lpServer = lpList->lpiServer->OpenServer (&status)) != NULL)
2472 lpServer->CloseBosObject();
2476 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveEnd, lpList->lpiServer, status);
2485 void AfsClass_AdminList_Free (LPADMINLIST lpList)
2487 if (lpList && !InterlockedDecrement (&lpList->cRef))
2489 if (lpList->aEntries)
2490 Free (lpList->aEntries);
2491 memset (lpList, 0x00, sizeof(ADMINLIST));
2497 size_t AfsClass_AdminList_AddEntry (LPADMINLIST lpList, LPTSTR pszAdmin)
2499 size_t iAdded = (size_t)-1;
2504 for (iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2506 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2509 if (iEntry >= lpList->cEntries)
2511 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_ADMINLISTENTRIES);
2513 if (iEntry < lpList->cEntries)
2516 lstrcpy (lpList->aEntries[ iAdded ].szAdmin, pszAdmin);
2517 lpList->aEntries[ iAdded ].fAdded = TRUE;
2518 lpList->aEntries[ iAdded ].fDeleted = FALSE;
2526 BOOL AfsClass_AdminList_DelEntry (LPADMINLIST lpList, size_t iIndex)
2531 (iIndex < lpList->cEntries) &&
2532 (lpList->aEntries[ iIndex ].szAdmin[0]) &&
2533 (!lpList->aEntries[ iIndex ].fDeleted) )
2535 if (lpList->aEntries[ iIndex ].fAdded)
2536 lpList->aEntries[ iIndex ].szAdmin[0] = TEXT('\0');
2538 lpList->aEntries[ iIndex ].fDeleted = TRUE;
2547 LPKEYLIST AfsClass_KeyList_Load (LPIDENT lpiServer, ULONG *pStatus)
2551 LPKEYLIST lpList = NULL;
2554 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadBegin, lpiServer);
2559 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2563 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2570 lpList = New(KEYLIST);
2571 memset (lpList, 0x00, sizeof(KEYLIST));
2572 lpList->lpiServer = lpiServer;
2574 WORKERPACKET wpBegin;
2575 wpBegin.wpBosKeyGetBegin.hServer = hBOS;
2576 if (!Worker_DoTask (wtaskBosKeyGetBegin, &wpBegin, &status))
2580 for (size_t iEnum = 0; ; ++iEnum)
2582 WORKERPACKET wpNext;
2583 wpNext.wpBosKeyGetNext.hEnum = wpBegin.wpBosKeyGetBegin.hEnum;
2585 if (!Worker_DoTask (wtaskBosKeyGetNext, &wpNext, &status))
2587 if (status == ADMITERATORDONE)
2594 if (REALLOC (lpList->aKeys, lpList->cKeys, 1+iEnum, cREALLOC_SERVERKEYS))
2596 lpList->aKeys[ iEnum ].keyVersion = wpNext.wpBosKeyGetNext.keyVersion;
2597 memcpy (&lpList->aKeys[ iEnum ].keyData, &wpNext.wpBosKeyGetNext.keyData, sizeof(ENCRYPTIONKEY));
2598 memcpy (&lpList->aKeys[ iEnum ].keyInfo, &wpNext.wpBosKeyGetNext.keyInfo, sizeof(ENCRYPTIONKEYINFO));
2602 WORKERPACKET wpDone;
2603 wpDone.wpBosKeyGetDone.hEnum = wpBegin.wpBosKeyGetBegin.hEnum;
2604 Worker_DoTask (wtaskBosKeyGetDone, &wpDone);
2608 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2610 lpServer->CloseBosObject();
2614 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadEnd, lpiServer, status);
2619 return (rc) ? lpList : NULL;
2623 void AfsClass_KeyList_Free (LPKEYLIST lpList)
2628 Free (lpList->aKeys);
2629 memset (lpList, 0x00, sizeof(KEYLIST));
2635 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPTSTR pszString, ULONG *pStatus)
2640 TCHAR szCell[ cchNAME ];
2641 lpiServer->GetCellName (szCell);
2644 wp.wpKasStringToKey.pszCell = szCell;
2645 wp.wpKasStringToKey.pszString = pszString;
2646 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
2650 else if (!AfsClass_AddKey (lpiServer, keyVersion, &wp.wpKasStringToKey.key, &status))
2661 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2669 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2673 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2681 wp.wpBosKeyCreate.hServer = hBOS;
2682 wp.wpBosKeyCreate.keyVersion = keyVersion;
2683 memcpy (&wp.wpBosKeyCreate.key, pKey, sizeof(ENCRYPTIONKEY));
2684 rc = Worker_DoTask (wtaskBosKeyCreate, &wp, &status);
2687 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2689 lpServer->CloseBosObject();
2699 BOOL AfsClass_DeleteKey (LPIDENT lpiServer, int keyVersion, ULONG *pStatus)
2707 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2711 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2719 wp.wpBosKeyDelete.hServer = hBOS;
2720 wp.wpBosKeyDelete.keyVersion = keyVersion;
2721 rc = Worker_DoTask (wtaskBosKeyDelete, &wp, &status);
2724 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2726 lpServer->CloseBosObject();
2736 BOOL AfsClass_GetRandomKey (LPIDENT lpi, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2744 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2748 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2751 hKAS = lpCell->GetKasObject (&status);
2758 wp.wpKasServerRandomKeyGet.hCell = hCell;
2759 wp.wpKasServerRandomKeyGet.hServer = hKAS;
2760 rc = Worker_DoTask (wtaskKasServerRandomKeyGet, &wp, &status);
2763 memcpy (pKey, &wp.wpKasServerRandomKeyGet.key, sizeof(ENCRYPTIONKEY));
2772 BOOL AfsClass_Clone (LPIDENT lpiRW, ULONG *pStatus)
2778 NOTIFYCALLBACK::SendNotificationToAll (evtCloneBegin, lpiRW, 0);
2784 if ((lpCell = lpiRW->OpenCell (&status)) == NULL)
2788 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2793 // Perform the actual operation
2798 wp.wpVosBackupVolumeCreate.hCell = hCell;
2799 lpiRW->GetFilesetID (&wp.wpVosBackupVolumeCreate.idVolume);
2802 rc = Worker_DoTask (wtaskVosBackupVolumeCreate, &wp, &status);
2811 if ((lpServer = lpiRW->OpenServer (&status)) == NULL)
2815 lpServer->Invalidate();
2816 rc = lpServer->RefreshAll (&status);
2821 NOTIFYCALLBACK::SendNotificationToAll (evtCloneEnd, lpiRW, status);
2830 BOOL AfsClass_CloneMultiple (LPIDENT lpi, LPTSTR pszPrefix, BOOL fExclude, ULONG *pStatus)
2836 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleBegin, lpi);
2842 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2846 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2851 // Obtain hServer if appropriate
2854 if (!lpi->fIsCell())
2857 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2861 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
2867 // If requested, obtain the appropriate aggregate ID
2869 int idPartition = NO_PARTITION;
2870 if (rc && (lpi->fIsFileset() || lpi->fIsAggregate()))
2872 LPAGGREGATE lpAggregate;
2873 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2877 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
2879 lpAggregate->Close();
2883 // Perform the actual operation
2888 wp.wpVosBackupVolumeCreateMultiple.hCell = hCell;
2889 wp.wpVosBackupVolumeCreateMultiple.hServer = hVOS;
2890 wp.wpVosBackupVolumeCreateMultiple.idPartition = idPartition;
2891 wp.wpVosBackupVolumeCreateMultiple.pszPrefix = pszPrefix;
2892 wp.wpVosBackupVolumeCreateMultiple.fExclude = fExclude;
2895 rc = Worker_DoTask (wtaskVosBackupVolumeCreateMultiple, &wp, &status);
2906 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2910 lpCell->Invalidate();
2911 rc = lpCell->RefreshAll (&status);
2918 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2922 lpServer->Invalidate();
2923 rc = lpServer->RefreshAll (&status);
2932 if ((lpServer = lpi->OpenServer (&status)) != NULL)
2934 lpServer->CloseVosObject();
2939 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleEnd, lpi, status);
2948 BOOL AfsClass_DumpFileset (LPIDENT lpi, LPTSTR pszFilename, LPSYSTEMTIME pstDate, ULONG *pStatus)
2954 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetBegin, lpi, pszFilename, 0);
2956 // Obtain hCell and hVOS
2961 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2965 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2970 // Obtain idPartition
2973 LPAGGREGATE lpAggregate;
2974 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2978 idPartition = lpAggregate->GetID();
2979 lpAggregate->Close();
2982 // Perform the actual operation
2987 wp.wpVosVolumeDump.hCell = hCell;
2988 wp.wpVosVolumeDump.hServer = hVOS;
2989 wp.wpVosVolumeDump.pszFilename = pszFilename;
2990 wp.wpVosVolumeDump.idPartition = idPartition;
2991 lpi->GetFilesetID (&wp.wpVosVolumeDump.idVolume);
2994 memcpy (&wp.wpVosVolumeDump.stStart, pstDate, sizeof(SYSTEMTIME));
2996 memset (&wp.wpVosVolumeDump.stStart, 0x00, sizeof(SYSTEMTIME));
2999 rc = Worker_DoTask (wtaskVosVolumeDump, &wp, &status);
3003 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetEnd, lpi, pszFilename, status);
3009 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3011 lpServer->CloseVosObject();
3022 BOOL AfsClass_RestoreFileset (LPIDENT lpi, LPTSTR pszFileset, LPTSTR pszFilename, BOOL fIncremental, ULONG *pStatus)
3028 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetBegin, lpi, NULL, pszFileset, pszFilename, 0, 0);
3030 // Obtain hCell and hVOS
3035 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3039 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
3044 // Obtain idPartition
3047 LPAGGREGATE lpAggregate;
3048 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
3052 idPartition = lpAggregate->GetID();
3053 lpAggregate->Close();
3056 // Perform the actual operation
3061 wp.wpVosVolumeRestore.hCell = hCell;
3062 wp.wpVosVolumeRestore.hServer = hVOS;
3063 wp.wpVosVolumeRestore.idPartition = idPartition;
3064 wp.wpVosVolumeRestore.pszVolume = pszFileset;
3065 wp.wpVosVolumeRestore.pszFilename = pszFilename;
3066 wp.wpVosVolumeRestore.fIncremental = fIncremental;
3068 if (lpi->fIsFileset())
3069 lpi->GetFilesetID (&wp.wpVosVolumeRestore.idVolume);
3071 wp.wpVosVolumeRestore.idVolume = NO_VOLUME;
3074 rc = Worker_DoTask (wtaskVosVolumeRestore, &wp, &status);
3082 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3086 lpServer->Invalidate();
3087 rc = lpServer->RefreshAll (&status);
3094 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3096 lpServer->CloseVosObject();
3101 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetEnd, lpi, NULL, pszFileset, pszFilename, 0, status);
3110 BOOL AfsClass_GetRestartTimes (LPIDENT lpiServer, BOOL *pfWeekly, LPSYSTEMTIME pstWeekly, BOOL *pfDaily, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3116 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesBegin, lpiServer);
3121 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3125 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3133 wp.wpBosExecutableRestartTimeGet.hServer = hBOS;
3136 rc = Worker_DoTask (wtaskBosExecutableRestartTimeGet, &wp, &status);
3141 *pfWeekly = wp.wpBosExecutableRestartTimeGet.fWeeklyRestart;
3142 *pstWeekly = wp.wpBosExecutableRestartTimeGet.timeWeekly;
3143 *pfDaily = wp.wpBosExecutableRestartTimeGet.fDailyRestart;
3144 *pstDaily = wp.wpBosExecutableRestartTimeGet.timeDaily;
3148 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3150 lpServer->CloseBosObject();
3154 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesEnd, lpiServer, status);
3163 BOOL AfsClass_SetRestartTimes (LPIDENT lpiServer, LPSYSTEMTIME pstWeekly, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3169 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesBegin, lpiServer);
3174 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3178 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3185 SYSTEMTIME timeNever;
3186 memset (&timeNever, 0x00, sizeof(SYSTEMTIME));
3189 wp.wpBosExecutableRestartTimeSet.hServer = hBOS;
3190 wp.wpBosExecutableRestartTimeSet.fWeeklyRestart = (pstWeekly != NULL) ? TRUE : FALSE;
3191 wp.wpBosExecutableRestartTimeSet.timeWeekly = (pstWeekly != NULL) ? *pstWeekly : timeNever;
3192 wp.wpBosExecutableRestartTimeSet.fDailyRestart = (pstDaily != NULL) ? TRUE : FALSE;
3193 wp.wpBosExecutableRestartTimeSet.timeDaily = (pstDaily != NULL) ? *pstDaily : timeNever;
3196 rc = Worker_DoTask (wtaskBosExecutableRestartTimeSet, &wp, &status);
3200 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3202 lpServer->CloseBosObject();
3206 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesEnd, lpiServer, status);
3215 BOOL AfsClass_MoveReplica (LPIDENT lpiReplica, LPIDENT lpiAggregateTarget, ULONG *pStatus)
3219 // Find the identifier for this replica's read/write fileset.
3221 LPIDENT lpiFilesetRW = NULL;
3222 LPFILESET lpFileset;
3223 if ((lpFileset = lpiReplica->OpenFileset (pStatus)) == NULL)
3227 if ((lpiFilesetRW = lpFileset->GetReadWriteIdentifier (pStatus)) == NULL)
3232 // If the fileset replica currently resides on the same server
3233 // as the target aggregate, we'll follow the following steps:
3235 // 1. Delete the old fileset replica -> on error, quit
3236 // 2. Create the new fileset replica -> on error, recreate old replica, quit
3238 // If the fileset replica instead currently resides on a different
3239 // server, we can follow the preferred steps:
3241 // 1. Create the new fileset replica -> on error, quit
3242 // 2. Delete the old fileset replica -> on error, delete the new replica, quit
3246 LPIDENT lpiReplicaNew;
3248 if (lpiReplica->GetServer() == lpiAggregateTarget->GetServer())
3250 LPIDENT lpiAggregateOriginal = lpiReplica->GetAggregate();
3252 if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3256 else if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3258 (void)AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateOriginal);
3262 else // different server?
3264 if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3268 else if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3270 (void)AfsClass_DeleteReplica (lpiReplicaNew, pStatus);
3280 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)
3286 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageBegin, lpiSalvage);
3291 if ((lpServer = lpiSalvage->OpenServer (&status)) == NULL)
3295 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3301 *ppszLogData = NULL;
3303 // Step one: perform the actual salvage. This will dump a log file onto
3304 // the target computer.
3308 LPTSTR pszAggregate = NULL;
3309 TCHAR szAggregate[ cchNAME ];
3310 if (lpiSalvage->fIsAggregate() || lpiSalvage->fIsFileset())
3312 lpiSalvage->GetAggregateName (szAggregate);
3313 pszAggregate = szAggregate;
3316 LPTSTR pszFileset = NULL;
3317 TCHAR szFileset[ cchNAME ];
3318 if (lpiSalvage->fIsFileset())
3321 lpiSalvage->GetFilesetID (&vid);
3322 wsprintf (szFileset, TEXT("%lu"), vid);
3323 pszFileset = szFileset;
3326 if (pszLogFile == NULL)
3327 pszLogFile = TEXT("SalvageLog");
3330 wp.wpBosSalvage.hCell = hCell;
3331 wp.wpBosSalvage.hServer = hBOS;
3332 wp.wpBosSalvage.pszAggregate = pszAggregate;
3333 wp.wpBosSalvage.pszFileset = pszFileset;
3334 wp.wpBosSalvage.nProcesses = nProcesses;
3335 wp.wpBosSalvage.pszTempDir = pszTempDir;
3336 wp.wpBosSalvage.pszLogFile = pszLogFile;
3337 wp.wpBosSalvage.fForce = fForce;
3338 wp.wpBosSalvage.fReadonly = fReadonly;
3339 wp.wpBosSalvage.fLogInodes = fLogInodes;
3340 wp.wpBosSalvage.fLogRootInodes = fLogRootInodes;
3341 wp.wpBosSalvage.fRebuildDirs = fRebuildDirs;
3342 wp.wpBosSalvage.fReadBlocks = fReadBlocks;
3345 rc = Worker_DoTask (wtaskBosSalvage, &wp, &status);
3349 // Step two: retrieve the log file from that salvage operation.
3350 // If we can't get the log file back, that's not fatal--just return
3351 // a NULL pointer for the log data.
3353 if (rc && ppszLogData)
3356 wp.wpBosLogGet.hServer = hBOS;
3357 wp.wpBosLogGet.pszLogName = pszLogFile;
3358 wp.wpBosLogGet.pszLogData = NULL;
3361 if ((rc = Worker_DoTask (wtaskBosLogGet, &wp, &status)) == TRUE)
3363 // Okay, well, we have the log in memory now. Problem is,
3364 // it has UNIX-style CR's... and so is missing the LF which
3365 // PCs expect before each CR. Wow--look at all the
3366 // acronyms! Count the CRs, alloc a larger buffer, and stuff
3367 // in the LFs before each CR.
3369 size_t cchRequired = 1;
3370 for (LPTSTR pchIn = wp.wpBosLogGet.pszLogData; *pchIn; ++pchIn)
3372 cchRequired += (*pchIn == TEXT('\r')) ? 0 : (*pchIn == TEXT('\n')) ? 2 : 1;
3375 if ((*ppszLogData = AllocateString (cchRequired)) != NULL)
3377 LPTSTR pszOut = *ppszLogData;
3378 for (LPTSTR pchIn = wp.wpBosLogGet.pszLogData; *pchIn; ++pchIn)
3380 if (*pchIn == TEXT('\n'))
3381 *pszOut++ = TEXT('\r');
3382 if (*pchIn != TEXT('\r'))
3385 *pszOut++ = TEXT('\0');
3391 if ((lpServer = lpiSalvage->OpenServer (&status)) != NULL)
3393 lpServer->CloseBosObject();
3397 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageEnd, lpiSalvage, status);
3406 void AfsClass_FreeSalvageLog (LPTSTR pszLogData)
3413 LPHOSTLIST AfsClass_HostList_Load (LPIDENT lpiServer, ULONG *pStatus)
3417 LPHOSTLIST lpList = NULL;
3420 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadBegin, lpiServer);
3425 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3429 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3436 lpList = New(HOSTLIST);
3437 memset (lpList, 0x00, sizeof(HOSTLIST));
3439 lpList->lpiServer = lpiServer;
3441 WORKERPACKET wpBegin;
3442 wpBegin.wpBosHostGetBegin.hServer = hBOS;
3443 if (!Worker_DoTask (wtaskBosHostGetBegin, &wpBegin, &status))
3449 TCHAR szHost[ cchNAME ];
3451 WORKERPACKET wpNext;
3452 wpNext.wpBosHostGetNext.hEnum = wpBegin.wpBosHostGetBegin.hEnum;
3453 wpNext.wpBosHostGetNext.pszServer = szHost;
3455 if (!Worker_DoTask (wtaskBosHostGetNext, &wpNext, &status))
3457 if (status == ADMITERATORDONE)
3465 if ((iAdded = AfsClass_HostList_AddEntry (lpList, szHost)) != (size_t)-1)
3467 lpList->aEntries[ iAdded ].fAdded = FALSE;
3471 WORKERPACKET wpDone;
3472 wpDone.wpBosHostGetDone.hEnum = wpBegin.wpBosHostGetBegin.hEnum;
3473 Worker_DoTask (wtaskBosHostGetDone, &wpDone);
3477 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3479 lpServer->CloseBosObject();
3483 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadEnd, lpiServer, status);
3488 return (rc) ? lpList : NULL;
3492 LPHOSTLIST AfsClass_HostList_Copy (LPHOSTLIST lpOld)
3494 LPHOSTLIST lpNew = NULL;
3498 lpNew = New(HOSTLIST);
3499 memcpy (lpNew, lpOld, sizeof(HOSTLIST));
3502 lpNew->aEntries = 0;
3503 lpNew->cEntries = 0;
3505 if (REALLOC (lpNew->aEntries, lpNew->cEntries, lpOld->cEntries, cREALLOC_HOSTLISTENTRIES))
3507 size_t cb = lpOld->cEntries * sizeof(HOSTLISTENTRY);
3508 memcpy (lpNew->aEntries, lpOld->aEntries, cb);
3516 BOOL AfsClass_HostList_Save (LPHOSTLIST lpList, ULONG *pStatus)
3522 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveBegin, lpList->lpiServer);
3527 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
3531 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3538 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3540 if (!lpList->aEntries[ iEntry ].szHost[0])
3543 // are we supposed to add this entry?
3545 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
3548 wp.wpBosHostCreate.hServer = hBOS;
3549 wp.wpBosHostCreate.pszServer = lpList->aEntries[ iEntry ].szHost;
3552 if (!Worker_DoTask (wtaskBosHostCreate, &wp, &thisstatus))
3555 status = thisstatus;
3559 lpList->aEntries[ iEntry ].fAdded = FALSE;
3563 // are we supposed to delete this entry?
3565 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
3568 wp.wpBosHostDelete.hServer = hBOS;
3569 wp.wpBosHostDelete.pszServer = lpList->aEntries[ iEntry ].szHost;
3572 if (!Worker_DoTask (wtaskBosHostDelete, &wp, &thisstatus))
3575 status = thisstatus;
3579 lpList->aEntries[ iEntry ].szHost[0] = TEXT('\0');
3580 lpList->aEntries[ iEntry ].fDeleted = FALSE;
3586 if ((lpServer = lpList->lpiServer->OpenServer (&status)) != NULL)
3588 lpServer->CloseBosObject();
3592 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveEnd, lpList->lpiServer, status);
3601 void AfsClass_HostList_Free (LPHOSTLIST lpList)
3603 if (lpList && !InterlockedDecrement (&lpList->cRef))
3605 if (lpList->aEntries)
3606 Free (lpList->aEntries);
3607 memset (lpList, 0x00, sizeof(HOSTLIST));
3613 size_t AfsClass_HostList_AddEntry (LPHOSTLIST lpList, LPTSTR pszHost)
3615 size_t iAdded = (size_t)-1;
3620 for (iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3622 if (!lpList->aEntries[ iEntry ].szHost[0])
3625 if (iEntry >= lpList->cEntries)
3627 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_HOSTLISTENTRIES);
3629 if (iEntry < lpList->cEntries)
3632 lstrcpy (lpList->aEntries[ iAdded ].szHost, pszHost);
3633 lpList->aEntries[ iAdded ].fAdded = TRUE;
3634 lpList->aEntries[ iAdded ].fDeleted = FALSE;
3642 BOOL AfsClass_HostList_DelEntry (LPHOSTLIST lpList, size_t iIndex)
3647 (iIndex < lpList->cEntries) &&
3648 (lpList->aEntries[ iIndex ].szHost[0]) &&
3649 (!lpList->aEntries[ iIndex ].fDeleted) )
3651 if (lpList->aEntries[ iIndex ].fAdded)
3652 lpList->aEntries[ iIndex ].szHost[0] = TEXT('\0');
3654 lpList->aEntries[ iIndex ].fDeleted = TRUE;
3663 BOOL AfsClass_GetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3668 memset (pProperties, 0x00, sizeof(PTSPROPERTIES));
3674 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3678 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3683 // Go get the necessary properties
3688 wp.wpPtsUserMaxGet.hCell = hCell;
3690 if ((rc = Worker_DoTask (wtaskPtsUserMaxGet, &wp, &status)) == TRUE)
3691 pProperties->idUserMax = wp.wpPtsUserMaxGet.idUserMax;
3697 wp.wpPtsGroupMaxGet.hCell = hCell;
3699 if ((rc = Worker_DoTask (wtaskPtsGroupMaxGet, &wp, &status)) == TRUE)
3700 pProperties->idGroupMax = wp.wpPtsGroupMaxGet.idGroupMax;
3709 BOOL AfsClass_SetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3718 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3722 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3727 // Modify the specified properties
3732 wp.wpPtsUserMaxSet.hCell = hCell;
3733 wp.wpPtsUserMaxSet.idUserMax = pProperties->idUserMax;
3734 rc = Worker_DoTask (wtaskPtsUserMaxSet, &wp, &status);
3740 wp.wpPtsGroupMaxSet.hCell = hCell;
3741 wp.wpPtsGroupMaxSet.idGroupMax = pProperties->idGroupMax;
3742 Worker_DoTask (wtaskPtsGroupMaxSet, &wp, &status);
3751 LPIDENT AfsClass_CreateUser (LPIDENT lpiCell, LPTSTR pszUserName, LPTSTR pszInstance, LPTSTR pszPassword, UINT_PTR idUser, BOOL fCreateKAS, BOOL fCreatePTS, ULONG *pStatus)
3756 if (pszInstance && !*pszInstance)
3760 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserBegin, lpiCell, pszUserName, 0);
3762 // We'll need both hCell and hKAS.
3767 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3771 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3774 hKAS = lpCell->GetKasObject (&status);
3778 // First try to create a KAS entry.
3780 if (rc && fCreateKAS)
3783 wp.wpKasPrincipalCreate.hCell = hCell;
3784 wp.wpKasPrincipalCreate.hServer = hKAS;
3785 wp.wpKasPrincipalCreate.pszPrincipal = pszUserName;
3786 wp.wpKasPrincipalCreate.pszInstance = pszInstance;
3787 wp.wpKasPrincipalCreate.pszPassword = pszPassword;
3790 rc = Worker_DoTask (wtaskKasPrincipalCreate, &wp, &status);
3794 // If that succeeded, try to create a PTS entry as well.
3796 if (rc && fCreatePTS)
3798 TCHAR szUserName[ cchNAME ];
3799 lstrcpy (szUserName, pszUserName);
3801 wsprintf (&szUserName[ lstrlen(szUserName) ], TEXT(".%s"), pszInstance);
3804 wp.wpPtsUserCreate.hCell = hCell;
3805 wp.wpPtsUserCreate.pszUser = szUserName;
3806 wp.wpPtsUserCreate.idUser = (int) idUser;
3810 if ((rc = Worker_DoTask (wtaskPtsUserCreate, &wp, &status)) == FALSE)
3812 if (status == PREXIST)
3818 // If we couldn't make a KAS entry as well, remove the KAS entry.
3823 wpDel.wpKasPrincipalDelete.hCell = hCell;
3824 wpDel.wpKasPrincipalDelete.hServer = hKAS;
3825 wpDel.wpKasPrincipalDelete.pszPrincipal = pszUserName;
3826 wpDel.wpKasPrincipalDelete.pszInstance = pszInstance;
3827 Worker_DoTask (wtaskKasPrincipalDelete, &wpDel);
3834 // If we were able to create the user's accounts successfully, refresh
3835 // the cell status and return the new user's ident.
3841 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3845 if (!lpCell->RefreshAccount (pszUserName, pszInstance, CELL_REFRESH_ACCOUNT_CREATED_USER, &lpiUser))
3853 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserEnd, lpiCell, pszUserName, status);
3858 return (rc) ? lpiUser : NULL;
3862 BOOL AfsClass_SetUserProperties (LPIDENT lpiUser, LPUSERPROPERTIES pProperties, ULONG *pStatus)
3868 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser);
3870 // We'll need both hCell and hKAS.
3875 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
3879 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3882 hKAS = lpCell->GetKasObject (&status);
3886 // We'll also need this user's current status
3890 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
3894 if (!lpUser->GetStatus (&us, TRUE, &status))
3899 // Modify the user's KAS entry (if necessary)
3901 DWORD dwKasMask = ( MASK_USERPROP_fAdmin |
3902 MASK_USERPROP_fGrantTickets |
3903 MASK_USERPROP_fCanEncrypt |
3904 MASK_USERPROP_fCanChangePassword |
3905 MASK_USERPROP_fCanReusePasswords |
3906 MASK_USERPROP_timeAccountExpires |
3907 MASK_USERPROP_cdayPwExpires |
3908 MASK_USERPROP_csecTicketLifetime |
3909 MASK_USERPROP_nFailureAttempts |
3910 MASK_USERPROP_csecFailedLoginLockTime );
3912 if (rc && (pProperties->dwMask & dwKasMask))
3914 TCHAR szPrincipal[ cchNAME ];
3915 TCHAR szInstance[ cchNAME ];
3916 lpiUser->GetUserName (szPrincipal, szInstance);
3919 wp.wpKasPrincipalFieldsSet.hCell = hCell;
3920 wp.wpKasPrincipalFieldsSet.hServer = hKAS;
3921 wp.wpKasPrincipalFieldsSet.pszPrincipal = szPrincipal;
3922 wp.wpKasPrincipalFieldsSet.pszInstance = szInstance;
3923 wp.wpKasPrincipalFieldsSet.fIsAdmin = (pProperties->dwMask & MASK_USERPROP_fAdmin) ? pProperties->fAdmin : us.KASINFO.fIsAdmin;
3924 wp.wpKasPrincipalFieldsSet.fGrantTickets = (pProperties->dwMask & MASK_USERPROP_fGrantTickets) ? pProperties->fGrantTickets : us.KASINFO.fCanGetTickets;
3925 wp.wpKasPrincipalFieldsSet.fCanEncrypt = (pProperties->dwMask & MASK_USERPROP_fCanEncrypt) ? pProperties->fCanEncrypt : us.KASINFO.fEncrypt;
3926 wp.wpKasPrincipalFieldsSet.fCanChangePassword = (pProperties->dwMask & MASK_USERPROP_fCanChangePassword) ? pProperties->fCanChangePassword : us.KASINFO.fCanChangePassword;
3927 wp.wpKasPrincipalFieldsSet.fCanReusePasswords = (pProperties->dwMask & MASK_USERPROP_fCanReusePasswords) ? pProperties->fCanReusePasswords : us.KASINFO.fCanReusePasswords;
3928 memcpy (&wp.wpKasPrincipalFieldsSet.timeExpires, (pProperties->dwMask & MASK_USERPROP_timeAccountExpires) ? &pProperties->timeAccountExpires : &us.KASINFO.timeExpires, sizeof(SYSTEMTIME));
3929 wp.wpKasPrincipalFieldsSet.cdayPwExpires = (pProperties->dwMask & MASK_USERPROP_cdayPwExpires) ? pProperties->cdayPwExpires : us.KASINFO.cdayPwExpire;
3930 wp.wpKasPrincipalFieldsSet.csecTicketLifetime = (pProperties->dwMask & MASK_USERPROP_csecTicketLifetime) ? pProperties->csecTicketLifetime : us.KASINFO.csecTicketLifetime;
3931 wp.wpKasPrincipalFieldsSet.nFailureAttempts = (pProperties->dwMask & MASK_USERPROP_nFailureAttempts) ? pProperties->nFailureAttempts : us.KASINFO.cFailLogin;
3932 wp.wpKasPrincipalFieldsSet.csecFailedLoginLockTime = (pProperties->dwMask & MASK_USERPROP_csecFailedLoginLockTime) ? pProperties->csecFailedLoginLockTime : us.KASINFO.csecFailLoginLock;
3935 rc = Worker_DoTask (wtaskKasPrincipalFieldsSet, &wp, &status);
3940 // Modify the user's PTS entry (if necessary)
3942 DWORD dwPtsMask = ( MASK_USERPROP_cGroupCreationQuota |
3943 MASK_USERPROP_aaListStatus |
3944 MASK_USERPROP_aaGroupsOwned |
3945 MASK_USERPROP_aaMembership );
3947 if (rc && (pProperties->dwMask & dwPtsMask))
3949 TCHAR szFullName[ cchNAME ];
3950 lpiUser->GetFullUserName (szFullName);
3953 wp.wpPtsUserModify.hCell = hCell;
3954 wp.wpPtsUserModify.pszUser = szFullName;
3955 memset (&wp.wpPtsUserModify.Delta, 0x00, sizeof(wp.wpPtsUserModify.Delta));
3957 if (pProperties->dwMask & MASK_USERPROP_cGroupCreationQuota)
3959 wp.wpPtsUserModify.Delta.flag = (pts_UserUpdateFlag_t)( (LONG)wp.wpPtsUserModify.Delta.flag | (LONG)PTS_USER_UPDATE_GROUP_CREATE_QUOTA );
3960 wp.wpPtsUserModify.Delta.groupCreationQuota = pProperties->cGroupCreationQuota;
3963 if (pProperties->dwMask & (MASK_USERPROP_aaListStatus | MASK_USERPROP_aaGroupsOwned | MASK_USERPROP_aaMembership))
3965 wp.wpPtsUserModify.Delta.flag = (pts_UserUpdateFlag_t)( (LONG)wp.wpPtsUserModify.Delta.flag | (LONG)PTS_USER_UPDATE_PERMISSIONS );
3966 wp.wpPtsUserModify.Delta.listStatus = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaListStatus) ? pProperties->aaListStatus : us.PTSINFO.aaListStatus );
3967 wp.wpPtsUserModify.Delta.listGroupsOwned = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaGroupsOwned) ? pProperties->aaGroupsOwned : us.PTSINFO.aaGroupsOwned );
3968 wp.wpPtsUserModify.Delta.listMembership = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaMembership) ? pProperties->aaMembership : us.PTSINFO.aaMembership );
3972 rc = Worker_DoTask (wtaskPtsUserModify, &wp, &status);
3976 // If we were able to modify the user's properties successfully, refresh
3977 // that user's status.
3979 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
3981 lpUser->Invalidate();
3982 lpUser->RefreshStatus();
3986 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser, status);
3995 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPTSTR pszPassword, ULONG *pStatus)
4000 TCHAR szCell[ cchNAME ];
4001 lpiUser->GetCellName (szCell);
4004 wp.wpKasStringToKey.pszCell = szCell;
4005 wp.wpKasStringToKey.pszString = pszPassword;
4006 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
4010 else if (!AfsClass_SetUserPassword (lpiUser, keyVersion, &wp.wpKasStringToKey.key, &status))
4021 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
4027 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordBegin, lpiUser);
4029 // We'll need both hCell and hKAS.
4034 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4038 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4041 hKAS = lpCell->GetKasObject (&status);
4045 // Change the user's password
4049 TCHAR szPrincipal[ cchNAME ];
4050 TCHAR szInstance[ cchNAME ];
4051 lpiUser->GetUserName (szPrincipal, szInstance);
4054 wp.wpKasPrincipalKeySet.hCell = hCell;
4055 wp.wpKasPrincipalKeySet.hServer = hKAS;
4056 wp.wpKasPrincipalKeySet.pszPrincipal = szPrincipal;
4057 wp.wpKasPrincipalKeySet.pszInstance = szInstance;
4058 wp.wpKasPrincipalKeySet.keyVersion = keyVersion;
4059 memcpy (&wp.wpKasPrincipalKeySet.key.key, &pKey->key, ENCRYPTIONKEY_LEN);
4062 rc = Worker_DoTask (wtaskKasPrincipalKeySet, &wp, &status);
4066 // If we were able to modify the user's password successfully, refresh
4067 // that user's status.
4070 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4072 lpUser->Invalidate();
4073 lpUser->RefreshStatus();
4077 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordEnd, lpiUser, status);
4086 BOOL AfsClass_DeleteUser (LPIDENT lpiUser, BOOL fDeleteKAS, BOOL fDeletePTS, ULONG *pStatus)
4092 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserBegin, lpiUser);
4094 // We'll need both hCell and hKAS.
4099 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4103 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4106 hKAS = lpCell->GetKasObject (&status);
4110 // Find out whether this user has KAS and/or PTS entries. Also
4111 // get the various lists of groups for this user...
4114 LPTSTR mszOwnerOf = NULL;
4115 LPTSTR mszMemberOf = NULL;
4116 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
4120 lpUser->GetOwnerOf (&mszOwnerOf);
4121 lpUser->GetMemberOf (&mszMemberOf);
4125 // Delete the user's PTS entry
4127 if (rc && fDeletePTS)
4129 TCHAR szFullName[ cchNAME ];
4130 lpiUser->GetFullUserName (szFullName);
4133 wp.wpPtsUserDelete.hCell = hCell;
4134 wp.wpPtsUserDelete.pszUser = szFullName;
4137 if ((rc = Worker_DoTask (wtaskPtsUserDelete, &wp, &status)) == FALSE)
4139 if (status == ADMPTSFAILEDNAMETRANSLATE) // User had no PTS entry?
4145 // Delete the user's KAS entry
4147 if (rc && fDeleteKAS)
4149 TCHAR szPrincipal[ cchNAME ];
4150 TCHAR szInstance[ cchNAME ];
4151 lpiUser->GetUserName (szPrincipal, szInstance);
4154 wp.wpKasPrincipalDelete.hCell = hCell;
4155 wp.wpKasPrincipalDelete.hServer = hKAS;
4156 wp.wpKasPrincipalDelete.pszPrincipal = szPrincipal;
4157 wp.wpKasPrincipalDelete.pszInstance = szInstance;
4160 if ((rc = Worker_DoTask (wtaskKasPrincipalDelete, &wp, &status)) == FALSE)
4162 if (status == KANOENT)
4168 // If we were able to delete the user's accounts successfully, refresh
4173 if ((lpCell = lpiUser->OpenCell (&status)) != NULL)
4175 TCHAR szPrincipal[ cchNAME ];
4176 TCHAR szInstance[ cchNAME ];
4177 lpiUser->GetUserName (szPrincipal, szInstance);
4179 lpCell->RefreshAccount (szPrincipal, szInstance, CELL_REFRESH_ACCOUNT_DELETED);
4180 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4181 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4186 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserEnd, lpiUser, status);
4190 FreeString (mszOwnerOf);
4192 FreeString (mszMemberOf);
4199 BOOL AfsClass_UnlockUser (LPIDENT lpiUser, ULONG *pStatus)
4205 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserBegin, lpiUser);
4207 // We'll need both hCell and hKAS.
4212 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4216 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4219 hKAS = lpCell->GetKasObject (&status);
4223 // Unlock the user's KAS entry
4227 TCHAR szPrincipal[ cchNAME ];
4228 TCHAR szInstance[ cchNAME ];
4229 lpiUser->GetUserName (szPrincipal, szInstance);
4232 wp.wpKasPrincipalUnlock.hCell = hCell;
4233 wp.wpKasPrincipalUnlock.hServer = hKAS;
4234 wp.wpKasPrincipalUnlock.pszPrincipal = szPrincipal;
4235 wp.wpKasPrincipalUnlock.pszInstance = szInstance;
4238 rc = Worker_DoTask (wtaskKasPrincipalUnlock, &wp, &status);
4242 // If we were able to unlock the user's accounts successfully, refresh
4243 // the user's properties.
4248 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4250 lpUser->Invalidate();
4251 lpUser->RefreshStatus();
4256 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserEnd, lpiUser, status);
4265 LPIDENT AfsClass_CreateGroup (LPIDENT lpiCell, LPTSTR pszGroupName, LPIDENT lpiOwner, int idGroup, ULONG *pStatus)
4271 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupBegin, lpiCell, pszGroupName, 0);
4277 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4281 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4286 // Create a PTS entry for the new group
4290 TCHAR szOwner[ cchNAME ] = TEXT("");
4291 if (lpiOwner && lpiOwner->fIsUser())
4292 lpiOwner->GetFullUserName (szOwner);
4293 else if (lpiOwner && lpiOwner->fIsGroup())
4294 lpiOwner->GetGroupName (szOwner);
4297 wp.wpPtsGroupCreate.hCell = hCell;
4298 wp.wpPtsGroupCreate.pszGroup = pszGroupName;
4299 wp.wpPtsGroupCreate.pszOwner = (szOwner[0]) ? szOwner : NULL;
4300 wp.wpPtsGroupCreate.idGroup = idGroup;
4303 rc = Worker_DoTask (wtaskPtsGroupCreate, &wp, &status);
4307 // If we were able to create the group successfully, refresh
4308 // the cell status and return the new group's ident.
4314 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4318 if (!lpCell->RefreshAccount (pszGroupName, NULL, CELL_REFRESH_ACCOUNT_CREATED_GROUP, &lpiGroup))
4326 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupEnd, lpiCell, pszGroupName, status);
4331 return (rc) ? lpiGroup : NULL;
4335 BOOL AfsClass_SetGroupProperties (LPIDENT lpiGroup, LPGROUPPROPERTIES pProperties, ULONG *pStatus)
4341 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup);
4347 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4351 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4356 // We'll also need this group's current status
4360 if ((lpGroup = lpiGroup->OpenGroup (&status)) == NULL)
4364 if (!lpGroup->GetStatus (&gs, TRUE, &status))
4369 // Modify the group's PTS entry (if requested)
4371 DWORD dwPtsMask = ( MASK_GROUPPROP_aaListStatus |
4372 MASK_GROUPPROP_aaListGroupsOwned |
4373 MASK_GROUPPROP_aaListMembers |
4374 MASK_GROUPPROP_aaAddMember |
4375 MASK_GROUPPROP_aaDeleteMember );
4377 if (rc && (pProperties->dwMask & dwPtsMask))
4379 TCHAR szGroup[ cchNAME ];
4380 lpiGroup->GetGroupName (szGroup);
4383 wp.wpPtsGroupModify.hCell = hCell;
4384 wp.wpPtsGroupModify.pszGroup = szGroup;
4385 memset (&wp.wpPtsGroupModify.Delta, 0x00, sizeof(wp.wpPtsGroupModify.Delta));
4386 wp.wpPtsGroupModify.Delta.listStatus = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListStatus) ? pProperties->aaListStatus : gs.aaListStatus );
4387 wp.wpPtsGroupModify.Delta.listGroupsOwned = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListGroupsOwned) ? pProperties->aaListGroupsOwned : gs.aaListGroupsOwned );
4388 wp.wpPtsGroupModify.Delta.listMembership = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListMembers) ? pProperties->aaListMembers : gs.aaListMembers );
4389 wp.wpPtsGroupModify.Delta.listAdd = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaAddMember) ? pProperties->aaAddMember : gs.aaAddMember );
4390 wp.wpPtsGroupModify.Delta.listDelete = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaDeleteMember) ? pProperties->aaDeleteMember : gs.aaDeleteMember );
4393 rc = Worker_DoTask (wtaskPtsGroupModify, &wp, &status);
4397 // Change the group's owner (if requested)
4399 if (rc && (pProperties->dwMask & MASK_GROUPPROP_szOwner))
4401 TCHAR szGroup[ cchNAME ];
4402 lpiGroup->GetGroupName (szGroup);
4405 wp.wpPtsGroupOwnerChange.hCell = hCell;
4406 wp.wpPtsGroupOwnerChange.pszGroup = szGroup;
4407 wp.wpPtsGroupOwnerChange.pszOwner = pProperties->szOwner;
4410 rc = Worker_DoTask (wtaskPtsGroupOwnerChange, &wp, &status);
4414 // If we were able to modify the group's properties successfully, refresh
4415 // either the group's status. If the group's owner changed, also refresh
4416 // the group's old and new owners.
4420 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4422 TCHAR szAccount[ cchNAME ];
4423 lpiGroup->GetGroupName (szAccount);
4424 lpCell->RefreshAccount (szAccount, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4426 if (pProperties->dwMask & MASK_GROUPPROP_szOwner)
4428 lpCell->RefreshAccount (gs.szOwner, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4429 lpCell->RefreshAccount (pProperties->szOwner, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4436 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup, status);
4445 BOOL AfsClass_RenameGroup (LPIDENT lpiGroup, LPTSTR pszNewName, ULONG *pStatus)
4451 NOTIFYCALLBACK::SendNotificationToAll (evtRenameGroupBegin, lpiGroup);
4457 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4461 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4466 // Get this group's list of members (etc)
4468 LPTSTR mszOwnerOf = NULL;
4469 LPTSTR mszMemberOf = NULL;
4470 LPTSTR mszMembers = NULL;
4473 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4475 lpGroup->GetOwnerOf (&mszOwnerOf);
4476 lpGroup->GetMemberOf (&mszMemberOf);
4477 lpGroup->GetMembers (&mszMembers);
4481 // Rename the group's PTS entry
4485 TCHAR szGroup[ cchNAME ];
4486 lpiGroup->GetGroupName (szGroup);
4489 wp.wpPtsGroupRename.hCell = hCell;
4490 wp.wpPtsGroupRename.pszGroup = szGroup;
4491 wp.wpPtsGroupRename.pszNewName = pszNewName;
4494 rc = Worker_DoTask (wtaskPtsGroupRename, &wp, &status);
4498 // If we were able to rename the group successfully, refresh the cell status.
4503 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4505 lpGroup->ChangeIdentName (pszNewName);
4508 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4510 lpCell->RefreshAccount (pszNewName, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4511 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4512 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4513 lpCell->RefreshAccounts (mszMembers, CELL_REFRESH_ACCOUNT_CHANGED);
4518 NOTIFYCALLBACK::SendNotificationToAll (evtRenameGroupEnd, lpiGroup, status);
4522 FreeString (mszOwnerOf);
4524 FreeString (mszMemberOf);
4526 FreeString (mszMembers);
4533 BOOL AfsClass_DeleteGroup (LPIDENT lpiGroup, ULONG *pStatus)
4539 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteGroupBegin, lpiGroup);
4545 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4549 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4554 // Get this group's list of members (etc)
4556 LPTSTR mszOwnerOf = NULL;
4557 LPTSTR mszMemberOf = NULL;
4558 LPTSTR mszMembers = NULL;
4561 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4563 lpGroup->GetOwnerOf (&mszOwnerOf);
4564 lpGroup->GetMemberOf (&mszMemberOf);
4565 lpGroup->GetMembers (&mszMembers);
4569 // Delete the group's PTS entry
4573 TCHAR szGroup[ cchNAME ];
4574 lpiGroup->GetGroupName (szGroup);
4577 wp.wpPtsGroupDelete.hCell = hCell;
4578 wp.wpPtsGroupDelete.pszGroup = szGroup;
4581 if ((rc = Worker_DoTask (wtaskPtsGroupDelete, &wp, &status)) == FALSE)
4583 if (status == ADMPTSFAILEDNAMETRANSLATE) // Group had no PTS entry?
4589 // If we were able to delete the group successfully, refresh the cell status.
4593 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4595 TCHAR szGroup[ cchNAME ];
4596 lpiGroup->GetGroupName (szGroup);
4597 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4598 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4599 lpCell->RefreshAccounts (mszMembers, CELL_REFRESH_ACCOUNT_CHANGED);
4600 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_DELETED);
4605 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteGroupEnd, lpiGroup, status);
4609 FreeString (mszOwnerOf);
4611 FreeString (mszMemberOf);
4613 FreeString (mszMembers);
4620 BOOL AfsClass_AddUserToGroup (LPIDENT lpiGroup, LPIDENT lpiUser, ULONG *pStatus)
4626 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberAddBegin, lpiGroup, lpiUser, NULL, NULL, 0, 0);
4632 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4636 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4641 TCHAR szGroup[ cchNAME ];
4642 lpiGroup->GetGroupName (szGroup);
4644 TCHAR szMember[ cchNAME ];
4645 if (lpiUser->fIsUser())
4646 lpiUser->GetFullUserName (szMember);
4647 else // (lpiUser->fIsGroup())
4648 lpiUser->GetGroupName (szMember);
4650 // Add this user to the specified group
4655 wp.wpPtsGroupMemberAdd.hCell = hCell;
4656 wp.wpPtsGroupMemberAdd.pszGroup = szGroup;
4657 wp.wpPtsGroupMemberAdd.pszUser = szMember;
4660 rc = Worker_DoTask (wtaskPtsGroupMemberAdd, &wp, &status);
4664 // If we were able to change the group successfully, update the group's
4665 // and user's properties.
4669 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4671 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4672 lpCell->RefreshAccount (szMember, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4677 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberAddEnd, lpiGroup, lpiUser, NULL, NULL, 0, status);
4686 BOOL AfsClass_RemoveUserFromGroup (LPIDENT lpiGroup, LPIDENT lpiUser, ULONG *pStatus)
4692 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberRemoveBegin, lpiGroup, lpiUser, NULL, NULL, 0, 0);
4698 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4702 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4707 TCHAR szGroup[ cchNAME ];
4708 lpiGroup->GetGroupName (szGroup);
4710 TCHAR szMember[ cchNAME ];
4711 if (lpiUser->fIsUser())
4712 lpiUser->GetFullUserName (szMember);
4713 else // (lpiUser->fIsGroup())
4714 lpiUser->GetGroupName (szMember);
4716 // Remove this user from the specified group
4721 wp.wpPtsGroupMemberRemove.hCell = hCell;
4722 wp.wpPtsGroupMemberRemove.pszGroup = szGroup;
4723 wp.wpPtsGroupMemberRemove.pszUser = szMember;
4726 rc = Worker_DoTask (wtaskPtsGroupMemberRemove, &wp, &status);
4730 // If we were able to change the group successfully, update the group's
4731 // and user's properties.
4735 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4737 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4738 lpCell->RefreshAccount (szMember, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4743 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberRemoveEnd, lpiGroup, lpiUser, NULL, NULL, 0, status);