Line data Source code
1 :
2 : /* getauditlog.c - Retrieve the audit log.
3 : Copyright (C) 2007 g10 Code GmbH
4 :
5 : This file is part of GPGME.
6 :
7 : GPGME is free software; you can redistribute it and/or modify it
8 : under the terms of the GNU Lesser General Public License as
9 : published by the Free Software Foundation; either version 2.1 of
10 : the License, or (at your option) any later version.
11 :
12 : GPGME is distributed in the hope that it will be useful, but
13 : WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : Lesser General Public License for more details.
16 :
17 : You should have received a copy of the GNU Lesser General Public
18 : License along with this program; if not, see <https://www.gnu.org/licenses/>.
19 : */
20 :
21 : #if HAVE_CONFIG_H
22 : #include <config.h>
23 : #endif
24 :
25 : #include "gpgme.h"
26 : #include "debug.h"
27 : #include "context.h"
28 : #include "ops.h"
29 :
30 :
31 : static gpgme_error_t
32 2 : getauditlog_status_handler (void *priv, gpgme_status_code_t code, char *args)
33 : {
34 : (void)priv;
35 : (void)code;
36 : (void)args;
37 2 : return 0;
38 : }
39 :
40 :
41 : static gpgme_error_t
42 25 : getauditlog_start (gpgme_ctx_t ctx, int synchronous,
43 : gpgme_data_t output, unsigned int flags)
44 : {
45 : gpgme_error_t err;
46 :
47 25 : if (!output)
48 0 : return gpg_error (GPG_ERR_INV_VALUE);
49 :
50 25 : err = _gpgme_op_reset (ctx, ((synchronous&255) | 256) );
51 25 : if (err)
52 0 : return err;
53 :
54 25 : _gpgme_engine_set_status_handler (ctx->engine,
55 : getauditlog_status_handler, ctx);
56 :
57 25 : return _gpgme_engine_op_getauditlog (ctx->engine, output, flags);
58 : }
59 :
60 :
61 :
62 : /* Return the auditlog for the current session. This may be called
63 : after a successful or failed operation. If no audit log is
64 : available GPG_ERR_NO_DATA is returned. This is the asynchronous
65 : variant. */
66 : gpgme_error_t
67 0 : gpgme_op_getauditlog_start (gpgme_ctx_t ctx,
68 : gpgme_data_t output, unsigned int flags)
69 : {
70 : gpg_error_t err;
71 0 : TRACE_BEG2 (DEBUG_CTX, "gpgme_op_getauditlog_start", ctx,
72 : "output=%p, flags=0x%x", output, flags);
73 :
74 0 : if (!ctx)
75 0 : return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
76 :
77 0 : err = getauditlog_start (ctx, 0, output, flags);
78 0 : return TRACE_ERR (err);
79 : }
80 :
81 :
82 : /* Return the auditlog for the current session. This may be called
83 : after a successful or failed operation. If no audit log is
84 : available GPG_ERR_NO_DATA is returned. This is the synchronous
85 : variant. */
86 : gpgme_error_t
87 25 : gpgme_op_getauditlog (gpgme_ctx_t ctx, gpgme_data_t output, unsigned int flags)
88 : {
89 : gpgme_error_t err;
90 :
91 25 : TRACE_BEG2 (DEBUG_CTX, "gpgme_op_getauditlog", ctx,
92 : "output=%p, flags=0x%x", output, flags);
93 :
94 25 : if (!ctx)
95 0 : return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
96 :
97 25 : err = getauditlog_start (ctx, 1, output, flags);
98 25 : if (!err)
99 2 : err = _gpgme_wait_one (ctx);
100 25 : return TRACE_ERR (err);
101 : }
102 :
|