Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 252912 | Differences between
and this patch

Collapse All | Expand All

(-)a/pinentry/pinentry.c (-108 / +126 lines)
Lines 43-49 Link Here
43
#include <iconv.h>
43
#include <iconv.h>
44
#endif
44
#endif
45
45
46
#include "assuan.h"
46
#include <assuan.h>
47
47
#include "memory.h"
48
#include "memory.h"
48
#include "secmem-util.h"
49
#include "secmem-util.h"
49
#include "argparse.h"
50
#include "argparse.h"
Lines 165-175 pinentry_reset (int use_defaults) Link Here
165
    }
166
    }
166
}
167
}
167
168
168
static void
169
static gpg_error_t
169
pinentry_assuan_reset_handler (ASSUAN_CONTEXT ctx)
170
pinentry_assuan_reset_handler (assuan_context_t ctx, char *line)
170
{
171
{
171
  (void)ctx;
172
  (void)ctx;
173
  (void)line;
174
172
  pinentry_reset (0);
175
  pinentry_reset (0);
176
177
  return 0;
173
}
178
}
174
179
175
180
Lines 356-362 copy_and_escape (char *buffer, const void *text, size_t textlen) Link Here
356
int
361
int
357
pinentry_inq_quality (pinentry_t pin, const char *passphrase, size_t length)
362
pinentry_inq_quality (pinentry_t pin, const char *passphrase, size_t length)
358
{
363
{
359
  ASSUAN_CONTEXT ctx = pin->ctx_assuan;
364
  assuan_context_t ctx = pin->ctx_assuan;
360
  const char prefix[] = "INQUIRE QUALITY ";
365
  const char prefix[] = "INQUIRE QUALITY ";
361
  char *command;
366
  char *command;
362
  char *line;
367
  char *line;
Lines 500-505 pinentry_setbuffer_use (pinentry_t pin, char *passphrase, int len) Link Here
500
  pin->pin_len = len;
505
  pin->pin_len = len;
501
}
506
}
502
507
508
static struct assuan_malloc_hooks assuan_malloc_hooks = {
509
  secmem_malloc, secmem_realloc, secmem_free
510
};
511
503
/* Initialize the secure memory subsystem, drop privileges and return.
512
/* Initialize the secure memory subsystem, drop privileges and return.
504
   Must be called early. */
513
   Must be called early. */
505
void
514
void
Lines 510-515 pinentry_init (const char *pgmname) Link Here
510
    abort ();
519
    abort ();
511
  strcpy (this_pgmname, pgmname);
520
  strcpy (this_pgmname, pgmname);
512
521
522
  gpgrt_check_version (NULL);
523
513
  /* Initialize secure memory.  1 is too small, so the default size
524
  /* Initialize secure memory.  1 is too small, so the default size
514
     will be used.  */
525
     will be used.  */
515
  secmem_init (1);
526
  secmem_init (1);
Lines 521-527 pinentry_init (const char *pgmname) Link Here
521
      /* FIXME: Could not register at-exit function, bail out.  */
532
      /* FIXME: Could not register at-exit function, bail out.  */
522
    }
533
    }
523
534
524
  assuan_set_malloc_hooks (secmem_malloc, secmem_realloc, secmem_free);
535
  assuan_set_malloc_hooks (&assuan_malloc_hooks);
