예제 #1
0
char *sysGetLocaleStr() {
    LCID lcid;
    int i;
    int len = sizeof(localeIDMap) / sizeof(LCIDtoLocale);

    if (!locale_initialized) {
        lcid = GetThreadLocale();
        /* first look for whole thing */
        for (i=0; i< len; i++) {
	    if (lcid == localeIDMap[i].winID) {
	        break;
	    }   
        }
        if (i == len) {
            lcid &= 0xff;      /* look for just language */
            for (i=0; i<len; i++) {
                if (lcid == localeIDMap[i].winID) {
                    break;
                }
            }    
        }
        if (i < len) {
            strncpy(_localeStr, localeIDMap[i].javaID, 64);
        } else {
            strcpy(_localeStr, "en_US");
        }
        if (sysStrCaseCmp(_localeStr, "C") == 0) {
            strcpy(_localeStr, "en_US");
        } 
    }
    return _localeStr;
}
예제 #2
0
static int isSecureProperty(char *key) {
    int i, defCount, start, end;

    if (securePropertyKeys == NULL) {
	char *Keys = getConfigSecureProperties();
	defCount = sizeof(DefaultSecurePropertyKeys) / 
                   sizeof(DefaultSecurePropertyKeys[0]); 
	if (Keys != NULL && strlen(Keys) > 0) {
	    char *remain;
	    int len = strlen(Keys);
	    securePropertiesCount = defCount+1;
	    for (i=0; i<len; i++) {
		if (Keys[i] == ',') {
		    securePropertiesCount++;
		}
	    }
	    securePropertyKeys = calloc(securePropertiesCount, sizeof(char *));
	    for (i=0; i<defCount; i++) {
	        securePropertyKeys[i] = DefaultSecurePropertyKeys[i];
	    }
	    remain = Keys;
	    while (strlen(remain) && i < securePropertiesCount) {
		int commaIndex = indexOf(remain, ',');
		if (commaIndex < 0) {
		    securePropertyKeys[i++] = strdup(remain);
		    break;
		} else {
	            remain[commaIndex++] = '\0';
		    while (remain[commaIndex] == ' ') { commaIndex++; }
		    securePropertyKeys[i++] = strdup(remain);
                    remain += commaIndex;
		}	
	    }
	} else {
	    securePropertyKeys = DefaultSecurePropertyKeys;
	    securePropertiesCount = defCount;
	}
    }
    for (i=0; i<securePropertiesCount; i++) {
        if (sysStrCaseCmp(key, securePropertyKeys[i]) == 0) {
        	return 1;
        }
    }   
    return 0;
}
예제 #3
0
void sysGetRegistryJREs (JREDescription jre_list[], int *nJREs) {
  HKEY hKey;
  DWORD cbData=MAX_PATH;
  unsigned int i;

  *nJREs = 0;
  /* get JRE Paths only.  common native code will figure out the versions */
  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, JRE_VERSION_REG_KEY,
		   0, KEY_READ, &hKey) == ERROR_SUCCESS) {
    DWORD dwIndex = 0, cbSubKey = MAX_PATH;
    char szSubKey[MAX_PATH];
    HRESULT result;

    while ((result = RegEnumKeyEx(hKey, dwIndex, szSubKey, &cbSubKey,
				  NULL, NULL, NULL, NULL)) == ERROR_SUCCESS) {
      /* only look at product version keys */
      char szTemp[MAX_PATH];
      DWORD cbDataJRE = MAX_PATH;
      HKEY hKeyJRE;
      int dotcount = 0;
      for (i = 0; i < cbSubKey; i++) {
	if (szSubKey[i] == '.') {
	  if (++dotcount > 1) break;
	}
      }
      if (dotcount > 1 || strncmp(szSubKey, "1.2", 3)==0) {
      
	wsprintf(szTemp, "%s\\%s", JRE_VERSION_REG_KEY, szSubKey);
	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szTemp,
			 0, KEY_READ, &hKeyJRE) == ERROR_SUCCESS) {
	  DWORD dwType;
	  jre_list[*nJREs].path = (char *)malloc(MAX_PATH);
	  if (RegQueryValueEx(hKeyJRE, JAVAHOMEVALUE, NULL, &dwType,
			      (unsigned char *)jre_list[*nJREs].path,
			      &cbDataJRE) == ERROR_SUCCESS) {
	    _tcscat(jre_list[*nJREs].path, "\\bin\\javaw.exe");
	    jre_list[*nJREs].osarch = ARCH;
	    jre_list[*nJREs].osname = PLATFORM;
	    (*nJREs)++;
	  } else {
	    free(jre_list[*nJREs].path);
	  }
	  RegCloseKey(hKeyJRE);
	}
      }
      cbSubKey = MAX_PATH;
      dwIndex++;
    }
    RegCloseKey(hKey);
  }
  for (i=0; i<*nJREs; i++) {
    if (sysStrCaseCmp(jre_list[i].path, sysGetInstallJRE()) == 0) {
	break;
    }
  }
  if (i == *nJREs) {
    jre_list[*nJREs].path = sysGetInstallJRE();
    jre_list[*nJREs].osarch = ARCH;
    jre_list[*nJREs].osname = PLATFORM;
    (*nJREs)++;
  }
}
예제 #4
0
/* Parse the XML Launch file 
 *
 * Looks for the following path: <jnlp><resources><j2se version=attr>
 */
