MongoDB  2.7.0
sasl_client_session.h
1 /* Copyright 2012 10gen Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <boost/scoped_array.hpp>
17 #include <sasl/sasl.h>
18 #include <string>
19 #include <vector>
20 
21 #include "mongo/base/disallow_copying.h"
22 #include "mongo/base/status.h"
23 #include "mongo/base/string_data.h"
24 #include "mongo/client/export_macros.h"
25 
26 namespace mongo {
27 
41  class MONGO_CLIENT_API SaslClientSession {
42  MONGO_DISALLOW_COPYING(SaslClientSession);
43  public:
47  enum Parameter {
48  parameterServiceName = 0,
49  parameterServiceHostname,
50  parameterMechanism,
51  parameterUser,
52  parameterPassword,
53  numParameters // Must be last
54  };
55 
58 
68  void setParameter(Parameter id, const StringData& value);
69 
73  bool hasParameter(Parameter id);
74 
85  StringData getParameter(Parameter id);
86 
93  sasl_secret_t* getPasswordAsSecret();
94 
100  Status initialize();
101 
117  Status step(const StringData& inputData, std::string* outputData);
118 
122  bool isDone() const { return _done; }
123 
124  private:
128  struct DataBuffer {
129  boost::scoped_array<char> data;
130  size_t size;
131  };
132 
134  static const int maxCallbacks = 4;
135 
137  sasl_conn_t* _saslConnection;
138 
141  sasl_callback_t _callbacks[maxCallbacks];
142 
144  DataBuffer _parameters[numParameters];
145 
147  int _step;
148 
150  bool _done;
151  };
152 
153 } // namespace mongo
bool isDone() const
Returns true if the authentication completed successfully.
Definition: sasl_client_session.h:122
Parameter
Identifiers of parameters used to configure a SaslClientSession.
Definition: sasl_client_session.h:47
Implementation of the client side of a SASL authentication conversation.
Definition: sasl_client_session.h:41