525
}
536
}
526
537
527
/* Simple test to check whether DISPLAY is set or the option --display
538
/* Simple test to check whether DISPLAY is set or the option --display
Lines 755-762 pinentry_parse_opts (int argc, char *argv[]) Link Here
755
}
766
}
756
767
757
768
758
static int
769
static gpg_error_t
759
option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value)
770
option_handler (assuan_context_t ctx, const char *key, const char *value)
760
{
771
{
761
  (void)ctx;
772
  (void)ctx;
762
773
Lines 779-785 option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value) Link Here
779
	free (pinentry.display);
790
	free (pinentry.display);
780
      pinentry.display = strdup (value);
791
      pinentry.display = strdup (value);
781
      if (!pinentry.display)
792
      if (!pinentry.display)
782
	return ASSUAN_Out_Of_Core;
793
	return gpg_error_from_syserror ();
783
    }
794
    }
784
  else if (!strcmp (key, "ttyname"))
795
  else if (!strcmp (key, "ttyname"))
785
    {
796
    {
Lines 787-793 option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value) Link Here
787
	free (pinentry.ttyname);
798
	free (pinentry.ttyname);
788
      pinentry.ttyname = strdup (value);
799
      pinentry.ttyname = strdup (value);
789
      if (!pinentry.ttyname)
800
      if (!pinentry.ttyname)
790
	return ASSUAN_Out_Of_Core;
801
	return gpg_error_from_syserror ();
791
    }
802
    }
792
  else if (!strcmp (key, "ttytype"))
803
  else if (!strcmp (key, "ttytype"))
793
    {
804
    {
Lines 795-801 option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value) Link Here
795
	free (pinentry.ttytype);
806
	free (pinentry.ttytype);
796
      pinentry.ttytype = strdup (value);
807
      pinentry.ttytype = strdup (value);
797
      if (!pinentry.ttytype)
808
      if (!pinentry.ttytype)
798
	return ASSUAN_Out_Of_Core;
809
	return gpg_error_from_syserror ();
799
    }
810
    }
800
  else if (!strcmp (key, "lc-ctype"))
811
  else if (!strcmp (key, "lc-ctype"))
801
    {
812
    {
Lines 803-809 option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value) Link Here
803
	free (pinentry.lc_ctype);
814
	free (pinentry.lc_ctype);
804
      pinentry.lc_ctype = strdup (value);
815
      pinentry.lc_ctype = strdup (value);
805
      if (!pinentry.lc_ctype)
816
      if (!pinentry.lc_ctype)
806
	return ASSUAN_Out_Of_Core;
817
	return gpg_error_from_syserror ();
807
    }
818
    }
808
  else if (!strcmp (key, "lc-messages"))
819
  else if (!strcmp (key, "lc-messages"))
809
    {
820
    {
Lines 811-817 option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value) Link Here
811
	free (pinentry.lc_messages);
822
	free (pinentry.lc_messages);
812
      pinentry.lc_messages = strdup (value);
823
      pinentry.lc_messages = strdup (value);
813
      if (!pinentry.lc_messages)
824
      if (!pinentry.lc_messages)
814
	return ASSUAN_Out_Of_Core;
825
	return gpg_error_from_syserror ();
815
    }
826
    }
816
  else if (!strcmp (key, "parent-wid"))
827
  else if (!strcmp (key, "parent-wid"))
817
    {
828
    {
Lines 824-854 option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value) Link Here
824
        free (pinentry.touch_file);
835
        free (pinentry.touch_file);
825
      pinentry.touch_file = strdup (value);
836
      pinentry.touch_file = strdup (value);
826
      if (!pinentry.touch_file)
837
      if (!pinentry.touch_file)
827
	return ASSUAN_Out_Of_Core;
838
	return gpg_error_from_syserror ();
828
    }
839
    }
829
  else if (!strcmp (key, "default-ok"))
840
  else if (!strcmp (key, "default-ok"))
830
    {
841
    {
831
      pinentry.default_ok = strdup (value);
842
      pinentry.default_ok = strdup (value);
832
      if (!pinentry.default_ok)
843
      if (!pinentry.default_ok)
833
	return ASSUAN_Out_Of_Core;
844
	return gpg_error_from_syserror ();
834
    }
845
    }
835
  else if (!strcmp (key, "default-cancel"))
846
  else if (!strcmp (key, "default-cancel"))
836
    {
847
    {
837
      pinentry.default_cancel = strdup (value);
848
      pinentry.default_cancel = strdup (value);
838
      if (!pinentry.default_cancel)
849
      if (!pinentry.default_cancel)
839
	return ASSUAN_Out_Of_Core;
850
	return gpg_error_from_syserror ();
840
    }
851
    }
841
  else if (!strcmp (key, "default-prompt"))
852
  else if (!strcmp (key, "default-prompt"))
842
    {
853
    {
843
      pinentry.default_prompt = strdup (value);
854
      pinentry.default_prompt = strdup (value);
844
      if (!pinentry.default_prompt)
855
      if (!pinentry.default_prompt)
845
	return ASSUAN_Out_Of_Core;
856
	return gpg_error_from_syserror ();
846
    }
857
    }
847
  else if (!strcmp (key, "default-pwmngr"))
858
  else if (!strcmp (key, "default-pwmngr"))
848
    {
859
    {
849
      pinentry.default_pwmngr = strdup (value);
860
      pinentry.default_pwmngr = strdup (value);
850
      if (!pinentry.default_pwmngr)
861
      if (!pinentry.default_pwmngr)
851
	return ASSUAN_Out_Of_Core;
862
	return gpg_error_from_syserror ();
852
    }
863
    }
853
  else if (!strcmp (key, "allow-external-password-cache") && !*value)
864
  else if (!strcmp (key, "allow-external-password-cache") && !*value)
854
    {
865
    {
Lines 856-862 option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value) Link Here
856
      pinentry.tried_password_cache = 0;
867
      pinentry.tried_password_cache = 0;
857
    }
868
    }
858
  else
869
  else
859
    return ASSUAN_Invalid_Option;
870
    return gpg_error (GPG_ERR_UNKNOWN_OPTION);
860
  return 0;
871
  return 0;
861
}
872
}
862
873
Lines 881-888 strcpy_escaped (char *d, const char *s) Link Here
881
}
892
}
882
893
883
894
884
static int
895
static gpg_error_t
885
cmd_setdesc (ASSUAN_CONTEXT ctx, char *line)
896
cmd_setdesc (assuan_context_t ctx, char *line)
886
{
897
{
887
  char *newd;
898
  char *newd;
888
899
Lines 890-896 cmd_setdesc (ASSUAN_CONTEXT ctx, char *line) Link Here
890
901
891
  newd = malloc (strlen (line) + 1);
902
  newd = malloc (strlen (line) + 1);
892
  if (!newd)
903
  if (!newd)
893
    return ASSUAN_Out_Of_Core;
904
    return gpg_error_from_syserror ();
894
905
895
  strcpy_escaped (newd, line);
906
  strcpy_escaped (newd, line);
896
  if (pinentry.description)
907
  if (pinentry.description)
Lines 900-907 cmd_setdesc (ASSUAN_CONTEXT ctx, char *line) Link Here
900
}
911
}
901
912
902
913
903
static int
914
static gpg_error_t
904
cmd_setprompt (ASSUAN_CONTEXT ctx, char *line)
915
cmd_setprompt (assuan_context_t ctx, char *line)
905
{
916
{
906
  char *newp;
917
  char *newp;
907
918
Lines 909-915 cmd_setprompt (ASSUAN_CONTEXT ctx, char *line) Link Here
909
920
910
  newp = malloc (strlen (line) + 1);
921
  newp = malloc (strlen (line) + 1);
911
  if (!newp)
922
  if (!newp)
912
    return ASSUAN_Out_Of_Core;
923
    return gpg_error_from_syserror ();
913
924
914
  strcpy_escaped (newp, line);
925
  strcpy_escaped (newp, line);
915
  if (pinentry.prompt)
926
  if (pinentry.prompt)
Lines 923-930 cmd_setprompt (ASSUAN_CONTEXT ctx, char *line) Link Here
923
   to identify a key for caching strategies of its own.  The empty
934
   to identify a key for caching strategies of its own.  The empty
924
   string and --clear mean that the key does not have a stable
935
   string and --clear mean that the key does not have a stable
925
   identifier.  */
