]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add functions to save and restore error state
authorGreg Hudson <ghudson@mit.edu>
Sun, 21 Oct 2012 04:49:05 +0000 (00:49 -0400)
committerGreg Hudson <ghudson@mit.edu>
Wed, 19 Dec 2012 17:45:11 +0000 (12:45 -0500)
src/include/k5-err.h
src/lib/krb5/krb/int-proto.h
src/lib/krb5/krb/kerrs.c

index d6d4bbff5f592fbb3e89177690951ac6d960e09b..083dee4a293db5f2a8e16bf4414917faf92e55a6 100644 (file)
@@ -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)
index 6f3de8f3459553e50cfde4be71aee602dca480b5..a4529155177505d7066fdd2057324bd453c786a7 100644 (file)
@@ -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__ */
index 416cb77187d8332af2737027c8446e643bf95b13..99db9267471754c54775c46bc0158a3d0a2cb985 100644 (file)
@@ -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;
+}