1 /* 2 * Copyright (c) 2015, 2021, Oracle and/or its affiliates. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License, version 2.0, 6 * as published by the Free Software Foundation. 7 * 8 * This program is also distributed with certain software (including 9 * but not limited to OpenSSL) that is licensed under separate terms, 10 * as designated in a particular file or component or in included license 11 * documentation. The authors of MySQL hereby grant you an additional 12 * permission to link the program and your derivative works with the 13 * separately licensed software that they have included with MySQL. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License, version 2.0, for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 23 * 02110-1301 USA 24 */ 25 26 #ifndef _CAP_HANDLES_EXPIRED_PASSWORDS_H_ 27 #define _CAP_HANDLES_EXPIRED_PASSWORDS_H_ 28 29 #include "ngs/capabilities/handler.h" 30 #include "ngs/mysqlx/getter_any.h" 31 #include "ngs/mysqlx/setter_any.h" 32 33 #include "xpl_client.h" 34 #include "xpl_log.h" 35 36 namespace xpl 37 { 38 39 class Cap_handles_expired_passwords : public ngs::Capability_handler 40 { 41 public: Cap_handles_expired_passwords(xpl::Client & client)42 Cap_handles_expired_passwords(xpl::Client &client) 43 : m_client(client) 44 { 45 m_value = m_client.supports_expired_passwords(); 46 } 47 48 private: name()49 virtual const std::string name() const { return "client.pwd_expire_ok"; } 50 is_supported()51 virtual bool is_supported() const { return true; } 52 get(::Mysqlx::Datatypes::Any & any)53 virtual void get(::Mysqlx::Datatypes::Any &any) 54 { 55 ngs::Setter_any::set_scalar(any, m_value); 56 } 57 set(const::Mysqlx::Datatypes::Any & any)58 virtual bool set(const ::Mysqlx::Datatypes::Any &any) 59 { 60 try 61 { 62 m_value = ngs::Getter_any::get_numeric_value<bool>(any); 63 } 64 catch (const ngs::Error_code &error) 65 { 66 log_error("Capability expired password failed with error: %s", error.message.c_str()); 67 return false; 68 } 69 return true; 70 } 71 commit()72 virtual void commit() 73 { 74 m_client.set_supports_expired_passwords(m_value); 75 } 76 77 private: 78 xpl::Client &m_client; 79 bool m_value; 80 }; 81 82 } 83 #endif 84