findlanabyname-20040228
[openafs.git] / src / WINNT / afssvrmgr / task.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include "svrmgr.h"
16 #include "task.h"
17 #include "display.h"
18 #include "action.h"
19 #include "svr_general.h"
20 #include "svr_window.h"
21 #include "svr_prop.h"
22 #include "svr_syncvldb.h"
23 #include "svr_salvage.h"
24 #include "svr_install.h"
25 #include "svr_uninstall.h"
26 #include "svr_prune.h"
27 #include "svr_getdates.h"
28 #include "svr_execute.h"
29 #include "svr_security.h"
30 #include "svr_address.h"
31 #include "svc_prop.h"
32 #include "svc_create.h"
33 #include "svc_general.h"
34 #include "svc_startstop.h"
35 #include "svc_viewlog.h"
36 #include "agg_general.h"
37 #include "agg_prop.h"
38 #include "set_create.h"
39 #include "set_delete.h"
40 #include "set_move.h"
41 #include "set_prop.h"
42 #include "set_general.h"
43 #include "set_quota.h"
44 #include "set_repprop.h"
45 #include "set_createrep.h"
46 #include "set_rename.h"
47 #include "set_release.h"
48 #include "set_clone.h"
49 #include "set_dump.h"
50 #include "set_restore.h"
51 #include "subset.h"
52 #include "messages.h"
53 #include "creds.h"
54
55
56 #ifdef DEBUG
57 #include <exportcl.h>
58 #endif
59
60
61 // As an additional debugging measure, you may want to enable the
62 // definition below--doing so causes the tool to ensure that
63 // AFSCLASS's critical section (accessed via AfsClass_Enter()/Leave()) is
64 // not leaking during tasks: for instance, if AfsClass_MoveFileset()
65 // calls AfsClass_Enter() three times but Leave() only twice, then an
66 // assertion will trigger in Task_Perform() (at which point it is
67 // not too late to easily determine which task leaked the critsec).
68 // Unfortunately, this has a side-effect: enabling the definition
69 // below prevents the AFSCLASS library from entirely exiting the
70 // critical section during its work--which means that only one
71 // AfsClass_* function can ever be run at once.  So, enable this
72 // definition if you see a lockup--and disable it when you're done.
73 //
74 #ifdef DEBUG
75 // #define DEBUG_CRIT
76 #endif
77
78
79 /*
80  * PROTOTYPES _________________________________________________________________
81  *
82  */
83
84 #ifdef DEBUG
85 void Task_ExportCell (LPTASKPACKET ptp);
86 #endif
87 void Task_OpenCell (LPTASKPACKET ptp);
88 void Task_OpenedCell (LPTASKPACKET ptp);
89 void Task_ClosedCell (LPTASKPACKET ptp);
90 void Task_Refresh (LPTASKPACKET ptp, BOOL fNewCreds);
91 void Task_Subset_To_List (LPTASKPACKET ptp);
92 void Task_Apply_Subset (LPTASKPACKET ptp);
93 void Task_Svr_Prop_Init (LPTASKPACKET ptp);
94 void Task_Svr_Scout_Init (LPTASKPACKET ptp);
95 void Task_Svr_Scout_Apply (LPTASKPACKET ptp);
96 void Task_Svr_Enum_To_ComboBox (LPTASKPACKET ptp);
97 void Task_Svr_GetWindowPos (LPTASKPACKET ptp);
98 void Task_Svr_SetWindowPos (LPTASKPACKET ptp);
99 void Task_Svr_SyncVLDB (LPTASKPACKET ptp);
100 void Task_Svr_Salvage (LPTASKPACKET ptp);
101 void Task_Svr_Install (LPTASKPACKET ptp);
102 void Task_Svr_Uninstall (LPTASKPACKET ptp);
103 void Task_Svr_Prune (LPTASKPACKET ptp);
104 void Task_Svr_GetDates (LPTASKPACKET ptp);
105 void Task_Svr_Execute (LPTASKPACKET ptp);
106 void Task_Svr_SetAuth (LPTASKPACKET ptp);
107 void Task_Svr_AdmList_Open (LPTASKPACKET ptp);
108 void Task_Svr_AdmList_Save (LPTASKPACKET ptp);
109 void Task_Svr_KeyList_Open (LPTASKPACKET ptp);
110 void Task_Svr_Key_Create (LPTASKPACKET ptp);
111 void Task_Svr_Key_Delete (LPTASKPACKET ptp);
112 void Task_Svr_HostList_Open (LPTASKPACKET ptp);
113 void Task_Svr_HostList_Save (LPTASKPACKET ptp);
114 void Task_Svr_GetRandomKey (LPTASKPACKET ptp);
115 void Task_Svr_Monitor_OnOff (LPTASKPACKET ptp);
116 void Task_Svr_ChangeAddr (LPTASKPACKET ptp);
117 void Task_Svc_Menu (LPTASKPACKET ptp);
118 void Task_Svc_Prop_Init (LPTASKPACKET ptp);
119 void Task_Svc_Prop_Apply (LPTASKPACKET ptp);
120 void Task_Svc_Start (LPTASKPACKET ptp);
121 void Task_Svc_Stop (LPTASKPACKET ptp);
122 void Task_Svc_Restart (LPTASKPACKET ptp);
123 void Task_Svc_FindLog (LPTASKPACKET ptp);
124 void Task_Svc_ViewLog (LPTASKPACKET ptp);
125 void Task_Svc_Create (LPTASKPACKET ptp);
126 void Task_Svc_Delete (LPTASKPACKET ptp);
127 void Task_Svc_GetRestartTimes (LPTASKPACKET ptp);
128 void Task_Svc_SetRestartTimes (LPTASKPACKET ptp);
129 void Task_Agg_Prop_Init (LPTASKPACKET ptp);
130 void Task_Agg_Prop_Apply (LPTASKPACKET ptp);
131 void Task_Agg_Find_Quota_Limits (LPTASKPACKET ptp);
132 void Task_Agg_Enum_To_ListView (LPTASKPACKET ptp);
133 void Task_Agg_Enum_To_ComboBox (LPTASKPACKET ptp);
134 void Task_Agg_Find_Ghost (LPTASKPACKET ptp);
135 void Task_Set_Enum_To_ComboBox (LPTASKPACKET ptp);
136 void Task_Set_Find_Ghost (LPTASKPACKET ptp);
137 void Task_Set_Create (LPTASKPACKET ptp);
138 void Task_Set_Delete (LPTASKPACKET ptp);
139 void Task_Set_Move (LPTASKPACKET ptp);
140 void Task_Set_MoveTo_Init (LPTASKPACKET ptp);
141 void Task_Set_Prop_Init (LPTASKPACKET ptp);
142 void Task_Set_Prop_Apply (LPTASKPACKET ptp);
143 void Task_Set_SetQuota_Init (LPTASKPACKET ptp);
144 void Task_Set_SetQuota_Apply (LPTASKPACKET ptp);
145 void Task_Set_RepProp_Init (LPTASKPACKET ptp);
146 void Task_Set_Select (LPTASKPACKET ptp);
147 void Task_Set_BeginDrag (LPTASKPACKET ptp);
148 void Task_Set_DragMenu (LPTASKPACKET ptp);
149 void Task_Set_Menu (LPTASKPACKET ptp);
150 void Task_Set_Lock (LPTASKPACKET ptp);
151 void Task_Set_Unlock (LPTASKPACKET ptp);
152 void Task_Set_CreateRep (LPTASKPACKET ptp);
153 void Task_Set_Rename_Init (LPTASKPACKET ptp);
154 void Task_Set_Rename_Apply (LPTASKPACKET ptp);
155 void Task_Set_Release (LPTASKPACKET ptp);
156 void Task_Set_Clone (LPTASKPACKET ptp);
157 void Task_Set_Clonesys (LPTASKPACKET ptp);
158 void Task_Set_Dump (LPTASKPACKET ptp);
159 void Task_Set_Restore (LPTASKPACKET ptp);
160 void Task_Set_Lookup (LPTASKPACKET ptp);
161 void Task_Expired_Creds (LPTASKPACKET ptp);
162
163
164 /*
165  * ROUTINES ___________________________________________________________________
166  *
167  */
168
169 LPTASKPACKET CreateTaskPacket (int idTask, HWND hReply, PVOID lpUser)
170 {
171    LPTASKPACKET ptp;
172
173    if ((ptp = New (TASKPACKET)) != NULL)
174       {
175       memset (ptp, 0x00, sizeof(TASKPACKET));
176
177       ptp->idTask = idTask;
178       ptp->hReply = hReply;
179       ptp->lpUser = lpUser;
180
181       ptp->rc = TRUE;
182       ptp->status = 0;
183
184       if ((ptp->pReturn = New (TASKPACKETDATA)) != NULL)
185          {
186          memset (ptp->pReturn, 0x00, sizeof(TASKPACKETDATA));
187          }
188       }
189
190    return ptp;
191 }
192
193
194 void FreeTaskPacket (LPTASKPACKET ptp)
195 {
196    if (ptp)
197       {
198       if (ptp->pReturn)
199          {
200          if (TASKDATA(ptp)->pszText1)
201             FreeString (TASKDATA(ptp)->pszText1);
202          if (TASKDATA(ptp)->pszText2)
203             FreeString (TASKDATA(ptp)->pszText2);
204          if (TASKDATA(ptp)->pszText3)
205             FreeString (TASKDATA(ptp)->pszText3);
206          Delete (ptp->pReturn);
207          }
208
209       Delete (ptp);
210       }
211 }
212
213
214 void PerformTask (LPTASKPACKET ptp)
215 {
216 #ifdef DEBUG_CRIT
217    AfsClass_Enter();
218    ASSERT( AfsClass_GetEnterCount() == 1 );
219 #endif
220
221    switch (ptp->idTask)
222       {
223 #ifdef DEBUG
224       case taskEXPORTCELL:
225          Task_ExportCell (ptp);
226          break;
227 #endif
228
229       case taskOPENCELL:
230          Task_OpenCell (ptp);
231          break;
232
233       case taskOPENEDCELL:
234          Task_OpenedCell (ptp);
235          break;
236
237       case taskCLOSEDCELL:
238          Task_ClosedCell (ptp);
239          break;
240
241       case taskREFRESH:
242          Task_Refresh (ptp, FALSE);
243          break;
244
245       case taskREFRESH_CREDS:
246          Task_Refresh (ptp, TRUE);
247          break;
248
249       case taskSUBSET_TO_LIST:
250          Task_Subset_To_List (ptp);
251          break;
252
253       case taskAPPLY_SUBSET:
254          Task_Apply_Subset (ptp);
255          break;
256
257       case taskSVR_PROP_INIT:
258          Task_Svr_Prop_Init (ptp);
259          break;
260
261       case taskSVR_SCOUT_INIT:
262          Task_Svr_Scout_Init (ptp);
263          break;
264
265       case taskSVR_SCOUT_APPLY:
266          Task_Svr_Scout_Apply (ptp);
267          break;
268
269       case taskSVR_ENUM_TO_COMBOBOX:
270          Task_Svr_Enum_To_ComboBox (ptp);
271          break;
272
273       case taskSVR_GETWINDOWPOS:
274          Task_Svr_GetWindowPos (ptp);
275          break;
276
277       case taskSVR_SETWINDOWPOS:
278          Task_Svr_SetWindowPos (ptp);
279          break;
280
281       case taskSVR_SYNCVLDB:
282          Task_Svr_SyncVLDB (ptp);
283          break;
284
285       case taskSVR_SALVAGE:
286          Task_Svr_Salvage (ptp);
287          break;
288
289       case taskSVR_INSTALL:
290          Task_Svr_Install (ptp);
291          break;
292
293       case taskSVR_UNINSTALL:
294          Task_Svr_Uninstall (ptp);
295          break;
296
297       case taskSVR_PRUNE:
298          Task_Svr_Prune (ptp);
299          break;
300
301       case taskSVR_GETDATES:
302          Task_Svr_GetDates (ptp);
303          break;
304
305       case taskSVR_EXECUTE:
306          Task_Svr_Execute (ptp);
307          break;
308
309       case taskSVR_SETAUTH:
310          Task_Svr_SetAuth (ptp);
311          break;
312
313       case taskSVR_ADMLIST_OPEN:
314          Task_Svr_AdmList_Open (ptp);
315          break;
316
317       case taskSVR_ADMLIST_SAVE:
318          Task_Svr_AdmList_Save (ptp);
319          break;
320
321       case taskSVR_KEYLIST_OPEN:
322          Task_Svr_KeyList_Open (ptp);
323          break;
324
325       case taskSVR_KEY_CREATE:
326          Task_Svr_Key_Create (ptp);
327          break;
328
329       case taskSVR_KEY_DELETE:
330          Task_Svr_Key_Delete (ptp);
331          break;
332
333       case taskSVR_GETRANDOMKEY:
334          Task_Svr_GetRandomKey (ptp);
335          break;
336
337       case taskSVR_HOSTLIST_OPEN:
338          Task_Svr_HostList_Open (ptp);
339          break;
340
341       case taskSVR_HOSTLIST_SAVE:
342          Task_Svr_HostList_Save (ptp);
343          break;
344
345       case taskSVR_MONITOR_ONOFF:
346          Task_Svr_Monitor_OnOff (ptp);
347          break;
348
349       case taskSVR_CHANGEADDR:
350          Task_Svr_ChangeAddr (ptp);
351          break;
352
353       case taskSVC_MENU:
354          Task_Svc_Menu (ptp);
355          break;
356
357       case taskSVC_PROP_INIT:
358          Task_Svc_Prop_Init (ptp);
359          break;
360
361       case taskSVC_PROP_APPLY:
362          Task_Svc_Prop_Apply (ptp);
363          break;
364
365       case taskSVC_START:
366          Task_Svc_Start (ptp);
367          break;
368
369       case taskSVC_STOP:
370          Task_Svc_Stop (ptp);
371          break;
372
373       case taskSVC_RESTART:
374          Task_Svc_Restart (ptp);
375          break;
376
377       case taskSVC_FINDLOG:
378          Task_Svc_FindLog (ptp);
379          break;
380
381       case taskSVC_VIEWLOG:
382          Task_Svc_ViewLog (ptp);
383          break;
384
385       case taskSVC_CREATE:
386          Task_Svc_Create (ptp);
387          break;
388
389       case taskSVC_DELETE:
390          Task_Svc_Delete (ptp);
391          break;
392
393       case taskSVC_GETRESTARTTIMES:
394          Task_Svc_GetRestartTimes (ptp);
395          break;
396
397       case taskSVC_SETRESTARTTIMES:
398          Task_Svc_SetRestartTimes (ptp);
399          break;
400
401       case taskAGG_PROP_INIT:
402          Task_Agg_Prop_Init (ptp);
403          break;
404
405       case taskAGG_PROP_APPLY:
406          Task_Agg_Prop_Apply (ptp);
407          break;
408
409       case taskAGG_FIND_QUOTA_LIMITS:
410          Task_Agg_Find_Quota_Limits (ptp);
411          break;
412
413       case taskAGG_ENUM_TO_LISTVIEW:
414          Task_Agg_Enum_To_ListView (ptp);
415          break;
416
417       case taskAGG_ENUM_TO_COMBOBOX:
418          Task_Agg_Enum_To_ComboBox (ptp);
419          break;
420
421       case taskAGG_FIND_GHOST:
422          Task_Agg_Find_Ghost (ptp);
423          break;
424
425       case taskSET_ENUM_TO_COMBOBOX:
426          Task_Set_Enum_To_ComboBox (ptp);
427          break;
428
429       case taskSET_FIND_GHOST:
430          Task_Set_Find_Ghost (ptp);
431          break;
432
433       case taskSET_CREATE:
434          Task_Set_Create (ptp);
435          break;
436
437       case taskSET_DELETE:
438          Task_Set_Delete (ptp);
439          break;
440
441       case taskSET_MOVE:
442          Task_Set_Move (ptp);
443          break;
444
445       case taskSET_MOVETO_INIT:
446          Task_Set_MoveTo_Init (ptp);
447          break;
448
449       case taskSET_PROP_INIT:
450          Task_Set_Prop_Init (ptp);
451          break;
452
453       case taskSET_PROP_APPLY:
454          Task_Set_Prop_Apply (ptp);
455          break;
456
457       case taskSET_SETQUOTA_INIT:
458          Task_Set_SetQuota_Init (ptp);
459          break;
460
461       case taskSET_SETQUOTA_APPLY:
462          Task_Set_SetQuota_Apply (ptp);
463          break;
464
465       case taskSET_REPPROP_INIT:
466          Task_Set_RepProp_Init (ptp);
467          break;
468
469       case taskSET_SELECT:
470          Task_Set_Select (ptp);
471          break;
472
473       case taskSET_BEGINDRAG:
474          Task_Set_BeginDrag (ptp);
475          break;
476
477       case taskSET_DRAGMENU:
478          Task_Set_DragMenu (ptp);
479          break;
480
481       case taskSET_MENU:
482          Task_Set_Menu (ptp);
483          break;
484
485       case taskSET_LOCK:
486          Task_Set_Lock (ptp);
487          break;
488
489       case taskSET_UNLOCK:
490          Task_Set_Unlock (ptp);
491          break;
492
493       case taskSET_CREATEREP:
494          Task_Set_CreateRep (ptp);
495          break;
496
497       case taskSET_RENAME_INIT:
498          Task_Set_Rename_Init (ptp);
499          break;
500
501       case taskSET_RENAME_APPLY:
502          Task_Set_Rename_Apply (ptp);
503          break;
504
505       case taskSET_RELEASE:
506          Task_Set_Release (ptp);
507          break;
508
509       case taskSET_CLONE:
510          Task_Set_Clone (ptp);
511          break;
512
513       case taskSET_CLONESYS:
514          Task_Set_Clonesys (ptp);
515          break;
516
517       case taskSET_DUMP:
518          Task_Set_Dump (ptp);
519          break;
520
521       case taskSET_RESTORE:
522          Task_Set_Restore (ptp);
523          break;
524
525       case taskSET_LOOKUP:
526          Task_Set_Lookup (ptp);
527          break;
528
529       case taskEXPIRED_CREDS:
530          Task_Expired_Creds (ptp);
531          break;
532
533       default:
534          ptp->rc = FALSE;
535          ptp->status = ERROR_INVALID_FUNCTION;
536          break;
537       }
538
539 #ifdef DEBUG_CRIT
540    ASSERT( AfsClass_GetEnterCount() == 1 );
541    AfsClass_Leave();
542 #endif
543 }
544
545
546 void CoverServerList (LPIDENT lpiCell, ULONG status)
547 {
548    TCHAR szName[ cchRESOURCE ];
549    lpiCell->GetCellName (szName);
550
551    int idsButton;
552
553    switch (status)
554       {
555       case ERROR_NOT_AUTHENTICATED:
556          idsButton = IDS_ALERT_BUTTON_GETCREDS;
557          break;
558       default:
559          idsButton = IDS_ALERT_BUTTON_TRYAGAIN;
560          break;
561       }
562
563
564    LPTSTR pszCover = FormatString (IDS_ERROR_REFRESH_CELLSERVERS, TEXT("%s%e"), szName, status);
565    LPTSTR pszButton = FormatString (idsButton);
566
567    AfsAppLib_CoverWindow (GetDlgItem (g.hMain, IDC_SERVERS), pszCover, pszButton);
568
569    FreeString (pszButton);
570    FreeString (pszCover);
571 }
572
573
574 #ifdef DEBUG
575 ULONG SystemTimeToUnixTime (SYSTEMTIME *pst)
576 {
577    SYSTEMTIME st;
578    if (pst == NULL)
579       GetSystemTime (&st);
580    else
581       st = *pst;
582
583    FILETIME ft;
584    if (!SystemTimeToFileTime (&st, &ft))
585       return 0;
586
587    LARGE_INTEGER now;
588    now.HighPart = (LONG)ft.dwHighDateTime;
589    now.LowPart = (ULONG)ft.dwLowDateTime;
590
591    LARGE_INTEGER offset;
592    offset.HighPart = 0x019db1de;
593    offset.LowPart = 0xd53e8000;
594
595    LARGE_INTEGER result;
596    result.QuadPart = (now.QuadPart - offset.QuadPart) / 10000000;
597    return (ULONG)result.LowPart;
598 }
599
600 static size_t nExportLevels = 0;
601 void Task_ExportCell_Spacing (LPTSTR pszSpacing)
602 {
603    wsprintf (pszSpacing, TEXT("%99s"), TEXT(""));
604    pszSpacing[ nExportLevels *3 ] = TEXT('\0');
605 }
606
607 #define chLBRC TEXT('{')
608 #define chRBRC TEXT('}')
609
610 void Task_ExportCell_Begin (HANDLE fh, LPTSTR eck, LPTSTR pszName)
611 {
612    TCHAR szSpacing[ 256 ];
613    Task_ExportCell_Spacing (szSpacing);
614    TCHAR szLine[ 256 ];
615    wsprintf (szLine, TEXT("\r\n%s%s %s %c\r\n"), szSpacing, eck, pszName, chLBRC);
616    DWORD cbWrote = 0;
617    WriteFile (fh, szLine, lstrlen(szLine), &cbWrote, NULL);
618    ++nExportLevels;
619 }
620
621 void Task_ExportCell_End (HANDLE fh)
622 {
623    --nExportLevels;
624    TCHAR szSpacing[ 256 ];
625    Task_ExportCell_Spacing (szSpacing);
626    TCHAR szLine[ 256 ];
627    wsprintf (szLine, TEXT("%s%c\r\n"), szSpacing, chRBRC);
628    DWORD cbWrote = 0;
629    WriteFile (fh, szLine, lstrlen(szLine), &cbWrote, NULL);
630 }
631
632 void Task_ExportCell_Line (HANDLE fh, LPTSTR eck, LPTSTR pszRHS)
633 {
634    TCHAR szSpacing[ 256 ];
635    Task_ExportCell_Spacing (szSpacing);
636    TCHAR szLine[ 256 ];
637    wsprintf (szLine, TEXT("%s%s = \"%s\"\r\n"), szSpacing, eck, pszRHS);
638    DWORD cbWrote = 0;
639    WriteFile (fh, szLine, lstrlen(szLine), &cbWrote, NULL);
640 }
641
642 void Task_ExportCell_LineAddr (HANDLE fh, LPTSTR eck, SOCKADDR_IN *pAddr)
643 {
644    LPSTR pszLine = FormatString (TEXT("%1"), TEXT("%a"), pAddr);
645    Task_ExportCell_Line (fh, eck, pszLine);
646    FreeString (pszLine);
647 }
648
649 void Task_ExportCell_LineInt (HANDLE fh, LPTSTR eck, int dw)
650 {
651    TCHAR szLine[256];
652    wsprintf (szLine, TEXT("%lu"), dw);
653    Task_ExportCell_Line (fh, eck, szLine);
654 }
655
656 void Task_ExportCell_LineLarge (HANDLE fh, LPTSTR eck, LARGE_INTEGER *pldw)
657 {
658    TCHAR szLine[256];
659    wsprintf (szLine, TEXT("%lu,,%lu"), pldw->HighPart, pldw->LowPart);
660    Task_ExportCell_Line (fh, eck, szLine);
661 }
662
663 void Task_ExportCell_LineDate (HANDLE fh, LPTSTR eck, SYSTEMTIME *pst)
664 {
665    Task_ExportCell_LineInt (fh, eck, SystemTimeToUnixTime(pst));
666 }
667
668 void Task_ExportService (HANDLE fh, LPSERVICE lpService)
669 {
670    TCHAR szName[ cchNAME ];
671    lpService->GetName (szName);
672    Task_ExportCell_Begin (fh, eckSERVICE, szName);
673
674    SERVICESTATUS ss;
675    if (lpService->GetStatus (&ss))
676       {
677       Task_ExportCell_LineInt  (fh, eckRUNNING,   (ss.state == SERVICESTATE_RUNNING));
678       Task_ExportCell_LineInt  (fh, eckSTATE,     ss.state);
679       Task_ExportCell_LineInt  (fh, eckNSTARTS,   ss.nStarts);
680       Task_ExportCell_LineInt  (fh, eckERRLAST,   ss.dwErrLast);
681       Task_ExportCell_LineInt  (fh, eckSIGLAST,   ss.dwSigLast);
682       Task_ExportCell_Line     (fh, eckPARAMS,    ss.szParams);
683       Task_ExportCell_Line     (fh, eckNOTIFIER,  ss.szNotifier);
684       Task_ExportCell_LineDate (fh, eckSTARTTIME, &ss.timeLastStart);
685       Task_ExportCell_LineDate (fh, eckSTOPTIME,  &ss.timeLastStop);
686       Task_ExportCell_LineDate (fh, eckERRORTIME, &ss.timeLastFail);
687
688       if (ss.type == SERVICETYPE_SIMPLE)
689          Task_ExportCell_Line  (fh, eckTYPE,    eckSIMPLE);
690       else if (ss.type == SERVICETYPE_CRON)
691          Task_ExportCell_Line  (fh, eckTYPE,    eckCRON);
692       else // (ss.type == SERVICETYPE_FS)
693          Task_ExportCell_Line  (fh, eckTYPE,    eckFS);
694       }
695
696    Task_ExportCell_End (fh);
697 }
698
699 void Task_ExportFileset (HANDLE fh, LPFILESET lpFileset)
700 {
701    TCHAR szName[ cchNAME ];
702    lpFileset->GetName (szName);
703    Task_ExportCell_Begin (fh, eckFILESET, szName);
704
705    FILESETSTATUS fs;
706    if (lpFileset->GetStatus (&fs))
707       {
708       Task_ExportCell_LineInt   (fh, eckID,          fs.id);
709       Task_ExportCell_LineInt   (fh, eckID_RW,       fs.idReadWrite);
710       Task_ExportCell_LineInt   (fh, eckID_BK,       fs.idClone);
711       Task_ExportCell_LineInt   (fh, eckUSED,        fs.ckUsed);
712       Task_ExportCell_LineInt   (fh, eckQUOTA,       fs.ckQuota);
713       Task_ExportCell_LineDate  (fh, eckCREATETIME, &fs.timeCreation);
714       Task_ExportCell_LineDate  (fh, eckUPDATETIME, &fs.timeLastUpdate);
715       Task_ExportCell_LineDate  (fh, eckACCESSTIME, &fs.timeLastAccess);
716       Task_ExportCell_LineDate  (fh, eckBACKUPTIME, &fs.timeLastBackup);
717       }
718
719    Task_ExportCell_End (fh);
720 }
721
722 void Task_ExportAggregate (HANDLE fh, LPAGGREGATE lpAggregate)
723 {
724    TCHAR szName[ cchNAME ];
725    lpAggregate->GetName (szName);
726    Task_ExportCell_Begin (fh, eckAGGREGATE, szName);
727
728    lpAggregate->GetDevice (szName);
729    Task_ExportCell_Line (fh, eckDEVICE, szName);
730
731    AGGREGATESTATUS as;
732    if (lpAggregate->GetStatus (&as))
733       {
734       Task_ExportCell_LineInt  (fh, eckID,      (int)as.dwID);
735       Task_ExportCell_LineInt  (fh, eckTOTAL,   (int)as.ckStorageTotal);
736       Task_ExportCell_LineInt  (fh, eckFREECUR, (int)as.ckStorageFree);
737       }
738
739    HENUM hEnum;
740    for (LPFILESET lpFileset = lpAggregate->FilesetFindFirst (&hEnum); lpFileset; lpFileset = lpAggregate->FilesetFindNext (&hEnum))
741       {
742       Task_ExportFileset (fh, lpFileset);
743       lpFileset->Close();
744       }
745
746    Task_ExportCell_End (fh);
747 }
748
749 void Task_ExportServer (HANDLE fh, LPSERVER lpServer)
750 {
751    TCHAR szName[ cchNAME ];
752    lpServer->GetLongName (szName);
753    Task_ExportCell_Begin (fh, eckSERVER, szName);
754
755    // First, properties of the server
756    //
757    SERVERSTATUS ss;
758    if (lpServer->GetStatus (&ss))
759       {
760       for (size_t iAddr = 0; iAddr < ss.nAddresses; ++iAddr)
761          Task_ExportCell_LineAddr (fh, eckADDRESS, &ss.aAddresses[ iAddr ]);
762       }
763
764    // Then, services on the server
765    //
766    HENUM hEnum;
767    for (LPSERVICE lpService = lpServer->ServiceFindFirst (&hEnum); lpService; lpService = lpServer->ServiceFindNext (&hEnum))
768       {
769       Task_ExportService (fh, lpService);
770       lpService->Close();
771       }
772
773    // Then, aggregates and filesets on the server
774    //
775    for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&hEnum); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&hEnum))
776       {
777       Task_ExportAggregate (fh, lpAggregate);
778       lpAggregate->Close();
779       }
780
781    Task_ExportCell_End (fh);
782 }
783
784 void Task_ExportCell (LPTASKPACKET ptp)
785 {
786    LPTSTR pszFilename = (LPTSTR)(ptp->lpUser);
787
788    HANDLE fh;
789    fh = CreateFile (pszFilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
790    if (fh != INVALID_HANDLE_VALUE)
791       {
792       TCHAR szName[ cchNAME ];
793       g.lpiCell->GetCellName (szName);
794       Task_ExportCell_Begin (fh, eckCELL, szName);
795
796       LPCELL lpCell;
797       if ((lpCell = g.lpiCell->OpenCell()) != NULL)
798          {
799          HENUM hEnum;
800          for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
801             {
802             Task_ExportServer (fh, lpServer);
803             lpServer->Close();
804             }
805
806          lpCell->Close();
807          }
808
809       Task_ExportCell_End (fh);
810       CloseHandle (fh);
811       }
812
813    Delete (pszFilename);
814    ptp->lpUser = 0; // we freed this; don't let the caller use it again
815 }
816 #endif
817
818
819 void Task_OpenCell (LPTASKPACKET ptp)
820 {
821    LPOPENCELL_PACKET lpp = (LPOPENCELL_PACKET)(ptp->lpUser);
822
823    LPSUBSET subOld = g.sub;
824    g.sub = lpp->sub;
825
826    if ((TASKDATA(ptp)->lpiCell = CELL::OpenCell (lpp->szCell, lpp->hCreds, &ptp->status)) == NULL)
827       {
828       ptp->rc = FALSE;
829
830       g.sub = subOld;
831       if (lpp->sub)
832          Subsets_FreeSubset (lpp->sub);
833       }
834    else if (subOld)
835       {
836       Subsets_FreeSubset (subOld);
837       }
838
839    if (ptp->rc)
840       {
841       PostMessage (g.hMain, WM_SHOW_YOURSELF, 0, 1);
842
843       if (gr.fActions)
844          PostMessage (g.hMain, WM_OPEN_ACTIONS, 0, 0);
845       }
846    else if (lpp->fCloseAppOnFail)
847       {
848       FatalErrorDialog (ptp->status, IDS_ERROR_CANT_OPEN_CELL, TEXT("%s"), lpp->szCell);
849       }
850
851    Delete (lpp);
852    ptp->lpUser = 0; // we freed this; don't let the caller use it again
853 }
854
855
856 void Task_OpenedCell (LPTASKPACKET ptp)
857 {
858    LPIDENT lpiCell = (LPIDENT)(ptp->lpUser);
859
860    if (lpiCell && lpiCell->fIsCell())
861       {
862       AfsClass_Enter();
863
864       DontNotifyMeEver (g.hMain);
865       NotifyMe (WHEN_CELL_OPENED, NULL, g.hMain, 0);
866       NotifyMe (WHEN_OBJECT_CHANGES, lpiCell, g.hMain, 0);
867       NotifyMe (WHEN_SVRS_CHANGE, lpiCell, g.hMain, 0);
868
869       if (g.lpiCell != NULL)
870          {
871          CELL::CloseCell (g.lpiCell);
872          }
873
874       g.lpiCell = lpiCell;
875       UpdateDisplay_Cell (TRUE);
876
877       TCHAR szName[ cchRESOURCE ];
878       lpiCell->GetCellName (szName);
879
880       LPTSTR pszCover = FormatString (IDS_SEARCHING_FOR_SERVERS, TEXT("%s"), szName);
881       AfsAppLib_CoverWindow (GetDlgItem (g.hMain, IDC_SERVERS), pszCover);
882       FreeString (pszCover);
883
884       LPCELL lpCell;
885       if ((lpCell = g.lpiCell->OpenCell (&ptp->status)) == NULL)
886          {
887          CoverServerList (g.lpiCell, ptp->status);
888          }
889       else
890          {
891          lpCell->Invalidate();
892          if ((ptp->rc = lpCell->RefreshAll (&ptp->status)) != TRUE)
893             {
894             CoverServerList (g.lpiCell, ptp->status);
895             }
896          lpCell->Close();
897          }
898
899       PostMessage (g.hMain, WM_OPEN_SERVERS, 0, 0);
900
901       Alert_StartScout();
902       AfsClass_Leave();
903       }
904 }
905
906
907 void Task_ClosedCell (LPTASKPACKET ptp)
908 {
909    LPIDENT lpiCell = (LPIDENT)(ptp->lpUser);
910
911    if (lpiCell && lpiCell->fIsCell())
912       {
913       AfsClass_Enter();
914
915       if (g.lpiCell == lpiCell)
916          {
917          LPCELL lpCellTest;
918          if ((lpCellTest = g.lpiCell->OpenCell()) != NULL)
919             {
920             // the user must have opened a cell, then opened it again.
921             // this is a bogus request to close the old copy of the
922             // cell.
923             lpCellTest->Close();
924             }
925          else
926             {
927             Server_CloseAll (FALSE);
928             g.lpiCell = NULL;
929             Main_Redraw_ThreadProc ((PVOID)FALSE);
930             }
931          }
932
933       AfsClass_Leave();
934       }
935 }
936
937
938 void Task_Refresh (LPTASKPACKET ptp, BOOL fNewCreds)
939 {
940    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
941    AfsClass_Enter();
942
943    if (lpi && lpi->fIsCell())
944       {
945       AfsAppLib_Uncover (GetDlgItem (g.hMain, IDC_SERVERS));
946
947       LPCELL lpCell;
948       if ((lpCell = lpi->OpenCell (&ptp->status)) == NULL)
949          {
950          CoverServerList (lpi, ptp->status);
951          }
952       else
953          {
954          if (fNewCreds)
955             lpCell->SetCurrentCredentials (g.hCreds);
956
957          lpCell->Invalidate();
958          if ((ptp->rc = lpCell->RefreshAll (&ptp->status)) != TRUE)
959             {
960             CoverServerList (lpi, ptp->status);
961             }
962          lpCell->Close();
963          }
964       }
965    else if (lpi && lpi->GetServer())
966       {
967       BOOL fWasMonitored = TRUE;
968
969       LPSERVER lpServer;
970       if ((lpServer = lpi->OpenServer()) != NULL)
971          {
972          if ((fWasMonitored = lpServer->fIsMonitored()) == FALSE)
973             lpServer->SetMonitor (TRUE);
974          lpServer->Close();
975          }
976
977       if (fWasMonitored) // if it was already monitored, we didn't just refresh
978          {
979          if (lpi && lpi->fIsServer())
980             {
981             if ((lpServer = lpi->OpenServer()) != NULL)
982                {
983                lpServer->Invalidate();
984                lpServer->RefreshAll();
985                lpServer->Close();
986                }
987             }
988          else if (lpi && lpi->fIsService())
989             {
990             LPSERVICE lpService;
991             if ((lpService = lpi->OpenService()) != NULL)
992                {
993                lpService->Invalidate();
994                lpService->RefreshStatus();
995                lpService->Close();
996                }
997             }
998          else if (lpi && lpi->fIsAggregate())
999             {
1000             LPAGGREGATE lpAggregate;
1001             if ((lpAggregate = lpi->OpenAggregate()) != NULL)
1002                {
1003                // if we implied this aggregate from fileset VLDB entries,
1004                // refresh its parent server, not this aggregate.
1005                //
1006                if (!(lpAggregate->GetGhostStatus() & GHOST_HAS_SERVER_ENTRY))
1007                   {
1008                   lpAggregate->Close();
1009
1010                   LPSERVER lpServer;
1011                   if ((lpServer = lpi->OpenServer()) != NULL)
1012                      {
1013                      lpServer->Invalidate();
1014                      lpServer->RefreshAll();
1015                      lpServer->Close();
1016                      }
1017                   }
1018                else
1019                   {
1020                   lpAggregate->Invalidate();
1021                   lpAggregate->RefreshStatus();
1022                   lpAggregate->RefreshFilesets();
1023                   lpAggregate->Close();
1024
1025                   LPCELL lpCell;
1026                   if ((lpCell = lpi->OpenCell()) != NULL)
1027                      {
1028                      lpCell->RefreshVLDB (lpi);
1029                      lpCell->Close();
1030                      }
1031                   }
1032                }
1033             }
1034          else if (lpi && lpi->fIsFileset())
1035             {
1036             LPFILESET lpFileset;
1037             if ((lpFileset = lpi->OpenFileset()) != NULL)
1038                {
1039                lpFileset->Invalidate();
1040                lpFileset->RefreshStatus();
1041                lpFileset->Close();
1042
1043                LPCELL lpCell;
1044                if ((lpCell = lpi->OpenCell()) != NULL)
1045                   {
1046                   lpCell->RefreshVLDB (lpi);
1047                   lpCell->Close();
1048                   }
1049                }
1050             }
1051          }
1052
1053       Alert_Scout_QueueCheckServer (lpi);
1054       }
1055
1056    AfsClass_Leave();
1057 }
1058
1059
1060 void Task_Subset_To_List (LPTASKPACKET ptp)
1061 {
1062    LPSUBSET_TO_LIST_PACKET lpp = (LPSUBSET_TO_LIST_PACKET)( ptp->lpUser );
1063
1064    LB_StartChange (lpp->hList, TRUE);
1065
1066    LPCELL lpCell = NULL;
1067    if (g.lpiCell)
1068       lpCell = g.lpiCell->OpenCell();
1069    if (lpCell)
1070       {
1071       HENUM hEnum;
1072       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
1073          {
1074          LPIDENT lpiServer = lpServer->GetIdentifier();
1075          TCHAR szServer[ cchNAME ];
1076          lpServer->GetName (szServer);
1077          lpServer->Close();
1078
1079          BOOL fMonitor = Subsets_fMonitorServer (lpp->sub, lpiServer);
1080
1081          LB_AddItem (lpp->hList, szServer, (LPARAM)fMonitor);
1082          }
1083
1084       lpCell->Close();
1085       }
1086
1087    LB_EndChange (lpp->hList);
1088
1089    Delete (lpp);
1090    ptp->lpUser = 0;  // we freed this; don't let anyone use it.
1091 }
1092
1093
1094 void Task_Apply_Subset (LPTASKPACKET ptp)
1095 {
1096    LPSUBSET sub = (LPSUBSET)( ptp->lpUser );
1097
1098    LPCELL lpCell = NULL;
1099    if (g.lpiCell)
1100       lpCell = g.lpiCell->OpenCell();
1101    if (lpCell)
1102       {
1103       HENUM hEnum;
1104       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
1105          {
1106          LPIDENT lpiServer = lpServer->GetIdentifier();
1107          TCHAR szServer[ cchNAME ];
1108          lpServer->GetName (szServer);
1109
1110          BOOL fMonitor = Subsets_fMonitorServer (sub, lpiServer);
1111          lpServer->SetMonitor (fMonitor);
1112
1113          lpServer->Close();
1114          }
1115
1116       lpCell->Close();
1117       }
1118 }
1119
1120
1121
1122 void Task_Svr_Prop_Init (LPTASKPACKET ptp)
1123 {
1124    LPIDENT lpiServer = (LPIDENT)(ptp->lpUser);
1125
1126    LPSERVER lpServer;
1127    if ((lpServer = lpiServer->OpenServer (&ptp->status)) == NULL)
1128       ptp->rc = FALSE;
1129    else
1130       {
1131       if (!lpServer->GetStatus (&TASKDATA(ptp)->ss, TRUE, &ptp->status))
1132          {
1133          ptp->rc = FALSE;
1134          }
1135       else
1136          {
1137          HENUM hEnum;
1138          for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&hEnum); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&hEnum))
1139             {
1140             AGGREGATESTATUS as;
1141             if (lpAggregate->GetStatus (&as))
1142                {
1143                TASKDATA(ptp)->ckCapacity += as.ckStorageTotal;
1144                TASKDATA(ptp)->ckAllocation += as.ckStorageAllocated;
1145                }
1146
1147             TASKDATA(ptp)->nAggr++;
1148             lpAggregate->Close();
1149             }
1150          }
1151
1152       lpServer->Close();
1153       }
1154 }
1155
1156
1157 void Task_Svr_Scout_Init (LPTASKPACKET ptp)
1158 {
1159    LPIDENT lpiServer = (LPIDENT)(ptp->lpUser);
1160
1161    if ((TASKDATA(ptp)->lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) == NULL)
1162       {
1163       ptp->rc = FALSE;
1164       ptp->status = ERROR_NOT_ENOUGH_MEMORY;
1165       }
1166 }
1167
1168
1169 void Task_Svr_Scout_Apply (LPTASKPACKET ptp)
1170 {
1171    LPSVR_SCOUT_APPLY_PACKET lpp = (LPSVR_SCOUT_APPLY_PACKET)(ptp->lpUser);
1172
1173    BOOL fRefreshVLDB = FALSE;
1174
1175    LPSERVER_PREF lpsp = NULL;
1176    if ((lpsp = (LPSERVER_PREF)lpp->lpiServer->GetUserParam()) == NULL)
1177       {
1178       ptp->rc = FALSE;
1179       ptp->status = ERROR_NOT_ENOUGH_MEMORY;
1180       }
1181    else
1182       {
1183       if (!lpp->fIDC_SVR_WARN_AGGFULL)
1184          lpsp->perWarnAggFull = 0;
1185       else
1186          lpsp->perWarnAggFull = lpp->wIDC_SVR_WARN_AGGFULL_PERCENT;
1187
1188       if (!lpp->fIDC_SVR_WARN_SETFULL)
1189          lpsp->perWarnSetFull = 0;
1190       else
1191          lpsp->perWarnSetFull = lpp->wIDC_SVR_WARN_SETFULL_PERCENT;
1192
1193       DWORD fOldWarnSet = (lpsp->fWarnSetNoVLDB << 1) | lpsp->fWarnSetNoServ;
1194
1195       lpsp->fWarnAggAlloc   = lpp->fIDC_SVR_WARN_AGGALLOC;
1196       lpsp->fWarnSvcStop    = lpp->fIDC_SVR_WARN_SVCSTOP;
1197       lpsp->fWarnSvrTimeout = lpp->fIDC_SVR_WARN_TIMEOUT;
1198       lpsp->fWarnSetNoVLDB  = lpp->fIDC_SVR_WARN_SETNOVLDB;
1199       lpsp->fWarnSetNoServ  = lpp->fIDC_SVR_WARN_SETNOSERV;
1200       lpsp->fWarnAggNoServ  = lpp->fIDC_SVR_WARN_AGGNOSERV;
1201
1202       DWORD fNewWarnSet = (lpsp->fWarnSetNoVLDB << 1) | lpsp->fWarnSetNoServ;
1203
1204       if (fNewWarnSet != fOldWarnSet)
1205          fRefreshVLDB = TRUE;
1206
1207       if (!lpp->fIDC_SVR_AUTOREFRESH)
1208          lpsp->oa.cTickRefresh = 0;
1209       else
1210          lpsp->oa.cTickRefresh = cmsec1MINUTE * lpp->dwIDC_SVR_AUTOREFRESH_MINUTES;
1211
1212       if (!Server_SavePreferences (lpp->lpiServer))
1213          {
1214          ptp->rc = FALSE;
1215          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
1216          }
1217       }
1218
1219    if (fRefreshVLDB)
1220       {
1221       LPCELL lpCell;
1222       if ((lpCell = lpp->lpiServer->OpenCell()) != NULL)
1223          {
1224          lpCell->RefreshVLDB (NULL);
1225          lpCell->Close();
1226          }
1227       }
1228
1229    (void)Alert_Scout_QueueCheckServer (lpp->lpiServer);
1230
1231    Delete (lpp);
1232    ptp->lpUser = 0;  // we freed this; don't let anyone use it.
1233 }
1234
1235
1236 void Task_Svr_Enum_To_ComboBox (LPTASKPACKET ptp)
1237 {
1238    LPSVR_ENUM_TO_COMBOBOX_PACKET lpp = (LPSVR_ENUM_TO_COMBOBOX_PACKET)(ptp->lpUser);
1239
1240    // Fill in the Servers combobox, and select the default server
1241    // (if one was specified, either as a server or as a fileset).
1242    //
1243    CB_StartChange (lpp->hCombo, TRUE);
1244
1245    LPCELL lpCell;
1246    if ((lpCell = g.lpiCell->OpenCell (&ptp->status)) == NULL)
1247       ptp->rc = FALSE;
1248    else
1249       {
1250       HENUM hEnum;
1251       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
1252          {
1253          TCHAR szName[ cchNAME ];
1254          lpServer->GetName (szName);
1255          CB_AddItem (lpp->hCombo, szName, (LPARAM)lpServer->GetIdentifier());
1256          lpServer->Close();
1257          }
1258       lpCell->Close();
1259       }
1260
1261    if (lpp->lpiSelect && lpp->lpiSelect->GetServer())
1262       CB_EndChange (lpp->hCombo, (LPARAM)(lpp->lpiSelect->GetServer()));
1263    else
1264       {
1265       CB_EndChange (lpp->hCombo, 0);
1266       CB_SetSelected (lpp->hCombo, 0);
1267       }
1268
1269    Delete (lpp);
1270    ptp->lpUser = NULL;  // we deleted this; don't let the caller use it again.
1271 }
1272
1273
1274 void Task_Svr_GetWindowPos (LPTASKPACKET ptp)
1275 {
1276    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
1277
1278    SetRectEmpty (&TASKDATA(ptp)->rWindow);
1279
1280    if (lpi != NULL)
1281       {
1282       LPSERVER_PREF lpsp = (LPSERVER_PREF)lpi->GetUserParam();
1283
1284       if (lpsp != NULL && (lpsp->rLast.right != 0))
1285          {
1286          TASKDATA(ptp)->rWindow = lpsp->rLast;
1287          }
1288       }
1289 }
1290
1291
1292 void Task_Svr_SetWindowPos (LPTASKPACKET ptp)
1293 {
1294    LPSVR_SETWINDOWPOS_PARAMS lpp = (LPSVR_SETWINDOWPOS_PARAMS)(ptp->lpUser);
1295
1296    if (lpp->lpi)
1297       {
1298       LPSERVER_PREF lpsp = (LPSERVER_PREF)(lpp->lpi->GetUserParam());
1299
1300       if (lpsp != NULL)
1301          {
1302          lpsp->rLast = lpp->rWindow;
1303          lpsp->fOpen = lpp->fOpen;
1304
1305          StorePreferences (lpp->lpi, lpsp, sizeof(SERVER_PREF));
1306          }
1307       }
1308
1309    Delete (lpp);
1310    ptp->lpUser = NULL;  // we deleted this; don't let the caller use it again.
1311 }
1312
1313
1314 void Task_Svr_SyncVLDB (LPTASKPACKET ptp)
1315 {
1316    LPSVR_SYNCVLDB_PARAMS lpp = (LPSVR_SYNCVLDB_PARAMS)(ptp->lpUser);
1317
1318    if (!AfsClass_SyncVLDB (lpp->lpi, lpp->fForce, &ptp->status))
1319       ptp->rc = FALSE;
1320
1321    if (!ptp->rc && !IsWindow (ptp->hReply))
1322       {
1323       ErrorDialog (ptp->status, IDS_ERROR_CANT_SYNCVLDB);
1324       }
1325
1326    Delete (lpp);
1327    ptp->lpUser = 0;  // we freed this; don't let anyone use it.
1328 }
1329
1330
1331 void Task_Svr_Salvage (LPTASKPACKET ptp)
1332 {
1333    LPSVR_SALVAGE_PARAMS lpp = (LPSVR_SALVAGE_PARAMS)(ptp->lpUser);
1334
1335    LPTSTR pszTempDir = (lpp->szTempDir[0] != TEXT('\0')) ? lpp->szTempDir : NULL;
1336    LPTSTR pszLogFile = (lpp->szLogFile[0] != TEXT('\0')) ? lpp->szLogFile : NULL;
1337
1338    if (!AfsClass_Salvage (lpp->lpiSalvage, &TASKDATA(ptp)->pszText1, lpp->nProcesses, pszTempDir, pszLogFile, lpp->fForce, lpp->fReadonly, lpp->fLogInodes, lpp->fLogRootInodes, lpp->fRebuildDirs, lpp->fReadBlocks, &ptp->status))
1339       ptp->rc = FALSE;
1340
1341    Delete (lpp);
1342    ptp->lpUser = 0;  // we freed this; don't let anyone use it.
1343 }
1344
1345
1346 void Task_Svr_Install (LPTASKPACKET ptp)
1347 {
1348    LPSVR_INSTALL_PARAMS lpp = (LPSVR_INSTALL_PARAMS)(ptp->lpUser);
1349
1350    ptp->rc = AfsClass_InstallFile (lpp->lpiServer, lpp->szTarget, lpp->szSource, &ptp->status);
1351
1352    if (!ptp->rc && !ptp->hReply)
1353       {
1354       TCHAR szFilename[ MAX_PATH ];
1355       TCHAR szSvrName[ cchRESOURCE ];
1356       lpp->lpiServer->GetServerName (szSvrName);
1357       CopyBaseFileName (szFilename, lpp->szSource);
1358       ErrorDialog (ptp->status, IDS_ERROR_CANT_INSTALL_FILE, TEXT("%s%s"), szSvrName, szFilename);
1359       }
1360
1361    Delete (lpp);
1362    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1363 }
1364
1365
1366 void Task_Svr_Uninstall (LPTASKPACKET ptp)
1367 {
1368    LPSVR_UNINSTALL_PARAMS lpp = (LPSVR_UNINSTALL_PARAMS)(ptp->lpUser);
1369
1370    ptp->rc = AfsClass_UninstallFile (lpp->lpiServer, lpp->szUninstall, &ptp->status);
1371
1372    if (!ptp->rc && !ptp->hReply)
1373       {
1374       TCHAR szFilename[ MAX_PATH ];
1375       TCHAR szSvrName[ cchRESOURCE ];
1376       lpp->lpiServer->GetServerName (szSvrName);
1377       CopyBaseFileName (szFilename, lpp->szUninstall);
1378       ErrorDialog (ptp->status, IDS_ERROR_CANT_UNINSTALL_FILE, TEXT("%s%s"), szSvrName, szFilename);
1379       }
1380
1381    Delete (lpp);
1382    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1383 }
1384
1385
1386 void Task_Svr_Prune (LPTASKPACKET ptp)
1387 {
1388    LPSVR_PRUNE_PARAMS lpp = (LPSVR_PRUNE_PARAMS)(ptp->lpUser);
1389
1390    ptp->rc = AfsClass_PruneOldFiles (lpp->lpiServer, lpp->fBAK, lpp->fOLD, lpp->fCore, &ptp->status);
1391
1392    if (!ptp->rc && !ptp->hReply)
1393       {
1394       TCHAR szSvrName[ cchRESOURCE ];
1395       lpp->lpiServer->GetServerName (szSvrName);
1396       ErrorDialog (ptp->status, IDS_ERROR_CANT_PRUNE_FILES, TEXT("%s"), szSvrName);
1397       }
1398
1399    Delete (lpp);
1400    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1401 }
1402
1403
1404 void Task_Svr_GetDates (LPTASKPACKET ptp)
1405 {
1406    LPSVR_GETDATES_PARAMS lpp = (LPSVR_GETDATES_PARAMS)(ptp->lpUser);
1407
1408    SYSTEMTIME stFile;
1409    SYSTEMTIME stOLD;
1410    SYSTEMTIME stBAK;
1411
1412    ptp->rc = AfsClass_GetFileDates (lpp->lpiServer, lpp->szFilename, &stFile, &stBAK, &stOLD, &ptp->status);
1413
1414    if (ptp->rc)
1415       {
1416       TCHAR szText[ cchRESOURCE ];
1417       if (FormatTime (szText, TEXT("%s"), &stFile))
1418          TASKDATA(ptp)->pszText1 = CloneString (szText);
1419
1420       if (FormatTime (szText, TEXT("%s"), &stBAK))
1421          TASKDATA(ptp)->pszText2 = CloneString (szText);
1422
1423       if (FormatTime (szText, TEXT("%s"), &stOLD))
1424          TASKDATA(ptp)->pszText3 = CloneString (szText);
1425       }
1426
1427    Delete (lpp);
1428    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1429 }
1430
1431
1432 void Task_Svr_Execute (LPTASKPACKET ptp)
1433 {
1434    LPSVR_EXECUTE_PARAMS lpp = (LPSVR_EXECUTE_PARAMS)(ptp->lpUser);
1435
1436    ptp->rc = AfsClass_ExecuteCommand (lpp->lpiServer, lpp->szCommand, &ptp->status);
1437
1438    if (!ptp->rc)
1439       {
1440       TCHAR szServer[ cchNAME ];
1441       lpp->lpiServer->GetServerName (szServer);
1442       ErrorDialog (ptp->status, IDS_ERROR_CANT_EXECUTE_COMMAND, TEXT("%s%s"), szServer, lpp->szCommand);
1443       }
1444
1445    Delete (lpp);
1446    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1447 }
1448
1449
1450 void Task_Svr_SetAuth (LPTASKPACKET ptp)
1451 {
1452    LPSVR_SETAUTH_PARAMS lpp = (LPSVR_SETAUTH_PARAMS)(ptp->lpUser);
1453
1454    ptp->rc = AfsClass_SetServerAuth (lpp->lpiServer, lpp->fEnableAuth, &ptp->status);
1455
1456    if (!ptp->rc)
1457       {
1458       TCHAR szServer[ cchNAME ];
1459       lpp->lpiServer->GetServerName (szServer);
1460       ErrorDialog (ptp->status, (lpp->fEnableAuth) ? IDS_ERROR_CANT_AUTH_ON : IDS_ERROR_CANT_AUTH_OFF, TEXT("%s"), szServer);
1461       }
1462
1463    Delete (lpp);
1464    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1465 }
1466
1467
1468 void Task_Svr_AdmList_Open (LPTASKPACKET ptp)
1469 {
1470    LPIDENT lpiServer = (LPIDENT)(ptp->lpUser);
1471
1472    if ((TASKDATA(ptp)->lpAdmList = AfsClass_AdminList_Load (lpiServer, &ptp->status)) == NULL)
1473       {
1474       ptp->rc = FALSE;
1475
1476       TCHAR szServer[ cchNAME ];
1477       lpiServer->GetServerName (szServer);
1478       ErrorDialog (ptp->status, IDS_ERROR_CANT_LOAD_ADMLIST, TEXT("%s"), szServer);
1479       }
1480 }
1481
1482
1483 void Task_Svr_AdmList_Save (LPTASKPACKET ptp)
1484 {
1485    LPADMINLIST lpAdmList = (LPADMINLIST)(ptp->lpUser);
1486
1487    // Increment the reference counter on this admin list before handing
1488    // it off to the Save routine, as that routine will be posting
1489    // notifications using its handle. When our notification handler
1490    // receives the End notification, it will attempt to free the list--
1491    // which will decrement the counter again, and actually free the list
1492    // if the counter hits zero.
1493    //
1494    InterlockedIncrement (&lpAdmList->cRef);
1495
1496    ptp->rc = AfsClass_AdminList_Save (lpAdmList, &ptp->status);
1497
1498    if (!ptp->rc)
1499       {
1500       TCHAR szServer[ cchNAME ];
1501       lpAdmList->lpiServer->GetServerName (szServer);
1502       ErrorDialog (ptp->status, IDS_ERROR_CANT_SAVE_ADMLIST, TEXT("%s"), szServer);
1503       }
1504
1505    AfsClass_AdminList_Free (lpAdmList);
1506    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1507 }
1508
1509
1510 void Task_Svr_KeyList_Open (LPTASKPACKET ptp)
1511 {
1512    LPIDENT lpiServer = (LPIDENT)(ptp->lpUser);
1513
1514    if ((TASKDATA(ptp)->lpKeyList = AfsClass_KeyList_Load (lpiServer, &ptp->status)) == NULL)
1515       {
1516       ptp->rc = FALSE;
1517
1518       TCHAR szServer[ cchNAME ];
1519       lpiServer->GetServerName (szServer);
1520       ErrorDialog (ptp->status, IDS_ERROR_CANT_LOAD_KEYLIST, TEXT("%s"), szServer);
1521       }
1522 }
1523
1524
1525 void Task_Svr_Key_Create (LPTASKPACKET ptp)
1526 {
1527    LPKEY_CREATE_PARAMS lpp = (LPKEY_CREATE_PARAMS)(ptp->lpUser);
1528
1529    if (lpp->szString[0])
1530       ptp->rc = AfsClass_AddKey (lpp->lpiServer, lpp->keyVersion, lpp->szString, &ptp->status);
1531    else
1532       ptp->rc = AfsClass_AddKey (lpp->lpiServer, lpp->keyVersion, &lpp->key, &ptp->status);
1533
1534    if ((TASKDATA(ptp)->lpKeyList = AfsClass_KeyList_Load (lpp->lpiServer, &ptp->status)) == NULL)
1535       {
1536       ptp->rc = FALSE;
1537
1538       TCHAR szServer[ cchNAME ];
1539       lpp->lpiServer->GetServerName (szServer);
1540       ErrorDialog (ptp->status, IDS_ERROR_CANT_CREATE_KEY, TEXT("%s"), szServer);
1541       }
1542
1543    Delete (lpp);
1544    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1545 }
1546
1547
1548 void Task_Svr_Key_Delete (LPTASKPACKET ptp)
1549 {
1550    LPKEY_DELETE_PARAMS lpp = (LPKEY_DELETE_PARAMS)(ptp->lpUser);
1551
1552    if (!AfsClass_DeleteKey (lpp->lpiServer, lpp->keyVersion, &ptp->status))
1553       {
1554       ptp->rc = FALSE;
1555
1556       TCHAR szServer[ cchNAME ];
1557       lpp->lpiServer->GetServerName (szServer);
1558       ErrorDialog (ptp->status, IDS_ERROR_CANT_DELETE_KEY, TEXT("%s%lu"), szServer, lpp->keyVersion);
1559       }
1560
1561    Delete (lpp);
1562    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1563 }
1564
1565
1566 void Task_Svr_GetRandomKey (LPTASKPACKET ptp)
1567 {
1568    LPIDENT lpiServer = (LPIDENT)(ptp->lpUser);
1569
1570    if (!AfsClass_GetRandomKey (lpiServer, &TASKDATA(ptp)->key, &ptp->status))
1571       {
1572       ptp->rc = FALSE;
1573
1574       TCHAR szServer[ cchNAME ];
1575       lpiServer->GetServerName (szServer);
1576       ErrorDialog (ptp->status, IDS_ERROR_CANT_GETRANDOMKEY, TEXT("%s"), szServer);
1577       }
1578 }
1579
1580
1581 void Task_Svr_HostList_Open (LPTASKPACKET ptp)
1582 {
1583    LPIDENT lpiServer = (LPIDENT)(ptp->lpUser);
1584
1585    if ((TASKDATA(ptp)->lpHostList = AfsClass_HostList_Load (lpiServer, &ptp->status)) == NULL)
1586       {
1587       ptp->rc = FALSE;
1588
1589       TCHAR szServer[ cchNAME ];
1590       lpiServer->GetServerName (szServer);
1591       ErrorDialog (ptp->status, IDS_ERROR_CANT_LOAD_HOSTLIST, TEXT("%s"), szServer);
1592       }
1593 }
1594
1595
1596 void Task_Svr_HostList_Save (LPTASKPACKET ptp)
1597 {
1598    LPHOSTLIST lpHostList = (LPHOSTLIST)(ptp->lpUser);
1599
1600    // Increment the reference counter on this admin list before handing
1601    // it off to the Save routine, as that routine will be posting
1602    // notifications using its handle. When our notification handler
1603    // receives the End notification, it will attempt to free the list--
1604    // which will decrement the counter again, and actually free the list
1605    // if the counter hits zero.
1606    //
1607    InterlockedIncrement (&lpHostList->cRef);
1608
1609    ptp->rc = AfsClass_HostList_Save (lpHostList, &ptp->status);
1610
1611    if (!ptp->rc)
1612       {
1613       TCHAR szServer[ cchNAME ];
1614       lpHostList->lpiServer->GetServerName (szServer);
1615       ErrorDialog (ptp->status, IDS_ERROR_CANT_SAVE_HOSTLIST, TEXT("%s"), szServer);
1616       }
1617
1618    AfsClass_HostList_Free (lpHostList);
1619    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1620 }
1621
1622
1623 void Task_Svr_Monitor_OnOff (LPTASKPACKET ptp)
1624 {
1625    LPIDENT lpiServer = (LPIDENT)(ptp->lpUser);
1626
1627    LPSERVER lpServer;
1628    if ((lpServer = lpiServer->OpenServer()) != NULL)
1629       {
1630       BOOL fMonitored = lpServer->fIsMonitored();
1631
1632       g.sub = Subsets_SetMonitor (g.sub, lpiServer, !fMonitored);
1633
1634       lpServer->SetMonitor (!fMonitored);
1635
1636       lpServer->Close();
1637       }
1638 }
1639
1640
1641 void Task_Svr_ChangeAddr (LPTASKPACKET ptp)
1642 {
1643    LPSVR_CHANGEADDR_PARAMS lpp = (LPSVR_CHANGEADDR_PARAMS)(ptp->lpUser);
1644
1645    if ((ptp->rc = AfsClass_ChangeAddress (lpp->lpiServer, &lpp->ssOld, &lpp->ssNew, &ptp->status)) == FALSE)
1646       {
1647       TCHAR szName[ cchRESOURCE ];
1648       lpp->lpiServer->GetServerName (szName);
1649       ErrorDialog (ptp->status, IDS_ERROR_CANT_CHANGEADDR, TEXT("%s"), szName);
1650       }
1651
1652    Delete (lpp);
1653    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1654 }
1655
1656
1657 void Task_Svc_Menu (LPTASKPACKET ptp)
1658 {
1659    TASKDATA(ptp)->mt = *(LPMENUTASK)(ptp->lpUser);
1660    Delete ((LPMENUTASK)(ptp->lpUser));
1661    ptp->lpUser = NULL;  // we deleted this; don't let the caller use it again.
1662
1663    if (TASKDATA(ptp)->mt.lpi && TASKDATA(ptp)->mt.lpi->fIsService())
1664       {
1665       LPSERVICE lpService;
1666       if ((lpService = TASKDATA(ptp)->mt.lpi->OpenService (&ptp->status)) == NULL)
1667          ptp->rc = FALSE;
1668       else
1669          {
1670          if (!lpService->GetStatus (&TASKDATA(ptp)->cs, FALSE, &ptp->status))
1671             ptp->rc = FALSE;
1672          lpService->Close();
1673          }
1674       }
1675 }
1676
1677
1678 void Task_Svc_Prop_Init (LPTASKPACKET ptp)
1679 {
1680    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
1681
1682    LPSERVICE lpService;
1683    if ((lpService = lpi->OpenService (&ptp->status)) == NULL)
1684       ptp->rc = FALSE;
1685    else
1686       {
1687       if (!lpService->GetStatus (&TASKDATA(ptp)->cs, TRUE, &ptp->status))
1688          {
1689          ptp->rc = FALSE;
1690          }
1691       else if ((TASKDATA(ptp)->lpcp = (LPSERVICE_PREF)lpi->GetUserParam()) == NULL)
1692          {
1693          ptp->rc = FALSE;
1694          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
1695          }
1696       lpService->Close();
1697       }
1698
1699    if (ptp->rc)
1700       {
1701       if ((TASKDATA(ptp)->lpsp = (LPSERVER_PREF)lpi->GetServer()->GetUserParam()) == NULL)
1702          {
1703          ptp->rc = FALSE;
1704          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
1705          }
1706       }
1707 }
1708
1709
1710 void Task_Svc_Prop_Apply (LPTASKPACKET ptp)
1711 {
1712    LPSVC_PROP_APPLY_PACKET lpp = (LPSVC_PROP_APPLY_PACKET)(ptp->lpUser);
1713
1714    LPSERVICE lpService;
1715    if ((lpService = lpp->lpi->OpenService (&ptp->status)) == NULL)
1716       ptp->rc = FALSE;
1717    else
1718       {
1719       LPSERVICE_PREF lpcp = NULL;
1720       if ((lpcp = (LPSERVICE_PREF)lpp->lpi->GetUserParam()) == NULL)
1721          {
1722          ptp->rc = FALSE;
1723          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
1724          }
1725       else
1726          {
1727          LPIDENT lpiServer;
1728          if ((lpiServer = lpp->lpi->GetServer()) != NULL)
1729             {
1730             LPSERVER_PREF lpsp;
1731             if ((lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) != NULL)
1732                {
1733                if (lpsp->fWarnSvcStop)
1734                   lpcp->fWarnSvcStop = lpp->fIDC_SVC_WARNSTOP;
1735                }
1736             }
1737
1738          if (!Services_SavePreferences (lpp->lpi))
1739             {
1740             ptp->rc = FALSE;
1741             ptp->status = GetLastError();
1742             }
1743          }
1744
1745       lpService->Close();
1746       }
1747
1748    (void)Alert_Scout_QueueCheckServer (lpp->lpi);
1749
1750    Delete (lpp);
1751    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1752 }
1753
1754
1755 void Task_Svc_Start (LPTASKPACKET ptp)
1756 {
1757    LPSVC_START_PARAMS lpp = (LPSVC_START_PARAMS)(ptp->lpUser);
1758
1759    if (!AfsClass_StartService (lpp->lpiStart, lpp->fTemporary, &ptp->status))
1760       ptp->rc = FALSE;
1761
1762    if (!ptp->rc && !ptp->hReply)
1763       {
1764       TCHAR szSvrName[ cchRESOURCE ];
1765       TCHAR szSvcName[ cchRESOURCE ];
1766       lpp->lpiStart->GetServerName (szSvrName);
1767       lpp->lpiStart->GetServiceName (szSvcName);
1768       ErrorDialog (ptp->status, IDS_ERROR_CANT_START_SERVICE, TEXT("%s%s"), szSvrName, szSvcName);
1769       }
1770
1771    Delete (lpp);
1772    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1773 }
1774
1775
1776 void Task_Svc_Stop (LPTASKPACKET ptp)
1777 {
1778    LPSVC_STOP_PARAMS lpp = (LPSVC_STOP_PARAMS)(ptp->lpUser);
1779
1780    if (!AfsClass_StopService (lpp->lpiStop, lpp->fTemporary, TRUE, &ptp->status))
1781       ptp->rc = FALSE;
1782
1783    if (!ptp->rc && !ptp->hReply)
1784       {
1785       TCHAR szSvrName[ cchRESOURCE ];
1786       TCHAR szSvcName[ cchRESOURCE ];
1787       lpp->lpiStop->GetServerName (szSvrName);
1788       lpp->lpiStop->GetServiceName (szSvcName);
1789       ErrorDialog (ptp->status, IDS_ERROR_CANT_STOP_SERVICE, TEXT("%s%s"), szSvrName, szSvcName);
1790       }
1791
1792    Delete (lpp);
1793    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1794 }
1795
1796
1797 void Task_Svc_Restart (LPTASKPACKET ptp)
1798 {
1799    LPIDENT lpiService = (LPIDENT)(ptp->lpUser);
1800
1801    if (!AfsClass_RestartService (lpiService, &ptp->status))
1802       ptp->rc = FALSE;
1803
1804    if (!ptp->rc && !ptp->hReply)
1805       {
1806       TCHAR szSvrName[ cchRESOURCE ];
1807       TCHAR szSvcName[ cchRESOURCE ];
1808       lpiService->GetServerName (szSvrName);
1809       lpiService->GetServiceName (szSvcName);
1810       ErrorDialog (ptp->status, IDS_ERROR_CANT_RESTART_SERVICE, TEXT("%s%s"), szSvrName, szSvcName);
1811       }
1812 }
1813
1814
1815 void Task_Svc_FindLog (LPTASKPACKET ptp)
1816 {
1817    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
1818
1819    if ((TASKDATA(ptp)->lpcp = (LPSERVICE_PREF)lpi->GetUserParam()) == NULL)
1820       {
1821       ptp->rc = FALSE;
1822       ptp->status = ERROR_NOT_ENOUGH_MEMORY;
1823       }
1824
1825    if (ptp->rc)
1826       {
1827       if (TASKDATA(ptp)->lpcp->szLogFile[0] == TEXT('\0'))
1828          {
1829          ptp->rc = FALSE;
1830          ptp->status = ERROR_FILE_NOT_FOUND;
1831          }
1832       }
1833
1834    if (ptp->rc)
1835       {
1836       if ((TASKDATA(ptp)->pszText1 = CloneString (TASKDATA(ptp)->lpcp->szLogFile)) == NULL)
1837          {
1838          ptp->rc = FALSE;
1839          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
1840          }
1841       }
1842 }
1843
1844
1845 void Task_Svc_ViewLog (LPTASKPACKET ptp)
1846 {
1847    LPSVC_VIEWLOG_PACKET lpp = (LPSVC_VIEWLOG_PACKET)(ptp->lpUser);
1848
1849    TCHAR szTempPath[ MAX_PATH ];
1850    GetTempPath (MAX_PATH, szTempPath);
1851
1852    TCHAR szFilename[ MAX_PATH ];
1853    GetTempFileName (szTempPath, TEXT("log"), 0, szFilename);
1854
1855    if (!AfsClass_GetServerLogFile (lpp->lpiServer, szFilename, lpp->szRemote, &ptp->status))
1856       {
1857       DeleteFile (szFilename);
1858       ptp->rc = FALSE;
1859       }
1860
1861    if (ptp->rc)
1862       {
1863       if ((TASKDATA(ptp)->pszText1 = CloneString (szFilename)) == NULL)
1864          {
1865          ptp->rc = FALSE;
1866          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
1867          }
1868       }
1869
1870    Delete (lpp);
1871    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1872 }
1873
1874
1875 void Task_Svc_Create (LPTASKPACKET ptp)
1876 {
1877    LPSVC_CREATE_PARAMS lpp = (LPSVC_CREATE_PARAMS)(ptp->lpUser);
1878
1879    LPIDENT lpiService;
1880    if ((lpiService = AfsClass_CreateService (lpp->lpiServer, lpp->szService, lpp->szCommand, lpp->szParams, lpp->szNotifier, lpp->type, &lpp->stIfCron, &ptp->status)) == NULL)
1881       {
1882       ptp->rc = FALSE;
1883       }
1884
1885    if (ptp->rc)
1886       {
1887       // Start it if necessary
1888       //
1889       if ((lpp->type == SERVICETYPE_SIMPLE) && (lpp->fRunNow))
1890          {
1891          if (!AfsClass_StartService (lpiService, FALSE, &ptp->status))
1892             {
1893             ptp->rc = FALSE;
1894             }
1895          }
1896       }
1897
1898    if (ptp->rc && lpp->szLogFile[0])
1899       {
1900       LPSERVICE_PREF lpsp;
1901       if ((lpsp = (LPSERVICE_PREF)lpiService->GetUserParam()) != NULL)
1902          {
1903          lstrcpy (lpsp->szLogFile, lpp->szLogFile);
1904
1905          if (!Services_SavePreferences (lpiService))
1906             {
1907             ptp->rc = FALSE;
1908             ptp->status = ERROR_NOT_ENOUGH_MEMORY;
1909             }
1910          }
1911       }
1912
1913    if (!ptp->rc)
1914       {
1915       TCHAR szServer[ cchNAME ];
1916       lpp->lpiServer->GetServerName (szServer);
1917       ErrorDialog (ptp->status, IDS_ERROR_CANT_CREATE_SERVICE, TEXT("%s%s"), szServer, lpp->szService);
1918       }
1919
1920    Delete (lpp);
1921    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1922 }
1923
1924
1925 void Task_Svc_Delete (LPTASKPACKET ptp)
1926 {
1927    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
1928
1929    ptp->rc = AfsClass_DeleteService (lpi, &ptp->status);
1930
1931    if (!ptp->rc)
1932       {
1933       TCHAR szServer[ cchNAME ];
1934       TCHAR szService[ cchNAME ];
1935       lpi->GetServerName (szServer);
1936       lpi->GetServiceName (szService);
1937       ErrorDialog (ptp->status, IDS_ERROR_CANT_DELETE_SERVICE, TEXT("%s%s"), szServer, szService);
1938       }
1939 }
1940
1941
1942 void Task_Svc_GetRestartTimes (LPTASKPACKET ptp)
1943 {
1944    LPSVC_RESTARTTIMES_PARAMS lpp = (LPSVC_RESTARTTIMES_PARAMS)(ptp->lpUser);
1945
1946    ptp->rc = AfsClass_GetRestartTimes (lpp->lpi, &lpp->fGeneral, &lpp->stGeneral, &lpp->fNewBinary, &lpp->stNewBinary, &ptp->status);
1947
1948    if (!ptp->rc)
1949       {
1950       lpp->fGeneral = FALSE;
1951       lpp->fNewBinary = FALSE;
1952
1953       TCHAR szSvrName[ cchNAME ];
1954       lpp->lpi->GetServerName (szSvrName);
1955       ErrorDialog (ptp->status, IDS_ERROR_REFRESH_SERVICE_STATUS, TEXT("%s%s"), szSvrName, TEXT("BOS"));
1956       }
1957
1958    if (!ptp->hReply)
1959       {
1960       Delete (lpp);
1961       ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1962       }
1963 }
1964
1965
1966 void Task_Svc_SetRestartTimes (LPTASKPACKET ptp)
1967 {
1968    LPSVC_RESTARTTIMES_PARAMS lpp = (LPSVC_RESTARTTIMES_PARAMS)(ptp->lpUser);
1969
1970    ptp->rc = AfsClass_SetRestartTimes (lpp->lpi, ((lpp->fGeneral) ? &lpp->stGeneral : NULL), ((lpp->fNewBinary) ? &lpp->stNewBinary : NULL), &ptp->status);
1971
1972    if (!ptp->rc)
1973       {
1974       TCHAR szSvrName[ cchNAME ];
1975       lpp->lpi->GetServerName (szSvrName);
1976       ErrorDialog (ptp->status, IDS_ERROR_CANT_SET_RESTART_TIMES, TEXT("%s"), szSvrName);
1977       }
1978
1979    if (!ptp->hReply)
1980       {
1981       Delete (lpp);
1982       ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
1983       }
1984 }
1985
1986
1987 void Task_Agg_Prop_Init (LPTASKPACKET ptp)
1988 {
1989    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
1990
1991    LPAGGREGATE lpAggregate;
1992    if ((lpAggregate = lpi->OpenAggregate (&ptp->status)) == NULL)
1993       ptp->rc = FALSE;
1994    else
1995       {
1996       if (!lpAggregate->GetStatus (&TASKDATA(ptp)->as, TRUE, &ptp->status))
1997          {
1998          ptp->rc = FALSE;
1999          }
2000
2001       if ((TASKDATA(ptp)->lpap = (LPAGGREGATE_PREF)lpAggregate->GetUserParam()) == NULL)
2002          {
2003          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
2004          ptp->rc = FALSE;
2005          }
2006
2007       TCHAR szText[ cchRESOURCE ];
2008       lpAggregate->GetDevice (szText);
2009       TASKDATA(ptp)->pszText1 = CloneString (szText);
2010
2011       if (ptp->rc)
2012          {
2013          TASKDATA(ptp)->nFilesets = 0;
2014
2015          HENUM hEnum;
2016          for (LPFILESET lpFileset = lpAggregate->FilesetFindFirst (&hEnum); lpFileset; lpFileset = lpAggregate->FilesetFindNext (&hEnum))
2017             {
2018             (TASKDATA(ptp)->nFilesets)++;
2019             lpFileset->Close();
2020             }
2021          }
2022
2023       lpAggregate->Close();
2024       }
2025
2026    if (ptp->rc)
2027       {
2028       if ((TASKDATA(ptp)->lpsp = (LPSERVER_PREF)lpi->GetServer()->GetUserParam()) == NULL)
2029          {
2030          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
2031          ptp->rc = FALSE;
2032          }
2033       }
2034 }
2035
2036
2037 void Task_Agg_Prop_Apply (LPTASKPACKET ptp)
2038 {
2039    LPAGG_PROP_APPLY_PACKET lpp = (LPAGG_PROP_APPLY_PACKET)(ptp->lpUser);
2040
2041    LPAGGREGATE_PREF lpap;
2042    if ((lpap = (LPAGGREGATE_PREF)lpp->lpi->GetAggregate()->GetUserParam()) == NULL)
2043       {
2044       ptp->status = ERROR_NOT_ENOUGH_MEMORY;
2045       ptp->rc = FALSE;
2046       }
2047    else
2048       {
2049       LPIDENT lpiServer;
2050       if ((lpiServer = lpp->lpi->GetServer()) != NULL)
2051          {
2052          LPSERVER_PREF lpsp;
2053          if ((lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) != NULL)
2054             {
2055             if (lpsp->fWarnAggAlloc)
2056                lpap->fWarnAggAlloc = lpp->fIDC_AGG_WARNALLOC;
2057             }
2058          }
2059
2060       if (!lpp->fIDC_AGG_WARN)
2061          lpap->perWarnAggFull = 0;
2062       else if (lpp->fIDC_AGG_WARN_AGGFULL_DEF)
2063          lpap->perWarnAggFull = -1;
2064       else
2065          lpap->perWarnAggFull = lpp->wIDC_AGG_WARN_AGGFULL_PERCENT;
2066
2067       if (!Aggregates_SavePreferences (lpp->lpi))
2068          {
2069          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
2070          ptp->rc = FALSE;
2071          }
2072
2073       (void)Alert_Scout_QueueCheckServer (lpp->lpi);
2074       }
2075
2076    Delete (lpp);
2077    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2078 }
2079
2080
2081 void Task_Agg_Find_Quota_Limits (LPTASKPACKET ptp)
2082 {
2083    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
2084
2085    TASKDATA(ptp)->ckMin = ckQUOTA_MINIMUM;
2086    TASKDATA(ptp)->ckMax = ckQUOTA_MAXIMUM;
2087
2088    if (lpi && (lpi->fIsAggregate() || lpi->fIsFileset()))
2089       {
2090       LPAGGREGATE lpAggregate;
2091       if ((lpAggregate = lpi->OpenAggregate (&ptp->status)) == NULL)
2092          ptp->rc = FALSE;
2093       else
2094          {
2095          AGGREGATESTATUS as;
2096          if (!lpAggregate->GetStatus (&as, TRUE, &ptp->status))
2097             ptp->rc = FALSE;
2098          else
2099             {
2100             TASKDATA(ptp)->ckMax = max( 1L, as.ckStorageTotal );
2101             }
2102          lpAggregate->Close();
2103          }
2104       }
2105 }
2106
2107
2108 void Task_Agg_Enum_To_ListView (LPTASKPACKET ptp)
2109 {
2110    LPAGG_ENUM_TO_LISTVIEW_PACKET lpp = (LPAGG_ENUM_TO_LISTVIEW_PACKET)(ptp->lpUser);
2111
2112    UpdateDisplay_Aggregates (TRUE, lpp->hList, NULL, 0, lpp->lpiServer, lpp->lpiSelect, lpp->lpvi);
2113
2114    Delete (lpp);
2115    ptp->lpUser = NULL;  // we deleted this; don't let the caller use it again.
2116 }
2117
2118
2119 void Task_Agg_Enum_To_ComboBox (LPTASKPACKET ptp)
2120 {
2121    LPAGG_ENUM_TO_COMBOBOX_PACKET lpp = (LPAGG_ENUM_TO_COMBOBOX_PACKET)(ptp->lpUser);
2122
2123    UpdateDisplay_Aggregates (TRUE, lpp->hCombo, NULL, 0, lpp->lpiServer, lpp->lpiSelect, NULL);
2124
2125    Delete (lpp);
2126    ptp->lpUser = NULL;  // we deleted this; don't let the caller use it again.
2127 }
2128
2129
2130 void Task_Agg_Find_Ghost (LPTASKPACKET ptp)
2131 {
2132    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
2133
2134    LPAGGREGATE lpAggregate;
2135    if ((lpAggregate = lpi->OpenAggregate (&ptp->status)) == NULL)
2136       ptp->rc = FALSE;
2137    else
2138       {
2139       TASKDATA(ptp)->wGhost = lpAggregate->GetGhostStatus();
2140       lpAggregate->Close();
2141       }
2142 }
2143
2144
2145 void Task_Set_Enum_To_ComboBox (LPTASKPACKET ptp)
2146 {
2147    LPSET_ENUM_TO_COMBOBOX_PACKET lpp = (LPSET_ENUM_TO_COMBOBOX_PACKET)(ptp->lpUser);
2148
2149    UpdateDisplay_Filesets (TRUE, lpp->hCombo, NULL, 0, lpp->lpiServer, lpp->lpiAggregate, lpp->lpiSelect);
2150
2151    Delete (lpp);
2152    ptp->lpUser = NULL;  // we deleted this; don't let the caller use it again.
2153 }
2154
2155
2156 void Task_Set_Find_Ghost (LPTASKPACKET ptp)
2157 {
2158    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
2159
2160    LPFILESET lpFileset;
2161    if ((lpFileset = lpi->OpenFileset (&ptp->status)) == NULL)
2162       ptp->rc = FALSE;
2163    else
2164       {
2165       TASKDATA(ptp)->wGhost = lpFileset->GetGhostStatus();
2166       TASKDATA(ptp)->fHasReplicas = FALSE;
2167
2168       if (!lpFileset->GetStatus (&TASKDATA(ptp)->fs))
2169          {
2170          TASKDATA(ptp)->fs.Type = ftREADWRITE;
2171          }
2172       else if (TASKDATA(ptp)->fs.Type == ftREADWRITE)
2173          {
2174          HENUM hEnum;
2175          for (LPIDENT lpiSearch = IDENT::FindFirst (&hEnum, &TASKDATA(ptp)->fs.idReplica); lpiSearch; lpiSearch = IDENT::FindNext (&hEnum))
2176             {
2177             LPFILESET lpReplica;
2178             if ((lpReplica = lpiSearch->OpenFileset()) != NULL)
2179                {
2180                lpReplica->Close();
2181                TASKDATA(ptp)->fHasReplicas = TRUE;
2182                break;
2183                }
2184             }
2185          IDENT::FindClose (&hEnum);
2186          }
2187
2188       lpFileset->Close();
2189       }
2190 }
2191
2192
2193 void Task_Set_Create (LPTASKPACKET ptp)
2194 {
2195    LPSET_CREATE_PARAMS lpp = (LPSET_CREATE_PARAMS)(ptp->lpUser);
2196
2197    LPIDENT lpiFileset;
2198    if ((lpiFileset = AfsClass_CreateFileset (lpp->lpiParent, lpp->szName, lpp->ckQuota, &ptp->status)) == NULL)
2199       ptp->rc = FALSE;
2200
2201    if (ptp->rc && lpp->fCreateClone)
2202       {
2203       ptp->rc = AfsClass_Clone (lpiFileset, &ptp->status);
2204       }
2205
2206    if (ptp->rc)
2207       {
2208       TASKDATA(ptp)->lpi = lpiFileset;
2209       }
2210    else
2211       {
2212       TCHAR szServer[ cchNAME ];
2213       TCHAR szAggregate[ cchNAME ];
2214       lpp->lpiParent->GetServerName (szServer);
2215       lpp->lpiParent->GetAggregateName (szAggregate);
2216       ErrorDialog (ptp->status, IDS_ERROR_CANT_CREATE_FILESET, TEXT("%s%s%s"), szServer, szAggregate, lpp->szName);
2217       }
2218
2219    Delete (lpp);
2220    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2221 }
2222
2223
2224 void Task_Set_Delete (LPTASKPACKET ptp)
2225 {
2226    LPSET_DELETE_PARAMS lpp = (LPSET_DELETE_PARAMS)(ptp->lpUser);
2227
2228    // First, what kind of fileset are we deleting here?
2229    //
2230    LPIDENT lpiClone = NULL;
2231    FILESETTYPE setType = ftREADWRITE;
2232    LPFILESET lpFileset;
2233    if ((lpFileset = lpp->lpiFileset->OpenFileset (&ptp->status)) == NULL)
2234       ptp->rc = FALSE;
2235    else
2236       {
2237       lpiClone = lpFileset->GetCloneIdentifier();
2238
2239       if (lpFileset->GetStatus (&TASKDATA(ptp)->fs))
2240          setType = TASKDATA(ptp)->fs.Type;
2241
2242       lpFileset->Close();
2243       }
2244
2245    // Delete the fileset in whichever way is appropriate
2246    //
2247    if (setType == ftREADWRITE)
2248       {
2249       if (lpp->fVLDB && lpiClone)
2250          {
2251          LPFILESET lpClone;
2252          if ((lpClone = lpiClone->OpenFileset()) != NULL) // clone really there?
2253             {
2254             lpClone->Close();
2255
2256             if (!AfsClass_DeleteClone (lpiClone, &ptp->status))
2257                ptp->rc = FALSE;
2258             }
2259          }
2260       if (ptp->rc)
2261          {
2262          if (!AfsClass_DeleteFileset (lpp->lpiFileset, lpp->fVLDB, lpp->fServer, &ptp->status))
2263             ptp->rc = FALSE;
2264          }
2265       }
2266    else if (setType == ftREPLICA)
2267       {
2268       if (!AfsClass_DeleteReplica (lpp->lpiFileset, &ptp->status))
2269          ptp->rc = FALSE;
2270       }
2271    else if (setType == ftCLONE)
2272       {
2273       if (!AfsClass_DeleteClone (lpp->lpiFileset, &ptp->status))
2274          ptp->rc = FALSE;
2275       }
2276
2277    // Clean up
2278    //
2279    if ( (!ptp->rc) ||
2280         (!lpp->fVLDB   && (lpp->wGhost & GHOST_HAS_VLDB_ENTRY)) ||
2281         (!lpp->fServer && (lpp->wGhost & GHOST_HAS_SERVER_ENTRY)) )
2282       {
2283       Alert_Scout_QueueCheckServer (lpp->lpiFileset->GetServer());
2284       }
2285
2286    if (!ptp->rc)
2287       {
2288       TCHAR szServer[ cchNAME ];
2289       TCHAR szAggregate[ cchNAME ];
2290       TCHAR szFileset[ cchNAME ];
2291       lpp->lpiFileset->GetServerName (szServer);
2292       lpp->lpiFileset->GetAggregateName (szAggregate);
2293       lpp->lpiFileset->GetFilesetName (szFileset);
2294       ErrorDialog (ptp->status, IDS_ERROR_CANT_DELETE_FILESET, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
2295       }
2296
2297    Delete (lpp);
2298    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2299 }
2300
2301
2302 void Task_Set_Move (LPTASKPACKET ptp)
2303 {
2304    LPSET_MOVE_PARAMS lpp = (LPSET_MOVE_PARAMS)(ptp->lpUser);
2305
2306    BOOL fIsReplica = FALSE;
2307
2308    LPFILESET lpFileset;
2309    if ((lpFileset = lpp->lpiSource->OpenFileset (&ptp->status)) == NULL)
2310       ptp->rc = FALSE;
2311    else
2312       {
2313       FILESETSTATUS fs;
2314       if (!lpFileset->GetStatus (&fs, TRUE, &ptp->status))
2315          ptp->rc = FALSE;
2316       else
2317          {
2318          if (fs.Type == ftREPLICA)
2319             fIsReplica = TRUE;
2320          }
2321       lpFileset->Close();
2322       }
2323
2324    if (ptp->rc)
2325       {
2326       if (fIsReplica)
2327          {
2328          if (!AfsClass_MoveReplica (lpp->lpiSource, lpp->lpiTarget, &ptp->status))
2329             ptp->rc = FALSE;
2330          }
2331       else
2332          {
2333          if (!AfsClass_MoveFileset (lpp->lpiSource, lpp->lpiTarget, &ptp->status))
2334             ptp->rc = FALSE;
2335          }
2336       }
2337
2338    if (!ptp->rc)
2339       {
2340       TCHAR szServerSource[ cchNAME ];
2341       TCHAR szServerTarget[ cchNAME ];
2342       TCHAR szAggregateSource[ cchNAME ];
2343       TCHAR szAggregateTarget[ cchNAME ];
2344       TCHAR szFileset[ cchNAME ];
2345       lpp->lpiSource->GetServerName (szServerSource);
2346       lpp->lpiSource->GetAggregateName (szAggregateSource);
2347       lpp->lpiSource->GetFilesetName (szFileset);
2348       lpp->lpiTarget->GetServerName (szServerTarget);
2349       lpp->lpiTarget->GetAggregateName (szAggregateTarget);
2350       ErrorDialog (ptp->status, IDS_ERROR_MOVE_FILESET, TEXT("%s%s%s%s%s"), szServerSource, szAggregateSource, szFileset, szServerTarget, szAggregateTarget);
2351       }
2352
2353    Delete (lpp);
2354    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2355 }
2356
2357
2358 void Task_Set_MoveTo_Init (LPTASKPACKET ptp)
2359 {
2360    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
2361
2362    LPFILESET lpFileset;
2363    if ((lpFileset = lpi->OpenFileset (&ptp->status)) == NULL)
2364       ptp->rc = FALSE;
2365    else
2366       {
2367       if (!lpFileset->GetStatus (&TASKDATA(ptp)->fs, TRUE, &ptp->status))
2368          ptp->rc = FALSE;
2369       lpFileset->Close();
2370       }
2371 }
2372
2373
2374 void Task_Set_Prop_Init (LPTASKPACKET ptp)
2375 {
2376    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
2377
2378    LPFILESET lpFileset;
2379    if ((lpFileset = lpi->OpenFileset (&ptp->status)) == NULL)
2380       ptp->rc = FALSE;
2381    else
2382       {
2383       if (!lpFileset->GetStatus (&TASKDATA(ptp)->fs, TRUE, &ptp->status))
2384          ptp->rc = FALSE;
2385       else if ((TASKDATA(ptp)->lpfp = (LPFILESET_PREF)lpFileset->GetUserParam()) == NULL)
2386          {
2387          ptp->rc = FALSE;
2388          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
2389          }
2390       lpFileset->Close();
2391       }
2392
2393    if (ptp->rc)
2394       {
2395       if ((TASKDATA(ptp)->lpsp = (LPSERVER_PREF)lpi->GetServer()->GetUserParam()) == NULL)
2396          {
2397          ptp->rc = FALSE;
2398          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
2399          }
2400       }
2401 }
2402
2403
2404 void Task_Set_Prop_Apply (LPTASKPACKET ptp)
2405 {
2406    LPSET_PROP_APPLY_PARAMS lpp = (LPSET_PROP_APPLY_PARAMS)(ptp->lpUser);
2407
2408    LPFILESET_PREF lpfp = NULL;
2409    if ((lpfp = (LPFILESET_PREF)lpp->lpi->GetUserParam()) == NULL)
2410       {
2411       ptp->rc = FALSE;
2412       ptp->status = ERROR_NOT_ENOUGH_MEMORY;
2413       }
2414    else
2415       {
2416       if (!lpp->fIDC_SET_WARN)
2417          lpfp->perWarnSetFull = 0;
2418       else if (lpp->fIDC_SET_WARN_SETFULL_DEF)
2419          lpfp->perWarnSetFull = -1;
2420       else
2421          lpfp->perWarnSetFull = lpp->wIDC_SET_WARN_SETFULL_PERCENT;
2422
2423       if (!Filesets_SavePreferences (lpp->lpi))
2424          {
2425          ptp->rc = FALSE;
2426          ptp->status = ERROR_NOT_ENOUGH_MEMORY;
2427          }
2428       }
2429
2430    Alert_Scout_QueueCheckServer (lpp->lpi);
2431
2432    Delete (lpp);
2433    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2434 }
2435
2436
2437 void Task_Set_SetQuota_Init (LPTASKPACKET ptp)
2438 {
2439    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
2440
2441    LPFILESET lpFileset;
2442    if ((lpFileset = lpi->OpenFileset (&ptp->status)) == NULL)
2443       ptp->rc = FALSE;
2444    else
2445       {
2446       if (!lpFileset->GetStatus (&TASKDATA(ptp)->fs, TRUE, &ptp->status))
2447          ptp->rc = FALSE;
2448
2449       lpFileset->Close();
2450       }
2451
2452    if (ptp->rc)
2453       {
2454       Task_Agg_Find_Quota_Limits (ptp);
2455       }
2456 }
2457
2458
2459 void Task_Set_SetQuota_Apply (LPTASKPACKET ptp)
2460 {
2461    LPSET_SETQUOTA_APPLY_PARAMS lpp = (LPSET_SETQUOTA_APPLY_PARAMS)(ptp->lpUser);
2462
2463    if (!AfsClass_SetFilesetQuota (lpp->lpiFileset, lpp->ckQuota, &ptp->status))
2464       ptp->rc = FALSE;
2465
2466    if (!ptp->rc)
2467       {
2468       TCHAR szServer[ cchNAME ];
2469       TCHAR szAggregate[ cchNAME ];
2470       TCHAR szFileset[ cchNAME ];
2471       lpp->lpiFileset->GetServerName (szServer);
2472       lpp->lpiFileset->GetAggregateName (szAggregate);
2473       lpp->lpiFileset->GetFilesetName (szFileset);
2474       ErrorDialog (ptp->status, IDS_ERROR_CANT_SET_FILESET_QUOTA, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
2475       }
2476
2477    Delete (lpp);
2478    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2479 }
2480
2481
2482 void Task_Set_RepProp_Init (LPTASKPACKET ptp)
2483 {
2484    LPSET_REPPROP_INIT_PARAMS lpp = (LPSET_REPPROP_INIT_PARAMS)(ptp->lpUser);
2485
2486    LPFILESET lpFileset;
2487    if ((lpFileset = lpp->lpiReq->OpenFileset (&ptp->status)) == NULL)
2488       ptp->rc = FALSE;
2489    else
2490       {
2491       if ((lpp->lpiRW = lpFileset->GetReadWriteIdentifier (&ptp->status)) == NULL)
2492          ptp->rc = FALSE;
2493       else if (!lpFileset->GetStatus (&lpp->fs, TRUE, &ptp->status))
2494          ptp->rc = FALSE;
2495       lpFileset->Close();
2496       }
2497
2498    // don't delete this packet (ptp->lpUser)!  the caller will free it.
2499 }
2500
2501
2502 void Task_Set_Select (LPTASKPACKET ptp)
2503 {
2504    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
2505
2506    LPFILESET lpFileset;
2507    if ((lpFileset = lpi->OpenFileset (&ptp->status)) == NULL)
2508       ptp->rc = FALSE;
2509    else
2510       {
2511       if (!lpFileset->GetStatus (&TASKDATA(ptp)->fs, TRUE, &ptp->status))
2512          ptp->rc = FALSE;
2513
2514       lpFileset->Close();
2515       }
2516 }
2517
2518
2519 void Task_Set_BeginDrag (LPTASKPACKET ptp)
2520 {
2521    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
2522
2523    LPFILESET lpFileset;
2524    if ((lpFileset = lpi->OpenFileset (&ptp->status)) == NULL)
2525       ptp->rc = FALSE;
2526    else
2527       {
2528       if (!lpFileset->GetStatus (&TASKDATA(ptp)->fs, TRUE, &ptp->status))
2529          ptp->rc = FALSE;
2530       lpFileset->Close();
2531       }
2532 }
2533
2534
2535 void Task_Set_DragMenu (LPTASKPACKET ptp)
2536 {
2537    TASKDATA(ptp)->mt = *(LPMENUTASK)(ptp->lpUser);
2538    Delete ((LPMENUTASK)(ptp->lpUser));
2539    ptp->lpUser = NULL;  // we deleted this; don't let the caller use it again.
2540
2541    if (TASKDATA(ptp)->mt.lpi && TASKDATA(ptp)->mt.lpi->fIsFileset())
2542       {
2543       LPFILESET lpFileset;
2544       if ((lpFileset = TASKDATA(ptp)->mt.lpi->OpenFileset (&ptp->status)) == NULL)
2545          ptp->rc = FALSE;
2546       else
2547          {
2548          if (!lpFileset->GetStatus (&TASKDATA(ptp)->fs, TRUE, &ptp->status))
2549             ptp->rc = FALSE;
2550          lpFileset->Close();
2551          }
2552       }
2553 }
2554
2555
2556 void Task_Set_Menu (LPTASKPACKET ptp)
2557 {
2558    TASKDATA(ptp)->mt = *(LPMENUTASK)(ptp->lpUser);
2559    Delete ((LPMENUTASK)(ptp->lpUser));
2560    ptp->lpUser = NULL;  // we deleted this; don't let the caller use it again.
2561
2562    if (TASKDATA(ptp)->mt.lpi && TASKDATA(ptp)->mt.lpi->fIsFileset())
2563       {
2564       LPFILESET lpFileset;
2565       if ((lpFileset = TASKDATA(ptp)->mt.lpi->OpenFileset (&ptp->status)) == NULL)
2566          ptp->rc = FALSE;
2567       else
2568          {
2569          if (!lpFileset->GetStatus (&TASKDATA(ptp)->fs, TRUE, &ptp->status))
2570             ptp->rc = FALSE;
2571
2572          lpFileset->Close();
2573          }
2574       }
2575 }
2576
2577
2578 void Task_Set_Lock (LPTASKPACKET ptp)
2579 {
2580    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
2581    ptp->rc = AfsClass_LockFileset (lpi, &ptp->status);
2582 }
2583
2584
2585 void Task_Set_Unlock (LPTASKPACKET ptp)
2586 {
2587    LPIDENT lpi = (LPIDENT)(ptp->lpUser);
2588
2589    if (lpi->fIsFileset())
2590       ptp->rc = AfsClass_UnlockFileset (lpi, &ptp->status);
2591    else
2592       ptp->rc = AfsClass_UnlockAllFilesets (lpi, &ptp->status);
2593 }
2594
2595
2596 void Task_Set_CreateRep (LPTASKPACKET ptp)
2597 {
2598    LPSET_CREATEREP_PARAMS lpp = (LPSET_CREATEREP_PARAMS)(ptp->lpUser);
2599
2600    LPIDENT lpiReplica;
2601    if ((lpiReplica = AfsClass_CreateReplica (lpp->lpiSource, lpp->lpiTarget, &ptp->status)) == NULL)
2602       ptp->rc = FALSE;
2603
2604    if (ptp->rc)
2605       {
2606       TASKDATA(ptp)->lpi = lpiReplica;
2607       }
2608    else
2609       {
2610       TCHAR szServer[ cchNAME ];
2611       TCHAR szAggregate[ cchNAME ];
2612       TCHAR szFileset[ cchNAME ];
2613       lpp->lpiTarget->GetServerName (szServer);
2614       lpp->lpiTarget->GetAggregateName (szAggregate);
2615       lpp->lpiSource->GetFilesetName (szFileset);
2616       ErrorDialog (ptp->status, IDS_ERROR_CANT_CREATE_REPLICA, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
2617       }
2618
2619    Delete (lpp);
2620    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2621 }
2622
2623
2624 void Task_Set_Rename_Init (LPTASKPACKET ptp)
2625 {
2626    LPSET_RENAME_INIT_PARAMS lpp = (LPSET_RENAME_INIT_PARAMS)(ptp->lpUser);
2627
2628    LPFILESET lpFileset;
2629    if ((lpFileset = lpp->lpiReq->OpenFileset (&ptp->status)) == NULL)
2630       ptp->rc = FALSE;
2631    else
2632       {
2633       if ((lpp->lpiRW = lpFileset->GetReadWriteIdentifier (&ptp->status)) == NULL)
2634          ptp->rc = FALSE;
2635       lpFileset->Close();
2636       }
2637
2638    // don't delete this packet (ptp->lpUser)!  the caller will free it.
2639 }
2640
2641
2642 void Task_Set_Rename_Apply (LPTASKPACKET ptp)
2643 {
2644    LPSET_RENAME_APPLY_PARAMS lpp = (LPSET_RENAME_APPLY_PARAMS)(ptp->lpUser);
2645
2646    ptp->rc = AfsClass_RenameFileset (lpp->lpiFileset, lpp->szNewName, &ptp->status);
2647
2648    if (!ptp->rc)
2649       {
2650       TCHAR szFileset[ cchNAME ];
2651       lpp->lpiFileset->GetFilesetName (szFileset);
2652       ErrorDialog (ptp->status, IDS_ERROR_CANT_RENAME_FILESET, TEXT("%s%s"), szFileset, lpp->szNewName);
2653       }
2654
2655    Delete (lpp);
2656    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2657 }
2658
2659
2660 void Task_Set_Release (LPTASKPACKET ptp)
2661 {
2662    LPSET_RELEASE_PARAMS lpp = (LPSET_RELEASE_PARAMS)(ptp->lpUser);
2663
2664    ptp->rc = AfsClass_ReleaseFileset (lpp->lpiRW, lpp->fForce, &ptp->status);
2665
2666    if (!ptp->rc)
2667       {
2668       TCHAR szServer[ cchNAME ];
2669       TCHAR szAggregate[ cchNAME ];
2670       TCHAR szFileset[ cchNAME ];
2671       lpp->lpiRW->GetServerName (szServer);
2672       lpp->lpiRW->GetAggregateName (szAggregate);
2673       lpp->lpiRW->GetFilesetName (szFileset);
2674       ErrorDialog (ptp->status, IDS_ERROR_CANT_RELEASE_FILESET, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
2675       }
2676
2677    Delete (lpp);
2678    ptp->lpUser = 0;  // we freed this; don't let anyone use it.
2679 }
2680
2681
2682 void Task_Set_Clone (LPTASKPACKET ptp)
2683 {
2684    LPIDENT lpiRW = (LPIDENT)(ptp->lpUser);
2685
2686    ptp->rc = AfsClass_Clone (lpiRW, &ptp->status);
2687
2688    if (!ptp->rc)
2689       {
2690       TCHAR szServer[ cchNAME ];
2691       TCHAR szAggregate[ cchNAME ];
2692       TCHAR szFileset[ cchNAME ];
2693       lpiRW->GetServerName (szServer);
2694       lpiRW->GetAggregateName (szAggregate);
2695       lpiRW->GetFilesetName (szFileset);
2696       ErrorDialog (ptp->status, IDS_ERROR_CANT_CLONE, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
2697       }
2698 }
2699
2700
2701 void Task_Set_Clonesys (LPTASKPACKET ptp)
2702 {
2703    LPSET_CLONESYS_PARAMS lpp = (LPSET_CLONESYS_PARAMS)(ptp->lpUser);
2704
2705    LPTSTR pszPrefix = (lpp->fUsePrefix) ? lpp->szPrefix : NULL;
2706    if (!AfsClass_CloneMultiple (lpp->lpi, pszPrefix, lpp->fExcludePrefix, &ptp->status))
2707       ptp->rc = FALSE;
2708
2709    if (!ptp->rc && !IsWindow (ptp->hReply))
2710       {
2711       ErrorDialog (ptp->status, IDS_ERROR_CANT_CLONESYS);
2712       }
2713
2714    Delete (lpp);
2715    ptp->lpUser = 0;  // we freed this; don't let anyone use it.
2716 }
2717
2718
2719 void Task_Set_Dump (LPTASKPACKET ptp)
2720 {
2721    LPSET_DUMP_PARAMS lpp = (LPSET_DUMP_PARAMS)(ptp->lpUser);
2722
2723    ptp->rc = AfsClass_DumpFileset (lpp->lpi, lpp->szFilename,
2724                                    (lpp->fDumpByDate) ? &lpp->stDump : NULL,
2725                                    &ptp->status);
2726
2727    if (!ptp->rc)
2728       {
2729       TCHAR szServer[ cchNAME ];
2730       TCHAR szAggregate[ cchNAME ];
2731       TCHAR szFileset[ cchNAME ];
2732       lpp->lpi->GetServerName (szServer);
2733       lpp->lpi->GetAggregateName (szAggregate);
2734       lpp->lpi->GetFilesetName (szFileset);
2735       ErrorDialog (ptp->status, IDS_ERROR_CANT_DUMP_FILESET, TEXT("%s%s%s%s"), szServer, szAggregate, szFileset, lpp->szFilename);
2736       }
2737
2738    Delete (lpp);
2739    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2740 }
2741
2742
2743 void Task_Set_Restore (LPTASKPACKET ptp)
2744 {
2745    LPSET_RESTORE_PARAMS lpp = (LPSET_RESTORE_PARAMS)(ptp->lpUser);
2746
2747    ptp->rc = AfsClass_RestoreFileset (lpp->lpi, lpp->szFileset, lpp->szFilename, lpp->fIncremental, &ptp->status);
2748
2749    if (!ptp->rc)
2750       {
2751       TCHAR szServer[ cchNAME ];
2752       TCHAR szAggregate[ cchNAME ];
2753       lpp->lpi->GetServerName (szServer);
2754       lpp->lpi->GetAggregateName (szAggregate);
2755       ErrorDialog (ptp->status, IDS_ERROR_CANT_RESTORE_FILESET, TEXT("%s%s%s%s"), szServer, szAggregate, lpp->szFileset, lpp->szFilename);
2756       }
2757
2758    Delete (lpp);
2759    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2760 }
2761
2762
2763 void Task_Set_Lookup (LPTASKPACKET ptp)
2764 {
2765    LPSET_LOOKUP_PACKET lpp = (LPSET_LOOKUP_PACKET)(ptp->lpUser);
2766
2767    if ((TASKDATA(ptp)->lpi = IDENT::FindFileset (g.lpiCell, lpp->szFileset)) != NULL)
2768       {
2769       LPFILESET lpFileset;
2770       if ((lpFileset = TASKDATA(ptp)->lpi->OpenFileset()) == NULL)
2771          TASKDATA(ptp)->lpi = NULL;  // fileset was probably deleted earlier
2772       else
2773          lpFileset->Close();
2774       }
2775
2776    Delete (lpp);
2777    ptp->lpUser = NULL; // deleted this, so don't let the caller use it.
2778 }
2779
2780
2781 void Task_Expired_Creds (LPTASKPACKET ptp)
2782 {
2783    if (g.lpiCell)
2784       {
2785       CheckForExpiredCredentials();
2786       }
2787 }
2788