~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to tools/gpgconf-comp.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Dorland
  • Date: 2009-03-08 22:46:47 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090308224647-gq17gatcl71lrc2k
Tags: 2.0.11-1
* New upstream release. (Closes: #496663)
* debian/control: Make the description a little more distinctive than
  gnupg v1's. Thanks Jari Aalto. (Closes: #496323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* gpgconf-comp.c - Configuration utility for GnuPG.
2
 
 * Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc.
 
2
 * Copyright (C) 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of GnuPG.
5
5
 *
104
104
 
105
105
 
106
106
/* Forward declaration.  */
107
 
void gpg_agent_runtime_change (void);
 
107
static void gpg_agent_runtime_change (void);
 
108
static void scdaemon_runtime_change (void);
108
109
 
109
110
/* Backend configuration.  Backends are used to decide how the default
110
111
   and current value of an option can be determined, and how the
163
164
  void (*runtime_change) (void);
164
165
 
165
166
  /* The option name for the configuration filename of this backend.
166
 
     This must be an absolute pathname.  It can be an option from a
 
167
     This must be an absolute filename.  It can be an option from a
167
168
     different backend (but then ordering of the options might
168
 
     matter).  */
 
169
     matter).  Note: This must be unique among all components.  */
169
170
  const char *option_config_filename;
170
171
 
171
172
  /* If this is a file backend rather than a program backend, then
181
182
    { "GPG Agent", "gpg-agent", GNUPG_MODULE_NAME_AGENT, 
182
183
      gpg_agent_runtime_change, "gpgconf-gpg-agent.conf" },
183
184
    { "SCDaemon", "scdaemon", GNUPG_MODULE_NAME_SCDAEMON,
184
 
      NULL, "gpgconf-scdaemon.conf" },
 
185
      scdaemon_runtime_change, "gpgconf-scdaemon.conf" },
185
186
    { "DirMngr", "dirmngr", GNUPG_MODULE_NAME_DIRMNGR,
186
187
      NULL, "gpgconf-dirmngr.conf" },
187
188
    { "DirMngr LDAP Server List", NULL, 0, 
218
219
 
219
220
    /* Complex argument types.  */
220
221
 
221
 
    /* A complete pathname.  */
222
 
    GC_ARG_TYPE_PATHNAME = 32,
 
222
    /* A complete filename.  */
 
223
    GC_ARG_TYPE_FILENAME = 32,
223
224
 
224
225
    /* An LDAP server in the format
225
226
       HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN.  */
234
235
    /* A user ID or key ID or fingerprint for a certificate with a key.  */
235
236
    GC_ARG_TYPE_SEC_KEY = 36,
236
237
 
 
238
    /* A alias list made up of a key, an equal sign and a space
 
239
       separated list of values.  */
 
240
    GC_ARG_TYPE_ALIAS_LIST = 37,
 
241
 
237
242
    /* ADD NEW COMPLEX TYPE ENTRIES HERE.  */
238
243
 
239
244
    /* The number of the above entries.  */
276
281
    { GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
277
282
 
278
283
    /* The complex argument types have a basic type as fallback.  */
279
 
    { GC_ARG_TYPE_STRING, "pathname" },
 
284
    { GC_ARG_TYPE_STRING, "filename" },
280
285
    { GC_ARG_TYPE_STRING, "ldap server" },
281
286
    { GC_ARG_TYPE_STRING, "key fpr" },
282
287
    { GC_ARG_TYPE_STRING, "pub key" },
283
288
    { GC_ARG_TYPE_STRING, "sec key" },
 
289
    { GC_ARG_TYPE_STRING, "alias list" },
284
290
  };
285
291
 
286
292
 
460
466
 {
461
467
   /* The configuration file to which we write the changes.  */
462
468
   { "gpgconf-gpg-agent.conf", GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
463
 
     NULL, NULL, GC_ARG_TYPE_PATHNAME, GC_BACKEND_GPG_AGENT },
 
469
     NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG_AGENT },
464
470
 
465
471
   { "Monitor",
466
472
     GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
480
486
     "gnupg", N_("Options controlling the configuration") },
481
487
   { "options", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
482
488
     "gnupg", "|FILE|read options from FILE",
483
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_GPG_AGENT },
 
489
     GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG_AGENT },
484
490
   { "disable-scdaemon", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
485
491
     "gnupg", "do not use the SCdaemon",
486
492
     GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
493
499
     GC_ARG_TYPE_STRING, GC_BACKEND_GPG_AGENT },
494
500
   { "log-file", GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
495
501
     "gnupg", N_("|FILE|write server mode logs to FILE"),
496
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_GPG_AGENT },
 
502
     GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG_AGENT },
497
503
   { "faked-system-time", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
498
504
     NULL, NULL,
499
505
     GC_ARG_TYPE_UINT32, GC_BACKEND_GPG_AGENT },
545
551
   { "check-passphrase-pattern", GC_OPT_FLAG_RUNTIME,
546
552
     GC_LEVEL_EXPERT,
547
553
     "gnupg", N_("|FILE|check new passphrases against pattern in FILE"),
548
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_GPG_AGENT },
 
554
     GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG_AGENT },
