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);
59 LPSERVER lpServer = NULL;
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
497 LPSERVER lpServer = NULL;
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
611 LPSERVER lpServer = NULL;
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();
1157 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1161 lpCell->InvalidateServers ();
1162 rc = lpCell->RefreshServers (TRUE, &status);
1167 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1176 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSERVERSTATUS pStatusOld, LPSERVERSTATUS pStatusNew, ULONG *pStatus)
1182 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1188 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1192 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1201 for (size_t iAddr = 0; rc && (iAddr < AFSCLASS_MAX_ADDRESSES_PER_SITE); ++iAddr)
1205 AfsClass_AddressToInt (&oldAddress, &pStatusOld->aAddresses[ iAddr ]);
1206 AfsClass_AddressToInt (&newAddress, &pStatusNew->aAddresses[ iAddr ]);
1208 if (oldAddress && newAddress && (oldAddress != newAddress))
1211 wp.wpVosFileServerAddressChange.hCell = hCell;
1212 wp.wpVosFileServerAddressChange.addrOld = pStatusOld->aAddresses[ iAddr ];
1213 wp.wpVosFileServerAddressChange.addrNew = pStatusNew->aAddresses[ iAddr ];
1215 rc = Worker_DoTask (wtaskVosFileServerAddressChange, &wp, &status);
1217 else if (oldAddress && !newAddress)
1220 wp.wpVosFileServerAddressRemove.hCell = hCell;
1221 wp.wpVosFileServerAddressRemove.addr = pStatusOld->aAddresses[ iAddr ];
1223 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1233 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1235 lpServer->InvalidateStatus();
1240 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1244 lpCell->InvalidateServers ();
1245 rc = lpCell->RefreshServers (TRUE, &status);
1250 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1259 BOOL AfsClass_LockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1265 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetBegin, lpiFileset);
1271 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1275 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1280 // Obtain the fileset's read-write identifier
1282 LPIDENT lpiRW = NULL;
1283 LPFILESET lpFileset;
1284 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1288 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1293 // Perform the lock operation
1298 wp.wpVosVLDBEntryLock.hCell = hCell;
1299 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryLock.idVolume);
1302 rc = Worker_DoTask (wtaskVosVLDBEntryLock, &wp, &status);
1309 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1314 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1316 lpCell->RefreshVLDB (lpiFileset->GetCell());
1321 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetEnd, lpiFileset, status);
1330 BOOL AfsClass_UnlockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1336 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetBegin, lpiFileset);
1342 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1346 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1351 // Obtain the fileset's read-write identifier
1353 LPIDENT lpiRW = NULL;
1354 LPFILESET lpFileset;
1355 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1359 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1364 // Perform the unlock operation
1369 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1370 wp.wpVosVLDBEntryUnlock.hServer = NULL;
1371 wp.wpVosVLDBEntryUnlock.idPartition = NO_PARTITION;
1372 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryUnlock.idVolume);
1375 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1382 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1387 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1389 lpCell->RefreshVLDB (lpiFileset->GetCell());
1394 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetEnd, lpiFileset, status);
1403 BOOL AfsClass_UnlockAllFilesets (LPIDENT lpi, ULONG *pStatus)
1409 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsBegin, lpi);
1415 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1419 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1424 // Obtain hServer if appropriate
1427 if (lpi && (!lpi->fIsCell()))
1430 if ((lpServer = lpi->OpenServer (&status)) == NULL)
1434 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
1440 // Obtain the ID of the scope aggregate.
1442 int idPartition = NO_PARTITION;
1443 if (rc && (lpi->fIsFileset() || (lpi->fIsAggregate())))
1445 LPAGGREGATE lpAggregate;
1446 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
1450 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1452 lpAggregate->Close();
1456 // Perform the unlock operation
1461 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1462 wp.wpVosVLDBEntryUnlock.hServer = hVOS;
1463 wp.wpVosVLDBEntryUnlock.idPartition = idPartition;
1464 wp.wpVosVLDBEntryUnlock.idVolume = NO_VOLUME;
1467 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1474 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1478 lpCell->RefreshVLDB (lpi);
1486 if ((lpServer = lpi->OpenServer (&status)) != NULL)
1488 lpServer->CloseVosObject();
1493 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsEnd, lpi);
1502 LPIDENT AfsClass_CreateReplica (LPIDENT lpiFileset, LPIDENT lpiAggregate, ULONG *pStatus)
1506 LPIDENT lpiReplica = NULL;
1509 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaBegin, lpiFileset, lpiAggregate, NULL, NULL, 0, 0);
1511 // Obtain hCell and hVOS for the target server
1516 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
1520 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1525 // Obtain idPartition
1528 LPAGGREGATE lpAggregate;
1529 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1533 idPartition = lpAggregate->GetID();
1534 lpAggregate->Close();
1537 // Modify VLDB to create mention of a new replica
1542 wp.wpVosVLDBReadOnlySiteCreate.hCell = hCell;
1543 wp.wpVosVLDBReadOnlySiteCreate.hServer = hVOS;
1544 wp.wpVosVLDBReadOnlySiteCreate.idPartition = idPartition;
1545 lpiFileset->GetFilesetID (&wp.wpVosVLDBReadOnlySiteCreate.idVolume);
1548 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteCreate, &wp, &status);
1556 LPAGGREGATE lpAggregate;
1557 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1561 lpAggregate->Invalidate();
1562 lpAggregate->RefreshFilesets (TRUE, &status);
1563 lpAggregate->Close();
1570 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
1574 lpCell->RefreshVLDB (lpiAggregate);
1581 LPFILESET lpFileset;
1582 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1586 if ((lpiReplica = lpFileset->GetReadOnlyIdentifier (lpiAggregate, &status)) == NULL)
1594 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
1596 lpServer->CloseVosObject();
1601 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaEnd, lpiFileset, lpiAggregate, NULL, NULL, 0, status);
1606 return (rc) ? lpiReplica : FALSE;
1610 BOOL AfsClass_DeleteReplica (LPIDENT lpiReplica, ULONG *pStatus)
1616 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiReplica);
1618 // Obtain hCell and hVOS for the server
1623 if ((lpServer = lpiReplica->OpenServer (&status)) == NULL)
1627 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1632 // Get the read/write fileset identifier and Ghost status
1634 LPIDENT lpiRW = NULL;
1635 int wFilesetGhost = 0;
1636 LPFILESET lpFileset;
1637 if ((lpFileset = lpiReplica->OpenFileset (&status)) == NULL)
1641 wFilesetGhost = lpFileset->GetGhostStatus();
1642 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1647 TCHAR szAggregateName[ cchNAME ];
1648 lpiReplica->GetAggregateName (szAggregateName);
1650 // Obtain the ID of the replica's partition
1653 LPAGGREGATE lpAggregate;
1654 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1658 idPartition = lpAggregate->GetID();
1659 lpAggregate->Close();
1662 // If the volume exists in both VLDB and on the server, just delete it
1664 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY) && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1667 wp.wpVosVolumeDelete.hCell = hCell;
1668 wp.wpVosVolumeDelete.hServer = hVOS;
1669 wp.wpVosVolumeDelete.idPartition = idPartition;
1670 lpiReplica->GetFilesetID (&wp.wpVosVolumeDelete.idVolume);
1673 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
1678 // If necessary, modify VLDB to remove mention of this replica
1680 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
1683 wp.wpVosVLDBReadOnlySiteDelete.hCell = hCell;
1684 wp.wpVosVLDBReadOnlySiteDelete.hServer = hVOS;
1685 wp.wpVosVLDBReadOnlySiteDelete.idPartition = idPartition;
1686 lpiRW->GetFilesetID (&wp.wpVosVLDBReadOnlySiteDelete.idVolume);
1689 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteDelete, &wp, &status);
1693 // If necessary, zap the volume
1695 if (rc && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1698 wp.wpVosVolumeZap.hCell = hCell;
1699 wp.wpVosVolumeZap.hServer = hVOS;
1700 wp.wpVosVolumeZap.idPartition = idPartition;
1701 lpiReplica->GetFilesetID (&wp.wpVosVolumeZap.idVolume);
1702 wp.wpVosVolumeZap.fForce = TRUE;
1705 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
1714 LPAGGREGATE lpAggregate;
1715 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1719 lpAggregate->Invalidate();
1720 lpAggregate->RefreshFilesets (TRUE, &status);
1721 lpAggregate->Close();
1728 if ((lpCell = lpiReplica->OpenCell()) == NULL)
1732 lpCell->RefreshVLDB (lpiReplica->GetAggregate());
1739 if ((lpServer = lpiReplica->OpenServer (&status)) != NULL)
1741 lpServer->CloseVosObject();
1746 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiReplica, status);
1755 BOOL AfsClass_DeleteClone (LPIDENT lpiClone, ULONG *pStatus)
1757 return AfsClass_DeleteFileset (lpiClone, TRUE, TRUE, pStatus);
1761 BOOL AfsClass_InstallFile (LPIDENT lpiServer, LPTSTR pszTarget, LPTSTR pszSource, ULONG *pStatus)
1767 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileBegin, lpiServer, pszSource, 0);
1772 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1776 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1784 wp.wpBosExecutableCreate.hServer = hBOS;
1785 wp.wpBosExecutableCreate.pszLocal = pszSource;
1786 wp.wpBosExecutableCreate.pszRemoteDir = pszTarget;
1789 rc = Worker_DoTask (wtaskBosExecutableCreate, &wp, &status);
1793 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1795 lpServer->CloseBosObject();
1799 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileEnd, lpiServer, pszSource, status);
1808 BOOL AfsClass_UninstallFile (LPIDENT lpiServer, LPTSTR pszUninstall, ULONG *pStatus)
1814 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileBegin, lpiServer, pszUninstall, 0);
1819 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1823 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1831 wp.wpBosExecutableRevert.hServer = hBOS;
1832 wp.wpBosExecutableRevert.pszFilename = pszUninstall;
1835 rc = Worker_DoTask (wtaskBosExecutableRevert, &wp, &status);
1839 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1841 lpServer->CloseBosObject();
1845 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileEnd, lpiServer, pszUninstall, status);
1854 BOOL AfsClass_PruneOldFiles (LPIDENT lpiServer, BOOL fBAK, BOOL fOLD, BOOL fCore, ULONG *pStatus)
1860 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesBegin, lpiServer);
1865 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1869 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1877 wp.wpBosExecutablePrune.hServer = hBOS;
1878 wp.wpBosExecutablePrune.fPruneBak = fBAK;
1879 wp.wpBosExecutablePrune.fPruneOld = fOLD;
1880 wp.wpBosExecutablePrune.fPruneCore = fCore;
1883 rc = Worker_DoTask (wtaskBosExecutablePrune, &wp, &status);
1887 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1889 lpServer->CloseBosObject();
1893 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesEnd, lpiServer, status);
1902 BOOL AfsClass_RenameFileset (LPIDENT lpiFileset, LPTSTR pszNewName, ULONG *pStatus)
1908 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetBegin, lpiFileset, pszNewName, 0);
1912 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1916 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1924 wp.wpVosVolumeRename.hCell = hCell;
1925 lpiFileset->GetFilesetID (&wp.wpVosVolumeRename.idVolume);
1926 wp.wpVosVolumeRename.pszVolume = pszNewName;
1929 rc = Worker_DoTask (wtaskVosVolumeRename, &wp, &status);
1936 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1940 lpCell->Invalidate();
1941 rc = lpCell->RefreshAll (&status);
1947 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetEnd, lpiFileset, pszNewName, status);
1956 #define iswhite(_ch) ((_ch)==TEXT(' ') || (_ch)==TEXT('\t'))
1958 LPIDENT AfsClass_CreateService (LPIDENT lpiServer, LPTSTR pszService, LPTSTR pszCommand, LPTSTR pszParams, LPTSTR pszNotifier, AFSSERVICETYPE type, SYSTEMTIME *pstIfCron, ULONG *pStatus)
1962 LPIDENT lpiService = NULL;
1965 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceBegin, lpiServer, pszService, 0);
1970 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1974 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1982 wp.wpBosProcessCreate.hServer = hBOS;
1983 wp.wpBosProcessCreate.pszService = pszService;
1984 wp.wpBosProcessCreate.type = type;
1985 wp.wpBosProcessCreate.pszNotifier = pszNotifier;
1987 TCHAR szFullCommand[ MAX_PATH + MAX_PATH ];
1988 wsprintf (szFullCommand, TEXT("%s %s"), pszCommand, pszParams);
1989 wp.wpBosProcessCreate.pszCommand = szFullCommand;
1991 TCHAR szCronTime[ 256 ] = TEXT("");
1992 wp.wpBosProcessCreate.pszTimeCron = szCronTime;
1994 if (type == SERVICETYPE_CRON)
1995 AfsClass_FormatRecurringTime (szCronTime, pstIfCron);
1997 wp.wpBosProcessCreate.pszTimeCron = NULL;
2000 rc = Worker_DoTask (wtaskBosProcessCreate, &wp, &status);
2006 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2010 lpServer->InvalidateServices();
2011 if (!lpServer->RefreshServices (TRUE, &status))
2015 LPSERVICE lpService;
2016 if ((lpService = lpServer->OpenService (pszService, &status)) == NULL)
2020 lpiService = lpService->GetIdentifier();
2028 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2030 lpServer->CloseBosObject();
2034 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceEnd, lpiServer, pszService, status);
2039 return (rc) ? lpiService : NULL;
2043 BOOL AfsClass_DeleteService (LPIDENT lpiService, ULONG *pStatus)
2049 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceBegin, lpiService);
2054 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2058 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2063 // Before a service can be deleted, it must be stopped (otherwise, on NT,
2064 // the Delete operation won't block for the required Stop to complete--
2065 // so our wtaskDeleteBosProcess would return before the service really
2070 TCHAR szService[ cchNAME ];
2071 lpiService->GetServiceName (szService);
2074 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
2075 wp.wpBosProcessExecutionStateSet.pszService = szService;
2076 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
2077 // TODO: wp.wpStopBosProcess.fWait = TRUE;
2080 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
2084 // Delete the service
2088 TCHAR szService[ cchNAME ];
2089 lpiService->GetServiceName (szService);
2092 wp.wpBosProcessDelete.hServer = hBOS;
2093 wp.wpBosProcessDelete.pszService = szService;
2096 rc = Worker_DoTask (wtaskBosProcessDelete, &wp, &status);
2102 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2106 lpServer->InvalidateServices();
2107 if (!lpServer->RefreshServices (TRUE, &status))
2113 if ((lpServer = lpiService->OpenServer (&status)) != NULL)
2115 lpServer->CloseBosObject();
2119 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceEnd, lpiService, status);
2128 BOOL AfsClass_ReleaseFileset (LPIDENT lpiFilesetRW, BOOL fForce, ULONG *pStatus)
2134 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetBegin, lpiFilesetRW);
2136 // Obtain hCell and hVOS
2141 if ((lpServer = lpiFilesetRW->OpenServer (&status)) == NULL)
2145 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2150 // Perform the actual operation
2155 wp.wpVosVolumeRelease.hCell = hCell;
2156 wp.wpVosVolumeRelease.fForce = fForce;
2157 lpiFilesetRW->GetFilesetID (&wp.wpVosVolumeRelease.idVolume);
2160 rc = Worker_DoTask (wtaskVosVolumeRelease, &wp, &status);
2169 if ((lpCell = lpiFilesetRW->OpenCell (&status)) == NULL)
2173 lpCell->Invalidate();
2174 rc = lpCell->RefreshAll (&status);
2181 if ((lpServer = lpiFilesetRW->OpenServer (&status)) != NULL)
2183 lpServer->CloseVosObject();
2188 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetEnd, lpiFilesetRW, status);
2197 BOOL AfsClass_GetFileDates (LPIDENT lpiServer, LPTSTR pszFilename, SYSTEMTIME *pstFile, SYSTEMTIME *pstBAK, SYSTEMTIME *pstOLD, ULONG *pStatus)
2203 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesBegin, lpiServer, pszFilename, 0);
2208 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2212 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2220 wp.wpBosExecutableTimestampGet.hServer = hBOS;
2221 wp.wpBosExecutableTimestampGet.pszFilename = pszFilename;
2224 if ((rc = Worker_DoTask (wtaskBosExecutableTimestampGet, &wp, &status)) == TRUE)
2226 *pstFile = wp.wpBosExecutableTimestampGet.timeNew;
2227 *pstBAK = wp.wpBosExecutableTimestampGet.timeBak;
2228 *pstOLD = wp.wpBosExecutableTimestampGet.timeOld;
2234 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2236 lpServer->CloseBosObject();
2240 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesEnd, lpiServer, pszFilename, status);
2249 BOOL AfsClass_ExecuteCommand (LPIDENT lpiServer, LPTSTR pszCommand, ULONG *pStatus)
2255 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandBegin, lpiServer, pszCommand, 0);
2260 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2264 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2272 wp.wpBosCommandExecute.hServer = hBOS;
2273 wp.wpBosCommandExecute.pszCommand = pszCommand;
2276 rc = Worker_DoTask (wtaskBosCommandExecute, &wp, &status);
2280 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2282 lpServer->CloseBosObject();
2286 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandEnd, lpiServer, pszCommand, status);
2295 LPADMINLIST AfsClass_AdminList_Load (LPIDENT lpiServer, ULONG *pStatus)
2299 LPADMINLIST lpList = NULL;
2302 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadBegin, lpiServer);
2307 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2311 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2318 lpList = New(ADMINLIST);
2319 memset (lpList, 0x00, sizeof(ADMINLIST));
2321 lpList->lpiServer = lpiServer;
2323 WORKERPACKET wpBegin;
2324 wpBegin.wpBosAdminGetBegin.hServer = hBOS;
2325 if (!Worker_DoTask (wtaskBosAdminGetBegin, &wpBegin, &status))
2331 TCHAR szAdmin[ cchNAME ];
2333 WORKERPACKET wpNext;
2334 wpNext.wpBosAdminGetNext.hEnum = wpBegin.wpBosAdminGetBegin.hEnum;
2335 wpNext.wpBosAdminGetNext.pszAdmin = szAdmin;
2337 if (!Worker_DoTask (wtaskBosAdminGetNext, &wpNext, &status))
2339 if (status == ADMITERATORDONE)
2347 if ((iAdded = AfsClass_AdminList_AddEntry (lpList, szAdmin)) != (size_t)-1)
2349 lpList->aEntries[ iAdded ].fAdded = FALSE;
2353 WORKERPACKET wpDone;
2354 wpDone.wpBosAdminGetDone.hEnum = wpBegin.wpBosAdminGetBegin.hEnum;
2355 Worker_DoTask (wtaskBosAdminGetDone, &wpDone);
2359 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2361 lpServer->CloseBosObject();
2365 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadEnd, lpiServer, status);
2370 return (rc) ? lpList : NULL;
2374 LPADMINLIST AfsClass_AdminList_Copy (LPADMINLIST lpOld)
2376 LPADMINLIST lpNew = NULL;
2380 lpNew = New(ADMINLIST);
2381 memcpy (lpNew, lpOld, sizeof(ADMINLIST));
2384 lpNew->aEntries = 0;
2385 lpNew->cEntries = 0;
2387 if (REALLOC (lpNew->aEntries, lpNew->cEntries, lpOld->cEntries, cREALLOC_ADMINLISTENTRIES))
2389 size_t cb = lpOld->cEntries * sizeof(ADMINLISTENTRY);
2390 memcpy (lpNew->aEntries, lpOld->aEntries, cb);
2398 BOOL AfsClass_AdminList_Save (LPADMINLIST lpList, ULONG *pStatus)
2404 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveBegin, lpList->lpiServer);
2409 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
2413 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2420 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2422 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2425 // are we supposed to add this entry?
2427 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
2430 wp.wpBosAdminCreate.hServer = hBOS;
2431 wp.wpBosAdminCreate.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2434 if (!Worker_DoTask (wtaskBosAdminCreate, &wp, &thisstatus))
2437 status = thisstatus;
2441 lpList->aEntries[ iEntry ].fAdded = FALSE;
2445 // are we supposed to delete this entry?
2447 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
2450 wp.wpBosAdminDelete.hServer = hBOS;
2451 wp.wpBosAdminDelete.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2454 if (!Worker_DoTask (wtaskBosAdminDelete, &wp, &thisstatus))
2457 status = thisstatus;
2461 lpList->aEntries[ iEntry ].szAdmin[0] = TEXT('\0');
2462 lpList->aEntries[ iEntry ].fDeleted = FALSE;
2468 if ((lpServer = lpList->lpiServer->OpenServer (&status)) != NULL)
2470 lpServer->CloseBosObject();
2474 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveEnd, lpList->lpiServer, status);
2483 void AfsClass_AdminList_Free (LPADMINLIST lpList)
2485 if (lpList && !InterlockedDecrement (&lpList->cRef))
2487 if (lpList->aEntries)
2488 Free (lpList->aEntries);
2489 memset (lpList, 0x00, sizeof(ADMINLIST));
2495 size_t AfsClass_AdminList_AddEntry (LPADMINLIST lpList, LPTSTR pszAdmin)
2497 size_t iAdded = (size_t)-1;
2502 for (iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2504 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2507 if (iEntry >= lpList->cEntries)
2509 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_ADMINLISTENTRIES);
2511 if (iEntry < lpList->cEntries)
2514 lstrcpy (lpList->aEntries[ iAdded ].szAdmin, pszAdmin);
2515 lpList->aEntries[ iAdded ].fAdded = TRUE;
2516 lpList->aEntries[ iAdded ].fDeleted = FALSE;
2524 BOOL AfsClass_AdminList_DelEntry (LPADMINLIST lpList, size_t iIndex)
2529 (iIndex < lpList->cEntries) &&
2530 (lpList->aEntries[ iIndex ].szAdmin[0]) &&
2531 (!lpList->aEntries[ iIndex ].fDeleted) )
2533 if (lpList->aEntries[ iIndex ].fAdded)
2534 lpList->aEntries[ iIndex ].szAdmin[0] = TEXT('\0');
2536 lpList->aEntries[ iIndex ].fDeleted = TRUE;
2545 LPKEYLIST AfsClass_KeyList_Load (LPIDENT lpiServer, ULONG *pStatus)
2549 LPKEYLIST lpList = NULL;
2552 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadBegin, lpiServer);
2557 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2561 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2568 lpList = New(KEYLIST);
2569 memset (lpList, 0x00, sizeof(KEYLIST));
2570 lpList->lpiServer = lpiServer;
2572 WORKERPACKET wpBegin;
2573 wpBegin.wpBosKeyGetBegin.hServer = hBOS;
2574 if (!Worker_DoTask (wtaskBosKeyGetBegin, &wpBegin, &status))
2578 for (size_t iEnum = 0; ; ++iEnum)
2580 WORKERPACKET wpNext;
2581 wpNext.wpBosKeyGetNext.hEnum = wpBegin.wpBosKeyGetBegin.hEnum;
2583 if (!Worker_DoTask (wtaskBosKeyGetNext, &wpNext, &status))
2585 if (status == ADMITERATORDONE)
2592 if (REALLOC (lpList->aKeys, lpList->cKeys, 1+iEnum, cREALLOC_SERVERKEYS))
2594 lpList->aKeys[ iEnum ].keyVersion = wpNext.wpBosKeyGetNext.keyVersion;
2595 memcpy (&lpList->aKeys[ iEnum ].keyData, &wpNext.wpBosKeyGetNext.keyData, sizeof(ENCRYPTIONKEY));
2596 memcpy (&lpList->aKeys[ iEnum ].keyInfo, &wpNext.wpBosKeyGetNext.keyInfo, sizeof(ENCRYPTIONKEYINFO));
2600 WORKERPACKET wpDone;
2601 wpDone.wpBosKeyGetDone.hEnum = wpBegin.wpBosKeyGetBegin.hEnum;
2602 Worker_DoTask (wtaskBosKeyGetDone, &wpDone);
2606 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2608 lpServer->CloseBosObject();
2612 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadEnd, lpiServer, status);
2617 return (rc) ? lpList : NULL;
2621 void AfsClass_KeyList_Free (LPKEYLIST lpList)
2626 Free (lpList->aKeys);
2627 memset (lpList, 0x00, sizeof(KEYLIST));
2633 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPTSTR pszString, ULONG *pStatus)
2638 TCHAR szCell[ cchNAME ];
2639 lpiServer->GetCellName (szCell);
2642 wp.wpKasStringToKey.pszCell = szCell;
2643 wp.wpKasStringToKey.pszString = pszString;
2644 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
2648 else if (!AfsClass_AddKey (lpiServer, keyVersion, &wp.wpKasStringToKey.key, &status))
2659 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2667 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2671 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2679 wp.wpBosKeyCreate.hServer = hBOS;
2680 wp.wpBosKeyCreate.keyVersion = keyVersion;
2681 memcpy (&wp.wpBosKeyCreate.key, pKey, sizeof(ENCRYPTIONKEY));
2682 rc = Worker_DoTask (wtaskBosKeyCreate, &wp, &status);
2685 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2687 lpServer->CloseBosObject();
2697 BOOL AfsClass_DeleteKey (LPIDENT lpiServer, int keyVersion, ULONG *pStatus)
2705 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2709 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2717 wp.wpBosKeyDelete.hServer = hBOS;
2718 wp.wpBosKeyDelete.keyVersion = keyVersion;
2719 rc = Worker_DoTask (wtaskBosKeyDelete, &wp, &status);
2722 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2724 lpServer->CloseBosObject();
2734 BOOL AfsClass_GetRandomKey (LPIDENT lpi, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2742 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2746 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2749 hKAS = lpCell->GetKasObject (&status);
2756 wp.wpKasServerRandomKeyGet.hCell = hCell;
2757 wp.wpKasServerRandomKeyGet.hServer = hKAS;
2758 rc = Worker_DoTask (wtaskKasServerRandomKeyGet, &wp, &status);
2761 memcpy (pKey, &wp.wpKasServerRandomKeyGet.key, sizeof(ENCRYPTIONKEY));
2770 BOOL AfsClass_Clone (LPIDENT lpiRW, ULONG *pStatus)
2776 NOTIFYCALLBACK::SendNotificationToAll (evtCloneBegin, lpiRW, 0);
2782 if ((lpCell = lpiRW->OpenCell (&status)) == NULL)
2786 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2791 // Perform the actual operation
2796 wp.wpVosBackupVolumeCreate.hCell = hCell;
2797 lpiRW->GetFilesetID (&wp.wpVosBackupVolumeCreate.idVolume);
2800 rc = Worker_DoTask (wtaskVosBackupVolumeCreate, &wp, &status);
2809 if ((lpServer = lpiRW->OpenServer (&status)) == NULL)
2813 lpServer->Invalidate();
2814 rc = lpServer->RefreshAll (&status);
2819 NOTIFYCALLBACK::SendNotificationToAll (evtCloneEnd, lpiRW, status);
2828 BOOL AfsClass_CloneMultiple (LPIDENT lpi, LPTSTR pszPrefix, BOOL fExclude, ULONG *pStatus)
2834 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleBegin, lpi);
2840 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2844 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2849 // Obtain hServer if appropriate
2852 if (!lpi->fIsCell())
2855 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2859 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
2865 // If requested, obtain the appropriate aggregate ID
2867 int idPartition = NO_PARTITION;
2868 if (rc && (lpi->fIsFileset() || lpi->fIsAggregate()))
2870 LPAGGREGATE lpAggregate;
2871 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2875 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
2877 lpAggregate->Close();
2881 // Perform the actual operation
2886 wp.wpVosBackupVolumeCreateMultiple.hCell = hCell;
2887 wp.wpVosBackupVolumeCreateMultiple.hServer = hVOS;
2888 wp.wpVosBackupVolumeCreateMultiple.idPartition = idPartition;
2889 wp.wpVosBackupVolumeCreateMultiple.pszPrefix = pszPrefix;
2890 wp.wpVosBackupVolumeCreateMultiple.fExclude = fExclude;
2893 rc = Worker_DoTask (wtaskVosBackupVolumeCreateMultiple, &wp, &status);
2904 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2908 lpCell->Invalidate();
2909 rc = lpCell->RefreshAll (&status);
2916 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2920 lpServer->Invalidate();
2921 rc = lpServer->RefreshAll (&status);
2930 if ((lpServer = lpi->OpenServer (&status)) != NULL)
2932 lpServer->CloseVosObject();
2937 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleEnd, lpi, status);
2946 BOOL AfsClass_DumpFileset (LPIDENT lpi, LPTSTR pszFilename, LPSYSTEMTIME pstDate, ULONG *pStatus)
2952 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetBegin, lpi, pszFilename, 0);
2954 // Obtain hCell and hVOS
2959 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2963 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2968 // Obtain idPartition
2971 LPAGGREGATE lpAggregate;
2972 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2976 idPartition = lpAggregate->GetID();
2977 lpAggregate->Close();
2980 // Perform the actual operation
2985 wp.wpVosVolumeDump.hCell = hCell;
2986 wp.wpVosVolumeDump.hServer = hVOS;
2987 wp.wpVosVolumeDump.pszFilename = pszFilename;
2988 wp.wpVosVolumeDump.idPartition = idPartition;
2989 lpi->GetFilesetID (&wp.wpVosVolumeDump.idVolume);
2992 memcpy (&wp.wpVosVolumeDump.stStart, pstDate, sizeof(SYSTEMTIME));
2994 memset (&wp.wpVosVolumeDump.stStart, 0x00, sizeof(SYSTEMTIME));
2997 rc = Worker_DoTask (wtaskVosVolumeDump, &wp, &status);
3001 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetEnd, lpi, pszFilename, status);
3007 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3009 lpServer->CloseVosObject();
3020 BOOL AfsClass_RestoreFileset (LPIDENT lpi, LPTSTR pszFileset, LPTSTR pszFilename, BOOL fIncremental, ULONG *pStatus)
3026 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetBegin, lpi, NULL, pszFileset, pszFilename, 0, 0);
3028 // Obtain hCell and hVOS
3033 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3037 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
3042 // Obtain idPartition
3045 LPAGGREGATE lpAggregate;
3046 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
3050 idPartition = lpAggregate->GetID();
3051 lpAggregate->Close();
3054 // Perform the actual operation
3059 wp.wpVosVolumeRestore.hCell = hCell;
3060 wp.wpVosVolumeRestore.hServer = hVOS;
3061 wp.wpVosVolumeRestore.idPartition = idPartition;
3062 wp.wpVosVolumeRestore.pszVolume = pszFileset;
3063 wp.wpVosVolumeRestore.pszFilename = pszFilename;
3064 wp.wpVosVolumeRestore.fIncremental = fIncremental;
3066 if (lpi->fIsFileset())
3067 lpi->GetFilesetID (&wp.wpVosVolumeRestore.idVolume);
3069 wp.wpVosVolumeRestore.idVolume = NO_VOLUME;
3072 rc = Worker_DoTask (wtaskVosVolumeRestore, &wp, &status);
3080 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3084 lpServer->Invalidate();
3085 rc = lpServer->RefreshAll (&status);
3092 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3094 lpServer->CloseVosObject();
3099 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetEnd, lpi, NULL, pszFileset, pszFilename, 0, status);
3108 BOOL AfsClass_GetRestartTimes (LPIDENT lpiServer, BOOL *pfWeekly, LPSYSTEMTIME pstWeekly, BOOL *pfDaily, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3114 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesBegin, lpiServer);
3119 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3123 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3131 wp.wpBosExecutableRestartTimeGet.hServer = hBOS;
3134 rc = Worker_DoTask (wtaskBosExecutableRestartTimeGet, &wp, &status);
3139 *pfWeekly = wp.wpBosExecutableRestartTimeGet.fWeeklyRestart;
3140 *pstWeekly = wp.wpBosExecutableRestartTimeGet.timeWeekly;
3141 *pfDaily = wp.wpBosExecutableRestartTimeGet.fDailyRestart;
3142 *pstDaily = wp.wpBosExecutableRestartTimeGet.timeDaily;
3146 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3148 lpServer->CloseBosObject();
3152 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesEnd, lpiServer, status);
3161 BOOL AfsClass_SetRestartTimes (LPIDENT lpiServer, LPSYSTEMTIME pstWeekly, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3167 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesBegin, lpiServer);
3172 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3176 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3183 SYSTEMTIME timeNever;
3184 memset (&timeNever, 0x00, sizeof(SYSTEMTIME));
3187 wp.wpBosExecutableRestartTimeSet.hServer = hBOS;
3188 wp.wpBosExecutableRestartTimeSet.fWeeklyRestart = (pstWeekly != NULL) ? TRUE : FALSE;
3189 wp.wpBosExecutableRestartTimeSet.timeWeekly = (pstWeekly != NULL) ? *pstWeekly : timeNever;
3190 wp.wpBosExecutableRestartTimeSet.fDailyRestart = (pstDaily != NULL) ? TRUE : FALSE;
3191 wp.wpBosExecutableRestartTimeSet.timeDaily = (pstDaily != NULL) ? *pstDaily : timeNever;
3194 rc = Worker_DoTask (wtaskBosExecutableRestartTimeSet, &wp, &status);
3198 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3200 lpServer->CloseBosObject();
3204 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesEnd, lpiServer, status);
3213 BOOL AfsClass_MoveReplica (LPIDENT lpiReplica, LPIDENT lpiAggregateTarget, ULONG *pStatus)
3217 // Find the identifier for this replica's read/write fileset.
3219 LPIDENT lpiFilesetRW = NULL;
3220 LPFILESET lpFileset;
3221 if ((lpFileset = lpiReplica->OpenFileset (pStatus)) == NULL)
3225 if ((lpiFilesetRW = lpFileset->GetReadWriteIdentifier (pStatus)) == NULL)
3230 // If the fileset replica currently resides on the same server
3231 // as the target aggregate, we'll follow the following steps:
3233 // 1. Delete the old fileset replica -> on error, quit
3234 // 2. Create the new fileset replica -> on error, recreate old replica, quit
3236 // If the fileset replica instead currently resides on a different
3237 // server, we can follow the preferred steps:
3239 // 1. Create the new fileset replica -> on error, quit
3240 // 2. Delete the old fileset replica -> on error, delete the new replica, quit
3244 LPIDENT lpiReplicaNew;
3246 if (lpiReplica->GetServer() == lpiAggregateTarget->GetServer())
3248 LPIDENT lpiAggregateOriginal = lpiReplica->GetAggregate();
3250 if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3254 else if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3256 (void)AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateOriginal);
3260 else // different server?
3262 if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3266 else if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3268 (void)AfsClass_DeleteReplica (lpiReplicaNew, pStatus);
3278 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)
3284 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageBegin, lpiSalvage);
3289 if ((lpServer = lpiSalvage->OpenServer (&status)) == NULL)
3293 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3299 *ppszLogData = NULL;
3301 // Step one: perform the actual salvage. This will dump a log file onto
3302 // the target computer.
3306 LPTSTR pszAggregate = NULL;
3307 TCHAR szAggregate[ cchNAME ];
3308 if (lpiSalvage->fIsAggregate() || lpiSalvage->fIsFileset())
3310 lpiSalvage->GetAggregateName (szAggregate);
3311 pszAggregate = szAggregate;
3314 LPTSTR pszFileset = NULL;
3315 TCHAR szFileset[ cchNAME ];
3316 if (lpiSalvage->fIsFileset())
3319 lpiSalvage->GetFilesetID (&vid);
3320 wsprintf (szFileset, TEXT("%lu"), vid);
3321 pszFileset = szFileset;
3324 if (pszLogFile == NULL)
3325 pszLogFile = TEXT("SalvageLog");
3328 wp.wpBosSalvage.hCell = hCell;
3329 wp.wpBosSalvage.hServer = hBOS;
3330 wp.wpBosSalvage.pszAggregate = pszAggregate;
3331 wp.wpBosSalvage.pszFileset = pszFileset;
3332 wp.wpBosSalvage.nProcesses = nProcesses;
3333 wp.wpBosSalvage.pszTempDir = pszTempDir;
3334 wp.wpBosSalvage.pszLogFile = pszLogFile;
3335 wp.wpBosSalvage.fForce = fForce;
3336 wp.wpBosSalvage.fReadonly = fReadonly;
3337 wp.wpBosSalvage.fLogInodes = fLogInodes;
3338 wp.wpBosSalvage.fLogRootInodes = fLogRootInodes;
3339 wp.wpBosSalvage.fRebuildDirs = fRebuildDirs;
3340 wp.wpBosSalvage.fReadBlocks = fReadBlocks;
3343 rc = Worker_DoTask (wtaskBosSalvage, &wp, &status);
3347 // Step two: retrieve the log file from that salvage operation.
3348 // If we can't get the log file back, that's not fatal--just return
3349 // a NULL pointer for the log data.
3351 if (rc && ppszLogData)
3354 wp.wpBosLogGet.hServer = hBOS;
3355 wp.wpBosLogGet.pszLogName = pszLogFile;
3356 wp.wpBosLogGet.pszLogData = NULL;
3359 if ((rc = Worker_DoTask (wtaskBosLogGet, &wp, &status)) == TRUE)
3361 // Okay, well, we have the log in memory now. Problem is,
3362 // it has UNIX-style CR's... and so is missing the LF which
3363 // PCs expect before each CR. Wow--look at all the
3364 // acronyms! Count the CRs, alloc a larger buffer, and stuff
3365 // in the LFs before each CR.
3367 size_t cchRequired = 1;
3368 for (LPTSTR pchIn = wp.wpBosLogGet.pszLogData; *pchIn; ++pchIn)
3370 cchRequired += (*pchIn == TEXT('\r')) ? 0 : (*pchIn == TEXT('\n')) ? 2 : 1;
3373 if ((*ppszLogData = AllocateString (cchRequired)) != NULL)
3375 LPTSTR pszOut = *ppszLogData;
3376 for (LPTSTR pchIn = wp.wpBosLogGet.pszLogData; *pchIn; ++pchIn)
3378 if (*pchIn == TEXT('\n'))
3379 *pszOut++ = TEXT('\r');
3380 if (*pchIn != TEXT('\r'))
3383 *pszOut++ = TEXT('\0');
3389 if ((lpServer = lpiSalvage->OpenServer (&status)) != NULL)
3391 lpServer->CloseBosObject();
3395 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageEnd, lpiSalvage, status);
3404 void AfsClass_FreeSalvageLog (LPTSTR pszLogData)
3411 LPHOSTLIST AfsClass_HostList_Load (LPIDENT lpiServer, ULONG *pStatus)
3415 LPHOSTLIST lpList = NULL;
3418 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadBegin, lpiServer);
3423 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3427 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3434 lpList = New(HOSTLIST);
3435 memset (lpList, 0x00, sizeof(HOSTLIST));
3437 lpList->lpiServer = lpiServer;
3439 WORKERPACKET wpBegin;
3440 wpBegin.wpBosHostGetBegin.hServer = hBOS;
3441 if (!Worker_DoTask (wtaskBosHostGetBegin, &wpBegin, &status))
3447 TCHAR szHost[ cchNAME ];
3449 WORKERPACKET wpNext;
3450 wpNext.wpBosHostGetNext.hEnum = wpBegin.wpBosHostGetBegin.hEnum;
3451 wpNext.wpBosHostGetNext.pszServer = szHost;
3453 if (!Worker_DoTask (wtaskBosHostGetNext, &wpNext, &status))
3455 if (status == ADMITERATORDONE)
3463 if ((iAdded = AfsClass_HostList_AddEntry (lpList, szHost)) != (size_t)-1)
3465 lpList->aEntries[ iAdded ].fAdded = FALSE;
3469 WORKERPACKET wpDone;
3470 wpDone.wpBosHostGetDone.hEnum = wpBegin.wpBosHostGetBegin.hEnum;
3471 Worker_DoTask (wtaskBosHostGetDone, &wpDone);
3475 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3477 lpServer->CloseBosObject();
3481 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadEnd, lpiServer, status);
3486 return (rc) ? lpList : NULL;
3490 LPHOSTLIST AfsClass_HostList_Copy (LPHOSTLIST lpOld)
3492 LPHOSTLIST lpNew = NULL;
3496 lpNew = New(HOSTLIST);
3497 memcpy (lpNew, lpOld, sizeof(HOSTLIST));
3500 lpNew->aEntries = 0;
3501 lpNew->cEntries = 0;
3503 if (REALLOC (lpNew->aEntries, lpNew->cEntries, lpOld->cEntries, cREALLOC_HOSTLISTENTRIES))
3505 size_t cb = lpOld->cEntries * sizeof(HOSTLISTENTRY);
3506 memcpy (lpNew->aEntries, lpOld->aEntries, cb);
3514 BOOL AfsClass_HostList_Save (LPHOSTLIST lpList, ULONG *pStatus)
3520 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveBegin, lpList->lpiServer);
3525 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
3529 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3536 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3538 if (!lpList->aEntries[ iEntry ].szHost[0])
3541 // are we supposed to add this entry?
3543 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
3546 wp.wpBosHostCreate.hServer = hBOS;
3547 wp.wpBosHostCreate.pszServer = lpList->aEntries[ iEntry ].szHost;
3550 if (!Worker_DoTask (wtaskBosHostCreate, &wp, &thisstatus))
3553 status = thisstatus;
3557 lpList->aEntries[ iEntry ].fAdded = FALSE;
3561 // are we supposed to delete this entry?
3563 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
3566 wp.wpBosHostDelete.hServer = hBOS;
3567 wp.wpBosHostDelete.pszServer = lpList->aEntries[ iEntry ].szHost;
3570 if (!Worker_DoTask (wtaskBosHostDelete, &wp, &thisstatus))
3573 status = thisstatus;
3577 lpList->aEntries[ iEntry ].szHost[0] = TEXT('\0');
3578 lpList->aEntries[ iEntry ].fDeleted = FALSE;
3584 if ((lpServer = lpList->lpiServer->OpenServer (&status)) != NULL)
3586 lpServer->CloseBosObject();
3590 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveEnd, lpList->lpiServer, status);
3599 void AfsClass_HostList_Free (LPHOSTLIST lpList)
3601 if (lpList && !InterlockedDecrement (&lpList->cRef))
3603 if (lpList->aEntries)
3604 Free (lpList->aEntries);
3605 memset (lpList, 0x00, sizeof(HOSTLIST));
3611 size_t AfsClass_HostList_AddEntry (LPHOSTLIST lpList, LPTSTR pszHost)
3613 size_t iAdded = (size_t)-1;
3618 for (iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3620 if (!lpList->aEntries[ iEntry ].szHost[0])
3623 if (iEntry >= lpList->cEntries)
3625 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_HOSTLISTENTRIES);
3627 if (iEntry < lpList->cEntries)
3630 lstrcpy (lpList->aEntries[ iAdded ].szHost, pszHost);
3631 lpList->aEntries[ iAdded ].fAdded = TRUE;
3632 lpList->aEntries[ iAdded ].fDeleted = FALSE;
3640 BOOL AfsClass_HostList_DelEntry (LPHOSTLIST lpList, size_t iIndex)
3645 (iIndex < lpList->cEntries) &&
3646 (lpList->aEntries[ iIndex ].szHost[0]) &&
3647 (!lpList->aEntries[ iIndex ].fDeleted) )
3649 if (lpList->aEntries[ iIndex ].fAdded)
3650 lpList->aEntries[ iIndex ].szHost[0] = TEXT('\0');
3652 lpList->aEntries[ iIndex ].fDeleted = TRUE;
3661 BOOL AfsClass_GetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3666 memset (pProperties, 0x00, sizeof(PTSPROPERTIES));
3672 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3676 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3681 // Go get the necessary properties
3686 wp.wpPtsUserMaxGet.hCell = hCell;
3688 if ((rc = Worker_DoTask (wtaskPtsUserMaxGet, &wp, &status)) == TRUE)
3689 pProperties->idUserMax = wp.wpPtsUserMaxGet.idUserMax;
3695 wp.wpPtsGroupMaxGet.hCell = hCell;
3697 if ((rc = Worker_DoTask (wtaskPtsGroupMaxGet, &wp, &status)) == TRUE)
3698 pProperties->idGroupMax = wp.wpPtsGroupMaxGet.idGroupMax;
3707 BOOL AfsClass_SetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3716 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3720 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3725 // Modify the specified properties
3730 wp.wpPtsUserMaxSet.hCell = hCell;
3731 wp.wpPtsUserMaxSet.idUserMax = pProperties->idUserMax;
3732 rc = Worker_DoTask (wtaskPtsUserMaxSet, &wp, &status);
3738 wp.wpPtsGroupMaxSet.hCell = hCell;
3739 wp.wpPtsGroupMaxSet.idGroupMax = pProperties->idGroupMax;
3740 Worker_DoTask (wtaskPtsGroupMaxSet, &wp, &status);
3749 LPIDENT AfsClass_CreateUser (LPIDENT lpiCell, LPTSTR pszUserName, LPTSTR pszInstance, LPTSTR pszPassword, UINT_PTR idUser, BOOL fCreateKAS, BOOL fCreatePTS, ULONG *pStatus)
3754 if (pszInstance && !*pszInstance)
3758 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserBegin, lpiCell, pszUserName, 0);
3760 // We'll need both hCell and hKAS.
3765 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3769 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3772 hKAS = lpCell->GetKasObject (&status);
3776 // First try to create a KAS entry.
3778 if (rc && fCreateKAS)
3781 wp.wpKasPrincipalCreate.hCell = hCell;
3782 wp.wpKasPrincipalCreate.hServer = hKAS;
3783 wp.wpKasPrincipalCreate.pszPrincipal = pszUserName;
3784 wp.wpKasPrincipalCreate.pszInstance = pszInstance;
3785 wp.wpKasPrincipalCreate.pszPassword = pszPassword;
3788 rc = Worker_DoTask (wtaskKasPrincipalCreate, &wp, &status);
3792 // If that succeeded, try to create a PTS entry as well.
3794 if (rc && fCreatePTS)
3796 TCHAR szUserName[ cchNAME ];
3797 lstrcpy (szUserName, pszUserName);
3799 wsprintf (&szUserName[ lstrlen(szUserName) ], TEXT(".%s"), pszInstance);
3802 wp.wpPtsUserCreate.hCell = hCell;
3803 wp.wpPtsUserCreate.pszUser = szUserName;
3804 wp.wpPtsUserCreate.idUser = (int) idUser;
3808 if ((rc = Worker_DoTask (wtaskPtsUserCreate, &wp, &status)) == FALSE)
3810 if (status == PREXIST)
3816 // If we couldn't make a KAS entry as well, remove the KAS entry.
3821 wpDel.wpKasPrincipalDelete.hCell = hCell;
3822 wpDel.wpKasPrincipalDelete.hServer = hKAS;
3823 wpDel.wpKasPrincipalDelete.pszPrincipal = pszUserName;
3824 wpDel.wpKasPrincipalDelete.pszInstance = pszInstance;
3825 Worker_DoTask (wtaskKasPrincipalDelete, &wpDel);
3832 // If we were able to create the user's accounts successfully, refresh
3833 // the cell status and return the new user's ident.
3839 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3843 if (!lpCell->RefreshAccount (pszUserName, pszInstance, CELL_REFRESH_ACCOUNT_CREATED_USER, &lpiUser))
3851 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserEnd, lpiCell, pszUserName, status);
3856 return (rc) ? lpiUser : NULL;
3860 BOOL AfsClass_SetUserProperties (LPIDENT lpiUser, LPUSERPROPERTIES pProperties, ULONG *pStatus)
3866 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser);
3868 // We'll need both hCell and hKAS.
3873 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
3877 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3880 hKAS = lpCell->GetKasObject (&status);
3884 // We'll also need this user's current status
3888 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
3892 if (!lpUser->GetStatus (&us, TRUE, &status))
3897 // Modify the user's KAS entry (if necessary)
3899 DWORD dwKasMask = ( MASK_USERPROP_fAdmin |
3900 MASK_USERPROP_fGrantTickets |
3901 MASK_USERPROP_fCanEncrypt |
3902 MASK_USERPROP_fCanChangePassword |
3903 MASK_USERPROP_fCanReusePasswords |
3904 MASK_USERPROP_timeAccountExpires |
3905 MASK_USERPROP_cdayPwExpires |
3906 MASK_USERPROP_csecTicketLifetime |
3907 MASK_USERPROP_nFailureAttempts |
3908 MASK_USERPROP_csecFailedLoginLockTime );
3910 if (rc && (pProperties->dwMask & dwKasMask))
3912 TCHAR szPrincipal[ cchNAME ];
3913 TCHAR szInstance[ cchNAME ];
3914 lpiUser->GetUserName (szPrincipal, szInstance);
3917 wp.wpKasPrincipalFieldsSet.hCell = hCell;
3918 wp.wpKasPrincipalFieldsSet.hServer = hKAS;
3919 wp.wpKasPrincipalFieldsSet.pszPrincipal = szPrincipal;
3920 wp.wpKasPrincipalFieldsSet.pszInstance = szInstance;
3921 wp.wpKasPrincipalFieldsSet.fIsAdmin = (pProperties->dwMask & MASK_USERPROP_fAdmin) ? pProperties->fAdmin : us.KASINFO.fIsAdmin;
3922 wp.wpKasPrincipalFieldsSet.fGrantTickets = (pProperties->dwMask & MASK_USERPROP_fGrantTickets) ? pProperties->fGrantTickets : us.KASINFO.fCanGetTickets;
3923 wp.wpKasPrincipalFieldsSet.fCanEncrypt = (pProperties->dwMask & MASK_USERPROP_fCanEncrypt) ? pProperties->fCanEncrypt : us.KASINFO.fEncrypt;
3924 wp.wpKasPrincipalFieldsSet.fCanChangePassword = (pProperties->dwMask & MASK_USERPROP_fCanChangePassword) ? pProperties->fCanChangePassword : us.KASINFO.fCanChangePassword;
3925 wp.wpKasPrincipalFieldsSet.fCanReusePasswords = (pProperties->dwMask & MASK_USERPROP_fCanReusePasswords) ? pProperties->fCanReusePasswords : us.KASINFO.fCanReusePasswords;
3926 memcpy (&wp.wpKasPrincipalFieldsSet.timeExpires, (pProperties->dwMask & MASK_USERPROP_timeAccountExpires) ? &pProperties->timeAccountExpires : &us.KASINFO.timeExpires, sizeof(SYSTEMTIME));
3927 wp.wpKasPrincipalFieldsSet.cdayPwExpires = (pProperties->dwMask & MASK_USERPROP_cdayPwExpires) ? pProperties->cdayPwExpires : us.KASINFO.cdayPwExpire;
3928 wp.wpKasPrincipalFieldsSet.csecTicketLifetime = (pProperties->dwMask & MASK_USERPROP_csecTicketLifetime) ? pProperties->csecTicketLifetime : us.KASINFO.csecTicketLifetime;
3929 wp.wpKasPrincipalFieldsSet.nFailureAttempts = (pProperties->dwMask & MASK_USERPROP_nFailureAttempts) ? pProperties->nFailureAttempts : us.KASINFO.cFailLogin;
3930 wp.wpKasPrincipalFieldsSet.csecFailedLoginLockTime = (pProperties->dwMask & MASK_USERPROP_csecFailedLoginLockTime) ? pProperties->csecFailedLoginLockTime : us.KASINFO.csecFailLoginLock;
3933 rc = Worker_DoTask (wtaskKasPrincipalFieldsSet, &wp, &status);
3938 // Modify the user's PTS entry (if necessary)
3940 DWORD dwPtsMask = ( MASK_USERPROP_cGroupCreationQuota |
3941 MASK_USERPROP_aaListStatus |
3942 MASK_USERPROP_aaGroupsOwned |
3943 MASK_USERPROP_aaMembership );
3945 if (rc && (pProperties->dwMask & dwPtsMask))
3947 TCHAR szFullName[ cchNAME ];
3948 lpiUser->GetFullUserName (szFullName);
3951 wp.wpPtsUserModify.hCell = hCell;
3952 wp.wpPtsUserModify.pszUser = szFullName;
3953 memset (&wp.wpPtsUserModify.Delta, 0x00, sizeof(wp.wpPtsUserModify.Delta));
3955 if (pProperties->dwMask & MASK_USERPROP_cGroupCreationQuota)
3957 wp.wpPtsUserModify.Delta.flag = (pts_UserUpdateFlag_t)( (LONG)wp.wpPtsUserModify.Delta.flag | (LONG)PTS_USER_UPDATE_GROUP_CREATE_QUOTA );
3958 wp.wpPtsUserModify.Delta.groupCreationQuota = pProperties->cGroupCreationQuota;
3961 if (pProperties->dwMask & (MASK_USERPROP_aaListStatus | MASK_USERPROP_aaGroupsOwned | MASK_USERPROP_aaMembership))
3963 wp.wpPtsUserModify.Delta.flag = (pts_UserUpdateFlag_t)( (LONG)wp.wpPtsUserModify.Delta.flag | (LONG)PTS_USER_UPDATE_PERMISSIONS );
3964 wp.wpPtsUserModify.Delta.listStatus = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaListStatus) ? pProperties->aaListStatus : us.PTSINFO.aaListStatus );
3965 wp.wpPtsUserModify.Delta.listGroupsOwned = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaGroupsOwned) ? pProperties->aaGroupsOwned : us.PTSINFO.aaGroupsOwned );
3966 wp.wpPtsUserModify.Delta.listMembership = ACCOUNTACCESS_TO_USERACCESS( (pProperties->dwMask & MASK_USERPROP_aaMembership) ? pProperties->aaMembership : us.PTSINFO.aaMembership );
3970 rc = Worker_DoTask (wtaskPtsUserModify, &wp, &status);
3974 // If we were able to modify the user's properties successfully, refresh
3975 // that user's status.
3977 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
3979 lpUser->Invalidate();
3980 lpUser->RefreshStatus();
3984 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser, status);
3993 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPTSTR pszPassword, ULONG *pStatus)
3998 TCHAR szCell[ cchNAME ];
3999 lpiUser->GetCellName (szCell);
4002 wp.wpKasStringToKey.pszCell = szCell;
4003 wp.wpKasStringToKey.pszString = pszPassword;
4004 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
4008 else if (!AfsClass_SetUserPassword (lpiUser, keyVersion, &wp.wpKasStringToKey.key, &status))
4019 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
4025 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordBegin, lpiUser);
4027 // We'll need both hCell and hKAS.
4032 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4036 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4039 hKAS = lpCell->GetKasObject (&status);
4043 // Change the user's password
4047 TCHAR szPrincipal[ cchNAME ];
4048 TCHAR szInstance[ cchNAME ];
4049 lpiUser->GetUserName (szPrincipal, szInstance);
4052 wp.wpKasPrincipalKeySet.hCell = hCell;
4053 wp.wpKasPrincipalKeySet.hServer = hKAS;
4054 wp.wpKasPrincipalKeySet.pszPrincipal = szPrincipal;
4055 wp.wpKasPrincipalKeySet.pszInstance = szInstance;
4056 wp.wpKasPrincipalKeySet.keyVersion = keyVersion;
4057 memcpy (&wp.wpKasPrincipalKeySet.key.key, &pKey->key, ENCRYPTIONKEY_LEN);
4060 rc = Worker_DoTask (wtaskKasPrincipalKeySet, &wp, &status);
4064 // If we were able to modify the user's password successfully, refresh
4065 // that user's status.
4068 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4070 lpUser->Invalidate();
4071 lpUser->RefreshStatus();
4075 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordEnd, lpiUser, status);
4084 BOOL AfsClass_DeleteUser (LPIDENT lpiUser, BOOL fDeleteKAS, BOOL fDeletePTS, ULONG *pStatus)
4090 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserBegin, lpiUser);
4092 // We'll need both hCell and hKAS.
4097 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4101 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4104 hKAS = lpCell->GetKasObject (&status);
4108 // Find out whether this user has KAS and/or PTS entries. Also
4109 // get the various lists of groups for this user...
4112 LPTSTR mszOwnerOf = NULL;
4113 LPTSTR mszMemberOf = NULL;
4114 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
4118 lpUser->GetOwnerOf (&mszOwnerOf);
4119 lpUser->GetMemberOf (&mszMemberOf);
4123 // Delete the user's PTS entry
4125 if (rc && fDeletePTS)
4127 TCHAR szFullName[ cchNAME ];
4128 lpiUser->GetFullUserName (szFullName);
4131 wp.wpPtsUserDelete.hCell = hCell;
4132 wp.wpPtsUserDelete.pszUser = szFullName;
4135 if ((rc = Worker_DoTask (wtaskPtsUserDelete, &wp, &status)) == FALSE)
4137 if (status == ADMPTSFAILEDNAMETRANSLATE) // User had no PTS entry?
4143 // Delete the user's KAS entry
4145 if (rc && fDeleteKAS)
4147 TCHAR szPrincipal[ cchNAME ];
4148 TCHAR szInstance[ cchNAME ];
4149 lpiUser->GetUserName (szPrincipal, szInstance);
4152 wp.wpKasPrincipalDelete.hCell = hCell;
4153 wp.wpKasPrincipalDelete.hServer = hKAS;
4154 wp.wpKasPrincipalDelete.pszPrincipal = szPrincipal;
4155 wp.wpKasPrincipalDelete.pszInstance = szInstance;
4158 if ((rc = Worker_DoTask (wtaskKasPrincipalDelete, &wp, &status)) == FALSE)
4160 if (status == KANOENT)
4166 // If we were able to delete the user's accounts successfully, refresh
4171 if ((lpCell = lpiUser->OpenCell (&status)) != NULL)
4173 TCHAR szPrincipal[ cchNAME ];
4174 TCHAR szInstance[ cchNAME ];
4175 lpiUser->GetUserName (szPrincipal, szInstance);
4177 lpCell->RefreshAccount (szPrincipal, szInstance, CELL_REFRESH_ACCOUNT_DELETED);
4178 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4179 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4184 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserEnd, lpiUser, status);
4188 FreeString (mszOwnerOf);
4190 FreeString (mszMemberOf);
4197 BOOL AfsClass_UnlockUser (LPIDENT lpiUser, ULONG *pStatus)
4203 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserBegin, lpiUser);
4205 // We'll need both hCell and hKAS.
4210 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4214 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4217 hKAS = lpCell->GetKasObject (&status);
4221 // Unlock the user's KAS entry
4225 TCHAR szPrincipal[ cchNAME ];
4226 TCHAR szInstance[ cchNAME ];
4227 lpiUser->GetUserName (szPrincipal, szInstance);
4230 wp.wpKasPrincipalUnlock.hCell = hCell;
4231 wp.wpKasPrincipalUnlock.hServer = hKAS;
4232 wp.wpKasPrincipalUnlock.pszPrincipal = szPrincipal;
4233 wp.wpKasPrincipalUnlock.pszInstance = szInstance;
4236 rc = Worker_DoTask (wtaskKasPrincipalUnlock, &wp, &status);
4240 // If we were able to unlock the user's accounts successfully, refresh
4241 // the user's properties.
4246 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4248 lpUser->Invalidate();
4249 lpUser->RefreshStatus();
4254 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserEnd, lpiUser, status);
4263 LPIDENT AfsClass_CreateGroup (LPIDENT lpiCell, LPTSTR pszGroupName, LPIDENT lpiOwner, int idGroup, ULONG *pStatus)
4269 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupBegin, lpiCell, pszGroupName, 0);
4275 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4279 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4284 // Create a PTS entry for the new group
4288 TCHAR szOwner[ cchNAME ] = TEXT("");
4289 if (lpiOwner && lpiOwner->fIsUser())
4290 lpiOwner->GetFullUserName (szOwner);
4291 else if (lpiOwner && lpiOwner->fIsGroup())
4292 lpiOwner->GetGroupName (szOwner);
4295 wp.wpPtsGroupCreate.hCell = hCell;
4296 wp.wpPtsGroupCreate.pszGroup = pszGroupName;
4297 wp.wpPtsGroupCreate.pszOwner = (szOwner[0]) ? szOwner : NULL;
4298 wp.wpPtsGroupCreate.idGroup = idGroup;
4301 rc = Worker_DoTask (wtaskPtsGroupCreate, &wp, &status);
4305 // If we were able to create the group successfully, refresh
4306 // the cell status and return the new group's ident.
4312 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4316 if (!lpCell->RefreshAccount (pszGroupName, NULL, CELL_REFRESH_ACCOUNT_CREATED_GROUP, &lpiGroup))
4324 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupEnd, lpiCell, pszGroupName, status);
4329 return (rc) ? lpiGroup : NULL;
4333 BOOL AfsClass_SetGroupProperties (LPIDENT lpiGroup, LPGROUPPROPERTIES pProperties, ULONG *pStatus)
4339 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup);
4345 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4349 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4354 // We'll also need this group's current status
4358 if ((lpGroup = lpiGroup->OpenGroup (&status)) == NULL)
4362 if (!lpGroup->GetStatus (&gs, TRUE, &status))
4367 // Modify the group's PTS entry (if requested)
4369 DWORD dwPtsMask = ( MASK_GROUPPROP_aaListStatus |
4370 MASK_GROUPPROP_aaListGroupsOwned |
4371 MASK_GROUPPROP_aaListMembers |
4372 MASK_GROUPPROP_aaAddMember |
4373 MASK_GROUPPROP_aaDeleteMember );
4375 if (rc && (pProperties->dwMask & dwPtsMask))
4377 TCHAR szGroup[ cchNAME ];
4378 lpiGroup->GetGroupName (szGroup);
4381 wp.wpPtsGroupModify.hCell = hCell;
4382 wp.wpPtsGroupModify.pszGroup = szGroup;
4383 memset (&wp.wpPtsGroupModify.Delta, 0x00, sizeof(wp.wpPtsGroupModify.Delta));
4384 wp.wpPtsGroupModify.Delta.listStatus = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListStatus) ? pProperties->aaListStatus : gs.aaListStatus );
4385 wp.wpPtsGroupModify.Delta.listGroupsOwned = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListGroupsOwned) ? pProperties->aaListGroupsOwned : gs.aaListGroupsOwned );
4386 wp.wpPtsGroupModify.Delta.listMembership = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaListMembers) ? pProperties->aaListMembers : gs.aaListMembers );
4387 wp.wpPtsGroupModify.Delta.listAdd = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaAddMember) ? pProperties->aaAddMember : gs.aaAddMember );
4388 wp.wpPtsGroupModify.Delta.listDelete = ACCOUNTACCESS_TO_GROUPACCESS( (pProperties->dwMask & MASK_GROUPPROP_aaDeleteMember) ? pProperties->aaDeleteMember : gs.aaDeleteMember );
4391 rc = Worker_DoTask (wtaskPtsGroupModify, &wp, &status);
4395 // Change the group's owner (if requested)
4397 if (rc && (pProperties->dwMask & MASK_GROUPPROP_szOwner))
4399 TCHAR szGroup[ cchNAME ];
4400 lpiGroup->GetGroupName (szGroup);
4403 wp.wpPtsGroupOwnerChange.hCell = hCell;
4404 wp.wpPtsGroupOwnerChange.pszGroup = szGroup;
4405 wp.wpPtsGroupOwnerChange.pszOwner = pProperties->szOwner;
4408 rc = Worker_DoTask (wtaskPtsGroupOwnerChange, &wp, &status);
4412 // If we were able to modify the group's properties successfully, refresh
4413 // either the group's status. If the group's owner changed, also refresh
4414 // the group's old and new owners.
4418 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4420 TCHAR szAccount[ cchNAME ];
4421 lpiGroup->GetGroupName (szAccount);
4422 lpCell->RefreshAccount (szAccount, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4424 if (pProperties->dwMask & MASK_GROUPPROP_szOwner)
4426 lpCell->RefreshAccount (gs.szOwner, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4427 lpCell->RefreshAccount (pProperties->szOwner, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4434 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup, status);
4443 BOOL AfsClass_RenameGroup (LPIDENT lpiGroup, LPTSTR pszNewName, ULONG *pStatus)
4449 NOTIFYCALLBACK::SendNotificationToAll (evtRenameGroupBegin, lpiGroup);
4455 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4459 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4464 // Get this group's list of members (etc)
4466 LPTSTR mszOwnerOf = NULL;
4467 LPTSTR mszMemberOf = NULL;
4468 LPTSTR mszMembers = NULL;
4471 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4473 lpGroup->GetOwnerOf (&mszOwnerOf);
4474 lpGroup->GetMemberOf (&mszMemberOf);
4475 lpGroup->GetMembers (&mszMembers);
4479 // Rename the group's PTS entry
4483 TCHAR szGroup[ cchNAME ];
4484 lpiGroup->GetGroupName (szGroup);
4487 wp.wpPtsGroupRename.hCell = hCell;
4488 wp.wpPtsGroupRename.pszGroup = szGroup;
4489 wp.wpPtsGroupRename.pszNewName = pszNewName;
4492 rc = Worker_DoTask (wtaskPtsGroupRename, &wp, &status);
4496 // If we were able to rename the group successfully, refresh the cell status.
4501 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4503 lpGroup->ChangeIdentName (pszNewName);
4506 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4508 lpCell->RefreshAccount (pszNewName, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4509 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4510 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4511 lpCell->RefreshAccounts (mszMembers, CELL_REFRESH_ACCOUNT_CHANGED);
4516 NOTIFYCALLBACK::SendNotificationToAll (evtRenameGroupEnd, lpiGroup, status);
4520 FreeString (mszOwnerOf);
4522 FreeString (mszMemberOf);
4524 FreeString (mszMembers);
4531 BOOL AfsClass_DeleteGroup (LPIDENT lpiGroup, ULONG *pStatus)
4537 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteGroupBegin, lpiGroup);
4543 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4547 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4552 // Get this group's list of members (etc)
4554 LPTSTR mszOwnerOf = NULL;
4555 LPTSTR mszMemberOf = NULL;
4556 LPTSTR mszMembers = NULL;
4559 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4561 lpGroup->GetOwnerOf (&mszOwnerOf);
4562 lpGroup->GetMemberOf (&mszMemberOf);
4563 lpGroup->GetMembers (&mszMembers);
4567 // Delete the group's PTS entry
4571 TCHAR szGroup[ cchNAME ];
4572 lpiGroup->GetGroupName (szGroup);
4575 wp.wpPtsGroupDelete.hCell = hCell;
4576 wp.wpPtsGroupDelete.pszGroup = szGroup;
4579 if ((rc = Worker_DoTask (wtaskPtsGroupDelete, &wp, &status)) == FALSE)
4581 if (status == ADMPTSFAILEDNAMETRANSLATE) // Group had no PTS entry?
4587 // If we were able to delete the group successfully, refresh the cell status.
4591 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4593 TCHAR szGroup[ cchNAME ];
4594 lpiGroup->GetGroupName (szGroup);
4595 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4596 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4597 lpCell->RefreshAccounts (mszMembers, CELL_REFRESH_ACCOUNT_CHANGED);
4598 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_DELETED);
4603 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteGroupEnd, lpiGroup, status);
4607 FreeString (mszOwnerOf);
4609 FreeString (mszMemberOf);
4611 FreeString (mszMembers);
4618 BOOL AfsClass_AddUserToGroup (LPIDENT lpiGroup, LPIDENT lpiUser, ULONG *pStatus)
4624 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberAddBegin, lpiGroup, lpiUser, NULL, NULL, 0, 0);
4630 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4634 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4639 TCHAR szGroup[ cchNAME ];
4640 lpiGroup->GetGroupName (szGroup);
4642 TCHAR szMember[ cchNAME ];
4643 if (lpiUser->fIsUser())
4644 lpiUser->GetFullUserName (szMember);
4645 else // (lpiUser->fIsGroup())
4646 lpiUser->GetGroupName (szMember);
4648 // Add this user to the specified group
4653 wp.wpPtsGroupMemberAdd.hCell = hCell;
4654 wp.wpPtsGroupMemberAdd.pszGroup = szGroup;
4655 wp.wpPtsGroupMemberAdd.pszUser = szMember;
4658 rc = Worker_DoTask (wtaskPtsGroupMemberAdd, &wp, &status);
4662 // If we were able to change the group successfully, update the group's
4663 // and user's properties.
4667 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4669 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4670 lpCell->RefreshAccount (szMember, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4675 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberAddEnd, lpiGroup, lpiUser, NULL, NULL, 0, status);
4684 BOOL AfsClass_RemoveUserFromGroup (LPIDENT lpiGroup, LPIDENT lpiUser, ULONG *pStatus)
4690 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberRemoveBegin, lpiGroup, lpiUser, NULL, NULL, 0, 0);
4696 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4700 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4705 TCHAR szGroup[ cchNAME ];
4706 lpiGroup->GetGroupName (szGroup);
4708 TCHAR szMember[ cchNAME ];
4709 if (lpiUser->fIsUser())
4710 lpiUser->GetFullUserName (szMember);
4711 else // (lpiUser->fIsGroup())
4712 lpiUser->GetGroupName (szMember);
4714 // Remove this user from the specified group
4719 wp.wpPtsGroupMemberRemove.hCell = hCell;
4720 wp.wpPtsGroupMemberRemove.pszGroup = szGroup;
4721 wp.wpPtsGroupMemberRemove.pszUser = szMember;
4724 rc = Worker_DoTask (wtaskPtsGroupMemberRemove, &wp, &status);
4728 // If we were able to change the group successfully, update the group's
4729 // and user's properties.
4733 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4735 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4736 lpCell->RefreshAccount (szMember, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4741 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberRemoveEnd, lpiGroup, lpiUser, NULL, NULL, 0, status);