Beispiel #1
0
/*{
** Name: II_PrecheckInstallation - Pre-check installation environment
**
** Description:
**	Verify that a machine environment will support the current release of
**	Ingres. The following checks are made:
**(E
**	a. A minimum operating system version
**	b. Other required software (currently none)
**	c. Check the install path
**	   - exists
**	   - that user can write to it
**	   - does not have any disallowed characters (Windows only).
**)E
**
** Inputs:
**	response_file	path to the Embedded Ingres response file.
**                  For more information concerning response file options
**                  please see the Ingres Embedded Edition User Guide.
**
** Outputs:
**  error_msg       Message text for status.  If the message text exceeds
**                  MAX_IIERR_LEN then the message is truncated to
**                  MAX_IIERR_LEN.
**                  Unchanged if II_SUCCESSFUL is returned.
**
** Returns:
**  II_SUCCESSFUL           The environment test completed successfully
**  II_NULL_PARAM           The parameters passed are invalid
**  II_NO_INSTALL_PATH      Error reading response file or no II_SYSTEM entry
**  II_CHARMAP_ERROR        Error processing character mapping file
**  II_GET_COMPUTER_FAIL    Attempt to retrieve computer name failed
**  II_INVALID_HOST         Computer name contains illegal characters
**  II_GET_HOST_FAILED      Attempt to retrieve the network name failed
**  II_INVALID_USER         The username contains illegal characters
**  II_UNMATCHED_NAME       Computer name does not match network name
**  II_OS_NOT_MIN_VERSION   OS version does not meet the minimum requirement
**  II_BAD_PATH             The II_SYSTEM path is incorrectly formed
**  II_INVAL_CHARS_IN_PATH  The II_SYSTEM path contains illegal characters
**  II_PATH_NOT_DIR         The II_SYSTEM path is not a directory
**  II_PATH_CANNOT_WRITE    No write permission in the II_SYSTEM directory
**  II_PATH_EXCEEDED        Length of the path exceeds permitted maximum
**
** Example:
**  # include "tngapi.h"
**
**  # if defined(UNIX)
**  II_CHAR reponsefile[] = {"./ingres.rsp"};
**  # else
**  II_CHAR reponsefile[] = {".\\ingres.rsp"};
**  # endif
**  II_INT4 status;
**  II_CHAR error_msg[MAX_IIERR_LEN + 1] = { '\0' };
**
**  if ((status = II_PrecheckInstallation( responsefile, error_msg )) !=
**      II_SUCCESSFUL)
**  {
**      printf( "II_PrecheckInstallation failed - %s\n", error_msg );
**  }
**
** Side Effects:
**	none
**
** History:
**	16-apr-2002 (abbjo03)
**	    Written.
**  11-Jul-2005 (fanra01)
**      Add more specific status code from check_path_chars.
*/
int
II_PrecheckInstallation(
char	*response_file,
char	*error_msg)
{
    LOCATION		loc;
    char		buf[MAX_LOC];
    char		charmap[MAX_LOC+1];
    LOINFORMATION	loinfo;
    i4			flags;
    int			result;
    CL_ERR_DESC clerr;

    if (!response_file || !error_msg)
    {
        result = II_NULL_PARAM;
        if (error_msg)
            II_GetErrorMessage(error_msgs[result], error_msg);
        return result;
    }

    if (!GetPrivateProfileString("Ingres Configuration", "II_SYSTEM", "", buf,
	    sizeof(buf), response_file))
    {
        result = II_NO_INSTALL_PATH;
        II_GetErrorMessage(error_msgs[result], error_msg);
        return result;
    }
    
    /*
    ** Get the charmap field from the response file.
    */
    if (!GetPrivateProfileString("Ingres Configuration", II_CHARMAP, "",
        charmap, sizeof(charmap), response_file))
    {
        result = II_NO_CHAR_MAP;
        II_GetErrorMessage(error_msgs[result], error_msg);
        return result;
    }

    /*
    ** Open and read the character map specified in the response file.
    ** This is a special installation character description file.
    */
#if defined(UNIX)
    if ((result = CMset_attr( charmap, &clerr )) != 0)
#else
    if ((result = CMread_attr( II_CHARSET, charmap, &clerr )) != 0)
#endif 
    {
        result = II_CHARMAP_ERROR;
        II_GetErrorMessage( error_msgs[result], error_msg );
        return(result);
    }

    if ((result = check_user()) != II_SUCCESSFUL)
    {
        II_GetErrorMessage( error_msgs[result], error_msg );
        return(result);
    }

    if ((result = check_host()) != II_SUCCESSFUL)
    {
        II_GetErrorMessage( error_msgs[result], error_msg );
        return(result);
    }
    
    if (check_platform( II_DEFARCH ) != OK)
    {
	result = II_OS_NOT_MIN_VERSION;
	II_GetErrorMessage(error_msgs[result], error_msg);
	return result;
    }

    if (LOfroms(PATH & FILENAME, buf, &loc) != OK)
    {
	result = II_BAD_PATH;
	II_GetErrorMessage(error_msgs[result], error_msg);
	return result;
    }

    flags = LO_I_TYPE | LO_I_PERMS;
    if (LOinfo(&loc, &flags, &loinfo) != OK)
    {
	result = II_BAD_PATH;
	II_GetErrorMessage(error_msgs[result], error_msg);
	return result;
    }

    if ((flags & LO_I_TYPE) == 0 || loinfo.li_type != LO_IS_DIR)
    {
	result = II_PATH_NOT_DIR;
	II_GetErrorMessage(error_msgs[result], error_msg);
	return result;
    }
    if ((flags & LO_I_PERMS) == 0 || (loinfo.li_perms & LO_P_WRITE) == 0)
    {
	result = II_PATH_CANNOT_WRITE;
	II_GetErrorMessage(error_msgs[result], error_msg);
	return result;
    }
    
    if (check_path_chars(&loc, &result))
    {
        switch(result)
        {
            case LO_BAD_DEVICE:
                result = II_BAD_PATH;
                break;
            case LO_NOT_PATH:
            case LO_NOT_FILE:
            default:
                result = II_INVAL_CHARS_IN_PATH;
                break;
        }
	II_GetErrorMessage(error_msgs[result], error_msg);
	return result;
    }
    
    result = II_SUCCESSFUL;
    II_GetErrorMessage(error_msgs[result], error_msg);
    return result;
}
Beispiel #2
0
/*{
** Name: II_PrecheckInstallationEx - Extended installation environment pre-check
**
** Description:
**  Verify that a machine environment will support the current release of
**  Ingres.
**  The following checks may be made by specifying the required set of flags:
**(E
**
**  a. Test for invalid characters in the machine hostname
**  b. Test for invalid characters in the username
**  c. A minimum operating system version
**  d. Test that the path value supplied for II_SYSTEM
**      i)      does not contain disallowed characters (Windows only)
**      ii)     consists of an existing parent directory
**  e. Test that the operating system user of the running process is granted
**     permission to write in d.ii).
**  f. The value of the instancecode field in the response file is tested
**     for valid characters and character sequences.
**)E
**
**  The path check flags II_CHK_PATHDIR and II_CHK_PATHPERM may be combined
**  (bit wise); they include an implicit II_CHK_PATHCHAR. All path checks
**  implicitly include an II_CHK_PATHLEN flag.
**  Use the II_CHK_ALL flag as a convenient shorthand to perform each of the
**  tests together.
**  Specifying a flag of zero will check for the existence of the
**  II_SYSTEM entry in the response file.
**
** Inputs:
**  eflags          Specifies the pre-installation checks to be performed.
**                  Can be a combination of the following
**                  0                   Test for existence of II_SYSTEM entry
**                                      in response file
**                  II_CHK_HOSTNAME     Verify characters in machine name
**                  II_CHK_OSVERSION    Verify minimum OS version
**                  II_CHK_PATHCHAR     Check characters used in II_SYSTEM
**                  II_CHK_PATHDIR      Check II_SYSTEM path for a valid
**                                      existing directory
**                  II_CHK_PATHPERM     Check path write permissions
**                  II_CHK_PATHLEN      Check length of path not exceeded
**                  II_CHK_USERNAME     Verify characters in user name
**                  II_CHK_INSTCODE     Verify characters of the configured
**                                      instance code
**                  II_CHK_ALL          Equivalent to II_PrecheckInstallation
**                                      call.
**  architecture    The value of architecture is used only if the
**                  II_CHK_VERSION flag is set in the eflags field.
**                  If the II_CHK_VERSION flag is set
**                      Let the value of architecture be set as follows:
**                      Case:
**                          -   II_DEFVER determines if the suitability of
**                              the internal Ingres platform architecture
**                              is appropriate for the operating architecture.
**                          -   Determines if the suitability of the defined
**                              value of architecture is appropriate for the
**                              operating architecture.
**                  If the II_CHK_VERSION flag is not set
**                      Let the value of architecture be set to II_DEFVER.
**
**  response_file   Path to the Embedded Ingres response file
**                  For more information concerning response file options
**                  please see the Ingres Embedded Edition User Guide.
**                  This function requires valid values for the II_SYSTEM and
**                  charmap entries.
**
** Outputs:
**  error_msg       Message text for status.  If the message text exceeds
**                  MAX_IIERR_LEN then the message is truncated to
**                  MAX_IIERR_LEN.
**                  Unchanged if II_SUCCESSFUL is returned.
**
** Returns:
**  II_SUCCESSFUL           The environment test completed successfully
**  II_NULL_PARAM           The parameters passed are invalid
**  II_NO_INSTALL_PATH      Error reading response file or no II_SYSTEM entry
**  II_NO_CHAR_MAP          Error reading response file or no II_CHARMAP entry
**  II_CHARMAP_ERROR        Error processing character mapping file
**  II_GET_COMPUTER_FAIL    Attempt to retrieve computer name failed
**  II_INVALID_HOST         Computer name contains illegal characters
**  II_GET_HOST_FAILED      Attempt to retrieve the network name failed
**  II_INVALID_USER         The username contains illegal characters
**  II_UNMATCHED_NAME       Computer name does not match network name
**  II_OS_NOT_MIN_VERSION   OS version does not meet the minimum requirement
**  II_BAD_PATH             The II_SYSTEM path is incorrectly formed
**  II_INVAL_CHARS_IN_PATH  The II_SYSTEM path contains illegal characters
**  II_PATH_NOT_DIR         The II_SYSTEM path does not contain a valid
**                          directory
**  II_PATH_CANNOT_WRITE    No write permission in the II_SYSTEM directory or
**                          a parent directory.
**  II_PATH_EXCEEDED        Length of the path exceeds permitted maximum
**  II_INVALID_INSTANCECODE Instance code contains illegal characters
**  II_INSTANCE_ERROR       Error reading instance code or no instancecode
**                          entry.
**
** Example:
**  # include "tngapi.h"
**
**  # if defined(UNIX)
**  II_CHAR reponsefile[] = {"./ingres.rsp"};
**  # else
**  II_CHAR reponsefile[] = {".\\ingres.rsp"};
**  # endif
**  II_INT4 status;
**  II_INT4 eflags = (II_CHK_HOSTNAME | II_CHK_OSVERSION | \
**      II_CHK_PATHCHAR | II_CHK_PATHDIR | II_CHK_PATHPERM | II_CHK_PATHLEN \
**      II_CHK_INSTCODE);
**  II_CHAR error_msg[MAX_IIERR_LEN + 1] = { '\0' };
**
**  if ((status = II_PrecheckInstallationEx( eflags, II_DEFARCH, responsefile,
**      error_msg )) != II_SUCCESSFUL)
**  {
**      printf( "II_PrecheckInstallationEx failed - %s\n", error_msg );
**  }
**
**  if ((status = II_PrecheckInstallationEx( II_CHK_OSVERSION, II_IA64,
**      responsefile, error_msg )) != II_SUCCESSFUL)
**  {
**      printf( "II_PrecheckInstallationEx failed - %s\n", error_msg );
**      if (status == II_OS_NOT_MIN_VERSION)
**      {
**          printf( "Target environment is unsuitable for IA64 binaries\n");
**      }
**  }
**
** Side Effects:
**  none
**
** History:
**  07-Sep-2004 (fanra01)
**      Created based on II_PrecheckInstallation.
**  30-Jun-2005 (fanra01)
**      Moved and extended path validation into check_path function.
**  18-Aug-2005 (fanra01)
**      Include path length check on character map file.
}*/
int
II_PrecheckInstallationEx(
    int     eflags,
    int     architecture,
    char*   response_file,
    char*   error_msg
)
{
    i4                  status = II_SUCCESSFUL;
    i4			        flags;
    i4                  pathlen;
    LOCATION		    loc;
    LOINFORMATION	    loinfo;
    char		        buf[MAX_LOC + 3]; /* over size buffer to detect overrun */
    char		        charmap[MAX_LOC + 3];
    char		        ii_install[MAX_LOC + 3];
    CL_ERR_DESC         clerr;
    i4                  pathchk = 0;
    
    while(TRUE)
    {
        if (!response_file || !error_msg)
        {
            status = II_NULL_PARAM;
            break;
        }
        if ((pathlen = GetPrivateProfileString( ERx("Ingres Configuration"),
            ERx("II_SYSTEM"), "", buf, sizeof(buf), response_file )) == 0)
        {
            status = II_NO_INSTALL_PATH;
            break;
        }
        else
        {
            if ((pathchk = (eflags & (II_CHK_PATHCHAR | II_CHK_PATHDIR |
                             II_CHK_PATHPERM | II_CHK_PATHLEN))) &&
                (pathlen > MAX_LOC))
            {
                status = II_PATH_EXCEEDED;
                break;
            }
        }
        if (eflags & II_CHK_INSTCODE)
        {
            if ((pathlen = GetPrivateProfileString("Ingres Configuration",
                 II_INSTCODE, "", ii_install, sizeof(ii_install), response_file)) == 0)
            {
                status = II_INSTANCE_ERROR;
                break;
            }
            else
            {
                if ((status = check_instcode( ii_install )) != II_SUCCESSFUL)
                {
                    break;
                }
            }
        }
        if ((eflags & (II_CHK_HOSTNAME | II_CHK_USERNAME | pathchk)) &&
            ((pathlen = GetPrivateProfileString("Ingres Configuration",
             II_CHARMAP, "", charmap, sizeof(charmap), response_file)) == 0))
        {
            status = II_NO_CHAR_MAP;
            break;
        }
        else
        {
            if (eflags & (II_CHK_HOSTNAME | II_CHK_USERNAME | pathchk))
            {
                if (pathlen > MAX_LOC)
                {
                    status = II_PATH_EXCEEDED;
                    break;
                }
                else
                {
#if defined(UNIX)
                    if ((status = CMset_attr( charmap, &clerr )) != 0)
#else
                    if ((status = CMread_attr( II_CHARSET, charmap, &clerr )) != 0)
#endif 
                    {
                        status = II_CHARMAP_ERROR;
                        break;
                    }
                }
            }
        }
    
        if ((eflags & II_CHK_HOSTNAME) &&
            ((status = check_host()) != II_SUCCESSFUL))
        {
            break;
        }
        
        if ((eflags & II_CHK_USERNAME) &&
            ((status = check_user()) != II_SUCCESSFUL))
        {
            break;
        }
        
        if ((eflags & II_CHK_OSVERSION) &&
            (check_platform( architecture ) != OK))
        {
            status = II_OS_NOT_MIN_VERSION;
            break;
        }

        /*
        ** Perform path validation test.
        */
        if (eflags & (II_CHK_PATHCHAR | II_CHK_PATHDIR | II_CHK_PATHPERM))
        {
            status = check_path( buf, eflags );
            break;
        }
        break;
    }
    if ((status != II_SUCCESSFUL) && (error_msg != NULL))
    {
        II_GetErrorMessage( error_msgs[status], error_msg );
    }
    return(status);
}
Beispiel #3
0
uint8_t
flash(FlashControl* flash_control,bool bmc_flash, uint32_t address, char* write_file, char* obj_path)
{
	bool has_sfc = false, has_ast = false, use_lpc = true;
	bool erase = true, program = true;

	int rc;
	printf("flasher: %s, BMC = %d, address = 0x%x\n",write_file,bmc_flash,address);
#ifdef __arm__
	/* Check platform */
	check_platform(&has_sfc, &has_ast);

	/* Prepare for access */
	if(bmc_flash) {
		if(!has_ast) {
			fprintf(stderr, "No BMC on this platform\n");
			return FLASH_SETUP_ERROR;
		}
		rc = flash_access_setup_bmc(use_lpc, erase || program);
		if(rc) {
			return FLASH_SETUP_ERROR;
		}
	} else {
		if(!has_ast && !has_sfc) {
			fprintf(stderr, "No BMC nor SFC on this platform\n");
			return FLASH_SETUP_ERROR;
		}
		rc = flash_access_setup_pnor(use_lpc, has_sfc, erase || program);
		if(rc) {
			return FLASH_SETUP_ERROR;
		}
	}

	rc = flash_get_info(fl_chip, &fl_name,
			&fl_total_size, &fl_erase_granule);
	if(rc) {
		fprintf(stderr, "Error %d getting flash info\n", rc);
		return FLASH_SETUP_ERROR;
	}
#endif
	if(strcmp(write_file,"")!=0)
	{
		// If file specified but not size, get size from file
		struct stat stbuf;
		if(stat(write_file, &stbuf)) {
			perror("Failed to get file size");
			return FLASH_ERROR;
		}
		uint32_t write_size = stbuf.st_size;
#ifdef __arm__
		rc = erase_chip();
		if(rc) {
			return FLASH_ERROR;
		}
		rc = program_file(flash_control, write_file, address, write_size);
		if(rc) {
			return FLASH_ERROR;
		}
#endif

		printf("Flash done\n");
	}
	else
	{
		printf("Flash tuned\n");
	}
	return FLASH_OK;
}