Blame src/getauditlog.c

Packit Service 672cf4
/* getauditlog.c - Retrieve the audit log.
Packit Service 0ef63b
 * Copyright (C) 2007 g10 Code GmbH
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * This file is part of GPGME.
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * GPGME is free software; you can redistribute it and/or modify it
Packit Service 0ef63b
 * under the terms of the GNU Lesser General Public License as
Packit Service 0ef63b
 * published by the Free Software Foundation; either version 2.1 of
Packit Service 0ef63b
 * the License, or (at your option) any later version.
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * GPGME is distributed in the hope that it will be useful, but
Packit Service 0ef63b
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 0ef63b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 0ef63b
 * Lesser General Public License for more details.
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * You should have received a copy of the GNU Lesser General Public
Packit Service 0ef63b
 * License along with this program; if not, see <https://gnu.org/licenses/>.
Packit Service 0ef63b
 * SPDX-License-Identifier: LGPL-2.1-or-later
Packit Service 672cf4
 */
Packit Service 672cf4
Packit Service 672cf4
#if HAVE_CONFIG_H
Packit Service 672cf4
#include <config.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include "gpgme.h"
Packit Service 672cf4
#include "debug.h"
Packit Service 672cf4
#include "context.h"
Packit Service 672cf4
#include "ops.h"
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
static gpgme_error_t
Packit Service 672cf4
getauditlog_status_handler (void *priv, gpgme_status_code_t code, char *args)
Packit Service 672cf4
{
Packit Service 672cf4
  (void)priv;
Packit Service 672cf4
  (void)code;
Packit Service 672cf4
  (void)args;
Packit Service 672cf4
  return 0;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
static gpgme_error_t
Packit Service 672cf4
getauditlog_start (gpgme_ctx_t ctx, int synchronous,
Packit Service 672cf4
                   gpgme_data_t output, unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
  gpgme_error_t err;
Packit Service 672cf4
Packit Service 672cf4
  if (!output)
Packit Service 672cf4
    return gpg_error (GPG_ERR_INV_VALUE);
Packit Service 672cf4
Packit Service 0ef63b
  if (!(flags & GPGME_AUDITLOG_DIAG))
Packit Service 0ef63b
    {
Packit Service 0ef63b
      err = _gpgme_op_reset (ctx, ((synchronous&255) | 256) );
Packit Service 0ef63b
      if (err)
Packit Service 0ef63b
        return err;
Packit Service 0ef63b
    }
Packit Service 672cf4
Packit Service 672cf4
  _gpgme_engine_set_status_handler (ctx->engine,
Packit Service 672cf4
                                    getauditlog_status_handler, ctx);
Packit Service 672cf4
Packit Service 672cf4
  return _gpgme_engine_op_getauditlog (ctx->engine, output, flags);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
/* Return the auditlog for the current session.  This may be called
Packit Service 672cf4
   after a successful or failed operation.  If no audit log is
Packit Service 672cf4
   available GPG_ERR_NO_DATA is returned.  This is the asynchronous
Packit Service 672cf4
   variant. */
Packit Service 672cf4
gpgme_error_t
Packit Service 672cf4
gpgme_op_getauditlog_start (gpgme_ctx_t ctx,
Packit Service 672cf4
                            gpgme_data_t output, unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
  gpg_error_t err;
Packit Service 0ef63b
  TRACE_BEG  (DEBUG_CTX, "gpgme_op_getauditlog_start", ctx,
Packit Service 672cf4
	      "output=%p, flags=0x%x", output, flags);
Packit Service 672cf4
Packit Service 672cf4
  if (!ctx)
Packit Service 672cf4
    return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
Packit Service 672cf4
Packit Service 672cf4
  err = getauditlog_start (ctx, 0, output, flags);
Packit Service 672cf4
  return TRACE_ERR (err);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
/* Return the auditlog for the current session.  This may be called
Packit Service 672cf4
   after a successful or failed operation.  If no audit log is
Packit Service 672cf4
   available GPG_ERR_NO_DATA is returned.  This is the synchronous
Packit Service 672cf4
   variant. */
Packit Service 672cf4
gpgme_error_t
Packit Service 672cf4
gpgme_op_getauditlog (gpgme_ctx_t ctx, gpgme_data_t output, unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
  gpgme_error_t err;
Packit Service 672cf4
Packit Service 0ef63b
  TRACE_BEG  (DEBUG_CTX, "gpgme_op_getauditlog", ctx,
Packit Service 672cf4
	      "output=%p, flags=0x%x", output, flags);
Packit Service 672cf4
Packit Service 672cf4
  if (!ctx)
Packit Service 672cf4
    return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
Packit Service 672cf4
Packit Service 672cf4
  err = getauditlog_start (ctx, 1, output, flags);
Packit Service 672cf4
  if (!err)
Packit Service 672cf4
    err = _gpgme_wait_one (ctx);
Packit Service 672cf4
  return TRACE_ERR (err);
Packit Service 672cf4
}
Packit Service 672cf4