Debian Codegraph @

pinentry/pinentry.c

raw symbols SCIP
1 /* pinentry.c - The PIN entry support library
2 Copyright (C) 2002, 2003, 2007, 2008 g10 Code GmbH
3
4 This file is part of PINENTRY.
5
6 PINENTRY is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 PINENTRY is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:412:9`!
21 #include <config.h>cxx . . $ `<file>/config.h`/
22 #endif
23
24 #include <errno.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <getopt.h>
28 #include <unistd.h>
29 #include <locale.h>
30 #ifdef HAVE_LANGINFO_Hcxx . . $ `config.h:21:9`!
31 #include <langinfo.h>
32 #endif
33 #include <limits.h>
34
35 #if defined FALLBACK_CURSES || defined PINENTRY_CURSES || defined PINENTRY_GTK
36 #include <iconv.h>
37 #endif
38
39 #include "assuan.h"cxx . . $ `<file>/assuan/assuan.h`/
40 #include "memory.h"cxx . . $ `<file>/secmem/memory.h`/
41 #include "secmem-util.h"cxx . . $ `<file>/secmem/secmem-util.h`/
42 #include "pinentry.h"cxx . . $ `<file>/pinentry/pinentry.h`/
43
44
45 /* Keep the name of our program here. */
46 static char this_pgmnamecxx . . $ this_pgmname.[50];
47
48
49 struct pinentrycxx . . $ pinentry# pinentrycxx . . $ pinentry. =
50 {
51 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, /* Description. */
52 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, /* Error. */
53 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, /* Prompt. */
54 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, /* Ok button. */
55 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, /* Cancel button. */
56 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, /* PIN. */
57 2048, /* PIN length. */
58 0, /* Display. */
59 0, /* TTY name. */
60 0, /* TTY type. */
61 0, /* TTY LC_CTYPE. */
62 0, /* TTY LC_MESSAGES. */
63 0, /* Debug mode. */
64 0, /* Enhanced mode. */
65 1, /* Global grab. */
66 0, /* Parent Window ID. */
67 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, /* Touch file. */
68 0, /* Result. */
69 0, /* Locale error flag. */
70 0, /* One-button flag. */
71 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, /* Quality-Bar flag and description. */
72 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, /* Quality-Bar tooltip. */
73 PINENTRY_COLOR_DEFAULTcxx . . $ PINENTRY_COLOR_DEFAULT.,
74 0,
75 PINENTRY_COLOR_DEFAULTcxx . . $ PINENTRY_COLOR_DEFAULT.,
76 PINENTRY_COLOR_DEFAULTcxx . . $ PINENTRY_COLOR_DEFAULT.,
77 0,
78 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! /* Assuan context. */
79 };
80
81
82
83 #if defined FALLBACK_CURSES || defined PINENTRY_CURSES || defined PINENTRY_GTK
84 char *
85 pinentry_utf8_to_local (char *lc_ctype, char *text)
86 {
87 iconv_t cd;
88 const char *input = text;
89 size_t input_len = strlen (text) + 1;
90 char *output;
91 size_t output_len;
92 char *output_buf;
93 size_t processed;
94 char *old_ctype;
95 char *target_encoding;
96
97 /* If no locale setting could be determined, simply copy the
98 string. */
99 if (!lc_ctype)
100 {
101 fprintf (stderr, "%s: no LC_CTYPE known - assuming UTF-8\n",
102 this_pgmname);
103 return strdup (text);
104 }
105
106 old_ctype = strdup (setlocale (LC_CTYPE, NULL));
107 if (!old_ctype)
108 return NULL;
109 setlocale (LC_CTYPE, lc_ctype);
110 target_encoding = nl_langinfo (CODESET);
111 if (!target_encoding)
112 target_encoding = "?";
113 setlocale (LC_CTYPE, old_ctype);
114 free (old_ctype);
115
116 /* This is overkill, but simplifies the iconv invocation greatly. */
117 output_len = input_len * MB_LEN_MAX;
118 output_buf = output = malloc (output_len);
119 if (!output)
120 return NULL;
121
122 cd = iconv_open (target_encoding, "UTF-8");
123 if (cd == (iconv_t) -1)
124 {
125 fprintf (stderr, "%s: can't convert from UTF-8 to %s: %s\n",
126 this_pgmname, target_encoding, strerror (errno));
127 free (output_buf);
128 return NULL;
129 }
130 processed = iconv (cd, &input, &input_len, &output, &output_len);
131 iconv_close (cd);
132 if (processed == (size_t) -1 || input_len)
133 {
134 fprintf (stderr, "%s: error converting from UTF-8 to %s: %s\n",
135 this_pgmname, target_encoding, strerror (errno));
136 free (output_buf);
137 return NULL;
138 }
139 return output_buf;
140 }
141
142 /* Convert TEXT which is encoded according to LC_CTYPE to UTF-8. With
143 SECURE set to true, use secure memory for the returned buffer.
144 Return NULL on error. */
145 char *
146 pinentry_local_to_utf8 (char *lc_ctype, char *text, int secure)
147 {
148 char *old_ctype;
149 char *source_encoding;
150 iconv_t cd;
151 const char *input = text;
152 size_t input_len = strlen (text) + 1;
153 char *output;
154 size_t output_len;
155 char *output_buf;
156 size_t processed;
157
158 /* If no locale setting could be determined, simply copy the
159 string. */
160 if (!lc_ctype)
161 {
162 fprintf (stderr, "%s: no LC_CTYPE known - assuming UTF-8\n",
163 this_pgmname);
164 output_buf = secure? secmem_malloc (input_len) : malloc (input_len);
165 if (output_buf)
166 strcpy (output_buf, input);
167 return output_buf;
168 }
169
170 old_ctype = strdup (setlocale (LC_CTYPE, NULL));
171 if (!old_ctype)
172 return NULL;
173 setlocale (LC_CTYPE, lc_ctype);
174 source_encoding = nl_langinfo (CODESET);
175 setlocale (LC_CTYPE, old_ctype);
176 free (old_ctype);
177
178 /* This is overkill, but simplifies the iconv invocation greatly. */
179 output_len = input_len * MB_LEN_MAX;
180 output_buf = output = secure? secmem_malloc (output_len):malloc (output_len);
181 if (!output)
182 return NULL;
183
184 cd = iconv_open ("UTF-8", source_encoding);
185 if (cd == (iconv_t) -1)
186 {
187 fprintf (stderr, "%s: can't convert from %s to UTF-8: %s\n",
188 this_pgmname, source_encoding? source_encoding : "?",
189 strerror (errno));
190 if (secure)
191 secmem_free (output_buf);
192 else
193 free (output_buf);
194 return NULL;
195 }
196 processed = iconv (cd, &input, &input_len, &output, &output_len);
197 iconv_close (cd);
198 if (processed == (size_t) -1 || input_len)
199 {
200 fprintf (stderr, "%s: error converting from %s to UTF-8: %s\n",
201 this_pgmname, source_encoding? source_encoding : "?",
202 strerror (errno));
203 if (secure)
204 secmem_free (output_buf);
205 else
206 free (output_buf);
207 return NULL;
208 }
209 return output_buf;
210 }
211 #endif
212
213
214 /* Copy TEXT or TEXTLEN to BUFFER and escape as required. Return a
215 pointer to the end of the new buffer. Note that BUFFER must be
216 large enough to keep the entire text; allocataing it 3 times of
217 TEXTLEN is sufficient. */
218 static char *
219 copy_and_escapecxx . . $ copy_and_escape(78becf43a9d096be). (char *buffer, const void *text, size_t textlen)
220 {
221 int i;
222 const unsigned char *s = (unsigned char *)text;
223 char *p = buffer;
224
225 for (i=0; i < textlen; i++)
226 {
227 if (s[i] < ' ' || s[i] == '+')
228 {
229 snprintfcxx . . $ snprintf(ea502d73e74c754c). (p, 4, "%%%02X", s[i]);
230 p += 3;
231 }
232 else if (s[i] == ' ')
233 *p++ = '+';
234 else
235 *p++ = s[i];
236 }
237 return p;
238 }
239
240
241
242 /* Run a quality inquiry for PASSPHRASE of LENGTH. (We need LENGTH
243 because not all backends might be able to return a proper
244 C-string.). Returns: A value between -100 and 100 to give an
245 estimate of the passphrase's quality. Negative values are use if
246 the caller won't even accept that passphrase. Note that we expect
247 just one data line which should not be escaped in any represent a
248 numeric signed decimal value. Extra data is currently ignored but
249 should not be send at all. */
250 int
251 pinentry_inq_qualitycxx . . $ pinentry_inq_quality(199af5c9056db858). (pinentry_tcxx . . $ pinentry_t# pin, const char *passphrase, size_t length)
252 {
253 ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx = pin->ctx_assuancxx . . $ pinentry#ctx_assuan.;
254 const char prefix[] = "INQUIRE QUALITY ";
255 char *command;
256 char *line;
257 size_t linelen;
258 int gotvalue = 0;
259 int value = 0;
260 int rc;
261
262 if (!ctx)
263 return 0; /* Can't run the callback. */
264
265 if (length > 300)
266 length = 300; /* Limit so that it definitely fits into an Assuan
267 line. */
268
269 command = secmem_malloccxx . . $ secmem_malloc(bfcfa4d6b7f7ef64). (strlencxx . . $ strlen(751346f8406fd082). (prefix) + 3*length + 1);
270 if (!command)
271 return 0;
272 strcpycxx . . $ strcpy(b7b3a83273496486). (command, prefix);
273 copy_and_escapecxx . . $ copy_and_escape(78becf43a9d096be). (command + strlencxx . . $ strlen(751346f8406fd082).(command), passphrase, length);
274 rc = assuan_write_linecxx . . $ assuan_write_line(ee7b1645795a12df). (ctx, command);
275 secmem_freecxx . . $ secmem_free(5d22bdacc48458e8). (command);
276 if (rc)
277 {
278 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ASSUAN WRITE LINE failed: rc=%d\n", rc);
279 return 0;
280 }
281
282 for (;;)
283 {
284 do
285 {
286 rc = assuan_read_linecxx . . $ assuan_read_line(cf365bd337ca36f2). (ctx, &line, &linelen);
287 if (rc)
288 {
289 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ASSUAN READ LINE failed: rc=%d\n", rc);
290 return 0;
291 }
292 }
293 while (*line == '#' || !linelen);
294 if (line[0] == 'E' && line[1] == 'N' && line[2] == 'D'
295 && (!line[3] || line[3] == ' '))
296 break; /* END command received*/
297 if (line[0] == 'C' && line[1] == 'A' && line[2] == 'N'
298 && (!line[3] || line[3] == ' '))
299 break; /* CAN command received*/
300 if (line[0] == 'E' && line[1] == 'R' && line[2] == 'R'
301 && (!line[3] || line[3] == ' '))
302 break; /* ERR command received*/
303 if (line[0] != 'D' || line[1] != ' ' || linelen < 3 || gotvalue)
304 continue;
305 gotvalue = 1;
306 value = atoicxx . . $ atoi(5c4306d8553b3696). (line+2);
307 }
308 if (value < -100)
309 value = -100;
310 else if (value > 100)
311 value = 100;
312
313 return value;
314 }
315
316
317
318 /* Try to make room for at least LEN bytes in the pinentry. Returns
319 new buffer on success and 0 on failure or when the old buffer is
320 sufficient. */
321 char *
322 pinentry_setbufferlencxx . . $ pinentry_setbufferlen(c6f507c5af595f65). (pinentry_tcxx . . $ pinentry_t# pin, int len)
323 {
324 char *newp;
325 if (len < pinentrycxx . . $ pinentry..pin_lencxx . . $ pinentry#pin_len.)
326 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
327 newp = secmem_realloccxx . . $ secmem_realloc(417ab160f6baadc6). (pin->pincxx . . $ pinentry#pin., 2 * pin->pin_lencxx . . $ pinentry#pin_len.);
328 if (newp)
329 {
330 pin->pincxx . . $ pinentry#pin. = newp;
331 pin->pin_lencxx . . $ pinentry#pin_len. *= 2;
332 }
333 else
334 {
335 secmem_freecxx . . $ secmem_free(5d22bdacc48458e8). (pin->pincxx . . $ pinentry#pin.);
336 pin->pincxx . . $ pinentry#pin. = 0;
337 pin->pin_lencxx . . $ pinentry#pin_len. = 0;
338 }
339 return newp;
340 }
341
342
343 /* Initialize the secure memory subsystem, drop privileges and return.
344 Must be called early. */
345 void
346 pinentry_initcxx . . $ pinentry_init(85c52e162fed56f9). (const char *pgmname)
347 {
348 /* Store away our name. */
349 if (strlencxx . . $ strlen(751346f8406fd082). (pgmname) > sizeof this_pgmnamecxx . . $ this_pgmname. - 2)
350 abortcxx . . $ abort(8df32a62017fbbf6). ();
351 strcpycxx . . $ strcpy(b7b3a83273496486). (this_pgmnamecxx . . $ this_pgmname., pgmname);
352
353 /* Initialize secure memory. 1 is too small, so the default size
354 will be used. */
355 secmem_initcxx . . $ secmem_init(2c44cd906ae4e829). (1);
356 secmem_set_flagscxx . . $ secmem_set_flags(cb2f890c2fdad230). (SECMEM_WARNcxx . . $ `secmem/memory.h:26:9`!);
357 drop_privscxx . . $ drop_privs(49f6e7a06ebc5aa8). ();
358
359 if (atexitcxx . . $ atexit(8919c3b35e68c42d). (secmem_termcxx . . $ secmem_term(49f6e7a06ebc5aa8).))
360 /* FIXME: Could not register at-exit function, bail out. */
361 ;
362
363 assuan_set_malloc_hookscxx . . $ assuan_set_malloc_hooks(dc9a7692af199bc0). (secmem_malloccxx . . $ secmem_malloc(bfcfa4d6b7f7ef64)., secmem_realloccxx . . $ secmem_realloc(417ab160f6baadc6)., secmem_freecxx . . $ secmem_free(5d22bdacc48458e8).);
364 }
365
366 /* Simple test to check whether DISPLAY is set or the option --display
367 was given. Used to decide whether the GUI or curses should be
368 initialized. */
369 int
370 pinentry_have_displaycxx . . $ pinentry_have_display(afcd3168fc1188a4). (int argc, char **argv)
371 {
372 const char *s;
373
374 s = getenvcxx . . $ getenv(a8b8e32347182212). ("DISPLAY");
375 if (s && *s)
376 return 1;
377 for (; argc; argc--, argv++)
378 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (*argv, "--display"))
379 return 1;
380 return 0;
381 }
382
383
384
385 static void
386 usagecxx . . $ usage(49f6e7a06ebc5aa8). (void)
387 {
388 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "Usage: %s [OPTION]...\n"
389 "Ask securely for a secret and print it to stdout.\n"
390 "\n"
391 " --display DISPLAY Set the X display\n"
392 " --ttyname PATH Set the tty terminal node name\n"
393 " --ttytype NAME Set the tty terminal type\n"
394 " --lc-ctype Set the tty LC_CTYPE value\n"
395 " --lc-messages Set the tty LC_MESSAGES value\n"
396 " -e, --enhanced Ask for timeout and insurance, too\n"
397 " -g, --no-global-grab Grab keyboard only while window is focused\n"
398 " --parent-wid Parent window ID (for positioning)\n"
399 " -d, --debug Turn on debugging output\n"
400 " -h, --help Display this help and exit\n"
401 " --version Output version information and exit\n", this_pgmnamecxx . . $ this_pgmname.);
402 }
403
404
405 char *
406 parse_colorcxx . . $ parse_color(43edb19d8879a881). (char *arg, pinentry_color_tcxx . . $ pinentry_color_t# *color_p, int *bright_p)
407 {
408 static structcxx . . $ parse_color(43edb19d8879a881).$anonymous_type_0#
409 {
410 const char *namecxx . . $ parse_color(43edb19d8879a881).$anonymous_type_0#name.;
411 pinentry_color_tcxx . . $ pinentry_color_t# colorcxx . . $ parse_color(43edb19d8879a881).$anonymous_type_0#color.;
412 } colors[] = { { "none", PINENTRY_COLOR_NONEcxx . . $ PINENTRY_COLOR_NONE. },
413 { "default", PINENTRY_COLOR_DEFAULTcxx . . $ PINENTRY_COLOR_DEFAULT. },
414 { "black", PINENTRY_COLOR_BLACKcxx . . $ PINENTRY_COLOR_BLACK. },
415 { "red", PINENTRY_COLOR_REDcxx . . $ PINENTRY_COLOR_RED. },
416 { "green", PINENTRY_COLOR_GREENcxx . . $ PINENTRY_COLOR_GREEN. },
417 { "yellow", PINENTRY_COLOR_YELLOWcxx . . $ PINENTRY_COLOR_YELLOW. },
418 { "blue", PINENTRY_COLOR_BLUEcxx . . $ PINENTRY_COLOR_BLUE. },
419 { "magenta", PINENTRY_COLOR_MAGENTAcxx . . $ PINENTRY_COLOR_MAGENTA. },
420 { "cyan", PINENTRY_COLOR_CYANcxx . . $ PINENTRY_COLOR_CYAN. },
421 { "white", PINENTRY_COLOR_WHITEcxx . . $ PINENTRY_COLOR_WHITE. } };
422
423 int i;
424 char *new_arg;
425 pinentry_color_tcxx . . $ pinentry_color_t# color = PINENTRY_COLOR_DEFAULTcxx . . $ PINENTRY_COLOR_DEFAULT.;
426
427 if (!arg)
428 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
429
430 new_arg = strchrcxx . . $ strchr(2050848944e00d54). (arg, ',');
431 if (new_arg)
432 new_arg++;
433
434 if (bright_p)
435 {
436 const char *bname[] = { "bright-", "bright", "bold-", "bold" };
437
438 *bright_p = 0;
439 for (i = 0; i < sizeof (bname) / sizeof (bname[0]); i++)
440 if (!strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e). (arg, bname[i], strlencxx . . $ strlen(751346f8406fd082). (bname[i])))
441 {
442 *bright_p = 1;
443 arg += strlencxx . . $ strlen(751346f8406fd082). (bname[i]);
444 }
445 }
446
447 for (i = 0; i < sizeof (colors) / sizeof (colors[0]); i++)
448 if (!strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e). (arg, colors[i].namecxx . . $ parse_color(43edb19d8879a881).$anonymous_type_0#name., strlencxx . . $ strlen(751346f8406fd082). (colors[i].namecxx . . $ parse_color(43edb19d8879a881).$anonymous_type_0#name.)))
449 color = colors[i].colorcxx . . $ parse_color(43edb19d8879a881).$anonymous_type_0#color.;
450
451 *color_p = color;
452 return new_arg;
453 }
454
455 /* Parse the command line options. Returns 1 if user should print
456 version and exit. Can exit the program if only help output is
457 requested. */
458 int
459 pinentry_parse_optscxx . . $ pinentry_parse_opts(afcd3168fc1188a4). (int argc, char *argv[])
460 {
461 int opt;
462 int opt_help = 0;
463 int opt_version = 0;
464 struct optioncxx . . $ option# opts[] =
465 {{ "debug", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, 0, 'd' },
466 { "display", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'D' },
467 { "ttyname", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'T' },
468 { "ttytype", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'N' },
469 { "lc-ctype", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'C' },
470 { "lc-messages", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'M' },
471 { "enhanced", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, 0, 'e' },
472 { "no-global-grab", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, 0, 'g' },
473 { "parent-wid", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'W' },
474 { "colors", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, 0, 'c' },
475 { "help", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, 0, 'h' },
476 { "version", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, &opt_version, 1 },
477 { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0 }};
478
479 while ((opt = getopt_longcxx . . $ getopt_long(41f665c090816971). (argc, argv, "degh", opts, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) != -1)
480 {
481 switch (opt)
482 {
483 case 0:
484 case '?':
485 break;
486 case 'd':
487 pinentrycxx . . $ pinentry..debugcxx . . $ pinentry#debug. = 1;
488 break;
489 case 'e':
490 pinentrycxx . . $ pinentry..enhancedcxx . . $ pinentry#enhanced. = 1;
491 break;
492 case 'g':
493 pinentrycxx . . $ pinentry..grabcxx . . $ pinentry#grab. = 0;
494 break;
495 case 'h':
496 opt_help = 1;
497 break;
498
499 case 'D':
500 /* Note, this is currently not used because the GUI engine
501 has already been initialized when parsing these options. */
502 pinentrycxx . . $ pinentry..displaycxx . . $ pinentry#display. = strdupcxx . . $ strdup(a8b8e32347182212). (optargcxx . . $ optarg.);
503 if (!pinentrycxx . . $ pinentry..displaycxx . . $ pinentry#display.)
504 {
505 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: %s\n", this_pgmnamecxx . . $ this_pgmname., strerrorcxx . . $ strerror(ff224f080444ee45). (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
506 exitcxx . . $ exit(3ca292c338df9bb3). (EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
507 }
508 break;
509 case 'T':
510 pinentrycxx . . $ pinentry..ttynamecxx . . $ pinentry#ttyname. = strdupcxx . . $ strdup(a8b8e32347182212). (optargcxx . . $ optarg.);
511 if (!pinentrycxx . . $ pinentry..ttynamecxx . . $ pinentry#ttyname.)
512 {
513 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: %s\n", this_pgmnamecxx . . $ this_pgmname., strerrorcxx . . $ strerror(ff224f080444ee45). (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
514 exitcxx . . $ exit(3ca292c338df9bb3). (EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
515 }
516 break;
517 case 'N':
518 pinentrycxx . . $ pinentry..ttytypecxx . . $ pinentry#ttytype. = strdupcxx . . $ strdup(a8b8e32347182212). (optargcxx . . $ optarg.);
519 if (!pinentrycxx . . $ pinentry..ttytypecxx . . $ pinentry#ttytype.)
520 {
521 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: %s\n", this_pgmnamecxx . . $ this_pgmname., strerrorcxx . . $ strerror(ff224f080444ee45). (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
522 exitcxx . . $ exit(3ca292c338df9bb3). (EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
523 }
524 break;
525 case 'C':
526 pinentrycxx . . $ pinentry..lc_ctypecxx . . $ pinentry#lc_ctype. = strdupcxx . . $ strdup(a8b8e32347182212). (optargcxx . . $ optarg.);
527 if (!pinentrycxx . . $ pinentry..lc_ctypecxx . . $ pinentry#lc_ctype.)
528 {
529 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: %s\n", this_pgmnamecxx . . $ this_pgmname., strerrorcxx . . $ strerror(ff224f080444ee45). (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
530 exitcxx . . $ exit(3ca292c338df9bb3). (EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
531 }
532 break;
533 case 'M':
534 pinentrycxx . . $ pinentry..lc_messagescxx . . $ pinentry#lc_messages. = strdupcxx . . $ strdup(a8b8e32347182212). (optargcxx . . $ optarg.);
535 if (!pinentrycxx . . $ pinentry..lc_messagescxx . . $ pinentry#lc_messages.)
536 {
537 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: %s\n", this_pgmnamecxx . . $ this_pgmname., strerrorcxx . . $ strerror(ff224f080444ee45). (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
538 exitcxx . . $ exit(3ca292c338df9bb3). (EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
539 }
540 break;
541 case 'W':
542 pinentrycxx . . $ pinentry..parent_widcxx . . $ pinentry#parent_wid. = atoicxx . . $ atoi(5c4306d8553b3696). (optargcxx . . $ optarg.);
543 /* FIXME: Add some error handling. Use strtol. */
544 break;
545
546 case 'c':
547 optargcxx . . $ optarg. = parse_colorcxx . . $ parse_color(43edb19d8879a881). (optargcxx . . $ optarg., &pinentrycxx . . $ pinentry..color_fgcxx . . $ pinentry#color_fg.,
548 &pinentrycxx . . $ pinentry..color_fg_brightcxx . . $ pinentry#color_fg_bright.);
549 optargcxx . . $ optarg. = parse_colorcxx . . $ parse_color(43edb19d8879a881). (optargcxx . . $ optarg., &pinentrycxx . . $ pinentry..color_bgcxx . . $ pinentry#color_bg., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
550 optargcxx . . $ optarg. = parse_colorcxx . . $ parse_color(43edb19d8879a881). (optargcxx . . $ optarg., &pinentrycxx . . $ pinentry..color_socxx . . $ pinentry#color_so.,
551 &pinentrycxx . . $ pinentry..color_so_brightcxx . . $ pinentry#color_so_bright.);
552 break;
553
554 default:
555 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: oops: option not handled\n", this_pgmnamecxx . . $ this_pgmname.);
556 break;
557 }
558 }
559 if (opt_version)
560 return 1;
561 if (opt_help)
562 {
563 usagecxx . . $ usage(49f6e7a06ebc5aa8). ();
564 exitcxx . . $ exit(3ca292c338df9bb3). (EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!);
565 }
566 return 0;
567 }
568
569
570 static int
571 option_handlercxx . . $ option_handler(7d4a227c335102d2). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, const char *key, const char *value)
572 {
573 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (key, "no-grab") && !*value)
574 pinentrycxx . . $ pinentry..grabcxx . . $ pinentry#grab. = 0;
575 else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (key, "grab") && !*value)
576 pinentrycxx . . $ pinentry..grabcxx . . $ pinentry#grab. = 1;
577 else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (key, "debug-wait"))
578 {
579 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: waiting for debugger - my pid is %u ...\n",
580 this_pgmnamecxx . . $ this_pgmname., (unsigned int) getpidcxx . . $ getpid(b126dc7c1de90089).());
581 sleepcxx . . $ sleep(2141b656ce2cc063). (*value?atoicxx . . $ atoi(5c4306d8553b3696). (value):5);
582 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: ... okay\n", this_pgmnamecxx . . $ this_pgmname.);
583 }
584 else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (key, "display"))
585 {
586 if (pinentrycxx . . $ pinentry..displaycxx . . $ pinentry#display.)
587 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..displaycxx . . $ pinentry#display.);
588 pinentrycxx . . $ pinentry..displaycxx . . $ pinentry#display. = strdupcxx . . $ strdup(a8b8e32347182212). (value);
589 if (!pinentrycxx . . $ pinentry..displaycxx . . $ pinentry#display.)
590 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
591 }
592 else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (key, "ttyname"))
593 {
594 if (pinentrycxx . . $ pinentry..ttynamecxx . . $ pinentry#ttyname.)
595 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..ttynamecxx . . $ pinentry#ttyname.);
596 pinentrycxx . . $ pinentry..ttynamecxx . . $ pinentry#ttyname. = strdupcxx . . $ strdup(a8b8e32347182212). (value);
597 if (!pinentrycxx . . $ pinentry..ttynamecxx . . $ pinentry#ttyname.)
598 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
599 }
600 else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (key, "ttytype"))
601 {
602 if (pinentrycxx . . $ pinentry..ttytypecxx . . $ pinentry#ttytype.)
603 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..ttytypecxx . . $ pinentry#ttytype.);
604 pinentrycxx . . $ pinentry..ttytypecxx . . $ pinentry#ttytype. = strdupcxx . . $ strdup(a8b8e32347182212). (value);
605 if (!pinentrycxx . . $ pinentry..ttytypecxx . . $ pinentry#ttytype.)
606 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
607 }
608 else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (key, "lc-ctype"))
609 {
610 if (pinentrycxx . . $ pinentry..lc_ctypecxx . . $ pinentry#lc_ctype.)
611 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..lc_ctypecxx . . $ pinentry#lc_ctype.);
612 pinentrycxx . . $ pinentry..lc_ctypecxx . . $ pinentry#lc_ctype. = strdupcxx . . $ strdup(a8b8e32347182212). (value);
613 if (!pinentrycxx . . $ pinentry..lc_ctypecxx . . $ pinentry#lc_ctype.)
614 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
615 }
616 else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (key, "lc-messages"))
617 {
618 if (pinentrycxx . . $ pinentry..lc_messagescxx . . $ pinentry#lc_messages.)
619 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..lc_messagescxx . . $ pinentry#lc_messages.);
620 pinentrycxx . . $ pinentry..lc_messagescxx . . $ pinentry#lc_messages. = strdupcxx . . $ strdup(a8b8e32347182212). (value);
621 if (!pinentrycxx . . $ pinentry..lc_messagescxx . . $ pinentry#lc_messages.)
622 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
623 }
624 else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (key, "parent-wid"))
625 {
626 pinentrycxx . . $ pinentry..parent_widcxx . . $ pinentry#parent_wid. = atoicxx . . $ atoi(5c4306d8553b3696). (value);
627 /* FIXME: Use strtol and add some error handling. */
628 }
629 else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (key, "touch-file"))
630 {
631 if (pinentrycxx . . $ pinentry..touch_filecxx . . $ pinentry#touch_file.)
632 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..touch_filecxx . . $ pinentry#touch_file.);
633 pinentrycxx . . $ pinentry..touch_filecxx . . $ pinentry#touch_file. = strdupcxx . . $ strdup(a8b8e32347182212). (value);
634 if (!pinentrycxx . . $ pinentry..touch_filecxx . . $ pinentry#touch_file.)
635 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
636 }
637 else
638 return ASSUAN_Invalid_Optioncxx . . $ ASSUAN_Invalid_Option.;
639 return 0;
640 }
641
642
643 /* Note, that it is sufficient to allocate the target string D as
644 long as the source string S, i.e.: strlen(s)+1; */
645 static void
646 strcpy_escapedcxx . . $ strcpy_escaped(d6c5f6b04427ee2c). (char *d, const unsigned char *s)
647 {
648 while (*s)
649 {
650 if (*s == '%' && s[1] && s[2])
651 {
652 s++;
653 *d++ = xtoi_2cxx . . $ `secmem/util.h:63:9`! ( s);
654 s += 2;
655 }
656 else
657 *d++ = *s++;
658 }
659 *d = 0;
660 }
661
662
663 static int
664 cmd_setdesccxx . . $ cmd_setdesc(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line)
665 {
666 char *newd;
667 newd = malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (strlencxx . . $ strlen(751346f8406fd082). (line) + 1);
668
669 if (!newd)
670 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
671
672 strcpy_escapedcxx . . $ strcpy_escaped(d6c5f6b04427ee2c). (newd, line);
673 if (pinentrycxx . . $ pinentry..descriptioncxx . . $ pinentry#description.)
674 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..descriptioncxx . . $ pinentry#description.);
675 pinentrycxx . . $ pinentry..descriptioncxx . . $ pinentry#description. = newd;
676 return 0;
677 }
678
679
680 static int
681 cmd_setpromptcxx . . $ cmd_setprompt(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line)
682 {
683 char *newp;
684 newp = malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (strlencxx . . $ strlen(751346f8406fd082). (line) + 1);
685
686 if (!newp)
687 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
688
689 strcpy_escapedcxx . . $ strcpy_escaped(d6c5f6b04427ee2c). (newp, line);
690 if (pinentrycxx . . $ pinentry..promptcxx . . $ pinentry#prompt.)
691 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..promptcxx . . $ pinentry#prompt.);
692 pinentrycxx . . $ pinentry..promptcxx . . $ pinentry#prompt. = newp;
693 return 0;
694 }
695
696
697 static int
698 cmd_seterrorcxx . . $ cmd_seterror(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line)
699 {
700 char *newe;
701 newe = malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (strlencxx . . $ strlen(751346f8406fd082). (line) + 1);
702
703 if (!newe)
704 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
705
706 strcpy_escapedcxx . . $ strcpy_escaped(d6c5f6b04427ee2c). (newe, line);
707 if (pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error.)
708 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error.);
709 pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error. = newe;
710 return 0;
711 }
712
713
714 static int
715 cmd_setokcxx . . $ cmd_setok(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line)
716 {
717 char *newo;
718 newo = malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (strlencxx . . $ strlen(751346f8406fd082). (line) + 1);
719
720 if (!newo)
721 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
722
723 strcpy_escapedcxx . . $ strcpy_escaped(d6c5f6b04427ee2c). (newo, line);
724 if (pinentrycxx . . $ pinentry..okcxx . . $ pinentry#ok.)
725 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..okcxx . . $ pinentry#ok.);
726 pinentrycxx . . $ pinentry..okcxx . . $ pinentry#ok. = newo;
727 return 0;
728 }
729
730
731 static int
732 cmd_setcancelcxx . . $ cmd_setcancel(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line)
733 {
734 char *newc;
735 newc = malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (strlencxx . . $ strlen(751346f8406fd082). (line) + 1);
736
737 if (!newc)
738 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
739
740 strcpy_escapedcxx . . $ strcpy_escaped(d6c5f6b04427ee2c). (newc, line);
741 if (pinentrycxx . . $ pinentry..cancelcxx . . $ pinentry#cancel.)
742 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..cancelcxx . . $ pinentry#cancel.);
743 pinentrycxx . . $ pinentry..cancelcxx . . $ pinentry#cancel. = newc;
744 return 0;
745 }
746
747
748
749 static int
750 cmd_setqualitybarcxx . . $ cmd_setqualitybar(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line)
751 {
752 char *newval;
753
754 if (!*line)
755 line = "Quality:";
756
757 newval = malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (strlencxx . . $ strlen(751346f8406fd082). (line) + 1);
758 if (!newval)
759 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
760
761 strcpy_escapedcxx . . $ strcpy_escaped(d6c5f6b04427ee2c). (newval, line);
762 if (pinentrycxx . . $ pinentry..quality_barcxx . . $ pinentry#quality_bar.)
763 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..quality_barcxx . . $ pinentry#quality_bar.);
764 pinentrycxx . . $ pinentry..quality_barcxx . . $ pinentry#quality_bar. = newval;
765 return 0;
766 }
767
768 /* Set the tooltip to be used for a quality bar. */
769 static int
770 cmd_setqualitybar_ttcxx . . $ cmd_setqualitybar_tt(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line)
771 {
772 char *newval;
773
774 if (*line)
775 {
776 newval = malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (strlencxx . . $ strlen(751346f8406fd082). (line) + 1);
777 if (!newval)
778 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
779
780 strcpy_escapedcxx . . $ strcpy_escaped(d6c5f6b04427ee2c). (newval, line);
781 }
782 else
783 newval = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
784 if (pinentrycxx . . $ pinentry..quality_bar_ttcxx . . $ pinentry#quality_bar_tt.)
785 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..quality_bar_ttcxx . . $ pinentry#quality_bar_tt.);
786 pinentrycxx . . $ pinentry..quality_bar_ttcxx . . $ pinentry#quality_bar_tt. = newval;
787 return 0;
788 }
789
790
791 static int
792 cmd_getpincxx . . $ cmd_getpin(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line)
793 {
794 int result;
795 int set_prompt = 0;
796
797 pinentrycxx . . $ pinentry..pincxx . . $ pinentry#pin. = secmem_malloccxx . . $ secmem_malloc(bfcfa4d6b7f7ef64). (pinentrycxx . . $ pinentry..pin_lencxx . . $ pinentry#pin_len.);
798 if (!pinentrycxx . . $ pinentry..pincxx . . $ pinentry#pin.)
799 return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.;
800 if (!pinentrycxx . . $ pinentry..promptcxx . . $ pinentry#prompt.)
801 {
802 pinentrycxx . . $ pinentry..promptcxx . . $ pinentry#prompt. = "PIN:";
803 set_prompt = 1;
804 }
805 pinentrycxx . . $ pinentry..locale_errcxx . . $ pinentry#locale_err. = 0;
806 pinentrycxx . . $ pinentry..one_buttoncxx . . $ pinentry#one_button. = 0;
807 pinentrycxx . . $ pinentry..ctx_assuancxx . . $ pinentry#ctx_assuan. = ctx;
808 result = (*pinentry_cmd_handlercxx . . $ pinentry_cmd_handler.) (&pinentrycxx . . $ pinentry.);
809 pinentrycxx . . $ pinentry..ctx_assuancxx . . $ pinentry#ctx_assuan. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
810 if (pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error.)
811 {
812 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error.);
813 pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
814 }
815 if (set_prompt)
816 pinentrycxx . . $ pinentry..promptcxx . . $ pinentry#prompt. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
817
818 pinentrycxx . . $ pinentry..quality_barcxx . . $ pinentry#quality_bar. = 0; /* Reset it after the command. */
819
820 if (result < 0)
821 {
822 if (pinentrycxx . . $ pinentry..pincxx . . $ pinentry#pin.)
823 {
824 secmem_freecxx . . $ secmem_free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..pincxx . . $ pinentry#pin.);
825 pinentrycxx . . $ pinentry..pincxx . . $ pinentry#pin. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
826 }
827 return pinentrycxx . . $ pinentry..locale_errcxx . . $ pinentry#locale_err.? ASSUAN_Locale_Problemcxx . . $ ASSUAN_Locale_Problem.: ASSUAN_Canceledcxx . . $ ASSUAN_Canceled.;
828 }
829
830 if (result)
831 {
832 result = assuan_send_datacxx . . $ assuan_send_data(7bfc732ed11f6ee8). (ctx, pinentrycxx . . $ pinentry..pincxx . . $ pinentry#pin., result);
833 if (!result)
834 result = assuan_send_datacxx . . $ assuan_send_data(7bfc732ed11f6ee8). (ctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
835 }
836
837 if (pinentrycxx . . $ pinentry..pincxx . . $ pinentry#pin.)
838 {
839 secmem_freecxx . . $ secmem_free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..pincxx . . $ pinentry#pin.);
840 pinentrycxx . . $ pinentry..pincxx . . $ pinentry#pin. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
841 }
842
843 return result;
844 }
845
846
847 /* Note that the option --one-button is hack to allow the use of old
848 pinentries while the caller is ignoring the result. Given that
849 options have never been used or flagged as an error the new option
850 is an easy way to enable the messsage mode while not requiring to
851 update pinentry or to have the caller test for the message
852 command. New applications which are free to require an updated
853 pinentry should use MESSAGE instead. */
854 static int
855 cmd_confirmcxx . . $ cmd_confirm(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line)
856 {
857 int result;
858
859 pinentrycxx . . $ pinentry..one_buttoncxx . . $ pinentry#one_button. = !!strstrcxx . . $ strstr(a713fe7b9a57cf96). (line, "--one-button");
860 pinentrycxx . . $ pinentry..quality_barcxx . . $ pinentry#quality_bar. = 0;
861 pinentrycxx . . $ pinentry..locale_errcxx . . $ pinentry#locale_err. = 0;
862 result = (*pinentry_cmd_handlercxx . . $ pinentry_cmd_handler.) (&pinentrycxx . . $ pinentry.);
863 if (pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error.)
864 {
865 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error.);
866 pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
867 }
868
869 return result ? 0
870 : (pinentrycxx . . $ pinentry..locale_errcxx . . $ pinentry#locale_err.? ASSUAN_Locale_Problemcxx . . $ ASSUAN_Locale_Problem.
871 : (pinentrycxx . . $ pinentry..one_buttoncxx . . $ pinentry#one_button.
872 ? 0
873 : ASSUAN_Not_Confirmedcxx . . $ ASSUAN_Not_Confirmed.));
874 }
875
876
877 static int
878 cmd_messagecxx . . $ cmd_message(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line)
879 {
880 int result;
881
882 pinentrycxx . . $ pinentry..one_buttoncxx . . $ pinentry#one_button. = 1;
883 pinentrycxx . . $ pinentry..quality_barcxx . . $ pinentry#quality_bar. = 0;
884 pinentrycxx . . $ pinentry..locale_errcxx . . $ pinentry#locale_err. = 0;
885 result = (*pinentry_cmd_handlercxx . . $ pinentry_cmd_handler.) (&pinentrycxx . . $ pinentry.);
886 if (pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error.)
887 {
888 freecxx . . $ free(5d22bdacc48458e8). (pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error.);
889 pinentrycxx . . $ pinentry..errorcxx . . $ pinentry#error. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
890 }
891
892 return result ? 0
893 : (pinentrycxx . . $ pinentry..locale_errcxx . . $ pinentry#locale_err.? ASSUAN_Locale_Problemcxx . . $ ASSUAN_Locale_Problem.
894 : 0);
895 }
896
897 /* GETINFO <what>
898
899 Multipurpose function to return a variety of information.
900 Supported values for WHAT are:
901
902 version - Return the version of the program.
903 pid - Return the process id of the server.
904 */
905 static int
906 cmd_getinfocxx . . $ cmd_getinfo(6da50a57b69ceb9e). (assuan_context_tcxx . . $ assuan_context_t# ctx, char *line)
907 {
908 int rc;
909
910 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (line, "version"))
911 {
912 const char *s = VERSIONcxx . . $ `config.h:215:9`!;
913 rc = assuan_send_datacxx . . $ assuan_send_data(7bfc732ed11f6ee8). (ctx, s, strlencxx . . $ strlen(751346f8406fd082). (s));
914 }
915 else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (line, "pid"))
916 {
917 char numbuf[50];
918
919 snprintfcxx . . $ snprintf(ea502d73e74c754c). (numbuf, sizeof numbuf, "%lu", (unsigned long)getpidcxx . . $ getpid(b126dc7c1de90089). ());
920 rc = assuan_send_datacxx . . $ assuan_send_data(7bfc732ed11f6ee8). (ctx, numbuf, strlencxx . . $ strlen(751346f8406fd082). (numbuf));
921 }
922 else
923 rc = ASSUAN_Parameter_Errorcxx . . $ `assuan/assuan.h:70:9`!;
924 return rc;
925 }
926
927
928 /* Tell the assuan library about our commands. */
929 static int
930 register_commandscxx . . $ register_commands(29493cd997091d1). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx)
931 {
932 static structcxx . . $ register_commands(29493cd997091d1).$anonymous_type_1#
933 {
934 const char *namecxx . . $ register_commands(29493cd997091d1).$anonymous_type_1#name.;
935 int cmd_idcxx . . $ register_commands(29493cd997091d1).$anonymous_type_1#cmd_id.;
936 int (*handlercxx . . $ register_commands(29493cd997091d1).$anonymous_type_1#handler.) (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT#, char *line);
937 } table[] =
938 {
939 { "SETDESC", 0, cmd_setdesccxx . . $ cmd_setdesc(6da50a57b69ceb9e). },
940 { "SETPROMPT", 0, cmd_setpromptcxx . . $ cmd_setprompt(6da50a57b69ceb9e). },
941 { "SETERROR", 0, cmd_seterrorcxx . . $ cmd_seterror(6da50a57b69ceb9e). },
942 { "SETOK", 0, cmd_setokcxx . . $ cmd_setok(6da50a57b69ceb9e). },
943 { "SETCANCEL", 0, cmd_setcancelcxx . . $ cmd_setcancel(6da50a57b69ceb9e). },
944 { "GETPIN", 0, cmd_getpincxx . . $ cmd_getpin(6da50a57b69ceb9e). },
945 { "CONFIRM", 0, cmd_confirmcxx . . $ cmd_confirm(6da50a57b69ceb9e). },
946 { "MESSAGE", 0, cmd_messagecxx . . $ cmd_message(6da50a57b69ceb9e). },
947 { "SETQUALITYBAR", 0, cmd_setqualitybarcxx . . $ cmd_setqualitybar(6da50a57b69ceb9e). },
948 { "SETQUALITYBAR_TT", 0, cmd_setqualitybar_ttcxx . . $ cmd_setqualitybar_tt(6da50a57b69ceb9e). },
949 { "GETINFO", 0, cmd_getinfocxx . . $ cmd_getinfo(6da50a57b69ceb9e). },
950 { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! }
951 };
952 int i, j, rc;
953
954 for (i = j = 0; table[i].namecxx . . $ register_commands(29493cd997091d1).$anonymous_type_1#name.; i++)
955 {
956 rc = assuan_register_commandcxx . . $ assuan_register_command(b82481c29d01abcc). (ctx,
957 table[i].cmd_idcxx . . $ register_commands(29493cd997091d1).$anonymous_type_1#cmd_id. ? table[i].cmd_idcxx . . $ register_commands(29493cd997091d1).$anonymous_type_1#cmd_id.
958 : (ASSUAN_CMD_USERcxx . . $ ASSUAN_CMD_USER. + j++),
959 table[i].namecxx . . $ register_commands(29493cd997091d1).$anonymous_type_1#name., table[i].handlercxx . . $ register_commands(29493cd997091d1).$anonymous_type_1#handler.);
960 if (rc)
961 return rc;
962 }
963 return 0;
964 }
965
966
967 /* Start the pinentry event loop. The program will start to process
968 Assuan commands until it is finished or an error occurs. If an
969 error occurs, -1 is returned. Otherwise, 0 is returned. */
970 int
971 pinentry_loopcxx . . $ pinentry_loop(b126dc7c1de90089). (void)
972 {
973 int rc;
974 int filedes[2];
975 ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx;
976
977 /* Extra check to make sure we have dropped privs. */
978 #ifndef HAVE_DOSISH_SYSTEM
979 if (getuidcxx . . $ getuid(db52760e79bf9054).() != geteuidcxx . . $ geteuid(db52760e79bf9054).())
980 abortcxx . . $ abort(8df32a62017fbbf6). ();
981 #endif
982
983 /* For now we use a simple pipe based server so that we can work
984 from scripts. We will later add options to run as a daemon and
985 wait for requests on a Unix domain socket. */
986 filedes[0] = 0;
987 filedes[1] = 1;
988 rc = assuan_init_pipe_servercxx . . $ assuan_init_pipe_server(93ea0ddd021a766c). (&ctx, filedes);
989 if (rc)
990 {
991 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: failed to initialize the server: %s\n",
992 this_pgmnamecxx . . $ this_pgmname., assuan_strerrorcxx . . $ assuan_strerror(fffa0a52a4999444).(rc));
993 return -1;
994 }
995 rc = register_commandscxx . . $ register_commands(29493cd997091d1). (ctx);
996 if (rc)
997 {
998 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: failed to the register commands with Assuan: %s\n",
999 this_pgmnamecxx . . $ this_pgmname., assuan_strerrorcxx . . $ assuan_strerror(fffa0a52a4999444).(rc));
1000 return -1;
1001 }
1002
1003 assuan_register_option_handlercxx . . $ assuan_register_option_handler(fcbcb73ed245437a). (ctx, option_handlercxx . . $ option_handler(7d4a227c335102d2).);
1004 #if 0
1005 assuan_set_log_stream (ctx, stderr);
1006 #endif
1007
1008 for (;;)
1009 {
1010 rc = assuan_acceptcxx . . $ assuan_accept(5c60088356380db8). (ctx);
1011 if (rc == -1)
1012 break;
1013 else if (rc)
1014 {
1015 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: Assuan accept problem: %s\n",
1016 this_pgmnamecxx . . $ this_pgmname., assuan_strerrorcxx . . $ assuan_strerror(fffa0a52a4999444). (rc));
1017 break;
1018 }
1019
1020 rc = assuan_processcxx . . $ assuan_process(29493cd997091d1). (ctx);
1021 if (rc)
1022 {
1023 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: Assuan processing failed: %s\n",
1024 this_pgmnamecxx . . $ this_pgmname., assuan_strerrorcxx . . $ assuan_strerror(fffa0a52a4999444). (rc));
1025 continue;
1026 }
1027 }
1028
1029 assuan_deinit_servercxx . . $ assuan_deinit_server(746ddb6f27ff0333). (ctx);
1030 return 0;
1031 }