示例#1
0
bool appendMemoryMaps(MemoryMaps& theMaps,
                      OEComponent *component,
                      string value)
{
    MemoryMap m;
    
    m.component = component;
    
    vector<string> items = strsplit(value, ',');
    
    for (vector<string>::iterator i = items.begin();
         i != items.end();
         i++)
    {
        string entry = strtolower(*i);
        
        m.read = (entry.find_first_of('r') != string::npos);
        m.write = (entry.find_first_of('w') != string::npos);
        
        if (!m.read && !m.write)
            m.read = m.write = true;
        
        entry = strsanitize(entry, "0123456789abcdef-x");
        
        vector<string> address = strsplit(entry, '-');
        
        if (address.size() == 1)
        {
            if (address[0] == "")
                return false;
            
            m.startAddress = m.endAddress = getOELong(address[0]);
        }
        else if (address.size() == 2)
        {
            if ((address[0] == "") || (address[1] == ""))
                return false;
            
            m.startAddress = getOELong(address[0]);
            m.endAddress = getOELong(address[1]);
        }
        else
            return false;
        
        theMaps.push_back(m);
    }
    
	return true;
}
int main()
{
	int		ret, status;
	char 		*env_var_ptr;
	struct stat	gtm_secshrdir_stat;
	struct stat	gtm_secshr_stat;
	char 		gtm_dist_val[MAX_ENV_VAR_VAL_LEN];
	char 		gtm_tmp_val[MAX_ENV_VAR_VAL_LEN];
	char 		gtm_dbglvl_val[MAX_ENV_VAR_VAL_LEN];
	char 		gtm_secshrdir_path[MAX_ENV_VAR_VAL_LEN];
	char 		gtm_secshrdir_path_display[MAX_ENV_VAR_VAL_LEN];
	char 		gtm_secshr_path[MAX_ENV_VAR_VAL_LEN];
	char 		gtm_secshr_path_display[MAX_ENV_VAR_VAL_LEN];
	char 		gtm_secshr_orig_path[MAX_ENV_VAR_VAL_LEN];
	int		gtm_tmp_exists = 0;
	int		gtm_dbglvl_exists = 0;
	sigset_t	mask;

	/* Reset the signal mask (since the one inherited from the invoking process might have signals such as SIGALRM or SIGTERM
	 * blocked) to let gtmsecshr manage its own signals using sig_init.
	 */
	sigemptyset(&mask);
	sigprocmask(SIG_SETMASK, &mask, NULL);
	OPENLOG("GTMSECSHRINIT", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_USER);
	ret = 0; /* start positive */
	/* get the ones we need */
	if (env_var_ptr = getenv(GTM_DIST))		/* Warning - assignment */
	{
		if (MAX_ALLOWABLE_LEN < (strlen(env_var_ptr) + STR_LIT_LEN(SUB_PATH_TO_GTMSECSHRDIR)
		    + STR_LIT_LEN(GTMSECSHR_BASENAME)))
		{
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRGTMDIST2LONG);
			ret = -1;
		} else
		{
			strcpy(gtm_dist_val, env_var_ptr);
			/* point the path to the real gtmsecshr - for display purposes only */
			strcpy(gtm_secshr_path, env_var_ptr);
			strcat(gtm_secshr_path, SUB_PATH_TO_GTMSECSHRDIR);
			strcat(gtm_secshr_path, GTMSECSHR_BASENAME);
			strsanitize(gtm_secshr_path, gtm_secshr_path_display);
			/* point the path to the real gtmsecshrdir */
			strcpy(gtm_secshrdir_path, env_var_ptr);
			strcat(gtm_secshrdir_path, SUB_PATH_TO_GTMSECSHRDIR);
			strsanitize(gtm_secshrdir_path, gtm_secshrdir_path_display);
		}
	} else
	{
		SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRNOGTMDIST);
		ret = -1;
	}
	if (env_var_ptr = getenv(GTM_TMP))		/* Warning - assignment */
	{
		if (MAX_ALLOWABLE_LEN < strlen(env_var_ptr))
		{
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRGTMTMP2LONG);
			ret = -1;
		} else
		{
			gtm_tmp_exists = 1;
			strcpy(gtm_tmp_val, env_var_ptr);
		}
	}
	if (env_var_ptr = getenv(GTM_DBGLVL))		/* Warning - assignment */
	{
		if (MAX_ALLOWABLE_LEN < strlen(env_var_ptr))
		{
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRGTMDBGLVL2LONG);
			ret = -1;
		} else
		{
			gtm_dbglvl_exists = 1;
			strcpy(gtm_dbglvl_val, env_var_ptr);
		}
	}
	if (!ret)
	{	/* clear all */
		status = gtm_clearenv();
		if (status)
		{
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRCLEARENVFAILED);
			ret = -1;
		}
		/* add the ones we need */
		status = gtm_setenv(GTM_DIST, gtm_dist_val, OVERWRITE);
		if (status)
		{
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRSETGTMDISTFAILED);
			ret = -1;
		}
		if (gtm_tmp_exists)
		{
			status = gtm_setenv(GTM_TMP, gtm_tmp_val, OVERWRITE);
			if (status)
			{
				SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRSETGTMTMPFAILED);
				ret = -1;
			}
		}
	}
	if (!ret)
	{	/* go to root */
		if (-1 == CHDIR(gtm_secshrdir_path))
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRCHDIRFAILED, gtm_secshrdir_path_display, errno);
		else if (-1 == Stat(REL_PATH_TO_CURDIR, &gtm_secshrdir_stat))
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRSTATFAILED, gtm_secshrdir_path_display, errno);
		else if (ROOTUID != gtm_secshrdir_stat.st_uid)
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRNOTOWNEDBYROOT, gtm_secshrdir_path_display);
		else if (gtm_secshrdir_stat.st_mode & 0277)
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRPERMINCRCT, gtm_secshrdir_path_display,
					gtm_secshrdir_stat.st_mode & 0777);
		else if (-1 == Stat(REL_PATH_TO_GTMSECSHR, &gtm_secshr_stat))
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRSTATFAILED, gtm_secshr_path_display, errno);
		else if (ROOTUID != gtm_secshr_stat.st_uid)
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRNOTOWNEDBYROOT, gtm_secshr_path_display);
		else if (gtm_secshr_stat.st_mode & 022)
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRWRITABLE, gtm_secshr_path_display);
		else if (!(gtm_secshr_stat.st_mode & 04000))
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRNOTSETUID, gtm_secshr_path_display);
		else if (-1 == setuid(ROOTUID))
			SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHRSETUIDFAILED);
		else
		{	/* call the real gtmsecshr, but have ps display the original gtmsecshr location */
			strcpy(gtm_secshr_orig_path, gtm_dist_val);
			strcat(gtm_secshr_orig_path, GTMSECSHR_BASENAME);
			ret = execl(REL_PATH_TO_GTMSECSHR, gtm_secshr_orig_path, NULL);
			if (-1 == ret)
				SYSLOG(LOG_USER | LOG_INFO, ERR_SECSHREXECLFAILED, gtm_secshr_path_display);
		}
	}
	CLOSELOG();
	return ret;
}