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