static void ParseXMLLaunchFile(char* s, JNLFile* jnlfile) {   
    XMLNode* doc = NULL;
    XMLNode* node = NULL;
    XMLNode* resources = NULL;
    XMLNode* tempnode = NULL;
    char* str;
    char* codebase;
    char* href;
    char *name;
    char *value;

    /* added for getting canonical home */
    char* firstjar = NULL;
    char* mainjar = NULL;
    char* str2;  

    jnlfile->jreVersion = NULL;
    jnlfile->jreLocation = NULL;
    jnlfile->isPlayer = FALSE;
    jnlfile->canonicalHome = NULL;

    /* Parse XML document. */
    doc = ParseXMLDocument(s);
    if (doc != NULL) {
      node = FindXMLChild(doc, "jnlp");      
     
      if (node != NULL) {
        codebase = FindXMLAttribute(node->_attributes, "codebase");
        href = FindXMLAttribute(node->_attributes, "href");
	if ((codebase != NULL) && (href != NULL)) {
	  if (strstr(href, "http:") == href) { 
	    jnlfile->jnlp_url = href;
	  } else {
	    char *last;
	    jnlfile->jnlp_url = malloc(strlen(codebase) + strlen(href) + 2);
	    strcpy(jnlfile->jnlp_url, codebase);
	    last = codebase + (strlen(codebase) - 1);
	    if (*last != '/') {
	      strcat(jnlfile->jnlp_url, "/");
	    }
	    strcat(jnlfile->jnlp_url, href);
	  }
	  /* canonical home is equal to href if href exist */
	  jnlfile->canonicalHome = malloc(strlen(jnlfile->jnlp_url) + 1);
	  strcpy(jnlfile->canonicalHome, jnlfile->jnlp_url);	
	}
      }

      /* find main jar to generate canonical home if no href */
      if (node != NULL && jnlfile->canonicalHome == NULL) {
         tempnode = FindXMLChild(node->_sub, "resources");
         if (tempnode != NULL) { 
        
	    tempnode = FindXMLChild(tempnode->_sub, "jar");
	  
	    /* go thru all jars and find main jar */	   
	    while (tempnode && mainjar == NULL) {	     
	      str = FindXMLAttribute(tempnode->_attributes, "href");	     
	      if (firstjar == NULL) {
		firstjar = malloc(strlen(str) + 1);	      
		strcpy(firstjar, str);	     
	      }	    
	      str2 = FindXMLAttribute(tempnode->_attributes, "main");	     
	      if (str2 != NULL && sysStrCaseCmp(str2, "true") == 0) {
		mainjar = malloc(strlen(str) + 1);	      
		strcpy(mainjar, str);		
	      }	   
	      tempnode = tempnode->_next;	      
	    }
	    /* if no main jar, return first jar */
	    if (mainjar == NULL) {
	      mainjar = strdup(firstjar);	     
	    }

	    if (codebase != NULL && mainjar != NULL) {
	      /* generate canonicalHome */
	      char *last;
	      jnlfile->canonicalHome = malloc(strlen(codebase) + strlen(mainjar) + 2);
	      strcpy(jnlfile->canonicalHome, codebase);
	      last = codebase + (strlen(codebase) - 1);
	      if (*last != '/') {
		strcat(jnlfile->canonicalHome, "/");
	      }
	      strcat(jnlfile->canonicalHome, mainjar);
	     
	    }
	 }
      }
     

      if (node != NULL) {
         resources = FindXMLChild(node->_sub, "resources");
         if (resources != NULL) { 
            node = FindXMLChild(resources->_sub, "j2se");
            if (node != NULL) {
		  str = FindXMLAttribute(node->_attributes, "version");
		  if (str != NULL) jnlfile->jreVersion = strdup(str);
		  str = FindXMLAttribute(node->_attributes, "href");
		  if (str != NULL) jnlfile->jreLocation = strdup(str);
		  
		  str = FindXMLAttribute(node->_attributes, "max-heap-size");
		  if (str != NULL) jnlfile->maxHeap = strdup(str);
		  str = FindXMLAttribute(node->_attributes, "initial-heap-size");
		  if (str != NULL) jnlfile->initialHeap = strdup(str);
            }
            node = FindXMLChild(resources->_sub, "property");
            while (node != NULL) {
                name = FindXMLAttribute(node->_attributes, "name");
                if (name != NULL) {
                    value = FindXMLAttribute(node->_attributes, "value");
                    if (value != NULL) {
                        if (isSecureProperty(name)) {
                            char *auxArg = malloc(16+strlen(name)+strlen(value));
                            sprintf(auxArg, "%s=%s",name, value);
                            addAuxArg(jnlfile, auxArg);
                        }
                    }    
                }
                node = FindXMLChild(node->_next, "property");
            }
         }
      }
    }

    /* Check for player */
    if (doc != NULL && FindXMLChild(doc, "player") != NULL) {
         jnlfile->isPlayer = TRUE;
    }

    free(firstjar);
    free(mainjar);
    FreeXMLDocument(doc);
}
/*
 * Get a list of all the JREs from the registry.  For each JRE in this
 * list, 1. add it to the config list if it's not already there, and
 * 2. mark it as "confirmed" in the config list.  Then, remove all
 * unconfirmed registered JREs from the config list.
 */