549
555
   { "max-passphrase-days", GC_OPT_FLAG_RUNTIME,
550
556
     GC_LEVEL_EXPERT, "gnupg", 
551
557
     N_("|N|expire the passphrase after N days"),
564
570
 {
565
571
   /* The configuration file to which we write the changes.  */
566
572
   { "gpgconf-scdaemon.conf", GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
567
 
     NULL, NULL, GC_ARG_TYPE_PATHNAME, GC_BACKEND_SCDAEMON },
 
573
     NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_SCDAEMON },
568
574
 
569
575
   { "Monitor",
570
576
     GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
571
577
     "gnupg", N_("Options controlling the diagnostic output") },
572
 
   { "verbose", GC_OPT_FLAG_LIST, GC_LEVEL_BASIC,
 
578
   { "verbose", GC_OPT_FLAG_LIST|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
573
579
     "gnupg", "verbose",
574
580
     GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
575
581
   { "quiet", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
584
590
     "gnupg", N_("Options controlling the configuration") },
585
591
   { "options", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
586
592
     "gnupg", "|FILE|read options from FILE",
587
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_SCDAEMON },
588
 
   { "reader-port", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
 
593
     GC_ARG_TYPE_FILENAME, GC_BACKEND_SCDAEMON },
 
594
   { "reader-port", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
589
595
     "gnupg", "|N|connect to reader at port N",
590
596
     GC_ARG_TYPE_STRING, GC_BACKEND_SCDAEMON },
591
 
   { "ctapi-driver", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
 
597
   { "ctapi-driver", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
592
598
     "gnupg", "|NAME|use NAME as ct-API driver",
593
599
     GC_ARG_TYPE_STRING, GC_BACKEND_SCDAEMON },
594
 
   { "pcsc-driver", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
 
600
   { "pcsc-driver", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
595
601
     "gnupg", "|NAME|use NAME as PC/SC driver",
596
602
     GC_ARG_TYPE_STRING, GC_BACKEND_SCDAEMON },
597
 
   { "disable-opensc", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
598
 
     "gnupg", "do not use the OpenSC layer",
599
 
     GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
600
 
   { "disable-ccid", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
 
603
   { "disable-ccid", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_EXPERT,
601
604
     "gnupg", "do not use the internal CCID driver",
602
605
     GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
603
 
   { "disable-keypad", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
 
606
   { "disable-keypad", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
604
607
     "gnupg", "do not use a reader's keypad",
605
608
     GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
 
609
   { "card-timeout", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
 
610
     "gnupg", "|N|disconnect the card after N seconds of inactivity",
 
611
     GC_ARG_TYPE_UINT32, GC_BACKEND_SCDAEMON },
606
612
 
607
613
   { "Debug",
608
614
     GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
609
615
     "gnupg", N_("Options useful for debugging") },
610
 
   { "debug-level", GC_OPT_FLAG_ARG_OPT, GC_LEVEL_ADVANCED,
 
616
   { "debug-level", GC_OPT_FLAG_ARG_OPT|GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
611
617
     "gnupg", "|LEVEL|set the debugging level to LEVEL",
612
618
     GC_ARG_TYPE_STRING, GC_BACKEND_SCDAEMON },
613
 
   { "log-file", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
614
 
     "gnupg", N_("|FILE|write server mode logs to FILE"),
615
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_SCDAEMON },
 
619
   { "log-file", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
 
620
     "gnupg", N_("|FILE|write a log to FILE"),
 
621
     GC_ARG_TYPE_FILENAME, GC_BACKEND_SCDAEMON },
616
622
 
617
623
   { "Security",
618
624
     GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
619
625
     "gnupg", N_("Options controlling the security") },
620
 
   { "allow-admin", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
621
 
     "gnupg", "allow the use of admin card commands",
 
626
   { "deny-admin", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
 
627
     "gnupg", "deny the use of admin card commands",
622
628
     GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
623
629
 
624
630
 
631
637
 {
632
638
   /* The configuration file to which we write the changes.  */
633
639
   { "gpgconf-gpg.conf", GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
634
 
     NULL, NULL, GC_ARG_TYPE_PATHNAME, GC_BACKEND_GPG },
 
640
     NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG },
635
641
 
636
642
   { "Monitor",
637
643
     GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
655
661
   { "encrypt-to", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
656
662
     "gnupg", N_("|NAME|encrypt to user ID NAME as well"),
657
663
     GC_ARG_TYPE_STRING, GC_BACKEND_GPG },
 
664
   { "group", GC_OPT_FLAG_LIST, GC_LEVEL_ADVANCED,
 
665
     "gnupg", N_("|SPEC|set up email aliases"),
 
666
     GC_ARG_TYPE_ALIAS_LIST, GC_BACKEND_GPG },
658
667
   { "options", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
659
668
     "gnupg", "|FILE|read options from FILE",
660
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_GPG },
 
669
     GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG },
661
670
 
662
671
   { "Debug",
663
672
     GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
667
676
     GC_ARG_TYPE_STRING, GC_BACKEND_GPG },
668
677
   { "log-file", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
669
678
     "gnupg", N_("|FILE|write server mode logs to FILE"),
670
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_GPG },
 
679
     GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG },
671
680
/*    { "faked-system-time", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE, */
672
681
/*      NULL, NULL, */
673
682
/*      GC_ARG_TYPE_UINT32, GC_BACKEND_GPG }, */
681
690
   { "allow-pka-lookup", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
682
691
     "gnupg", N_("allow PKA lookups (DNS requests)"),
683
692
     GC_ARG_TYPE_NONE, GC_BACKEND_GPG },
 
693
   { "auto-key-locate", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
 
694
     "gnupg", N_("|MECHANISMS|use MECHANISMS to locate keys by mail address"),
 
695
     GC_ARG_TYPE_STRING, GC_BACKEND_GPG },
684
696
 
685
697
 
686
698
   GC_OPTION_NULL
693
705
 {
694
706
   /* The configuration file to which we write the changes.  */
695
707
   { "gpgconf-gpgsm.conf", GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
696
 
     NULL, NULL, GC_ARG_TYPE_PATHNAME, GC_BACKEND_GPGSM },
 
708
     NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_GPGSM },
697
709
 
698
710
   { "Monitor",
699
711
     GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
719
731
     GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM },
720
732
   { "options", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
721
733
     "gnupg", "|FILE|read options from FILE",
722
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_GPGSM },
 
734
     GC_ARG_TYPE_FILENAME, GC_BACKEND_GPGSM },
723
735
   { "prefer-system-dirmngr", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
724
736
     "gnupg", "use system's dirmngr if available",
725
737
     GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
729
741
   { "p12-charset", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
730
742
     "gnupg", N_("|NAME|use encoding NAME for PKCS#12 passphrases"),
731
743
     GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM },
 
744
   { "keyserver", GC_OPT_FLAG_LIST, GC_LEVEL_BASIC,
 
745
     "gnupg", N_("|SPEC|use this keyserver to lookup keys"),
 
746
     GC_ARG_TYPE_LDAP_SERVER, GC_BACKEND_GPGSM },
732
747
 
733
748
   { "Debug",
734
749
     GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
738
753
     GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM },
739
754
   { "log-file", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
740
755
     "gnupg", N_("|FILE|write server mode logs to FILE"),
741
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_GPGSM },
 
756
     GC_ARG_TYPE_FILENAME, GC_BACKEND_GPGSM },
742
757
   { "faked-system-time", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
743
758
     NULL, NULL,
744
759
     GC_ARG_TYPE_UINT32, GC_BACKEND_GPGSM },
777
792
 {
778
793
   /* The configuration file to which we write the changes.  */
779
794
   { "gpgconf-dirmngr.conf", GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
780
 
     NULL, NULL, GC_ARG_TYPE_PATHNAME, GC_BACKEND_DIRMNGR },
 
795
     NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_DIRMNGR },
781
796
 
782
797
   { "Monitor",
783
798
     GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
807
822
     "gnupg", N_("Options controlling the configuration") },
808
823
   { "options", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
809
824
     "dirmngr", "|FILE|read options from FILE",
810
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_DIRMNGR },
 
825
     GC_ARG_TYPE_FILENAME, GC_BACKEND_DIRMNGR },
811
826
 
812
827
   { "Debug",
813
828
     GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
820
835
     GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
821
836
   { "log-file", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
822
837
     "dirmngr", N_("|FILE|write server mode logs to FILE"),
823
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_DIRMNGR },
 
838
     GC_ARG_TYPE_FILENAME, GC_BACKEND_DIRMNGR },
824
839
   { "debug-wait", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
825
840
     NULL, NULL,
826
841
     GC_ARG_TYPE_UINT32, GC_BACKEND_DIRMNGR },
880
895
   { "ldapserverlist-file",
881
896
     GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
882
897
     "dirmngr", "|FILE|read LDAP server list from FILE",
883
 
     GC_ARG_TYPE_PATHNAME, GC_BACKEND_DIRMNGR },
 
898
     GC_ARG_TYPE_FILENAME, GC_BACKEND_DIRMNGR },
884
899
   /* This entry must come after at least one entry for
885
900
      GC_BACKEND_DIRMNGR in this component, so that the entry for
886
901
      "ldapserverlist-file will be initialized before this one.  */
980
995
 
981
996
 
982
997
/* Engine specific support.  */
983
 
void
 
998
static void
984
999
gpg_agent_runtime_change (void)
985
1000
{
986
1001
#ifndef HAVE_W32_SYSTEM
1011
1026
 
1012
1027
  /* Ignore any errors here.  */
1013
1028
  kill (pid, SIGHUP);
 
1029
#else
 
1030
  gpg_error_t err;
 
1031
  const char *pgmname;
 
1032
  const char *argv[2];
 
1033
  pid_t pid;
 
1034
  
 
1035
  pgmname = gnupg_module_name (GNUPG_MODULE_NAME_CONNECT_AGENT);
 
1036
  argv[0] = "reloadagent";
 
1037
  argv[1] = NULL;
 
1038
  
 
1039
  err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid);
 
1040
  if (!err)
 
1041
    err = gnupg_wait_process (pgmname, pid, NULL);
 
1042
  if (err)
 
1043
    gc_error (0, 0, "error running `%s%s': %s",
 
1044
              pgmname, " reloadagent", gpg_strerror (err));
1014
1045
#endif /*!HAVE_W32_SYSTEM*/
1015
1046
}
1016
1047
 
 
1048
 
 
1049
static void
 
1050
scdaemon_runtime_change (void)
 
1051
{
 
1052
  gpg_error_t err;
 
1053
  const char *pgmname;
 
1054
  const char *argv[6];
 
1055
  pid_t pid;
 
1056
  
 
1057
  /* We use "GETINFO app_running" to see whether the agent is already
 
1058
     running and kill it only in this case.  This avoids an explicit
 
1059
     starting of the agent in case it is not yet running.  There is
 
1060
     obviously a race condition but that should not harm too much.  */
 
1061
 
 
1062
  pgmname = gnupg_module_name (GNUPG_MODULE_NAME_CONNECT_AGENT);
 
1063
  argv[0] = "-s";
 
1064
  argv[1] = "GETINFO scd_running";
 
1065
  argv[2] = "/if ${! $?}";
 
1066
  argv[3] = "scd killscd";
 
1067
  argv[4] = "/end";
 
1068
  argv[5] = NULL;
 
1069
  
 
1070
  err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid);
 
1071
  if (!err)
 
1072
    err = gnupg_wait_process (pgmname, pid, NULL);
 
1073
  if (err)
 
1074
    gc_error (0, 0, "error running `%s%s': %s",
 
1075
              pgmname, " scd killscd", gpg_strerror (err));
 
1076
}
 
1077
 
 
1078
 
 
1079
/* Unconditionally reload COMPONENT or all components if COMPONENT is -1.  */
 
1080
void
 
1081
gc_component_reload (int component)
 
1082
{
 
1083
  int runtime[GC_BACKEND_NR];
 
1084
  gc_option_t *option;
 
1085
  gc_backend_t backend;
 
1086
 
 
1087
  /* Set a flag for the backends to be reloaded.  */
 
1088
  for (backend = 0; backend < GC_BACKEND_NR; backend++)
 
1089
    runtime[backend] = 0;
 
1090
  
 
1091
  if (component == -1)
 
1092
    {
 
1093
      for (component = 0; component < GC_COMPONENT_NR; component++)
 
1094
        {
 
1095
          option = gc_component[component].options;
 
1096
          for (; option && option->name; option++)
 
1097
            runtime[option->backend] = 1;
 
1098
        }
 
1099
    }
 
1100
  else
 
1101
    {
 
1102
      assert (component < GC_COMPONENT_NR);
 
1103
      option = gc_component[component].options;
 
1104
      for (; option && option->name; option++)
 
1105
        runtime[option->backend] = 1;
 
1106
    }
 
1107
 
 
1108
  /* Do the reload for all selected backends.  */
 
1109
  for (backend = 0; backend < GC_BACKEND_NR; backend++)  
 
1110
    {
 
1111
      if (runtime[backend] && gc_backend[backend].runtime_change)
 
1112
        (*gc_backend[backend].runtime_change) ();
 
1113
    }
 
1114
}
 
1115
 
 
1116
 
1017
1117
 
1018
1118
/* More or less Robust version of dgettext.  It has the side effect of
1019
1119
   switching the codeset to utf-8 because this is what we want to
1024
1124
static const char *
1025
1125
my_dgettext (const char *domain, const char *msgid)
1026
1126
{
1027
 
#ifdef ENABLE_NLS
 
1127
#ifdef USE_SIMPLE_GETTEXT
 
1128
  if (domain)
 
1129
    {
 
1130
      static int switched_codeset;
 
1131
      char *text;
 
1132
      
 
1133
      if (!switched_codeset)
 
1134
        {
 
1135
          switched_codeset = 1;
 
1136
          gettext_select_utf8 (1);
 
1137
        }
 
1138
 
 
1139
      if (!strcmp (domain, "gnupg"))
 
1140
        domain = PACKAGE_GT;
 
1141
 
 
1142
      /* FIXME: we have no dgettext, thus we can't switch.  */
 
1143
 
 
1144
      text = gettext (msgid);
 
1145
      return text ? text : msgid;
 
1146
    }
 
1147
#elif defined(ENABLE_NLS)
1028
1148
  if (domain)
1029
1149
    {
1030
1150
      static int switched_codeset;
1057
1177
 
1058
1178
/* Percent-Escape special characters.  The string is valid until the
1059
1179
   next invocation of the function.  */
1060
 
static char *
1061
 
my_percent_escape (const char *src)
 
1180
char *
 
1181
gc_percent_escape (const char *src)
1062
1182
{
1063
1183
  static char *esc_str;
1064
1184
  static int esc_str_len;
1186
1306
          desc = gc_component[component].desc;
1187
1307
          desc = my_dgettext (gc_component[component].desc_domain, desc);
1188
1308
          fprintf (out, "%s:%s:",
1189
 
                   gc_component[component].name,  my_percent_escape (desc));
1190
 
          fprintf (out, "%s\n",  my_percent_escape (pgmname));
 
1309
                   gc_component[component].name,  gc_percent_escape (desc));
 
1310
          fprintf (out, "%s\n",  gc_percent_escape (pgmname));
1191
1311
        }
1192
1312
    }
1193
1313
}
1294
1414
}
1295
1415
 
1296
1416
 
1297
 
 
1298
 
/* Check all components that are available.  */
1299
 
void
1300
 
gc_component_check_programs (FILE *out)
 
1417
/* Check the options of a single component.  Returns 0 if everything
 
1418
   is OK.  */
 
1419
int
 
1420
gc_component_check_options (int component, FILE *out, const char *conf_file)
1301
1421
{
1302
1422
  gpg_error_t err;
1303
 
  gc_component_t component;
1304
1423
  unsigned int result;
1305
1424
  int backend_seen[GC_BACKEND_NR];
1306
1425
  gc_backend_t backend;
1307
1426
  gc_option_t *option;
1308
 
  const char *desc;
1309
1427
  const char *pgmname;
1310
 
  const char *argv[2];
 
1428
  const char *argv[4];
 
1429
  int i;
1311
1430
  pid_t pid;
1312
1431
  int exitcode;
1313
1432
  int filedes[2];
1314
 
  error_line_t errlines, errptr;
 
1433
  error_line_t errlines;
1315
1434
 
1316
1435
  /* We use a temporary file to collect the error output.  It would be
1317
1436
     better to use a pipe here but as of now we have no suitable
1318
1437
     fucntion to create a portable pipe outside of exechelp.  Thus it
1319
1438
     is easier to use the tempfile approach.  */
 
1439
 
 
1440
  for (backend = 0; backend < GC_BACKEND_NR; backend++)
 
1441
    backend_seen[backend] = 0;
 
1442
 
 
1443
  option = gc_component[component].options;
 
1444
  for (; option && option->name; option++)
 
1445
    {
 
1446
      if ((option->flags & GC_OPT_FLAG_GROUP))
 
1447
        continue;
 
1448
      backend = option->backend;
 
1449
      if (backend_seen[backend])
 
1450
        continue;
 
1451
      backend_seen[backend] = 1;
 
1452
      assert (backend != GC_BACKEND_ANY);
 
1453
      if (!gc_backend[backend].program)
 
1454
        continue;
 
1455
      if (!gc_backend[backend].module_name)
 
1456
        continue;
 
1457
 
 
1458
      break;
 
1459
    }
 
1460
  if (! option || ! option->name)
 
1461
    return 0;
 
1462
 
 
1463
  pgmname = gnupg_module_name (gc_backend[backend].module_name);
 
1464
  i = 0;
 
1465
  if (conf_file)
 
1466
    {
 
1467
      argv[i++] = "--options";
 
1468
      argv[i++] = conf_file;
 
1469
    }
 
1470
  argv[i++] = "--gpgconf-test";
 
1471
  argv[i++] = NULL;
 
1472
  
 
1473
  err = gnupg_create_inbound_pipe (filedes);
 
1474
  if (err)
 
1475
    gc_error (1, 0, _("error creating a pipe: %s\n"), 
 
1476
              gpg_strerror (err));
 
1477
  
 
1478
  result = 0;
 
1479
  errlines = NULL;
 
1480
  if (gnupg_spawn_process_fd (pgmname, argv, -1, -1, filedes[1], &pid))
 
1481
    {
 
1482
      close (filedes[0]);
 
1483
      close (filedes[1]);
 
1484
      result |= 1; /* Program could not be run.  */
 
1485
    }
 
1486
  else 
 
1487
    {
 
1488
      close (filedes[1]);
 
1489
      errlines = collect_error_output (filedes[0], 
 
1490
                                       gc_component[component].name);
 
1491
      if (gnupg_wait_process (pgmname, pid, &exitcode))
 
1492
        {
 
1493
          if (exitcode == -1)
 
1494
            result |= 1; /* Program could not be run or it
 
1495
                            terminated abnormally.  */
 
1496
          result |= 2; /* Program returned an error.  */
 
1497
        }
 
1498
    }
 
1499
  
 
1500
  /* If the program could not be run, we can't tell whether
 
1501
     the config file is good.  */
 
1502
  if (result & 1)
 
1503
    result |= 2;  
 
1504
  
 
1505
  if (out)
 
1506
    {
 
1507
      const char *desc;
 
1508
      error_line_t errptr;
 
1509
 
 
1510
      desc = gc_component[component].desc;
 
1511
      desc = my_dgettext (gc_component[component].desc_domain, desc);
 
1512
      fprintf (out, "%s:%s:",
 
1513
               gc_component[component].name, gc_percent_escape (desc));
 
1514
      fputs (gc_percent_escape (pgmname), out);
 
1515
      fprintf (out, ":%d:%d:", !(result & 1), !(result & 2));
 
1516
      for (errptr = errlines; errptr; errptr = errptr->next)
 
1517
        {
 
1518
          if (errptr != errlines)
 
1519
            fputs ("\n:::::", out); /* Continuation line.  */
 
1520
          if (errptr->fname)
 
1521
            fputs (gc_percent_escape (errptr->fname), out);
 
1522
          putc (':', out);
 
1523
          if (errptr->fname)
 
1524
            fprintf (out, "%u", errptr->lineno);
 
1525
          putc (':', out);
 
1526
          fputs (gc_percent_escape (errptr->errtext), out);
 
1527
          putc (':', out);
 
1528
        }
 
1529
      putc ('\n', out);
 
1530
    }
 
1531
 
 
1532
  while (errlines)
 
1533
    {
 
1534
      error_line_t tmp = errlines->next;
 
1535
      xfree (errlines);
 
1536
      errlines = tmp;
 
1537
    }
 
1538
 
 
1539
  return result;
 
1540
}
 
1541
 
 
1542
 
 
1543
/* Check all components that are available.  */
 
1544
void
 
1545
gc_check_programs (FILE *out)
 
1546
{
 
1547
  gc_component_t component;
 
1548
 
1320
1549
  for (component = 0; component < GC_COMPONENT_NR; component++)
1321
 
    {
1322
 
      if (!gc_component[component].options)
1323
 
        continue;
1324
 
 
1325
 
      for (backend = 0; backend < GC_BACKEND_NR; backend++)
1326
 
        backend_seen[backend] = 0;
1327
 
 
1328
 
      option = gc_component[component].options;
1329
 
      for (; option && option->name; option++)
1330
 
        {
1331
 
          if ((option->flags & GC_OPT_FLAG_GROUP))
1332
 
            continue;
1333
 
          backend = option->backend;
1334
 
          if (backend_seen[backend])
1335
 
            continue;
1336
 
          backend_seen[backend] = 1;
1337
 
          assert (backend != GC_BACKEND_ANY);
1338
 
          if (!gc_backend[backend].program)
1339
 
            continue;
1340
 
          if (!gc_backend[backend].module_name)
1341
 
            continue;
1342
 
 
1343
 
          pgmname = gnupg_module_name (gc_backend[backend].module_name);
1344
 
          argv[0] = "--gpgconf-test";
1345
 
          argv[1] = NULL;
1346
 
 
1347
 
          err = gnupg_create_inbound_pipe (filedes);
1348
 
          if (err)
1349
 
            gc_error (1, 0, _("error creating a pipe: %s\n"), 
1350
 
                      gpg_strerror (err));
1351
 
 
1352
 
          result = 0;
1353
 
          errlines = NULL;
1354
 
          if (gnupg_spawn_process_fd (pgmname, argv, -1, -1, filedes[1], &pid))
1355
 
            {
1356
 
              close (filedes[0]);
1357
 
              close (filedes[1]);
1358
 
              result |= 1; /* Program could not be run.  */
1359
 
            }
1360
 
          else 
1361
 
            {
1362
 
              close (filedes[1]);
1363
 
              errlines = collect_error_output (filedes[0], 
1364
 
                                               gc_component[component].name);
1365
 
              if (gnupg_wait_process (pgmname, pid, &exitcode))
1366
 
                {
1367
 
                  if (exitcode == -1)
1368
 
                    result |= 1; /* Program could not be run or it
1369
 
                                    terminated abnormally.  */
1370
 
                  result |= 2; /* Program returned an error.  */
1371
 
                }
1372
 
            }
1373
 
          
1374
 
          /* If the program could not be run, we can't tell whether
1375
 
             the config file is good.  */
1376
 
          if ((result&1))
1377
 
            result |= 2;  
1378
 
          
1379
 
          desc = gc_component[component].desc;
1380
 
          desc = my_dgettext (gc_component[component].desc_domain, desc);
1381
 
          fprintf (out, "%s:%s:",
1382
 
                   gc_component[component].name, my_percent_escape (desc));
1383
 
          fputs (my_percent_escape (pgmname), out);
1384
 
          fprintf (out, ":%d:%d:", !(result & 1), !(result & 2));
1385
 
          for (errptr = errlines; errptr; errptr = errptr->next)
1386
 
            {
1387
 
              if (errptr != errlines)
1388
 
                fputs ("\n:::::", out); /* Continuation line.  */
1389
 
              if (errptr->fname)
1390
 
                fputs (my_percent_escape (errptr->fname), out);
1391
 
              putc (':', out);
1392
 
              if (errptr->fname)
1393
 
                fprintf (out, "%u", errptr->lineno);
1394
 
              putc (':', out);
1395
 
              fputs (my_percent_escape (errptr->errtext), out);
1396
 
              putc (':', out);
1397
 
            }
1398
 
          putc ('\n', out);
1399
 
          
1400
 
          while (errlines)
1401
 
            {
1402
 
              error_line_t tmp = errlines->next;
1403
 
              xfree (errlines);
1404
 
              errlines = tmp;
1405
 
            }
1406
 
          break; /* Loop over options of this component  */
1407
 
        }
1408
 
    } 
 
1550
    gc_component_check_options (component, out, NULL);
1409
1551
}
1410
1552
 
1411
1553
 
1497
1639
    fprintf (out, " %s", gc_level[option->level].name);
1498
1640
 
1499
1641
  /* The description field.  */
1500
 
  fprintf (out, ":%s", desc ? my_percent_escape (desc) : "");
 
1642
  fprintf (out, ":%s", desc ? gc_percent_escape (desc) : "");
1501
1643
  
1502
1644
  /* The type field.  */
1503
1645
  fprintf (out, ":%u", option->arg_type);
1511
1653
             gc_arg_type[gc_arg_type[option->arg_type].fallback].name);
1512
1654
 
1513
1655
  /* The argument name field.  */
1514
 
  fprintf (out, ":%s", arg_name ? my_percent_escape (arg_name) : "");
 
1656
  fprintf (out, ":%s", arg_name ? gc_percent_escape (arg_name) : "");
1515
1657
  if (arg_name)
1516
1658
    xfree (arg_name);
1517
1659
 
1611
1753
}
1612
1754
 
1613
1755
 
1614
 
/* Determine the configuration pathname for the component COMPONENT
 
1756
/* Determine the configuration filename for the component COMPONENT
1615
1757
   and backend BACKEND.  */
1616
1758
static char *
1617
 
get_config_pathname (gc_component_t component, gc_backend_t backend)
 
1759
get_config_filename (gc_component_t component, gc_backend_t backend)
1618
1760
{
1619
 
  char *pathname = NULL;
 
1761
  char *filename = NULL;
1620
1762
  gc_option_t *option = find_option
1621
1763
    (component, gc_backend[backend].option_config_filename, GC_BACKEND_ANY);
1622
1764
  assert (option);
1623
 
  assert (option->arg_type == GC_ARG_TYPE_PATHNAME);
 
1765
  assert (option->arg_type == GC_ARG_TYPE_FILENAME);
1624
1766
  assert (!(option->flags & GC_OPT_FLAG_LIST));
1625
1767
 
1626
1768
  if (!option->active || !option->default_value)
1629
1771
              gc_backend[backend].name);
1630
1772
 
1631
1773
  if (option->value && *option->value)
1632
 
    pathname = percent_deescape (&option->value[1]);
 
1774
    filename = percent_deescape (&option->value[1]);
1633
1775
  else if (option->default_value && *option->default_value)
1634
 
    pathname = percent_deescape (&option->default_value[1]);
 
1776
    filename = percent_deescape (&option->default_value[1]);
1635
1777
  else
1636
 
    pathname = "";
 
1778
    filename = "";
1637
1779
 
1638
1780
#ifdef HAVE_DOSISH_SYSTEM
1639
 
  if (!(pathname[0] 
1640
 
        && pathname[1] == ':'
1641
 
        && (pathname[2] == '/' || pathname[2] == '\\')))
 
1781
  if (!(filename[0] 
 
1782
        && filename[1] == ':'
 
1783
        && (filename[2] == '/' || filename[2] == '\\')))
1642
1784
#else
1643
 
  if (pathname[0] != '/')
 
1785
  if (filename[0] != '/')
1644
1786
#endif
1645
1787
    gc_error (1, 0, "Option %s, needed by backend %s, is not absolute",
1646
1788
              gc_backend[backend].option_config_filename,
1647
1789
              gc_backend[backend].name);
1648
1790
 
1649
 
  return pathname;
 
1791
  return filename;
1650
1792
}
1651
1793
 
