1 /* Copyright (c) 2015, 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
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef MYSQL_SERVICE_SECURITY_CONTEXT
24 #define MYSQL_SERVICE_SECURITY_CONTEXT
25 
26 /**
27   @file include/mysql/service_security_context.h
28 
29   This service provides functions for plugins and storage engines to
30   manipulate the thread's security context.
31 */
32 
33 #ifdef __cplusplus
34 class Security_context;
35 #define MYSQL_SECURITY_CONTEXT Security_context*
36 #else
37 #define MYSQL_SECURITY_CONTEXT void*
38 #endif
39 typedef char my_svc_bool;
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 extern struct security_context_service_st {
46   my_svc_bool (*thd_get_security_context)(MYSQL_THD, MYSQL_SECURITY_CONTEXT *out_ctx);
47   my_svc_bool (*thd_set_security_context)(MYSQL_THD, MYSQL_SECURITY_CONTEXT in_ctx);
48 
49   my_svc_bool (*security_context_create)(MYSQL_SECURITY_CONTEXT *out_ctx);
50   my_svc_bool (*security_context_destroy)(MYSQL_SECURITY_CONTEXT);
51   my_svc_bool (*security_context_copy)(MYSQL_SECURITY_CONTEXT in_ctx, MYSQL_SECURITY_CONTEXT *out_ctx);
52 
53   my_svc_bool (*security_context_lookup)(MYSQL_SECURITY_CONTEXT ctx,
54                                          const char *user, const char *host,
55                                          const char *ip, const char *db);
56 
57   my_svc_bool (*security_context_get_option)(MYSQL_SECURITY_CONTEXT, const char *name, void *inout_pvalue);
58   my_svc_bool (*security_context_set_option)(MYSQL_SECURITY_CONTEXT, const char *name, void *pvalue);
59 } *security_context_service;
60 
61 #ifdef MYSQL_DYNAMIC_PLUGIN
62 
63 #define thd_get_security_context(_THD, _CTX) \
64   security_context_service->thd_get_security_context(_THD, _CTX)
65 #define thd_set_security_context(_THD, _CTX) \
66   security_context_service->thd_set_security_context(_THD, _CTX)
67 
68 #define security_context_create(_CTX) \
69   security_context_service->security_context_create(_CTX)
70 #define security_context_destroy(_CTX) \
71   security_context_service->security_context_destroy(_CTX)
72 #define security_context_copy(_CTX1, _CTX2) \
73   security_context_service->security_context_copy(_CTX1,_CTX2)
74 
75 #define security_context_lookup(_CTX, _U, _H, _IP, _DB) \
76   security_context_service->security_context_lookup(_CTX, _U, _H, _IP, _DB)
77 
78 #define security_context_get_option(_SEC_CTX, _NAME, _VALUE) \
79   security_context_service->security_context_get_option(_SEC_CTX, _NAME, _VALUE)
80 #define security_context_set_option(_SEC_CTX, _NAME, _VALUE) \
81   security_context_service->security_context_set_option(_SEC_CTX, _NAME, _VALUE)
82 #else
83   my_svc_bool thd_get_security_context(MYSQL_THD, MYSQL_SECURITY_CONTEXT *out_ctx);
84   my_svc_bool thd_set_security_context(MYSQL_THD, MYSQL_SECURITY_CONTEXT in_ctx);
85 
86   my_svc_bool security_context_create(MYSQL_SECURITY_CONTEXT *out_ctx);
87   my_svc_bool security_context_destroy(MYSQL_SECURITY_CONTEXT ctx);
88   my_svc_bool security_context_copy(MYSQL_SECURITY_CONTEXT in_ctx, MYSQL_SECURITY_CONTEXT *out_ctx);
89 
90   my_svc_bool security_context_lookup(MYSQL_SECURITY_CONTEXT ctx,
91                                   const char *user, const char *host,
92                                   const char *ip, const char *db);
93 
94   my_svc_bool security_context_get_option(MYSQL_SECURITY_CONTEXT, const char *name, void *inout_pvalue);
95   my_svc_bool security_context_set_option(MYSQL_SECURITY_CONTEXT, const char *name, void *pvalue);
96 #endif /* !MYSQL_DYNAMIC_PLUGIN */
97 
98 #ifdef __cplusplus
99 }
100 #endif /* _cplusplus */
101 
102 #endif /* !MYSQL_SERVICE_SECURITY_CONTEXT */
103