16 #include "handshake.h"
31 SEC_WCHAR *m_service_name;
34 SEC_WCHAR m_service_name_buf[MAX_SERVICE_NAME_LENGTH];
65 const char *target,
size_t len)
66 :
Handshake(SSP_NAME, CLIENT), m_service_name(NULL), m_con(con)
68 if (!target || 0 == len)
73 m_service_name= utf8_to_wchar(target, &len);
76 DBUG_PRINT(
"info", (
"Using target service: %S\n", m_service_name));
84 ERROR_LOG(WARNING, (
"Could not decode UPN sent by the server"
85 "; target service name will not be used"
86 " and Kerberos authentication will not work"));
91 Handshake_client::~Handshake_client()
114 if (!
m_error && packet.is_null())
120 DBUG_PRINT(
"dump", (
"Got the following bytes"));
121 DBUG_DUMP(
"dump", packet.ptr(), packet.len());
153 if (
m_round == 1 && data.len() > 254)
155 len2= data.len() - 254;
156 DBUG_PRINT(
"info", (
"Splitting first packet of length %lu"
157 ", %lu bytes will be sent in a second part",
163 unsigned block_count= data.len()/512 + ((data.len() % 512) ? 1 : 0);
165 #if !defined(DBUG_OFF) && defined(WINAUTH_USE_DBUG_LIB)
171 DBUG_EXECUTE_IF(
"winauth_first_packet_test",{
172 block_count= data.len() == 601 ? 0 :
173 data.len() == 602 ? 1 :
179 DBUG_ASSERT(block_count < (
unsigned)0x100);
180 saved_byte= data[254];
181 data[254] = block_count;
186 DBUG_PRINT(
"dump", (
"Sending the following data"));
187 DBUG_DUMP(
"dump", data.ptr(), data.len());
196 data[254]= saved_byte;
197 Blob data2(data.ptr() + 254, len2);
198 DBUG_PRINT(
"info", (
"Sending second part of data"));
199 DBUG_DUMP(
"info", data2.ptr(), data2.len());
200 ret= m_con.
write(data2);
228 #if !defined(DBUG_OFF) && defined(WINAUTH_USE_DBUG_LIB)
252 static byte test_buf[2048];
255 && DBUG_EVALUATE_IF(
"winauth_first_packet_test",
true,
false))
257 const char *env= getenv(
"TEST_PACKET_LENGTH");
258 size_t len= env ? atoi(env) : 0;
261 if (len >
sizeof(test_buf))
262 len=
sizeof(test_buf);
270 for (byte b= 0; ptr < test_buf + len; ++ptr, ++b)
273 return Blob(test_buf, len);
283 ret= InitializeSecurityContextW(
287 ASC_REQ_ALLOCATE_MEMORY,
289 SECURITY_NETWORK_DREP,
300 (
"InitializeSecurityContext() failed with error %X", ret));
331 DBUG_ENTER(
"win_auth_handshake_client");
337 const char *opt= getenv(
"AUTHENTICATION_WIN_LOG");
338 int opt_val= opt ? atoi(opt) : 0;
341 if (!strncasecmp(
"on", opt, 2)) opt_val= 2;
342 if (!strncasecmp(
"yes", opt, 3)) opt_val= 2;
343 if (!strncasecmp(
"true", opt, 4)) opt_val= 2;
344 if (!strncasecmp(
"debug", opt, 5)) opt_val= 4;
345 if (!strncasecmp(
"dbug", opt, 4)) opt_val= 4;
347 set_log_level(opt_val);
350 ERROR_LOG(INFO, (
"Authentication handshake for account %s", mysql->user));
355 DBUG_ASSERT(!con.error());
359 Blob service_name= con.read();
361 if (con.error() || service_name.is_null())
363 ERROR_LOG(ERROR, (
"Error reading initial packet"));
366 DBUG_PRINT(
"info", (
"Got initial packet of length %d", service_name.len()));
371 service_name[0] ? (
char *)service_name.ptr() : NULL,
375 ERROR_LOG(ERROR, (
"Could not create authentication handshake context"));
379 DBUG_ASSERT(!hndshk.error());
387 if (hndshk.packet_processing_loop())
390 DBUG_ASSERT(!hndshk.error() && hndshk.is_complete());