1652
1794
 
1665
1807
  size_t line_len = 0;
1666
1808
  ssize_t length;
1667
1809
  FILE *config;
1668
 
  char *config_pathname;
 
1810
  char *config_filename;
1669
1811
 
1670
1812
  err = gnupg_create_inbound_pipe (filedes);
1671
1813
  if (err)
1771
1913
 
1772
1914
 
1773
1915
  /* At this point, we can parse the configuration file.  */
1774
 
  config_pathname = get_config_pathname (component, backend);
 
1916
  config_filename = get_config_filename (component, backend);
1775
1917
 
1776
 
  config = fopen (config_pathname, "r");
 
1918
  config = fopen (config_filename, "r");
1777
1919
  if (!config)
1778
1920
    gc_error (0, errno, "warning: can not open config file %s",
1779
 
              config_pathname);
 
1921
              config_filename);
1780
1922
  else
1781
1923
    {
1782
1924
      while ((length = read_line (config, &line, &line_len, NULL)) > 0)
1830
1972
                }
1831
1973
              else if (gc_arg_type[option->arg_type].fallback
1832
1974
                       == GC_ARG_TYPE_STRING)
1833
 
                opt_value = xasprintf ("\"%s", my_percent_escape (value));
 
1975
                opt_value = xasprintf ("\"%s", gc_percent_escape (value));
