.ad 8
.bm 8
.fm 4
.bt $Copyright by   Software AG, 1993$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $NME$Project Distributed Database System$vos01ic$
.tt 2 $$$
.tt 3 $R.Roedling$Installation Functions$1997-05-07$
***********************************************************
.nf


    ========== licence begin LGPL
    Copyright (C) 2002 SAP AG

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    ========== licence end

.fo
.nf
.sp
Module  : Installation_Functions
=========
.sp
Purpose :
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :

.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :

.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :

.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : R.Roedling
.sp
.cp 3
Created : 1997-04-22
.sp
.cp 3
Version : 1997-04-22
.sp
.cp 3
Release :  6.2 	 Date : 1997-05-07
.br
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:

.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:

.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:

.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
/*PRETTY*/


//
//  INCLUDE FILES
//


//
//  DEFINES
//

#define MOD__  "VOS01IC : "
#define MF__   MOD__"UNDEFINED"

#define XSERVER_IS_ACTIVE      0x0001
#define SERVERDB_IS_ACTIVE     0x0002
#define GATEWAY_IS_ACTIVE      0x0004

#define ACCESS_ALL             0x0001
#define ACCESS_READ            0x0002
#define ACCESS_WRITE           0x0004
#define ACCESS_EXECUTE         0x0008
#define ACCESS_DELETE          0x0010
#define ACCESS_CHANGE_OWNER    0x0020
#define ACCESS_TAKE_OWNERSHIP  0x0040

#define ACCESS_FILE            0x8000

#define REGISTRY_SZ            0
#define REGISTRY_EXPAND_SZ     1
#define REGISTRY_DWORD         2
#define REGISTRY_BINARY        3

//
//  MACROS
//


//
//  LOCAL TYPE AND STRUCT DEFINITIONS
//


//
//  EXTERNAL VARIABLES
//


//
//  EXPORTED VARIABLES
//


//
//  LOCAL VARIABLES
//

//
//  LOCAL FUNCTION PROTOTYPES
//
static LONG sql01ic_map_access ( ULONG ulFileOrPathAccess );



//
// ========================== GLOBAL FUNCTIONS ================================
//

LONG sqlCheckActivePgms ( PULONG  pulPgmTypes )
  {
  #undef  MF__
  #define MF__ MOD__"sqlCheckActivePgms"
  LONG             rc    = NO_ERROR;
  BOOL             fActive;
  SQL_DBNAMEC      szServerDB;

  DBGIN;

  *pulPgmTypes = 0;

  rc = sql97_update( NULL );

  if ( rc != NO_ERROR )
    return ( rc );

  // --- check SERVERDBs
  rc = sql97_first_db_gw_state ( FALSE, szServerDB, &fActive );

  if (( rc == NO_ERROR ) && ( fActive ))
    *pulPgmTypes |= SERVERDB_IS_ACTIVE;
  else
    {
    while ( rc == NO_ERROR )
      {
      rc = sql97_next_db_gw_state ( szServerDB, &fActive );

      if (( rc == NO_ERROR ) && ( fActive ))
        {
        *pulPgmTypes |= SERVERDB_IS_ACTIVE;
        break;
        }
      }
    }

  if (( rc == NO_ERROR ) || ( rc == ERROR_NO_MORE_FILES  ))
    {
    // --- check GATEWAYs
    rc = sql97_first_db_gw_state ( FALSE, szServerDB, &fActive );

    if (( rc == NO_ERROR ) && ( fActive ))
      *pulPgmTypes |= GATEWAY_IS_ACTIVE;
    else
      {
      while ( rc == NO_ERROR )
        {
        rc = sql97_next_db_gw_state ( szServerDB, &fActive );

        if (( rc == NO_ERROR ) && ( fActive ))
          {
          *pulPgmTypes |= GATEWAY_IS_ACTIVE;
          break;
          }
        }
      }
    }

  if (( rc == NO_ERROR ) || ( rc == ERROR_NO_MORE_FILES  ))
    {
    rc = sql97_xserver_state ( NULL, &fActive );
    *pulPgmTypes |= fActive ? XSERVER_IS_ACTIVE : 0;
    }


  DBGOUT;
  return ( rc );
  }

