Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TSaslClientTransport.cpp
Go to the documentation of this file.
1 // This file will be removed when the code is accepted into the Thrift library.
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  */
20 
21 #include "config.h"
22 #ifdef HAVE_SASL_SASL_H
23 #include <stdint.h>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/scoped_ptr.hpp>
26 
27 #include <thrift/transport/TBufferTransports.h>
30 
31 using namespace sasl;
32 
33 namespace apache { namespace thrift { namespace transport {
34 
35 TSaslClientTransport::TSaslClientTransport(boost::shared_ptr<sasl::TSasl> saslClient,
36  boost::shared_ptr<TTransport> transport)
37  : TSaslTransport(saslClient, transport) {
38 }
39 
41 
42  uint32_t resLength = 0;
43  uint8_t dummy = 0;
44  uint8_t *initialResponse = &dummy;
45 
46  /* Get data to send to the server if the client goes first. */
47  if (sasl_->hasInitialResponse()) {
48  initialResponse = sasl_->evaluateChallengeOrResponse(NULL, 0, &resLength);
49  }
50 
51  /* These two calls comprise a single message in the thrift-sasl protocol. */
53  (uint8_t*)sasl_->getMechanismName().c_str(),
54  sasl_->getMechanismName().length(), false);
55  sendSaslMessage(TSASL_OK, initialResponse, resLength);
56 
57  transport_->flush();
58 }
59 }}}
60 
61 #endif
void sendSaslMessage(const NegotiationStatus status, const uint8_t *payload, const uint32_t length, bool flush=true)
virtual void handleSaslStartMessage()
Handle any startup messages.
boost::shared_ptr< sasl::TSasl > sasl_
boost::shared_ptr< TTransport > transport_
Underlying transport.