1834
1976
              else
1835
1977
                {
1836
1978
                  /* FIXME: Verify that the number is sane.  */
1861
2003
        }
1862
2004
 
1863
2005
      if (length < 0 || ferror (config))
1864
 
        gc_error (1, errno, "error reading from %s", config_pathname);
 
2006
        gc_error (1, errno, "error reading from %s", config_filename);
1865
2007
      if (fclose (config) && ferror (config))
1866
 
        gc_error (1, errno, "error closing %s", config_pathname);
 
2008
        gc_error (1, errno, "error closing %s", config_filename);
1867
2009
    }
1868
2010
 
1869
2011
  xfree (line);
1876
2018
retrieve_options_from_file (gc_component_t component, gc_backend_t backend)
1877
2019
{
1878
2020
  gc_option_t *list_option;
1879
 
  char *list_pathname;
 
2021
  gc_option_t *config_option;
 
2022
  char *list_filename;
1880
2023
  FILE *list_file;
1881
2024
  char *line = NULL;
1882
2025
  size_t line_len = 0;
1888
2031
  assert (list_option);
1889
2032
  assert (!list_option->active);
1890
2033
 
1891
 
  list_pathname = get_config_pathname (component, backend);
1892
 
  list_file = fopen (list_pathname, "r");
 
2034
  list_filename = get_config_filename (component, backend);
 
2035
  list_file = fopen (list_filename, "r");
1893
2036
  if (!list_file)
1894
 
    gc_error (0, errno, "warning: can not open list file %s", list_pathname);
 
2037
    gc_error (0, errno, "warning: can not open list file %s", list_filename);
1895
2038
  else
1896
2039
    {
1897
2040
 
1921
2064
             really append.  */
1922
2065
          if (list)
1923
2066
            {
1924
 
              new_list = xasprintf ("%s,\"%s", list, my_percent_escape (start));
 
2067
              new_list = xasprintf ("%s,\"%s", list, gc_percent_escape (start));
1925
2068
              xfree (list);
1926
2069
              list = new_list;
1927
2070
            }
1928
2071
          else
1929
 
            list = xasprintf ("\"%s", my_percent_escape (start));
 
2072
            list = xasprintf ("\"%s", gc_percent_escape (start));
1930
2073
        }
1931
2074
      if (length < 0 || ferror (list_file))
1932
 
        gc_error (1, errno, "can not read list file %s", list_pathname);
 
2075
        gc_error (1, errno, "can not read list file %s", list_filename);
1933
2076
    }
