LINUX: afs_create infinite fetchStatus loop
[pkg-k5-afs_openafs.git] / src / WINNT / afsclass / afsclassfn.cpp
blob8c96b105dfb4ea24522dc8a7842e441d2970b4a0
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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
8 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afsconfig.h>
15 #include <afs/param.h>
16 #include <roken.h>
19 #include <WINNT/afsclass.h>
20 #include "internal.h"
24 * DEFINITIONS ________________________________________________________________
28 #define cREALLOC_ADMINLISTENTRIES 32
30 #define cREALLOC_HOSTLISTENTRIES 16
32 #define cREALLOC_SERVERKEYS 16
34 #define ACCOUNTACCESS_TO_USERACCESS(_aa) ( ((_aa) == aaOWNER_ONLY) ? PTS_USER_OWNER_ACCESS : PTS_USER_ANYUSER_ACCESS )
36 #define ACCOUNTACCESS_TO_GROUPACCESS(_aa) ( ((_aa) == aaOWNER_ONLY) ? PTS_GROUP_OWNER_ACCESS : ((_aa) == aaGROUP_ONLY) ? PTS_GROUP_ACCESS : PTS_GROUP_ANYUSER_ACCESS )
40 * PROTOTYPES _________________________________________________________________
46 * ROUTINES ___________________________________________________________________
50 BOOL AfsClass_GetServerLogFile (LPIDENT lpiServer, LPTSTR pszLocal, LPTSTR pszRemote, ULONG *pStatus)
52 BOOL rc = TRUE;
53 ULONG status;
55 AfsClass_Enter();
56 NOTIFYCALLBACK::SendNotificationToAll (evtGetServerLogFileBegin, lpiServer, pszRemote, 0);
58 PVOID hCell = NULL;
59 PVOID hBOS = NULL;
60 LPSERVER lpServer = NULL;
61 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
62 rc = FALSE;
63 else
65 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
66 rc = FALSE;
67 lpServer->Close();
70 if (rc)
72 WORKERPACKET wp;
73 wp.wpBosLogGet.hServer = hBOS;
74 wp.wpBosLogGet.pszLogName = pszRemote;
75 wp.wpBosLogGet.pszLogData = NULL;
77 AfsClass_Leave();
78 if ((rc = Worker_DoTask (wtaskBosLogGet, &wp, &status)) == TRUE)
80 HANDLE fh;
81 if ((fh = CreateFile (pszLocal, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL)) != INVALID_HANDLE_VALUE)
83 // Write the file a line at a time in order to make
84 // sure that each line ends with "\r\n". If we encounter
85 // a line which ends in \r\n already, well, leave it alone.
87 for (LPTSTR psz = wp.wpBosLogGet.pszLogData; psz && *psz; )
89 LPTSTR pszNext;
90 for (pszNext = psz; *pszNext && (*pszNext != TEXT('\r')) && (*pszNext != TEXT('\n')); ++pszNext)
92 DWORD cbWrite;
93 DWORD cbWrote;
94 if ((cbWrite = (DWORD)(pszNext - psz)) != 0)
95 WriteFile (fh, psz, cbWrite, &cbWrote, NULL);
96 WriteFile (fh, TEXT("\r\n"), 2, &cbWrote, NULL);
97 psz = (*pszNext == TEXT('\r')) ? (2+pszNext) : (*pszNext == TEXT('\n')) ? (1+pszNext) : NULL;
99 CloseHandle (fh);
102 Free (wp.wpBosLogGet.pszLogData);
105 AfsClass_Enter();
108 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
110 lpServer->CloseBosObject();
111 lpServer->Close();
114 NOTIFYCALLBACK::SendNotificationToAll (evtGetServerLogFileEnd, lpiServer, pszRemote, status);
115 AfsClass_Leave();
117 if (pStatus && !rc)
118 *pStatus = status;
119 return rc;
123 BOOL AfsClass_SetServerAuth (LPIDENT lpiServer, BOOL fEnabled, ULONG *pStatus)
125 BOOL rc = TRUE;
126 ULONG status;
128 AfsClass_Enter();
129 NOTIFYCALLBACK::SendNotificationToAll (evtSetServerAuthBegin, lpiServer);
131 PVOID hCell;
132 PVOID hBOS;
133 LPSERVER lpServer;
134 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
135 rc = FALSE;
136 else
138 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
139 rc = FALSE;
140 lpServer->Close();
143 if (rc)
145 WORKERPACKET wp;
146 wp.wpBosAuthSet.hServer = hBOS;
147 wp.wpBosAuthSet.fEnableAuth = fEnabled;
149 AfsClass_Leave();
150 rc = Worker_DoTask (wtaskBosAuthSet, &wp, &status);
151 AfsClass_Enter();
154 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
156 lpServer->CloseBosObject();
157 lpServer->Close();
160 NOTIFYCALLBACK::SendNotificationToAll (evtSetServerAuthEnd, lpiServer, status);
161 AfsClass_Leave();
163 if (pStatus && !rc)
164 *pStatus = status;
165 return rc;
169 BOOL AfsClass_StartService (LPIDENT lpiStart, BOOL fTemporary, ULONG *pStatus)
171 BOOL rc = TRUE;
172 ULONG status;
174 AfsClass_Enter();
175 NOTIFYCALLBACK::SendNotificationToAll (evtStartServiceBegin, lpiStart);
177 PVOID hCell;
178 PVOID hBOS;
179 LPSERVER lpServer;
180 if ((lpServer = lpiStart->OpenServer (&status)) == NULL)
181 rc = FALSE;
182 else
184 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
185 rc = FALSE;
186 lpServer->Close();
189 if (rc)
191 if (lpiStart->fIsService())
193 TCHAR szName[ cchNAME ];
194 lpiStart->GetServiceName (szName);
196 if (fTemporary)
198 WORKERPACKET wp;
199 wp.wpBosProcessExecutionStateSetTemporary.hServer = hBOS;
200 wp.wpBosProcessExecutionStateSetTemporary.pszService = szName;
201 wp.wpBosProcessExecutionStateSetTemporary.state = SERVICESTATE_RUNNING;
203 AfsClass_Leave();
204 rc = Worker_DoTask (wtaskBosProcessExecutionStateSetTemporary, &wp, &status);
205 AfsClass_Enter();
207 else
209 WORKERPACKET wp;
210 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
211 wp.wpBosProcessExecutionStateSet.pszService = szName;
212 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_RUNNING;
214 AfsClass_Leave();
215 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
216 AfsClass_Enter();
219 else
221 WORKERPACKET wp;
222 wp.wpBosProcessAllStart.hServer = hBOS;
223 AfsClass_Leave();
224 rc = Worker_DoTask (wtaskBosProcessAllStart, &wp, &status);
225 AfsClass_Enter();
229 if (rc)
231 if (lpiStart->fIsService())
233 LPSERVICE lpService;
234 if ((lpService = lpiStart->OpenService (&status)) == NULL)
235 rc = FALSE;
236 else
238 lpService->Invalidate();
239 lpService->RefreshStatus();
240 lpService->Close();
243 else
245 if ((lpServer = lpiStart->OpenServer (&status)) == NULL)
246 rc = FALSE;
247 else
249 lpServer->Invalidate();
250 lpServer->RefreshAll();
251 lpServer->Close();
256 if ((lpServer = lpiStart->OpenServer (&status)) != NULL)
258 lpServer->CloseBosObject();
259 lpServer->Close();
262 NOTIFYCALLBACK::SendNotificationToAll (evtStartServiceEnd, lpiStart, status);
263 AfsClass_Leave();
265 if (pStatus && !rc)
266 *pStatus = status;
267 return rc;
271 BOOL AfsClass_StopService (LPIDENT lpiStop, BOOL fTemporary, BOOL fWait, ULONG *pStatus)
273 BOOL rc = TRUE;
274 ULONG status;
276 AfsClass_Enter();
277 NOTIFYCALLBACK::SendNotificationToAll (evtStopServiceBegin, lpiStop);
279 PVOID hCell;
280 PVOID hBOS;
281 LPSERVER lpServer;
282 if ((lpServer = lpiStop->OpenServer (&status)) == NULL)
283 rc = FALSE;
284 else
286 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
287 rc = FALSE;
288 lpServer->Close();
291 if (rc)
293 if (lpiStop->fIsService())
295 TCHAR szName[ cchNAME ];
296 lpiStop->GetServiceName (szName);
298 if (fTemporary)
300 WORKERPACKET wp;
301 wp.wpBosProcessExecutionStateSetTemporary.hServer = hBOS;
302 wp.wpBosProcessExecutionStateSetTemporary.pszService = szName;
303 wp.wpBosProcessExecutionStateSetTemporary.state = SERVICESTATE_STOPPED;
304 // TODO: wp.wpStopBosProcessTemporary.fWait = TRUE;
306 AfsClass_Leave();
307 rc = Worker_DoTask (wtaskBosProcessExecutionStateSetTemporary, &wp, &status);
308 AfsClass_Enter();
310 else
312 WORKERPACKET wp;
313 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
314 wp.wpBosProcessExecutionStateSet.pszService = szName;
315 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
316 // TODO: wp.wpStopBosProcess.fWait = TRUE;
318 AfsClass_Leave();
319 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
320 AfsClass_Enter();
323 else if (fWait)
325 WORKERPACKET wp;
326 wp.wpBosProcessAllWaitStop.hServer = hBOS;
328 AfsClass_Leave();
329 rc = Worker_DoTask (wtaskBosProcessAllWaitStop, &wp, &status);
330 AfsClass_Enter();
332 else // (!fWait)
334 WORKERPACKET wp;
335 wp.wpBosProcessAllStop.hServer = hBOS;
337 AfsClass_Leave();
338 rc = Worker_DoTask (wtaskBosProcessAllStop, &wp, &status);
339 AfsClass_Enter();
343 if (rc)
345 if (lpiStop->fIsService())
347 LPSERVICE lpService;
348 if ((lpService = lpiStop->OpenService (&status)) == NULL)
349 rc = FALSE;
350 else
352 lpService->Invalidate();
353 lpService->RefreshStatus();
354 lpService->Close();
357 else
359 LPSERVER lpServer;
360 if ((lpServer = lpiStop->OpenServer (&status)) == NULL)
361 rc = FALSE;
362 else
364 lpServer->Invalidate();
365 lpServer->RefreshAll();
366 lpServer->Close();
371 if ((lpServer = lpiStop->OpenServer (&status)) != NULL)
373 lpServer->CloseBosObject();
374 lpServer->Close();
377 NOTIFYCALLBACK::SendNotificationToAll (evtStopServiceEnd, lpiStop, status);
378 AfsClass_Leave();
380 if (pStatus && !rc)
381 *pStatus = status;
382 return rc;
386 BOOL AfsClass_RestartService (LPIDENT lpiRestart, ULONG *pStatus)
388 BOOL rc = TRUE;
389 ULONG status;
391 AfsClass_Enter();
392 NOTIFYCALLBACK::SendNotificationToAll (evtRestartServiceBegin, lpiRestart);
394 PVOID hCell = NULL;
395 PVOID hBOS = NULL;
396 LPSERVER lpServer;
397 if ((lpServer = lpiRestart->OpenServer (&status)) == NULL)
398 rc = FALSE;
399 else
401 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
402 rc = FALSE;
403 lpServer->Close();
406 BOOL fRestartAll = FALSE;
407 if (!lpiRestart->fIsService())
408 fRestartAll = TRUE;
410 TCHAR szServiceRestart[ cchNAME ];
411 if (lpiRestart->fIsService())
413 lpiRestart->GetServiceName (szServiceRestart);
414 if (!lstrcmpi (szServiceRestart, TEXT("BOS")))
415 fRestartAll = TRUE;
418 if (rc)
420 if (!fRestartAll)
422 WORKERPACKET wp;
423 wp.wpBosProcessRestart.hServer = hBOS;
424 wp.wpBosProcessRestart.pszService = szServiceRestart;
426 AfsClass_Leave();
427 rc = Worker_DoTask (wtaskBosProcessRestart, &wp, &status);
428 AfsClass_Enter();
430 else // (fRestartAll)
432 WORKERPACKET wp;
433 wp.wpBosProcessAllStopAndRestart.hServer = hBOS;
434 wp.wpBosProcessAllStopAndRestart.fRestartBOS = TRUE;
436 AfsClass_Leave();
437 rc = Worker_DoTask (wtaskBosProcessAllStopAndRestart, &wp, &status);
438 AfsClass_Enter();
442 if (rc)
444 if (!fRestartAll)
446 LPSERVICE lpService;
447 if ((lpService = lpiRestart->OpenService (&status)) == NULL)
448 rc = FALSE;
449 else
451 lpService->Invalidate();
452 lpService->RefreshStatus();
453 lpService->Close();
456 else // (fRestartAll)
458 LPSERVER lpServer;
459 if ((lpServer = lpiRestart->OpenServer (&status)) == NULL)
460 rc = FALSE;
461 else
463 lpServer->Invalidate();
464 lpServer->RefreshAll();
465 lpServer->Close();
470 if ((lpServer = lpiRestart->OpenServer (&status)) != NULL)
472 lpServer->CloseBosObject();
473 lpServer->Close();
476 NOTIFYCALLBACK::SendNotificationToAll (evtRestartServiceEnd, lpiRestart, status);
477 AfsClass_Leave();
479 if (pStatus && !rc)
480 *pStatus = status;
481 return rc;
485 LPIDENT AfsClass_CreateFileset (LPIDENT lpiAggregate, LPTSTR pszFileset, ULONG ckQuota, ULONG *pStatus)
487 LPIDENT lpiFileset = NULL;
488 ULONG status;
489 BOOL rc = TRUE;
491 AfsClass_Enter();
492 NOTIFYCALLBACK::SendNotificationToAll (evtCreateFilesetBegin, lpiAggregate, pszFileset, 0);
494 // Obtain hCell and hVOS
496 PVOID hCell = NULL;
497 PVOID hVOS = NULL;
498 LPSERVER lpServer = NULL;
499 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
500 rc = FALSE;
501 else
503 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
504 rc = FALSE;
505 lpServer->Close();
508 // Obtain idPartition
510 int idPartition;
511 LPAGGREGATE lpAggregate;
512 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
513 rc = FALSE;
514 else
516 idPartition = lpAggregate->GetID();
517 lpAggregate->Close();
520 // Perform the actual operation
522 if (rc)
524 WORKERPACKET wp;
525 wp.wpVosVolumeCreate.hCell = hCell;
526 wp.wpVosVolumeCreate.hServer = hVOS;
527 wp.wpVosVolumeCreate.idPartition = idPartition;
528 wp.wpVosVolumeCreate.pszVolume = pszFileset;
529 wp.wpVosVolumeCreate.ckQuota = ckQuota;
531 AfsClass_Leave();
532 rc = Worker_DoTask (wtaskVosVolumeCreate, &wp, &status);
533 AfsClass_Enter();
536 // Clean up
538 if (rc)
540 LPAGGREGATE lpAggregate;
541 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
542 rc = FALSE;
543 else
545 lpAggregate->Invalidate();
546 lpAggregate->RefreshFilesets (TRUE, &status);
547 lpAggregate->Close();
551 if (rc)
553 LPCELL lpCell;
554 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
555 rc = FALSE;
556 else
558 lpCell->RefreshVLDB (lpiAggregate);
559 lpCell->Close();
563 if (rc)
565 LPAGGREGATE lpAggregate;
566 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
567 rc = FALSE;
568 else
570 LPFILESET lpFileset;
571 if ((lpFileset = lpAggregate->OpenFileset (pszFileset, &status)) == NULL)
572 rc = FALSE;
573 else
575 lpiFileset = lpFileset->GetIdentifier();
576 lpFileset->Close();
578 lpAggregate->Close();
582 if (hVOS)
584 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
586 lpServer->CloseVosObject();
587 lpServer->Close();
591 NOTIFYCALLBACK::SendNotificationToAll (evtCreateFilesetEnd, lpiAggregate, pszFileset, status);
592 AfsClass_Leave();
594 if (pStatus && !rc)
595 *pStatus = status;
596 return (rc) ? lpiFileset : NULL;
600 BOOL AfsClass_DeleteFileset (LPIDENT lpiFileset, BOOL fVLDB, BOOL fServer, ULONG *pStatus)
602 BOOL rc = TRUE;
603 ULONG status;
605 AfsClass_Enter();
606 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiFileset);
608 // Obtain hCell and hVOS
610 PVOID hCell = NULL;
611 PVOID hVOS = NULL;
612 LPSERVER lpServer = NULL;
613 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
614 rc = FALSE;
615 else
617 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
618 rc = FALSE;
619 lpServer->Close();
622 // Does the fileset have a VLDB entry? Does it actually exist on the server?
623 // What's its volume ID? Its R/W ID? Its partition ID?
625 VOLUMEID vidFileset;
626 VOLUMEID vidReadWrite;
627 int wFilesetGhost;
629 // Obtain the ID of the fileset's parent aggregate.
631 int idPartition;
632 LPAGGREGATE lpAggregate;
633 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
634 rc = FALSE;
635 else
637 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
638 rc = FALSE;
639 lpAggregate->Close();
642 if (rc)
644 LPFILESET lpFileset;
645 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
646 rc = FALSE;
647 else
649 wFilesetGhost = lpFileset->GetGhostStatus();
650 lpiFileset->GetFilesetID (&vidFileset);
652 FILESETSTATUS fs;
653 if (!lpFileset->GetStatus (&fs))
654 vidReadWrite = vidFileset;
655 else
656 vidReadWrite = fs.idReadWrite;
658 lpFileset->Close();
662 if (!(wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
663 fVLDB = FALSE;
664 if (!(wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
665 fServer = FALSE;
667 if (rc && fVLDB && fServer)
669 WORKERPACKET wp;
670 wp.wpVosVolumeDelete.hCell = hCell;
671 wp.wpVosVolumeDelete.hServer = hVOS;
672 wp.wpVosVolumeDelete.idPartition = idPartition;
673 wp.wpVosVolumeDelete.idVolume = vidFileset;
675 AfsClass_Leave();
676 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
677 AfsClass_Enter();
679 else if (rc && fVLDB)
681 WORKERPACKET wp;
682 wp.wpVosVLDBEntryRemove.hCell = hCell;
683 wp.wpVosVLDBEntryRemove.hServer = hVOS;
684 wp.wpVosVLDBEntryRemove.idPartition = idPartition;
685 wp.wpVosVLDBEntryRemove.idVolume = vidReadWrite;
687 AfsClass_Leave();
688 rc = Worker_DoTask (wtaskVosVLDBEntryRemove, &wp, &status);
689 AfsClass_Enter();
691 else if (rc && fServer)
693 WORKERPACKET wp;
694 wp.wpVosVolumeZap.hCell = hCell;
695 wp.wpVosVolumeZap.hServer = hVOS;
696 wp.wpVosVolumeZap.idPartition = idPartition;
697 wp.wpVosVolumeZap.idVolume = vidFileset;
698 wp.wpVosVolumeZap.fForce = TRUE;
700 AfsClass_Leave();
701 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
702 AfsClass_Enter();
705 if (rc)
707 LPAGGREGATE lpAggregate;
708 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
709 rc = FALSE;
710 else
712 lpAggregate->Invalidate();
713 lpAggregate->RefreshFilesets (TRUE);
714 lpAggregate->Close();
718 if (rc)
720 LPCELL lpCell;
721 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
722 rc = FALSE;
723 else
725 lpCell->RefreshVLDB (lpiFileset->GetAggregate(), TRUE);
726 lpCell->Close();
730 if (hVOS)
732 if ((lpServer = lpiFileset->OpenServer()) != NULL)
734 lpServer->CloseVosObject();
735 lpServer->Close();
739 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiFileset, status);
740 AfsClass_Leave();
742 if (pStatus && !rc)
743 *pStatus = status;
744 return rc;
748 BOOL AfsClass_MoveFileset (LPIDENT lpiFileset, LPIDENT lpiAggregateTarget, ULONG *pStatus)
750 BOOL rc = TRUE;
751 ULONG status;
753 AfsClass_Enter();
754 NOTIFYCALLBACK::SendNotificationToAll (evtMoveFilesetBegin, lpiFileset, lpiAggregateTarget, NULL, NULL, 0, 0);
756 LPIDENT lpiAggregateSource = lpiFileset->GetAggregate();
758 // Obtain hCell, hVOS and the aggregate name for the source
760 PVOID hCell;
761 PVOID hVOSSource = NULL;
762 LPSERVER lpServer;
763 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
764 rc = FALSE;
765 else
767 if ((hVOSSource = lpServer->OpenVosObject (&hCell, &status)) == NULL)
768 rc = FALSE;
769 lpServer->Close();
772 // Obtain the ID of the source aggregate
774 int idPartitionSource;
775 LPAGGREGATE lpAggregate;
776 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
777 rc = FALSE;
778 else
780 if ((idPartitionSource = lpAggregate->GetID()) == NO_PARTITION)
781 rc = FALSE;
782 lpAggregate->Close();
785 // Obtain hCell, hVOS and the aggregate name for the target
787 PVOID hVOSTarget = NULL;
788 if ((lpServer = lpiAggregateTarget->OpenServer (&status)) == NULL)
789 rc = FALSE;
790 else
792 if ((hVOSTarget = lpServer->OpenVosObject (NULL, &status)) == NULL)
793 rc = FALSE;
794 lpServer->Close();
797 // Obtain the ID of the target aggregate
799 int idPartitionTarget;
800 if ((lpAggregate = lpiAggregateTarget->OpenAggregate (&status)) == NULL)
801 rc = FALSE;
802 else
804 if ((idPartitionTarget = lpAggregate->GetID()) == NO_PARTITION)
805 rc = FALSE;
806 lpAggregate->Close();
809 if (rc)
811 WORKERPACKET wp;
812 wp.wpVosVolumeMove.hCell = hCell;
813 wp.wpVosVolumeMove.hServerFrom = hVOSSource;
814 wp.wpVosVolumeMove.idPartitionFrom = idPartitionSource;
815 wp.wpVosVolumeMove.hServerTo = hVOSTarget;
816 wp.wpVosVolumeMove.idPartitionTo = idPartitionTarget;
817 lpiFileset->GetFilesetID (&wp.wpVosVolumeMove.idVolume);
819 AfsClass_Leave();
820 rc = Worker_DoTask (wtaskVosVolumeMove, &wp, &status);
821 AfsClass_Enter();
824 if (rc)
826 LPAGGREGATE lpAggregate;
827 if ((lpAggregate = lpiAggregateSource->OpenAggregate (&status)) == NULL)
828 rc = FALSE;
829 else
831 lpAggregate->Invalidate();
832 lpAggregate->RefreshFilesets();
833 lpAggregate->Close();
837 if (rc)
839 LPAGGREGATE lpAggregate;
840 if ((lpAggregate = lpiAggregateTarget->OpenAggregate (&status)) == NULL)
841 rc = FALSE;
842 else
844 lpAggregate->Invalidate();
845 lpAggregate->RefreshFilesets();
846 lpAggregate->Close();
850 if (rc)
852 LPFILESET lpFileset;
853 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
854 rc = FALSE;
855 else
857 lpFileset->Invalidate();
858 lpFileset->RefreshStatus();
859 lpFileset->Close();
863 if (rc)
865 LPCELL lpCell;
866 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
867 rc = FALSE;
868 else
870 lpCell->RefreshVLDB (lpiAggregateSource, TRUE);
871 lpCell->RefreshVLDB (lpiAggregateTarget, TRUE);
872 lpCell->Close();
876 if (hVOSSource)
878 if ((lpServer = lpiAggregateSource->OpenServer()) != NULL)
880 lpServer->CloseVosObject();
881 lpServer->Close();
884 if (hVOSTarget)
886 if ((lpServer = lpiAggregateTarget->OpenServer()) != NULL)
888 lpServer->CloseVosObject();
889 lpServer->Close();
893 NOTIFYCALLBACK::SendNotificationToAll (evtMoveFilesetEnd, lpiFileset, lpiAggregateTarget, NULL, NULL, 0, status);
894 AfsClass_Leave();
896 if (pStatus && !rc)
897 *pStatus = status;
898 return rc;
902 BOOL AfsClass_SetFilesetQuota (LPIDENT lpiFileset, size_t ckQuotaNew, ULONG *pStatus)
904 BOOL rc = TRUE;
905 ULONG status;
907 AfsClass_Enter();
908 NOTIFYCALLBACK::SendNotificationToAll (evtSetFilesetQuotaBegin, lpiFileset);
910 // Obtain hCell and hVOS for the server where this fileset lives
912 PVOID hCell;
913 PVOID hVOS = NULL;
914 LPSERVER lpServer;
915 if ((lpServer = lpiFileset->OpenServer (&status)) == NULL)
916 rc = FALSE;
917 else
919 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
920 rc = FALSE;
921 lpServer->Close();
924 // Obtain the ID of the fileset's parent aggregate.
926 int idPartition;
927 if (rc)
929 LPAGGREGATE lpAggregate;
930 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
931 rc = FALSE;
932 else
934 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
935 rc = FALSE;
936 lpAggregate->Close();
940 // Change the fileset's quota.
942 if (rc)
944 WORKERPACKET wp;
945 wp.wpVosVolumeQuotaChange.hCell = hCell;
946 wp.wpVosVolumeQuotaChange.hServer = hVOS;
947 wp.wpVosVolumeQuotaChange.idPartition = idPartition;
948 lpiFileset->GetFilesetID (&wp.wpVosVolumeQuotaChange.idVolume);
949 wp.wpVosVolumeQuotaChange.ckQuota = ckQuotaNew;
951 AfsClass_Leave();
952 rc = Worker_DoTask (wtaskVosVolumeQuotaChange, &wp, &status);
953 AfsClass_Enter();
956 if (rc)
958 LPFILESET lpFileset;
959 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
960 rc = FALSE;
961 else
963 lpFileset->Invalidate();
964 lpFileset->RefreshStatus();
965 lpFileset->Close();
969 if (rc)
971 LPAGGREGATE lpAggregate;
972 if ((lpAggregate = lpiFileset->OpenAggregate (&status)) == NULL)
973 rc = FALSE;
974 else
976 lpAggregate->RefreshStatus();
977 lpAggregate->Close();
981 if (hVOS != NULL)
983 if ((lpServer = lpiFileset->OpenServer()) != NULL)
985 lpServer->CloseVosObject();
986 lpServer->Close();
990 NOTIFYCALLBACK::SendNotificationToAll (evtSetFilesetQuotaEnd, lpiFileset, status);
991 AfsClass_Leave();
993 if (pStatus && !rc)
994 *pStatus = status;
995 return rc;
999 BOOL AfsClass_SyncVLDB (LPIDENT lpiSync, BOOL fForce, ULONG *pStatus)
1001 BOOL rc = TRUE;
1002 ULONG status;
1004 AfsClass_Enter();
1005 NOTIFYCALLBACK::SendNotificationToAll (evtSyncVLDBBegin, lpiSync);
1007 // Obtain hCell and hVOS
1009 PVOID hCell;
1010 PVOID hVOS = NULL;
1011 LPSERVER lpServer;
1012 if ((lpServer = lpiSync->OpenServer (&status)) == NULL)
1013 rc = FALSE;
1014 else
1016 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1017 rc = FALSE;
1018 lpServer->Close();
1021 // Obtain the ID of the target aggregate.
1023 int idPartition = NO_PARTITION;
1024 if (rc && (lpiSync->fIsAggregate() || lpiSync->fIsFileset()))
1026 LPAGGREGATE lpAggregate;
1027 if ((lpAggregate = lpiSync->OpenAggregate (&status)) == NULL)
1028 rc = FALSE;
1029 else
1031 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1032 rc = FALSE;
1033 lpAggregate->Close();
1037 if (rc)
1039 WORKERPACKET wp;
1040 wp.wpVosVLDBSync.hCell = hCell;
1041 wp.wpVosVLDBSync.hServer = hVOS;
1042 wp.wpVosVLDBSync.idPartition = idPartition;
1043 wp.wpVosVLDBSync.fForce = fForce;
1045 AfsClass_Leave();
1046 rc = Worker_DoTask (wtaskVosVLDBSync, &wp, &status);
1047 AfsClass_Enter();
1050 if (rc)
1052 if (lpiSync->fIsServer())
1054 LPSERVER lpServer;
1055 if ((lpServer = lpiSync->OpenServer (&status)) == NULL)
1056 rc = FALSE;
1057 else
1059 lpServer->Invalidate();
1060 rc = lpServer->RefreshAll (&status);
1061 lpServer->Close();
1064 else // (lpiSync->fIsAggregate())
1066 LPAGGREGATE lpAggregate;
1067 if ((lpAggregate = lpiSync->OpenAggregate (&status)) == NULL)
1068 rc = FALSE;
1069 else
1071 lpAggregate->Invalidate();
1072 lpAggregate->RefreshStatus();
1073 lpAggregate->RefreshFilesets();
1074 lpAggregate->Close();
1076 LPCELL lpCell;
1077 if ((lpCell = lpiSync->OpenCell()) == NULL)
1078 rc = FALSE;
1079 else
1081 lpCell->RefreshVLDB (lpiSync);
1082 lpCell->Close();
1088 if (hVOS)
1090 if ((lpServer = lpiSync->OpenServer()) != NULL)
1092 lpServer->CloseVosObject();
1093 lpServer->Close();
1097 NOTIFYCALLBACK::SendNotificationToAll (evtSyncVLDBEnd, lpiSync, status);
1098 AfsClass_Leave();
1100 if (pStatus && !rc)
1101 *pStatus = status;
1102 return rc;
1106 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSOCKADDR_IN pAddrOld, LPSOCKADDR_IN pAddrNew, ULONG *pStatus)
1108 BOOL rc = TRUE;
1109 ULONG status;
1111 AfsClass_Enter();
1112 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1114 // Obtain hCell
1116 PVOID hCell;
1117 LPCELL lpCell;
1118 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1119 rc = FALSE;
1120 else
1122 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1123 rc = FALSE;
1124 lpCell->Close();
1127 if (rc && pAddrNew)
1129 WORKERPACKET wp;
1130 wp.wpVosFileServerAddressChange.hCell = hCell;
1131 wp.wpVosFileServerAddressChange.addrOld = *pAddrOld;
1132 wp.wpVosFileServerAddressChange.addrNew = *pAddrNew;
1134 AfsClass_Leave();
1135 rc = Worker_DoTask (wtaskVosFileServerAddressChange, &wp, &status);
1136 AfsClass_Enter();
1138 else if (rc && !pAddrNew)
1140 WORKERPACKET wp;
1141 wp.wpVosFileServerAddressRemove.hCell = hCell;
1142 wp.wpVosFileServerAddressRemove.addr = *pAddrOld;
1144 AfsClass_Leave();
1145 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1146 AfsClass_Enter();
1149 if (rc)
1151 LPSERVER lpServer;
1152 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1154 lpServer->InvalidateStatus();
1155 lpServer->Close();
1158 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1159 rc = FALSE;
1160 else
1162 lpCell->InvalidateServers ();
1163 rc = lpCell->RefreshServers (TRUE, &status);
1164 lpCell->Close();
1168 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1169 AfsClass_Leave();
1171 if (pStatus && !rc)
1172 *pStatus = status;
1173 return rc;
1177 BOOL AfsClass_ChangeAddress (LPIDENT lpiServer, LPSERVERSTATUS pStatusOld, LPSERVERSTATUS pStatusNew, ULONG *pStatus)
1179 BOOL rc = TRUE;
1180 ULONG status;
1182 AfsClass_Enter();
1183 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressBegin, lpiServer);
1185 // Obtain hCell
1187 PVOID hCell;
1188 LPCELL lpCell;
1189 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1190 rc = FALSE;
1191 else
1193 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1194 rc = FALSE;
1195 lpCell->Close();
1198 if (rc)
1200 AfsClass_Leave();
1202 for (size_t iAddr = 0; rc && (iAddr < AFSCLASS_MAX_ADDRESSES_PER_SITE); ++iAddr)
1204 int oldAddress;
1205 int newAddress;
1206 AfsClass_AddressToInt (&oldAddress, &pStatusOld->aAddresses[ iAddr ]);
1207 AfsClass_AddressToInt (&newAddress, &pStatusNew->aAddresses[ iAddr ]);
1209 if (oldAddress && newAddress && (oldAddress != newAddress))
1211 WORKERPACKET wp;
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)
1220 WORKERPACKET wp;
1221 wp.wpVosFileServerAddressRemove.hCell = hCell;
1222 wp.wpVosFileServerAddressRemove.addr = pStatusOld->aAddresses[ iAddr ];
1224 rc = Worker_DoTask (wtaskVosFileServerAddressRemove, &wp, &status);
1228 AfsClass_Enter();
1231 if (rc)
1233 LPSERVER lpServer;
1234 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1236 lpServer->InvalidateStatus();
1237 lpServer->Close();
1240 LPCELL lpCell;
1241 if ((lpCell = lpiServer->OpenCell (&status)) == NULL)
1242 rc = FALSE;
1243 else
1245 lpCell->InvalidateServers ();
1246 rc = lpCell->RefreshServers (TRUE, &status);
1247 lpCell->Close();
1251 NOTIFYCALLBACK::SendNotificationToAll (evtChangeAddressEnd, lpiServer, status);
1252 AfsClass_Leave();
1254 if (pStatus && !rc)
1255 *pStatus = status;
1256 return rc;
1260 BOOL AfsClass_LockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1262 BOOL rc = TRUE;
1263 ULONG status;
1265 AfsClass_Enter();
1266 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetBegin, lpiFileset);
1268 // Obtain hCell
1270 PVOID hCell;
1271 LPCELL lpCell;
1272 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1273 rc = FALSE;
1274 else
1276 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1277 rc = FALSE;
1278 lpCell->Close();
1281 // Obtain the fileset's read-write identifier
1283 LPIDENT lpiRW = NULL;
1284 LPFILESET lpFileset;
1285 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1286 rc = FALSE;
1287 else
1289 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1290 rc = FALSE;
1291 lpFileset->Close();
1294 // Perform the lock operation
1296 if (rc)
1298 WORKERPACKET wp;
1299 wp.wpVosVLDBEntryLock.hCell = hCell;
1300 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryLock.idVolume);
1302 AfsClass_Leave();
1303 rc = Worker_DoTask (wtaskVosVLDBEntryLock, &wp, &status);
1304 AfsClass_Enter();
1307 if (rc)
1309 LPCELL lpCell;
1310 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1311 rc = FALSE;
1312 else
1314 if (lpiRW)
1315 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1316 else
1317 lpCell->RefreshVLDB (lpiFileset->GetCell());
1318 lpCell->Close();
1322 NOTIFYCALLBACK::SendNotificationToAll (evtLockFilesetEnd, lpiFileset, status);
1323 AfsClass_Leave();
1325 if (pStatus && !rc)
1326 *pStatus = status;
1327 return rc;
1331 BOOL AfsClass_UnlockFileset (LPIDENT lpiFileset, ULONG *pStatus)
1333 BOOL rc = TRUE;
1334 ULONG status;
1336 AfsClass_Enter();
1337 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetBegin, lpiFileset);
1339 // Obtain hCell
1341 PVOID hCell;
1342 LPCELL lpCell;
1343 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1344 rc = FALSE;
1345 else
1347 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1348 rc = FALSE;
1349 lpCell->Close();
1352 // Obtain the fileset's read-write identifier
1354 LPIDENT lpiRW = NULL;
1355 LPFILESET lpFileset;
1356 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1357 rc = FALSE;
1358 else
1360 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1361 rc = FALSE;
1362 lpFileset->Close();
1365 // Perform the unlock operation
1367 if (rc)
1369 WORKERPACKET wp;
1370 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1371 wp.wpVosVLDBEntryUnlock.hServer = NULL;
1372 wp.wpVosVLDBEntryUnlock.idPartition = NO_PARTITION;
1373 lpiRW->GetFilesetID (&wp.wpVosVLDBEntryUnlock.idVolume);
1375 AfsClass_Leave();
1376 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1377 AfsClass_Enter();
1380 if (rc)
1382 LPCELL lpCell;
1383 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1384 rc = FALSE;
1385 else
1387 if (lpiRW)
1388 lpCell->RefreshVLDB (lpiRW, TRUE, NULL, TRUE);
1389 else
1390 lpCell->RefreshVLDB (lpiFileset->GetCell());
1391 lpCell->Close();
1395 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockFilesetEnd, lpiFileset, status);
1396 AfsClass_Leave();
1398 if (pStatus && !rc)
1399 *pStatus = status;
1400 return rc;
1404 BOOL AfsClass_UnlockAllFilesets (LPIDENT lpi, ULONG *pStatus)
1406 BOOL rc = TRUE;
1407 ULONG status;
1409 AfsClass_Enter();
1410 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsBegin, lpi);
1412 // Obtain hCell
1414 PVOID hCell;
1415 LPCELL lpCell;
1416 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1417 rc = FALSE;
1418 else
1420 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1421 rc = FALSE;
1422 lpCell->Close();
1425 // Obtain hServer if appropriate
1427 PVOID hVOS = NULL;
1428 if (lpi && (!lpi->fIsCell()))
1430 LPSERVER lpServer;
1431 if ((lpServer = lpi->OpenServer (&status)) == NULL)
1432 rc = FALSE;
1433 else
1435 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
1436 rc = FALSE;
1437 lpServer->Close();
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)
1448 rc = FALSE;
1449 else
1451 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
1452 rc = FALSE;
1453 lpAggregate->Close();
1457 // Perform the unlock operation
1459 if (rc)
1461 WORKERPACKET wp;
1462 wp.wpVosVLDBEntryUnlock.hCell = hCell;
1463 wp.wpVosVLDBEntryUnlock.hServer = hVOS;
1464 wp.wpVosVLDBEntryUnlock.idPartition = idPartition;
1465 wp.wpVosVLDBEntryUnlock.idVolume = NO_VOLUME;
1467 AfsClass_Leave();
1468 rc = Worker_DoTask (wtaskVosVLDBEntryUnlock, &wp, &status);
1469 AfsClass_Enter();
1472 if (rc)
1474 LPCELL lpCell;
1475 if ((lpCell = lpi->OpenCell (&status)) == NULL)
1476 rc = FALSE;
1477 else
1479 lpCell->RefreshVLDB (lpi);
1480 lpCell->Close();
1484 if (hVOS)
1486 LPSERVER lpServer;
1487 if ((lpServer = lpi->OpenServer (&status)) != NULL)
1489 lpServer->CloseVosObject();
1490 lpServer->Close();
1494 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockAllFilesetsEnd, lpi);
1495 AfsClass_Leave();
1497 if (pStatus && !rc)
1498 *pStatus = status;
1499 return rc;
1503 LPIDENT AfsClass_CreateReplica (LPIDENT lpiFileset, LPIDENT lpiAggregate, ULONG *pStatus)
1505 BOOL rc = TRUE;
1506 ULONG status;
1507 LPIDENT lpiReplica = NULL;
1509 AfsClass_Enter();
1510 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaBegin, lpiFileset, lpiAggregate, NULL, NULL, 0, 0);
1512 // Obtain hCell and hVOS for the target server
1514 PVOID hCell;
1515 PVOID hVOS = NULL;
1516 LPSERVER lpServer;
1517 if ((lpServer = lpiAggregate->OpenServer (&status)) == NULL)
1518 rc = FALSE;
1519 else
1521 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1522 rc = FALSE;
1523 lpServer->Close();
1526 // Obtain idPartition
1528 int idPartition;
1529 LPAGGREGATE lpAggregate;
1530 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1531 rc = FALSE;
1532 else
1534 idPartition = lpAggregate->GetID();
1535 lpAggregate->Close();
1538 // Modify VLDB to create mention of a new replica
1540 if (rc)
1542 WORKERPACKET wp;
1543 wp.wpVosVLDBReadOnlySiteCreate.hCell = hCell;
1544 wp.wpVosVLDBReadOnlySiteCreate.hServer = hVOS;
1545 wp.wpVosVLDBReadOnlySiteCreate.idPartition = idPartition;
1546 lpiFileset->GetFilesetID (&wp.wpVosVLDBReadOnlySiteCreate.idVolume);
1548 AfsClass_Leave();
1549 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteCreate, &wp, &status);
1550 AfsClass_Enter();
1553 // Clean up
1555 if (rc)
1557 LPAGGREGATE lpAggregate;
1558 if ((lpAggregate = lpiAggregate->OpenAggregate (&status)) == NULL)
1559 rc = FALSE;
1560 else
1562 lpAggregate->Invalidate();
1563 lpAggregate->RefreshFilesets (TRUE, &status);
1564 lpAggregate->Close();
1568 if (rc)
1570 LPCELL lpCell;
1571 if ((lpCell = lpiAggregate->OpenCell()) == NULL)
1572 rc = FALSE;
1573 else
1575 lpCell->RefreshVLDB (lpiAggregate);
1576 lpCell->Close();
1580 if (rc)
1582 LPFILESET lpFileset;
1583 if ((lpFileset = lpiFileset->OpenFileset (&status)) == NULL)
1584 rc = FALSE;
1585 else
1587 if ((lpiReplica = lpFileset->GetReadOnlyIdentifier (lpiAggregate, &status)) == NULL)
1588 rc = FALSE;
1589 lpFileset->Close();
1593 if (hVOS)
1595 if ((lpServer = lpiAggregate->OpenServer (&status)) != NULL)
1597 lpServer->CloseVosObject();
1598 lpServer->Close();
1602 NOTIFYCALLBACK::SendNotificationToAll (evtCreateReplicaEnd, lpiFileset, lpiAggregate, NULL, NULL, 0, status);
1603 AfsClass_Leave();
1605 if (pStatus && !rc)
1606 *pStatus = status;
1607 return (rc) ? lpiReplica : FALSE;
1611 BOOL AfsClass_DeleteReplica (LPIDENT lpiReplica, ULONG *pStatus)
1613 BOOL rc = TRUE;
1614 ULONG status;
1616 AfsClass_Enter();
1617 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetBegin, lpiReplica);
1619 // Obtain hCell and hVOS for the server
1621 PVOID hCell;
1622 PVOID hVOS = NULL;
1623 LPSERVER lpServer;
1624 if ((lpServer = lpiReplica->OpenServer (&status)) == NULL)
1625 rc = FALSE;
1626 else
1628 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
1629 rc = FALSE;
1630 lpServer->Close();
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)
1639 rc = FALSE;
1640 else
1642 wFilesetGhost = lpFileset->GetGhostStatus();
1643 if ((lpiRW = lpFileset->GetReadWriteIdentifier()) == NULL)
1644 rc = FALSE;
1645 lpFileset->Close();
1648 TCHAR szAggregateName[ cchNAME ];
1649 lpiReplica->GetAggregateName (szAggregateName);
1651 // Obtain the ID of the replica's partition
1653 int idPartition;
1654 LPAGGREGATE lpAggregate;
1655 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1656 rc = FALSE;
1657 else
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))
1667 WORKERPACKET wp;
1668 wp.wpVosVolumeDelete.hCell = hCell;
1669 wp.wpVosVolumeDelete.hServer = hVOS;
1670 wp.wpVosVolumeDelete.idPartition = idPartition;
1671 lpiReplica->GetFilesetID (&wp.wpVosVolumeDelete.idVolume);
1673 AfsClass_Leave();
1674 rc = Worker_DoTask (wtaskVosVolumeDelete, &wp, &status);
1675 AfsClass_Enter();
1677 else
1679 // If necessary, modify VLDB to remove mention of this replica
1681 if (rc && (wFilesetGhost & GHOST_HAS_VLDB_ENTRY))
1683 WORKERPACKET wp;
1684 wp.wpVosVLDBReadOnlySiteDelete.hCell = hCell;
1685 wp.wpVosVLDBReadOnlySiteDelete.hServer = hVOS;
1686 wp.wpVosVLDBReadOnlySiteDelete.idPartition = idPartition;
1687 lpiRW->GetFilesetID (&wp.wpVosVLDBReadOnlySiteDelete.idVolume);
1689 AfsClass_Leave();
1690 rc = Worker_DoTask (wtaskVosVLDBReadOnlySiteDelete, &wp, &status);
1691 AfsClass_Enter();
1694 // If necessary, zap the volume
1696 if (rc && (wFilesetGhost & GHOST_HAS_SERVER_ENTRY))
1698 WORKERPACKET wp;
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;
1705 AfsClass_Leave();
1706 rc = Worker_DoTask (wtaskVosVolumeZap, &wp, &status);
1707 AfsClass_Enter();
1711 // Clean up
1713 if (rc)
1715 LPAGGREGATE lpAggregate;
1716 if ((lpAggregate = lpiReplica->OpenAggregate (&status)) == NULL)
1717 rc = FALSE;
1718 else
1720 lpAggregate->Invalidate();
1721 lpAggregate->RefreshFilesets (TRUE, &status);
1722 lpAggregate->Close();
1726 if (rc)
1728 LPCELL lpCell;
1729 if ((lpCell = lpiReplica->OpenCell()) == NULL)
1730 rc = FALSE;
1731 else
1733 lpCell->RefreshVLDB (lpiReplica->GetAggregate());
1734 lpCell->Close();
1738 if (hVOS)
1740 if ((lpServer = lpiReplica->OpenServer (&status)) != NULL)
1742 lpServer->CloseVosObject();
1743 lpServer->Close();
1747 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteFilesetEnd, lpiReplica, status);
1748 AfsClass_Leave();
1750 if (pStatus && !rc)
1751 *pStatus = status;
1752 return rc;
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)
1764 BOOL rc = TRUE;
1765 ULONG status;
1767 AfsClass_Enter();
1768 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileBegin, lpiServer, pszSource, 0);
1770 PVOID hCell;
1771 PVOID hBOS;
1772 LPSERVER lpServer;
1773 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1774 rc = FALSE;
1775 else
1777 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1778 rc = FALSE;
1779 lpServer->Close();
1782 if (rc)
1784 WORKERPACKET wp;
1785 wp.wpBosExecutableCreate.hServer = hBOS;
1786 wp.wpBosExecutableCreate.pszLocal = pszSource;
1787 wp.wpBosExecutableCreate.pszRemoteDir = pszTarget;
1789 AfsClass_Leave();
1790 rc = Worker_DoTask (wtaskBosExecutableCreate, &wp, &status);
1791 AfsClass_Enter();
1794 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1796 lpServer->CloseBosObject();
1797 lpServer->Close();
1800 NOTIFYCALLBACK::SendNotificationToAll (evtInstallFileEnd, lpiServer, pszSource, status);
1801 AfsClass_Leave();
1803 if (pStatus && !rc)
1804 *pStatus = status;
1805 return rc;
1809 BOOL AfsClass_UninstallFile (LPIDENT lpiServer, LPTSTR pszUninstall, ULONG *pStatus)
1811 BOOL rc = TRUE;
1812 ULONG status;
1814 AfsClass_Enter();
1815 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileBegin, lpiServer, pszUninstall, 0);
1817 PVOID hCell;
1818 PVOID hBOS;
1819 LPSERVER lpServer;
1820 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1821 rc = FALSE;
1822 else
1824 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1825 rc = FALSE;
1826 lpServer->Close();
1829 if (rc)
1831 WORKERPACKET wp;
1832 wp.wpBosExecutableRevert.hServer = hBOS;
1833 wp.wpBosExecutableRevert.pszFilename = pszUninstall;
1835 AfsClass_Leave();
1836 rc = Worker_DoTask (wtaskBosExecutableRevert, &wp, &status);
1837 AfsClass_Enter();
1840 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1842 lpServer->CloseBosObject();
1843 lpServer->Close();
1846 NOTIFYCALLBACK::SendNotificationToAll (evtUninstallFileEnd, lpiServer, pszUninstall, status);
1847 AfsClass_Leave();
1849 if (pStatus && !rc)
1850 *pStatus = status;
1851 return rc;
1855 BOOL AfsClass_PruneOldFiles (LPIDENT lpiServer, BOOL fBAK, BOOL fOLD, BOOL fCore, ULONG *pStatus)
1857 BOOL rc = TRUE;
1858 ULONG status;
1860 AfsClass_Enter();
1861 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesBegin, lpiServer);
1863 PVOID hCell;
1864 PVOID hBOS;
1865 LPSERVER lpServer;
1866 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1867 rc = FALSE;
1868 else
1870 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1871 rc = FALSE;
1872 lpServer->Close();
1875 if (rc)
1877 WORKERPACKET wp;
1878 wp.wpBosExecutablePrune.hServer = hBOS;
1879 wp.wpBosExecutablePrune.fPruneBak = fBAK;
1880 wp.wpBosExecutablePrune.fPruneOld = fOLD;
1881 wp.wpBosExecutablePrune.fPruneCore = fCore;
1883 AfsClass_Leave();
1884 rc = Worker_DoTask (wtaskBosExecutablePrune, &wp, &status);
1885 AfsClass_Enter();
1888 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
1890 lpServer->CloseBosObject();
1891 lpServer->Close();
1894 NOTIFYCALLBACK::SendNotificationToAll (evtPruneFilesEnd, lpiServer, status);
1895 AfsClass_Leave();
1897 if (pStatus && !rc)
1898 *pStatus = status;
1899 return rc;
1903 BOOL AfsClass_RenameFileset (LPIDENT lpiFileset, LPTSTR pszNewName, ULONG *pStatus)
1905 BOOL rc = TRUE;
1906 ULONG status;
1908 AfsClass_Enter();
1909 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetBegin, lpiFileset, pszNewName, 0);
1911 PVOID hCell;
1912 LPCELL lpCell;
1913 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1914 rc = FALSE;
1915 else
1917 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
1918 rc = FALSE;
1919 lpCell->Close();
1922 if (rc)
1924 WORKERPACKET wp;
1925 wp.wpVosVolumeRename.hCell = hCell;
1926 lpiFileset->GetFilesetID (&wp.wpVosVolumeRename.idVolume);
1927 wp.wpVosVolumeRename.pszVolume = pszNewName;
1929 AfsClass_Leave();
1930 rc = Worker_DoTask (wtaskVosVolumeRename, &wp, &status);
1931 AfsClass_Enter();
1934 if (rc)
1936 LPCELL lpCell;
1937 if ((lpCell = lpiFileset->OpenCell (&status)) == NULL)
1938 rc = FALSE;
1939 else
1941 lpCell->Invalidate();
1942 rc = lpCell->RefreshAll (&status);
1943 lpCell->Close();
1948 NOTIFYCALLBACK::SendNotificationToAll (evtRenameFilesetEnd, lpiFileset, pszNewName, status);
1949 AfsClass_Leave();
1951 if (pStatus && !rc)
1952 *pStatus = status;
1953 return rc;
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)
1961 BOOL rc = TRUE;
1962 ULONG status;
1963 LPIDENT lpiService = NULL;
1965 AfsClass_Enter();
1966 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceBegin, lpiServer, pszService, 0);
1968 PVOID hCell;
1969 PVOID hBOS;
1970 LPSERVER lpServer;
1971 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
1972 rc = FALSE;
1973 else
1975 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
1976 rc = FALSE;
1977 lpServer->Close();
1980 if (rc)
1982 WORKERPACKET wp;
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);
1997 else
1998 wp.wpBosProcessCreate.pszTimeCron = NULL;
2000 AfsClass_Leave();
2001 rc = Worker_DoTask (wtaskBosProcessCreate, &wp, &status);
2002 AfsClass_Enter();
2005 if (rc)
2007 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2008 rc = FALSE;
2009 else
2011 lpServer->InvalidateServices();
2012 if (!lpServer->RefreshServices (TRUE, &status))
2013 rc = FALSE;
2014 else
2016 LPSERVICE lpService;
2017 if ((lpService = lpServer->OpenService (pszService, &status)) == NULL)
2018 rc = FALSE;
2019 else
2021 lpiService = lpService->GetIdentifier();
2022 lpService->Close();
2025 lpServer->Close();
2029 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2031 lpServer->CloseBosObject();
2032 lpServer->Close();
2035 NOTIFYCALLBACK::SendNotificationToAll (evtCreateServiceEnd, lpiServer, pszService, status);
2036 AfsClass_Leave();
2038 if (pStatus && !rc)
2039 *pStatus = status;
2040 return (rc) ? lpiService : NULL;
2044 BOOL AfsClass_DeleteService (LPIDENT lpiService, ULONG *pStatus)
2046 BOOL rc = TRUE;
2047 ULONG status;
2049 AfsClass_Enter();
2050 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceBegin, lpiService);
2052 PVOID hCell;
2053 PVOID hBOS;
2054 LPSERVER lpServer;
2055 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2056 rc = FALSE;
2057 else
2059 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2060 rc = FALSE;
2061 lpServer->Close();
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
2067 // was deleted).
2069 if (rc)
2071 TCHAR szService[ cchNAME ];
2072 lpiService->GetServiceName (szService);
2074 WORKERPACKET wp;
2075 wp.wpBosProcessExecutionStateSet.hServer = hBOS;
2076 wp.wpBosProcessExecutionStateSet.pszService = szService;
2077 wp.wpBosProcessExecutionStateSet.state = SERVICESTATE_STOPPED;
2078 // TODO: wp.wpStopBosProcess.fWait = TRUE;
2080 AfsClass_Leave();
2081 rc = Worker_DoTask (wtaskBosProcessExecutionStateSet, &wp, &status);
2082 AfsClass_Enter();
2085 // Delete the service
2087 if (rc)
2089 TCHAR szService[ cchNAME ];
2090 lpiService->GetServiceName (szService);
2092 WORKERPACKET wp;
2093 wp.wpBosProcessDelete.hServer = hBOS;
2094 wp.wpBosProcessDelete.pszService = szService;
2096 AfsClass_Leave();
2097 rc = Worker_DoTask (wtaskBosProcessDelete, &wp, &status);
2098 AfsClass_Enter();
2101 if (rc)
2103 if ((lpServer = lpiService->OpenServer (&status)) == NULL)
2104 rc = FALSE;
2105 else
2107 lpServer->InvalidateServices();
2108 if (!lpServer->RefreshServices (TRUE, &status))
2109 rc = FALSE;
2110 lpServer->Close();
2114 if ((lpServer = lpiService->OpenServer (&status)) != NULL)
2116 lpServer->CloseBosObject();
2117 lpServer->Close();
2120 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteServiceEnd, lpiService, status);
2121 AfsClass_Leave();
2123 if (pStatus && !rc)
2124 *pStatus = status;
2125 return rc;
2129 BOOL AfsClass_ReleaseFileset (LPIDENT lpiFilesetRW, BOOL fForce, ULONG *pStatus)
2131 BOOL rc = TRUE;
2132 ULONG status;
2134 AfsClass_Enter();
2135 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetBegin, lpiFilesetRW);
2137 // Obtain hCell and hVOS
2139 PVOID hCell;
2140 PVOID hVOS = NULL;
2141 LPSERVER lpServer;
2142 if ((lpServer = lpiFilesetRW->OpenServer (&status)) == NULL)
2143 rc = FALSE;
2144 else
2146 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2147 rc = FALSE;
2148 lpServer->Close();
2151 // Perform the actual operation
2153 if (rc)
2155 WORKERPACKET wp;
2156 wp.wpVosVolumeRelease.hCell = hCell;
2157 wp.wpVosVolumeRelease.fForce = fForce;
2158 lpiFilesetRW->GetFilesetID (&wp.wpVosVolumeRelease.idVolume);
2160 AfsClass_Leave();
2161 rc = Worker_DoTask (wtaskVosVolumeRelease, &wp, &status);
2162 AfsClass_Enter();
2165 // Clean up
2167 if (rc)
2169 LPCELL lpCell;
2170 if ((lpCell = lpiFilesetRW->OpenCell (&status)) == NULL)
2171 rc = FALSE;
2172 else
2174 lpCell->Invalidate();
2175 rc = lpCell->RefreshAll (&status);
2176 lpCell->Close();
2180 if (hVOS)
2182 if ((lpServer = lpiFilesetRW->OpenServer (&status)) != NULL)
2184 lpServer->CloseVosObject();
2185 lpServer->Close();
2189 NOTIFYCALLBACK::SendNotificationToAll (evtReleaseFilesetEnd, lpiFilesetRW, status);
2190 AfsClass_Leave();
2192 if (pStatus && !rc)
2193 *pStatus = status;
2194 return rc;
2198 BOOL AfsClass_GetFileDates (LPIDENT lpiServer, LPTSTR pszFilename, SYSTEMTIME *pstFile, SYSTEMTIME *pstBAK, SYSTEMTIME *pstOLD, ULONG *pStatus)
2200 BOOL rc = TRUE;
2201 ULONG status;
2203 AfsClass_Enter();
2204 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesBegin, lpiServer, pszFilename, 0);
2206 PVOID hCell;
2207 PVOID hBOS;
2208 LPSERVER lpServer;
2209 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2210 rc = FALSE;
2211 else
2213 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2214 rc = FALSE;
2215 lpServer->Close();
2218 if (rc)
2220 WORKERPACKET wp;
2221 wp.wpBosExecutableTimestampGet.hServer = hBOS;
2222 wp.wpBosExecutableTimestampGet.pszFilename = pszFilename;
2224 AfsClass_Leave();
2225 if ((rc = Worker_DoTask (wtaskBosExecutableTimestampGet, &wp, &status)) == TRUE)
2227 *pstFile = wp.wpBosExecutableTimestampGet.timeNew;
2228 *pstBAK = wp.wpBosExecutableTimestampGet.timeBak;
2229 *pstOLD = wp.wpBosExecutableTimestampGet.timeOld;
2232 AfsClass_Enter();
2235 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2237 lpServer->CloseBosObject();
2238 lpServer->Close();
2241 NOTIFYCALLBACK::SendNotificationToAll (evtGetFileDatesEnd, lpiServer, pszFilename, status);
2242 AfsClass_Leave();
2244 if (pStatus && !rc)
2245 *pStatus = status;
2246 return rc;
2250 BOOL AfsClass_ExecuteCommand (LPIDENT lpiServer, LPTSTR pszCommand, ULONG *pStatus)
2252 BOOL rc = TRUE;
2253 ULONG status;
2255 AfsClass_Enter();
2256 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandBegin, lpiServer, pszCommand, 0);
2258 PVOID hCell;
2259 PVOID hBOS;
2260 LPSERVER lpServer;
2261 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2262 rc = FALSE;
2263 else
2265 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2266 rc = FALSE;
2267 lpServer->Close();
2270 if (rc)
2272 WORKERPACKET wp;
2273 wp.wpBosCommandExecute.hServer = hBOS;
2274 wp.wpBosCommandExecute.pszCommand = pszCommand;
2276 AfsClass_Leave();
2277 rc = Worker_DoTask (wtaskBosCommandExecute, &wp, &status);
2278 AfsClass_Enter();
2281 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
2283 lpServer->CloseBosObject();
2284 lpServer->Close();
2287 NOTIFYCALLBACK::SendNotificationToAll (evtExecuteCommandEnd, lpiServer, pszCommand, status);
2288 AfsClass_Leave();
2290 if (pStatus && !rc)
2291 *pStatus = status;
2292 return rc;
2296 LPADMINLIST AfsClass_AdminList_Load (LPIDENT lpiServer, ULONG *pStatus)
2298 BOOL rc = TRUE;
2299 ULONG status;
2300 LPADMINLIST lpList = NULL;
2302 AfsClass_Enter();
2303 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadBegin, lpiServer);
2305 PVOID hCell;
2306 PVOID hBOS;
2307 LPSERVER lpServer;
2308 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2309 rc = FALSE;
2310 else
2312 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2313 rc = FALSE;
2314 lpServer->Close();
2317 if (rc)
2319 lpList = New(ADMINLIST);
2320 memset (lpList, 0x00, sizeof(ADMINLIST));
2321 lpList->cRef = 1;
2322 lpList->lpiServer = lpiServer;
2324 WORKERPACKET wpBegin;
2325 wpBegin.wpBosAdminGetBegin.hServer = hBOS;
2326 if (!Worker_DoTask (wtaskBosAdminGetBegin, &wpBegin, &status))
2327 rc = FALSE;
2328 else
2330 for (;;)
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)
2341 status = 0;
2342 else
2343 rc = FALSE;
2344 break;
2347 size_t iAdded;
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();
2363 lpServer->Close();
2366 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListLoadEnd, lpiServer, status);
2367 AfsClass_Leave();
2369 if (pStatus && !rc)
2370 *pStatus = status;
2371 return (rc) ? lpList : NULL;
2375 LPADMINLIST AfsClass_AdminList_Copy (LPADMINLIST lpOld)
2377 LPADMINLIST lpNew = NULL;
2379 if (lpOld)
2381 lpNew = New(ADMINLIST);
2382 memcpy (lpNew, lpOld, sizeof(ADMINLIST));
2384 lpNew->cRef = 1;
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);
2395 return lpNew;
2399 BOOL AfsClass_AdminList_Save (LPADMINLIST lpList, ULONG *pStatus)
2401 BOOL rc = TRUE;
2402 ULONG status;
2404 AfsClass_Enter();
2405 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveBegin, lpList->lpiServer);
2407 PVOID hCell;
2408 PVOID hBOS;
2409 LPSERVER lpServer;
2410 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
2411 rc = FALSE;
2412 else
2414 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2415 rc = FALSE;
2416 lpServer->Close();
2419 if (rc)
2421 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2423 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2424 continue;
2426 // are we supposed to add this entry?
2428 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
2430 WORKERPACKET wp;
2431 wp.wpBosAdminCreate.hServer = hBOS;
2432 wp.wpBosAdminCreate.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2434 ULONG thisstatus;
2435 if (!Worker_DoTask (wtaskBosAdminCreate, &wp, &thisstatus))
2437 rc = FALSE;
2438 status = thisstatus;
2440 else
2442 lpList->aEntries[ iEntry ].fAdded = FALSE;
2446 // are we supposed to delete this entry?
2448 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
2450 WORKERPACKET wp;
2451 wp.wpBosAdminDelete.hServer = hBOS;
2452 wp.wpBosAdminDelete.pszAdmin = lpList->aEntries[ iEntry ].szAdmin;
2454 ULONG thisstatus;
2455 if (!Worker_DoTask (wtaskBosAdminDelete, &wp, &thisstatus))
2457 rc = FALSE;
2458 status = thisstatus;
2460 else
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();
2472 lpServer->Close();
2475 NOTIFYCALLBACK::SendNotificationToAll (evtAdminListSaveEnd, lpList->lpiServer, status);
2476 AfsClass_Leave();
2478 if (pStatus && !rc)
2479 *pStatus = status;
2480 return rc;
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));
2491 Delete (lpList);
2496 size_t AfsClass_AdminList_AddEntry (LPADMINLIST lpList, LPTSTR pszAdmin)
2498 size_t iAdded = (size_t)-1;
2500 if (lpList)
2502 size_t iEntry;
2503 for (iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
2505 if (!lpList->aEntries[ iEntry ].szAdmin[0])
2506 break;
2508 if (iEntry >= lpList->cEntries)
2510 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_ADMINLISTENTRIES);
2512 if (iEntry < lpList->cEntries)
2514 iAdded = iEntry;
2515 lstrcpy (lpList->aEntries[ iAdded ].szAdmin, pszAdmin);
2516 lpList->aEntries[ iAdded ].fAdded = TRUE;
2517 lpList->aEntries[ iAdded ].fDeleted = FALSE;
2521 return iAdded;
2525 BOOL AfsClass_AdminList_DelEntry (LPADMINLIST lpList, size_t iIndex)
2527 BOOL rc = FALSE;
2529 if ( lpList &&
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');
2536 else
2537 lpList->aEntries[ iIndex ].fDeleted = TRUE;
2539 rc = TRUE;
2542 return rc;
2546 LPKEYLIST AfsClass_KeyList_Load (LPIDENT lpiServer, ULONG *pStatus)
2548 BOOL rc = TRUE;
2549 ULONG status;
2550 LPKEYLIST lpList = NULL;
2552 AfsClass_Enter();
2553 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadBegin, lpiServer);
2555 PVOID hCell;
2556 PVOID hBOS;
2557 LPSERVER lpServer;
2558 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2559 rc = FALSE;
2560 else
2562 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2563 rc = FALSE;
2564 lpServer->Close();
2567 if (rc)
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))
2576 rc = FALSE;
2577 else
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)
2587 status = 0;
2588 else
2589 rc = FALSE;
2590 break;
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();
2610 lpServer->Close();
2613 NOTIFYCALLBACK::SendNotificationToAll (evtKeyListLoadEnd, lpiServer, status);
2614 AfsClass_Leave();
2616 if (pStatus && !rc)
2617 *pStatus = status;
2618 return (rc) ? lpList : NULL;
2622 void AfsClass_KeyList_Free (LPKEYLIST lpList)
2624 if (lpList)
2626 if (lpList->aKeys)
2627 Free (lpList->aKeys);
2628 memset (lpList, 0x00, sizeof(KEYLIST));
2629 Delete (lpList);
2634 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPTSTR pszString, ULONG *pStatus)
2636 BOOL rc = TRUE;
2637 ULONG status = 0;
2639 TCHAR szCell[ cchNAME ];
2640 lpiServer->GetCellName (szCell);
2642 WORKERPACKET wp;
2643 wp.wpKasStringToKey.pszCell = szCell;
2644 wp.wpKasStringToKey.pszString = pszString;
2645 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
2647 rc = FALSE;
2649 else if (!AfsClass_AddKey (lpiServer, keyVersion, &wp.wpKasStringToKey.key, &status))
2651 rc = FALSE;
2654 if (pStatus && !rc)
2655 *pStatus = status;
2656 return rc;
2660 BOOL AfsClass_AddKey (LPIDENT lpiServer, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2662 BOOL rc = TRUE;
2663 ULONG status = 0;
2665 PVOID hCell;
2666 PVOID hBOS;
2667 LPSERVER lpServer;
2668 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2669 rc = FALSE;
2670 else
2672 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2673 rc = FALSE;
2674 lpServer->Close();
2677 if (rc)
2679 WORKERPACKET wp;
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();
2689 lpServer->Close();
2692 if (pStatus && !rc)
2693 *pStatus = status;
2694 return rc;
2698 BOOL AfsClass_DeleteKey (LPIDENT lpiServer, int keyVersion, ULONG *pStatus)
2700 BOOL rc = TRUE;
2701 ULONG status = 0;
2703 PVOID hCell;
2704 PVOID hBOS;
2705 LPSERVER lpServer;
2706 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
2707 rc = FALSE;
2708 else
2710 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
2711 rc = FALSE;
2712 lpServer->Close();
2715 if (rc)
2717 WORKERPACKET wp;
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();
2726 lpServer->Close();
2729 if (pStatus && !rc)
2730 *pStatus = status;
2731 return rc;
2735 BOOL AfsClass_GetRandomKey (LPIDENT lpi, LPENCRYPTIONKEY pKey, ULONG *pStatus)
2737 BOOL rc = TRUE;
2738 ULONG status = 0;
2740 PVOID hCell;
2741 PVOID hKAS;
2742 LPCELL lpCell;
2743 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2744 rc = FALSE;
2745 else
2747 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2748 rc = FALSE;
2749 else
2750 hKAS = lpCell->GetKasObject (&status);
2751 lpCell->Close();
2754 if (rc)
2756 WORKERPACKET wp;
2757 wp.wpKasServerRandomKeyGet.hCell = hCell;
2758 wp.wpKasServerRandomKeyGet.hServer = hKAS;
2759 rc = Worker_DoTask (wtaskKasServerRandomKeyGet, &wp, &status);
2761 if (rc)
2762 memcpy (pKey, &wp.wpKasServerRandomKeyGet.key, sizeof(ENCRYPTIONKEY));
2765 if (pStatus && !rc)
2766 *pStatus = status;
2767 return rc;
2771 BOOL AfsClass_Clone (LPIDENT lpiRW, ULONG *pStatus)
2773 BOOL rc = TRUE;
2774 ULONG status;
2776 AfsClass_Enter();
2777 NOTIFYCALLBACK::SendNotificationToAll (evtCloneBegin, lpiRW, 0);
2779 // Obtain hCell
2781 PVOID hCell;
2782 LPCELL lpCell;
2783 if ((lpCell = lpiRW->OpenCell (&status)) == NULL)
2784 rc = FALSE;
2785 else
2787 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2788 rc = FALSE;
2789 lpCell->Close();
2792 // Perform the actual operation
2794 if (rc)
2796 WORKERPACKET wp;
2797 wp.wpVosBackupVolumeCreate.hCell = hCell;
2798 lpiRW->GetFilesetID (&wp.wpVosBackupVolumeCreate.idVolume);
2800 AfsClass_Leave();
2801 rc = Worker_DoTask (wtaskVosBackupVolumeCreate, &wp, &status);
2802 AfsClass_Enter();
2805 // Clean up
2807 if (rc)
2809 LPSERVER lpServer;
2810 if ((lpServer = lpiRW->OpenServer (&status)) == NULL)
2811 rc = FALSE;
2812 else
2814 lpServer->Invalidate();
2815 rc = lpServer->RefreshAll (&status);
2816 lpServer->Close();
2820 NOTIFYCALLBACK::SendNotificationToAll (evtCloneEnd, lpiRW, status);
2821 AfsClass_Leave();
2823 if (pStatus && !rc)
2824 *pStatus = status;
2825 return rc;
2829 BOOL AfsClass_CloneMultiple (LPIDENT lpi, LPTSTR pszPrefix, BOOL fExclude, ULONG *pStatus)
2831 BOOL rc = TRUE;
2832 ULONG status;
2834 AfsClass_Enter();
2835 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleBegin, lpi);
2837 // Obtain hCell
2839 PVOID hCell;
2840 LPCELL lpCell;
2841 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2842 rc = FALSE;
2843 else
2845 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
2846 rc = FALSE;
2847 lpCell->Close();
2850 // Obtain hServer if appropriate
2852 PVOID hVOS = NULL;
2853 if (!lpi->fIsCell())
2855 LPSERVER lpServer;
2856 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2857 rc = FALSE;
2858 else
2860 if ((hVOS = lpServer->OpenVosObject (NULL, &status)) == NULL)
2861 rc = FALSE;
2862 lpServer->Close();
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)
2873 rc = FALSE;
2874 else
2876 if ((idPartition = lpAggregate->GetID()) == NO_PARTITION)
2877 rc = FALSE;
2878 lpAggregate->Close();
2882 // Perform the actual operation
2884 if (rc)
2886 WORKERPACKET wp;
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;
2893 AfsClass_Leave();
2894 rc = Worker_DoTask (wtaskVosBackupVolumeCreateMultiple, &wp, &status);
2895 AfsClass_Enter();
2898 // Clean up
2900 if (rc)
2902 if (lpi->fIsCell())
2904 LPCELL lpCell;
2905 if ((lpCell = lpi->OpenCell (&status)) == NULL)
2906 rc = FALSE;
2907 else
2909 lpCell->Invalidate();
2910 rc = lpCell->RefreshAll (&status);
2911 lpCell->Close();
2914 else
2916 LPSERVER lpServer;
2917 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2918 rc = FALSE;
2919 else
2921 lpServer->Invalidate();
2922 rc = lpServer->RefreshAll (&status);
2923 lpServer->Close();
2928 if (hVOS)
2930 LPSERVER lpServer;
2931 if ((lpServer = lpi->OpenServer (&status)) != NULL)
2933 lpServer->CloseVosObject();
2934 lpServer->Close();
2938 NOTIFYCALLBACK::SendNotificationToAll (evtCloneMultipleEnd, lpi, status);
2939 AfsClass_Leave();
2941 if (pStatus && !rc)
2942 *pStatus = status;
2943 return rc;
2947 BOOL AfsClass_DumpFileset (LPIDENT lpi, LPTSTR pszFilename, LPSYSTEMTIME pstDate, ULONG *pStatus)
2949 BOOL rc = TRUE;
2950 ULONG status;
2952 AfsClass_Enter();
2953 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetBegin, lpi, pszFilename, 0);
2955 // Obtain hCell and hVOS
2957 PVOID hCell;
2958 PVOID hVOS = NULL;
2959 LPSERVER lpServer;
2960 if ((lpServer = lpi->OpenServer (&status)) == NULL)
2961 rc = FALSE;
2962 else
2964 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
2965 rc = FALSE;
2966 lpServer->Close();
2969 // Obtain idPartition
2971 int idPartition;
2972 LPAGGREGATE lpAggregate;
2973 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
2974 rc = FALSE;
2975 else
2977 idPartition = lpAggregate->GetID();
2978 lpAggregate->Close();
2981 // Perform the actual operation
2983 if (rc)
2985 WORKERPACKET wp;
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);
2992 if (pstDate)
2993 memcpy (&wp.wpVosVolumeDump.stStart, pstDate, sizeof(SYSTEMTIME));
2994 else
2995 memset (&wp.wpVosVolumeDump.stStart, 0x00, sizeof(SYSTEMTIME));
2997 AfsClass_Leave();
2998 rc = Worker_DoTask (wtaskVosVolumeDump, &wp, &status);
2999 AfsClass_Enter();
3002 NOTIFYCALLBACK::SendNotificationToAll (evtDumpFilesetEnd, lpi, pszFilename, status);
3003 AfsClass_Leave();
3005 if (hVOS)
3007 LPSERVER lpServer;
3008 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3010 lpServer->CloseVosObject();
3011 lpServer->Close();
3015 if (pStatus && !rc)
3016 *pStatus = status;
3017 return rc;
3021 BOOL AfsClass_RestoreFileset (LPIDENT lpi, LPTSTR pszFileset, LPTSTR pszFilename, BOOL fIncremental, ULONG *pStatus)
3023 BOOL rc = TRUE;
3024 ULONG status;
3026 AfsClass_Enter();
3027 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetBegin, lpi, NULL, pszFileset, pszFilename, 0, 0);
3029 // Obtain hCell and hVOS
3031 PVOID hCell;
3032 PVOID hVOS = NULL;
3033 LPSERVER lpServer;
3034 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3035 rc = FALSE;
3036 else
3038 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
3039 rc = FALSE;
3040 lpServer->Close();
3043 // Obtain idPartition
3045 int idPartition;
3046 LPAGGREGATE lpAggregate;
3047 if ((lpAggregate = lpi->OpenAggregate (&status)) == NULL)
3048 rc = FALSE;
3049 else
3051 idPartition = lpAggregate->GetID();
3052 lpAggregate->Close();
3055 // Perform the actual operation
3057 if (rc)
3059 WORKERPACKET wp;
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);
3069 else
3070 wp.wpVosVolumeRestore.idVolume = NO_VOLUME;
3072 AfsClass_Leave();
3073 rc = Worker_DoTask (wtaskVosVolumeRestore, &wp, &status);
3074 AfsClass_Enter();
3077 // Clean up
3079 if (rc)
3081 if ((lpServer = lpi->OpenServer (&status)) == NULL)
3082 rc = FALSE;
3083 else
3085 lpServer->Invalidate();
3086 rc = lpServer->RefreshAll (&status);
3087 lpServer->Close();
3091 if (hVOS)
3093 if ((lpServer = lpi->OpenServer (&status)) != NULL)
3095 lpServer->CloseVosObject();
3096 lpServer->Close();
3100 NOTIFYCALLBACK::SendNotificationToAll (evtRestoreFilesetEnd, lpi, NULL, pszFileset, pszFilename, 0, status);
3101 AfsClass_Leave();
3103 if (pStatus && !rc)
3104 *pStatus = status;
3105 return rc;
3109 BOOL AfsClass_GetRestartTimes (LPIDENT lpiServer, BOOL *pfWeekly, LPSYSTEMTIME pstWeekly, BOOL *pfDaily, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3111 BOOL rc = TRUE;
3112 ULONG status;
3114 AfsClass_Enter();
3115 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesBegin, lpiServer);
3117 PVOID hCell;
3118 PVOID hBOS;
3119 LPSERVER lpServer;
3120 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3121 rc = FALSE;
3122 else
3124 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3125 rc = FALSE;
3126 lpServer->Close();
3129 if (rc)
3131 WORKERPACKET wp;
3132 wp.wpBosExecutableRestartTimeGet.hServer = hBOS;
3134 AfsClass_Leave();
3135 rc = Worker_DoTask (wtaskBosExecutableRestartTimeGet, &wp, &status);
3136 AfsClass_Enter();
3138 if (rc)
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();
3150 lpServer->Close();
3153 NOTIFYCALLBACK::SendNotificationToAll (evtGetRestartTimesEnd, lpiServer, status);
3154 AfsClass_Leave();
3156 if (pStatus && !rc)
3157 *pStatus = status;
3158 return rc;
3162 BOOL AfsClass_SetRestartTimes (LPIDENT lpiServer, LPSYSTEMTIME pstWeekly, LPSYSTEMTIME pstDaily, ULONG *pStatus)
3164 BOOL rc = TRUE;
3165 ULONG status;
3167 AfsClass_Enter();
3168 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesBegin, lpiServer);
3170 PVOID hCell;
3171 PVOID hBOS;
3172 LPSERVER lpServer;
3173 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3174 rc = FALSE;
3175 else
3177 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3178 rc = FALSE;
3179 lpServer->Close();
3182 if (rc)
3184 SYSTEMTIME timeNever;
3185 memset (&timeNever, 0x00, sizeof(SYSTEMTIME));
3187 WORKERPACKET wp;
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;
3194 AfsClass_Leave();
3195 rc = Worker_DoTask (wtaskBosExecutableRestartTimeSet, &wp, &status);
3196 AfsClass_Enter();
3199 if ((lpServer = lpiServer->OpenServer (&status)) != NULL)
3201 lpServer->CloseBosObject();
3202 lpServer->Close();
3205 NOTIFYCALLBACK::SendNotificationToAll (evtSetRestartTimesEnd, lpiServer, status);
3206 AfsClass_Leave();
3208 if (pStatus && !rc)
3209 *pStatus = status;
3210 return rc;
3214 BOOL AfsClass_MoveReplica (LPIDENT lpiReplica, LPIDENT lpiAggregateTarget, ULONG *pStatus)
3216 BOOL rc = TRUE;
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)
3223 rc = FALSE;
3224 else
3226 if ((lpiFilesetRW = lpFileset->GetReadWriteIdentifier (pStatus)) == NULL)
3227 rc = FALSE;
3228 lpFileset->Close();
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
3243 if (rc)
3245 LPIDENT lpiReplicaNew;
3247 if (lpiReplica->GetServer() == lpiAggregateTarget->GetServer())
3249 LPIDENT lpiAggregateOriginal = lpiReplica->GetAggregate();
3251 if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3253 rc = FALSE;
3255 else if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3257 (void)AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateOriginal);
3258 rc = FALSE;
3261 else // different server?
3263 if ((lpiReplicaNew = AfsClass_CreateReplica (lpiFilesetRW, lpiAggregateTarget, pStatus)) == NULL)
3265 rc = FALSE;
3267 else if (!AfsClass_DeleteReplica (lpiReplica, pStatus))
3269 (void)AfsClass_DeleteReplica (lpiReplicaNew, pStatus);
3270 rc = FALSE;
3275 return rc;
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)
3281 BOOL rc = TRUE;
3282 ULONG status;
3284 AfsClass_Enter();
3285 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageBegin, lpiSalvage);
3287 PVOID hCell;
3288 PVOID hBOS;
3289 LPSERVER lpServer;
3290 if ((lpServer = lpiSalvage->OpenServer (&status)) == NULL)
3291 rc = FALSE;
3292 else
3294 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3295 rc = FALSE;
3296 lpServer->Close();
3299 if (ppszLogData)
3300 *ppszLogData = NULL;
3302 // Step one: perform the actual salvage. This will dump a log file onto
3303 // the target computer.
3305 if (rc)
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())
3319 VOLUMEID vid;
3320 lpiSalvage->GetFilesetID (&vid);
3321 wsprintf (szFileset, TEXT("%lu"), vid);
3322 pszFileset = szFileset;
3325 if (pszLogFile == NULL)
3326 pszLogFile = TEXT("SalvageLog");
3328 WORKERPACKET wp;
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;
3343 AfsClass_Leave();
3344 rc = Worker_DoTask (wtaskBosSalvage, &wp, &status);
3345 AfsClass_Enter();
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)
3354 WORKERPACKET wp;
3355 wp.wpBosLogGet.hServer = hBOS;
3356 wp.wpBosLogGet.pszLogName = pszLogFile;
3357 wp.wpBosLogGet.pszLogData = NULL;
3359 AfsClass_Leave();
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'))
3382 *pszOut++ = *pchIn;
3384 *pszOut++ = TEXT('\0');
3387 AfsClass_Enter();
3390 if ((lpServer = lpiSalvage->OpenServer (&status)) != NULL)
3392 lpServer->CloseBosObject();
3393 lpServer->Close();
3396 NOTIFYCALLBACK::SendNotificationToAll (evtSalvageEnd, lpiSalvage, status);
3397 AfsClass_Leave();
3399 if (pStatus && !rc)
3400 *pStatus = status;
3401 return rc;
3405 void AfsClass_FreeSalvageLog (LPTSTR pszLogData)
3407 if (pszLogData)
3408 Free (pszLogData);
3412 LPHOSTLIST AfsClass_HostList_Load (LPIDENT lpiServer, ULONG *pStatus)
3414 BOOL rc = TRUE;
3415 ULONG status;
3416 LPHOSTLIST lpList = NULL;
3418 AfsClass_Enter();
3419 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadBegin, lpiServer);
3421 PVOID hCell;
3422 PVOID hBOS;
3423 LPSERVER lpServer;
3424 if ((lpServer = lpiServer->OpenServer (&status)) == NULL)
3425 rc = FALSE;
3426 else
3428 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3429 rc = FALSE;
3430 lpServer->Close();
3433 if (rc)
3435 lpList = New(HOSTLIST);
3436 memset (lpList, 0x00, sizeof(HOSTLIST));
3437 lpList->cRef = 1;
3438 lpList->lpiServer = lpiServer;
3440 WORKERPACKET wpBegin;
3441 wpBegin.wpBosHostGetBegin.hServer = hBOS;
3442 if (!Worker_DoTask (wtaskBosHostGetBegin, &wpBegin, &status))
3443 rc = FALSE;
3444 else
3446 for (;;)
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)
3457 status = 0;
3458 else
3459 rc = FALSE;
3460 break;
3463 size_t iAdded;
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();
3479 lpServer->Close();
3482 NOTIFYCALLBACK::SendNotificationToAll (evtHostListLoadEnd, lpiServer, status);
3483 AfsClass_Leave();
3485 if (pStatus && !rc)
3486 *pStatus = status;
3487 return (rc) ? lpList : NULL;
3491 LPHOSTLIST AfsClass_HostList_Copy (LPHOSTLIST lpOld)
3493 LPHOSTLIST lpNew = NULL;
3495 if (lpOld)
3497 lpNew = New(HOSTLIST);
3498 memcpy (lpNew, lpOld, sizeof(HOSTLIST));
3500 lpNew->cRef = 1;
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);
3511 return lpNew;
3515 BOOL AfsClass_HostList_Save (LPHOSTLIST lpList, ULONG *pStatus)
3517 BOOL rc = TRUE;
3518 ULONG status;
3520 AfsClass_Enter();
3521 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveBegin, lpList->lpiServer);
3523 PVOID hCell;
3524 PVOID hBOS;
3525 LPSERVER lpServer;
3526 if ((lpServer = lpList->lpiServer->OpenServer (&status)) == NULL)
3527 rc = FALSE;
3528 else
3530 if ((hBOS = lpServer->OpenBosObject (&hCell, &status)) == NULL)
3531 rc = FALSE;
3532 lpServer->Close();
3535 if (rc)
3537 for (size_t iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3539 if (!lpList->aEntries[ iEntry ].szHost[0])
3540 continue;
3542 // are we supposed to add this entry?
3544 if (lpList->aEntries[ iEntry ].fAdded && !lpList->aEntries[ iEntry ].fDeleted)
3546 WORKERPACKET wp;
3547 wp.wpBosHostCreate.hServer = hBOS;
3548 wp.wpBosHostCreate.pszServer = lpList->aEntries[ iEntry ].szHost;
3550 ULONG thisstatus;
3551 if (!Worker_DoTask (wtaskBosHostCreate, &wp, &thisstatus))
3553 rc = FALSE;
3554 status = thisstatus;
3556 else
3558 lpList->aEntries[ iEntry ].fAdded = FALSE;
3562 // are we supposed to delete this entry?
3564 if (!lpList->aEntries[ iEntry ].fAdded && lpList->aEntries[ iEntry ].fDeleted)
3566 WORKERPACKET wp;
3567 wp.wpBosHostDelete.hServer = hBOS;
3568 wp.wpBosHostDelete.pszServer = lpList->aEntries[ iEntry ].szHost;
3570 ULONG thisstatus;
3571 if (!Worker_DoTask (wtaskBosHostDelete, &wp, &thisstatus))
3573 rc = FALSE;
3574 status = thisstatus;
3576 else
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();
3588 lpServer->Close();
3591 NOTIFYCALLBACK::SendNotificationToAll (evtHostListSaveEnd, lpList->lpiServer, status);
3592 AfsClass_Leave();
3594 if (pStatus && !rc)
3595 *pStatus = status;
3596 return rc;
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));
3607 Delete (lpList);
3612 size_t AfsClass_HostList_AddEntry (LPHOSTLIST lpList, LPTSTR pszHost)
3614 size_t iAdded = (size_t)-1;
3616 if (lpList)
3618 size_t iEntry;
3619 for (iEntry = 0; iEntry < lpList->cEntries; ++iEntry)
3621 if (!lpList->aEntries[ iEntry ].szHost[0])
3622 break;
3624 if (iEntry >= lpList->cEntries)
3626 (void)REALLOC (lpList->aEntries, lpList->cEntries, 1+iEntry, cREALLOC_HOSTLISTENTRIES);
3628 if (iEntry < lpList->cEntries)
3630 iAdded = iEntry;
3631 lstrcpy (lpList->aEntries[ iAdded ].szHost, pszHost);
3632 lpList->aEntries[ iAdded ].fAdded = TRUE;
3633 lpList->aEntries[ iAdded ].fDeleted = FALSE;
3637 return iAdded;
3641 BOOL AfsClass_HostList_DelEntry (LPHOSTLIST lpList, size_t iIndex)
3643 BOOL rc = FALSE;
3645 if ( lpList &&
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');
3652 else
3653 lpList->aEntries[ iIndex ].fDeleted = TRUE;
3655 rc = TRUE;
3658 return rc;
3662 BOOL AfsClass_GetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3664 BOOL rc = TRUE;
3665 ULONG status;
3667 memset (pProperties, 0x00, sizeof(PTSPROPERTIES));
3669 // Obtain hCell
3671 PVOID hCell;
3672 LPCELL lpCell;
3673 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3674 rc = FALSE;
3675 else
3677 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3678 rc = FALSE;
3679 lpCell->Close();
3682 // Go get the necessary properties
3684 if (rc)
3686 WORKERPACKET wp;
3687 wp.wpPtsUserMaxGet.hCell = hCell;
3689 if ((rc = Worker_DoTask (wtaskPtsUserMaxGet, &wp, &status)) == TRUE)
3690 pProperties->idUserMax = wp.wpPtsUserMaxGet.idUserMax;
3693 if (rc)
3695 WORKERPACKET wp;
3696 wp.wpPtsGroupMaxGet.hCell = hCell;
3698 if ((rc = Worker_DoTask (wtaskPtsGroupMaxGet, &wp, &status)) == TRUE)
3699 pProperties->idGroupMax = wp.wpPtsGroupMaxGet.idGroupMax;
3702 if (pStatus && !rc)
3703 *pStatus = status;
3704 return rc;
3708 BOOL AfsClass_SetPtsProperties (LPIDENT lpiCell, LPPTSPROPERTIES pProperties, ULONG *pStatus)
3710 BOOL rc = TRUE;
3711 ULONG status;
3713 // Obtain hCell
3715 PVOID hCell;
3716 LPCELL lpCell;
3717 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3718 rc = FALSE;
3719 else
3721 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3722 rc = FALSE;
3723 lpCell->Close();
3726 // Modify the specified properties
3728 if (rc)
3730 WORKERPACKET wp;
3731 wp.wpPtsUserMaxSet.hCell = hCell;
3732 wp.wpPtsUserMaxSet.idUserMax = pProperties->idUserMax;
3733 rc = Worker_DoTask (wtaskPtsUserMaxSet, &wp, &status);
3736 if (rc)
3738 WORKERPACKET wp;
3739 wp.wpPtsGroupMaxSet.hCell = hCell;
3740 wp.wpPtsGroupMaxSet.idGroupMax = pProperties->idGroupMax;
3741 Worker_DoTask (wtaskPtsGroupMaxSet, &wp, &status);
3744 if (pStatus && !rc)
3745 *pStatus = status;
3746 return rc;
3750 LPIDENT AfsClass_CreateUser (LPIDENT lpiCell, LPTSTR pszUserName, LPTSTR pszInstance, LPTSTR pszPassword, UINT_PTR idUser, BOOL fCreateKAS, BOOL fCreatePTS, ULONG *pStatus)
3752 BOOL rc = TRUE;
3753 ULONG status;
3755 if (pszInstance && !*pszInstance)
3756 pszInstance = NULL;
3758 AfsClass_Enter();
3759 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserBegin, lpiCell, pszUserName, 0);
3761 // We'll need both hCell and hKAS.
3763 PVOID hCell;
3764 PVOID hKAS;
3765 LPCELL lpCell;
3766 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3767 rc = FALSE;
3768 else
3770 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3771 rc = FALSE;
3772 else
3773 hKAS = lpCell->GetKasObject (&status);
3774 lpCell->Close();
3777 // First try to create a KAS entry.
3779 if (rc && fCreateKAS)
3781 WORKERPACKET wp;
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;
3788 AfsClass_Leave();
3789 rc = Worker_DoTask (wtaskKasPrincipalCreate, &wp, &status);
3790 AfsClass_Enter();
3793 // If that succeeded, try to create a PTS entry as well.
3795 if (rc && fCreatePTS)
3797 TCHAR szUserName[ cchNAME ];
3798 lstrcpy (szUserName, pszUserName);
3799 if (pszInstance)
3800 wsprintf (&szUserName[ lstrlen(szUserName) ], TEXT(".%s"), pszInstance);
3802 WORKERPACKET wp;
3803 wp.wpPtsUserCreate.hCell = hCell;
3804 wp.wpPtsUserCreate.pszUser = szUserName;
3805 wp.wpPtsUserCreate.idUser = (int) idUser;
3807 AfsClass_Leave();
3809 if ((rc = Worker_DoTask (wtaskPtsUserCreate, &wp, &status)) == FALSE)
3811 if (status == PREXIST)
3812 rc = TRUE;
3815 if (!rc)
3817 // If we couldn't make a KAS entry as well, remove the KAS entry.
3819 if (fCreateKAS)
3821 WORKERPACKET wpDel;
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);
3830 AfsClass_Enter();
3833 // If we were able to create the user's accounts successfully, refresh
3834 // the cell status and return the new user's ident.
3836 LPIDENT lpiUser;
3838 if (rc)
3840 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
3841 rc = FALSE;
3842 else
3844 if (!lpCell->RefreshAccount (pszUserName, pszInstance, CELL_REFRESH_ACCOUNT_CREATED_USER, &lpiUser))
3845 rc = FALSE;
3846 else if (!lpiUser)
3847 rc = FALSE;
3848 lpCell->Close();
3852 NOTIFYCALLBACK::SendNotificationToAll (evtCreateUserEnd, lpiCell, pszUserName, status);
3853 AfsClass_Leave();
3855 if (pStatus && !rc)
3856 *pStatus = status;
3857 return (rc) ? lpiUser : NULL;
3861 BOOL AfsClass_SetUserProperties (LPIDENT lpiUser, LPUSERPROPERTIES pProperties, ULONG *pStatus)
3863 BOOL rc = TRUE;
3864 ULONG status;
3866 AfsClass_Enter();
3867 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser);
3869 // We'll need both hCell and hKAS.
3871 PVOID hCell;
3872 PVOID hKAS;
3873 LPCELL lpCell;
3874 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
3875 rc = FALSE;
3876 else
3878 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
3879 rc = FALSE;
3880 else
3881 hKAS = lpCell->GetKasObject (&status);
3882 lpCell->Close();
3885 // We'll also need this user's current status
3887 LPUSER lpUser;
3888 USERSTATUS us;
3889 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
3890 rc = FALSE;
3891 else
3893 if (!lpUser->GetStatus (&us, TRUE, &status))
3894 rc = FALSE;
3895 lpUser->Close();
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);
3917 WORKERPACKET wp;
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;
3933 AfsClass_Leave();
3934 rc = Worker_DoTask (wtaskKasPrincipalFieldsSet, &wp, &status);
3935 AfsClass_Enter();
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);
3951 WORKERPACKET wp;
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 );
3970 AfsClass_Leave();
3971 rc = Worker_DoTask (wtaskPtsUserModify, &wp, &status);
3972 AfsClass_Enter();
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();
3982 lpUser->Close();
3985 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserBegin, lpiUser, status);
3986 AfsClass_Leave();
3988 if (pStatus && !rc)
3989 *pStatus = status;
3990 return rc;
3994 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPTSTR pszPassword, ULONG *pStatus)
3996 BOOL rc = TRUE;
3997 ULONG status = 0;
3999 TCHAR szCell[ cchNAME ];
4000 lpiUser->GetCellName (szCell);
4002 WORKERPACKET wp;
4003 wp.wpKasStringToKey.pszCell = szCell;
4004 wp.wpKasStringToKey.pszString = pszPassword;
4005 if (!Worker_DoTask (wtaskKasStringToKey, &wp, &status))
4007 rc = FALSE;
4009 else if (!AfsClass_SetUserPassword (lpiUser, keyVersion, &wp.wpKasStringToKey.key, &status))
4011 rc = FALSE;
4014 if (pStatus && !rc)
4015 *pStatus = status;
4016 return rc;
4020 BOOL AfsClass_SetUserPassword (LPIDENT lpiUser, int keyVersion, LPENCRYPTIONKEY pKey, ULONG *pStatus)
4022 BOOL rc = TRUE;
4023 ULONG status;
4025 AfsClass_Enter();
4026 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordBegin, lpiUser);
4028 // We'll need both hCell and hKAS.
4030 PVOID hCell;
4031 PVOID hKAS;
4032 LPCELL lpCell;
4033 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4034 rc = FALSE;
4035 else
4037 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4038 rc = FALSE;
4039 else
4040 hKAS = lpCell->GetKasObject (&status);
4041 lpCell->Close();
4044 // Change the user's password
4046 if (rc)
4048 TCHAR szPrincipal[ cchNAME ];
4049 TCHAR szInstance[ cchNAME ];
4050 lpiUser->GetUserName (szPrincipal, szInstance);
4052 WORKERPACKET wp;
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);
4060 AfsClass_Leave();
4061 rc = Worker_DoTask (wtaskKasPrincipalKeySet, &wp, &status);
4062 AfsClass_Enter();
4065 // If we were able to modify the user's password successfully, refresh
4066 // that user's status.
4068 LPUSER lpUser;
4069 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4071 lpUser->Invalidate();
4072 lpUser->RefreshStatus();
4073 lpUser->Close();
4076 NOTIFYCALLBACK::SendNotificationToAll (evtChangeUserPasswordEnd, lpiUser, status);
4077 AfsClass_Leave();
4079 if (pStatus && !rc)
4080 *pStatus = status;
4081 return rc;
4085 BOOL AfsClass_DeleteUser (LPIDENT lpiUser, BOOL fDeleteKAS, BOOL fDeletePTS, ULONG *pStatus)
4087 BOOL rc = TRUE;
4088 ULONG status;
4090 AfsClass_Enter();
4091 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserBegin, lpiUser);
4093 // We'll need both hCell and hKAS.
4095 PVOID hCell;
4096 PVOID hKAS;
4097 LPCELL lpCell;
4098 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4099 rc = FALSE;
4100 else
4102 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4103 rc = FALSE;
4104 else
4105 hKAS = lpCell->GetKasObject (&status);
4106 lpCell->Close();
4109 // Find out whether this user has KAS and/or PTS entries. Also
4110 // get the various lists of groups for this user...
4112 LPUSER lpUser;
4113 LPTSTR mszOwnerOf = NULL;
4114 LPTSTR mszMemberOf = NULL;
4115 if ((lpUser = lpiUser->OpenUser (&status)) == NULL)
4116 rc = FALSE;
4117 else
4119 lpUser->GetOwnerOf (&mszOwnerOf);
4120 lpUser->GetMemberOf (&mszMemberOf);
4121 lpUser->Close();
4124 // Delete the user's PTS entry
4126 if (rc && fDeletePTS)
4128 TCHAR szFullName[ cchNAME ];
4129 lpiUser->GetFullUserName (szFullName);
4131 WORKERPACKET wp;
4132 wp.wpPtsUserDelete.hCell = hCell;
4133 wp.wpPtsUserDelete.pszUser = szFullName;
4135 AfsClass_Leave();
4136 if ((rc = Worker_DoTask (wtaskPtsUserDelete, &wp, &status)) == FALSE)
4138 if (status == ADMPTSFAILEDNAMETRANSLATE) // User had no PTS entry?
4139 rc = TRUE;
4141 AfsClass_Enter();
4144 // Delete the user's KAS entry
4146 if (rc && fDeleteKAS)
4148 TCHAR szPrincipal[ cchNAME ];
4149 TCHAR szInstance[ cchNAME ];
4150 lpiUser->GetUserName (szPrincipal, szInstance);
4152 WORKERPACKET wp;
4153 wp.wpKasPrincipalDelete.hCell = hCell;
4154 wp.wpKasPrincipalDelete.hServer = hKAS;
4155 wp.wpKasPrincipalDelete.pszPrincipal = szPrincipal;
4156 wp.wpKasPrincipalDelete.pszInstance = szInstance;
4158 AfsClass_Leave();
4159 if ((rc = Worker_DoTask (wtaskKasPrincipalDelete, &wp, &status)) == FALSE)
4161 if (status == KANOENT)
4162 rc = TRUE;
4164 AfsClass_Enter();
4167 // If we were able to delete the user's accounts successfully, refresh
4168 // the cell status.
4170 if (rc)
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);
4181 lpCell->Close();
4185 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteUserEnd, lpiUser, status);
4186 AfsClass_Leave();
4188 if (mszOwnerOf)
4189 FreeString (mszOwnerOf);
4190 if (mszMemberOf)
4191 FreeString (mszMemberOf);
4192 if (pStatus && !rc)
4193 *pStatus = status;
4194 return rc;
4198 BOOL AfsClass_UnlockUser (LPIDENT lpiUser, ULONG *pStatus)
4200 BOOL rc = TRUE;
4201 ULONG status;
4203 AfsClass_Enter();
4204 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserBegin, lpiUser);
4206 // We'll need both hCell and hKAS.
4208 PVOID hCell;
4209 PVOID hKAS;
4210 LPCELL lpCell;
4211 if ((lpCell = lpiUser->OpenCell (&status)) == NULL)
4212 rc = FALSE;
4213 else
4215 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4216 rc = FALSE;
4217 else
4218 hKAS = lpCell->GetKasObject (&status);
4219 lpCell->Close();
4222 // Unlock the user's KAS entry
4224 if (rc)
4226 TCHAR szPrincipal[ cchNAME ];
4227 TCHAR szInstance[ cchNAME ];
4228 lpiUser->GetUserName (szPrincipal, szInstance);
4230 WORKERPACKET wp;
4231 wp.wpKasPrincipalUnlock.hCell = hCell;
4232 wp.wpKasPrincipalUnlock.hServer = hKAS;
4233 wp.wpKasPrincipalUnlock.pszPrincipal = szPrincipal;
4234 wp.wpKasPrincipalUnlock.pszInstance = szInstance;
4236 AfsClass_Leave();
4237 rc = Worker_DoTask (wtaskKasPrincipalUnlock, &wp, &status);
4238 AfsClass_Enter();
4241 // If we were able to unlock the user's accounts successfully, refresh
4242 // the user's properties.
4244 if (rc)
4246 LPUSER lpUser;
4247 if ((lpUser = lpiUser->OpenUser (&status)) != NULL)
4249 lpUser->Invalidate();
4250 lpUser->RefreshStatus();
4251 lpUser->Close();
4255 NOTIFYCALLBACK::SendNotificationToAll (evtUnlockUserEnd, lpiUser, status);
4256 AfsClass_Leave();
4258 if (pStatus && !rc)
4259 *pStatus = status;
4260 return rc;
4264 LPIDENT AfsClass_CreateGroup (LPIDENT lpiCell, LPTSTR pszGroupName, LPIDENT lpiOwner, int idGroup, ULONG *pStatus)
4266 BOOL rc = TRUE;
4267 ULONG status;
4269 AfsClass_Enter();
4270 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupBegin, lpiCell, pszGroupName, 0);
4272 // Obtain hCell
4274 PVOID hCell;
4275 LPCELL lpCell;
4276 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4277 rc = FALSE;
4278 else
4280 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4281 rc = FALSE;
4282 lpCell->Close();
4285 // Create a PTS entry for the new group
4287 if (rc)
4289 TCHAR szOwner[ cchNAME ] = TEXT("");
4290 if (lpiOwner && lpiOwner->fIsUser())
4291 lpiOwner->GetFullUserName (szOwner);
4292 else if (lpiOwner && lpiOwner->fIsGroup())
4293 lpiOwner->GetGroupName (szOwner);
4295 WORKERPACKET wp;
4296 wp.wpPtsGroupCreate.hCell = hCell;
4297 wp.wpPtsGroupCreate.pszGroup = pszGroupName;
4298 wp.wpPtsGroupCreate.pszOwner = (szOwner[0]) ? szOwner : NULL;
4299 wp.wpPtsGroupCreate.idGroup = idGroup;
4301 AfsClass_Leave();
4302 rc = Worker_DoTask (wtaskPtsGroupCreate, &wp, &status);
4303 AfsClass_Enter();
4306 // If we were able to create the group successfully, refresh
4307 // the cell status and return the new group's ident.
4309 LPIDENT lpiGroup;
4311 if (rc)
4313 if ((lpCell = lpiCell->OpenCell (&status)) == NULL)
4314 rc = FALSE;
4315 else
4317 if (!lpCell->RefreshAccount (pszGroupName, NULL, CELL_REFRESH_ACCOUNT_CREATED_GROUP, &lpiGroup))
4318 rc = FALSE;
4319 else if (!lpiGroup)
4320 rc = FALSE;
4321 lpCell->Close();
4325 NOTIFYCALLBACK::SendNotificationToAll (evtCreateGroupEnd, lpiCell, pszGroupName, status);
4326 AfsClass_Leave();
4328 if (pStatus && !rc)
4329 *pStatus = status;
4330 return (rc) ? lpiGroup : NULL;
4334 BOOL AfsClass_SetGroupProperties (LPIDENT lpiGroup, LPGROUPPROPERTIES pProperties, ULONG *pStatus)
4336 BOOL rc = TRUE;
4337 ULONG status;
4339 AfsClass_Enter();
4340 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup);
4342 // Obtain hCell
4344 PVOID hCell;
4345 LPCELL lpCell;
4346 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4347 rc = FALSE;
4348 else
4350 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4351 rc = FALSE;
4352 lpCell->Close();
4355 // We'll also need this group's current status
4357 LPPTSGROUP lpGroup;
4358 PTSGROUPSTATUS gs;
4359 if ((lpGroup = lpiGroup->OpenGroup (&status)) == NULL)
4360 rc = FALSE;
4361 else
4363 if (!lpGroup->GetStatus (&gs, TRUE, &status))
4364 rc = FALSE;
4365 lpGroup->Close();
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);
4381 WORKERPACKET wp;
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 );
4391 AfsClass_Leave();
4392 rc = Worker_DoTask (wtaskPtsGroupModify, &wp, &status);
4393 AfsClass_Enter();
4396 // Change the group's owner (if requested)
4398 if (rc && (pProperties->dwMask & MASK_GROUPPROP_szOwner))
4400 TCHAR szGroup[ cchNAME ];
4401 lpiGroup->GetGroupName (szGroup);
4403 WORKERPACKET wp;
4404 wp.wpPtsGroupOwnerChange.hCell = hCell;
4405 wp.wpPtsGroupOwnerChange.pszGroup = szGroup;
4406 wp.wpPtsGroupOwnerChange.pszOwner = pProperties->szOwner;
4408 AfsClass_Leave();
4409 rc = Worker_DoTask (wtaskPtsGroupOwnerChange, &wp, &status);
4410 AfsClass_Enter();
4413 // If we were able to modify the group's properties successfully, refresh
4414 // either the group's status. If the group's owner changed, also refresh
4415 // the group's old and new owners.
4417 if (rc)
4419 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4421 TCHAR szAccount[ cchNAME ];
4422 lpiGroup->GetGroupName (szAccount);
4423 lpCell->RefreshAccount (szAccount, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4425 if (pProperties->dwMask & MASK_GROUPPROP_szOwner)
4427 lpCell->RefreshAccount (gs.szOwner, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4428 lpCell->RefreshAccount (pProperties->szOwner, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4431 lpCell->Close();
4435 NOTIFYCALLBACK::SendNotificationToAll (evtChangeGroupBegin, lpiGroup, status);
4436 AfsClass_Leave();
4438 if (pStatus && !rc)
4439 *pStatus = status;
4440 return rc;
4444 BOOL AfsClass_RenameGroup (LPIDENT lpiGroup, LPTSTR pszNewName, ULONG *pStatus)
4446 BOOL rc = TRUE;
4447 ULONG status;
4449 AfsClass_Enter();
4450 NOTIFYCALLBACK::SendNotificationToAll (evtRenameGroupBegin, lpiGroup);
4452 // Obtain hCell
4454 PVOID hCell;
4455 LPCELL lpCell;
4456 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4457 rc = FALSE;
4458 else
4460 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4461 rc = FALSE;
4462 lpCell->Close();
4465 // Get this group's list of members (etc)
4467 LPTSTR mszOwnerOf = NULL;
4468 LPTSTR mszMemberOf = NULL;
4469 LPTSTR mszMembers = NULL;
4471 LPPTSGROUP lpGroup;
4472 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4474 lpGroup->GetOwnerOf (&mszOwnerOf);
4475 lpGroup->GetMemberOf (&mszMemberOf);
4476 lpGroup->GetMembers (&mszMembers);
4477 lpGroup->Close();
4480 // Rename the group's PTS entry
4482 if (rc)
4484 TCHAR szGroup[ cchNAME ];
4485 lpiGroup->GetGroupName (szGroup);
4487 WORKERPACKET wp;
4488 wp.wpPtsGroupRename.hCell = hCell;
4489 wp.wpPtsGroupRename.pszGroup = szGroup;
4490 wp.wpPtsGroupRename.pszNewName = pszNewName;
4492 AfsClass_Leave();
4493 rc = Worker_DoTask (wtaskPtsGroupRename, &wp, &status);
4494 AfsClass_Enter();
4497 // If we were able to rename the group successfully, refresh the cell status.
4499 if (rc)
4501 LPPTSGROUP lpGroup;
4502 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4504 lpGroup->ChangeIdentName (pszNewName);
4505 lpGroup->Close();
4507 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4509 lpCell->RefreshAccount (pszNewName, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4510 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4511 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4512 lpCell->RefreshAccounts (mszMembers, CELL_REFRESH_ACCOUNT_CHANGED);
4513 lpCell->Close();
4517 NOTIFYCALLBACK::SendNotificationToAll (evtRenameGroupEnd, lpiGroup, status);
4518 AfsClass_Leave();
4520 if (mszOwnerOf)
4521 FreeString (mszOwnerOf);
4522 if (mszMemberOf)
4523 FreeString (mszMemberOf);
4524 if (mszMembers)
4525 FreeString (mszMembers);
4526 if (pStatus && !rc)
4527 *pStatus = status;
4528 return rc;
4532 BOOL AfsClass_DeleteGroup (LPIDENT lpiGroup, ULONG *pStatus)
4534 BOOL rc = TRUE;
4535 ULONG status;
4537 AfsClass_Enter();
4538 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteGroupBegin, lpiGroup);
4540 // Obtain hCell
4542 PVOID hCell;
4543 LPCELL lpCell;
4544 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4545 rc = FALSE;
4546 else
4548 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4549 rc = FALSE;
4550 lpCell->Close();
4553 // Get this group's list of members (etc)
4555 LPTSTR mszOwnerOf = NULL;
4556 LPTSTR mszMemberOf = NULL;
4557 LPTSTR mszMembers = NULL;
4559 LPPTSGROUP lpGroup;
4560 if ((lpGroup = lpiGroup->OpenGroup (&status)) != NULL)
4562 lpGroup->GetOwnerOf (&mszOwnerOf);
4563 lpGroup->GetMemberOf (&mszMemberOf);
4564 lpGroup->GetMembers (&mszMembers);
4565 lpGroup->Close();
4568 // Delete the group's PTS entry
4570 if (rc)
4572 TCHAR szGroup[ cchNAME ];
4573 lpiGroup->GetGroupName (szGroup);
4575 WORKERPACKET wp;
4576 wp.wpPtsGroupDelete.hCell = hCell;
4577 wp.wpPtsGroupDelete.pszGroup = szGroup;
4579 AfsClass_Leave();
4580 if ((rc = Worker_DoTask (wtaskPtsGroupDelete, &wp, &status)) == FALSE)
4582 if (status == ADMPTSFAILEDNAMETRANSLATE) // Group had no PTS entry?
4583 rc = TRUE;
4585 AfsClass_Enter();
4588 // If we were able to delete the group successfully, refresh the cell status.
4590 if (rc)
4592 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4594 TCHAR szGroup[ cchNAME ];
4595 lpiGroup->GetGroupName (szGroup);
4596 lpCell->RefreshAccounts (mszOwnerOf, CELL_REFRESH_ACCOUNT_CHANGED);
4597 lpCell->RefreshAccounts (mszMemberOf, CELL_REFRESH_ACCOUNT_CHANGED);
4598 lpCell->RefreshAccounts (mszMembers, CELL_REFRESH_ACCOUNT_CHANGED);
4599 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_DELETED);
4600 lpCell->Close();
4604 NOTIFYCALLBACK::SendNotificationToAll (evtDeleteGroupEnd, lpiGroup, status);
4605 AfsClass_Leave();
4607 if (mszOwnerOf)
4608 FreeString (mszOwnerOf);
4609 if (mszMemberOf)
4610 FreeString (mszMemberOf);
4611 if (mszMembers)
4612 FreeString (mszMembers);
4613 if (pStatus && !rc)
4614 *pStatus = status;
4615 return rc;
4619 BOOL AfsClass_AddUserToGroup (LPIDENT lpiGroup, LPIDENT lpiUser, ULONG *pStatus)
4621 BOOL rc = TRUE;
4622 ULONG status;
4624 AfsClass_Enter();
4625 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberAddBegin, lpiGroup, lpiUser, NULL, NULL, 0, 0);
4627 // Obtain hCell
4629 PVOID hCell;
4630 LPCELL lpCell;
4631 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4632 rc = FALSE;
4633 else
4635 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4636 rc = FALSE;
4637 lpCell->Close();
4640 TCHAR szGroup[ cchNAME ];
4641 lpiGroup->GetGroupName (szGroup);
4643 TCHAR szMember[ cchNAME ];
4644 if (lpiUser->fIsUser())
4645 lpiUser->GetFullUserName (szMember);
4646 else // (lpiUser->fIsGroup())
4647 lpiUser->GetGroupName (szMember);
4649 // Add this user to the specified group
4651 if (rc)
4653 WORKERPACKET wp;
4654 wp.wpPtsGroupMemberAdd.hCell = hCell;
4655 wp.wpPtsGroupMemberAdd.pszGroup = szGroup;
4656 wp.wpPtsGroupMemberAdd.pszUser = szMember;
4658 AfsClass_Leave();
4659 rc = Worker_DoTask (wtaskPtsGroupMemberAdd, &wp, &status);
4660 AfsClass_Enter();
4663 // If we were able to change the group successfully, update the group's
4664 // and user's properties.
4666 if (rc)
4668 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4670 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4671 lpCell->RefreshAccount (szMember, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4672 lpCell->Close();
4676 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberAddEnd, lpiGroup, lpiUser, NULL, NULL, 0, status);
4677 AfsClass_Leave();
4679 if (pStatus && !rc)
4680 *pStatus = status;
4681 return rc;
4685 BOOL AfsClass_RemoveUserFromGroup (LPIDENT lpiGroup, LPIDENT lpiUser, ULONG *pStatus)
4687 BOOL rc = TRUE;
4688 ULONG status;
4690 AfsClass_Enter();
4691 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberRemoveBegin, lpiGroup, lpiUser, NULL, NULL, 0, 0);
4693 // Obtain hCell
4695 PVOID hCell;
4696 LPCELL lpCell;
4697 if ((lpCell = lpiGroup->OpenCell (&status)) == NULL)
4698 rc = FALSE;
4699 else
4701 if ((hCell = lpCell->GetCellObject (&status)) == NULL)
4702 rc = FALSE;
4703 lpCell->Close();
4706 TCHAR szGroup[ cchNAME ];
4707 lpiGroup->GetGroupName (szGroup);
4709 TCHAR szMember[ cchNAME ];
4710 if (lpiUser->fIsUser())
4711 lpiUser->GetFullUserName (szMember);
4712 else // (lpiUser->fIsGroup())
4713 lpiUser->GetGroupName (szMember);
4715 // Remove this user from the specified group
4717 if (rc)
4719 WORKERPACKET wp;
4720 wp.wpPtsGroupMemberRemove.hCell = hCell;
4721 wp.wpPtsGroupMemberRemove.pszGroup = szGroup;
4722 wp.wpPtsGroupMemberRemove.pszUser = szMember;
4724 AfsClass_Leave();
4725 rc = Worker_DoTask (wtaskPtsGroupMemberRemove, &wp, &status);
4726 AfsClass_Enter();
4729 // If we were able to change the group successfully, update the group's
4730 // and user's properties.
4732 if (rc)
4734 if ((lpCell = lpiGroup->OpenCell (&status)) != NULL)
4736 lpCell->RefreshAccount (szGroup, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4737 lpCell->RefreshAccount (szMember, NULL, CELL_REFRESH_ACCOUNT_CHANGED);
4738 lpCell->Close();
4742 NOTIFYCALLBACK::SendNotificationToAll (evtGroupMemberRemoveEnd, lpiGroup, lpiUser, NULL, NULL, 0, status);
4743 AfsClass_Leave();
4745 if (pStatus && !rc)
4746 *pStatus = status;
4747 return rc;