bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config ) { const char *overrideVal; int overrideSize; bool override, ret; if (getValueForBootKey(bootArgs->CommandLine, key, val, size)) { return true; } ret = getValueForConfigTableKey(config, key, val, size); // Try to find alternate keys in bootInfo->chameleonConfig (if config can be overriden) // and prefer its values with the exceptions for // "Kernel"="mach_kernel" and "Kernel Flags"="". if (config->canOverride) { if (getValueForConfigTableKey(&bootInfo->chameleonConfig, key, &overrideVal, &overrideSize)) { override = true; // NOTE: Values are defined by apple as being in com.apple.Boot.plist // kHelperRootUUIDKey, kKernelArchKey, kMKextCacheKey, kKernelCacheKey, kKernelNameKey, kKernelFlagsKey if (ret && (strcmp(key, kKernelNameKey) == 0) && (overrideSize == 0)) { override = false; } if (ret && (strcmp(key, kKernelFlagsKey) == 0) && (overrideSize == 0)) { override = false; }
bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config ) { const char *overrideVal; int overrideSize; bool override, ret; if (getValueForBootKey(bootArgs->CommandLine, key, val, size)) return true; ret = getValueForConfigTableKey(config, key, val, size); // Try to find alternate keys in bootInfo->overrideConfig // and prefer its values with the exceptions for // "Kernel"="mach_kernel" and "Kernel Flags"="". if (config->canOverride) { if (getValueForConfigTableKey(&bootInfo->overrideConfig, key, &overrideVal, &overrideSize)) { override = true; if (ret && (strcmp(key, "Kernel") == 0) && (strcmp(overrideVal, "mach_kernel") == 0)) override = false; if (ret && (strcmp(key, "Kernel Flags") == 0) && (overrideSize == 0)) override = false; if (override) { *val = overrideVal; *size = overrideSize; return true; } } }
/* * Returns a new malloc'ed string if one is found * in the string table matching 'key'. Also translates * \n escapes in the string. */ char *newStringForStringTableKey(char *table, char *key, config_file_t *config) { const char *val; char *newstr, *p; int size; if (getValueForConfigTableKey(config, key, &val, &size)) { newstr = (char *)malloc(size+1); for (p = newstr; size; size--, p++, val++) { if ((*p = *val) == '\\') { switch (*++val) { case 'r': *p = '\r'; break; case 'n': *p = '\n'; break; case 't': *p = '\t'; break; default: *p = *val; break; } size--; } } *p = '\0'; return newstr; } else { return 0; } }
bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config ) { if (getValueForBootKey(bootArgs->CommandLine, key, val, size)) return true; return getValueForConfigTableKey(config, key, val, size); }
BOOL processBootArgument( const char *argName, // The argument to search for const char *userString, // Typed-in boot arguments const char *kernelFlags, // Kernel flags from config table const char *configTable, char **argP, // Output value int *cntRemainingP, // Output count char *foundVal // found value ) { const char *val; int cnt; BOOL found = NO; if (getValueForBootKey(userString, argName, &val, &cnt)) { // Don't copy; these values will be copied at the end of argument processing. found = YES; } else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) { // Don't copy; these values will be copied at the end of argument processing. found = YES; } else if (getValueForConfigTableKey(configTable, argName, &val, &cnt)) { copyArgument(argName, val, cnt, argP, cntRemainingP); found = YES; } if (found && foundVal) { strlcpy(foundVal, val, cnt+1); } return found; }
BOOL getValueForKey( const char *key, const char **val, int *size ) { if (getValueForBootKey(bootArgs->bootString, key, val, size)) return YES; else if (getValueForConfigTableKey(bootArgs->config, key, val, size)) return YES; return NO; }