* exec.c (make_tempdir) [_WIN32]: Modified to properly handle
[gnupg.git] / g10 / status.c
blob2044820080fcb4bba8384b0aa45c05ec680b7bf4
1 /* status.c
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
3 * 2004, 2005 Free Software Foundation, Inc.
5 * This file is part of GnuPG.
7 * GnuPG is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * GnuPG is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
23 #include <config.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <unistd.h>
29 #include <signal.h>
30 #ifdef USE_SHM_COPROCESSING
31 #ifdef USE_CAPABILITIES
32 #include <sys/capability.h>
33 #endif
34 #ifdef HAVE_SYS_IPC_H
35 #include <sys/types.h>
36 #include <sys/ipc.h>
37 #endif
38 #ifdef HAVE_SYS_SHM_H
39 #include <sys/shm.h>
40 #endif
41 #if defined(HAVE_MLOCK)
42 #include <sys/mman.h>
43 #endif
44 #endif
45 #include "util.h"
46 #include "status.h"
47 #include "ttyio.h"
48 #include "options.h"
49 #include "main.h"
50 #include "i18n.h"
51 #include "cipher.h" /* for progress functions */
53 #define CONTROL_D ('D' - 'A' + 1)
57 static FILE *statusfp;
59 #ifdef USE_SHM_COPROCESSING
60 static int shm_id = -1;
61 static volatile char *shm_area;
62 static size_t shm_size;
63 static int shm_is_locked;
64 #endif /*USE_SHM_COPROCESSING*/
67 static void
68 progress_cb ( void *ctx, int c )
70 char buf[50];
72 if ( c == '\n' )
73 sprintf ( buf, "%.20s X 100 100", (char*)ctx );
74 else
75 sprintf ( buf, "%.20s %c 0 0", (char*)ctx, c );
76 write_status_text ( STATUS_PROGRESS, buf );
79 static const char *
80 get_status_string ( int no )
82 const char *s;
84 switch( no )
86 case STATUS_ENTER : s = "ENTER"; break;
87 case STATUS_LEAVE : s = "LEAVE"; break;
88 case STATUS_ABORT : s = "ABORT"; break;
89 case STATUS_NEWSIG : s = "NEWSIG"; break;
90 case STATUS_GOODSIG: s = "GOODSIG"; break;
91 case STATUS_KEYEXPIRED: s = "KEYEXPIRED"; break;
92 case STATUS_KEYREVOKED: s = "KEYREVOKED"; break;
93 case STATUS_BADSIG : s = "BADSIG"; break;
94 case STATUS_ERRSIG : s = "ERRSIG"; break;
95 case STATUS_BADARMOR : s = "BADARMOR"; break;
96 case STATUS_RSA_OR_IDEA : s= "RSA_OR_IDEA"; break;
97 case STATUS_TRUST_UNDEFINED: s = "TRUST_UNDEFINED"; break;
98 case STATUS_TRUST_NEVER : s = "TRUST_NEVER"; break;
99 case STATUS_TRUST_MARGINAL : s = "TRUST_MARGINAL"; break;
100 case STATUS_TRUST_FULLY : s = "TRUST_FULLY"; break;
101 case STATUS_TRUST_ULTIMATE : s = "TRUST_ULTIMATE"; break;
102 case STATUS_GET_BOOL : s = "GET_BOOL"; break;
103 case STATUS_GET_LINE : s = "GET_LINE"; break;
104 case STATUS_GET_HIDDEN : s = "GET_HIDDEN"; break;
105 case STATUS_GOT_IT : s = "GOT_IT"; break;
106 case STATUS_SHM_INFO : s = "SHM_INFO"; break;
107 case STATUS_SHM_GET : s = "SHM_GET"; break;
108 case STATUS_SHM_GET_BOOL : s = "SHM_GET_BOOL"; break;
109 case STATUS_SHM_GET_HIDDEN : s = "SHM_GET_HIDDEN"; break;
110 case STATUS_NEED_PASSPHRASE: s = "NEED_PASSPHRASE"; break;
111 case STATUS_VALIDSIG : s = "VALIDSIG"; break;
112 case STATUS_SIG_ID : s = "SIG_ID"; break;
113 case STATUS_ENC_TO : s = "ENC_TO"; break;
114 case STATUS_NODATA : s = "NODATA"; break;
115 case STATUS_BAD_PASSPHRASE : s = "BAD_PASSPHRASE"; break;
116 case STATUS_NO_PUBKEY : s = "NO_PUBKEY"; break;
117 case STATUS_NO_SECKEY : s = "NO_SECKEY"; break;
118 case STATUS_NEED_PASSPHRASE_SYM: s = "NEED_PASSPHRASE_SYM"; break;
119 case STATUS_NEED_PASSPHRASE_PIN: s = "NEED_PASSPHRASE_PIN"; break;
120 case STATUS_DECRYPTION_FAILED: s = "DECRYPTION_FAILED"; break;
121 case STATUS_DECRYPTION_OKAY: s = "DECRYPTION_OKAY"; break;
122 case STATUS_MISSING_PASSPHRASE: s = "MISSING_PASSPHRASE"; break;
123 case STATUS_GOOD_PASSPHRASE : s = "GOOD_PASSPHRASE"; break;
124 case STATUS_GOODMDC : s = "GOODMDC"; break;
125 case STATUS_BADMDC : s = "BADMDC"; break;
126 case STATUS_ERRMDC : s = "ERRMDC"; break;
127 case STATUS_IMPORTED : s = "IMPORTED"; break;
128 case STATUS_IMPORT_OK : s = "IMPORT_OK"; break;
129 case STATUS_IMPORT_CHECK : s = "IMPORT_CHECK"; break;
130 case STATUS_IMPORT_RES : s = "IMPORT_RES"; break;
131 case STATUS_FILE_START : s = "FILE_START"; break;
132 case STATUS_FILE_DONE : s = "FILE_DONE"; break;
133 case STATUS_FILE_ERROR : s = "FILE_ERROR"; break;
134 case STATUS_BEGIN_DECRYPTION:s = "BEGIN_DECRYPTION"; break;
135 case STATUS_END_DECRYPTION : s = "END_DECRYPTION"; break;
136 case STATUS_BEGIN_ENCRYPTION:s = "BEGIN_ENCRYPTION"; break;
137 case STATUS_END_ENCRYPTION : s = "END_ENCRYPTION"; break;
138 case STATUS_DELETE_PROBLEM : s = "DELETE_PROBLEM"; break;
139 case STATUS_PROGRESS : s = "PROGRESS"; break;
140 case STATUS_SIG_CREATED : s = "SIG_CREATED"; break;
141 case STATUS_SESSION_KEY : s = "SESSION_KEY"; break;
142 case STATUS_NOTATION_NAME : s = "NOTATION_NAME" ; break;
143 case STATUS_NOTATION_DATA : s = "NOTATION_DATA" ; break;
144 case STATUS_POLICY_URL : s = "POLICY_URL" ; break;
145 case STATUS_BEGIN_STREAM : s = "BEGIN_STREAM"; break;
146 case STATUS_END_STREAM : s = "END_STREAM"; break;
147 case STATUS_KEY_CREATED : s = "KEY_CREATED"; break;
148 case STATUS_KEY_NOT_CREATED: s = "KEY_NOT_CREATED"; break;
149 case STATUS_USERID_HINT : s = "USERID_HINT"; break;
150 case STATUS_UNEXPECTED : s = "UNEXPECTED"; break;
151 case STATUS_INV_RECP : s = "INV_RECP"; break;
152 case STATUS_NO_RECP : s = "NO_RECP"; break;
153 case STATUS_ALREADY_SIGNED : s = "ALREADY_SIGNED"; break;
154 case STATUS_SIGEXPIRED : s = "SIGEXPIRED deprecated-use-keyexpired-instead"; break;
155 case STATUS_EXPSIG : s = "EXPSIG"; break;
156 case STATUS_EXPKEYSIG : s = "EXPKEYSIG"; break;
157 case STATUS_REVKEYSIG : s = "REVKEYSIG"; break;
158 case STATUS_ATTRIBUTE : s = "ATTRIBUTE"; break;
159 case STATUS_CARDCTRL : s = "CARDCTRL"; break;
160 case STATUS_PLAINTEXT : s = "PLAINTEXT"; break;
161 case STATUS_PLAINTEXT_LENGTH:s = "PLAINTEXT_LENGTH"; break;
162 case STATUS_SIG_SUBPACKET : s = "SIG_SUBPACKET"; break;
163 case STATUS_SC_OP_SUCCESS : s = "SC_OP_SUCCESS"; break;
164 case STATUS_SC_OP_FAILURE : s = "SC_OP_FAILURE"; break;
165 case STATUS_BACKUP_KEY_CREATED:s="BACKUP_KEY_CREATED"; break;
166 case STATUS_PKA_TRUST_BAD : s = "PKA_TRUST_BAD"; break;
167 case STATUS_PKA_TRUST_GOOD : s = "PKA_TRUST_GOOD"; break;
168 case STATUS_BEGIN_SIGNING : s = "BEGIN_SIGNING"; break;
169 default: s = "?"; break;
171 return s;
175 /* Return true if the status message NO may currently be issued. We
176 need this to avoid syncronisation problem while auto retrieving a
177 key. There it may happen that a status NODATA is issued for a non
178 available key and the user may falsely interpret this has a missing
179 signature. */
180 static int
181 status_currently_allowed (int no)
183 if (!glo_ctrl.in_auto_key_retrieve)
184 return 1; /* Yes. */
186 /* We allow some statis anyway, so that import statistics are
187 correct and to avoid problems if the retriebval subsystem will
188 prompt the user. */
189 switch (no)
191 case STATUS_GET_BOOL:
192 case STATUS_GET_LINE:
193 case STATUS_GET_HIDDEN:
194 case STATUS_GOT_IT:
195 case STATUS_IMPORTED:
196 case STATUS_IMPORT_OK:
197 case STATUS_IMPORT_CHECK:
198 case STATUS_IMPORT_RES:
199 return 1; /* Yes. */
200 default:
201 break;
203 return 0; /* No. */
207 void
208 set_status_fd ( int fd )
210 static int last_fd = -1;
212 if ( fd != -1 && last_fd == fd )
213 return;
215 if ( statusfp && statusfp != stdout && statusfp != stderr )
216 fclose (statusfp);
217 statusfp = NULL;
218 if ( fd == -1 )
219 return;
221 if( fd == 1 )
222 statusfp = stdout;
223 else if( fd == 2 )
224 statusfp = stderr;
225 else
226 statusfp = fdopen( fd, "w" );
227 if( !statusfp ) {
228 log_fatal("can't open fd %d for status output: %s\n",
229 fd, strerror(errno));
231 last_fd = fd;
232 register_primegen_progress ( progress_cb, "primegen" );
233 register_pk_dsa_progress ( progress_cb, "pk_dsa" );
234 register_pk_elg_progress ( progress_cb, "pk_elg" );
238 is_status_enabled()
240 return !!statusfp;
243 void
244 write_status ( int no )
246 write_status_text( no, NULL );
249 void
250 write_status_text ( int no, const char *text)
252 if( !statusfp || !status_currently_allowed (no) )
253 return; /* Not enabled or allowed. */
255 fputs ( "[GNUPG:] ", statusfp );
256 fputs ( get_status_string (no), statusfp );
257 if( text ) {
258 putc ( ' ', statusfp );
259 for (; *text; text++) {
260 if (*text == '\n')
261 fputs ( "\\n", statusfp );
262 else if (*text == '\r')
263 fputs ( "\\r", statusfp );
264 else
265 putc ( *(const byte *)text, statusfp );
268 putc ('\n',statusfp);
269 if ( fflush (statusfp) && opt.exit_on_status_write_error )
270 g10_exit (0);
275 * Write a status line with a buffer using %XX escapes. If WRAP is >
276 * 0 wrap the line after this length. If STRING is not NULL it will
277 * be prepended to the buffer, no escaping is done for string.
278 * A wrap of -1 forces spaces not to be encoded as %20.
280 void
281 write_status_text_and_buffer ( int no, const char *string,
282 const char *buffer, size_t len, int wrap )
284 const char *s, *text;
285 int esc, first;
286 int lower_limit = ' ';
287 size_t n, count, dowrap;
289 if( !statusfp || !status_currently_allowed (no) )
290 return; /* Not enabled or allowed. */
292 if (wrap == -1) {
293 lower_limit--;
294 wrap = 0;
297 text = get_status_string (no);
298 count = dowrap = first = 1;
299 do {
300 if (dowrap) {
301 fprintf (statusfp, "[GNUPG:] %s ", text );
302 count = dowrap = 0;
303 if (first && string) {
304 fputs (string, statusfp);
305 count += strlen (string);
307 first = 0;
309 for (esc=0, s=buffer, n=len; n && !esc; s++, n-- ) {
310 if ( *s == '%' || *(const byte*)s <= lower_limit
311 || *(const byte*)s == 127 )
312 esc = 1;
313 if ( wrap && ++count > wrap ) {
314 dowrap=1;
315 break;
318 if (esc) {
319 s--; n++;
321 if (s != buffer)
322 fwrite (buffer, s-buffer, 1, statusfp );
323 if ( esc ) {
324 fprintf (statusfp, "%%%02X", *(const byte*)s );
325 s++; n--;
327 buffer = s;
328 len = n;
329 if ( dowrap && len )
330 putc ( '\n', statusfp );
331 } while ( len );
333 putc ('\n',statusfp);
334 if ( fflush (statusfp) && opt.exit_on_status_write_error )
335 g10_exit (0);
338 void
339 write_status_buffer ( int no, const char *buffer, size_t len, int wrap )
341 write_status_text_and_buffer (no, NULL, buffer, len, wrap);
345 #ifdef USE_SHM_COPROCESSING
347 #ifndef IPC_RMID_DEFERRED_RELEASE
348 static void
349 remove_shmid( void )
351 if( shm_id != -1 ) {
352 shmctl ( shm_id, IPC_RMID, 0);
353 shm_id = -1;
356 #endif
358 void
359 init_shm_coprocessing ( ulong requested_shm_size, int lock_mem )
361 char buf[100];
362 struct shmid_ds shmds;
364 #ifndef IPC_RMID_DEFERRED_RELEASE
365 atexit( remove_shmid );
366 #endif
367 requested_shm_size = (requested_shm_size + 4095) & ~4095;
368 if ( requested_shm_size > 2 * 4096 )
369 log_fatal("too much shared memory requested; only 8k are allowed\n");
370 shm_size = 4096 /* one page for us */ + requested_shm_size;
372 shm_id = shmget( IPC_PRIVATE, shm_size, IPC_CREAT | 0700 );
373 if ( shm_id == -1 )
374 log_fatal("can't get %uk of shared memory: %s\n",
375 (unsigned)shm_size/1024, strerror(errno));
377 #if !defined(IPC_HAVE_SHM_LOCK) \
378 && defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
379 /* part of the old code which uses mlock */
380 shm_area = shmat( shm_id, 0, 0 );
381 if ( shm_area == (char*)-1 )
382 log_fatal("can't attach %uk shared memory: %s\n",
383 (unsigned)shm_size/1024, strerror(errno));
384 log_debug("mapped %uk shared memory at %p, id=%d\n",
385 (unsigned)shm_size/1024, shm_area, shm_id );
386 if( lock_mem ) {
387 #ifdef USE_CAPABILITIES
388 cap_set_proc( cap_from_text("cap_ipc_lock+ep") );
389 #endif
390 /* (need the cast for Solaris with Sun's workshop compilers) */
391 if ( mlock ( (char*)shm_area, shm_size) )
392 log_info("locking shared memory %d failed: %s\n",
393 shm_id, strerror(errno));
394 else
395 shm_is_locked = 1;
396 #ifdef USE_CAPABILITIES
397 cap_set_proc( cap_from_text("cap_ipc_lock+p") );
398 #endif
401 #ifdef IPC_RMID_DEFERRED_RELEASE
402 if( shmctl( shm_id, IPC_RMID, 0) )
403 log_fatal("shmctl IPC_RMDID of %d failed: %s\n",
404 shm_id, strerror(errno));
405 #endif
407 if( shmctl( shm_id, IPC_STAT, &shmds ) )
408 log_fatal("shmctl IPC_STAT of %d failed: %s\n",
409 shm_id, strerror(errno));
410 if( shmds.shm_perm.uid != getuid() ) {
411 shmds.shm_perm.uid = getuid();
412 if( shmctl( shm_id, IPC_SET, &shmds ) )
413 log_fatal("shmctl IPC_SET of %d failed: %s\n",
414 shm_id, strerror(errno));
417 #else /* this is the new code which handles the changes in the SHM
418 * semantics introduced with Linux 2.4. The changes is that we
419 * now change the permissions and then attach to the memory.
422 if( lock_mem ) {
423 #ifdef USE_CAPABILITIES
424 cap_set_proc( cap_from_text("cap_ipc_lock+ep") );
425 #endif
426 #ifdef IPC_HAVE_SHM_LOCK
427 if ( shmctl (shm_id, SHM_LOCK, 0) )
428 log_info("locking shared memory %d failed: %s\n",
429 shm_id, strerror(errno));
430 else
431 shm_is_locked = 1;
432 #else
433 log_info("Locking shared memory %d failed: No way to do it\n", shm_id );
434 #endif
435 #ifdef USE_CAPABILITIES
436 cap_set_proc( cap_from_text("cap_ipc_lock+p") );
437 #endif
440 if( shmctl( shm_id, IPC_STAT, &shmds ) )
441 log_fatal("shmctl IPC_STAT of %d failed: %s\n",
442 shm_id, strerror(errno));
443 if( shmds.shm_perm.uid != getuid() ) {
444 shmds.shm_perm.uid = getuid();
445 if( shmctl( shm_id, IPC_SET, &shmds ) )
446 log_fatal("shmctl IPC_SET of %d failed: %s\n",
447 shm_id, strerror(errno));
450 shm_area = shmat( shm_id, 0, 0 );
451 if ( shm_area == (char*)-1 )
452 log_fatal("can't attach %uk shared memory: %s\n",
453 (unsigned)shm_size/1024, strerror(errno));
454 log_debug("mapped %uk shared memory at %p, id=%d\n",
455 (unsigned)shm_size/1024, shm_area, shm_id );
457 #ifdef IPC_RMID_DEFERRED_RELEASE
458 if( shmctl( shm_id, IPC_RMID, 0) )
459 log_fatal("shmctl IPC_RMDID of %d failed: %s\n",
460 shm_id, strerror(errno));
461 #endif
463 #endif
464 /* write info; Protocol version, id, size, locked size */
465 sprintf( buf, "pv=1 pid=%d shmid=%d sz=%u lz=%u", (int)getpid(),
466 shm_id, (unsigned)shm_size, shm_is_locked? (unsigned)shm_size:0 );
467 write_status_text( STATUS_SHM_INFO, buf );
470 /****************
471 * Request a string from client
472 * If bool, returns static string on true (do not free) or NULL for false
474 static char *
475 do_shm_get( const char *keyword, int hidden, int bool )
477 size_t n;
478 byte *p;
479 char *string;
481 if( !shm_area )
482 BUG();
484 shm_area[0] = 0; /* msb of length of control block */
485 shm_area[1] = 32; /* and lsb */
486 shm_area[2] = 1; /* indicate that we are waiting on a reply */
487 shm_area[3] = 0; /* clear data available flag */
489 write_status_text( bool? STATUS_SHM_GET_BOOL :
490 hidden? STATUS_SHM_GET_HIDDEN : STATUS_SHM_GET, keyword );
492 do {
493 pause_on_sigusr(1);
494 if( shm_area[0] || shm_area[1] != 32 || shm_area[2] != 1 )
495 log_fatal("client modified shm control block - abort\n");
496 } while( !shm_area[3] );
497 shm_area[2] = 0; /* reset request flag */
498 p = (byte*)shm_area+32;
499 n = p[0] << 8 | p[1];
500 p += 2;
501 if( n+32+2+1 > 4095 )
502 log_fatal("client returns too large data (%u bytes)\n", (unsigned)n );
504 if( bool )
505 return p[0]? "" : NULL;
507 string = hidden? xmalloc_secure( n+1 ) : xmalloc( n+1 );
508 memcpy(string, p, n );
509 string[n] = 0; /* make sure it is a string */
510 if( hidden ) /* invalidate the memory */
511 memset( p, 0, n );
513 return string;
516 #endif /* USE_SHM_COPROCESSING */
518 static int
519 myread(int fd, void *buf, size_t count)
521 int rc;
522 do {
523 rc = read( fd, buf, count );
524 } while ( rc == -1 && errno == EINTR );
525 if ( !rc && count ) {
526 static int eof_emmited=0;
527 if ( eof_emmited < 3 ) {
528 *(char*)buf = CONTROL_D;
529 rc = 1;
530 eof_emmited++;
532 else { /* Ctrl-D not caught - do something reasonable */
533 #ifdef HAVE_DOSISH_SYSTEM
534 raise (SIGINT); /* nothing to hangup under DOS */
535 #else
536 raise (SIGHUP); /* no more input data */
537 #endif
540 return rc;
545 /****************
546 * Request a string from the client over the command-fd
547 * If bool, returns static string on true (do not free) or NULL for false
549 static char *
550 do_get_from_fd( const char *keyword, int hidden, int bool )
552 int i, len;
553 char *string;
555 if(statusfp!=stdout)
556 fflush(stdout);
558 write_status_text( bool? STATUS_GET_BOOL :
559 hidden? STATUS_GET_HIDDEN : STATUS_GET_LINE, keyword );
561 for( string = NULL, i = len = 200; ; i++ ) {
562 if( i >= len-1 ) {
563 char *save = string;
564 len += 100;
565 string = hidden? xmalloc_secure ( len ) : xmalloc ( len );
566 if( save )
567 memcpy(string, save, i );
568 else
569 i=0;
571 /* Hmmm: why not use our read_line function here */
572 if( myread( opt.command_fd, string+i, 1) != 1 || string[i] == '\n' )
573 break;
574 else if ( string[i] == CONTROL_D ) {
575 /* found ETX - cancel the line and return a sole ETX */
576 string[0] = CONTROL_D;
577 i=1;
578 break;
581 string[i] = 0;
583 write_status( STATUS_GOT_IT );
585 if( bool ) /* Fixme: is this correct??? */
586 return (string[0] == 'Y' || string[0] == 'y') ? "" : NULL;
588 return string;
594 cpr_enabled()
596 if( opt.command_fd != -1 )
597 return 1;
598 #ifdef USE_SHM_COPROCESSING
599 if( opt.shm_coprocess )
600 return 1;
601 #endif
602 return 0;
605 char *
606 cpr_get_no_help( const char *keyword, const char *prompt )
608 char *p;
610 if( opt.command_fd != -1 )
611 return do_get_from_fd ( keyword, 0, 0 );
612 #ifdef USE_SHM_COPROCESSING
613 if( opt.shm_coprocess )
614 return do_shm_get( keyword, 0, 0 );
615 #endif
616 for(;;) {
617 p = tty_get( prompt );
618 return p;
622 char *
623 cpr_get( const char *keyword, const char *prompt )
625 char *p;
627 if( opt.command_fd != -1 )
628 return do_get_from_fd ( keyword, 0, 0 );
629 #ifdef USE_SHM_COPROCESSING
630 if( opt.shm_coprocess )
631 return do_shm_get( keyword, 0, 0 );
632 #endif
633 for(;;) {
634 p = tty_get( prompt );
635 if( *p=='?' && !p[1] && !(keyword && !*keyword)) {
636 xfree(p);
637 display_online_help( keyword );
639 else
640 return p;
645 char *
646 cpr_get_utf8( const char *keyword, const char *prompt )
648 char *p;
649 p = cpr_get( keyword, prompt );
650 if( p ) {
651 char *utf8 = native_to_utf8( p );
652 xfree( p );
653 p = utf8;
655 return p;
658 char *
659 cpr_get_hidden( const char *keyword, const char *prompt )
661 char *p;
663 if( opt.command_fd != -1 )
664 return do_get_from_fd ( keyword, 1, 0 );
665 #ifdef USE_SHM_COPROCESSING
666 if( opt.shm_coprocess )
667 return do_shm_get( keyword, 1, 0 );
668 #endif
669 for(;;) {
670 p = tty_get_hidden( prompt );
671 if( *p == '?' && !p[1] ) {
672 xfree(p);
673 display_online_help( keyword );
675 else
676 return p;
680 void
681 cpr_kill_prompt(void)
683 if( opt.command_fd != -1 )
684 return;
685 #ifdef USE_SHM_COPROCESSING
686 if( opt.shm_coprocess )
687 return;
688 #endif
689 tty_kill_prompt();
690 return;
694 cpr_get_answer_is_yes( const char *keyword, const char *prompt )
696 int yes;
697 char *p;
699 if( opt.command_fd != -1 )
700 return !!do_get_from_fd ( keyword, 0, 1 );
701 #ifdef USE_SHM_COPROCESSING
702 if( opt.shm_coprocess )
703 return !!do_shm_get( keyword, 0, 1 );
704 #endif
705 for(;;) {
706 p = tty_get( prompt );
707 trim_spaces(p); /* it is okay to do this here */
708 if( *p == '?' && !p[1] ) {
709 xfree(p);
710 display_online_help( keyword );
712 else {
713 tty_kill_prompt();
714 yes = answer_is_yes(p);
715 xfree(p);
716 return yes;
722 cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt )
724 int yes;
725 char *p;
727 if( opt.command_fd != -1 )
728 return !!do_get_from_fd ( keyword, 0, 1 );
729 #ifdef USE_SHM_COPROCESSING
730 if( opt.shm_coprocess )
731 return !!do_shm_get( keyword, 0, 1 );
732 #endif
733 for(;;) {
734 p = tty_get( prompt );
735 trim_spaces(p); /* it is okay to do this here */
736 if( *p == '?' && !p[1] ) {
737 xfree(p);
738 display_online_help( keyword );
740 else {
741 tty_kill_prompt();
742 yes = answer_is_yes_no_quit(p);
743 xfree(p);
744 return yes;
751 cpr_get_answer_okay_cancel (const char *keyword,
752 const char *prompt,
753 int def_answer)
755 int yes;
756 char *answer = NULL;
757 char *p;
759 if( opt.command_fd != -1 )
760 answer = do_get_from_fd ( keyword, 0, 0 );
761 #ifdef USE_SHM_COPROCESSING
762 else if( opt.shm_coprocess )
763 answer = do_shm_get( keyword, 0, 0 );
764 #endif
766 if (answer)
768 yes = answer_is_okay_cancel (answer, def_answer);
769 xfree (answer);
770 return yes;
773 for(;;)
775 p = tty_get( prompt );
776 trim_spaces(p); /* it is okay to do this here */
777 if (*p == '?' && !p[1])
779 xfree(p);
780 display_online_help (keyword);
782 else
784 tty_kill_prompt();
785 yes = answer_is_okay_cancel (p, def_answer);
786 xfree(p);
787 return yes;