/*------------------------------*/

LONG sqlInstallXServer ( PSZ pszDBRoot )
  {
  #undef  MF__
  #define MF__ MOD__"sqlInstallXServer"

  DBGPAS;

  return ( sql96_update_service ( NULL, pszDBRoot ));
  }

/*------------------------------*/

LONG sqlInstallSERVERDB( PSZ pszDBRoot,
                         PSZ pszServerDB  )
  {
  #undef  MF__
  #define MF__ MOD__"sqlInstallSERVERDB"

  DBGPAS;

  return ( sql94_service_entry ( UPDATE_ADABAS_SERVICE,
                                 KERNEL_TYPE_FAST, FALSE,
                                 NULL, pszDBRoot,
                                 pszServerDB, NULL ));
  }

/*------------------------------*/

LONG sqlSetConfigPath ( PSZ pszConfigPath )
  {
  #undef  MF__
  #define MF__ MOD__"sqlSetConfigPath"

  DBGPAS;

  return (sql01c_set_config_path ( pszConfigPath ));
  }

/*------------------------------*/

VOID sqlGetConfigPath ( PSZ *ppszConfigPath )
  {
  #undef  MF__
  #define MF__ MOD__"sqlGetConfigPath"

  DBGPAS;

  sql01c_get_config_path ( ppszConfigPath );

  return;
  }

/*------------------------------*/

LONG sqlSetWrkPath ( PSZ pszWorkPath )
  {
  #undef  MF__
  #define MF__ MOD__"sqlSetWrkPath"

  DBGPAS;

  return (sql01c_set_wrk_path ( pszWorkPath ));
  }

/*------------------------------*/

VOID sqlGetWrkPath ( PSZ *ppszWorkPath )
  {
  #undef  MF__
  #define MF__ MOD__"sqlGetWrkPath"

  DBGPAS;

  sql01c_get_wrk_path ( ppszWorkPath );

  return;
  }
/*------------------------------*/

LONG sqlSetTCPIPDll( PSZ  pszTCPIPDLLName )
  {
  #undef  MF__
  #define MF__ MOD__"sqlSetTCPIPDll"

  DBGPAS;

  return (sql40c_set_tcpip_dll_path ( pszTCPIPDLLName ));
  }

/*------------------------------*/

LONG sqlGetTCPIPDll ( PSZ  *ppszTCPIPDLLName )
  {
  #undef  MF__
  #define MF__ MOD__"sqlGetTCPIPDll"

  DBGPAS;

  return (sql40c_get_tcpip_dll_path ( ppszTCPIPDLLName ));
  }

/*------------------------------*/

LONG sqlAddOpeartorGroup ( VOID )
  {
  #undef  MF__
  #define MF__ MOD__"sqlAddOpeartorGroup"

  DBGPAS;

  return (sql03c_add_ADABAS_operators_group ());
  }

/*------------------------------*/

ULONG sqlSetLocMachRegValue ( PSZ    pszRelativePath,
                              PSZ    pszValueName,
                              PVOID  pValue,
                              ULONG  ulDataLen,    // - REG_BINARY ONLY!
                              DWORD  dwValueType )
  {
  #undef  MF__
  #define MF__ MOD__"sqlSetLocMachRegValue"
  REG_ENTRY_REC    RegistryEntries[1];
  LONG             rc    = NO_ERROR;

  DBGIN;

  RegistryEntries[0].pszValueName = pszValueName;
  RegistryEntries[0].pValue       = pValue;


  switch ( dwValueType )
    {
    case REGISTRY_SZ :
      RegistryEntries[0].ulValueSize  = strlen((PSZ)pValue);
      RegistryEntries[0].ulValueType  = REG_SZ;
      break;
    case REGISTRY_EXPAND_SZ :
      RegistryEntries[0].ulValueSize  = strlen((PSZ)pValue);
      RegistryEntries[0].ulValueType  = REG_EXPAND_SZ;
      break;
    case REGISTRY_DWORD :
      RegistryEntries[0].ulValueSize  = sizeof(DWORD);
      RegistryEntries[0].ulValueType  = REG_DWORD;
      break;
    case REGISTRY_BINARY :
      RegistryEntries[0].ulValueSize  = ulDataLen;
      RegistryEntries[0].ulValueType  = REG_BINARY;
      break;
    default:
      DBGOUT;
      return ( ERROR_INVALID_PARAMETER );
    }


  rc = sql50_reg_put_applic_values ( NULL, HKEY_LOCAL_MACHINE,
                                     pszRelativePath, NULL, 1, RegistryEntries );

  DBGOUT;
  return ( rc );
  }

