1 /* Copyright (c) 2008, 2021, Oracle and/or its affiliates.
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, version 2.0,
5   as published by the Free Software Foundation.
6 
7   This program is also distributed with certain software (including
8   but not limited to OpenSSL) that is licensed under separate terms,
9   as designated in a particular file or component or in included license
10   documentation.  The authors of MySQL hereby grant you an additional
11   permission to link the program and your derivative works with the
12   separately licensed software that they have included with MySQL.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License, version 2.0, for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software Foundation,
21   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #include "table_session_account_connect_attrs.h"
24 
25 THR_LOCK table_session_account_connect_attrs::m_table_lock;
26 
27 PFS_engine_table_share
28 table_session_account_connect_attrs::m_share=
29 {
30   { C_STRING_WITH_LEN("session_account_connect_attrs") },
31   &pfs_readonly_world_acl,
32   table_session_account_connect_attrs::create,
33   NULL, /* write_row */
34   NULL, /* delete_all_rows */
35   cursor_by_thread_connect_attr::get_row_count,
36   sizeof(pos_connect_attr_by_thread_by_attr), /* ref length */
37   &m_table_lock,
38   &m_field_def,
39   false, /* checked */
40   false  /* perpetual */
41 };
42 
create()43 PFS_engine_table* table_session_account_connect_attrs::create()
44 {
45   return new table_session_account_connect_attrs();
46 }
47 
table_session_account_connect_attrs()48 table_session_account_connect_attrs::table_session_account_connect_attrs()
49   : table_session_connect(&m_share)
50 {}
51 
52 bool
thread_fits(PFS_thread * thread)53 table_session_account_connect_attrs::thread_fits(PFS_thread *thread)
54 {
55   PFS_thread *current_thread= PFS_thread::get_current_thread();
56   /* The current thread may not have instrumentation attached. */
57   if (current_thread == NULL)
58     return false;
59 
60   /* The thread we compare to, by definition, has some instrumentation. */
61   assert(thread != NULL);
62 
63   uint username_length= current_thread->m_username_length;
64   uint hostname_length= current_thread->m_hostname_length;
65 
66   if (   (thread->m_username_length != username_length)
67       || (thread->m_hostname_length != hostname_length))
68     return false;
69 
70   if (memcmp(thread->m_username, current_thread->m_username, username_length) != 0)
71     return false;
72 
73   if (memcmp(thread->m_hostname, current_thread->m_hostname, hostname_length) != 0)
74     return false;
75 
76   return true;
77 }
78