[svn] GnuPG - r4626 - in trunk: common sm
svn author wk
cvs at cvs.gnupg.org
Mon Nov 26 12:00:40 CET 2007
Author: wk
Date: 2007-11-26 12:00:39 +0100 (Mon, 26 Nov 2007)
New Revision: 4626
Modified:
trunk/common/audit.c
trunk/common/audit.h
trunk/sm/ChangeLog
trunk/sm/gpgsm.c
trunk/sm/server.c
Log:
Add option --data to GETAUDITLOG command.
Return HTML formatted dummy output.
Modified: trunk/common/audit.c
===================================================================
--- trunk/common/audit.c 2007-11-22 16:24:21 UTC (rev 4625)
+++ trunk/common/audit.c 2007-11-26 11:00:39 UTC (rev 4626)
@@ -297,18 +297,20 @@
/* Print the formatted audit result. THIS IS WORK IN PROGRESS. */
void
-audit_print_result (audit_ctx_t ctx, FILE *fp)
+audit_print_result (audit_ctx_t ctx, estream_t out)
{
int idx;
int maxlen;
size_t n;
+ es_fputs ("<div class=\"GnuPGAuditLog\">\n", out);
+
if (!ctx)
- return;
+ goto leave;
if (!ctx->log || !ctx->logused)
{
- fprintf (fp, "AUDIT-LOG: No entries\n");
- return;
+ es_fprintf (out, "<p>AUDIT-LOG: No entries</p>\n");
+ goto leave;
}
for (idx=0,maxlen=0; idx < DIM (eventstr_msgidx); idx++)
@@ -318,19 +320,24 @@
maxlen = n;
}
+ es_fputs ("<ul>\n", out);
for (idx=0; idx < ctx->logused; idx++)
{
- fprintf (fp, "AUDIT-LOG[%d]: %-*s",
- idx, maxlen, event2str (ctx->log[idx].event));
+ es_fprintf (out, " <li>%-*s",
+ maxlen, event2str (ctx->log[idx].event));
if (ctx->log[idx].have_intvalue)
- fprintf (fp, " i=%d", ctx->log[idx].intvalue);
+ es_fprintf (out, " i=%d", ctx->log[idx].intvalue);
if (ctx->log[idx].string)
- fprintf (fp, " s=`%s'", ctx->log[idx].string);
+ es_fprintf (out, " s=`%s'", ctx->log[idx].string);
if (ctx->log[idx].cert)
- fprintf (fp, " has_cert");
+ es_fprintf (out, " has_cert");
if (ctx->log[idx].have_err)
- fprintf (fp, " err=\"%s\"", gpg_strerror (ctx->log[idx].err));
- putc ('\n', fp);
+ es_fprintf (out, " err=\"%s\"", gpg_strerror (ctx->log[idx].err));
+ es_fputs ("</li>\n", out);
}
+ es_fputs ("</ul>\n", out);
+
+ leave:
+ es_fputs ("</div>\n", out);
}
Modified: trunk/common/audit.h
===================================================================
--- trunk/common/audit.h 2007-11-22 16:24:21 UTC (rev 4625)
+++ trunk/common/audit.h 2007-11-26 11:00:39 UTC (rev 4626)
@@ -22,6 +22,7 @@
#include <ksba.h>
+#include "estream.h"
struct audit_ctx_s;
typedef struct audit_ctx_s *audit_ctx_t;
@@ -132,7 +133,7 @@
void audit_log_cert (audit_ctx_t ctx, audit_event_t event,
ksba_cert_t cert, gpg_error_t err);
-void audit_print_result (audit_ctx_t ctx, FILE *fp);
+void audit_print_result (audit_ctx_t ctx, estream_t stream);
Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog 2007-11-22 16:24:21 UTC (rev 4625)
+++ trunk/sm/ChangeLog 2007-11-26 11:00:39 UTC (rev 4626)
@@ -1,7 +1,7 @@
-2007-11-22 Werner Koch <wk at g10code.com>
+h2007-11-22 Werner Koch <wk at g10code.com>
* server.c (cmd_getauditlog): New.
- (register_commands): Register GETAUDITLOG
+ (register_commands): Register GETAUDITLOG.
2007-11-19 Werner Koch <wk at g10code.com>
Modified: trunk/sm/gpgsm.c
===================================================================
--- trunk/sm/gpgsm.c 2007-11-22 16:24:21 UTC (rev 4625)
+++ trunk/sm/gpgsm.c 2007-11-26 11:00:39 UTC (rev 4626)
@@ -1649,7 +1649,7 @@
case aVerify:
{
FILE *fp = NULL;
- FILE *auditfp = NULL;
+ estream_t auditfp = NULL;
set_binary (stdin);
if (argc == 2 && opt.outfile)
@@ -1661,7 +1661,7 @@
{
audit_release (ctrl.audit);
ctrl.audit = audit_new ();
- auditfp = open_fwrite (auditlog);
+ auditfp = open_es_fwrite (auditlog);
}
if (!argc)
@@ -1682,8 +1682,7 @@
if (fp && fp != stdout)
fclose (fp);
- if (auditfp && auditfp != stdout)
- fclose (auditfp);
+ es_fclose (auditfp);
}
break;
Modified: trunk/sm/server.c
===================================================================
--- trunk/sm/server.c 2007-11-22 16:24:21 UTC (rev 4625)
+++ trunk/sm/server.c 2007-11-26 11:00:39 UTC (rev 4626)
@@ -934,36 +934,56 @@
-/* GETAUDITLOG
+/* GETAUDITLOG [--data]
!!!WORK in PROGRESS!!!
+
+ If --data is used, the output is send using D-lines and not to the
+ source given by an OUTPUT command.
*/
static int
cmd_getauditlog (assuan_context_t ctx, char *line)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
int out_fd;
- FILE *out_fp;
+ estream_t out_stream;
+ int opt_data;
int rc;
+ opt_data = has_option (line, "--data");
+ line = skip_options (line);
+
if (!ctrl->audit)
return gpg_error (GPG_ERR_NO_DATA);
- out_fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
- if (out_fd == -1)
- return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
-
- out_fp = fdopen ( dup(out_fd), "w");
- if (!out_fp)
+ if (opt_data)
{
- return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed");
+ out_stream = es_fopencookie (ctx, "w", data_line_cookie_functions);
+ if (!out_stream)
+ return set_error (GPG_ERR_ASS_GENERAL,
+ "error setting up a data stream");
}
- audit_print_result (ctrl->audit, out_fp);
+ else
+ {
+ out_fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
+ if (out_fd == -1)
+ return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
+
+ out_stream = es_fdopen_nc ( dup (out_fd), "w");
+ if (!out_stream)
+ {
+ return set_error (GPG_ERR_ASS_GENERAL, "es_fdopen() failed");
+ }
+ }
+
+ audit_print_result (ctrl->audit, out_stream);
rc = 0;
- fclose (out_fp);
+ es_fclose (out_stream);
+
/* Close and reset the fd. */
- assuan_close_output_fd (ctx);
+ if (!opt_data)
+ assuan_close_output_fd (ctx);
return rc;
}
More information about the Gnupg-commits
mailing list