Debian Codegraph @

src/pam/auth-support/wait-for-card.c

raw symbols SCIP
1 /* wait-for-card.c - Waiting for smartcard insertion (Poldi)
2 Copyright (C) 2004, 2005, 2007, 2008 g10 Code GmbH
3
4 This file is part of Poldi.
5
6 Poldi 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 3 of the License, or
9 (at your option) any later version.
10
11 Poldi 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
18 <http://www.gnu.org/licenses/>. */
19
20 #include <config.h>cxx . . $ `<file>/config.h`/
21
22 #include <gpg-error.h>
23 #include <time.h>
24
25 #include "scd.h"cxx . . $ `<file>/src/scd/scd.h`/
26
27
28
29 /* Wait for insertion of a card in slot specified by SLOT,
30 communication with the user through the PAM conversation function
31 CONV.
32
33 Returns proper error code. */
34 gpg_error_tcxx . . $ gpg_error_t#
35 wait_for_cardcxx . . $ wait_for_card(a48b6dfb027d77a2). (scd_context_tcxx . . $ scd_context_t# ctx, unsigned int timeout)
36 {
37 gpg_error_tcxx . . $ gpg_error_t# err; /* <- rc? */
38 time_tcxx . . $ time_t# t0;
39 time_tcxx . . $ time_t# t;
40
41 if (timeout)
42 timecxx . . $ time(7f38134db6521d23). (&t0);
43
44 err = 0;
45
46 while (1)
47 {
48 err = scd_serialnocxx . . $ scd_serialno(8fbe1a4b844610be). (ctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
49
50 if (err == 0)
51 /* Card present! */
52 break;
53 else if (gpg_err_codecxx . . $ gpg_err_code(3a8eb0b02ee1fc1a). (err) == GPG_ERR_CARD_NOT_PRESENTcxx . . $ GPG_ERR_CARD_NOT_PRESENT.)
54
55 {
56 /* Card not present. */
57
58 /* FIXME: are there error codes besides
59 GPG_ERR_CARD_NOT_PRESENT, which can be thrown in case a
60 smartcard is not currently inserted? */
61
62 #ifdef HAVE_NANOSLEEPcxx . . $ `config.h:40:9`!
63 {
64 /* Wait 500ms. */
65 struct timespeccxx . . $ timespec# augenblick;
66
67 augenblick.tv_seccxx . . $ timespec#tv_sec. = 0;
68 augenblick.tv_nseccxx . . $ timespec#tv_nsec. = 500000000;
69 nanosleepcxx . . $ nanosleep(645c6fc2576d4126). (&augenblick, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
70 }
71 #else
72 sleep (1);
73 #endif
74
75 if (timeout)
76 {
77 timecxx . . $ time(7f38134db6521d23). (&t);
78 if ((t - t0) > timeout)
79 {
80 err = GPG_ERR_CARD_NOT_PRESENTcxx . . $ GPG_ERR_CARD_NOT_PRESENT.;
81 break;
82 }
83 }
84 }
85 else
86 /* Unexpected different error -> stop waiting and propagate
87 error upwards. */
88 break;
89 }
90
91 return err;
92 }