~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-security

« back to all changes in this revision

Viewing changes to tools/symcryptrun.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* symcryptrun.c - Tool to call simple symmetric encryption tools.
2
 
 *      Copyright (C) 2005 Free Software Foundation, Inc.
 
2
 *      Copyright (C) 2005, 2007 Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of GnuPG.
5
5
 *
6
6
 * GnuPG is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * the Free Software Foundation; either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
11
 * GnuPG is distributed in the hope that it will be useful,
14
14
 * GNU General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
20
 
68
67
#include <string.h>
69
68
#include <errno.h>
70
69
#include <assert.h>
 
70
#include <signal.h>
71
71
#include <sys/stat.h>
72
72
#include <sys/types.h>
73
73
#include <sys/wait.h>
 
74
#ifdef HAVE_PTY_H
74
75
#include <pty.h>
 
76
#endif
75
77
#include <utmp.h>
76
78
#include <ctype.h>
77
79
#ifdef HAVE_LOCALE_H
92
94
#include "../common/simple-pwquery.h"
93
95
 
94
96
 
95
 
/* Used by gcry for logging */
96
 
static void
97
 
my_gcry_logger (void *dummy, int level, const char *fmt, va_list arg_ptr)
98
 
{
99
 
  /* translate the log levels */
100
 
  switch (level)
101
 
    {
102
 
    case GCRY_LOG_CONT: level = JNLIB_LOG_CONT; break;
103
 
    case GCRY_LOG_INFO: level = JNLIB_LOG_INFO; break;
104
 
    case GCRY_LOG_WARN: level = JNLIB_LOG_WARN; break;
105
 
    case GCRY_LOG_ERROR:level = JNLIB_LOG_ERROR; break;
106
 
    case GCRY_LOG_FATAL:level = JNLIB_LOG_FATAL; break;
107
 
    case GCRY_LOG_BUG:  level = JNLIB_LOG_BUG; break;
108
 
    case GCRY_LOG_DEBUG:level = JNLIB_LOG_DEBUG; break;
109
 
    default:            level = JNLIB_LOG_ERROR; break;      }
110
 
  log_logv (level, fmt, arg_ptr);
111
 
}
112
 
 
113
 
 
114
97
/* From simple-gettext.c.  */
115
98
 
116
99
/* We assume to have `unsigned long int' value with at least 32 bits.  */
238
221
}
239
222
 
240
223
 
241
 
/* Initialize the gettext system.  */
242
 
static void
243
 
i18n_init(void)
244
 
{
245
 
#ifdef USE_SIMPLE_GETTEXT
246
 
  set_gettext_file (PACKAGE_GT);
247
 
#else
248
 
# ifdef ENABLE_NLS
249
 
  setlocale (LC_ALL, "");
250
 
  bindtextdomain (PACKAGE_GT, LOCALEDIR);
251
 
  textdomain (PACKAGE_GT);
252
 
# endif
253
 
#endif
254
 
}
255
 
 
256
224
 
257
225
/* This is in the GNU C library in unistd.h.  */
258
226
 
268
236
       __result; }))
269
237
#endif
270
238
 
 
239
/* Include the implementation of map_spwq_error.  */
 
240
MAP_SPWQ_ERROR_IMPL
271
241
 
272
242
/* Unlink a file, and shred it if SHRED is true.  */
273
243
int
454
424
{
455
425
  int err;
456
426
  char *pw;
457
 
#ifdef HAVE_LANGINFO_CODESET
458
 
  char *orig_codeset = NULL;
459
 
#endif
 
427
  char *orig_codeset;
460
428
 
461
429
  if (canceled)
462
430
    *canceled = 0;
463
431
  
464
 
#ifdef ENABLE_NLS
465
 
  /* The Assuan agent protocol requires us to transmit utf-8 strings */
466
 
  orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
467
 
#ifdef HAVE_LANGINFO_CODESET
468
 
  if (!orig_codeset)
469
 
    orig_codeset = nl_langinfo (CODESET);
470
 
#endif
471
 
  if (orig_codeset && !strcmp (orig_codeset, "UTF-8"))
472
 
    orig_codeset = NULL;
473
 
  if (orig_codeset)
474
 
    {
475
 
      /* We only switch when we are able to restore the codeset later. */
476
 
      orig_codeset = xstrdup (orig_codeset);
477
 
      if (!bind_textdomain_codeset (PACKAGE_GT, "utf-8"))
478
 
        orig_codeset = NULL; 
479
 
    }
480
 
#endif
481
 
 
 
432
  orig_codeset = i18n_switchto_utf8 ();
482
433
  pw = simple_pwquery (cacheid,
483
434
                       again ? _("does not match - try again"):NULL,
484
 
                       _("Passphrase:"), NULL, &err);
485
 
 
486
 
#ifdef ENABLE_NLS
487
 
  if (orig_codeset)
488
 
    {
489
 
      bind_textdomain_codeset (PACKAGE_GT, orig_codeset);
490
 
      xfree (orig_codeset);
491
 
    }
492
 
#endif
 
435
                       _("Passphrase:"), NULL, 0, &err);
 
436
  err = map_spwq_error (err);
 
437
  i18n_switchback (orig_codeset);
493
438
 
494
439
  if (!pw)
495
440
    {
938
883
  set_strusage (my_strusage);
939
884
  log_set_prefix ("symcryptrun", 1);
940
885
 
941
 
  /* Try to auto set the character set.  */
942
 
  set_native_charset (NULL); 
 
886
  /* Make sure that our subsystems are ready.  */
 
887
  init_common_subsystems ();
943
888
 
944
889
  i18n_init();
945
890
 
1049
994
  gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
1050
995
  if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
1051
996
    {
1052
 
      log_fatal( _("libgcrypt is too old (need %s, have %s)\n"),
 
997
      log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt",
1053
998
                 NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
1054
999
    }
1055
 
  gcry_set_log_handler (my_gcry_logger, NULL);
 
1000
  setup_libgcrypt_logging ();
1056
1001
  gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
1057
1002
 
 
1003
  /* Tell simple-pwquery about the the standard socket name.  */
 
1004
  {
 
1005
    char *tmp = make_filename (opt.homedir, "S.gpg-agent", NULL);
 
1006
    simple_pw_set_socket (tmp);
 
1007
    xfree (tmp);
 
1008
  }
 
1009
 
1058
1010
  if (!opt.class)
1059
1011
    {
1060
1012
      log_error (_("no class provided\n"));
1061
1013
      res = 1;
1062
1014
    }
1063
1015
  else if (!strcmp (opt.class, "confucius"))
1064
 
    res = confucius_main (mode, argc, argv);
 
1016
    {
 
1017
      res = confucius_main (mode, argc, argv);
 
1018
    }
1065
1019
  else
1066
1020
    {
1067
1021
      log_error (_("class %s is not supported\n"), opt.class);