1934
2077
 
1935
2078
  list_option->active = 1;
1936
2079
  list_option->value = list;
1937
2080
 
 
2081
  /* Fix up the read-only flag.  */
 
2082
  config_option = find_option
 
2083
    (component, gc_backend[backend].option_config_filename, GC_BACKEND_ANY);
 
2084
  if (config_option->flags & GC_OPT_FLAG_NO_CHANGE)
 
2085
    list_option->flags |= GC_OPT_FLAG_NO_CHANGE;
 
2086
 
1938
2087
  if (list_file && fclose (list_file) && ferror (list_file))
1939
 
    gc_error (1, errno, "error closing %s", list_pathname);
 
2088
    gc_error (1, errno, "error closing %s", list_filename);
1940
2089
  xfree (line);
1941
2090
}
1942
2091
 
2197
2346
  assert (gc_arg_type[option->arg_type].fallback != GC_ARG_TYPE_NONE);
2198
2347
 
2199
2348
  /* FIXME.  Throughout the function, do better error reporting.  */
2200
 
  /* Note that get_config_pathname() calls percent_deescape(), so we
 
2349
  /* Note that get_config_filename() calls percent_deescape(), so we
2201
2350
     call this before processing the arguments.  */
2202
 
  dest_filename = xstrdup (get_config_pathname (component, backend));
 
