Add Janet copyright to GSS command files.
[gssweb.git] / json_gssapi / src / commands / GSSImportName.cpp
1 /*
2  * Copyright (c) 2014, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #include "GSSImportName.h"
36 #include "GSSException.h"
37 #include <cache/GSSNameCache.h>
38 #include <datamodel/GSSDisplayStatus.h>
39
40
41 typedef OM_uint32 (*gss_imp_name_type)(
42     OM_uint32 *,        /* minor_status */
43     gss_buffer_t,       /* input_name_buffer */
44     gss_OID,            /* input_name_type(used to be const) */
45     gss_name_t *);      /* output_name */
46
47
48
49 void GSSImportName::execute()
50 {
51   /* Variables */
52   gss_name_t name;
53   std::string key;
54
55   /* Error checking */
56   /* Setup */
57
58   /* Main */
59   retVal = function(&minor_status, inputName.toGss(), inputNameType.toGss(), &name);
60 //   if ( GSS_ERROR(this->retVal) )
61 //   {
62     JSONObject errors;
63     GSSDisplayStatus ds(retVal, minor_status, inputNameType.toGss());
64     errors.set("major_status_message", ds.getMajorMessage().c_str());
65     errors.set("minor_status_message", ds.getMinorMessage().c_str());
66     values->set("errors", errors);
67 //   }
68   
69   
70   
71   this->outputName.setValue(name);
72   key = GSSNameCache::instance()->store(this->outputName);
73 //   std::cout << "Storing key: " << key << std::endl;
74   this->outputName.setKey(key);
75   /* Cleanup */
76   /* Return */
77   
78 }
79
80 /* Example output:
81  * 
82  *   {
83  *     "major_status": 0,
84  *     "minor_status": 0,
85  *     "gss_name": "base64_encoded_string"
86  *   }
87  * 
88  */
89 JSONObject *GSSImportName::toJSON()
90 {
91   /* Variables */
92   /* Error checking */
93   
94   /* Setup */
95   
96   /* Main */
97   values->set("major_status", this->retVal);
98   values->set("minor_status", this->minor_status);
99   values->set("gss_name", this->outputName.getKey().c_str() );
100   
101   /* Cleanup */
102   
103   /* Return */
104   return(values);
105 }
106
107 GSSImportName::GSSImportName ( gss_imp_name_type fn )
108 {
109   // defaults
110   function = fn;
111   inputName = string("");
112   inputNameType.setValue(GSSBuffer( string("{ 1 2 840 113554 1 2 1 4 }") ));
113   values = new JSONObject();
114 }
115
116 GSSImportName::GSSImportName(JSONObject *params, gss_imp_name_type fn) : GSSCommand(params)
117 {
118   /* Variables */
119   /* Error checking */
120   /* Setup */
121   /* Main */
122   values = new JSONObject();
123   loadParameters(params);
124   function = fn;
125   /* Cleanup */
126   /* Return */
127   
128 }
129
130 bool GSSImportName::loadParameters(JSONObject *params)
131 {
132   /* Variables */
133   
134   /* Error checking */
135   /* Setup */
136   // Should I zeroOut?
137   
138   /* Main processing */
139   // Easy stuff(*params)
140   if ( params->isNull() )
141     return true;
142   
143   if ( !params->get("input_name").isNull() )
144   {
145     if ( params->get("input_name").isString() )
146     {
147       std::string input_name = params->get("input_name").string();
148       this->inputName.setValue( input_name );
149     }
150   }
151   
152   if ( !params->get("input_name_type").isNull() )
153   {
154     if ( params->get("input_name_type").isString() )
155     {
156       std::string input_name_type = params->get("input_name_type").string();
157       this->inputNameType.setValue( input_name_type );
158     }
159   }
160   
161   /* Cleanup */
162   /* Return */
163   return true;
164 }
165
166
167
168
169 /* Variables */
170 /* Error checking */
171 /* Setup */
172 /* Main */
173 /* Cleanup */
174 /* Return */