982033d735f657ba4088ea5e1011397392fb8433
[gssweb.git] / json_gssapi / src / datamodel / GSSContext.cpp
1 /*
2  * Copyright (c) 2014 <copyright holder> <email>
3  *
4  * For license details, see the LICENSE file in the root of this project.
5  *
6  */
7
8 #include "GSSContext.h"
9 #include "GSSException.h"
10
11 #include <gssapi/gssapi.h>
12
13 GSSContext::GSSContext()
14 {
15   skipRelease = false;
16   context = GSS_C_NO_CONTEXT;
17 }
18
19 GSSContext::GSSContext ( const GSSContext& other )
20 {
21   // Variables
22   // Error checking
23   // Setup
24   // Main
25   skipRelease = true;
26   this->context = other.context;
27   // Cleanup
28   // Return
29
30 }
31
32 GSSContext::~GSSContext()
33 {
34   // Variables
35   GSSBuffer output;
36   // Error checking
37   // Setup
38   // Main
39   release(&output);
40
41   // Cleanup
42   // Would love to do something useful with outputToken, but in a destructor that's
43   // not particularly meaningful.
44   // Return
45 }
46
47 void GSSContext::setContext ( gss_ctx_id_t ctxt, bool skipRelease )
48 {
49   context = ctxt; 
50   this->skipRelease = skipRelease;
51 }
52
53
54 GSSContext& GSSContext::operator= ( const GSSContext& other )
55 {
56   this->context = other.context;
57   this->skipRelease = true;
58   
59   return *this;
60 }
61
62 void GSSContext::release(GSSBuffer *output)
63 {
64   // Variables
65   gss_buffer_desc outputToken;
66   OM_uint32 major, minor;
67   
68   // Error checking
69   if (GSS_C_NO_CONTEXT == context || skipRelease)
70     return;
71   
72   // Setup
73
74   // Main
75   major = gss_delete_sec_context(&minor, &context, &outputToken);
76   if (GSS_ERROR(major))
77   {
78     throw GSSException("Error in releasing a GSS context", major, minor);
79   }
80
81   output->setValue(&outputToken);
82   
83   // Cleanup
84   // Return
85 }
86
87
88   // Variables
89   // Error checking
90   // Setup
91   // Main
92   // Cleanup
93   // Return