MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
handshake.h
1 /* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15 
16 #ifndef HANDSHAKE_H
17 #define HANDSHAKE_H
18 
19 #include "common.h"
20 
27 #define SSP_NAME "Negotiate"
28 
35 #define MAX_HANDSHAKE_ROUNDS 50
36 
37 
39 
40 class Security_buffer: public SecBufferDesc
41 {
42  SecBuffer m_buf;
43 
44  void init(byte *ptr, size_t len)
45  {
46  ulVersion= 0;
47  cBuffers= 1;
48  pBuffers= &m_buf;
49 
50  m_buf.BufferType= SECBUFFER_TOKEN;
51  m_buf.pvBuffer= ptr;
52  m_buf.cbBuffer= len;
53  }
54 
56  const bool m_allocated;
57 
58  // Copying/assignment is not supported and can lead to memory leaks
59  // So declaring copy constructor and assignment operator as private
61  const Security_buffer& operator=( const Security_buffer& );
62 
63  public:
64 
65  Security_buffer(const Blob&);
67 
69  {
70  free();
71  }
72 
73  byte* ptr() const
74  {
75  return (byte*)m_buf.pvBuffer;
76  }
77 
78  size_t len() const
79  {
80  return m_buf.cbBuffer;
81  }
82 
83  const Blob as_blob() const
84  {
85  return Blob(ptr(), len());
86  }
87 
88  void free(void);
89 };
90 
91 
93 
94 class Handshake
95 {
96 public:
97 
98  typedef enum {CLIENT, SERVER} side_t;
99 
100  Handshake(const char *ssp, side_t side);
101  virtual ~Handshake();
102 
104 
105  bool virtual is_complete() const
106  {
107  return m_complete;
108  }
109 
110  int error() const
111  {
112  return m_error;
113  }
114 
115 protected:
116 
118  CtxtHandle m_sctx;
119 
121  CredHandle m_cred;
122 
124  TimeStamp m_expire;
125 
127  ULONG m_atts;
128 
134  unsigned int m_round;
135 
137  int m_error;
138 
141 
144 
147 
150 
151  bool process_result(int);
152 
162  virtual Blob process_data(const Blob &data) =0;
163 
165  virtual Blob read_packet() =0;
166 
168  virtual int write_packet(Blob &data) =0;
169 
170 #ifndef DBUG_OFF
171 
172 private:
173  SecPkgInfo *m_ssp_info;
174 public:
175  const char* ssp_name();
176 
177 #endif
178 };
179 
180 
181 #endif