~evarlast/ubuntu/trusty/mongodb/upstart-workaround-debian-bug-718702

« back to all changes in this revision

Viewing changes to src/mongo/client/sasl_client_session.h

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-07 13:21:03 UTC
  • mfrom: (44.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130807132103-5ch290okdlzg9u9y
Tags: 1:2.4.5-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Enable SSL support:
    + d/control: Add libssl-dev to BD's.
    + d/rules: Enabled --ssl option.
    + d/mongodb.conf: Add example SSL configuration options.
  - d/mongodb-server.mongodb.upstart: Add upstart configuration.
  - d/rules: Don't strip binaries during scons build for Ubuntu.
  - d/control: Add armhf to target archs.
  - d/p/0008-ignore-unused-local-typedefs.patch: Add -Wno-unused-typedefs
    to unbreak building with g++-4.8.
  - d/p/0009-boost-1.53.patch: Fixup signed/unsigned casting issue.
  - d/p/0010-install-libs-to-usr-lib-not-usr-lib64-Closes-588557.patch:
    Install libraries to lib not lib64.
  - d/p/0011-Use-a-signed-char-to-store-BSONType-enumerations.patch: Fixup
    build failure on ARM due to missing signed'ness of char cast.
* Dropped changes, no longer required:
  - d/p/SConscript.client.patch: fixup install of client libraries.
* d/rules,control: Switch back to using gcc/g++ 4.8 as we have appropriate
  fixes in the Ubuntu delta.
* d/mongodb-server.mongodb.upstart: Sync changes from upstream packaging
  upstart configuration, specifically;
  - increase nofile limits to 20000/20000.
  - wait 300s between SIGTERM and SIGKILL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
25
namespace mongo {
 
26
 
 
27
    /**
 
28
     * Implementation of the client side of a SASL authentication conversation.
 
29
     *
 
30
     * To use, create an instance, then use setParameter() to configure the authentication
 
31
     * parameters.  Once all parameters are set, call initialize() to initialize the client state
 
32
     * machine.  Finally, use repeated calls to step() to generate messages to send to the server
 
33
     * and process server responses.
 
34
     *
 
35
     * The required parameters vary by mechanism, but all mechanisms require parameterServiceName,
 
36
     * parameterServiceHostname, parameterMechanism and parameterUser.  All of the required
 
37
     * parameters must be UTF-8 encoded strings with no embedded NUL characters.  The
 
38
     * parameterPassword parameter is not constrained.
 
39
     */
 
40
    class SaslClientSession {
 
41
        MONGO_DISALLOW_COPYING(SaslClientSession);
 
42
    public:
 
43
        /**
 
44
         * Identifiers of parameters used to configure a SaslClientSession.
 
45
         */
 
46
        enum Parameter {
 
47
            parameterServiceName = 0,
 
48
            parameterServiceHostname,
 
49
            parameterMechanism,
 
50
            parameterUser,
 
51
            parameterPassword,
 
52
            numParameters  // Must be last
 
53
        };
 
54
 
 
55
        SaslClientSession();
 
56
        ~SaslClientSession();
 
57
 
 
58
        /**
 
59
         * Sets the parameter identified by "id" to "value".
 
60
         *
 
61
         * The value of "id" must be one of the legal values of Parameter less than numParameters.
 
62
         * May be called repeatedly for the same value of "id", with the last "value" replacing
 
63
         * previous values.
 
64
         *
 
65
         * The session object makes and owns a copy of the data in "value".
 
66
         */
 
67
        void setParameter(Parameter id, const StringData& value);
 
68
 
 
69
        /**
 
70
         * Returns true if "id" identifies a parameter previously set by a call to setParameter().
 
71
         */
 
72
        bool hasParameter(Parameter id);
 
73
 
 
74
        /**
 
75
         * Returns the value of a previously set parameter.
 
76
         *
 
77
         * If parameter "id" was never set, returns an empty StringData.  Note that a parameter may
 
78
         * be explicitly set to StringData(), so use hasParameter() to distinguish those cases.
 
79
         *
 
80
         * The session object owns the storage behind the returned StringData, which will remain
 
81
         * valid until setParameter() is called with the same value of "id", or the session object
 
82
         * goes out of scope.
 
83
         */
 
84
        StringData getParameter(Parameter id);
 
85
 
 
86
        /**
 
87
         * Returns the value of the parameterPassword parameter in the form of a sasl_secret_t, used
 
88
         * by the Cyrus SASL library's SASL_CB_PASS callback.  The session object owns the storage
 
89
         * referenced by the returned sasl_secret_t*, which will remain in scope according to the
 
90
         * same rules as given for getParameter(), above.
 
91
         */
 
92
        sasl_secret_t* getPasswordAsSecret();
 
93
 
 
94
        /**
 
95
         * Initializes a session for use.
 
96
         *
 
97
         * Call exactly once, after setting any parameters you intend to set via setParameter().
 
98
         */
 
99
        Status initialize();
 
100
 
 
101
        /**
 
102
         * Takes one step of the SASL protocol on behalf of the client.
 
103
         *
 
104
         * Caller should provide data from the server side of the conversation in "inputData", or an
 
105
         * empty StringData() if none is available.  If the client should make a response to the
 
106
         * server, stores the response into "*outputData".
 
107
         *
 
108
         * Returns Status::OK() on success.  Any other return value indicates a failed
 
109
         * authentication, though the specific return value may provide insight into the cause of
 
110
         * the failure (e.g., ProtocolError, AuthenticationFailed).
 
111
         *
 
112
         * In the event that this method returns Status::OK(), consult the value of isDone() to
 
113
         * determine if the conversation has completed.  When step() returns Status::OK() and
 
114
         * isDone() returns true, authentication has completed successfully.
 
115
         */
 
116
        Status step(const StringData& inputData, std::string* outputData);
 
117
 
 
118
        /**
 
119
         * Returns true if the authentication completed successfully.
 
120
         */
 
121
        bool isDone() const { return _done; }
 
122
 
 
123
    private:
 
124
        /**
 
125
         * Buffer object that owns data for a single parameter.
 
126
         */
 
127
        struct DataBuffer {
 
128
            boost::scoped_array<char> data;
 
129
            size_t size;
 
130
        };
 
131
 
 
132
        /// Maximum number of Cyrus SASL callbacks stored in _callbacks.
 
133
        static const int maxCallbacks = 4;
 
134
 
 
135
        /// Underlying Cyrus SASL library connection object.
 
136
        sasl_conn_t* _saslConnection;
 
137
 
 
138
        /// Callbacks registered on _saslConnection for providing the Cyrus SASL library with
 
139
        /// parameter values, etc.
 
140
        sasl_callback_t _callbacks[maxCallbacks];
 
141
 
 
142
        /// Buffers for each of the settable parameters.
 
143
        DataBuffer _parameters[numParameters];
 
144
 
 
145
        /// Number of successfully completed conversation steps.
 
146
        int _step;
 
147
 
 
148
        /// See isDone().
 
149
        bool _done;
 
150
    };
 
151
 
 
152
}  // namespace mongo