MySQL 8.0.39
Source Code Documentation
service_security_context.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
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 02110-1301 USA */
23
24#ifndef MYSQL_SERVICE_SECURITY_CONTEXT
25#define MYSQL_SERVICE_SECURITY_CONTEXT
26
27/**
28 @file include/mysql/service_security_context.h
29
30 Definitions for the password validation service.
31
32 @sa security_context_service_st
33*/
34
35#include "mysql/plugin.h"
36
37#ifdef __cplusplus
39/** an opaque class reference hiding the actual security context object. */
40#define MYSQL_SECURITY_CONTEXT Security_context *
41#else
42#define MYSQL_SECURITY_CONTEXT void *
43#endif
44typedef char my_svc_bool;
45
46/**
47 @ingroup group_ext_plugin_services
48
49 This service provides functions for plugins and storage engines to
50 manipulate the thread's security context.
51
52 The service allows creation, copying, filling in by user account and
53 destruction of security context objects.
54 It also allows getting and setting the security context for a thread.
55 And it also allows reading and setting security context properties.
56
57 The range of the above services allows plugins to inspect the security
58 context they're running it, impersonate a user account of their choice
59 (a.k.a. sudo in Unix) and craft a security context not related to an
60 existing user account.
61
62 No authentication is done in any of the above services. Authentication
63 is specific to the media and does not belong to the security context,
64 that's used mostly for authorization.
65
66 Make sure you keep the original security context of a thread or restore
67 it when done, as leaving a different security context active may lead to
68 various kinds of problems.
69
70 @sa Security_context, THD, MYSQL_SECURITY_CONTEXT
71*/
72extern "C" struct security_context_service_st {
73 /**
74 Retrieves a handle to the current security context for a thread.
75 @sa ::thd_get_security_context
76 */
78 MYSQL_SECURITY_CONTEXT *out_ctx);
79 /**
80 Sets a new security context for a thread
81 @sa ::thd_set_security_context
82 */
85
86 /**
87 Creates a new security context
88 @sa ::security_context_create
89 */
91 /**
92 Creates a new security context
93 @sa ::security_context_create
94 */
96 /**
97 Creates a copy of a security context
98 @sa ::security_context_copy
99 */
101 MYSQL_SECURITY_CONTEXT *out_ctx);
102
103 /**
104 Fills in a security context with the attributes of a user account
105 @sa ::security_context_lookup
106 */
108 const char *user, const char *host,
109 const char *ip, const char *db);
110
111 /**
112 Retrieves the value for a named attribute of a security context
113 @sa ::security_context_get_option
114 */
116 const char *name,
117 void *inout_pvalue);
118 /**
119 Sets a new value for a named attribute of a security context
120 @sa ::security_context_set_option
121 */
123 const char *name, void *pvalue);
125
126#ifdef MYSQL_DYNAMIC_PLUGIN
127
128#define thd_get_security_context(_THD, _CTX) \
129 security_context_service->thd_get_security_context(_THD, _CTX)
130#define thd_set_security_context(_THD, _CTX) \
131 security_context_service->thd_set_security_context(_THD, _CTX)
132
133#define security_context_create(_CTX) \
134 security_context_service->security_context_create(_CTX)
135#define security_context_destroy(_CTX) \
136 security_context_service->security_context_destroy(_CTX)
137#define security_context_copy(_CTX1, _CTX2) \
138 security_context_service->security_context_copy(_CTX1, _CTX2)
139
140#define security_context_lookup(_CTX, _U, _H, _IP, _DB) \
141 security_context_service->security_context_lookup(_CTX, _U, _H, _IP, _DB)
142
143#define security_context_get_option(_SEC_CTX, _NAME, _VALUE) \
144 security_context_service->security_context_get_option(_SEC_CTX, _NAME, _VALUE)
145#define security_context_set_option(_SEC_CTX, _NAME, _VALUE) \
146 security_context_service->security_context_set_option(_SEC_CTX, _NAME, _VALUE)
147#else
149 MYSQL_SECURITY_CONTEXT *out_ctx);
151
155 MYSQL_SECURITY_CONTEXT *out_ctx);
156
158 const char *user, const char *host,
159 const char *ip, const char *db);
160
162 const char *name, void *inout_pvalue);
164 const char *name, void *pvalue);
165#endif /* !MYSQL_DYNAMIC_PLUGIN */
166
167#endif /* !MYSQL_SERVICE_SECURITY_CONTEXT */
#define MYSQL_THD
Definition: backup_page_tracker.h:38
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:55
struct security_context_service_st * security_context_service
char * user
Definition: mysqladmin.cc:60
const char * host
Definition: mysqladmin.cc:59
my_svc_bool thd_get_security_context(MYSQL_THD, MYSQL_SECURITY_CONTEXT *out_ctx)
Gets the security context for the thread.
Definition: service_security_context.cc:55
my_svc_bool security_context_set_option(MYSQL_SECURITY_CONTEXT, const char *name, void *pvalue)
Sets a value for a named security context attribute Currently defined names are:
Definition: service_security_context.cc:304
my_svc_bool security_context_lookup(MYSQL_SECURITY_CONTEXT ctx, const char *user, const char *host, const char *ip, const char *db)
Looks up in the defined user accounts an account based on the user@host[ip] combo supplied and checks...
Definition: service_security_context.cc:177
my_svc_bool security_context_create(MYSQL_SECURITY_CONTEXT *out_ctx)
Creates a new security context and initializes it with the defaults (no access, no user etc).
Definition: service_security_context.cc:109
my_svc_bool security_context_get_option(MYSQL_SECURITY_CONTEXT, const char *name, void *inout_pvalue)
Reads a named security context attribute and returns its value.
Definition: service_security_context.cc:239
char my_svc_bool
Definition: service_security_context.h:44
my_svc_bool security_context_copy(MYSQL_SECURITY_CONTEXT in_ctx, MYSQL_SECURITY_CONTEXT *out_ctx)
Duplicates a security context.
Definition: service_security_context.cc:146
#define MYSQL_SECURITY_CONTEXT
an opaque class reference hiding the actual security context object.
Definition: service_security_context.h:40
my_svc_bool thd_set_security_context(MYSQL_THD, MYSQL_SECURITY_CONTEXT in_ctx)
Sets a new security context for the thread.
Definition: service_security_context.cc:80
my_svc_bool security_context_destroy(MYSQL_SECURITY_CONTEXT ctx)
Deallocates a security context.
Definition: service_security_context.cc:127
case opt name
Definition: sslopt-case.h:33
This service provides functions for plugins and storage engines to manipulate the thread's security c...
Definition: service_security_context.h:72
my_svc_bool(* security_context_destroy)(MYSQL_SECURITY_CONTEXT)
Creates a new security context.
Definition: service_security_context.h:95
my_svc_bool(* thd_get_security_context)(MYSQL_THD, MYSQL_SECURITY_CONTEXT *out_ctx)
Retrieves a handle to the current security context for a thread.
Definition: service_security_context.h:77
my_svc_bool(* security_context_create)(MYSQL_SECURITY_CONTEXT *out_ctx)
Creates a new security context.
Definition: service_security_context.h:90
my_svc_bool(* security_context_copy)(MYSQL_SECURITY_CONTEXT in_ctx, MYSQL_SECURITY_CONTEXT *out_ctx)
Creates a copy of a security context.
Definition: service_security_context.h:100
my_svc_bool(* thd_set_security_context)(MYSQL_THD, MYSQL_SECURITY_CONTEXT in_ctx)
Sets a new security context for a thread.
Definition: service_security_context.h:83
my_svc_bool(* security_context_lookup)(MYSQL_SECURITY_CONTEXT ctx, const char *user, const char *host, const char *ip, const char *db)
Fills in a security context with the attributes of a user account.
Definition: service_security_context.h:107
my_svc_bool(* security_context_set_option)(MYSQL_SECURITY_CONTEXT, const char *name, void *pvalue)
Sets a new value for a named attribute of a security context.
Definition: service_security_context.h:122
my_svc_bool(* security_context_get_option)(MYSQL_SECURITY_CONTEXT, const char *name, void *inout_pvalue)
Retrieves the value for a named attribute of a security context.
Definition: service_security_context.h:115