/*------------------------------*/

ULONG sqlGetLocMachRegValue ( PSZ     pszRelativePath,
                              PSZ     pszValueName,
                              PVOID   pValue,
                              PULONG  pulDataLen,
                              DWORD   dwValueType )
  {
  #undef  MF__
  #define MF__ MOD__"sqlGetLocMachRegValue"
  REG_ENTRY_REC    RegistryEntries[1];
  LONG             rc    = NO_ERROR;

  DBGIN;

  switch ( dwValueType )
    {
    case REGISTRY_SZ :
      RegistryEntries[0].ulValueType  = REG_SZ;
      RegistryEntries[0].ulValueSize  = *pulDataLen;
      break;
    case REGISTRY_EXPAND_SZ :
      RegistryEntries[0].ulValueType  = REG_EXPAND_SZ;
      RegistryEntries[0].ulValueSize  = *pulDataLen;
      break;
    case REGISTRY_DWORD :
      RegistryEntries[0].ulValueType  = REG_DWORD;
      RegistryEntries[0].ulValueSize  = sizeof(DWORD);
      break;
    case REGISTRY_BINARY :
      RegistryEntries[0].ulValueType  = REG_BINARY;
      RegistryEntries[0].ulValueSize  = *pulDataLen;
      break;
    default:
      DBGOUT;
      return ( ERROR_INVALID_PARAMETER );
    }

  RegistryEntries[0].pszValueName = pszValueName;
  RegistryEntries[0].pValue       = pValue;

  rc = sql50_reg_get_applic_values ( NULL, HKEY_LOCAL_MACHINE,
                                     pszRelativePath, 1, RegistryEntries );

  if ( rc == NO_ERROR )
    *pulDataLen = RegistryEntries[0].ulValueSize;
  else
    *pulDataLen = 0;

  DBGOUT;
  return ( rc );
  }

/*------------------------------*/

