]> git.saurik.com Git - apple/configd.git/blob - scutil.tproj/scutil.c
configd-888.1.2.tar.gz
[apple/configd.git] / scutil.tproj / scutil.c
1 /*
2 * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * Modification History
26 *
27 * June 13, 2005 Allan Nathanson <ajn@apple.com>
28 * - added SCPreferences support
29 *
30 * August 4, 2004 Allan Nathanson <ajn@apple.com>
31 * - added network configuration (prefs) support
32 *
33 * September 25, 2002 Allan Nathanson <ajn@apple.com>
34 * - added command line history & editing
35 *
36 * July 9, 2001 Allan Nathanson <ajn@apple.com>
37 * - added "-r" option for checking network reachability
38 * - added "-w" option to check/wait for the presence of a
39 * dynamic store key.
40 *
41 * June 1, 2001 Allan Nathanson <ajn@apple.com>
42 * - public API conversion
43 *
44 * November 9, 2000 Allan Nathanson <ajn@apple.com>
45 * - initial revision
46 */
47
48 #include <TargetConditionals.h>
49 #include <ctype.h>
50 #include <getopt.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <string.h>
54 #include <termios.h>
55 #include <unistd.h>
56 #include <sysexits.h>
57
58 #ifdef DEBUG
59 #include <mach/mach.h>
60 #include <mach/mach_error.h>
61 #endif /* DEBUG */
62
63 #include "scutil.h"
64 #include "commands.h"
65 #include "dictionary.h"
66 #include "net.h"
67 #include "nc.h"
68 #include "prefs.h"
69 #include "session.h"
70 #include "tests.h"
71
72 #define LINE_LENGTH 2048
73
74 __private_extern__ AuthorizationRef authorization = NULL;
75 __private_extern__ InputRef currentInput = NULL;
76 __private_extern__ Boolean doDispatch = FALSE;
77 __private_extern__ int nesting = 0;
78 __private_extern__ CFRunLoopRef notifyRl = NULL;
79 __private_extern__ CFRunLoopSourceRef notifyRls = NULL;
80 __private_extern__ SCPreferencesRef prefs = NULL;
81 __private_extern__ SCDynamicStoreRef store = NULL;
82 __private_extern__ CFPropertyListRef value = NULL;
83 __private_extern__ CFMutableArrayRef watchedKeys = NULL;
84 __private_extern__ CFMutableArrayRef watchedPatterns = NULL;
85
86 static const struct option longopts[] = {
87 // { "debug", no_argument, NULL, 'd' },
88 // { "dispatch", no_argument, NULL, 'D' },
89 // { "verbose", no_argument, NULL, 'v' },
90 // { "SPI", no_argument, NULL, 'p' },
91 // { "check-reachability", required_argument, NULL, 'r' },
92 // { "timeout", required_argument, NULL, 't' },
93 // { "wait-key", required_argument, NULL, 'w' },
94 // { "watch-reachability", no_argument, NULL, 'W' },
95 { "dns", no_argument, NULL, 0 },
96 { "get", required_argument, NULL, 0 },
97 { "error", required_argument, NULL, 0 },
98 { "help", no_argument, NULL, '?' },
99 { "nc", required_argument, NULL, 0 },
100 { "net", no_argument, NULL, 0 },
101 { "nwi", no_argument, NULL, 0 },
102 { "prefs", no_argument, NULL, 0 },
103 { "proxy", no_argument, NULL, 0 },
104 { "renew", required_argument, NULL, 0 },
105 { "set", required_argument, NULL, 0 },
106 { "snapshot", no_argument, NULL, 0 },
107 { "user", required_argument, NULL, 0 },
108 { "password", required_argument, NULL, 0 },
109 { "secret", required_argument, NULL, 0 },
110 { "log", required_argument, NULL, 0 },
111 { "disable-until-needed", no_argument, NULL, 0 },
112 { NULL, 0, NULL, 0 }
113 };
114
115
116 __private_extern__
117 CFStringRef
118 _copyStringFromSTDIN(CFStringRef prompt, CFStringRef defaultValue)
119 {
120 char buf[1024];
121 int i;
122 Boolean is_user_prompt = (prompt != NULL && isatty(STDIN_FILENO) && isatty(STDOUT_FILENO));
123 int len;
124 char *modbuf;
125 int modlen;
126 CFStringRef utf8;
127
128 /* Print out a prompt to user that entry is desired */
129 if (is_user_prompt) {
130 if (defaultValue != NULL) {
131 SCPrint(TRUE, stdout, CFSTR("%@ [%@]: "), prompt, defaultValue);
132 } else {
133 SCPrint(TRUE, stdout, CFSTR("%@: "), prompt);
134 }
135 }
136
137 /* Get user input */
138 if (fgets(buf, sizeof(buf), stdin) == NULL) {
139 return NULL;
140 }
141
142 /* Prepare for trim */
143 len = (int)strlen(buf);
144 modbuf = buf;
145 modlen = len;
146
147 /* Trim new-line */
148 if ((modlen > 0) && (modbuf[modlen - 1] == '\n')) {
149 modbuf[modlen - 1] = '\0';
150 modlen--;
151 }
152
153 /* If nothing was entered at the user prompt, set default */
154 if (is_user_prompt && defaultValue != NULL && modlen == 0) {
155 CFRetain(defaultValue);
156 return defaultValue;
157 }
158
159 /* Trim spaces from front */
160 while (modlen > 0 && isspace(modbuf[0])) {
161 modbuf = &modbuf[1];
162 modlen--;
163 }
164
165 /* Trim spaces from back */
166 for (i = modlen - 1; i >= 0; i--) {
167 if (isspace(buf[i])) {
168 buf[i] = '\0';
169 modlen--;
170 } else {
171 break;
172 }
173 }
174
175 utf8 = CFStringCreateWithBytes(NULL, (UInt8 *)modbuf, modlen, kCFStringEncodingUTF8, TRUE);
176 return utf8;
177 }
178
179 static char *
180 getLine(char *buf, int len, InputRef src)
181 {
182 int n;
183
184 if (src->el) {
185 int count;
186 const char *line;
187
188 line = el_gets(src->el, &count);
189 if (line == NULL)
190 return NULL;
191
192 strlcpy(buf, line, len);
193 } else {
194 if (fgets(buf, len, src->fp) == NULL)
195 return NULL;
196 }
197
198 n = (int)strlen(buf);
199 if (buf[n-1] == '\n') {
200 /* the entire line fit in the buffer, remove the newline */
201 buf[n-1] = '\0';
202 } else if (!src->el) {
203 /* eat the remainder of the line */
204 do {
205 n = fgetc(src->fp);
206 } while ((n != '\n') && (n != EOF));
207 }
208
209 if (src->h && (buf[0] != '\0')) {
210 HistEvent ev;
211
212 history(src->h, &ev, H_ENTER, buf);
213 }
214
215 return buf;
216 }
217
218
219 static char *
220 getString(char **line)
221 {
222 char *s, *e, c, *string;
223 int i, isQuoted = 0, escaped = 0;
224
225 if (*line == NULL) return NULL;
226 if (**line == '\0') return NULL;
227
228 /* Skip leading white space */
229 while (isspace(**line)) *line += 1;
230
231 /* Grab the next string */
232 s = *line;
233 if (*s == '\0') {
234 return NULL; /* no string available */
235 } else if (*s == '"') {
236 isQuoted = 1; /* it's a quoted string */
237 s++;
238 }
239
240 for (e = s; (c = *e) != '\0'; e++) {
241 if (isQuoted && (c == '"'))
242 break; /* end of quoted string */
243 if (c == '\\') {
244 e++;
245 if (*e == '\0')
246 break; /* if premature end-of-string */
247 if ((*e == '"') || isspace(*e))
248 escaped++; /* if escaped quote or white space */
249 }
250 if (!isQuoted && isspace(c))
251 break; /* end of non-quoted string */
252 }
253
254 string = malloc(e - s - escaped + 1);
255
256 for (i = 0; s < e; s++) {
257 string[i] = *s;
258 if (!((s[0] == '\\') && ((s[1] == '"') || isspace(s[1])))) i++;
259 }
260 string[i] = '\0';
261
262 if (isQuoted)
263 e++; /* move past end of quoted string */
264
265 *line = e;
266 return string;
267 }
268
269
270 __private_extern__
271 Boolean
272 process_line(InputRef src)
273 {
274 char *arg;
275 int argc = 0;
276 char **argv = NULL;
277 int i;
278 char line[LINE_LENGTH];
279 char *s = line;
280
281 // if end-of-file, exit
282 if (getLine(line, sizeof(line), src) == NULL)
283 return FALSE;
284
285 if (nesting > 0) {
286 SCPrint(TRUE, stdout, CFSTR("%d> %s\n"), nesting, line);
287 }
288
289 // break up the input line
290 while ((arg = getString(&s)) != NULL) {
291 if (argc == 0)
292 argv = (char **)malloc(2 * sizeof(char *));
293 else
294 argv = (char **)reallocf(argv, ((argc + 2) * sizeof(char *)));
295 argv[argc++] = arg;
296 }
297
298 if (argc == 0) {
299 return TRUE; // if no arguments
300 }
301
302 /* process the command */
303 if (*argv[0] != '#') {
304 argv[argc] = NULL; // just in case...
305 currentInput = src;
306 do_command(argc, argv);
307 }
308
309 /* free the arguments */
310 for (i = 0; i < argc; i++) {
311 free(argv[i]);
312 }
313 free(argv);
314
315 return !termRequested;
316 }
317
318
319 static void
320 usage(const char *command)
321 {
322 SCPrint(TRUE, stderr, CFSTR("usage: %s\n"), command);
323 SCPrint(TRUE, stderr, CFSTR("\tinteractive access to the dynamic store.\n"));
324 SCPrint(TRUE, stderr, CFSTR("\n"));
325 SCPrint(TRUE, stderr, CFSTR(" or: %s --prefs [preference-file]\n"), command);
326 SCPrint(TRUE, stderr, CFSTR("\tinteractive access to the [raw] stored preferences.\n"));
327 SCPrint(TRUE, stderr, CFSTR("\n"));
328 SCPrint(TRUE, stderr, CFSTR(" or: %s [-W] -r nodename\n"), command);
329 SCPrint(TRUE, stderr, CFSTR(" or: %s [-W] -r address\n"), command);
330 SCPrint(TRUE, stderr, CFSTR(" or: %s [-W] -r local-address remote-address\n"), command);
331 SCPrint(TRUE, stderr, CFSTR("\tcheck reachability of node, address, or address pair (-W to \"watch\").\n"));
332 SCPrint(TRUE, stderr, CFSTR("\n"));
333 SCPrint(TRUE, stderr, CFSTR(" or: %s -w dynamic-store-key [ -t timeout ]\n"), command);
334 SCPrint(TRUE, stderr, CFSTR("\t-w\twait for presense of dynamic store key\n"));
335 SCPrint(TRUE, stderr, CFSTR("\t-t\ttime to wait for key\n"));
336 SCPrint(TRUE, stderr, CFSTR("\n"));
337 SCPrint(TRUE, stderr, CFSTR(" or: %s --get pref\n"), command);
338 SCPrint(TRUE, stderr, CFSTR(" or: %s --set pref [newval]\n"), command);
339 SCPrint(TRUE, stderr, CFSTR(" or: %s --get filename path key \n"), command);
340 SCPrint(TRUE, stderr, CFSTR("\tpref\tdisplay (or set) the specified preference. Valid preferences\n"));
341 SCPrint(TRUE, stderr, CFSTR("\t\tinclude:\n"));
342 SCPrint(TRUE, stderr, CFSTR("\t\t\tComputerName, LocalHostName, HostName\n"));
343 SCPrint(TRUE, stderr, CFSTR("\tnewval\tNew preference value to be set. If not specified,\n"));
344 SCPrint(TRUE, stderr, CFSTR("\t\tthe new value will be read from standard input.\n"));
345 SCPrint(TRUE, stderr, CFSTR("\n"));
346 SCPrint(TRUE, stderr, CFSTR(" or: %s --dns\n"), command);
347 SCPrint(TRUE, stderr, CFSTR("\tshow DNS configuration.\n"));
348 SCPrint(TRUE, stderr, CFSTR("\n"));
349 SCPrint(TRUE, stderr, CFSTR(" or: %s --proxy\n"), command);
350 SCPrint(TRUE, stderr, CFSTR("\tshow \"proxy\" configuration.\n"));
351 SCPrint(TRUE, stderr, CFSTR("\n"));
352 SCPrint(TRUE, stderr, CFSTR(" or: %s --nwi\n"), command);
353 SCPrint(TRUE, stderr, CFSTR("\tshow network information\n"));
354 SCPrint(TRUE, stderr, CFSTR("\n"));
355 SCPrint(TRUE, stderr, CFSTR(" or: %s --nc\n"), command);
356 SCPrint(TRUE, stderr, CFSTR("\tshow VPN network configuration information. Use --nc help for full command list\n"));
357
358 if (_sc_debug) {
359 SCPrint(TRUE, stderr, CFSTR("\n"));
360 SCPrint(TRUE, stderr, CFSTR(" or: %s --log IPMonitor [off|on]\n"), command);
361 SCPrint(TRUE, stderr, CFSTR("\tmanage logging.\n"));
362
363 SCPrint(TRUE, stderr, CFSTR("\n"));
364 SCPrint(TRUE, stderr, CFSTR(" or: %s --disable-until-needed <interfaceName> [on|off ]\n"), command);
365 SCPrint(TRUE, stderr, CFSTR("\tmanage secondary interface demand.\n"));
366 }
367
368 if (getenv("ENABLE_EXPERIMENTAL_SCUTIL_COMMANDS")) {
369 SCPrint(TRUE, stderr, CFSTR("\n"));
370 SCPrint(TRUE, stderr, CFSTR(" or: %s --net\n"), command);
371 SCPrint(TRUE, stderr, CFSTR("\tmanage network configuration.\n"));
372 }
373
374 SCPrint(TRUE, stderr, CFSTR("\n"));
375 SCPrint(TRUE, stderr, CFSTR(" or: %s --error err#\n"), command);
376 SCPrint(TRUE, stderr, CFSTR("\tdisplay a descriptive message for the given error code\n"));
377
378 exit (EX_USAGE);
379 }
380
381
382 static char *
383 prompt(EditLine *el)
384 {
385 #if !TARGET_OS_SIMULATOR
386 return "> ";
387 #else // !TARGET_OS_SIMULATOR
388 return "sim> ";
389 #endif // !TARGET_OS_SIMULATOR
390 }
391
392
393 int
394 main(int argc, char * const argv[])
395 {
396 Boolean disableUntilNeeded = FALSE;
397 Boolean doDNS = FALSE;
398 Boolean doNet = FALSE;
399 Boolean doNWI = FALSE;
400 Boolean doPrefs = FALSE;
401 Boolean doProxy = FALSE;
402 Boolean doReach = FALSE;
403 Boolean doSnap = FALSE;
404 char *error = NULL;
405 char *get = NULL;
406 char *log = NULL;
407 extern int optind;
408 int opt;
409 int opti;
410 const char *prog = argv[0];
411 char *renew = NULL;
412 char *set = NULL;
413 char *nc_cmd = NULL;
414 InputRef src;
415 int timeout = 15; /* default timeout (in seconds) */
416 char *wait = NULL;
417 Boolean watch = FALSE;
418 int xStore = 0; /* non dynamic store command line options */
419
420 /* process any arguments */
421
422 while ((opt = getopt_long(argc, argv, "dDvprt:w:W", longopts, &opti)) != -1)
423 switch(opt) {
424 case 'd':
425 _sc_debug = TRUE;
426 _sc_log = FALSE; /* enable framework logging */
427 break;
428 case 'D':
429 doDispatch = TRUE;
430 break;
431 case 'v':
432 _sc_verbose = TRUE;
433 _sc_log = FALSE; /* enable framework logging */
434 break;
435 case 'p':
436 enablePrivateAPI = TRUE;
437 break;
438 case 'r':
439 doReach = TRUE;
440 xStore++;
441 break;
442 case 't':
443 timeout = atoi(optarg);
444 break;
445 case 'w':
446 wait = optarg;
447 xStore++;
448 break;
449 case 'W':
450 watch = TRUE;
451 break;
452 case 0:
453 if (strcmp(longopts[opti].name, "dns") == 0) {
454 doDNS = TRUE;
455 xStore++;
456 } else if (strcmp(longopts[opti].name, "error") == 0) {
457 error = optarg;
458 xStore++;
459 } else if (strcmp(longopts[opti].name, "get") == 0) {
460 get = optarg;
461 xStore++;
462 } else if (strcmp(longopts[opti].name, "nc") == 0) {
463 nc_cmd = optarg;
464 xStore++;
465 } else if (strcmp(longopts[opti].name, "net") == 0) {
466 doNet = TRUE;
467 xStore++;
468 } else if (strcmp(longopts[opti].name, "nwi") == 0) {
469 doNWI = TRUE;
470 xStore++;
471 } else if (strcmp(longopts[opti].name, "prefs") == 0) {
472 doPrefs = TRUE;
473 xStore++;
474 } else if (strcmp(longopts[opti].name, "proxy") == 0) {
475 doProxy = TRUE;
476 xStore++;
477 } else if (strcmp(longopts[opti].name, "renew") == 0) {
478 renew = optarg;
479 xStore++;
480 } else if (strcmp(longopts[opti].name, "set") == 0) {
481 set = optarg;
482 xStore++;
483 } else if (strcmp(longopts[opti].name, "snapshot") == 0) {
484 doSnap = TRUE;
485 xStore++;
486 } else if (strcmp(longopts[opti].name, "log") == 0) {
487 log = optarg;
488 xStore++;
489 } else if (strcmp(longopts[opti].name, "disable-until-needed") == 0) {
490 disableUntilNeeded = TRUE;
491 xStore++;
492 } else if (strcmp(longopts[opti].name, "user") == 0) {
493 username = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingUTF8);
494 } else if (strcmp(longopts[opti].name, "password") == 0) {
495 password = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingUTF8);
496 } else if (strcmp(longopts[opti].name, "secret") == 0) {
497 sharedsecret = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingUTF8);
498 }
499 break;
500 case '?':
501 default :
502 usage(prog);
503 }
504 argc -= optind;
505 argv += optind;
506
507 if (xStore > 1) {
508 // if we are attempting to process more than one type of request
509 usage(prog);
510 }
511
512 /* are we checking (or watching) the reachability of a host/address */
513 if (doReach) {
514 if (argc < 1) {
515 usage(prog);
516 }
517 if (watch) {
518 do_watchReachability(argc, (char **)argv);
519 } else {
520 do_checkReachability(argc, (char **)argv);
521 }
522 /* NOT REACHED */
523 }
524
525 /* are we waiting on the presense of a dynamic store key */
526 if (wait) {
527 do_wait(wait, timeout);
528 /* NOT REACHED */
529 }
530
531 /* are we looking up the DNS configuration */
532 if (doDNS) {
533 if (watch) {
534 do_watchDNSConfiguration(argc, (char **)argv);
535 } else {
536 do_showDNSConfiguration(argc, (char **)argv);
537 }
538 /* NOT REACHED */
539 }
540
541 if (doNWI) {
542 if (watch) {
543 do_watchNWI(argc, (char**)argv);
544 } else {
545 do_showNWI(argc, (char**)argv);
546 }
547 /* NOT REACHED */
548 }
549
550 if (doSnap) {
551 if (!enablePrivateAPI
552 #if !TARGET_OS_SIMULATOR
553 || (geteuid() != 0)
554 #endif // !TARGET_OS_SIMULATOR
555 ) {
556 usage(prog);
557 }
558
559 do_open(0, NULL); /* open the dynamic store */
560 do_snapshot(argc, (char**)argv);
561 exit(0);
562 }
563
564 /* are we translating error #'s to descriptive text */
565 if (error != NULL) {
566 int sc_status = atoi(error);
567
568 SCPrint(TRUE, stdout, CFSTR("Error: 0x%08x %d %s\n"),
569 sc_status,
570 sc_status,
571 SCErrorString(sc_status));
572 exit(0);
573 }
574
575 /* are we looking up a preference value */
576 if (get) {
577 if (argc == 0) {
578 if (findPref(get) < 0) {
579 usage(prog);
580 }
581 } else if (argc == 2) {
582 /*
583 * extended --get
584 * i.e. scutil --get <filename> <prefs path> <key>
585 *
586 * need to go back one argument to re-use the 1st "--get"
587 * argument as the prefs path name
588 */
589 argc++;
590 argv--;
591 } else {
592 usage(prog);
593 }
594
595 do_getPref(get, argc, (char **)argv);
596 /* NOT REACHED */
597 }
598
599 /* are we looking up the proxy configuration */
600 if (doProxy) {
601 do_showProxyConfiguration(argc, (char **)argv);
602 /* NOT REACHED */
603 }
604
605 /* are we changing a preference value */
606 if (set) {
607 if (findPref(set) < 0) {
608 usage(prog);
609 }
610 do_setPref(set, argc, (char **)argv);
611 /* NOT REACHED */
612 }
613
614 /* verbose log */
615 if (log != NULL) {
616 if (strcasecmp(log, "IPMonitor")) {
617 usage(prog);
618 }
619 do_log(log, argc, (char * *)argv);
620 /* NOT REACHED */
621 }
622
623 /* disableUntilNeeded */
624 if (disableUntilNeeded) {
625 do_disable_until_needed(argc, (char * *)argv);
626 /* NOT REACHED */
627 }
628 /* network connection commands */
629 if (nc_cmd) {
630 if (find_nc_cmd(nc_cmd) < 0) {
631 usage(prog);
632 }
633 do_nc_cmd(nc_cmd, argc, (char **)argv, watch);
634 /* NOT REACHED */
635 }
636
637 if (doNet) {
638 /* if we are going to be managing the network configuration */
639 commands = (cmdInfo *)commands_net;
640 nCommands = nCommands_net;
641
642 if (!getenv("ENABLE_EXPERIMENTAL_SCUTIL_COMMANDS")) {
643 usage(prog);
644 }
645
646 do_net_init(); /* initialization */
647 do_net_open(argc, (char **)argv); /* open prefs */
648 } else if (doPrefs) {
649 /* if we are going to be managing the network configuration */
650 commands = (cmdInfo *)commands_prefs;
651 nCommands = nCommands_prefs;
652
653 do_dictInit(0, NULL); /* start with an empty dictionary */
654 do_prefs_init(); /* initialization */
655 do_prefs_open(argc, (char **)argv); /* open prefs */
656 } else {
657 /* if we are going to be managing the dynamic store */
658 commands = (cmdInfo *)commands_store;
659 nCommands = nCommands_store;
660
661 do_dictInit(0, NULL); /* start with an empty dictionary */
662 do_open(0, NULL); /* open the dynamic store */
663 }
664
665 /* are we trying to renew a DHCP lease */
666 if (renew != NULL) {
667 do_renew(renew);
668 /* NOT REACHED */
669 }
670
671 /* allocate command input stream */
672 src = (InputRef)CFAllocatorAllocate(NULL, sizeof(Input), 0);
673 src->fp = stdin;
674 src->el = NULL;
675 src->h = NULL;
676
677 if (isatty(fileno(src->fp))) {
678 int editmode = 1;
679 HistEvent ev;
680 struct termios t;
681
682 if (tcgetattr(fileno(src->fp), &t) != -1) {
683 if ((t.c_lflag & ECHO) == 0) {
684 editmode = 0;
685 }
686 }
687 src->el = el_init(prog, src->fp, stdout, stderr);
688 src->h = history_init();
689
690 (void)history(src->h, &ev, H_SETSIZE, INT_MAX);
691 el_set(src->el, EL_HIST, history, src->h);
692
693 if (!editmode) {
694 el_set(src->el, EL_EDITMODE, 0);
695 }
696
697 el_set(src->el, EL_EDITOR, "emacs");
698 el_set(src->el, EL_PROMPT, prompt);
699
700 el_source(src->el, NULL);
701
702 if ((el_get(src->el, EL_EDITMODE, &editmode) != -1) && editmode != 0) {
703 el_set(src->el, EL_SIGNAL, 1);
704 } else {
705 history_end(src->h);
706 src->h = NULL;
707 el_end(src->el);
708 src->el = NULL;
709 }
710 }
711
712 while (TRUE) {
713 Boolean ok;
714
715 ok = process_line(src);
716 if (!ok) {
717 break;
718 }
719 }
720
721 /* close the socket, free resources */
722 if (src->h) history_end(src->h);
723 if (src->el) el_end(src->el);
724 (void)fclose(src->fp);
725 CFAllocatorDeallocate(NULL, src);
726
727 exit (EX_OK); // insure the process exit status is 0
728 return 0; // ...and make main fit the ANSI spec.
729 }