chiark / gitweb /
Replace use of variable-length-arrays.
[gnupg2.git] / scd / scdaemon.h
1 /* scdaemon.h - Global definitions for the SCdaemon
2  *      Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuPG.
5  *
6  * GnuPG is free software; you can redistribute it and/or modify
7  * it 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  * GnuPG is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU 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 <https://www.gnu.org/licenses/>.
18  */
19
20 #ifndef SCDAEMON_H
21 #define SCDAEMON_H
22
23 #ifdef GPG_ERR_SOURCE_DEFAULT
24 #error GPG_ERR_SOURCE_DEFAULT already defined
25 #endif
26 #define GPG_ERR_SOURCE_DEFAULT  GPG_ERR_SOURCE_SCD
27 #include <gpg-error.h>
28
29 #include <time.h>
30 #include <gcrypt.h>
31 #include "../common/util.h"
32 #include "../common/sysutils.h"
33
34 /* To convey some special hash algorithms we use algorithm numbers
35    reserved for application use. */
36 #ifndef GCRY_MODULE_ID_USER
37 #define GCRY_MODULE_ID_USER 1024
38 #endif
39 #define MD_USER_TLS_MD5SHA1 (GCRY_MODULE_ID_USER+1)
40
41 /* Maximum length of a digest.  */
42 #define MAX_DIGEST_LEN 64
43
44
45
46 /* A large struct name "opt" to keep global flags. */
47 struct
48 {
49   unsigned int debug; /* Debug flags (DBG_foo_VALUE). */
50   int verbose;        /* Verbosity level. */
51   int quiet;          /* Be as quiet as possible. */
52   int dry_run;        /* Don't change any persistent data. */
53   int batch;          /* Batch mode. */
54   const char *ctapi_driver; /* Library to access the ctAPI. */
55   const char *pcsc_driver;  /* Library to access the PC/SC system. */
56   const char *reader_port;  /* NULL or reder port to use. */
57   int disable_ccid;    /* Disable the use of the internal CCID driver. */
58   int disable_pinpad;  /* Do not use a pinpad. */
59   int enable_pinpad_varlen;  /* Use variable length input for pinpad. */
60   int allow_admin;     /* Allow the use of admin commands for certain
61                           cards. */
62   strlist_t disabled_applications;  /* Card applications we do not
63                                        want to use. */
64   unsigned long card_timeout; /* Disconnect after N seconds of inactivity.  */
65 } opt;
66
67
68 #define DBG_MPI_VALUE     2     /* debug mpi details */
69 #define DBG_CRYPTO_VALUE  4     /* debug low level crypto */
70 #define DBG_MEMORY_VALUE  32    /* debug memory allocation stuff */
71 #define DBG_CACHE_VALUE   64    /* debug the caching */
72 #define DBG_MEMSTAT_VALUE 128   /* show memory statistics */
73 #define DBG_HASHING_VALUE 512   /* debug hashing operations */
74 #define DBG_IPC_VALUE     1024
75 #define DBG_CARD_IO_VALUE 2048
76 #define DBG_READER_VALUE  4096  /* Trace reader related functions.  */
77
78 #define DBG_CRYPTO  (opt.debug & DBG_CRYPTO_VALUE)
79 #define DBG_MEMORY  (opt.debug & DBG_MEMORY_VALUE)
80 #define DBG_CACHE   (opt.debug & DBG_CACHE_VALUE)
81 #define DBG_HASHING (opt.debug & DBG_HASHING_VALUE)
82 #define DBG_IPC     (opt.debug & DBG_IPC_VALUE)
83 #define DBG_CARD_IO (opt.debug & DBG_CARD_IO_VALUE)
84 #define DBG_READER  (opt.debug & DBG_READER_VALUE)
85
86 struct server_local_s;
87 struct app_ctx_s;
88
89 struct server_control_s
90 {
91   /* Private data used to fire up the connection thread.  We use this
92      structure do avoid an extra allocation for just a few bytes. */
93   struct {
94     gnupg_fd_t fd;
95   } thread_startup;
96
97   /* Local data of the server; used only in command.c. */
98   struct server_local_s *server_local;
99
100   /* The application context used with this connection or NULL if none
101      associated.  Note that this is shared with the other connections:
102      All connections accessing the same reader are using the same
103      application context. */
104   struct app_ctx_s *app_ctx;
105
106   /* Helper to store the value we are going to sign */
107   struct
108   {
109     unsigned char *value;
110     int valuelen;
111   } in_data;
112 };
113
114 typedef struct app_ctx_s *app_t;
115
116 /*-- scdaemon.c --*/
117 void scd_exit (int rc);
118 const char *scd_get_socket_name (void);
119
120 /*-- command.c --*/
121 void initialize_module_command (void);
122 int  scd_command_handler (ctrl_t, int);
123 void send_status_info (ctrl_t ctrl, const char *keyword, ...)
124      GPGRT_ATTR_SENTINEL(1);
125 void send_status_direct (ctrl_t ctrl, const char *keyword, const char *args);
126 void scd_update_reader_status_file (void);
127
128
129 #endif /*SCDAEMON_H*/