Blame src/getauditlog.c

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