[27435] in CVS-changelog-for-Kerberos-V5

home help back first fref pref prev next nref lref last post

krb5 commit: Add functions to save and restore error state

daemon@ATHENA.MIT.EDU (Greg Hudson)
Wed Dec 19 12:55:55 2012

Date: Wed, 19 Dec 2012 12:55:38 -0500
From: Greg Hudson <ghudson@mit.edu>
Message-Id: <201212191755.qBJHtc06026052@drugstore.mit.edu>
To: cvs-krb5@mit.edu
Reply-To: krbdev@mit.edu
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cvs-krb5-bounces@mit.edu

https://github.com/krb5/krb5/commit/26245eed626245255c980efdfe69ca1f65186338
commit 26245eed626245255c980efdfe69ca1f65186338
Author: Greg Hudson <ghudson@mit.edu>
Date:   Sun Oct 21 00:49:05 2012 -0400

    Add functions to save and restore error state

 src/include/k5-err.h         |    1 +
 src/lib/krb5/krb/int-proto.h |    8 ++++++++
 src/lib/krb5/krb/kerrs.c     |   29 +++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/include/k5-err.h b/src/include/k5-err.h
index d6d4bbf..083dee4 100644
--- a/src/include/k5-err.h
+++ b/src/include/k5-err.h
@@ -46,6 +46,7 @@ struct errinfo {
     long code;
     char *msg;
 };
+#define EMPTY_ERRINFO { 0, NULL }
 
 void k5_set_error(struct errinfo *ep, long code, const char *fmt, ...)
 #if !defined(__cplusplus) && (__GNUC__ > 2)
diff --git a/src/lib/krb5/krb/int-proto.h b/src/lib/krb5/krb/int-proto.h
index 6f3de8f..a452915 100644
--- a/src/lib/krb5/krb/int-proto.h
+++ b/src/lib/krb5/krb/int-proto.h
@@ -234,4 +234,12 @@ const char *
 k5_response_items_get_answer(const k5_response_items *ri,
                              const char *question);
 
+/* Save code and its extended message (if any) in out. */
+void
+k5_save_ctx_error(krb5_context ctx, krb5_error_code code, struct errinfo *out);
+
+/* Return the code from in and restore its extended message (if any). */
+krb5_error_code
+k5_restore_ctx_error(krb5_context ctx, struct errinfo *in);
+
 #endif /* KRB5_INT_FUNC_PROTO__ */
diff --git a/src/lib/krb5/krb/kerrs.c b/src/lib/krb5/krb/kerrs.c
index 416cb77..99db926 100644
--- a/src/lib/krb5/krb/kerrs.c
+++ b/src/lib/krb5/krb/kerrs.c
@@ -26,6 +26,7 @@
 
 #include <stdarg.h>
 #include "k5-int.h"
+#include "int-proto.h"
 
 #ifdef DEBUG
 static int error_message_debug = 0;
@@ -151,3 +152,31 @@ krb5_clear_error_message(krb5_context ctx)
         return;
     k5_clear_error(&ctx->err);
 }
+
+void
+k5_save_ctx_error(krb5_context ctx, krb5_error_code code, struct errinfo *out)
+{
+    out->code = code;
+    out->msg = NULL;
+    if (ctx != NULL && ctx->err.code == code) {
+        out->msg = ctx->err.msg;
+        ctx->err.code = 0;
+        ctx->err.msg = NULL;
+    }
+}
+
+krb5_error_code
+k5_restore_ctx_error(krb5_context ctx, struct errinfo *in)
+{
+    krb5_error_code code = in->code;
+
+    if (ctx != NULL) {
+        k5_clear_error(&ctx->err);
+        ctx->err.code = in->code;
+        ctx->err.msg = in->msg;
+        in->msg = NULL;
+    } else {
+        k5_clear_error(in);
+    }
+    return code;
+}
_______________________________________________
cvs-krb5 mailing list
cvs-krb5@mit.edu
https://mailman.mit.edu/mailman/listinfo/cvs-krb5

home help back first fref pref prev next nref lref last post