21 template <>
void error_log_print<error_log_level::INFO>(
const char *
fmt, ...);
22 template <>
void error_log_print<error_log_level::WARNING>(
const char *
fmt, ...);
23 template <>
void error_log_print<error_log_level::ERROR>(
const char *
fmt, ...);
41 int opt_auth_win_log_level= 2;
72 m_error= m_vio->
write_packet(m_vio, blob.ptr(), blob.len());
76 DBUG_PRINT(
"error", (
"vio write error %d", m_error));
103 return Blob(ptr, len);
122 Sid::Sid(
const wchar_t *account_name): m_data(NULL)
127 DWORD sid_size= 0, domain_size= 0;
132 success= LookupAccountNameW(NULL, account_name, NULL, &sid_size,
133 NULL, &domain_size, &m_type);
135 if (!success && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
138 Error_message_buf error_buf;
139 DBUG_PRINT(
"error", (
"Could not determine SID buffer size, "
140 "LookupAccountName() failed with error %X (%s)",
141 GetLastError(), get_last_error_message(error_buf)));
148 wchar_t *domain=
new wchar_t[domain_size];
149 m_data= (TOKEN_USER*)
new BYTE[sid_size +
sizeof(TOKEN_USER)];
150 m_data->User.Sid= (BYTE*)m_data +
sizeof(TOKEN_USER);
152 success= LookupAccountNameW(NULL, account_name,
153 m_data->User.Sid, &sid_size,
154 domain, &domain_size,
160 Error_message_buf error_buf;
161 DBUG_PRINT(
"error", (
"Could not determine SID of '%S', "
162 "LookupAccountName() failed with error %X (%s)",
163 account_name, GetLastError(),
164 get_last_error_message(error_buf)));
201 success= GetTokenInformation(token, TokenUser, NULL, 0, &req_size);
202 if (!success && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
205 Error_message_buf error_buf;
206 DBUG_PRINT(
"error", (
"Could not determine SID buffer size, "
207 "GetTokenInformation() failed with error %X (%s)",
208 GetLastError(), get_last_error_message(error_buf)));
213 m_data= (TOKEN_USER*)
new BYTE[req_size];
214 success= GetTokenInformation(token, TokenUser, m_data, req_size, &req_size);
223 Error_message_buf error_buf;
224 DBUG_PRINT(
"error", (
"Could not read SID from security token, "
225 "GetTokenInformation() failed with error %X (%s)",
226 GetLastError(), get_last_error_message(error_buf)));
239 LocalFree(m_as_string);
246 return m_data && m_data->User.Sid && IsValidSid(m_data->User.Sid);
268 bool success= ConvertSidToStringSid(m_data->User.Sid, &m_as_string);
273 Error_message_buf error_buf;
274 DBUG_PRINT(
"error", (
"Could not get textual representation of a SID, "
275 "ConvertSidToStringSid() failed with error %X (%s)",
276 GetLastError(), get_last_error_message(error_buf)));
289 bool Sid::operator ==(
const Sid &other)
294 return EqualSid(m_data->User.Sid, other.m_data->User.Sid);
307 wchar_t buf1[MAX_SERVICE_NAME_LENGTH];
311 m_len=
sizeof(buf1)/
sizeof(
wchar_t);
313 if (!GetUserNameExW(NameUserPrincipal, buf1, (PULONG)&m_len))
318 Error_message_buf error_buf;
319 DBUG_PRINT(
"note", (
"When determining UPN"
320 ", GetUserNameEx() failed with error %X (%s)",
321 GetLastError(), get_last_error_message(error_buf)));
323 if (ERROR_MORE_DATA == GetLastError())
324 ERROR_LOG(INFO, (
"Buffer overrun when determining UPN:"
325 " need %ul characters but have %ul",
326 m_len,
sizeof(buf1)/
sizeof(WCHAR)));
338 m_buf= wchar_to_utf8(buf1, &m_len);
341 ERROR_LOG(ERROR, (
"Failed to convert UPN to utf8"));
371 char* wchar_to_utf8(
const wchar_t *
string,
size_t *len)
374 size_t str_len= len && *len ? *len : wcslen(
string);
382 size_t buf_len= 3 * str_len;
384 buf= (
char*)malloc(buf_len + 1);
387 DBUG_PRINT(
"error",(
"Out of memory when converting string '%S' to utf8",
392 int res= WideCharToMultiByte(CP_UTF8,
410 Error_message_buf error_buf;
411 DBUG_PRINT(
"error", (
"Could not convert string '%S' to utf8"
412 ", WideCharToMultiByte() failed with error %X (%s)",
413 string, GetLastError(),
414 get_last_error_message(error_buf)));
418 DBUG_ASSERT(ERROR_INSUFFICIENT_BUFFER != GetLastError());
439 wchar_t* utf8_to_wchar(
const char *
string,
size_t *len)
449 buf_len= len && *len ? *len : strlen(
string);
450 wchar_t *buf= (
wchar_t*)malloc((buf_len+1)*
sizeof(wchar_t));
454 DBUG_PRINT(
"error",(
"Out of memory when converting utf8 string '%s'"
455 " to wide-char representation",
string));
460 res= MultiByteToWideChar(CP_UTF8,
476 Error_message_buf error_buf;
477 DBUG_PRINT(
"error", (
"Could not convert UPN from UTF-8"
478 ", MultiByteToWideChar() failed with error %X (%s)",
479 GetLastError(), get_last_error_message(error_buf)));
483 DBUG_ASSERT(ERROR_INSUFFICIENT_BUFFER != GetLastError());
500 const char* get_last_error_message(Error_message_buf buf)
502 int error= GetLastError();
505 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
506 NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
507 (LPTSTR)buf,
sizeof(buf), NULL );