936
   identifier.  */
926
static int
937
static gpg_error_t
927
cmd_setkeyinfo (ASSUAN_CONTEXT ctx, char *line)
938
cmd_setkeyinfo (assuan_context_t ctx, char *line)
928
{
939
{
929
  (void)ctx;
940
  (void)ctx;
930
941
Lines 940-947 cmd_setkeyinfo (ASSUAN_CONTEXT ctx, char *line) Link Here
940
}
951
}
941
952
942
953
943
static int
954
static gpg_error_t
944
cmd_setrepeat (ASSUAN_CONTEXT ctx, char *line)
955
cmd_setrepeat (assuan_context_t ctx, char *line)
945
{
956
{
946
  char *p;
957
  char *p;
947
958
Lines 949-955 cmd_setrepeat (ASSUAN_CONTEXT ctx, char *line) Link Here
949
960
950
  p = malloc (strlen (line) + 1);
961
  p = malloc (strlen (line) + 1);
951
  if (!p)
962
  if (!p)
952
    return ASSUAN_Out_Of_Core;
963
    return gpg_error_from_syserror ();
953
964
954
  strcpy_escaped (p, line);
965
  strcpy_escaped (p, line);
955
  free (pinentry.repeat_passphrase);
966
  free (pinentry.repeat_passphrase);
Lines 958-965 cmd_setrepeat (ASSUAN_CONTEXT ctx, char *line) Link Here
958
}
969
}
959
970
960
971
961
static int
972
static gpg_error_t
962
cmd_setrepeaterror (ASSUAN_CONTEXT ctx, char *line)
973
cmd_setrepeaterror (assuan_context_t ctx, char *line)
963
{
974
{
964
  char *p;
975
  char *p;
965
976
Lines 967-973 cmd_setrepeaterror (ASSUAN_CONTEXT ctx, char *line) Link Here
967
978
968
  p = malloc (strlen (line) + 1);
979
  p = malloc (strlen (line) + 1);
969
  if (!p)
980
  if (!p)
970
    return ASSUAN_Out_Of_Core;
981
    return gpg_error_from_syserror ();
971
982
972
  strcpy_escaped (p, line);
983
  strcpy_escaped (p, line);
973
  free (pinentry.repeat_error_string);
984
  free (pinentry.repeat_error_string);
Lines 976-983 cmd_setrepeaterror (ASSUAN_CONTEXT ctx, char *line) Link Here
976
}
987
}
977
988
978
989
979
static int
990
static gpg_error_t
980
cmd_seterror (ASSUAN_CONTEXT ctx, char *line)
991
cmd_seterror (assuan_context_t ctx, char *line)
981
{
992
{
982
  char *newe;
993
  char *newe;
983
994
Lines 985-991 cmd_seterror (ASSUAN_CONTEXT ctx, char *line) Link Here
985
996
986
  newe = malloc (strlen (line) + 1);
997
  newe = malloc (strlen (line) + 1);
987
  if (!newe)
998
  if (!newe)
988
    return ASSUAN_Out_Of_Core;
999
    return gpg_error_from_syserror ();
989
1000
990
  strcpy_escaped (newe, line);
1001
  strcpy_escaped (newe, line);
991
  if (pinentry.error)
1002
  if (pinentry.error)
Lines 995-1002 cmd_seterror (ASSUAN_CONTEXT ctx, char *line) Link Here
995
}
1006
}
996
1007
997
1008
998
static int
1009
static gpg_error_t
999
cmd_setok (ASSUAN_CONTEXT ctx, char *line)
1010
cmd_setok (assuan_context_t ctx, char *line)
1000
{
1011
{
1001
  char *newo;
1012
  char *newo;
1002
1013
Lines 1004-1010 cmd_setok (ASSUAN_CONTEXT ctx, char *line) Link Here
1004
1015
1005
  newo = malloc (strlen (line) + 1);
1016
  newo = malloc (strlen (line) + 1);
1006
  if (!newo)
1017
  if (!newo)
1007
    return ASSUAN_Out_Of_Core;
1018
    return gpg_error_from_syserror ();
1008
1019
1009
  strcpy_escaped (newo, line);
1020
  strcpy_escaped (newo, line);
1010
  if (pinentry.ok)
1021
  if (pinentry.ok)
Lines 1014-1021 cmd_setok (ASSUAN_CONTEXT ctx, char *line) Link Here
1014
}
1025
}
1015
1026
1016
1027
1017
static int
1028
static gpg_error_t
1018
cmd_setnotok (ASSUAN_CONTEXT ctx, char *line)
1029
cmd_setnotok (assuan_context_t ctx, char *line)
1019
{
1030
{
1020
  char *newo;
1031
  char *newo;
1021
1032
Lines 1023-1029 cmd_setnotok (ASSUAN_CONTEXT ctx, char *line) Link Here
1023
1034
1024
  newo = malloc (strlen (line) + 1);
1035
  newo = malloc (strlen (line) + 1);
1025
  if (!newo)
1036
  if (!newo)
1026
    return ASSUAN_Out_Of_Core;
1037
    return gpg_error_from_syserror ();
1027
1038
1028
  strcpy_escaped (newo, line);
1039
  strcpy_escaped (newo, line);
1029
  if (pinentry.notok)
1040
  if (pinentry.notok)
Lines 1033-1040 cmd_setnotok (ASSUAN_CONTEXT ctx, char *line) Link Here
1033
}
1044
}
1034
1045
1035
1046
1036
static int
1047
static gpg_error_t
1037
cmd_setcancel (ASSUAN_CONTEXT ctx, char *line)
1048
cmd_setcancel (assuan_context_t ctx, char *line)
1038
{
1049
{
1039
  char *newc;
1050
  char *newc;
1040
1051
Lines 1042-1048 cmd_setcancel (ASSUAN_CONTEXT ctx, char *line) Link Here
1042
1053
1043
  newc = malloc (strlen (line) + 1);
1054
  newc = malloc (strlen (line) + 1);
1044
  if (!newc)
1055
  if (!newc)
1045
    return ASSUAN_Out_Of_Core;
1056
    return gpg_error_from_syserror ();
1046
1057
1047
  strcpy_escaped (newc, line);
1058
  strcpy_escaped (newc, line);
1048
  if (pinentry.cancel)
1059
  if (pinentry.cancel)
Lines 1052-1059 cmd_setcancel (ASSUAN_CONTEXT ctx, char *line) Link Here
1052
}
1063
}
1053
1064
1054
1065
1055
static int
1066
static gpg_error_t
1056
cmd_settimeout (ASSUAN_CONTEXT ctx, char *line)
1067
cmd_settimeout (assuan_context_t ctx, char *line)
1057
{
1068
{
1058
  (void)ctx;
1069
  (void)ctx;
1059
1070
Lines 1063-1070 cmd_settimeout (ASSUAN_CONTEXT ctx, char *line) Link Here
1063
  return 0;
1074
  return 0;
1064
}
1075
}
1065
1076
1066
static int
1077
static gpg_error_t
1067
cmd_settitle (ASSUAN_CONTEXT ctx, char *line)
1078
cmd_settitle (assuan_context_t ctx, char *line)
1068
{
1079
{
1069
  char *newt;
1080
  char *newt;
1070
1081
Lines 1072-1078 cmd_settitle (ASSUAN_CONTEXT ctx, char *line) Link Here
1072
1083
1073
  newt = malloc (strlen (line) + 1);
1084
  newt = malloc (strlen (line) + 1);
1074
  if (!newt)
1085
  if (!newt)
1075
    return ASSUAN_Out_Of_Core;
1086
    return gpg_error_from_syserror ();
1076
1087
1077
  strcpy_escaped (newt, line);
1088
  strcpy_escaped (newt, line);
1078
  if (pinentry.title)
1089
  if (pinentry.title)
Lines 1081-1088 cmd_settitle (ASSUAN_CONTEXT ctx, char *line) Link Here
1081
  return 0;
1092
  return 0;
1082
}
1093
}
1083
1094
1084
static int
1095
static gpg_error_t
1085
cmd_setqualitybar (ASSUAN_CONTEXT ctx, char *line)
1096
cmd_setqualitybar (assuan_context_t ctx, char *line)
1086
{
1097
{
1087
  char *newval;
1098
  char *newval;
1088
1099
Lines 1093-1099 cmd_setqualitybar (ASSUAN_CONTEXT ctx, char *line) Link Here
1093
1104
1094
  newval = malloc (strlen (line) + 1);
1105
  newval = malloc (strlen (line) + 1);
1095
  if (!newval)
1106
  if (!newval)
1096
    return ASSUAN_Out_Of_Core;
1107
    return gpg_error_from_syserror ();
1097
1108
1098
  strcpy_escaped (newval, line);
1109
  strcpy_escaped (newval, line);
1099
  if (pinentry.quality_bar)
1110
  if (pinentry.quality_bar)
Lines 1103-1110 cmd_setqualitybar (ASSUAN_CONTEXT ctx, char *line) Link Here
1103
}
1114
}
1104
1115
1105
/* Set the tooltip to be used for a quality bar.  */
1116
/* Set the tooltip to be used for a quality bar.  */
1106
static int
1117
static gpg_error_t
1107
cmd_setqualitybar_tt (ASSUAN_CONTEXT ctx, char *line)
1118
cmd_setqualitybar_tt (assuan_context_t ctx, char *line)
1108
{
1119
{
1109
  char *newval;
1120
  char *newval;
1110
1121
Lines 1114-1120 cmd_setqualitybar_tt (ASSUAN_CONTEXT ctx, char *line) Link Here
1114
    {
1125
    {
1115
      newval = malloc (strlen (line) + 1);
1126
      newval = malloc (strlen (line) + 1);
1116
      if (!newval)
1127
      if (!newval)
1117
        return ASSUAN_Out_Of_Core;
1128
        return gpg_error_from_syserror ();
1118
1129
1119
      strcpy_escaped (newval, line);
1130
      strcpy_escaped (newval, line);
1120
    }
1131
    }
Lines 1127-1134 cmd_setqualitybar_tt (ASSUAN_CONTEXT ctx, char *line) Link Here
1127
}
1138
}
1128
1139
1129
1140
1130
static int
1141
static gpg_error_t
1131
cmd_getpin (ASSUAN_CONTEXT ctx, char *line)
1142
cmd_getpin (assuan_context_t ctx, char *line)
1132
{
1143
{
1133
  int result;
1144
  int result;
1134
  int set_prompt = 0;
1145
  int set_prompt = 0;
Lines 1138-1144 cmd_getpin (ASSUAN_CONTEXT ctx, char *line) Link Here
1138
1149
1139
  pinentry_setbuffer_init (&pinentry);
1150
  pinentry_setbuffer_init (&pinentry);
1140
  if (!pinentry.pin)
1151
  if (!pinentry.pin)
1141
    return ASSUAN_Out_Of_Core;
1152
    return gpg_error (GPG_ERR_ENOMEM);
1142
1153
1143
  /* Try reading from the password cache.  */
1154
  /* Try reading from the password cache.  */
1144
  if (/* If repeat passphrase is set, then we don't want to read from
1155
  if (/* If repeat passphrase is set, then we don't want to read from
Lines 1224-1230 cmd_getpin (ASSUAN_CONTEXT ctx, char *line) Link Here
1224
      pinentry_setbuffer_clear (&pinentry);
1235
      pinentry_setbuffer_clear (&pinentry);
1225
      if (pinentry.specific_err)
1236
      if (pinentry.specific_err)
1226
        return pinentry.specific_err;
1237
        return pinentry.specific_err;
1227
      return pinentry.locale_err? ASSUAN_Locale_Problem: ASSUAN_Canceled;
1238
      return (pinentry.locale_err
1239
	      ? gpg_error (GPG_ERR_LOCALE_PROBLEM)
1240
	      : gpg_error (GPG_ERR_CANCELED));
1228
    }
1241
    }
1229
1242
1230
 out:
1243
 out:
Lines 1259-1266 cmd_getpin (ASSUAN_CONTEXT ctx, char *line) Link Here
1259
   update pinentry or to have the caller test for the message
1272
   update pinentry or to have the caller test for the message
1260
   command.  New applications which are free to require an updated
1273
   command.  New applications which are free to require an updated
1261
   pinentry should use MESSAGE instead. */
1274
   pinentry should use MESSAGE instead. */
1262
static int
1275
static gpg_error_t
1263
cmd_confirm (ASSUAN_CONTEXT ctx, char *line)
1276
cmd_confirm (assuan_context_t ctx, char *line)
1264
{
1277
{
1265
  int result;
1278
  int result;
1266
1279
Lines 1288-1306 cmd_confirm (ASSUAN_CONTEXT ctx, char *line) Link Here
1288
    return pinentry.specific_err;
1301
    return pinentry.specific_err;
1289
1302
1290
  if (pinentry.locale_err)
1303
  if (pinentry.locale_err)
1291
    return ASSUAN_Locale_Problem;
1304
    return gpg_error (GPG_ERR_LOCALE_PROBLEM);
1292
1305
1293
  if (pinentry.one_button)
1306
  if (pinentry.one_button)
1294
    return 0;
1307
    return 0;
1295
1308
1296
  if (pinentry.canceled)
1309
  if (pinentry.canceled)
1297
    return ASSUAN_Canceled;
1310
    return gpg_error (GPG_ERR_CANCELED);
1298
  return ASSUAN_Not_Confirmed;
1311
  return gpg_error (GPG_ERR_NOT_CONFIRMED);
1299
}
1312
}
1300
1313
1301
1314
1302
static int
1315
static gpg_error_t
1303
cmd_message (ASSUAN_CONTEXT ctx, char *line)
1316
cmd_message (assuan_context_t ctx, char *line)
1304
{
1317
{
1305
  (void)line;
1318
  (void)line;
1306
1319
Lines 1315-1321 cmd_message (ASSUAN_CONTEXT ctx, char *line) Link Here
1315
     version     - Return the version of the program.
1328
     version     - Return the version of the program.
1316
     pid         - Return the process id of the server.
1329
     pid         - Return the process id of the server.
1317
 */
1330
 */
1318
static int
1331
static gpg_error_t
1319
cmd_getinfo (assuan_context_t ctx, char *line)
1332
cmd_getinfo (assuan_context_t ctx, char *line)
1320
{
1333
{
1321
  int rc;
1334
  int rc;
Lines 1333-1339 cmd_getinfo (assuan_context_t ctx, char *line) Link Here
1333
      rc = assuan_send_data (ctx, numbuf, strlen (numbuf));
1346
      rc = assuan_send_data (ctx, numbuf, strlen (numbuf));
1334
    }
1347
    }
1335
  else
1348
  else
1336
    rc = ASSUAN_Parameter_Error;
1349
    rc = gpg_error (GPG_ERR_ASS_PARAMETER);
1337
  return rc;
1350
  return rc;
1338
}
1351
}
1339
1352
Lines 1342-1354 cmd_getinfo (assuan_context_t ctx, char *line) Link Here
1342
   Clear the cache passphrase associated with the key identified by
1355
   Clear the cache passphrase associated with the key identified by
1343
   cacheid.
1356
   cacheid.
1344
 */
1357
 */
1345
static int
1358
static gpg_error_t
1346
cmd_clear_passphrase (ASSUAN_CONTEXT ctx, char *line)
1359
cmd_clear_passphrase (assuan_context_t ctx, char *line)
1347
{
1360
{
1348
  (void)ctx;
1361
  (void)ctx;
1349
1362
1350
  if (! line)
1363
  if (! line)
1351
    return ASSUAN_Invalid_Value;
1364
    return gpg_error (GPG_ERR_ASS_INV_VALUE);
1352
1365
1353
  /* Remove leading and trailing white space.  */
1366
  /* Remove leading and trailing white space.  */
1354
  while (*line == ' ')
1367
  while (*line == ' ')
Lines 1359-1408 cmd_clear_passphrase (ASSUAN_CONTEXT ctx, char *line) Link Here
1359
  switch (password_cache_clear (line))
1372
  switch (password_cache_clear (line))
1360
    {
1373
    {
1361
    case 1: return 0;
1374
    case 1: return 0;
1362
    case 0: return ASSUAN_Invalid_Value;
1375
    case 0: return gpg_error (GPG_ERR_ASS_INV_VALUE);
1363
    default: return ASSUAN_General_Error;
1376
    default: return gpg_error (GPG_ERR_ASS_GENERAL);
1364
    }
1377
    }
1365
}
1378
}
1366
1379
1367
/* Tell the assuan library about our commands.  */
1380
/* Tell the assuan library about our commands.  */
1368
static int
1381
static gpg_error_t
1369
register_commands (ASSUAN_CONTEXT ctx)
1382
register_commands (assuan_context_t ctx)
1370
{
1383
{
1371
  static struct
1384
  static struct
1372
  {
1385
  {
1373
    const char *name;
1386
    const char *name;
1374
    int cmd_id;
1387
    gpg_error_t (*handler) (assuan_context_t, char *line);
1375
    int (*handler) (ASSUAN_CONTEXT, char *line);
1376
  } table[] =
1388
  } table[] =
1377
    {
1389
    {
1378
      { "SETDESC",    0,  cmd_setdesc },
1390
      { "SETDESC",    cmd_setdesc },
1379
      { "SETPROMPT",  0,  cmd_setprompt },
1391
      { "SETPROMPT",  cmd_setprompt },
1380
      { "SETKEYINFO", 0,  cmd_setkeyinfo },
1392
      { "SETKEYINFO", cmd_setkeyinfo },
1381
      { "SETREPEAT",  0,  cmd_setrepeat },
1393
      { "SETREPEAT",  cmd_setrepeat },
1382
      { "SETREPEATERROR",0, cmd_setrepeaterror },
1394
      { "SETREPEATERROR", cmd_setrepeaterror },
1383
      { "SETERROR",   0,  cmd_seterror },
1395
      { "SETERROR",   cmd_seterror },
1384
      { "SETOK",      0,  cmd_setok },
1396
      { "SETOK",      cmd_setok },
1385
      { "SETNOTOK",   0,  cmd_setnotok },
1397
      { "SETNOTOK",   cmd_setnotok },
1386
      { "SETCANCEL",  0,  cmd_setcancel },
1398
      { "SETCANCEL",  cmd_setcancel },
1387
      { "GETPIN",     0,  cmd_getpin },
1399
      { "GETPIN",     cmd_getpin },
1388
      { "CONFIRM",    0,  cmd_confirm },
1400
      { "CONFIRM",    cmd_confirm },
1389
      { "MESSAGE",    0,  cmd_message },
1401
      { "MESSAGE",    cmd_message },
1390
      { "SETQUALITYBAR", 0,  cmd_setqualitybar },
1402
      { "SETQUALITYBAR", cmd_setqualitybar },
1391
      { "SETQUALITYBAR_TT", 0,  cmd_setqualitybar_tt },
1403
      { "SETQUALITYBAR_TT", cmd_setqualitybar_tt },
1392
      { "GETINFO",    0,  cmd_getinfo },
1404
      { "GETINFO",    cmd_getinfo },
1393
      { "SETTITLE",   0,  cmd_settitle },
1405
      { "SETTITLE",   cmd_settitle },
1394
      { "SETTIMEOUT",   0,  cmd_settimeout },
1406
      { "SETTIMEOUT", cmd_settimeout },
1395
      { "CLEARPASSPHRASE", 0, cmd_clear_passphrase },
1407
      { "CLEARPASSPHRASE", cmd_clear_passphrase },
1396
      { NULL }
1408
      { NULL }
1397
    };
1409
    };
1398
  int i, j, rc;
1410
  int i, j;
1411
  gpg_error_t rc;
1399
1412
1400
  for (i = j = 0; table[i].name; i++)
1413
  for (i = j = 0; table[i].name; i++)
1401
    {
1414
    {
1402
      rc = assuan_register_command (ctx,
1415
      rc = assuan_register_command (ctx, table[i].name, table[i].handler, NULL);
1403
                                    table[i].cmd_id ? table[i].cmd_id
1404
                                                   : (ASSUAN_CMD_USER + j++),
1405
                                    table[i].name, table[i].handler);
1406
      if (rc)
1416
      if (rc)
1407
        return rc;
1417
        return rc;
1408
    }
1418
    }
Lines 1413-1421 register_commands (ASSUAN_CONTEXT ctx) Link Here
1413
int
1423
int
1414
pinentry_loop2 (int infd, int outfd)
1424
pinentry_loop2 (int infd, int outfd)
1415
{
1425
{
1416
  int rc;
1426
  gpg_error_t rc;
1417
  int filedes[2];
1427
  int filedes[2];
1418
  ASSUAN_CONTEXT ctx;
1428
  assuan_context_t ctx;
1419
1429
1420
  /* Extra check to make sure we have dropped privs. */
1430
  /* Extra check to make sure we have dropped privs. */
1421
#ifndef HAVE_DOSISH_SYSTEM
1431
#ifndef HAVE_DOSISH_SYSTEM
Lines 1423-1445 pinentry_loop2 (int infd, int outfd) Link Here
1423
    abort ();
1433
    abort ();
1424
#endif
1434
#endif
1425
1435
1436
  rc = assuan_new (&ctx);
1437
  if (rc)
1438
    {
1439
      fprintf (stderr, "server context creation failed: %s\n",
1440
	       gpg_strerror (rc));
1441
      return -1;
1442
    }
1443
1426
  /* For now we use a simple pipe based server so that we can work
1444
  /* For now we use a simple pipe based server so that we can work
1427
     from scripts.  We will later add options to run as a daemon and
1445
     from scripts.  We will later add options to run as a daemon and
1428
     wait for requests on a Unix domain socket.  */
1446
     wait for requests on a Unix domain socket.  */
1429
  filedes[0] = infd;
1447
  filedes[0] = infd;
1430
  filedes[1] = outfd;
1448
  filedes[1] = outfd;
1431
  rc = assuan_init_pipe_server (&ctx, filedes);
1449
  rc = assuan_init_pipe_server (ctx, filedes);
1432
  if (rc)
1450
  if (rc)
1433
    {
1451
    {
1434
      fprintf (stderr, "%s: failed to initialize the server: %s\n",
1452
      fprintf (stderr, "%s: failed to initialize the server: %s\n",
1435
               this_pgmname, assuan_strerror(rc));
1453
               this_pgmname, gpg_strerror (rc));
1436
      return -1;
1454
      return -1;
1437
    }
1455
    }
1438
  rc = register_commands (ctx);
1456
  rc = register_commands (ctx);
1439
  if (rc)
1457
  if (rc)
1440
    {
1458
    {
1441
      fprintf (stderr, "%s: failed to the register commands with Assuan: %s\n",
1459
      fprintf (stderr, "%s: failed to the register commands with Assuan: %s\n",
1442
               this_pgmname, assuan_strerror(rc));
1460
               this_pgmname, gpg_strerror (rc));
1443
      return -1;
1461
      return -1;
1444
    }
1462
    }
1445
1463
Lines 1457-1463 pinentry_loop2 (int infd, int outfd) Link Here
1457
      else if (rc)
1475
      else if (rc)
1458
        {
1476
        {
1459
          fprintf (stderr, "%s: Assuan accept problem: %s\n",
1477
          fprintf (stderr, "%s: Assuan accept problem: %s\n",
1460
                   this_pgmname, assuan_strerror (rc));
1478
                   this_pgmname, gpg_strerror (rc));
1461
          break;
1479
          break;
1462
        }
1480
        }
1463
1481
Lines 1465-1476 pinentry_loop2 (int infd, int outfd) Link Here
1465
      if (rc)
1483
      if (rc)
1466
        {
1484
        {
1467
          fprintf (stderr, "%s: Assuan processing failed: %s\n",
1485
          fprintf (stderr, "%s: Assuan processing failed: %s\n",
1468
                   this_pgmname, assuan_strerror (rc));
1486
                   this_pgmname, gpg_strerror (rc));
1469
          continue;
1487
          continue;
1470
        }
1488
        }
1471
    }
1489
    }
1472
1490
1473
  assuan_deinit_server (ctx);
1491
  assuan_release (ctx);
1474
  return 0;
1492
  return 0;
1475
}
1493
}
1476
1494

Return to bug 252912