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