2351
  dest_filename = xstrdup (get_config_filename (component, backend));
2203
2352
  src_filename = xasprintf ("%s.gpgconf.%i.new", dest_filename, getpid ());
2204
2353
  orig_filename = xasprintf ("%s.gpgconf.%i.bak", dest_filename, getpid ());
2205
2354
 
2491
2640
  int utf8strings_seen = 0;
2492
2641
 
2493
2642
  /* FIXME.  Throughout the function, do better error reporting.  */
2494
 
  dest_filename = xstrdup (get_config_pathname (component, backend));
 
2643
  dest_filename = xstrdup (get_config_filename (component, backend));
2495
2644
  src_filename = xasprintf ("%s.gpgconf.%i.new", dest_filename, getpid ());
2496
2645
  orig_filename = xasprintf ("%s.gpgconf.%i.bak", dest_filename, getpid ());
2497
2646
 
2808
2957
   modifications are expected to already have been set to the global
2809
2958
   table. */
2810
2959
void
2811
 
gc_component_change_options (int component, FILE *in)
 
2960
gc_component_change_options (int component, FILE *in, FILE *out)
2812
2961
{
2813
2962
  int err = 0;
2814
2963
  int runtime[GC_BACKEND_NR];
2815
 
  char *src_pathname[GC_BACKEND_NR];
2816
 
  char *dest_pathname[GC_BACKEND_NR];
2817
 
  char *orig_pathname[GC_BACKEND_NR];
 
2964
  char *src_filename[GC_BACKEND_NR];
 
2965
  char *dest_filename[GC_BACKEND_NR];
 
2966
  char *orig_filename[GC_BACKEND_NR];
2818
2967
  gc_backend_t backend;
2819
2968
  gc_option_t *option;
2820
2969
  char *line = NULL;
2824
2973
  for (backend = 0; backend < GC_BACKEND_NR; backend++)
2825
2974
    {
2826
2975
      runtime[backend] = 0;
2827
 
      src_pathname[backend] = NULL;
2828
 
      dest_pathname[backend] = NULL;
2829
 
      orig_pathname[backend] = NULL;
 
2976
      src_filename[backend] = NULL;
 
2977
      dest_filename[backend] = NULL;
 
2978
      orig_filename[backend] = NULL;
2830
2979
    }
2831
2980
 
2832
2981
  if (in)
2904
3053
    {
2905
3054
      /* Go on if we have already seen this backend, or if there is
2906
3055
         nothing to do.  */
2907
 
      if (src_pathname[option->backend]
 
3056
      if (src_filename[option->backend]
2908
3057
          || !(option->new_flags || option->new_value))
2909
3058
        {
2910
3059
          option++;
2912
3061
        }
2913
3062
 
2914
3063
      if (gc_backend[option->backend].program)
2915
 
        err = change_options_program (component, option->backend,
2916
 
                                      &src_pathname[option->backend],
2917
 
                                      &dest_pathname[option->backend],
2918
 
                                      &orig_pathname[option->backend]);
 
3064
        {
 
3065
          err = change_options_program (component, option->backend,
 
3066
                                        &src_filename[option->backend],
 
3067
                                        &dest_filename[option->backend],
 
3068
                                        &orig_filename[option->backend]);
 
3069
          if (! err)
 
3070
            {
 
3071
              /* External verification.  */
 
3072
              err = gc_component_check_options (component, out,
 
3073
                                                src_filename[option->backend]);
 
3074
              if (err)
 
3075
                {
 
3076
                  gc_error (0, 0,
 
3077
                            _("External verification of component %s failed"),
 
3078
                            gc_component[component].name);
 
3079
                  errno = EINVAL;
 
3080
                }
 
3081
            }
 
3082
 
 
3083
        }
2919
3084
      else
2920
3085
        err = change_options_file (component, option->backend,
2921
 
                                   &src_pathname[option->backend],
2922
 
                                   &dest_pathname[option->backend],
2923
 
                                   &orig_pathname[option->backend]);
 
3086
                                   &src_filename[option->backend],
 
3087
                                   &dest_filename[option->backend],
 
3088
                                   &orig_filename[option->backend]);
2924
3089
        
2925
3090
      if (err)
2926
3091
        break;
2928
3093
      option++;
2929
3094
    }
2930
3095
 
2931
 
  if (!err)
 
3096
  if (! err && ! opt.dry_run)
2932
3097
    {
2933
3098
      int i;
2934
3099
 
2935
3100
      for (i = 0; i < GC_BACKEND_NR; i++)
2936
3101
        {
2937
 
          if (src_pathname[i])
 
3102
          if (src_filename[i])
2938
3103
            {
2939
3104
              /* FIXME: Make a verification here.  */
2940
3105
 
2941
 
              assert (dest_pathname[i]);
 
3106
              assert (dest_filename[i]);
2942
3107
 
2943
 
              if (orig_pathname[i])
 
3108
              if (orig_filename[i])
2944
3109
                {
2945
3110
#ifdef HAVE_W32_SYSTEM
2946
3111
                  /* There is no atomic update on W32.  */
2947
 
                  err = unlink (dest_pathname[i]);
 
3112
                  err = unlink (dest_filename[i]);
2948
3113
#endif /* HAVE_W32_SYSTEM */
2949
3114
                  if (!err)
2950
 
                    err = rename (src_pathname[i], dest_pathname[i]);
 
3115
                    err = rename (src_filename[i], dest_filename[i]);
2951
3116
                }
2952
3117
              else
2953
3118
                {
2954
3119
#ifdef HAVE_W32_SYSTEM
2955
3120
                  /* We skip the unlink if we expect the file not to
2956
3121
                     be there.  */
2957
 
                  err = rename (src_pathname[i], dest_pathname[i]);
 
3122
                  err = rename (src_filename[i], dest_filename[i]);
2958
3123
#else /* HAVE_W32_SYSTEM */
2959
3124
                  /* This is a bit safer than rename() because we
2960
 
                     expect DEST_PATHNAME not to be there.  If it
 
3125
                     expect DEST_FILENAME not to be there.  If it
2961
3126
                     happens to be there, this will fail.  */
2962
 
                  err = link (src_pathname[i], dest_pathname[i]);
 
3127
                  err = link (src_filename[i], dest_filename[i]);
2963
3128
                  if (!err)
2964
 
                    err = unlink (src_pathname[i]);
 
3129
                    err = unlink (src_filename[i]);
2965
3130
#endif /* !HAVE_W32_SYSTEM */
2966
3131
                }
2967
3132
              if (err)
2968
3133
                break;
2969
 
              src_pathname[i] = NULL;
 
3134
              src_filename[i] = NULL;
2970
3135
            }
2971
3136
        }
2972
3137
    }
2973
3138
 
2974
 
  if (err)
 
3139
  if (err || opt.dry_run)
2975
3140
    {
2976
3141
      int i;
2977
3142
      int saved_errno = errno;
2978
3143
 
2979
 
      /* An error occured.  */
 
3144
      /* An error occured or a dry-run is requested.  */
2980
3145
      for (i = 0; i < GC_BACKEND_NR; i++)
2981
3146
        {
2982
 
          if (src_pathname[i])
 
3147
          if (src_filename[i])
2983
3148
            {
2984
3149
              /* The change was not yet committed.  */
2985
 
              unlink (src_pathname[i]);
2986
 
              if (orig_pathname[i])
2987
 
                unlink (orig_pathname[i]);
 
3150
              unlink (src_filename[i]);
 
3151
              if (orig_filename[i])
 
3152
                unlink (orig_filename[i]);
2988
3153
            }
2989
3154
          else
2990
3155
            {
2992
3157
                 tad dangerous, as we don't know if we don't overwrite
2993
3158
                 a version of the file that is even newer than the one
2994
3159
                 we just installed.  */
2995
 
              if (orig_pathname[i])
 
3160
              if (orig_filename[i])
2996
3161
                {
2997
3162
#ifdef HAVE_W32_SYSTEM
2998
3163
                  /* There is no atomic update on W32.  */
2999
 
                  unlink (dest_pathname[i]);
 
3164
                  unlink (dest_filename[i]);
3000
3165
#endif /* HAVE_W32_SYSTEM */
3001
 
                  rename (orig_pathname[i], dest_pathname[i]);
 
3166
                  rename (orig_filename[i], dest_filename[i]);
3002
3167
                }
3003
3168
              else
3004
 
                unlink (dest_pathname[i]);
 
3169
                unlink (dest_filename[i]);
3005
3170
            }
3006
3171
        }
3007
 
      gc_error (1, saved_errno, "could not commit changes");
 
3172
      if (err)
 
3173
        gc_error (1, saved_errno, "could not commit changes");
 
3174
 
 
3175
      /* Fall-through for dry run.  */
 
3176
      goto leave;
3008
3177
    }
3009
3178
 
3010
3179
  /* If it all worked, notify the daemons of the changes.  */
3017
3186
 
3018
3187
  /* Move the per-process backup file into its place.  */
3019
3188
  for (backend = 0; backend < GC_BACKEND_NR; backend++)  
3020
 
    if (orig_pathname[backend])
 
3189
    if (orig_filename[backend])
3021
3190
      {
3022
 
        char *backup_pathname;
3023
 
 
3024
 
        assert (dest_pathname[backend]);
3025
 
 
3026
 
        backup_pathname = xasprintf ("%s.gpgconf.bak", dest_pathname[backend]);
 
3191
        char *backup_filename;
 
3192
 
 
3193
        assert (dest_filename[backend]);
 
3194
 
 
3195
        backup_filename = xasprintf ("%s.gpgconf.bak", dest_filename[backend]);
3027
3196
 
3028
3197
#ifdef HAVE_W32_SYSTEM
3029
3198
        /* There is no atomic update on W32.  */
3030
 
        unlink (backup_pathname);
 
3199
        unlink (backup_filename);
3031
3200
#endif /* HAVE_W32_SYSTEM */
3032
 
        rename (orig_pathname[backend], backup_pathname);
 
3201
        rename (orig_filename[backend], backup_filename);
3033
3202
      }
3034
3203
 
 
3204
 leave:
3035
3205
  xfree (line);
3036
3206
}
3037
3207
 
