Example #1
0
BOOL GeneralTab_AskIfStopped (HWND hDlg)
{
   BOOL fStopService = FALSE;
   BOOL fStartService = FALSE;

   // If we changed things, ask if we should restart the service.
   // Otherwise, if it's stopped, ask the user if we should start the service.
   //
   DWORD CurrentState = Config_GetServiceState();
   if (g.fIsAdmin)
      {
      if ((CurrentState == SERVICE_RUNNING) && (g.fNeedRestart))
         {
         if (Message (MB_YESNO | MB_ICONQUESTION, IDS_RESTART_TITLE, IDS_RESTART_DESC) == IDYES)
            {
            fStopService = TRUE;
            fStartService = TRUE;
            }
         }
      if (CurrentState == SERVICE_STOPPED)
         {
         if (Message (MB_YESNO | MB_ICONQUESTION, GetCautionTitle(), IDS_OKSTOP_DESC) == IDYES)
            {
            fStartService = TRUE;
            }
         }
      }

   // If we need to, start or stop-n-restart the service
   //
   if (fStartService && fStopService)
      {
      GeneralTab_DoStartStop (hDlg, FALSE, TRUE); // Stop and restart the thing
      }
   else if (fStartService && !fStopService)
      {
      GeneralTab_DoStartStop (hDlg, TRUE, FALSE); // Just start it
      }

   if (fStartService)
      {
      while ( (l.fRestartIfStopped) ||
              (l.fWarnIfNotStopped) ||
              (l.fWarnIfStopped) )
         {
         MSG msg;
         if (!GetMessage (&msg, NULL, 0, 0))
            break;
         if (IsMemoryManagerMessage (&msg))
            continue;
         TranslateMessage (&msg);
         DispatchMessage (&msg);
         }
      }

   if (fStartService && !l.fServiceIsRunning)
      return FALSE;

   return TRUE;
}
Example #2
0
BOOL Config_SetProbeInt (ULONG csecProbe, ULONG *pStatus)
{
    BOOL rc = TRUE;
    ULONG status = 0;

    // TODO: NEED REGISTRY SETTING
    if (Config_GetServiceState() == SERVICE_RUNNING)
    {
        struct chservinfo checkserv;
        memset (&checkserv, 0x00, sizeof(checkserv));
        checkserv.magic = 0x12345678;
        checkserv.tinterval = csecProbe;

        BYTE OutData[ PIOCTL_MAXSIZE ];
        memset (OutData, 0x00, sizeof(OutData));

        struct ViceIoctl IOInfo;
        IOInfo.in_size = sizeof(checkserv);
        IOInfo.in = (char *)&checkserv;
        IOInfo.out = (char *)OutData;
        IOInfo.out_size = PIOCTL_MAXSIZE;

        if ((status = pioctl (0, VIOCCKSERV, &IOInfo, 1)) != 0)
        {
            rc = FALSE;
        }
    }

    if (pStatus && !rc)
        *pStatus = status;
    if (!rc)
        Message (MB_ICONHAND, GetErrorTitle(), IDS_FAILCONFIG_PROBE, TEXT("%ld"), status);
    return rc;
}
Example #3
0
void GeneralTab_OnTimer (HWND hDlg)
{
   DWORD CurrentState = Config_GetServiceState();
   DWORD DisplayState = GeneralTab_GetDisplayState(hDlg);
   TestAndDoMapShare(CurrentState);		//Re map mounted drives if necessary

   BOOL fInEndState = ((CurrentState == SERVICE_RUNNING) || (CurrentState == SERVICE_STOPPED));
   if (fInEndState && l.hStatus)
      {
      if (IsWindow (l.hStatus))
         DestroyWindow (l.hStatus);
      l.hStatus = NULL;
      }
   else if (!fInEndState && !l.hStatus)
      {
      l.hStatus = ModelessDialog (IDD_STARTSTOP, GetParent (hDlg), (DLGPROC)Status_DlgProc);
      }

   if (CurrentState != DisplayState)
      {
      GeneralTab_OnRefresh (hDlg, FALSE);
      Main_RefreshAllTabs();

      if (l.hStatus && IsWindow (l.hStatus))
         PostMessage (l.hStatus, WM_COMMAND, IDINIT, 0);
      }

   BOOL fNeedFastRefresh = ((CurrentState == SERVICE_STOPPED) || (CurrentState == SERVICE_RUNNING)) ? FALSE : TRUE;
   BOOL fHaveFastRefresh = ((DisplayState == SERVICE_STOPPED) || (DisplayState == SERVICE_RUNNING)) ? FALSE : TRUE;

   if (fNeedFastRefresh != fHaveFastRefresh)
      {
      GeneralTab_FixRefreshTimer (hDlg, ((fNeedFastRefresh) ? cmsecFAST_REFRESH : cmsecIDLE_REFRESH));
      }
}
Example #4
0
void GeneralTab_OnInitDialog (HWND hDlg)
{
   DWORD CurrentState = Config_GetServiceState();
   BOOL fNeedFastRefresh = ((CurrentState == SERVICE_STOPPED) || (CurrentState == SERVICE_RUNNING)) ? FALSE : TRUE;
   GeneralTab_FixRefreshTimer (hDlg, ((fNeedFastRefresh) ? cmsecFAST_REFRESH : cmsecIDLE_REFRESH));
   GeneralTab_OnTimer (hDlg);
   GeneralTab_OnRefresh (hDlg, TRUE);
}
Example #5
0
BOOL Config_SetSysName (LPCTSTR pszName, ULONG *pStatus)
{
    BOOL rc = TRUE;
    ULONG status = 0;

    if (Config_GetServiceState() == SERVICE_RUNNING)
    {
        struct {
            ULONG cbData;
            TCHAR szData[ PIOCTL_MAXSIZE ];
        } InData;
        memset (&InData, 0x00, sizeof(InData));
        USHORT i=0, j=0, len=lstrlen(pszName);
        
        if ( len == 0 ) {
            Message (MB_ICONHAND, GetErrorTitle(), IDS_FAILCONFIG_SYSNAME, TEXT("A sysname must be specified"));
            return(-1);
        }

        while ( pszName[i] ) {
            if ( !isspace(pszName[i]) ) {
                InData.szData[j++] = pszName[i];
            } else if (InData.szData[j-1] != '\0') {
                InData.szData[j++] = '\0';
                InData.cbData++;
            }
            i++;
        }
        InData.szData[j++] = '\0';
        InData.cbData++;      /* one word */

        BYTE OutData[ PIOCTL_MAXSIZE ];
        memset (OutData, 0x00, sizeof(OutData));

        struct ViceIoctl IOInfo;
        IOInfo.in_size = sizeof(ULONG) + j;
        IOInfo.in = (char *)&InData;
        IOInfo.out = (char *)OutData;
        IOInfo.out_size = PIOCTL_MAXSIZE;

        if ((status = pioctl (0, VIOC_AFS_SYSNAME, &IOInfo, 1)) != 0)
        {
            rc = FALSE;
        }
    }

    if (rc)
    {
        Config_WriteGlobalString (TEXT("SysName"), pszName);
    }

    if (pStatus && !rc)
        *pStatus = status;
    if (!rc)
        Message (MB_ICONHAND, GetErrorTitle(), IDS_FAILCONFIG_SYSNAME, TEXT("%ld"), status);
    return rc;
}
Example #6
0
void Status_OnRefresh (HWND hDlg)
{
   DWORD CurrentState = Config_GetServiceState();
   if (CurrentState == SERVICE_START_PENDING)
      l.fStarting = TRUE;
   else if (CurrentState == SERVICE_STOP_PENDING)
      l.fStarting = FALSE;

   ShowWindow (GetDlgItem (l.hStatus, IDC_STARTING), l.fStarting);
   ShowWindow (GetDlgItem (l.hStatus, IDC_STOPPING), !l.fStarting);
}
Example #7
0
PSERVERPREFS Config_GetServerPrefs (BOOL fVLServers)
{
   PSERVERPREFS pPrefs = New (SERVERPREFS);
   memset (pPrefs, 0x00, sizeof(SERVERPREFS));
   pPrefs->fVLServers = fVLServers;

   if (Config_GetServiceState() == SERVICE_RUNNING)
      {
      // We retrieve server prefs in batches--start that loop now.
      //
      size_t iOut = 0;
      for (int iOffset = 0; ; )
         {
         cm_SPrefRequest_t InData;
         memset (&InData, 0x00, sizeof(InData));
         InData.offset = iOffset;
         InData.flags = (pPrefs->fVLServers) ? CM_SPREF_VLONLY : 0;
         InData.num_servers = cSERVERPREFS_CHUNK;

         BYTE OutDataStorage[ sizeof(cm_SPrefInfo_t) + cSERVERPREFS_CHUNK * sizeof(cm_SPref_t) ];
         memset (OutDataStorage, 0x00, sizeof(OutDataStorage));
         cm_SPrefInfo_t *pOutData = (cm_SPrefInfo_t *)OutDataStorage;

         struct ViceIoctl IOInfo;
         IOInfo.in_size = sizeof(InData);
         IOInfo.in = (char *)&InData;
         IOInfo.out = (char *)pOutData;
         IOInfo.out_size = sizeof(cm_SPrefInfo_t) + cSERVERPREFS_CHUNK * sizeof(cm_SPref_t);

         if (pioctl (0, VIOC_GETSPREFS, &IOInfo, 1) != 0)
            break;

         if (!REALLOC (pPrefs->aPrefs, pPrefs->cPrefs, iOut + pOutData->num_servers, cREALLOC_PREFS))
            break;

         for (size_t ii = 0; ii < pOutData->num_servers; ++ii)
            {
            pPrefs->aPrefs[ iOut ].ipServer = pOutData->servers[ ii ].host.s_addr;
            pPrefs->aPrefs[ iOut ].iRank = pOutData->servers[ ii ].rank;
            iOut ++;
            }

         if ((iOffset = pOutData->next_offset) == 0)
            break;
         }
     }

   return pPrefs;
}
Example #8
0
void GeneralTab_ShowCurrentState (HWND hDlg)
{
   TCHAR szNoCell[ cchRESOURCE ];
   GetString (szNoCell, IDS_CELL_UNKNOWN);

   TCHAR szCell[ cchRESOURCE ];
   GetDlgItemText (hDlg, IDC_CELL, szCell, cchRESOURCE);

   BOOL fValidCell = TRUE;
   if (!szCell[0])
      fValidCell = FALSE;
   if (!lstrcmpi (szCell, szNoCell))
      fValidCell = FALSE;

   DWORD CurrentState = Config_GetServiceState();

   TCHAR szText[ cchRESOURCE ];
   switch (CurrentState)
      {
      case SERVICE_STOPPED:
         GetString (szText, (fValidCell) ? IDS_STATE_STOPPED : IDS_STOPPED_NOCELL);
         break;
      case SERVICE_RUNNING:
         GetString (szText, IDS_STATE_RUNNING);
         break;
      case SERVICE_START_PENDING:
         GetString (szText, IDS_STATE_STARTING);
         break;
      case SERVICE_STOP_PENDING:
         GetString (szText, IDS_STATE_STOPPING);
         break;
      default:
         GetString (szText, IDS_STATE_UNKNOWN);
         break;
      }
   SetDlgItemText (hDlg, IDC_STATUS, szText);

   // Enable or disable controls as necessary
   //
   BOOL fIfServiceStopped = !(g.fIsWinNT && !g.fIsAdmin);
   BOOL fIfServiceRunning = fIfServiceStopped && (CurrentState == SERVICE_RUNNING);

   EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_START), ((CurrentState == SERVICE_STOPPED) && (g.fIsAdmin) && (fValidCell)));
   EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_STOP),  ((CurrentState == SERVICE_RUNNING) && (g.fIsAdmin)));
}
Example #9
0
BOOL Config_GetCacheInUse (ULONG *pckCacheInUse, ULONG *pStatus)
{
    BOOL rc = TRUE;
    ULONG status = 0;

    *pckCacheInUse = 0;

    if (Config_GetServiceState() != SERVICE_RUNNING)
    {
        rc = FALSE;
        status = ERROR_SERVICE_NOT_ACTIVE;
    }
    else
    {
        BYTE OutData[ PIOCTL_MAXSIZE ];
        memset (OutData, 0x00, sizeof(OutData));

        struct ViceIoctl IOInfo;
        IOInfo.in_size = 0;
        IOInfo.in = (char *)0;
        IOInfo.out = (char *)OutData;
        IOInfo.out_size = PIOCTL_MAXSIZE;

        if ((status = pioctl (0, VIOCGETCACHEPARMS, &IOInfo, 1)) != 0)
        {
            rc = FALSE;
        }
        else
        {
            *pckCacheInUse = ((LONG*)OutData)[1];
        }
    }

    if (pStatus && !rc)
        *pStatus = status;
    return rc;
}
Example #10
0
BOOL Config_SetServerPrefs (PSERVERPREFS pPrefs, ULONG *pStatus)
{
   BOOL rc = TRUE;
   ULONG status = 0;

   if (pPrefs)
      {
      size_t cChanged = 0;
      size_t ii;
      for (ii = 0; ii < pPrefs->cPrefs; ++ii)
         {
         if (pPrefs->aPrefs[ ii ].fChanged)
            ++cChanged;
         }

      if (cChanged)
         {
         if (Config_GetServiceState() != SERVICE_RUNNING)
            {
            rc = FALSE;
            status = ERROR_SERVICE_NOT_ACTIVE;
            }
         else
            {
            size_t cbInDataStorage = sizeof(cm_SSetPref_t) + cChanged * sizeof(cm_SPref_t);

            PBYTE pInDataStorage;
            if ((pInDataStorage = (PBYTE)Allocate (cbInDataStorage)) == NULL)
               {
               rc = FALSE;
               status = ERROR_NOT_ENOUGH_MEMORY;
               }
            else
               {
               memset (pInDataStorage, 0x00, sizeof(cbInDataStorage));

               cm_SSetPref_t *pInData = (cm_SSetPref_t*)pInDataStorage;
               pInData->flags = (pPrefs->fVLServers) ? CM_SPREF_VLONLY : 0;
               pInData->num_servers = cChanged;

               size_t iOut = 0;
               for (ii = 0; ii < pPrefs->cPrefs; ++ii)
                  {
                  if (pPrefs->aPrefs[ ii ].fChanged)
                     {
                     pInData->servers[ iOut ].host.s_addr = pPrefs->aPrefs[ ii ].ipServer;
                     pInData->servers[ iOut ].rank = (unsigned short)pPrefs->aPrefs[ ii ].iRank;
                     iOut++;
                     }
                  }

               BYTE OutDataStorage[ PIOCTL_MAXSIZE ];

               struct ViceIoctl IOInfo;
               IOInfo.in_size = cbInDataStorage;
               IOInfo.in = (char *)pInData;
               IOInfo.out = (char *)OutDataStorage;
               IOInfo.out_size = PIOCTL_MAXSIZE;

               if ((status = pioctl (0, VIOC_SETSPREFS, &IOInfo, 1)) != 0)
                  {
                  rc = FALSE;
                  }

               Free (pInDataStorage);
               }
            }
         }
      }

   if (pStatus && !rc)
      *pStatus = status;
   if (!rc)
      Message (MB_ICONHAND, GetErrorTitle(), IDS_FAILCONFIG_PREFS, TEXT("%ld"), status);
   return rc;
}
Example #11
0
void GeneralTab_OnRefresh (HWND hDlg, BOOL fRequery)
{
   // If necessary, update any fields in g.Configuration that we care about
   //
   if (fRequery)
      {
      if (g.fIsWinNT)
         Config_GetGatewayFlag (&g.Configuration.fBeGateway);
      else
         Config_GetGatewayName (g.Configuration.szGateway);

      Config_GetCellName (g.Configuration.szCell);
      g.Configuration.fLogonAuthent=RWLogonOption(TRUE,LOGON_OPTION_INTEGRATED);
      Config_GetTrayIconFlag (&g.Configuration.fShowTrayIcon);

      if (!g.fIsWinNT)
         SetDlgItemText (hDlg, IDC_GATEWAY, g.Configuration.szGateway);
      else
         CheckDlgButton (hDlg, IDC_GATEWAY, g.Configuration.fBeGateway);

      SetDlgItemText (hDlg, IDC_CELL, g.Configuration.szCell);
      CheckDlgButton (hDlg, IDC_LOGON, g.Configuration.fLogonAuthent);
      CheckDlgButton (hDlg, IDC_TRAYICON, g.Configuration.fShowTrayIcon);
      }

   // Update our display of the service's status
   //
   DWORD CurrentState = Config_GetServiceState();
   BOOL fIfServiceStopped = !(g.fIsWinNT && !g.fIsAdmin);
   BOOL fIfServiceRunning = fIfServiceStopped && (CurrentState == SERVICE_RUNNING);

   GeneralTab_ShowCurrentState (hDlg);

   EnableWindow (GetDlgItem (hDlg, IDC_CELL), fIfServiceStopped && g.fIsWinNT);

   EnableWindow (GetDlgItem (hDlg, IDC_LOGON), fIfServiceStopped);
   EnableWindow (GetDlgItem (hDlg, IDC_GATEWAY), fIfServiceStopped);

   // Update our warning. Note that under WinNT, this tab doesn't have any
   // controls (other than Start Service) which disable just because the
   // service isn't running...so don't show that warning in that case.
   //
   TCHAR szText[ cchRESOURCE ];
   if ((!g.fIsWinNT) && (CurrentState != SERVICE_RUNNING))
      {
      GetString (szText, IDS_WARN_STOPPED);
      SetDlgItemText (hDlg, IDC_WARN, szText);
      ShowWindow (GetDlgItem (hDlg, IDC_WARN), SW_SHOW);
      }
   else if (g.fIsWinNT && !g.fIsAdmin)
      {
      GetString (szText, IDS_WARN_ADMIN);
      SetDlgItemText (hDlg, IDC_WARN, szText);
      ShowWindow (GetDlgItem (hDlg, IDC_WARN), SW_SHOW);
      }
   else // ((CurrentState == SERVICE_RUNNING) && (g.fIsAdmin))
      {
      ShowWindow (GetDlgItem (hDlg, IDC_WARN), SW_HIDE);
      }

   GeneralTab_OnGateway (hDlg);

   // If the service isn't running/stopped, we may need to complain
   //
   if ((CurrentState == SERVICE_RUNNING) && (l.fWarnIfNotStopped))
      {
      Message (MB_ICONHAND, GetErrorTitle(), IDS_SERVICE_FAIL_STOP, TEXT("%08lX"), ERROR_SERVICE_SPECIFIC_ERROR);
      }
   else if ((CurrentState == SERVICE_STOPPED) && (l.fWarnIfStopped))
      {
      Message (MB_ICONHAND, GetErrorTitle(), IDS_SERVICE_FAIL_START, TEXT("%08lX"), ERROR_SERVICE_SPECIFIC_ERROR);
      }

   if ((CurrentState == SERVICE_RUNNING) || (CurrentState == SERVICE_STOPPED))
      {
      BOOL fRestart = ((CurrentState == SERVICE_STOPPED) && (l.fRestartIfStopped));
      l.fWarnIfStopped = FALSE;
      l.fWarnIfNotStopped = FALSE;
      l.fRestartIfStopped = FALSE;
      l.fServiceIsRunning = (CurrentState == SERVICE_RUNNING);

      if (fRestart)
         {
         GeneralTab_DoStartStop (hDlg, TRUE, FALSE);
         }
      }
}