2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
14 #include <afs/param.h>
18 #include <WINNT/afsclass.h>
23 * DEFINITIONS ________________________________________________________________
27 #define cREALLOC_ADMINLISTENTRIES 32
29 #define cREALLOC_HOSTLISTENTRIES 16
31 #define cREALLOC_SERVERKEYS 16
33 #define ACCOUNTACCESS_TO_USERACCESS(_aa) ( ((_aa) == aaOWNER_ONLY) ? PTS_USER_OWNER_ACCESS : PTS_USER_ANYUSER_ACCESS )
35 #define ACCOUNTACCESS_TO_GROUPACCESS(_aa) ( ((_aa) == aaOWNER_ONLY) ? PTS_GROUP_OWNER_ACCESS : ((_aa) == aaGROUP_ONLY) ? PTS_GROUP_ACCESS : PTS_GROUP_ANYUSER_ACCESS )
39 * PROTOTYPES _________________________________________________________________
45 * ROUTINES ___________________________________________________________________
49 BOOL AfsClass_GetServerLogFile (LPIDENT lpiServer, LPTSTR pszLocal, LPTSTR pszRemote, ULONG *pStatus)
55 NOTIFYCALLBACK::SendNotificationToAll (evtGetServerLogFileBegin, lpiServer, pszRemote, 0);
60 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
64 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
72 wp.wpBosLogGet.hServer = hBOS;
73 wp.wpBosLogGet.pszLogName = pszRemote;
74 wp.wpBosLogGet.pszLogData = NULL;
77 if ((rc = Worker_DoTask (wtaskBosLogGet, &wp, &status)) == TRUE)
80 if ((fh = CreateFile (pszLocal, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL)) != INVALID_HANDLE_VALUE)
82 // Write the file a line at a time in order to make
83 // sure that each line ends with "\r\n". If we encounter
84 // a line which ends in \r\n already, well, leave it alone.
86 for (LPTSTR psz = wp.wpBosLogGet.pszLogData; psz && *psz; )
89 for (pszNext = psz; *pszNext && (*pszNext != TEXT('\r')) && (*pszNext != TEXT('\n')); ++pszNext)
93 if ((cbWrite = (DWORD)(pszNext - psz)) != 0)
94 WriteFile (fh, psz, cbWrite, &cbWrote, NULL);
95 WriteFile (fh, TEXT("\r\n"), 2, &cbWrote, NULL);
96 psz = (*pszNext == TEXT('\r')) ? (2+pszNext) : (*pszNext == TEXT('\n')) ? (1+pszNext) : NULL;
101 Free (wp.wpBosLogGet.pszLogData);
107 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
109 lpServer->CloseBosObject();
113 NOTIFYCALLBACK::SendNotificationToAll (evtGetServerLogFileEnd, lpiServer, pszRemote, status);
122 BOOL AfsClass_SetServerAuth (LPIDENT lpiServer, BOOL fEnabled, ULONG *pStatus)
128 NOTIFYCALLBACK::SendNotificationToAll (evtSetServerAuthBegin, lpiServer);
133 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
137 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
145 wp.wpBosAuthSet.hServer = hBOS;
146 wp.wpBosAuthSet.fEnableAuth = fEnabled;
149 rc = Worker_DoTask (wtaskBosAuthSet, &wp, &status);
153 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
155 lpServer->CloseBosObject();
159 NOTIFYCALLBACK::SendNotificationToAll (evtSetServerAuthEnd, lpiServer, status);
168 BOOL AfsClass_StartService (LPIDENT lpiStart, BOOL fTemporary, ULONG *pStatus)
174 NOTIFYCALLBACK::SendNotificationToAll (evtStartServiceBegin, lpiStart);
179 if ((lpServer = lpiStart->OpenServer (&status)) == NULL)
183 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
190 if (lpiStart->fIsService())
192 TCHAR szName[ cchNAME ];
193 lpiStart->GetServiceName (szName);
198 wp.wpBosProcessExecutionStateSetTemporary.hServer = hBOS;
199 wp.wpBosProcessExecutionStateSetTemporary.pszService = szName;
200 wp.wpBosProcessExecutionStateSetTemporary.state = SERVICESTATE_RUNNING;
203 rc = Worker_DoTask (wtaskBosProcessExecutionStateSetTemporary, &wp, &status);
209 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
210 wp.wpBosProcessExecutionStateSet.pszService = szName;
211 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_RUNNING;
214 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
221 wp.wpBosProcessAllStart.hServer = hBOS;
223 rc = Worker_DoTask (wtaskBosProcessAllStart, &wp, &status);
230 if (lpiStart->fIsService())
233 if ((lpService = lpiStart->OpenService (&status)) == NULL)
237 lpService->Invalidate();
238 lpService->RefreshStatus();
244 if ((lpServer = lpiStart->OpenServer (&status)) == NULL)
248 lpServer->Invalidate();
249 lpServer->RefreshAll();
255 if ((lpServer = lpiStart->OpenServer (&status)) != NULL)
257 lpServer->CloseBosObject();
261 NOTIFYCALLBACK::SendNotificationToAll (evtStartServiceEnd, lpiStart, status);
270 BOOL AfsClass_StopService (LPIDENT lpiStop, BOOL fTemporary, BOOL fWait, ULONG *pStatus)
276 NOTIFYCALLBACK::SendNotificationToAll (evtStopServiceBegin, lpiStop);
281 if ((lpServer = lpiStop->OpenServer (&status)) == NULL)
285 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
292 if (lpiStop->fIsService())
294 TCHAR szName[ cchNAME ];
295 lpiStop->GetServiceName (szName);
300 wp.wpBosProcessExecutionStateSetTemporary.hServer = hBOS;
301 wp.wpBosProcessExecutionStateSetTemporary.pszService = szName;
302 wp.wpBosProcessExecutionStateSetTemporary.state = SERVICESTATE_STOPPED;
303 // TODO: wp.wpStopBosProcessTemporary.fWait = TRUE;
306 rc = Worker_DoTask (wtaskBosProcessExecutionStateSetTemporary, &wp, &status);
312 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
313 wp.wpBosProcessExecutionStateSet.pszService = szName;
314 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
315 // TODO: wp.wpStopBosProcess.fWait = TRUE;
318 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
325 wp.wpBosProcessAllWaitStop.hServer = hBOS;
328 rc = Worker_DoTask (wtaskBosProcessAllWaitStop, &wp, &status);
334 wp.wpBosProcessAllStop.hServer = hBOS;
337 rc = Worker_DoTask (wtaskBosProcessAllStop, &wp, &status);
344 if (lpiStop->fIsService())
347 if ((lpService = lpiStop->OpenService (&status)) == NULL)
351 lpService->Invalidate();
352 lpService->RefreshStatus();
359 if ((lpServer = lpiStop->OpenServer (&status)) == NULL)
363 lpServer->Invalidate();
364 lpServer->RefreshAll();
370 if ((lpServer = lpiStop->OpenServer (&status)) != NULL)
372 lpServer->CloseBosObject();
376 NOTIFYCALLBACK::SendNotificationToAll (evtStopServiceEnd, lpiStop, status);
385 BOOL AfsClass_RestartService (LPIDENT lpiRestart, ULONG *pStatus)
391 NOTIFYCALLBACK::SendNotificationToAll (evtRestartServiceBegin, lpiRestart);
396 if ((lpServer = lpiRestart->OpenServer (&status)) == NULL)
400 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
405 BOOL fRestartAll = FALSE;
406 if (!lpiRestart->fIsService())
409 TCHAR szServiceRestart[ cchNAME ];
410 if (lpiRestart->fIsService())
412 lpiRestart->GetServiceName (szServiceRestart);
413 if (!lstrcmpi (szServiceRestart, TEXT("BOS")))
422 wp.wpBosProcessRestart.hServer = hBOS;
423 wp.wpBosProcessRestart.pszService = szServiceRestart;
426 rc = Worker_DoTask (wtaskBosProcessRestart, &wp, &status);
429 else // (fRestartAll)
432 wp.wpBosProcessAllStopAndRestart.hServer = hBOS;
433 wp.wpBosProcessAllStopAndRestart.fRestartBOS = TRUE;
436 rc = Worker_DoTask (wtaskBosProcessAllStopAndRestart, &wp, &status);
446 if ((lpService = lpiRestart->OpenService (&status)) == NULL)
450 lpService->Invalidate();
451 lpService->RefreshStatus();
455 else // (fRestartAll)
458 if ((lpServer = lpiRestart->OpenServer (&status)) == NULL)
462 lpServer->Invalidate();
463 lpServer->RefreshAll();
469 if ((lpServer = lpiRestart->OpenServer (&status)) != NULL)
471 lpServer->CloseBosObject();
475 NOTIFYCALLBACK::SendNotificationToAll (evtRestartServiceEnd, lpiRestart, status);
484 LPIDENT AfsClass_CreateFileset (LPIDENT lpiAggregate, LPTSTR pszFileset, ULONG ckQuota, ULONG *pStatus)
486 LPIDENT lpiFileset = NULL;
491 NOTIFYCALLBACK::SendNotificationToAll (evtCreateFilesetBegin, lpiAggregate, pszFileset, 0);
493 // Obtain hCell and hVOS
498 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
502 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
507 // Obtain idPartition
510 LPAGGREGATE lpAggregate;
511 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
515 idPartition = lpAggregate->GetID();
516 lpAggregate->Close();
519 // Perform the actual operation
524 wp.wpVosVolumeCreate.hCell = hCell;
525 wp.wpVosVolumeCreate.hServer = hVOS;
526 wp.wpVosVolumeCreate.idPartition = idPartition;
527 wp.wpVosVolumeCreate.pszVolume = pszFileset;
528 wp.wpVosVolumeCreate.ckQuota = ckQuota;
531 rc = Worker_DoTask (wtaskVosVolumeCreate, &wp, &status);
539 LPAGGREGATE lpAggregate;
540 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
544 lpAggregate->Invalidate();
545 lpAggregate->RefreshFilesets (TRUE, &status);
546 lpAggregate->Close();
553 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
557 lpCell->RefreshVLDB (lpiAggregate);
564 LPAGGREGATE lpAggregate;
565 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
570 if ((lpFileset = lpAggregate->OpenFileset (pszFileset, &status)) == NULL)
574 lpiFileset = lpFileset->GetIdentifier();
577 lpAggregate->Close();
583 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
585 lpServer->CloseVosObject();
590 NOTIFYCALLBACK::SendNotificationToAll (evtCreateFilesetEnd, lpiAggregate, pszFileset, status);
595 return (rc) ? lpiFileset : NULL;
599 BOOL AfsClass_DeleteFileset (LPIDENT lpiFileset, BOOL fVLDB, BOOL fServer, ULONG *pStatus)
605 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiFileset);
607 // Obtain hCell and hVOS
612 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
616 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
621 // Does the fileset have a VLDB entry? Does it actually exist on the server?
622 // What's its volume ID? Its R/W ID? Its partition ID?
625 VOLUMEID vidReadWrite;
628 // Obtain the ID of the fileset's parent aggregate.
631 LPAGGREGATE lpAggregate;
632 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
636 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
638 lpAggregate->Close();
644 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
648 wFilesetGhost = lpFileset->GetGhostStatus();
649 lpiFileset->GetFilesetID (&vidFileset);
652 if (!lpFileset->GetStatus (&fs))
653 vidReadWrite = vidFileset;
655 vidReadWrite = fs.idReadWrite;
661 if (!(wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
663 if (!(wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
666 if (rc && fVLDB && fServer)
669 wp.wpVosVolumeDelete.hCell = hCell;
670 wp.wpVosVolumeDelete.hServer = hVOS;
671 wp.wpVosVolumeDelete.idPartition = idPartition;
672 wp.wpVosVolumeDelete.idVolume = vidFileset;
675 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
678 else if (rc && fVLDB)
681 wp.wpVosVLDBEntryRemove.hCell = hCell;
682 wp.wpVosVLDBEntryRemove.hServer = hVOS;
683 wp.wpVosVLDBEntryRemove.idPartition = idPartition;
684 wp.wpVosVLDBEntryRemove.idVolume = vidReadWrite;
687 rc = Worker_DoTask (wtaskVosVLDBEntryRemove, &wp, &status);
690 else if (rc && fServer)
693 wp.wpVosVolumeZap.hCell = hCell;
694 wp.wpVosVolumeZap.hServer = hVOS;
695 wp.wpVosVolumeZap.idPartition = idPartition;
696 wp.wpVosVolumeZap.idVolume = vidFileset;
697 wp.wpVosVolumeZap.fForce = TRUE;
700 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
706 LPAGGREGATE lpAggregate;
707 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
711 lpAggregate->Invalidate();
712 lpAggregate->RefreshFilesets (TRUE);
713 lpAggregate->Close();
720 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
724 lpCell->RefreshVLDB (lpiFileset->GetAggregate(), TRUE);
731 if ((lpServer = lpiFileset->OpenServer()) != NULL)
733 lpServer->CloseVosObject();
738 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiFileset, status);
747 BOOL AfsClass_MoveFileset (LPIDENT lpiFileset, LPIDENT lpiAggregateTarget, ULONG *pStatus)
753 NOTIFYCALLBACK::SendNotificationToAll (evtMoveFilesetBegin, lpiFileset, lpiAggregateTarget, NULL, NULL, 0, 0);
755 LPIDENT lpiAggregateSource = lpiFileset->GetAggregate();
757 // Obtain hCell, hVOS and the aggregate name for the source
760 PVOID hVOSSource = NULL;
762 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
766 if ((hVOSSource = lpServer->OpenVosObject (&hCell, &status)) == NULL)
771 // Obtain the ID of the source aggregate
773 int idPartitionSource;
774 LPAGGREGATE lpAggregate;
775 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
779 if ((idPartitionSource = lpAggregate->GetID()) == NO_PARTITION)
781 lpAggregate->Close();
784 // Obtain hCell, hVOS and the aggregate name for the target
786 PVOID hVOSTarget = NULL;
787 if ((lpServer = lpiAggregateTarget->OpenServer (&status)) == NULL)
791 if ((hVOSTarget = lpServer->OpenVosObject (NULL, &status)) == NULL)
796 // Obtain the ID of the target aggregate
798 int idPartitionTarget;
799 if ((lpAggregate = lpiAggregateTarget->OpenAggregate (&status)) == NULL)
803 if ((idPartitionTarget = lpAggregate->GetID()) == NO_PARTITION)
805 lpAggregate->Close();
811 wp.wpVosVolumeMove.hCell = hCell;
812 wp.wpVosVolumeMove.hServerFrom = hVOSSource;
813 wp.wpVosVolumeMove.idPartitionFrom = idPartitionSource;
814 wp.wpVosVolumeMove.hServerTo = hVOSTarget;
815 wp.wpVosVolumeMove.idPartitionTo = idPartitionTarget;
816 lpiFileset->GetFilesetID (&wp.wpVosVolumeMove.idVolume);
819 rc = Worker_DoTask (wtaskVosVolumeMove, &wp, &status);
825 LPAGGREGATE lpAggregate;
826 if ((lpAggregate = lpiAggregateSource->OpenAggregate (&status)) == NULL)
830 lpAggregate->Invalidate();
831 lpAggregate->RefreshFilesets();
832 lpAggregate->Close();
838 LPAGGREGATE lpAggregate;
839 if ((lpAggregate = lpiAggregateTarget->OpenAggregate (&status)) == NULL)
843 lpAggregate->Invalidate();
844 lpAggregate->RefreshFilesets();
845 lpAggregate->Close();
852 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
856 lpFileset->Invalidate();
857 lpFileset->RefreshStatus();
865 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
869 lpCell->RefreshVLDB (lpiAggregateSource, TRUE);
870 lpCell->RefreshVLDB (lpiAggregateTarget, TRUE);
877 if ((lpServer = lpiAggregateSource->OpenServer()) != NULL)
879 lpServer->CloseVosObject();
885 if ((lpServer = lpiAggregateTarget->OpenServer()) != NULL)
887 lpServer->CloseVosObject();
892 NOTIFYCALLBACK::SendNotificationToAll (evtMoveFilesetEnd, lpiFileset, lpiAggregateTarget, NULL, NULL, 0, status);
901 BOOL AfsClass_SetFilesetQuota (LPIDENT lpiFileset, size_t ckQuotaNew, ULONG *pStatus)
907 NOTIFYCALLBACK::SendNotificationToAll (evtSetFilesetQuotaBegin, lpiFileset);
909 // Obtain hCell and hVOS for the server where this fileset lives
914 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
918 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
923 // Obtain the ID of the fileset's parent aggregate.
928 LPAGGREGATE lpAggregate;
929 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
933 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
935 lpAggregate->Close();
939 // Change the fileset's quota.
944 wp.wpVosVolumeQuotaChange.hCell = hCell;
945 wp.wpVosVolumeQuotaChange.hServer = hVOS;
946 wp.wpVosVolumeQuotaChange.idPartition = idPartition;
947 lpiFileset->GetFilesetID (&wp.wpVosVolumeQuotaChange.idVolume);
948 wp.wpVosVolumeQuotaChange.ckQuota = ckQuotaNew;
951 rc = Worker_DoTask (wtaskVosVolumeQuotaChange, &wp, &status);
958 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
962 lpFileset->Invalidate();
963 lpFileset->RefreshStatus();
970 LPAGGREGATE lpAggregate;
971 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
975 lpAggregate->RefreshStatus();
976 lpAggregate->Close();
982 if ((lpServer = lpiFileset->OpenServer()) != NULL)
984 lpServer->CloseVosObject();
989 NOTIFYCALLBACK::SendNotificationToAll (evtSetFilesetQuotaEnd, lpiFileset, status);
998 BOOL AfsClass_SyncVLDB (LPIDENT lpiSync, BOOL fForce, ULONG *pStatus)
1004 NOTIFYCALLBACK::SendNotificationToAll (evtSyncVLDBBegin, lpiSync);
1006 // Obtain hCell and hVOS
1011 if ((lpServer = lpiSync->OpenServer (&status)) == NULL)
1015 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1020 // Obtain the ID of the target aggregate.
1022 int idPartition = NO_PARTITION;
1023 if (rc && (lpiSync->fIsAggregate() || lpiSync->fIsFileset()))
1025 LPAGGREGATE lpAggregate;
1026 if ((lpAggregate = lpiSync->OpenAggregate (&status)) == NULL)
1030 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1032 lpAggregate->Close();
1039 wp.wpVosVLDBSync.hCell = hCell;
1040 wp.wpVosVLDBSync.hServer = hVOS;
1041 wp.wpVosVLDBSync.idPartition = idPartition;
1042 wp.wpVosVLDBSync.fForce = fForce;
1045 rc = Worker_DoTask (wtaskVosVLDBSync, &wp, &status);
1051 if (lpiSync->fIsServer())
1054 if ((lpServer = lpiSync->OpenServer (&status)) == NULL)
1058 lpServer->Invalidate();
1059 rc = lpServer->RefreshAll (&status);
1063 else // (lpiSync->fIsAggregate())
1065 LPAGGREGATE lpAggregate;
1066 if ((lpAggregate = lpiSync->OpenAggregate (&status)) == NULL)
1070 lpAggregate->Invalidate();
1071 lpAggregate->RefreshStatus();
1072 lpAggregate->RefreshFilesets();
1073 lpAggregate->Close();
1076 if ((lpCell = lpiSync->OpenCell()) == NULL)
1080 lpCell->RefreshVLDB (lpiSync);
1089 if ((lpServer = lpiSync->OpenServer()) != NULL)
1091 lpServer->CloseVosObject();
1096 NOTIFYCALLBACK::SendNotificationToAll (evtSyncVLDBEnd, lpiSync, status);
1105 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSOCKADDR_IN pAddrOld, LPSOCKADDR_IN pAddrNew, ULONG *pStatus)
1111 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1117 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1121 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1129 wp.wpVosFileServerAddressChange.hCell = hCell;
1130 wp.wpVosFileServerAddressChange.addrOld = *pAddrOld;
1131 wp.wpVosFileServerAddressChange.addrNew = *pAddrNew;
1134 rc = Worker_DoTask (wtaskVosFileServerAddressChange, &wp, &status);
1137 else if (rc && !pAddrNew)
1140 wp.wpVosFileServerAddressRemove.hCell = hCell;
1141 wp.wpVosFileServerAddressRemove.addr = *pAddrOld;
1144 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1151 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1153 lpServer->InvalidateStatus();
1158 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1162 lpCell->InvalidateServers ();
1163 rc = lpCell->RefreshServers (TRUE, &status);
1168 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1177 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSERVERSTATUS pStatusOld, LPSERVERSTATUS pStatusNew, ULONG *pStatus)
1183 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1189 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1193 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1202 for (size_t iAddr = 0; rc && (iAddr < AFSCLASS_MAX_ADDRESSES_PER_SITE); ++iAddr)
1206 AfsClass_AddressToInt (&oldAddress, &pStatusOld->aAddresses[ iAddr ]);
1207 AfsClass_AddressToInt (&newAddress, &pStatusNew->aAddresses[ iAddr ]);
1209 if (oldAddress && newAddress && (oldAddress != newAddress))
1212 wp.wpVosFileServerAddressChange.hCell = hCell;
1213 wp.wpVosFileServerAddressChange.addrOld = pStatusOld->aAddresses[ iAddr ];
1214 wp.wpVosFileServerAddressChange.addrNew = pStatusNew->aAddresses[ iAddr ];
1216 rc = Worker_DoTask (wtaskVosFileServerAddressChange, &wp, &status);
1218 else if (oldAddress && !newAddress)
1221 wp.wpVosFileServerAddressRemove.hCell = hCell;
1222 wp.wpVosFileServerAddressRemove.addr = pStatusOld->aAddresses[ iAddr ];
1224 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1234 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1236 lpServer->InvalidateStatus();
1241 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1245 lpCell->InvalidateServers ();
1246 rc = lpCell->RefreshServers (TRUE, &status);
1251 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1260 BOOL AfsClass_LockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1266 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetBegin, lpiFileset);
1272 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1276 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1281 // Obtain the fileset's read-write identifier
1283 LPIDENT lpiRW = NULL;
1284 LPFILESET lpFileset;
1285 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1289 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1294 // Perform the lock operation
1299 wp.wpVosVLDBEntryLock.hCell = hCell;
1300 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryLock.idVolume);
1303 rc = Worker_DoTask (wtaskVosVLDBEntryLock, &wp, &status);
1310 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1315 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1317 lpCell->RefreshVLDB (lpiFileset->GetCell());
1322 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetEnd, lpiFileset, status);
1331 BOOL AfsClass_UnlockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1337 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetBegin, lpiFileset);
1343 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1347 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1352 // Obtain the fileset's read-write identifier
1354 LPIDENT lpiRW = NULL;
1355 LPFILESET lpFileset;
1356 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1360 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1365 // Perform the unlock operation
1370 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1371 wp.wpVosVLDBEntryUnlock.hServer = NULL;
1372 wp.wpVosVLDBEntryUnlock.idPartition = NO_PARTITION;
1373 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryUnlock.idVolume);
1376 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1383 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1388 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1390 lpCell->RefreshVLDB (lpiFileset->GetCell());
1395 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetEnd, lpiFileset, status);
1404 BOOL AfsClass_UnlockAllFilesets (LPIDENT lpi, ULONG *pStatus)
1410 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsBegin, lpi);
1416 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1420 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1425 // Obtain hServer if appropriate
1428 if (lpi && (!lpi->fIsCell()))
1431 if ((lpServer = lpi->OpenServer (&status)) == NULL)
1435 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
1441 // Obtain the ID of the scope aggregate.
1443 int idPartition = NO_PARTITION;
1444 if (rc && (lpi->fIsFileset() || (lpi->fIsAggregate())))
1446 LPAGGREGATE lpAggregate;
1447 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
1451 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1453 lpAggregate->Close();
1457 // Perform the unlock operation
1462 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1463 wp.wpVosVLDBEntryUnlock.hServer = hVOS;
1464 wp.wpVosVLDBEntryUnlock.idPartition = idPartition;
1465 wp.wpVosVLDBEntryUnlock.idVolume = NO_VOLUME;
1468 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1475 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1479 lpCell->RefreshVLDB (lpi);
1487 if ((lpServer = lpi->OpenServer (&status)) != NULL)
1489 lpServer->CloseVosObject();
1494 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsEnd, lpi);
1503 LPIDENT AfsClass_CreateReplica (LPIDENT lpiFileset, LPIDENT lpiAggregate, ULONG *pStatus)
1507 LPIDENT lpiReplica = NULL;
1510 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaBegin, lpiFileset, lpiAggregate, NULL, NULL, 0, 0);
1512 // Obtain hCell and hVOS for the target server
1517 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
1521 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1526 // Obtain idPartition
1529 LPAGGREGATE lpAggregate;
1530 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1534 idPartition = lpAggregate->GetID();
1535 lpAggregate->Close();
1538 // Modify VLDB to create mention of a new replica
1543 wp.wpVosVLDBReadOnlySiteCreate.hCell = hCell;
1544 wp.wpVosVLDBReadOnlySiteCreate.hServer = hVOS;
1545 wp.wpVosVLDBReadOnlySiteCreate.idPartition = idPartition;
1546 lpiFileset->GetFilesetID (&wp.wpVosVLDBReadOnlySiteCreate.idVolume);
1549 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteCreate, &wp, &status);
1557 LPAGGREGATE lpAggregate;
1558 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1562 lpAggregate->Invalidate();
1563 lpAggregate->RefreshFilesets (TRUE, &status);
1564 lpAggregate->Close();
1571 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
1575 lpCell->RefreshVLDB (lpiAggregate);
1582 LPFILESET lpFileset;
1583 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1587 if ((lpiReplica = lpFileset->GetReadOnlyIdentifier (lpiAggregate, &status)) == NULL)
1595 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
1597 lpServer->CloseVosObject();
1602 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaEnd, lpiFileset, lpiAggregate, NULL, NULL, 0, status);
1607 return (rc) ? lpiReplica : FALSE;
1611 BOOL AfsClass_DeleteReplica (LPIDENT lpiReplica, ULONG *pStatus)
1617 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiReplica);
1619 // Obtain hCell and hVOS for the server
1624 if ((lpServer = lpiReplica->OpenServer (&status)) == NULL)
1628 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1633 // Get the read/write fileset identifier and Ghost status
1635 LPIDENT lpiRW = NULL;
1636 int wFilesetGhost = 0;
1637 LPFILESET lpFileset;
1638 if ((lpFileset = lpiReplica->OpenFileset (&status)) == NULL)
1642 wFilesetGhost = lpFileset->GetGhostStatus();
1643 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1648 TCHAR szAggregateName[ cchNAME ];
1649 lpiReplica->GetAggregateName (szAggregateName);
1651 // Obtain the ID of the replica's partition
1654 LPAGGREGATE lpAggregate;
1655 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1659 idPartition = lpAggregate->GetID();
1660 lpAggregate->Close();
1663 // If the volume exists in both VLDB and on the server, just delete it
1665 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY) && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1668 wp.wpVosVolumeDelete.hCell = hCell;
1669 wp.wpVosVolumeDelete.hServer = hVOS;
1670 wp.wpVosVolumeDelete.idPartition = idPartition;
1671 lpiReplica->GetFilesetID (&wp.wpVosVolumeDelete.idVolume);
1674 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
1679 // If necessary, modify VLDB to remove mention of this replica
1681 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
1684 wp.wpVosVLDBReadOnlySiteDelete.hCell = hCell;
1685 wp.wpVosVLDBReadOnlySiteDelete.hServer = hVOS;
1686 wp.wpVosVLDBReadOnlySiteDelete.idPartition = idPartition;
1687 lpiRW->GetFilesetID (&wp.wpVosVLDBReadOnlySiteDelete.idVolume);
1690 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteDelete, &wp, &status);
1694 // If necessary, zap the volume
1696 if (rc && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1699 wp.wpVosVolumeZap.hCell = hCell;
1700 wp.wpVosVolumeZap.hServer = hVOS;
1701 wp.wpVosVolumeZap.idPartition = idPartition;
1702 lpiReplica->GetFilesetID (&wp.wpVosVolumeZap.idVolume);
1703 wp.wpVosVolumeZap.fForce = TRUE;
1706 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
1715 LPAGGREGATE lpAggregate;
1716 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1720 lpAggregate->Invalidate();
1721 lpAggregate->RefreshFilesets (TRUE, &status);
1722 lpAggregate->Close();
1729 if ((lpCell = lpiReplica->OpenCell()) == NULL)
1733 lpCell->RefreshVLDB (lpiReplica->GetAggregate());
1740 if ((lpServer = lpiReplica->OpenServer (&status)) != NULL)
1742 lpServer->CloseVosObject();
1747 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiReplica, status);
1756 BOOL AfsClass_DeleteClone (LPIDENT lpiClone, ULONG *pStatus)
1758 return AfsClass_DeleteFileset (lpiClone, TRUE, TRUE, pStatus);
1762 BOOL AfsClass_InstallFile (LPIDENT lpiServer, LPTSTR pszTarget, LPTSTR pszSource, ULONG *pStatus)
1768 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileBegin, lpiServer, pszSource, 0);
1773 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1777 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1785 wp.wpBosExecutableCreate.hServer = hBOS;
1786 wp.wpBosExecutableCreate.pszLocal = pszSource;
1787 wp.wpBosExecutableCreate.pszRemoteDir = pszTarget;
1790 rc = Worker_DoTask (wtaskBosExecutableCreate, &wp, &status);
1794 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1796 lpServer->CloseBosObject();
1800 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileEnd, lpiServer, pszSource, status);
1809 BOOL AfsClass_UninstallFile (LPIDENT lpiServer, LPTSTR pszUninstall, ULONG *pStatus)
1815 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileBegin, lpiServer, pszUninstall, 0);
1820 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1824 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1832 wp.wpBosExecutableRevert.hServer = hBOS;
1833 wp.wpBosExecutableRevert.pszFilename = pszUninstall;
1836 rc = Worker_DoTask (wtaskBosExecutableRevert, &wp, &status);
1840 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1842 lpServer->CloseBosObject();
1846 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileEnd, lpiServer, pszUninstall, status);
1855 BOOL AfsClass_PruneOldFiles (LPIDENT lpiServer, BOOL fBAK, BOOL fOLD, BOOL fCore, ULONG *pStatus)
1861 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesBegin, lpiServer);
1866 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1870 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1878 wp.wpBosExecutablePrune.hServer = hBOS;
1879 wp.wpBosExecutablePrune.fPruneBak = fBAK;
1880 wp.wpBosExecutablePrune.fPruneOld = fOLD;
1881 wp.wpBosExecutablePrune.fPruneCore = fCore;
1884 rc = Worker_DoTask (wtaskBosExecutablePrune, &wp, &status);
1888 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1890 lpServer->CloseBosObject();
1894 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesEnd, lpiServer, status);
1903 BOOL AfsClass_RenameFileset (LPIDENT lpiFileset, LPTSTR pszNewName, ULONG *pStatus)
1909 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetBegin, lpiFileset, pszNewName, 0);
1913 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1917 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1925 wp.wpVosVolumeRename.hCell = hCell;
1926 lpiFileset->GetFilesetID (&wp.wpVosVolumeRename.idVolume);
1927 wp.wpVosVolumeRename.pszVolume = pszNewName;
1930 rc = Worker_DoTask (wtaskVosVolumeRename, &wp, &status);
1937 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1941 lpCell->Invalidate();
1942 rc = lpCell->RefreshAll (&status);
1948 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetEnd, lpiFileset, pszNewName, status);
1957 #define iswhite(_ch) ((_ch)==TEXT(' ') || (_ch)==TEXT('\t'))
1959 LPIDENT AfsClass_CreateService (LPIDENT lpiServer, LPTSTR pszService, LPTSTR pszCommand, LPTSTR pszParams, LPTSTR pszNotifier, AFSSERVICETYPE type, SYSTEMTIME *pstIfCron, ULONG *pStatus)
1963 LPIDENT lpiService = NULL;
1966 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceBegin, lpiServer, pszService, 0);
1971 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1975 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1983 wp.wpBosProcessCreate.hServer = hBOS;
1984 wp.wpBosProcessCreate.pszService = pszService;
1985 wp.wpBosProcessCreate.type = type;
1986 wp.wpBosProcessCreate.pszNotifier = pszNotifier;
1988 TCHAR szFullCommand[ MAX_PATH + MAX_PATH ];
1989 wsprintf (szFullCommand, TEXT("%s %s"), pszCommand, pszParams);
1990 wp.wpBosProcessCreate.pszCommand = szFullCommand;
1992 TCHAR szCronTime[ 256 ] = TEXT("");
1993 wp.wpBosProcessCreate.pszTimeCron = szCronTime;
1995 if (type == SERVICETYPE_CRON)
1996 AfsClass_FormatRecurringTime (szCronTime, pstIfCron);
1998 wp.wpBosProcessCreate.pszTimeCron = NULL;
2001 rc = Worker_DoTask (wtaskBosProcessCreate, &wp, &status);
2007 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2011 lpServer->InvalidateServices();
2012 if (!lpServer->RefreshServices (TRUE, &status))
2016 LPSERVICE lpService;
2017 if ((lpService = lpServer->OpenService (pszService, &status)) == NULL)
2021 lpiService = lpService->GetIdentifier();
2029 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2031 lpServer->CloseBosObject();
2035 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceEnd, lpiServer, pszService, status);
2040 return (rc) ? lpiService : NULL;
2044 BOOL AfsClass_DeleteService (LPIDENT lpiService, ULONG *pStatus)
2050 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceBegin, lpiService);
2055 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2059 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2064 // Before a service can be deleted, it must be stopped (otherwise, on NT,
2065 // the Delete operation won't block for the required Stop to complete--
2066 // so our wtaskDeleteBosProcess would return before the service really
2071 TCHAR szService[ cchNAME ];
2072 lpiService->GetServiceName (szService);
2075 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
2076 wp.wpBosProcessExecutionStateSet.pszService = szService;
2077 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
2078 // TODO: wp.wpStopBosProcess.fWait = TRUE;
2081 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
2085 // Delete the service
2089 TCHAR szService[ cchNAME ];
2090 lpiService->GetServiceName (szService);
2093 wp.wpBosProcessDelete.hServer = hBOS;
2094 wp.wpBosProcessDelete.pszService = szService;
2097 rc = Worker_DoTask (wtaskBosProcessDelete, &wp, &status);
2103 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2107 lpServer->InvalidateServices();
2108 if (!lpServer->RefreshServices (TRUE, &status))
2114 if ((lpServer = lpiService->OpenServer (&status)) != NULL)
2116 lpServer->CloseBosObject();
2120 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceEnd, lpiService, status);
2129 BOOL AfsClass_ReleaseFileset (LPIDENT lpiFilesetRW, BOOL fForce, ULONG *pStatus)
2135 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetBegin, lpiFilesetRW);
2137 // Obtain hCell and hVOS
2142 if ((lpServer = lpiFilesetRW->OpenServer (&status)) == NULL)
2146 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2151 // Perform the actual operation
2156 wp.wpVosVolumeRelease.hCell = hCell;
2157 wp.wpVosVolumeRelease.fForce = fForce;
2158 lpiFilesetRW->GetFilesetID (&wp.wpVosVolumeRelease.idVolume);
2161 rc = Worker_DoTask (wtaskVosVolumeRelease, &wp, &status);
2170 if ((lpCell = lpiFilesetRW->OpenCell (&status)) == NULL)
2174 lpCell->Invalidate();
2175 rc = lpCell->RefreshAll (&status);
2182 if ((lpServer = lpiFilesetRW->OpenServer (&status)) != NULL)
2184 lpServer->CloseVosObject();
2189 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetEnd, lpiFilesetRW, status);
2198 BOOL AfsClass_GetFileDates (LPIDENT lpiServer, LPTSTR pszFilename, SYSTEMTIME *pstFile, SYSTEMTIME *pstBAK, SYSTEMTIME *pstOLD, ULONG *pStatus)
2204 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesBegin, lpiServer, pszFilename, 0);
2209 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2213 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2221 wp.wpBosExecutableTimestampGet.hServer = hBOS;
2222 wp.wpBosExecutableTimestampGet.pszFilename = pszFilename;
2225 if ((rc = Worker_DoTask (wtaskBosExecutableTimestampGet, &wp, &status)) == TRUE)
2227 *pstFile = wp.wpBosExecutableTimestampGet.timeNew;
2228 *pstBAK = wp.wpBosExecutableTimestampGet.timeBak;
2229 *pstOLD = wp.wpBosExecutableTimestampGet.timeOld;
2235 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2237 lpServer->CloseBosObject();
2241 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesEnd, lpiServer, pszFilename, status);
2250 BOOL AfsClass_ExecuteCommand (LPIDENT lpiServer, LPTSTR pszCommand, ULONG *pStatus)
2256 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandBegin, lpiServer, pszCommand, 0);
2261 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2265 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2273 wp.wpBosCommandExecute.hServer = hBOS;
2274 wp.wpBosCommandExecute.pszCommand = pszCommand;
2277 rc = Worker_DoTask (wtaskBosCommandExecute, &wp, &status);
2281 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2283 lpServer->CloseBosObject();
2287 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandEnd, lpiServer, pszCommand, status);
2296 LPADMINLIST AfsClass_AdminList_Load (LPIDENT lpiServer, ULONG *pStatus)
2300 LPADMINLIST lpList = NULL;
2303 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadBegin, lpiServer);
2308 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2312 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2319 lpList = New(ADMINLIST);
2320 memset (lpList, 0x00, sizeof(ADMINLIST));
2322 lpList->lpiServer = lpiServer;
2324 WORKERPACKET wpBegin;
2325 wpBegin.wpBosAdminGetBegin.hServer = hBOS;
2326 if (!Worker_DoTask (wtaskBosAdminGetBegin, &wpBegin, &status))
2332 TCHAR szAdmin[ cchNAME ];
2334 WORKERPACKET wpNext;
2335 wpNext.wpBosAdminGetNext.hEnum = wpBegin.wpBosAdminGetBegin.hEnum;
2336 wpNext.wpBosAdminGetNext.pszAdmin = szAdmin;
2338 if (!Worker_DoTask (wtaskBosAdminGetNext, &wpNext, &status))
2340 if (status == ADMITERATORDONE)
2348 if ((iAdded = AfsClass_AdminList_AddEntry (lpList, szAdmin)) != (size_t)-1)
2350 lpList->aEntries[ iAdded ].fAdded = FALSE;
2354 WORKERPACKET wpDone;
2355 wpDone.wpBosAdminGetDone.hEnum = wpBegin.wpBosAdminGetBegin.hEnum;
2356 Worker_DoTask (wtaskBosAdminGetDone, &wpDone);
2360 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2362 lpServer->CloseBosObject();
2366 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadEnd, lpiServer, status);
2371 return (rc) ? lpList : NULL;
2375 LPADMINLIST AfsClass_AdminList_Copy (LPADMINLIST lpOld)
2377 LPADMINLIST lpNew = NULL;
2381 lpNew = New(ADMINLIST);
2382 memcpy (lpNew, lpOld, sizeof(ADMINLIST));
2385 lpNew->aEntries = 0;
2386 lpNew->cEntries = 0;
2388 if (REALLOC (lpNew->aEntries, lpNew->cEntries, lpOld->cEntries, cREALLOC_ADMINLISTENTRIES))
2390 size_t cb = lpOld->cEntries * sizeof(ADMINLISTENTRY);
2391 memcpy (lpNew->aEntries, lpOld->aEntries, cb);
2399 BOOL AfsClass_AdminList_Save (LPADMINLIST lpList, ULONG *pStatus)
2405 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveBegin, lpList->lpiServer);
2410 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
2414 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2421 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2423 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2426 // are we supposed to add this entry?
2428 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
2431 wp.wpBosAdminCreate.hServer = hBOS;
2432 wp.wpBosAdminCreate.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2435 if (!Worker_DoTask (wtaskBosAdminCreate, &wp, &thisstatus))
2438 status = thisstatus;
2442 lpList->aEntries[ iEntry ].fAdded = FALSE;
2446 // are we supposed to delete this entry?
2448 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
2451 wp.wpBosAdminDelete.hServer = hBOS;
2452 wp.wpBosAdminDelete.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2455 if (!Worker_DoTask (wtaskBosAdminDelete, &wp, &thisstatus))
2458 status = thisstatus;
2462 lpList->aEntries[ iEntry ].szAdmin[0] = TEXT('\0');
2463 lpList->aEntries[ iEntry ].fDeleted = FALSE;
2469 if ((lpServer = lpList->lpiServer->OpenServer (&status)) != NULL)
2471 lpServer->CloseBosObject();
2475 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveEnd, lpList->lpiServer, status);
2484 void AfsClass_AdminList_Free (LPADMINLIST lpList)
2486 if (lpList && !InterlockedDecrement (&lpList->cRef))
2488 if (lpList->aEntries)
2489 Free (lpList->aEntries);
2490 memset (lpList, 0x00, sizeof(ADMINLIST));
2496 size_t AfsClass_AdminList_AddEntry (LPADMINLIST lpList, LPTSTR pszAdmin)
2498 size_t iAdded = (size_t)-1;
2503 for (iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2505 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2508 if (iEntry >= lpList->cEntries)
2510 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_ADMINLISTENTRIES);
2512 if (iEntry < lpList->cEntries)
2515 lstrcpy (lpList->aEntries[ iAdded ].szAdmin, pszAdmin);
2516 lpList->aEntries[ iAdded ].fAdded = TRUE;
2517 lpList->aEntries[ iAdded ].fDeleted = FALSE;
2525 BOOL AfsClass_AdminList_DelEntry (LPADMINLIST lpList, size_t iIndex)
2530 (iIndex < lpList->cEntries) &&
2531 (lpList->aEntries[ iIndex ].szAdmin[0]) &&
2532 (!lpList->aEntries[ iIndex ].fDeleted) )
2534 if (lpList->aEntries[ iIndex ].fAdded)
2535 lpList->aEntries[ iIndex ].szAdmin[0] = TEXT('\0');
2537 lpList->aEntries[ iIndex ].fDeleted = TRUE;
2546 LPKEYLIST AfsClass_KeyList_Load (LPIDENT lpiServer, ULONG *pStatus)
2550 LPKEYLIST lpList = NULL;
2553 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadBegin, lpiServer);
2558 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2562 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2569 lpList = New(KEYLIST);
2570 memset (lpList, 0x00, sizeof(KEYLIST));
2571 lpList->lpiServer = lpiServer;
2573 WORKERPACKET wpBegin;
2574 wpBegin.wpBosKeyGetBegin.hServer = hBOS;
2575 if (!Worker_DoTask (wtaskBosKeyGetBegin, &wpBegin, &status))
2579 for (size_t iEnum = 0; ; ++iEnum)
2581 WORKERPACKET wpNext;
2582 wpNext.wpBosKeyGetNext.hEnum = wpBegin.wpBosKeyGetBegin.hEnum;
2584 if (!Worker_DoTask (wtaskBosKeyGetNext, &wpNext, &status))
2586 if (status == ADMITERATORDONE)
2593 if (REALLOC (lpList->aKeys, lpList->cKeys, 1+iEnum, cREALLOC_SERVERKEYS))
2595 lpList->aKeys[ iEnum ].keyVersion = wpNext.wpBosKeyGetNext.keyVersion;
2596 memcpy (&lpList->aKeys[ iEnum ].keyData, &wpNext.wpBosKeyGetNext.keyData, sizeof(ENCRYPTIONKEY));
2597 memcpy (&lpList->aKeys[ iEnum ].keyInfo, &wpNext.wpBosKeyGetNext.keyInfo, sizeof(ENCRYPTIONKEYINFO));
2601 WORKERPACKET wpDone;
2602 wpDone.wpBosKeyGetDone.hEnum = wpBegin.wpBosKeyGetBegin.hEnum;
2603 Worker_DoTask (wtaskBosKeyGetDone, &wpDone);
2607 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2609 lpServer->CloseBosObject();
2613 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadEnd, lpiServer, status);
2618 return (rc) ? lpList : NULL;
2622 void AfsClass_KeyList_Free (LPKEYLIST lpList)
2627 Free (lpList->aKeys);
2628 memset (lpList, 0x00, sizeof(KEYLIST));
2634 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPTSTR pszString, ULONG *pStatus)
2639 TCHAR szCell[ cchNAME ];
2640 lpiServer->GetCellName (szCell);
2643 wp.wpKasStringToKey.pszCell = szCell;
2644 wp.wpKasStringToKey.pszString = pszString;
2645 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
2649 else if (!AfsClass_AddKey (lpiServer, keyVersion, &wp.wpKasStringToKey.key, &status))
2660 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2668 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2672 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2680 wp.wpBosKeyCreate.hServer = hBOS;
2681 wp.wpBosKeyCreate.keyVersion = keyVersion;
2682 memcpy (&wp.wpBosKeyCreate.key, pKey, sizeof(ENCRYPTIONKEY));
2683 rc = Worker_DoTask (wtaskBosKeyCreate, &wp, &status);
2686 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2688 lpServer->CloseBosObject();
2698 BOOL AfsClass_DeleteKey (LPIDENT lpiServer, int keyVersion, ULONG *pStatus)
2706 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2710 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2718 wp.wpBosKeyDelete.hServer = hBOS;
2719 wp.wpBosKeyDelete.keyVersion = keyVersion;
2720 rc = Worker_DoTask (wtaskBosKeyDelete, &wp, &status);
2723 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2725 lpServer->CloseBosObject();
2735 BOOL AfsClass_GetRandomKey (LPIDENT lpi, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2743 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2747 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2750 hKAS = lpCell->GetKasObject (&status);
2757 wp.wpKasServerRandomKeyGet.hCell = hCell;
2758 wp.wpKasServerRandomKeyGet.hServer = hKAS;
2759 rc = Worker_DoTask (wtaskKasServerRandomKeyGet, &wp, &status);
2762 memcpy (pKey, &wp.wpKasServerRandomKeyGet.key, sizeof(ENCRYPTIONKEY));
2771 BOOL AfsClass_Clone (LPIDENT lpiRW, ULONG *pStatus)
2777 NOTIFYCALLBACK::SendNotificationToAll (evtCloneBegin, lpiRW, 0);
2783 if ((lpCell = lpiRW->OpenCell (&status)) == NULL)
2787 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2792 // Perform the actual operation
2797 wp.wpVosBackupVolumeCreate.hCell = hCell;
2798 lpiRW->GetFilesetID (&wp.wpVosBackupVolumeCreate.idVolume);
2801 rc = Worker_DoTask (wtaskVosBackupVolumeCreate, &wp, &status);
2810 if ((lpServer = lpiRW->OpenServer (&status)) == NULL)
2814 lpServer->Invalidate();
2815 rc = lpServer->RefreshAll (&status);
2820 NOTIFYCALLBACK::SendNotificationToAll (evtCloneEnd, lpiRW, status);
2829 BOOL AfsClass_CloneMultiple (LPIDENT lpi, LPTSTR pszPrefix, BOOL fExclude, ULONG *pStatus)
2835 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleBegin, lpi);
2841 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2845 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2850 // Obtain hServer if appropriate
2853 if (!lpi->fIsCell())
2856 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2860 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
2866 // If requested, obtain the appropriate aggregate ID
2868 int idPartition = NO_PARTITION;
2869 if (rc && (lpi->fIsFileset() || lpi->fIsAggregate()))
2871 LPAGGREGATE lpAggregate;
2872 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2876 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
2878 lpAggregate->Close();
2882 // Perform the actual operation
2887 wp.wpVosBackupVolumeCreateMultiple.hCell = hCell;
2888 wp.wpVosBackupVolumeCreateMultiple.hServer = hVOS;
2889 wp.wpVosBackupVolumeCreateMultiple.idPartition = idPartition;
2890 wp.wpVosBackupVolumeCreateMultiple.pszPrefix = pszPrefix;
2891 wp.wpVosBackupVolumeCreateMultiple.fExclude = fExclude;
2894 rc = Worker_DoTask (wtaskVosBackupVolumeCreateMultiple, &wp, &status);
2905 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2909 lpCell->Invalidate();
2910 rc = lpCell->RefreshAll (&status);
2917 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2921 lpServer->Invalidate();
2922 rc = lpServer->RefreshAll (&status);
2931 if ((lpServer = lpi->OpenServer (&status)) != NULL)
2933 lpServer->CloseVosObject();
2938 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleEnd, lpi, status);
2947 BOOL AfsClass_DumpFileset (LPIDENT lpi, LPTSTR pszFilename, LPSYSTEMTIME pstDate, ULONG *pStatus)
2953 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetBegin, lpi, pszFilename, 0);
2955 // Obtain hCell and hVOS
2960 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2964 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2969 // Obtain idPartition
2972 LPAGGREGATE lpAggregate;
2973 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2977 idPartition = lpAggregate->GetID();
2978 lpAggregate->Close();
2981 // Perform the actual operation
2986 wp.wpVosVolumeDump.hCell = hCell;
2987 wp.wpVosVolumeDump.hServer = hVOS;
2988 wp.wpVosVolumeDump.pszFilename = pszFilename;
2989 wp.wpVosVolumeDump.idPartition = idPartition;
2990 lpi->GetFilesetID (&wp.wpVosVolumeDump.idVolume);
2993 memcpy (&wp.wpVosVolumeDump.stStart, pstDate, sizeof(SYSTEMTIME));
2995 memset (&wp.wpVosVolumeDump.stStart, 0x00, sizeof(SYSTEMTIME));
2998 rc = Worker_DoTask (wtaskVosVolumeDump, &wp, &status);
3002 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetEnd, lpi, pszFilename, status);
3008 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3010 lpServer->CloseVosObject();
3021 BOOL AfsClass_RestoreFileset (LPIDENT lpi, LPTSTR pszFileset, LPTSTR pszFilename, BOOL fIncremental, ULONG *pStatus)
3027 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetBegin, lpi, NULL, pszFileset, pszFilename, 0, 0);
3029 // Obtain hCell and hVOS
3034 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3038 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
3043 // Obtain idPartition
3046 LPAGGREGATE lpAggregate;
3047 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
3051 idPartition = lpAggregate->GetID();
3052 lpAggregate->Close();
3055 // Perform the actual operation
3060 wp.wpVosVolumeRestore.hCell = hCell;
3061 wp.wpVosVolumeRestore.hServer = hVOS;
3062 wp.wpVosVolumeRestore.idPartition = idPartition;
3063 wp.wpVosVolumeRestore.pszVolume = pszFileset;
3064 wp.wpVosVolumeRestore.pszFilename = pszFilename;
3065 wp.wpVosVolumeRestore.fIncremental = fIncremental;
3067 if (lpi->fIsFileset())
3068 lpi->GetFilesetID (&wp.wpVosVolumeRestore.idVolume);
3070 wp.wpVosVolumeRestore.idVolume = NO_VOLUME;
3073 rc = Worker_DoTask (wtaskVosVolumeRestore, &wp, &status);
3081 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3085 lpServer->Invalidate();
3086 rc = lpServer->RefreshAll (&status);
3093 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3095 lpServer->CloseVosObject();
3100 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetEnd, lpi, NULL, pszFileset, pszFilename, 0, status);
3109 BOOL AfsClass_GetRestartTimes (LPIDENT lpiServer, BOOL *pfWeekly, LPSYSTEMTIME pstWeekly, BOOL *pfDaily, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3115 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesBegin, lpiServer);
3120 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3124 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3132 wp.wpBosExecutableRestartTimeGet.hServer = hBOS;
3135 rc = Worker_DoTask (wtaskBosExecutableRestartTimeGet, &wp, &status);
3140 *pfWeekly = wp.wpBosExecutableRestartTimeGet.fWeeklyRestart;
3141 *pstWeekly = wp.wpBosExecutableRestartTimeGet.timeWeekly;
3142 *pfDaily = wp.wpBosExecutableRestartTimeGet.fDailyRestart;
3143 *pstDaily = wp.wpBosExecutableRestartTimeGet.timeDaily;
3147 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3149 lpServer->CloseBosObject();
3153 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesEnd, lpiServer, status);
3162 BOOL AfsClass_SetRestartTimes (LPIDENT lpiServer, LPSYSTEMTIME pstWeekly, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3168 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesBegin, lpiServer);
3173 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3177 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3184 SYSTEMTIME timeNever;
3185 memset (&timeNever, 0x00, sizeof(SYSTEMTIME));
3188 wp.wpBosExecutableRestartTimeSet.hServer = hBOS;
3189 wp.wpBosExecutableRestartTimeSet.fWeeklyRestart = (pstWeekly != NULL) ? TRUE : FALSE;
3190 wp.wpBosExecutableRestartTimeSet.timeWeekly = (pstWeekly != NULL) ? *pstWeekly : timeNever;
3191 wp.wpBosExecutableRestartTimeSet.fDailyRestart = (pstDaily != NULL) ? TRUE : FALSE;
3192 wp.wpBosExecutableRestartTimeSet.timeDaily = (pstDaily != NULL) ? *pstDaily : timeNever;
3195 rc = Worker_DoTask (wtaskBosExecutableRestartTimeSet, &wp, &status);
3199 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3201 lpServer->CloseBosObject();
3205 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesEnd, lpiServer, status);
3214 BOOL AfsClass_MoveReplica (LPIDENT lpiReplica, LPIDENT lpiAggregateTarget, ULONG *pStatus)
3218 // Find the identifier for this replica's read/write fileset.
3220 LPIDENT lpiFilesetRW = NULL;
3221 LPFILESET lpFileset;
3222 if ((lpFileset = lpiReplica->OpenFileset (pStatus)) == NULL)
3226 if ((lpiFilesetRW = lpFileset->GetReadWriteIdentifier (pStatus)) == NULL)
3231 // If the fileset replica currently resides on the same server
3232 // as the target aggregate, we'll follow the following steps:
3234 // 1. Delete the old fileset replica -> on error, quit
3235 // 2. Create the new fileset replica -> on error, recreate old replica, quit
3237 // If the fileset replica instead currently resides on a different
3238 // server, we can follow the preferred steps:
3240 // 1. Create the new fileset replica -> on error, quit
3241 // 2. Delete the old fileset replica -> on error, delete the new replica, quit
3245 LPIDENT lpiReplicaNew;
3247 if (lpiReplica->GetServer() == lpiAggregateTarget->GetServer())
3249 LPIDENT lpiAggregateOriginal = lpiReplica->GetAggregate();
3251 if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3255 else if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3257 (void)AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateOriginal);
3261 else // different server?
3263 if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3267 else if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3269 (void)AfsClass_DeleteReplica (lpiReplicaNew, pStatus);
3279 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)
3285 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageBegin, lpiSalvage);
3290 if ((lpServer = lpiSalvage->OpenServer (&status)) == NULL)
3294 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3300 *ppszLogData = NULL;
3302 // Step one: perform the actual salvage. This will dump a log file onto
3303 // the target computer.
3307 LPTSTR pszAggregate = NULL;
3308 TCHAR szAggregate[ cchNAME ];
3309 if (lpiSalvage->fIsAggregate() || lpiSalvage->fIsFileset())
3311 lpiSalvage->GetAggregateName (szAggregate);
3312 pszAggregate = szAggregate;
3315 LPTSTR pszFileset = NULL;
3316 TCHAR szFileset[ cchNAME ];
3317 if (lpiSalvage->fIsFileset())
3320 lpiSalvage->GetFilesetID (&vid);
3321 wsprintf (szFileset, TEXT("%lu"), vid);
3322 pszFileset = szFileset;
3325 if (pszLogFile == NULL)
3326 pszLogFile = TEXT("SalvageLog");
3329 wp.wpBosSalvage.hCell = hCell;
3330 wp.wpBosSalvage.hServer = hBOS;
3331 wp.wpBosSalvage.pszAggregate = pszAggregate;
3332 wp.wpBosSalvage.pszFileset = pszFileset;
3333 wp.wpBosSalvage.nProcesses = nProcesses;
3334 wp.wpBosSalvage.pszTempDir = pszTempDir;
3335 wp.wpBosSalvage.pszLogFile = pszLogFile;
3336 wp.wpBosSalvage.fForce = fForce;
3337 wp.wpBosSalvage.fReadonly = fReadonly;
3338 wp.wpBosSalvage.fLogInodes = fLogInodes;
3339 wp.wpBosSalvage.fLogRootInodes = fLogRootInodes;
3340 wp.wpBosSalvage.fRebuildDirs = fRebuildDirs;
3341 wp.wpBosSalvage.fReadBlocks = fReadBlocks;
3344 rc = Worker_DoTask (wtaskBosSalvage, &wp, &status);
3348 // Step two: retrieve the log file from that salvage operation.
3349 // If we can't get the log file back, that's not fatal--just return
3350 // a NULL pointer for the log data.
3352 if (rc && ppszLogData)
3355 wp.wpBosLogGet.hServer = hBOS;
3356 wp.wpBosLogGet.pszLogName = pszLogFile;
3357 wp.wpBosLogGet.pszLogData = NULL;
3360 if ((rc = Worker_DoTask (wtaskBosLogGet, &wp, &status)) == TRUE)
3362 // Okay, well, we have the log in memory now. Problem is,
3363 // it has UNIX-style CR's... and so is missing the LF which
3364 // PCs expect before each CR. Wow--look at all the
3365 // acronyms! Count the CRs, alloc a larger buffer, and stuff
3366 // in the LFs before each CR.
3368 size_t cchRequired = 1;
3369 for (LPTSTR pchIn = wp.wpBosLogGet.pszLogData; *pchIn; ++pchIn)
3371 cchRequired += (*pchIn == TEXT('\r')) ? 0 : (*pchIn == TEXT('\n')) ? 2 : 1;
3374 if ((*ppszLogData = AllocateString (cchRequired)) != NULL)
3376 LPTSTR pszOut = *ppszLogData;
3377 for (LPTSTR pchIn = wp.wpBosLogGet.pszLogData; *pchIn; ++pchIn)
3379 if (*pchIn == TEXT('\n'))
3380 *pszOut++ = TEXT('\r');
3381 if (*pchIn != TEXT('\r'))
3384 *pszOut++ = TEXT('\0');
3390 if ((lpServer = lpiSalvage->OpenServer (&status)) != NULL)
3392 lpServer->CloseBosObject();
3396 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageEnd, lpiSalvage, status);
3405 void AfsClass_FreeSalvageLog (LPTSTR pszLogData)
3412 LPHOSTLIST AfsClass_HostList_Load (LPIDENT lpiServer, ULONG *pStatus)
3416 LPHOSTLIST lpList = NULL;
3419 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadBegin, lpiServer);
3424 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3428 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3435 lpList = New(HOSTLIST);
3436 memset (lpList, 0x00, sizeof(HOSTLIST));
3438 lpList->lpiServer = lpiServer;
3440 WORKERPACKET wpBegin;
3441 wpBegin.wpBosHostGetBegin.hServer = hBOS;
3442 if (!Worker_DoTask (wtaskBosHostGetBegin, &wpBegin, &status))
3448 TCHAR szHost[ cchNAME ];
3450 WORKERPACKET wpNext;
3451 wpNext.wpBosHostGetNext.hEnum = wpBegin.wpBosHostGetBegin.hEnum;
3452 wpNext.wpBosHostGetNext.pszServer = szHost;
3454 if (!Worker_DoTask (wtaskBosHostGetNext, &wpNext, &status))
3456 if (status == ADMITERATORDONE)
3464 if ((iAdded = AfsClass_HostList_AddEntry (lpList, szHost)) != (size_t)-1)
3466 lpList->aEntries[ iAdded ].fAdded = FALSE;
3470 WORKERPACKET wpDone;
3471 wpDone.wpBosHostGetDone.hEnum = wpBegin.wpBosHostGetBegin.hEnum;
3472 Worker_DoTask (wtaskBosHostGetDone, &wpDone);
3476 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3478 lpServer->CloseBosObject();
3482 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadEnd, lpiServer, status);
3487 return (rc) ? lpList : NULL;
3491 LPHOSTLIST AfsClass_HostList_Copy (LPHOSTLIST lpOld)
3493 LPHOSTLIST lpNew = NULL;
3497 lpNew = New(HOSTLIST);
3498 memcpy (lpNew, lpOld, sizeof(HOSTLIST));
3501 lpNew->aEntries = 0;
3502 lpNew->cEntries = 0;
3504 if (REALLOC (lpNew->aEntries, lpNew->cEntries, lpOld->cEntries, cREALLOC_HOSTLISTENTRIES))
3506 size_t cb = lpOld->cEntries * sizeof(HOSTLISTENTRY);
3507 memcpy (lpNew->aEntries, lpOld->aEntries, cb);
3515 BOOL AfsClass_HostList_Save (LPHOSTLIST lpList, ULONG *pStatus)
3521 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveBegin, lpList->lpiServer);
3526 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
3530 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3537 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3539 if (!lpList->aEntries[ iEntry ].szHost[0])
3542 // are we supposed to add this entry?
3544 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
3547 wp.wpBosHostCreate.hServer = hBOS;
3548 wp.wpBosHostCreate.pszServer = lpList->aEntries[ iEntry ].szHost;
3551 if (!Worker_DoTask (wtaskBosHostCreate, &wp, &thisstatus))
3554 status = thisstatus;
3558 lpList->aEntries[ iEntry ].fAdded = FALSE;
3562 // are we supposed to delete this entry?
3564 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
3567 wp.wpBosHostDelete.hServer = hBOS;
3568 wp.wpBosHostDelete.pszServer = lpList->aEntries[ iEntry ].szHost;
3571 if (!Worker_DoTask (wtaskBosHostDelete, &wp, &thisstatus))
3574 status = thisstatus;
3578 lpList->aEntries[ iEntry ].szHost[0] = TEXT('\0');
3579 lpList->aEntries[ iEntry ].fDeleted = FALSE;
3585 if ((lpServer = lpList->lpiServer->OpenServer (&status)) != NULL)
3587 lpServer->CloseBosObject();
3591 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveEnd, lpList->lpiServer, status);
3600 void AfsClass_HostList_Free (LPHOSTLIST lpList)
3602 if (lpList && !InterlockedDecrement (&lpList->cRef))
3604 if (lpList->aEntries)
3605 Free (lpList->aEntries);
3606 memset (lpList, 0x00, sizeof(HOSTLIST));
3612 size_t AfsClass_HostList_AddEntry (LPHOSTLIST lpList, LPTSTR pszHost)
3614 size_t iAdded = (size_t)-1;
3619 for (iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3621 if (!lpList->aEntries[ iEntry ].szHost[0])
3624 if (iEntry >= lpList->cEntries)
3626 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_HOSTLISTENTRIES);
3628 if (iEntry < lpList->cEntries)
3631 lstrcpy (lpList->aEntries[ iAdded ].szHost, pszHost);
3632 lpList->aEntries[ iAdded ].fAdded = TRUE;
3633 lpList->aEntries[ iAdded ].fDeleted = FALSE;
3641 BOOL AfsClass_HostList_DelEntry (LPHOSTLIST lpList, size_t iIndex)
3646 (iIndex < lpList->cEntries) &&
3647 (lpList->aEntries[ iIndex ].szHost[0]) &&
3648 (!lpList->aEntries[ iIndex ].fDeleted) )
3650 if (lpList->aEntries[ iIndex ].fAdded)
3651 lpList->aEntries[ iIndex ].szHost[0] = TEXT('\0');
3653 lpList->aEntries[ iIndex ].fDeleted = TRUE;
3662 BOOL AfsClass_GetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3667 memset (pProperties, 0x00, sizeof(PTSPROPERTIES));
3673 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3677 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3682 // Go get the necessary properties
3687 wp.wpPtsUserMaxGet.hCell = hCell;
3689 if ((rc = Worker_DoTask (wtaskPtsUserMaxGet, &wp, &status)) == TRUE)
3690 pProperties->idUserMax = wp.wpPtsUserMaxGet.idUserMax;
3696 wp.wpPtsGroupMaxGet.hCell = hCell;
3698 if ((rc = Worker_DoTask (wtaskPtsGroupMaxGet, &wp, &status)) == TRUE)
3699 pProperties->idGroupMax = wp.wpPtsGroupMaxGet.idGroupMax;
3708 BOOL AfsClass_SetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3717 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3721 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3726 // Modify the specified properties
3731 wp.wpPtsUserMaxSet.hCell = hCell;
3732 wp.wpPtsUserMaxSet.idUserMax = pProperties->idUserMax;
3733 rc = Worker_DoTask (wtaskPtsUserMaxSet, &wp, &status);
3739 wp.wpPtsGroupMaxSet.hCell = hCell;
3740 wp.wpPtsGroupMaxSet.idGroupMax = pProperties->idGroupMax;
3741 Worker_DoTask (wtaskPtsGroupMaxSet, &wp, &status);
3750 LPIDENT AfsClass_CreateUser (LPIDENT lpiCell, LPTSTR pszUserName, LPTSTR pszInstance, LPTSTR pszPassword, UINT_PTR idUser, BOOL fCreateKAS, BOOL fCreatePTS, ULONG *pStatus)
3755 if (pszInstance && !*pszInstance)
3759 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserBegin, lpiCell, pszUserName, 0);
3761 // We'll need both hCell and hKAS.
3766 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3770 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3773 hKAS = lpCell->GetKasObject (&status);
3777 // First try to create a KAS entry.
3779 if (rc && fCreateKAS)
3782 wp.wpKasPrincipalCreate.hCell = hCell;
3783 wp.wpKasPrincipalCreate.hServer = hKAS;
3784 wp.wpKasPrincipalCreate.pszPrincipal = pszUserName;
3785 wp.wpKasPrincipalCreate.pszInstance = pszInstance;
3786 wp.wpKasPrincipalCreate.pszPassword = pszPassword;
3789 rc = Worker_DoTask (wtaskKasPrincipalCreate, &wp, &status);
3793 // If that succeeded, try to create a PTS entry as well.
3795 if (rc && fCreatePTS)
3797 TCHAR szUserName[ cchNAME ];
3798 lstrcpy (szUserName, pszUserName);
3800 wsprintf (&szUserName[ lstrlen(szUserName) ], TEXT(".%s"), pszInstance);
3803 wp.wpPtsUserCreate.hCell = hCell;
3804 wp.wpPtsUserCreate.pszUser = szUserName;
3805 wp.wpPtsUserCreate.idUser = (int) idUser;
3809 if ((rc = Worker_DoTask (wtaskPtsUserCreate, &wp, &status)) == FALSE)
3811 if (status == PREXIST)
3817 // If we couldn't make a KAS entry as well, remove the KAS entry.
3822 wpDel.wpKasPrincipalDelete.hCell = hCell;
3823 wpDel.wpKasPrincipalDelete.hServer = hKAS;
3824 wpDel.wpKasPrincipalDelete.pszPrincipal = pszUserName;
3825 wpDel.wpKasPrincipalDelete.pszInstance = pszInstance;
3826 Worker_DoTask (wtaskKasPrincipalDelete, &wpDel);
3833 // If we were able to create the user's accounts successfully, refresh
3834 // the cell status and return the new user's ident.
3840 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3844 if (!lpCell->RefreshAccount (pszUserName, pszInstance, CELL_REFRESH_ACCOUNT_CREATED_USER, &lpiUser))
3852 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserEnd, lpiCell, pszUserName, status);
3857 return (rc) ? lpiUser : NULL;
3861 BOOL AfsClass_SetUserProperties (LPIDENT lpiUser, LPUSERPROPERTIES pProperties, ULONG *pStatus)
3867 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser);
3869 // We'll need both hCell and hKAS.
3874 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
3878 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3881 hKAS = lpCell->GetKasObject (&status);
3885 // We'll also need this user's current status
3889 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
3893 if (!lpUser->GetStatus (&us, TRUE, &status))
3898 // Modify the user's KAS entry (if necessary)
3900 DWORD dwKasMask = ( MASK_USERPROP_fAdmin |
3901 MASK_USERPROP_fGrantTickets |
3902 MASK_USERPROP_fCanEncrypt |
3903 MASK_USERPROP_fCanChangePassword |
3904 MASK_USERPROP_fCanReusePasswords |
3905 MASK_USERPROP_timeAccountExpires |
3906 MASK_USERPROP_cdayPwExpires |
3907 MASK_USERPROP_csecTicketLifetime |
3908 MASK_USERPROP_nFailureAttempts |
3909 MASK_USERPROP_csecFailedLoginLockTime );
3911 if (rc && (pProperties->dwMask & dwKasMask))
3913 TCHAR szPrincipal[ cchNAME ];
3914 TCHAR szInstance[ cchNAME ];
3915 lpiUser->GetUserName (szPrincipal, szInstance);
3918 wp.wpKasPrincipalFieldsSet.hCell = hCell;
3919 wp.wpKasPrincipalFieldsSet.hServer = hKAS;
3920 wp.wpKasPrincipalFieldsSet.pszPrincipal = szPrincipal;
3921 wp.wpKasPrincipalFieldsSet.pszInstance = szInstance;
3922 wp.wpKasPrincipalFieldsSet.fIsAdmin = (pProperties->dwMask & MASK_USERPROP_fAdmin) ? pProperties->fAdmin : us.KASINFO.fIsAdmin;
3923 wp.wpKasPrincipalFieldsSet.fGrantTickets = (pProperties->dwMask & MASK_USERPROP_fGrantTickets) ? pProperties->fGrantTickets : us.KASINFO.fCanGetTickets;
3924 wp.wpKasPrincipalFieldsSet.fCanEncrypt = (pProperties->dwMask & MASK_USERPROP_fCanEncrypt) ? pProperties->fCanEncrypt : us.KASINFO.fEncrypt;
3925 wp.wpKasPrincipalFieldsSet.fCanChangePassword = (pProperties->dwMask & MASK_USERPROP_fCanChangePassword) ? pProperties->fCanChangePassword : us.KASINFO.fCanChangePassword;
3926 wp.wpKasPrincipalFieldsSet.fCanReusePasswords = (pProperties->dwMask & MASK_USERPROP_fCanReusePasswords) ? pProperties->fCanReusePasswords : us.KASINFO.fCanReusePasswords;
3927 memcpy (&wp.wpKasPrincipalFieldsSet.timeExpires, (pProperties->dwMask & MASK_USERPROP_timeAccountExpires) ? &pProperties->timeAccountExpires : &us.KASINFO.timeExpires, sizeof(SYSTEMTIME));
3928 wp.wpKasPrincipalFieldsSet.cdayPwExpires = (pProperties->dwMask & MASK_USERPROP_cdayPwExpires) ? pProperties->cdayPwExpires : us.KASINFO.cdayPwExpire;
3929 wp.wpKasPrincipalFieldsSet.csecTicketLifetime = (pProperties->dwMask & MASK_USERPROP_csecTicketLifetime) ? pProperties->csecTicketLifetime : us.KASINFO.csecTicketLifetime;
3930 wp.wpKasPrincipalFieldsSet.nFailureAttempts = (pProperties->dwMask & MASK_USERPROP_nFailureAttempts) ? pProperties->nFailureAttempts : us.KASINFO.cFailLogin;
3931 wp.wpKasPrincipalFieldsSet.csecFailedLoginLockTime = (pProperties->dwMask & MASK_USERPROP_csecFailedLoginLockTime) ? pProperties->csecFailedLoginLockTime : us.KASINFO.csecFailLoginLock;
3934 rc = Worker_DoTask (wtaskKasPrincipalFieldsSet, &wp, &status);
3939 // Modify the user's PTS entry (if necessary)
3941 DWORD dwPtsMask = ( MASK_USERPROP_cGroupCreationQuota |
3942 MASK_USERPROP_aaListStatus |
3943 MASK_USERPROP_aaGroupsOwned |
3944 MASK_USERPROP_aaMembership );
3946 if (rc && (pProperties->dwMask & dwPtsMask))
3948 TCHAR szFullName[ cchNAME ];
3949 lpiUser->GetFullUserName (szFullName);
3952 wp.wpPtsUserModify.hCell = hCell;
3953 wp.wpPtsUserModify.pszUser = szFullName;
3954 memset (&wp.wpPtsUserModify.Delta, 0x00, sizeof(wp.wpPtsUserModify.Delta));
3956 if (pProperties->dwMask & MASK_USERPROP_cGroupCreationQuota)
3958 wp.wpPtsUserModify.Delta.flag = (pts_UserUpdateFlag_t)( (LONG)wp.wpPtsUserModify.Delta.flag | (LONG)PTS_USER_UPDATE_GROUP_CREATE_QUOTA );
3959 wp.wpPtsUserModify.Delta.groupCreationQuota = pProperties->cGroupCreationQuota;
3962 if (pProperties->dwMask & (MASK_USERPROP_aaListStatus | MASK_USERPROP_aaGroupsOwned | MASK_USERPROP_aaMembership))
3964 wp.wpPtsUserModify.Delta.flag = (pts_UserUpdateFlag_t)( (LONG)wp.wpPtsUserModify.Delta.flag | (LONG)PTS_USER_UPDATE_PERMISSIONS );
3965 wp.wpPtsUserModify.Delta.listStatus = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaListStatus) ? pProperties->aaListStatus : us.PTSINFO.aaListStatus );
3966 wp.wpPtsUserModify.Delta.listGroupsOwned = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaGroupsOwned) ? pProperties->aaGroupsOwned : us.PTSINFO.aaGroupsOwned );
3967 wp.wpPtsUserModify.Delta.listMembership = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaMembership) ? pProperties->aaMembership : us.PTSINFO.aaMembership );
3971 rc = Worker_DoTask (wtaskPtsUserModify, &wp, &status);
3975 // If we were able to modify the user's properties successfully, refresh
3976 // that user's status.
3978 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
3980 lpUser->Invalidate();
3981 lpUser->RefreshStatus();
3985 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser, status);
3994 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPTSTR pszPassword, ULONG *pStatus)
3999 TCHAR szCell[ cchNAME ];
4000 lpiUser->GetCellName (szCell);
4003 wp.wpKasStringToKey.pszCell = szCell;
4004 wp.wpKasStringToKey.pszString = pszPassword;
4005 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
4009 else if (!AfsClass_SetUserPassword (lpiUser, keyVersion, &wp.wpKasStringToKey.key, &status))
4020 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
4026 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordBegin, lpiUser);
4028 // We'll need both hCell and hKAS.
4033 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4037 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4040 hKAS = lpCell->GetKasObject (&status);
4044 // Change the user's password
4048 TCHAR szPrincipal[ cchNAME ];
4049 TCHAR szInstance[ cchNAME ];
4050 lpiUser->GetUserName (szPrincipal, szInstance);
4053 wp.wpKasPrincipalKeySet.hCell = hCell;
4054 wp.wpKasPrincipalKeySet.hServer = hKAS;
4055 wp.wpKasPrincipalKeySet.pszPrincipal = szPrincipal;
4056 wp.wpKasPrincipalKeySet.pszInstance = szInstance;
4057 wp.wpKasPrincipalKeySet.keyVersion = keyVersion;
4058 memcpy (&wp.wpKasPrincipalKeySet.key.key, &pKey->key, ENCRYPTIONKEY_LEN);
4061 rc = Worker_DoTask (wtaskKasPrincipalKeySet, &wp, &status);
4065 // If we were able to modify the user's password successfully, refresh
4066 // that user's status.
4069 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4071 lpUser->Invalidate();
4072 lpUser->RefreshStatus();
4076 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordEnd, lpiUser, status);
4085 BOOL AfsClass_DeleteUser (LPIDENT lpiUser, BOOL fDeleteKAS, BOOL fDeletePTS, ULONG *pStatus)
4091 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserBegin, lpiUser);
4093 // We'll need both hCell and hKAS.
4098 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4102 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4105 hKAS = lpCell->GetKasObject (&status);
4109 // Find out whether this user has KAS and/or PTS entries. Also
4110 // get the various lists of groups for this user...
4113 LPTSTR mszOwnerOf = NULL;
4114 LPTSTR mszMemberOf = NULL;
4115 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
4119 lpUser->GetOwnerOf (&mszOwnerOf);
4120 lpUser->GetMemberOf (&mszMemberOf);
4124 // Delete the user's PTS entry
4126 if (rc && fDeletePTS)
4128 TCHAR szFullName[ cchNAME ];
4129 lpiUser->GetFullUserName (szFullName);
4132 wp.wpPtsUserDelete.hCell = hCell;
4133 wp.wpPtsUserDelete.pszUser = szFullName;
4136 if ((rc = Worker_DoTask (wtaskPtsUserDelete, &wp, &status)) == FALSE)
4138 if (status == ADMPTSFAILEDNAMETRANSLATE) // User had no PTS entry?
4144 // Delete the user's KAS entry
4146 if (rc && fDeleteKAS)
4148 TCHAR szPrincipal[ cchNAME ];
4149 TCHAR szInstance[ cchNAME ];
4150 lpiUser->GetUserName (szPrincipal, szInstance);
4153 wp.wpKasPrincipalDelete.hCell = hCell;
4154 wp.wpKasPrincipalDelete.hServer = hKAS;
4155 wp.wpKasPrincipalDelete.pszPrincipal = szPrincipal;
4156 wp.wpKasPrincipalDelete.pszInstance = szInstance;
4159 if ((rc = Worker_DoTask (wtaskKasPrincipalDelete, &wp, &status)) == FALSE)
4161 if (status == KANOENT)
4167 // If we were able to delete the user's accounts successfully, refresh
4172 if ((lpCell = lpiUser->OpenCell (&status)) != NULL)
4174 TCHAR szPrincipal[ cchNAME ];
4175 TCHAR szInstance[ cchNAME ];
4176 lpiUser->GetUserName (szPrincipal, szInstance);
4178 lpCell->RefreshAccount (szPrincipal, szInstance, CELL_REFRESH_ACCOUNT_DELETED);
4179 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4180 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4185 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserEnd, lpiUser, status);
4189 FreeString (mszOwnerOf);
4191 FreeString (mszMemberOf);
4198 BOOL AfsClass_UnlockUser (LPIDENT lpiUser, ULONG *pStatus)
4204 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserBegin, lpiUser);
4206 // We'll need both hCell and hKAS.
4211 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4215 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4218 hKAS = lpCell->GetKasObject (&status);
4222 // Unlock the user's KAS entry
4226 TCHAR szPrincipal[ cchNAME ];
4227 TCHAR szInstance[ cchNAME ];
4228 lpiUser->GetUserName (szPrincipal, szInstance);
4231 wp.wpKasPrincipalUnlock.hCell = hCell;
4232 wp.wpKasPrincipalUnlock.hServer = hKAS;
4233 wp.wpKasPrincipalUnlock.pszPrincipal = szPrincipal;
4234 wp.wpKasPrincipalUnlock.pszInstance = szInstance;
4237 rc = Worker_DoTask (wtaskKasPrincipalUnlock, &wp, &status);
4241 // If we were able to unlock the user's accounts successfully, refresh
4242 // the user's properties.
4247 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4249 lpUser->Invalidate();
4250 lpUser->RefreshStatus();
4255 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserEnd, lpiUser, status);
4264 LPIDENT AfsClass_CreateGroup (LPIDENT lpiCell, LPTSTR pszGroupName, LPIDENT lpiOwner, int idGroup, ULONG *pStatus)
4270 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupBegin, lpiCell, pszGroupName, 0);
4276 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4280 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4285 // Create a PTS entry for the new group
4289 TCHAR szOwner[ cchNAME ] = TEXT("");
4290 if (lpiOwner && lpiOwner->fIsUser())
4291 lpiOwner->GetFullUserName (szOwner);
4292 else if (lpiOwner && lpiOwner->fIsGroup())
4293 lpiOwner->GetGroupName (szOwner);
4296 wp.wpPtsGroupCreate.hCell = hCell;
4297 wp.wpPtsGroupCreate.pszGroup = pszGroupName;
4298 wp.wpPtsGroupCreate.pszOwner = (szOwner[0]) ? szOwner : NULL;
4299 wp.wpPtsGroupCreate.idGroup = idGroup;
4302 rc = Worker_DoTask (wtaskPtsGroupCreate, &wp, &status);
4306 // If we were able to create the group successfully, refresh
4307 // the cell status and return the new group's ident.
4313 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4317 if (!lpCell->RefreshAccount (pszGroupName, NULL, CELL_REFRESH_ACCOUNT_CREATED_GROUP, &lpiGroup))
4325 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupEnd, lpiCell, pszGroupName, status);
4330 return (rc) ? lpiGroup : NULL;
4334 BOOL AfsClass_SetGroupProperties (LPIDENT lpiGroup, LPGROUPPROPERTIES pProperties, ULONG *pStatus)
4340 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup);
4346 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4350 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4355 // We'll also need this group's current status
4359 if ((lpGroup = lpiGroup->OpenGroup (&status)) == NULL)
4363 if (!lpGroup->GetStatus (&gs, TRUE, &status))
4368 // Modify the group's PTS entry (if requested)
4370 DWORD dwPtsMask = ( MASK_GROUPPROP_aaListStatus |
4371 MASK_GROUPPROP_aaListGroupsOwned |
4372 MASK_GROUPPROP_aaListMembers |
4373 MASK_GROUPPROP_aaAddMember |
4374 MASK_GROUPPROP_aaDeleteMember );
4376 if (rc && (pProperties->dwMask & dwPtsMask))
4378 TCHAR szGroup[ cchNAME ];
4379 lpiGroup->GetGroupName (szGroup);
4382 wp.wpPtsGroupModify.hCell = hCell;
4383 wp.wpPtsGroupModify.pszGroup = szGroup;
4384 memset (&wp.wpPtsGroupModify.Delta, 0x00, sizeof(wp.wpPtsGroupModify.Delta));
4385 wp.wpPtsGroupModify.Delta.listStatus = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListStatus) ? pProperties->aaListStatus : gs.aaListStatus );
4386 wp.wpPtsGroupModify.Delta.listGroupsOwned = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListGroupsOwned) ? pProperties->aaListGroupsOwned : gs.aaListGroupsOwned );
4387 wp.wpPtsGroupModify.Delta.listMembership = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListMembers) ? pProperties->aaListMembers : gs.aaListMembers );
4388 wp.wpPtsGroupModify.Delta.listAdd = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaAddMember) ? pProperties->aaAddMember : gs.aaAddMember );
4389 wp.wpPtsGroupModify.Delta.listDelete = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaDeleteMember) ? pProperties->aaDeleteMember : gs.aaDeleteMember );
4392 rc = Worker_DoTask (wtaskPtsGroupModify, &wp, &status);
4396 // Change the group's owner (if requested)
4398 if (rc && (pProperties->dwMask & MASK_GROUPPROP_szOwner))
4400 TCHAR szGroup[ cchNAME ];
4401 lpiGroup->GetGroupName (szGroup);
4404 wp.wpPtsGroupOwnerChange.hCell = hCell;
4405 wp.wpPtsGroupOwnerChange.pszGroup = szGroup;