LONG sqlSetFileOrPathSecurity ( PSZ    pszFileOrPathName,
                                ULONG  ulWorldDirAccess,
                                ULONG  ulBackupOpDirAccess,
                                ULONG  ulWorldFileAccess,
                                ULONG  ulBackupOpFileAccess )
  {
  #undef  MF__
  #define MF__ MOD__"sqlSetFileOrPathSecurity"
  LONG                rc    = NO_ERROR;
  ACCESS_RIGHTS_REC   Access;
  SECURITY_ATTRIBUTES SA;

  DBGIN;

  SA.nLength         = sizeof(SA);
  SA.bInheritHandle  = TRUE;


  memset ( &Access, 0, sizeof (Access) );  // - this must be done first!
  Access.fDescOwnerIsAdmin          = TRUE;

  Access.Creator.ulAccess           = FILE_ALL_ACCESS;
  Access.Creator.ulAceFlags         = CONTAINER_INHERIT_ACE;
  Access.Creator.ulInheritAccess    = GENERIC_ALL;
  Access.Creator.ulInheritAceFlags  = INHERIT_ONLY_ACE|OBJECT_INHERIT_ACE;

  Access.Admin.ulAccess             = FILE_ALL_ACCESS;
  Access.Admin.ulAceFlags           = CONTAINER_INHERIT_ACE;
  Access.Admin.ulInheritAccess      = GENERIC_ALL;
  Access.Admin.ulInheritAceFlags    = INHERIT_ONLY_ACE|OBJECT_INHERIT_ACE;

  Access.System.ulAccess            = FILE_ALL_ACCESS;
  Access.System.ulAceFlags          = CONTAINER_INHERIT_ACE;
  Access.System.ulInheritAccess     = GENERIC_ALL;
  Access.System.ulInheritAceFlags   = INHERIT_ONLY_ACE|OBJECT_INHERIT_ACE;

  Access.AdabasOp.ulAccess          = FILE_ALL_ACCESS;
  Access.AdabasOp.ulAceFlags        = CONTAINER_INHERIT_ACE;
  Access.AdabasOp.ulInheritAccess   = GENERIC_ALL;
  Access.AdabasOp.ulInheritAceFlags = INHERIT_ONLY_ACE|OBJECT_INHERIT_ACE;

  Access.World.ulAccess             = sql01ic_map_access(ulWorldDirAccess);
  Access.World.ulAceFlags           = CONTAINER_INHERIT_ACE;
  Access.World.ulInheritAccess      = sql01ic_map_access(ulWorldFileAccess|ACCESS_FILE);
  Access.World.ulInheritAceFlags    = INHERIT_ONLY_ACE|OBJECT_INHERIT_ACE;

  Access.BackupOp.ulAccess          = sql01ic_map_access(ulBackupOpDirAccess);
  Access.BackupOp.ulAceFlags        = CONTAINER_INHERIT_ACE;
  Access.BackupOp.ulInheritAccess   = sql01ic_map_access(ulBackupOpFileAccess|ACCESS_FILE);
  Access.BackupOp.ulInheritAceFlags = INHERIT_ONLY_ACE|OBJECT_INHERIT_ACE;

  rc = sql49c_alloc_and_init_SD( &Access, &SA.lpSecurityDescriptor );

  if ( rc == NO_ERROR )
    {
    rc = sql49c_set_file_security ( pszFileOrPathName,
                                    SA.lpSecurityDescriptor );
    FREE_MEM (SA.lpSecurityDescriptor);
    }

  DBGOUT;
  return ( rc );
  }


//
// ========================== LOCAL FUNCTIONS =================================
//

static LONG sql01ic_map_access ( ULONG ulFileOrPathAccess )
  {
  #undef  MF__
  #define MF__ MOD__"sql01ic_map_access"
  ULONG            ulAccess = 0;

  DBGPAS;

  if ( ACCESS_FILE & ulFileOrPathAccess)
    {
    if ( ulFileOrPathAccess & ACCESS_ALL )
      ulAccess = FILE_ALL_ACCESS;
    else
      {
      if ( ulFileOrPathAccess & ACCESS_READ )
        ulAccess |= FILE_GENERIC_READ;

      if ( ulFileOrPathAccess & ACCESS_WRITE )
        ulAccess |= FILE_GENERIC_WRITE;

      if ( ulFileOrPathAccess & ACCESS_EXECUTE )
        ulAccess |= FILE_GENERIC_EXECUTE;

      if ( ulFileOrPathAccess & ACCESS_DELETE )
        ulAccess |= DELETE;

      if ( ulFileOrPathAccess & ACCESS_TAKE_OWNERSHIP )
        ulAccess |= WRITE_OWNER;

      if ( ulFileOrPathAccess & ACCESS_CHANGE_OWNER )
        ulAccess |= WRITE_DAC;
      }
    }
  else
    {
    if ( ulFileOrPathAccess & ACCESS_ALL )
      ulAccess = GENERIC_ALL;
    else
      {
      if ( ulFileOrPathAccess & ACCESS_READ )
        ulAccess |= GENERIC_READ;

      if ( ulFileOrPathAccess & ACCESS_WRITE )
        ulAccess |= GENERIC_WRITE;

      if ( ulFileOrPathAccess & ACCESS_EXECUTE )
        ulAccess |= GENERIC_EXECUTE;

      if ( ulFileOrPathAccess & ACCESS_DELETE )
        ulAccess |= DELETE;

      if ( ulFileOrPathAccess & ACCESS_TAKE_OWNERSHIP )
        ulAccess |= WRITE_OWNER;

      if ( ulFileOrPathAccess & ACCESS_CHANGE_OWNER )
        ulAccess |= WRITE_DAC;
      }
    }

  return ( ulAccess );
  }


//
// =============================== END ========================================
//
.CM *-END-* code ----------------------------------------
.SP 2
***********************************************************
.PA