3365
3535
                    *p = 0; /* We better strip any extra stuff. */
3366
3536
                }                    
3367
3537
              
3368
 
              fprintf (listfp, "k:%s:", my_percent_escape (key));
3369
 
              fprintf (listfp, "%s\n", group? my_percent_escape (group):"");
 
3538
              fprintf (listfp, "k:%s:", gc_percent_escape (key));
 
3539
              fprintf (listfp, "%s\n", group? gc_percent_escape (group):"");
3370
3540
            }
3371
3541
 
3372
3542
          /* All other lines are rule records.  */
3375
3545
                   option_info->name? option_info->name : "",
3376
3546
                   flags? flags : "");
3377
3547
          if (value != empty)
3378
 
            fprintf (listfp, "\"%s", my_percent_escape (value));
 
3548
            fprintf (listfp, "\"%s", gc_percent_escape (value));
3379
3549
          
3380
3550
          putc ('\n', listfp);
3381
3551
        }
3440
3610
 
3441
3611
      for (component_id = 0; component_id < GC_COMPONENT_NR; component_id++)
3442
3612
        {
3443
 
          gc_component_change_options (component_id, NULL);
 
3613
          gc_component_change_options (component_id, NULL, NULL);
3444
3614
        }
3445
3615
      opt.runtime = save_opt_runtime;
3446
3616