1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License"). You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | /*␊ |
25 | * Copyright 1993 NeXT, Inc.␊ |
26 | * All rights reserved.␊ |
27 | */␊ |
28 | ␊ |
29 | #include "bootstruct.h"␊ |
30 | #include "libsaio.h"␊ |
31 | #include "xml.h"␊ |
32 | #include "boot.h" //Azi:canoverride␊ |
33 | #include "ramdisk.h" //Azi:searchalgo␊ |
34 | ␊ |
35 | extern char *Language;␊ |
36 | extern char *LoadableFamilies;␊ |
37 | ␊ |
38 | bool sysConfigValid;␊ |
39 | ␊ |
40 | /*␊ |
41 | * Compare a string to a key with quoted characters␊ |
42 | */␊ |
43 | static inline int␊ |
44 | keyncmp(const char *str, const char *key, int n)␊ |
45 | {␊ |
46 | int c;␊ |
47 | while (n--) {␊ |
48 | ␉c = *key++;␊ |
49 | ␉if (c == '\\') {␊ |
50 | ␉ switch(c = *key++) {␊ |
51 | ␉ case 'n':␊ |
52 | ␉␉c = '\n';␊ |
53 | ␉␉break;␊ |
54 | ␉ case 'r':␊ |
55 | ␉␉c = '\r';␊ |
56 | ␉␉break;␊ |
57 | ␉ case 't':␊ |
58 | ␉␉c = '\t';␊ |
59 | ␉␉break;␊ |
60 | ␉ default:␊ |
61 | ␉␉break;␊ |
62 | ␉ }␊ |
63 | ␉} else if (c == '\"') {␊ |
64 | ␉ /* Premature end of key */␊ |
65 | ␉ return 1;␊ |
66 | ␉}␊ |
67 | ␉if (c != *str++) {␊ |
68 | ␉ return 1;␊ |
69 | ␉}␊ |
70 | }␊ |
71 | return 0;␊ |
72 | }␊ |
73 | ␊ |
74 | #if UNUSED␊ |
75 | ␊ |
76 | static void eatThru(char val, const char **table_p)␊ |
77 | {␊ |
78 | ␉register const char *table = *table_p;␊ |
79 | ␉register bool found = false;␊ |
80 | ␊ |
81 | ␉while (*table && !found)␊ |
82 | ␉{␊ |
83 | ␉␉if (*table == '\\') table += 2;␊ |
84 | ␉␉else␊ |
85 | ␉␉{␊ |
86 | ␉␉␉if (*table == val) found = true;␊ |
87 | ␉␉␉table++;␊ |
88 | ␉␉}␊ |
89 | ␉}␊ |
90 | ␉*table_p = table;␊ |
91 | }␊ |
92 | ␊ |
93 | /* Remove key and its associated value from the table. */␊ |
94 | ␊ |
95 | bool␊ |
96 | removeKeyFromTable(const char *key, char *table)␊ |
97 | {␊ |
98 | register int len;␊ |
99 | register char *tab;␊ |
100 | char *buf;␊ |
101 | ␊ |
102 | len = strlen(key);␊ |
103 | tab = (char *)table;␊ |
104 | buf = (char *)malloc(len + 3);␊ |
105 | ␊ |
106 | sprintf(buf, "\"%s\"", key);␊ |
107 | len = strlen(buf);␊ |
108 | ␊ |
109 | while(*tab) {␊ |
110 | if(strncmp(buf, tab, len) == 0) {␊ |
111 | char c;␊ |
112 | ␊ |
113 | while((c = *(tab + len)) != ';') {␊ |
114 | if(c == 0) {␊ |
115 | len = -1;␊ |
116 | goto out;␊ |
117 | }␊ |
118 | len++;␊ |
119 | }␊ |
120 | len++;␊ |
121 | if(*(tab + len) == '\n') len++;␊ |
122 | goto out;␊ |
123 | }␊ |
124 | tab++;␊ |
125 | }␊ |
126 | len = -1;␊ |
127 | out:␊ |
128 | free(buf);␊ |
129 | ␊ |
130 | if(len == -1) return false;␊ |
131 | ␊ |
132 | while((*tab = *(tab + len))) {␊ |
133 | tab++;␊ |
134 | }␊ |
135 | ␊ |
136 | return true;␊ |
137 | }␊ |
138 | ␊ |
139 | char *␊ |
140 | newStringFromList(␊ |
141 | char **list,␊ |
142 | int *size␊ |
143 | )␊ |
144 | {␊ |
145 | char *begin = *list, *end;␊ |
146 | char *newstr;␊ |
147 | int newsize = *size;␊ |
148 | int bufsize;␊ |
149 | ␊ |
150 | while (*begin && newsize && isspace(*begin)) {␊ |
151 | ␉begin++;␊ |
152 | ␉newsize--;␊ |
153 | }␊ |
154 | end = begin;␊ |
155 | while (*end && newsize && !isspace(*end)) {␊ |
156 | ␉end++;␊ |
157 | ␉newsize--;␊ |
158 | }␊ |
159 | if (begin == end)␊ |
160 | ␉return 0;␊ |
161 | bufsize = end - begin + 1;␊ |
162 | newstr = malloc(bufsize);␊ |
163 | strlcpy(newstr, begin, bufsize);␊ |
164 | *list = end;␊ |
165 | *size = newsize;␊ |
166 | return newstr;␊ |
167 | }␊ |
168 | ␊ |
169 | #endif␊ |
170 | ␊ |
171 | /* ␊ |
172 | * compress == compress escaped characters to one character␊ |
173 | */␊ |
174 | int stringLength(const char *table, int compress)␊ |
175 | {␊ |
176 | ␉int ret = 0;␊ |
177 | ␊ |
178 | ␉while (*table)␊ |
179 | ␉{␊ |
180 | ␉␉if (*table == '\\')␊ |
181 | ␉␉{␊ |
182 | ␉␉␉table += 2;␊ |
183 | ␉␉␉ret += 1 + (compress ? 0 : 1);␊ |
184 | ␉␉}␊ |
185 | ␉␉else␊ |
186 | ␉␉{␊ |
187 | ␉␉␉if (*table == '\"') return ret;␊ |
188 | ␉␉␉ret++;␊ |
189 | ␉␉␉table++;␊ |
190 | ␉␉}␊ |
191 | ␉}␊ |
192 | ␉return ret;␊ |
193 | }␊ |
194 | ␊ |
195 | ␊ |
196 | bool getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size)␊ |
197 | {␊ |
198 | ␉if (config->dictionary != 0)␊ |
199 | ␉{␊ |
200 | ␉␉// Look up key in XML dictionary␊ |
201 | ␉␉TagPtr value;␊ |
202 | ␉␉value = XMLGetProperty(config->dictionary, key);␊ |
203 | ␉␉if (value != 0)␊ |
204 | ␉␉{␊ |
205 | ␉␉␉if (value->type != kTagTypeString)␊ |
206 | ␉␉␉{␊ |
207 | ␉␉␉␉error("Non-string tag '%s' found in config file\n", key);␊ |
208 | ␉␉␉␉return false;␊ |
209 | ␉␉␉}␊ |
210 | ␉␉␉␊ |
211 | ␉␉␉*val = value->string;␊ |
212 | ␉␉␉*size = strlen(value->string);␊ |
213 | ␉␉␉return true;␊ |
214 | ␉␉}␊ |
215 | ␉}␊ |
216 | ␉else␊ |
217 | ␉{␊ |
218 | ␉␉// Legacy plist-style table Azi:??␊ |
219 | ␉}␊ |
220 | ␉return false;␊ |
221 | }␊ |
222 | ␊ |
223 | #if UNUSED␊ |
224 | ␊ |
225 | /*␊ |
226 | * Returns a new malloc'ed string if one is found␊ |
227 | * in the string table matching 'key'. Also translates␊ |
228 | * \n escapes in the string.␊ |
229 | */␊ |
230 | char *newStringForStringTableKey(␊ |
231 | ␉char *table,␊ |
232 | ␉char *key,␊ |
233 | ␉config_file_t *config␊ |
234 | )␊ |
235 | {␊ |
236 | const char *val;␊ |
237 | char *newstr, *p;␊ |
238 | int size;␊ |
239 | ␊ |
240 | if (getValueForConfigTableKey(config, key, &val, &size)) {␊ |
241 | ␉newstr = (char *)malloc(size+1);␊ |
242 | ␉for (p = newstr; size; size--, p++, val++) {␊ |
243 | ␉ if ((*p = *val) == '\\') {␊ |
244 | ␉␉switch (*++val) {␊ |
245 | ␉␉case 'r':␊ |
246 | ␉␉ *p = '\r';␊ |
247 | ␉␉ break;␊ |
248 | ␉␉case 'n':␊ |
249 | ␉␉ *p = '\n';␊ |
250 | ␉␉ break;␊ |
251 | ␉␉case 't':␊ |
252 | ␉␉ *p = '\t';␊ |
253 | ␉␉ break;␊ |
254 | ␉␉default:␊ |
255 | ␉␉ *p = *val;␊ |
256 | ␉␉ break;␊ |
257 | ␉␉}␊ |
258 | ␉␉size--;␊ |
259 | ␉ }␊ |
260 | ␉}␊ |
261 | ␉*p = '\0';␊ |
262 | ␉return newstr;␊ |
263 | } else {␊ |
264 | ␉return 0;␊ |
265 | }␊ |
266 | }␊ |
267 | ␊ |
268 | #endif␊ |
269 | ␊ |
270 | char *␊ |
271 | newStringForKey(char *key, config_file_t *config)␊ |
272 | {␊ |
273 | const char *val;␊ |
274 | char *newstr;␊ |
275 | int size;␊ |
276 | ␊ |
277 | if (getValueForKey(key, &val, &size, config) && size) {␊ |
278 | ␉newstr = (char *)malloc(size + 1);␊ |
279 | ␉strlcpy(newstr, val, size + 1);␊ |
280 | ␉return newstr;␊ |
281 | } else {␊ |
282 | ␉return 0;␊ |
283 | }␊ |
284 | }␊ |
285 | ␊ |
286 | /* parse a command line␊ |
287 | * in the form: [<argument> ...] [<option>=<value> ...]␊ |
288 | * both <option> and <value> must be either composed of␊ |
289 | * non-whitespace characters, or enclosed in quotes.␊ |
290 | */␊ |
291 | ␊ |
292 | static const char *getToken(const char *line, const char **begin, int *len)␊ |
293 | {␊ |
294 | if (*line == '\"') {␊ |
295 | ␉*begin = ++line;␊ |
296 | ␉while (*line && *line != '\"')␊ |
297 | ␉ line++;␊ |
298 | ␉*len = line++ - *begin;␊ |
299 | } else {␊ |
300 | ␉*begin = line;␊ |
301 | ␉while (*line && !isspace(*line) && *line != '=')␊ |
302 | ␉ line++;␊ |
303 | ␉*len = line - *begin;␊ |
304 | }␊ |
305 | return line;␊ |
306 | }␊ |
307 | ␊ |
308 | bool getValueForBootKey(const char *line, const char *match, const char **matchval, int *len)␊ |
309 | {␊ |
310 | const char *key, *value;␊ |
311 | int key_len, value_len;␊ |
312 | bool retval = false;␊ |
313 | ␊ |
314 | while (*line)␊ |
315 | ␉{␊ |
316 | ␉␉// look for keyword or argument␊ |
317 | ␉␉while (isspace(*line)) line++;␊ |
318 | ␉␉␊ |
319 | ␉␉// now look for '=' or whitespace␊ |
320 | ␉␉line = getToken(line, &key, &key_len);␊ |
321 | ␉␉// line now points to '=' or space␊ |
322 | ␉␉if (*line && !isspace(*line))␊ |
323 | ␉␉{␊ |
324 | ␉␉␉line = getToken(++line, &value, &value_len);␊ |
325 | ␉␉}␊ |
326 | ␉␉else␊ |
327 | ␉␉{␊ |
328 | ␉␉␉value = line;␊ |
329 | ␉␉␉value_len = 0;␊ |
330 | ␉␉}␊ |
331 | ␉␉␊ |
332 | ␉␉if ((strlen(match) == key_len) && strncmp(match, key, key_len) == 0)␊ |
333 | ␉␉{␊ |
334 | ␉␉␉*matchval = value;␊ |
335 | ␉␉␉*len = value_len;␊ |
336 | ␉␉␉retval = true;␊ |
337 | /* Continue to look for this key; last one wins. */␊ |
338 | ␉␉}␊ |
339 | }␊ |
340 | return retval;␊ |
341 | }␊ |
342 | ␊ |
343 | /* Return NULL if no option has been successfully retrieved, or the string otherwise */␊ |
344 | const char * getStringForKey(const char * key, config_file_t *config)␊ |
345 | {␊ |
346 | static const char* value =0;␊ |
347 | int len=0;␊ |
348 | if(!getValueForKey(key, &value, &len, config)) value = 0;␊ |
349 | return value;␊ |
350 | }␊ |
351 | ␊ |
352 | ␊ |
353 | /* Returns TRUE if a value was found, FALSE otherwise.␊ |
354 | * The boolean value of the key is stored in 'val'.␊ |
355 | */␊ |
356 | ␊ |
357 | bool getBoolForKey( const char *key, bool *result_val, config_file_t *config )␊ |
358 | {␊ |
359 | const char *key_val;␊ |
360 | int size;␊ |
361 | ␊ |
362 | if (getValueForKey(key, &key_val, &size, config)) {␊ |
363 | if ( (size >= 1) && (key_val[0] == 'Y' || key_val[0] == 'y') ) {␊ |
364 | *result_val = true;␊ |
365 | } else {␊ |
366 | *result_val = false;␊ |
367 | }␊ |
368 | return true;␊ |
369 | }␊ |
370 | return false;␊ |
371 | }␊ |
372 | ␊ |
373 | bool getIntForKey( const char *key, int *value, config_file_t *config )␊ |
374 | {␊ |
375 | const char *val;␊ |
376 | int size, sum;␊ |
377 | bool negative = false;␊ |
378 | ␊ |
379 | if (getValueForKey(key, &val, &size, config))␊ |
380 | ␉{␊ |
381 | ␉␉if ( size )␊ |
382 | ␉␉{␊ |
383 | ␉␉␉if (*val == '-')␊ |
384 | ␉␉␉{␊ |
385 | ␉␉␉␉negative = true;␊ |
386 | ␉␉␉␉val++;␊ |
387 | ␉␉␉␉size--;␊ |
388 | ␉␉␉}␊ |
389 | ␉␉␉␊ |
390 | ␉␉␉for (sum = 0; size > 0; size--)␊ |
391 | ␉␉␉{␊ |
392 | ␉␉␉␉if (*val < '0' || *val > '9')␊ |
393 | ␉␉␉␉␉return false;␊ |
394 | ␉␉␉␉␊ |
395 | ␉␉␉␉sum = (sum * 10) + (*val++ - '0');␊ |
396 | ␉␉␉}␊ |
397 | ␉␉␉␊ |
398 | ␉␉␉if (negative)␊ |
399 | ␉␉␉␉sum = -sum;␊ |
400 | ␉␉␉␊ |
401 | ␉␉␉*value = sum;␊ |
402 | ␉␉␉return true;␊ |
403 | ␉␉}␊ |
404 | ␉}␊ |
405 | return false;␊ |
406 | }␊ |
407 | ␊ |
408 | /*␊ |
409 | *␊ |
410 | */␊ |
411 | ␊ |
412 | bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size )␊ |
413 | {␊ |
414 | ␉const char *val;␊ |
415 | ␉␊ |
416 | int size = 0;␊ |
417 | ␉int sum = 0;␊ |
418 | ␊ |
419 | ␉bool negative = false;␊ |
420 | ␉bool percentage = false;␊ |
421 | ␉␊ |
422 | if (getValueForKey(key, &val, &size, config))␊ |
423 | ␉{␊ |
424 | ␉␉if ( size )␊ |
425 | ␉␉{␊ |
426 | ␉␉␉if (*val == '-')␊ |
427 | ␉␉␉{␊ |
428 | ␉␉␉␉negative = true;␊ |
429 | ␉␉␉␉val++;␊ |
430 | ␉␉␉␉size--;␊ |
431 | ␉␉␉}␊ |
432 | ␉␉␉␊ |
433 | ␉␉␉if (val[size-1] == '%')␊ |
434 | ␉␉␉{␊ |
435 | ␉␉␉␉percentage = true;␊ |
436 | ␉␉␉␉size--;␊ |
437 | ␉␉␉}␊ |
438 | ␉␉␉␊ |
439 | ␉␉␉// convert string to integer␊ |
440 | ␉␉␉for (sum = 0; size > 0; size--)␊ |
441 | ␉␉␉{␊ |
442 | ␉␉␉␉if (*val < '0' || *val > '9')␊ |
443 | ␉␉␉␉␉return false;␊ |
444 | ␉␉␉␉␊ |
445 | ␉␉␉␉sum = (sum * 10) + (*val++ - '0');␊ |
446 | ␉␉␉}␊ |
447 | ␉␉␉␊ |
448 | ␉␉␉if (percentage)␊ |
449 | ␉␉␉␉sum = ( dimension_max * sum ) / 100;␊ |
450 | ␉␉␉␊ |
451 | ␉␉␉// calculate offset from opposite origin␊ |
452 | ␉␉␉if (negative)␊ |
453 | ␉␉␉␉sum = ( ( dimension_max - object_size ) - sum );␊ |
454 | ␉␉␉␊ |
455 | ␉␉} else {␊ |
456 | ␉␉␉␊ |
457 | ␉␉␉// null value calculate center␊ |
458 | ␉␉␉sum = ( dimension_max - object_size ) / 2;␊ |
459 | ␉␉␉␊ |
460 | ␉␉}␊ |
461 | ␉␉␊ |
462 | ␉␉*value = (uint16_t) sum;␊ |
463 | ␉␉return true;␊ |
464 | ␉}␊ |
465 | ␉␊ |
466 | ␉// key not found␊ |
467 | return false;␊ |
468 | }␊ |
469 | ␊ |
470 | /*␊ |
471 | *␉get color value from plist format #RRGGBB␊ |
472 | */␊ |
473 | ␊ |
474 | bool getColorForKey( const char *key, unsigned int *value, config_file_t *config )␊ |
475 | {␊ |
476 | const char *val;␊ |
477 | int size;␊ |
478 | ␊ |
479 | if (getValueForKey(key, &val, &size, config))␊ |
480 | ␉{␊ |
481 | ␉␉if (*val == '#')␊ |
482 | ␉␉{␊ |
483 | val++;␊ |
484 | ␉␉␉*value = strtol(val, NULL, 16);␊ |
485 | ␉␉␉return true;␊ |
486 | }␊ |
487 | }␊ |
488 | return false;␊ |
489 | }␊ |
490 | ␊ |
491 | bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config )␊ |
492 | {␊ |
493 | ␉const char *overrideVal;␊ |
494 | ␉int overrideSize;␊ |
495 | ␉bool override, ret;␊ |
496 | ␉␊ |
497 | ␉if (getValueForBootKey(bootArgs->CommandLine, key, val, size))␊ |
498 | ␉␉return true;␊ |
499 | ␉␊ |
500 | ␉ret = getValueForConfigTableKey(config, key, val, size);␊ |
501 | ␉␊ |
502 | ␉// Try to find alternate keys in bootInfo->overrideConfig and prefer its values␊ |
503 | ␉// with the exceptions for "Kernel"="mach_kernel" and "Kernel Flags"="".␊ |
504 | ␉if (config->canOverride)␊ |
505 | ␉{␊ |
506 | ␉␉if (getValueForConfigTableKey(&bootInfo->overrideConfig, key, &overrideVal, &overrideSize))␊ |
507 | ␉␉{␊ |
508 | ␉␉␉override = true;␊ |
509 | ␉␉␉//Azi: kKernelNameKey, kDefaultKernelk, KernelFlagsKey can be used if boot.h is included.␊ |
510 | ␉␉␉if (ret && (strcmp(key, kKernelNameKey) == 0) && (strcmp(overrideVal, kDefaultKernelName) == 0))␊ |
511 | ␉␉␉␉override = false;␊ |
512 | ␉␉␉␊ |
513 | ␉␉␉if (ret && (strcmp(key, kKernelFlagsKey) == 0) && (overrideSize == 0))␊ |
514 | ␉␉␉␉override = false;␊ |
515 | ␉␉␉␊ |
516 | ␉␉␉if (override)␊ |
517 | ␉␉␉{␊ |
518 | ␉␉␉␉*val = overrideVal;␊ |
519 | ␉␉␉␉*size = overrideSize;␊ |
520 | ␉␉␉␉return true;␊ |
521 | ␉␉␉}␊ |
522 | ␉␉}␊ |
523 | ␉}␊ |
524 | ␉return ret;␊ |
525 | }␊ |
526 | ␊ |
527 | ␊ |
528 | #if UNUSED␊ |
529 | void␊ |
530 | printSystemConfig(char *p1)␊ |
531 | {␊ |
532 | char *p2 = p1, tmp;␊ |
533 | ␊ |
534 | while (*p1 != '\0') {␊ |
535 | ␉while (*p2 != '\0' && *p2 != '\n') p2++;␊ |
536 | ␉tmp = *p2;␊ |
537 | ␉*p2 = '\0';␊ |
538 | ␉printf("%s\n", p1);␊ |
539 | ␉*p2 = tmp;␊ |
540 | ␉if (tmp == '\0') break;␊ |
541 | ␉p1 = ++p2;␊ |
542 | }␊ |
543 | }␊ |
544 | #endif␊ |
545 | ␊ |
546 | //==========================================================================␊ |
547 | // ParseXMLFile␊ |
548 | // Modifies the input buffer.␊ |
549 | // Expects to see one dictionary in the XML file.␊ |
550 | // Puts the first dictionary it finds in the␊ |
551 | // tag pointer and returns 0, or returns -1 if not found␊ |
552 | // (and does not modify dict pointer).␊ |
553 | // Prints an error message if there is a parsing error.␊ |
554 | //␊ |
555 | int ParseXMLFile( char * buffer, TagPtr * dict )␊ |
556 | {␊ |
557 | long length, pos;␊ |
558 | TagPtr tag;␊ |
559 | pos = 0;␊ |
560 | char *configBuffer;␊ |
561 | ␊ |
562 | configBuffer = malloc(strlen(buffer)+1);␊ |
563 | strcpy(configBuffer, buffer);␊ |
564 | ␊ |
565 | while (1)␊ |
566 | {␊ |
567 | length = XMLParseNextTag(configBuffer + pos, &tag);␊ |
568 | if (length == -1) break;␊ |
569 | ␊ |
570 | pos += length;␊ |
571 | ␊ |
572 | if (tag == 0) continue;␊ |
573 | if (tag->type == kTagTypeDict) break;␊ |
574 | ␊ |
575 | XMLFreeTag(tag);␊ |
576 | }␊ |
577 | free(configBuffer);␊ |
578 | if (length < 0) {␊ |
579 | error ("Error parsing plist file\n");␊ |
580 | return -1;␊ |
581 | }␊ |
582 | *dict = tag;␊ |
583 | return 0;␊ |
584 | }␊ |
585 | ␊ |
586 | /* loadConfigFile␊ |
587 | *␊ |
588 | * Returns 0 - successful.␊ |
589 | *␉␉ -1 - unsuccesful.␊ |
590 | */␊ |
591 | int loadConfigFile(const char *configFile, config_file_t *config)␊ |
592 | {␊ |
593 | ␉int fd, count;␊ |
594 | ␊ |
595 | ␉if ((fd = open_bvdev("bt(0,0)", configFile, 0)) < 0) {␊ |
596 | ␉␉return -1;␊ |
597 | ␉}␊ |
598 | ␉// read file␊ |
599 | ␉count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);␊ |
600 | ␉close(fd);␊ |
601 | ␉␊ |
602 | ␉// build xml dictionary␊ |
603 | ␉ParseXMLFile(config->plist, &config->dictionary);␊ |
604 | ␉return 0;␊ |
605 | }␊ |
606 | ␊ |
607 | /* loadSystemConfig␊ |
608 | *␊ |
609 | * Returns 0 - successful.␊ |
610 | *␉␉ -1 - unsuccesful.␊ |
611 | */␊ |
612 | int loadSystemConfig(config_file_t *config) //Azi:searchalgo???␊ |
613 | {␊ |
614 | ␉char *dirspec[] = {␊ |
615 | ␉␉//"/Extra/com.apple.Boot.plist", removed in favor of bt(0,0) - review? only needed to load it from selected volume.␊ |
616 | ␉␉"bt(0,0)/Extra/com.apple.Boot.plist",␊ |
617 | ␉␉"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",␊ |
618 | ␉␉"/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",␊ |
619 | ␉␉"/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",␊ |
620 | ␉␉"/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"␊ |
621 | ␉};␊ |
622 | ␊ |
623 | ␉int i, fd, count, ret = -1;␊ |
624 | ␊ |
625 | ␉for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++)␊ |
626 | ␉{␊ |
627 | ␉␉if ((fd = open(dirspec[i], 0)) >= 0)␊ |
628 | ␉␉{␊ |
629 | ␉␉␉// read file␊ |
630 | ␉␉␉count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);␊ |
631 | ␉␉␉close(fd);␊ |
632 | ␊ |
633 | ␉␉␉// build xml dictionary␊ |
634 | ␉␉␉ParseXMLFile(config->plist, &config->dictionary);␊ |
635 | ␉␉␉sysConfigValid = true;␉␊ |
636 | ␉␉␉ret = 0;␊ |
637 | ␊ |
638 | ␉␉␉// enable canOverride flag␊ |
639 | ␉␉␉config->canOverride = true;␊ |
640 | ␉␉␉␊ |
641 | ␉␉␉//Azi: disable canOverride. Remove?␊ |
642 | ␉␉␉getBoolForKey(kCanOverrideKey, &config->canOverride, &bootInfo->bootConfig);␊ |
643 | ␊ |
644 | ␉␉␉break;␊ |
645 | ␉␉}␊ |
646 | ␉}␊ |
647 | ␉return ret;␊ |
648 | }␊ |
649 | ␊ |
650 | /* loadOverrideConfig␊ |
651 | *␊ |
652 | * Returns 0 - successful.␊ |
653 | *␉␉ -1 - unsuccesful.␊ |
654 | */␊ |
655 | int loadOverrideConfig(config_file_t *config)␊ |
656 | {␊ |
657 | ␉char␉␉ dirSpecBplist[128] = "";␊ |
658 | ␉const char␉*override_pathname = NULL;␊ |
659 | ␉const char␉*filename = "com.apple.Boot.plist";␊ |
660 | ␉int␉␉␉ count, ret, fd, len = 0;␊ |
661 | ␉extern char gMacOSVersion;␊ |
662 | ␊ |
663 | ␉// Take in account user overriding the override :P␊ |
664 | ␉if (getValueForKey(kTestConfigKey, &override_pathname, &len, &bootInfo->bootConfig))␊ |
665 | ␉{␊ |
666 | ␉␉// Specify a path to a file, e.g. config=/Extra/test.plist␊ |
667 | ␉␉strcpy(dirSpecBplist, override_pathname);␊ |
668 | ␉␉fd = open(dirSpecBplist, 0);␊ |
669 | ␉␉if (fd >= 0) goto success_fd;␊ |
670 | ␉}␊ |
671 | ␊ |
672 | ␉// Check rd's root for override config.␊ |
673 | ␉sprintf(dirSpecBplist, "rd(0,0)/%s", filename);␊ |
674 | ␉fd = open(dirSpecBplist, 0);␊ |
675 | ␉if (fd >= 0) goto success_fd;␊ |
676 | ␊ |
677 | ␉// Check OS specific folders.␊ |
678 | ␉sprintf(dirSpecBplist, "bt(0,0)/Extra/%s/%s", &gMacOSVersion, filename);␊ |
679 | ␉fd = open(dirSpecBplist, 0);␊ |
680 | //␉if (fd >= 0) goto success_fd;␊ |
681 | ␊ |
682 | ␉//Azi: i really don't like these two!␊ |
683 | ␉// "/Extra/com.apple.Boot.plist"␊ |
684 | ␉// "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"␊ |
685 | ␊ |
686 | ␉// These i have no way to test, need advice.␊ |
687 | ␉// "/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist)␊ |
688 | ␉// "/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist)␊ |
689 | ␉// "/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist)␊ |
690 | ␊ |
691 | success_fd:␊ |
692 | ␊ |
693 | ␉if (fd >= 0)␊ |
694 | ␉{␊ |
695 | ␉␉// read file␊ |
696 | ␉␉count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);␊ |
697 | ␉␉close(fd);␊ |
698 | ␊ |
699 | ␉␉// build xml dictionary␊ |
700 | ␉␉ParseXMLFile(config->plist, &config->dictionary);␊ |
701 | ␉␉sysConfigValid = true;␊ |
702 | ␉␉ret = 0;␊ |
703 | ␉}␊ |
704 | ␉else␊ |
705 | ␉{␊ |
706 | ␉␉printf("No override config provided!\n");␊ |
707 | ␉␉ret = -1;␊ |
708 | ␉}␊ |
709 | ␉return ret;␊ |
710 | }␊ |
711 | ␊ |
712 | /* loadHelperConfig␊ |
713 | *␊ |
714 | * Returns 0 - successful.␊ |
715 | *␉␉ -1 - unsuccesful.␊ |
716 | *␊ |
717 | */␊ |
718 | int loadHelperConfig(config_file_t *config)␊ |
719 | {␊ |
720 | ␉//Azi: Called from options.c, processBootOptions (secondrun).␊ |
721 | ␉// Seems to be used just to check plist for UUID key.␊ |
722 | ␉char *dirspec[] = {␊ |
723 | ␉␉"/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",␊ |
724 | ␉␉"/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",␊ |
725 | ␉␉"/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"␊ |
726 | ␉};␊ |
727 | ␊ |
728 | ␉int i, fd, count, ret = -1;␊ |
729 | ␊ |
730 | ␉for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++)␊ |
731 | ␉{␊ |
732 | ␉␉if ((fd = open(dirspec[i], 0)) >= 0)␊ |
733 | ␉␉{␊ |
734 | ␉␉␉// read file␊ |
735 | ␉␉␉count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);␊ |
736 | ␉␉␉close(fd);␊ |
737 | ␉␉␉␊ |
738 | ␉␉␉// build xml dictionary␊ |
739 | ␉␉␉ParseXMLFile(config->plist, &config->dictionary);␊ |
740 | ␉␉␉sysConfigValid = true;␊ |
741 | ␉␉␉ret = 0;␊ |
742 | ␉␉␉break;␊ |
743 | ␉␉}␊ |
744 | ␉}␊ |
745 | ␉return ret;␊ |
746 | }␊ |
747 | ␊ |
748 | char * newString(const char * oldString)␊ |
749 | {␊ |
750 | if ( oldString )␊ |
751 | return strcpy(malloc(strlen(oldString)+1), oldString);␊ |
752 | else␊ |
753 | return NULL;␊ |
754 | }␊ |
755 | ␊ |
756 | /*␊ |
757 | * Extracts the next argument from the command line, double quotes are allowed here.␊ |
758 | */␊ |
759 | char * getNextArg(char ** argPtr, char * val)␊ |
760 | {␊ |
761 | char * ptr = *argPtr;␊ |
762 | const char * strStart;␊ |
763 | int len = 0;␊ |
764 | bool isQuoted = false;␊ |
765 | ␊ |
766 | *val = '\0';␊ |
767 | ␊ |
768 | // Scan for the next non-whitespace character.␊ |
769 | while ( *ptr && (*ptr == ' ' || *ptr == '=') )␊ |
770 | {␊ |
771 | ptr++;␊ |
772 | }␊ |
773 | ␊ |
774 | strStart = ptr;␊ |
775 | ␊ |
776 | // Skip the leading double quote character.␊ |
777 | if (*ptr == '\"')␊ |
778 | {␊ |
779 | isQuoted = true;␊ |
780 | ptr++;␊ |
781 | strStart++;␊ |
782 | }␊ |
783 | ␊ |
784 | // Scan for the argument terminator character.␊ |
785 | // This can be either a NULL character - in case we reach the end of the string,␊ |
786 | // a double quote in case of quoted argument,␊ |
787 | // or a whitespace character (' ' or '=') for non-quoted argument.␊ |
788 | while (*ptr && !( (isQuoted && (*ptr == '\"')) ||␊ |
789 | (!isQuoted && (*ptr == ' ' || *ptr == '=')) )␊ |
790 | )␊ |
791 | {␊ |
792 | ptr++;␊ |
793 | }␊ |
794 | ␊ |
795 | len = ptr - strStart;␊ |
796 | ␊ |
797 | // Skip the closing double quote character and adjust␊ |
798 | // the starting pointer for the next getNextArg call.␊ |
799 | if (*ptr && isQuoted && *ptr == '\"')␊ |
800 | ptr++;␊ |
801 | ␊ |
802 | // Copy the extracted argument to val.␊ |
803 | strncat(val, strStart, len);␊ |
804 | ␊ |
805 | // Set command line pointer.␊ |
806 | *argPtr = ptr;␊ |
807 | ␊ |
808 | return ptr;␊ |
809 | }␊ |
810 | |