int RescanJREs(int verbose) {
  JREDescription reg_list[255];
  int nJREs = 0;
  int i, j;
  char *path;
  char *osname;
  char *osarch;
  int return_value = FALSE;
  int haveRegistry = 1;

  memset(reg_list, 0, sizeof(JREDescription) * 255);
  sysGetRegistryJREs(reg_list, &nJREs);
 
  /**
   * On Unix platforms, reg_list[i].product_version == NULL,
   * because sysGetRegistryJREs Unix implementation fakes a registry entry
   */
  if(nJREs==0) {
      haveRegistry = 0;
  } else if(nJREs==1) {
      haveRegistry = reg_list[0].product_version != NULL;
  }
 
  for (i = 0; i < nJREs; i++) {
    /* check if the JRE is already in the list */
    int match = 0;
    /* compare path in Unicode format */
    char *reg_path = sysMBCSToSeqUnicode(reg_list[i].path);
    if(!haveRegistry) {
        // earmark the system JRE in case we have no registry
        nonRegisteredSystemJRE = strdup(reg_path);
    }

    for (j = 0; j < nIndices; j++) {
      int index = indexArray[j].index;
      path = GetJREJavaCmd(index);
      osname = GetJREOsName(index);
      osarch = GetJREOsArch(index);    
      if (path != NULL && sysStrCaseCmp(path, reg_path) == 0) {
        if(verbose) {
            printf("test %d: path:<%s> regPath<%s> match \n", index, path, reg_path);
        }
        /* make sure osname and osarch matches too, if they are specified */
        if (osname == NULL || (osname != NULL && sysStrCaseCmp(osname, reg_list[i].osname) == 0)) {
          if(verbose) {
              printf("test %d: osname:<%s> regOsname<%s> match \n", index, 
                (osname==NULL)?"NULL":osname, (reg_list[i].osname==NULL)?"NULL":reg_list[i].osname);
          }
          /* only compare osarch if osname is SunOS */
          if (osarch == NULL || (osname != NULL && strcmp(osname, "SunOS") != 0) || (osarch != NULL && sysStrCaseCmp(osarch, reg_list[i].osarch) == 0)) {
            if(verbose) {
                printf("test %d: osarch:<%s> regOsarch<%s> match \n", index, osarch, 
                    (reg_list[i].osarch==NULL)?"NULL":reg_list[i].osarch);
            }
            /**
             * it matches.  mark it confirmed and registered 
             * now match only if version is matching. 
	     *
	     * since product version may contain milestones, e.g. 1.6.0_11-beta
	     * compare only the version string without milestone.
             */
            if ( !haveRegistry ||
                 ( GetJREProductVersion(index) != NULL && 
                   reg_list[i].product_version != NULL &&
                   sysStrNCaseCmp(GetJREProductVersion(index), 
				  reg_list[i].product_version,
				  strlen(reg_list[i].product_version)) == 0) ) 
            {
                if(verbose) {
                    printf("test %d: productV:<%s> regProductV<%s> match \n", index, 
                        (GetJREProductVersion(index)==NULL)?"NULL":GetJREProductVersion(index), 
                        (reg_list[i].product_version==NULL)?"NULL":reg_list[i].product_version);
                }
                match = 1;
                indexArray[j].confirmed = 1;
                if (!isJRERegistered(index) && haveRegistry) {
                    SetJRERegistered(index, "true");
                    return_value = TRUE;
                }
            } else if(verbose) {
                printf("test %d: productV:<%s> regProductV<%s> doesn't match \n", index, 
                        (GetJREProductVersion(index)==NULL)?"NULL":GetJREProductVersion(index), 
                        (reg_list[i].product_version==NULL)?"NULL":reg_list[i].product_version);
            }
          } else if(verbose) {
            printf("test %d: osarch:<%s> regOsarch<%s> doesn't match \n", index, 
                    (osarch==NULL)?"NULL":osarch,
                    (reg_list[i].osarch==NULL)?"NULL":reg_list[i].osarch);
          }
        } else if(verbose) {
          printf("test %d: osname:<%s> regOsname<%s> doesn't match \n", index, 
                    (osname==NULL)?"NULL":osname,
                    (reg_list[i].osname==NULL)?"NULL":reg_list[i].osname);
        }
        /* keep going here - may be more with same path */
      } else if(verbose) {
          printf("test %d: path:<%s> regPath<%s> doesn't match\n", index, 
                    (path==NULL)?"NULL":path,
                    (reg_path==NULL)?"NULL":reg_path);
      }
    }

    /* if there was no match we need to add the JRE to the list */
    if (match == 0) {
      int new = getUniqueIndexArrayIndex();
      UpdateJREInfo(&reg_list[i]);

      /* fix for 4813021 */
      /* check to make sure all the info exist before adding */
      if (!(reg_list[i].platform_version == NULL ||
          reg_list[i].product_version == NULL ||
          reg_list[i].href == NULL ||
          reg_list[i].osname == NULL ||
          reg_list[i].osarch == NULL)) {

        indexArray[nIndices].index = new;
        indexArray[nIndices++].confirmed = 1;
        SetJREPlatformVersion(new, reg_list[i].platform_version);
        SetJREProductVersion(new, reg_list[i].product_version);
        SetJRELocation(new, reg_list[i].href);
        SetJREJavaCmd(new, reg_list[i].path);
        SetJREOsName(new, reg_list[i].osname);
        SetJREOsArch(new, reg_list[i].osarch);
        SetJREEnabled(new, "true");
        if ( haveRegistry ) {
            SetJRERegistered(new, "true");
        } else {
            SetJRERegistered(new, "false");
        }
        return_value = TRUE;
        if(verbose) {
            printf("test add new %d: regPath<%s>, registered: %d\n", new, 
                (reg_list[i].path==NULL)?"NULL":reg_list[i].path,
                isJRERegistered(new));
        }
      }