forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_dcl_executor.cpp
More file actions
537 lines (522 loc) · 21 KB
/
Copy pathob_dcl_executor.cpp
File metadata and controls
537 lines (522 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
/*
* Copyright (c) 2025 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define USING_LOG_PREFIX SQL_ENG
#include "sql/engine/cmd/ob_dcl_executor.h"
#include "lib/encrypt/ob_encrypted_helper.h"
#include "sql/engine/ob_exec_context.h"
#include "sql/resolver/dcl/ob_grant_stmt.h"
#include "sql/resolver/dcl/ob_revoke_stmt.h"
#include "sql/engine/cmd/ob_user_cmd_executor.h"
namespace oceanbase
{
using namespace common;
using namespace share::schema;
namespace sql
{
int ObGrantExecutor::execute(ObExecContext &ctx, ObGrantStmt &stmt)
{
int ret = OB_SUCCESS;
ObTaskExecutorCtx *task_exec_ctx = NULL;
obrpc::ObCommonRpcProxy *common_rpc_proxy = NULL;
ObSQLSessionInfo *session_info = NULL;
const uint64_t tenant_id = stmt.get_tenant_id();
const ObStrings &users = stmt.get_users();
ObIAllocator &allocator = ctx.get_allocator();
obrpc::ObGrantArg &arg = static_cast<obrpc::ObGrantArg &>(stmt.get_ddl_arg());
const bool is_role = arg.roles_.count() > 0;
ObSchemaGetterGuard schema_guard;
const ObUserInfo *user_info = NULL;
if (OB_ISNULL(task_exec_ctx = GET_TASK_EXECUTOR_CTX(ctx))) {
ret = OB_NOT_INIT;
LOG_WARN("get task executor context failed");
} else if (OB_ISNULL(session_info = ctx.get_my_session())) {
ret = OB_NOT_INIT;
LOG_WARN("Get my session error");
} else if (OB_ISNULL(common_rpc_proxy = task_exec_ctx->get_common_rpc())) {
ret = OB_NOT_INIT;
LOG_WARN("get common rpc proxy failed", K(ret));
} else if (OB_ISNULL(GCTX.schema_service_)) {
ret = OB_NOT_INIT;
LOG_WARN("get schema service failed", K(ret));
} else if (!is_role) {
ObString user_name;
ObString host_name;
ObString pwd;
ObString need_enc;
//i += 4, each with user_name, pwd, need_enc
if (OB_UNLIKELY(users.count() <= 0) || OB_UNLIKELY(0 != users.count() % 4)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("Resolve users error. Users should have user and pwd",
"ObStrings count", users.count(), K(ret));
}
for (int64_t i = 0; OB_SUCC(ret) && i < users.count(); i += 4) {
if (OB_FAIL(users.get_string(i, user_name))) {
LOG_WARN("Get string from ObStrings error", "count",
users.count(), K(i), K(ret));
} else if (OB_FAIL(users.get_string(i + 1, host_name))) {
LOG_WARN("Get string from ObStrings error", "count",
users.count(), K(i), K(ret));
} else if (OB_FAIL(users.get_string(i + 2, pwd))) {
LOG_WARN("Get string from ObStrings error", "count",
users.count(), K(i), K(ret));
} else if (OB_FAIL(users.get_string(i + 3, need_enc))) {
LOG_WARN("Get string from ObStrings error", "count",
users.count(), K(i), K(ret));
} else {
if (OB_FAIL(arg.users_passwd_.push_back(user_name))) {
LOG_WARN("failed to add user", K(ret));
} else if (OB_FAIL(arg.hosts_.push_back(host_name))) {
LOG_WARN("failed to add user", K(ret));
} else if (ObString::make_string("YES") == need_enc) {
ObString pwd_enc;
if (pwd.length() > 0) {
char *enc_buf = NULL;
if (NULL == (enc_buf = static_cast<char *>(allocator.alloc(ENC_BUF_LEN)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("Failed to allocate memory", K(ret), K(ENC_BUF_LEN));
} else if (OB_FAIL(ObCreateUserExecutor::encrypt_passwd(pwd,
pwd_enc,
enc_buf,
ENC_BUF_LEN))) {
LOG_WARN("Encrypt password failed", K(ret));
} else { }//do nothing
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(arg.users_passwd_.push_back(pwd_enc))) {
LOG_WARN("failed to add password", K(ret));
} else { }//do nothing
} else {
if (OB_FAIL(arg.users_passwd_.push_back(pwd))) {
LOG_WARN("failed to add password", K(ret));
}
}
}
}
}
if (OB_FAIL(ret)) {
// do nothing.
} else if (OB_ISNULL(stmt.get_query_ctx())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("query ctx is null", K(ret));
} else {
arg.tenant_id_ = tenant_id;
arg.db_ = stmt.get_database_name();
arg.table_ = stmt.get_table_name();
arg.priv_set_ = stmt.get_priv_set();
arg.priv_level_ = stmt.get_grant_level();
arg.need_create_user_ = stmt.get_need_create_user();
arg.has_create_user_priv_ = session_info->get_user_priv_set() & OB_PRIV_CREATE_USER;
arg.ddl_stmt_str_ = stmt.get_query_ctx()->get_sql_stmt();
arg.option_ = stmt.get_option();
arg.object_type_ = stmt.get_object_type();
arg.object_id_ = stmt.get_object_id();
arg.grantor_id_ = stmt.get_grantor_id();
arg.is_inner_ = session_info->is_inner();
arg.based_schema_object_infos_.reset();
if (OB_FAIL(append(arg.column_names_priv_, stmt.get_column_privs()))
|| OB_FAIL(append(arg.ins_col_ids_, stmt.get_ins_col_ids()))
|| OB_FAIL(append(arg.upd_col_ids_, stmt.get_upd_col_ids()))
|| OB_FAIL(append(arg.ref_col_ids_, stmt.get_ref_col_ids()))) {
LOG_WARN("append failed", K(ret));
} else if (lib::is_mysql_mode() && arg.object_type_ == ObObjectType::TABLE
&& arg.column_names_priv_.count() > 0) {
if (arg.object_id_ == OB_INVALID) {
//do nothing
//todo: oracle every object will use id, and should also record the schema version in future.
} else if (stmt.get_table_schema_version() != 0
&& OB_FAIL(arg.based_schema_object_infos_.push_back(ObBasedSchemaObjectInfo(arg.object_id_,
TABLE_SCHEMA,
stmt.get_table_schema_version())))) {
LOG_WARN("push back failed", K(ret));
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(tenant_id, schema_guard))) {
LOG_WARN("failed to get tenant schema guard", K(ret));
} else if (OB_FAIL(schema_guard.get_user_info(tenant_id,
session_info->get_priv_user_id(),
user_info))) {
LOG_WARN("failed to get user info", K(ret));
} else if (OB_ISNULL(user_info)) {
// ignore ret
LOG_WARN("user info is unexpected null", K(ret));
} else if (OB_FAIL(ob_write_string(allocator, user_info->get_user_name_str(), arg.grantor_))) {
LOG_WARN("failed to write string", K(ret));
} else if (OB_FAIL(ob_write_string(allocator, user_info->get_host_name_str(), arg.grantor_host_))) {
LOG_WARN("failed to write string", K(ret));
}
int tmp_ret = OB_SUCCESS;
if (OB_TMP_FAIL(schema_guard.reset())) {
LOG_WARN("failed to reset schema guard", K(tmp_ret));
if (OB_SUCC(ret)) {
ret = tmp_ret;
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(common_rpc_proxy->grant(arg))) {
LOG_WARN("Grant privileges to user error", K(ret), K(arg));
}
}
return ret;
}
int ObRevokeExecutor::execute(ObExecContext &ctx, ObRevokeStmt &stmt)
{
int ret = OB_SUCCESS;
ObTaskExecutorCtx *task_exec_ctx = NULL;
obrpc::ObCommonRpcProxy *common_rpc_proxy = NULL;
if (OB_ISNULL(task_exec_ctx = GET_TASK_EXECUTOR_CTX(ctx))) {
ret = OB_NOT_INIT;
LOG_WARN("get task executor context failed");
} else if (OB_ISNULL(common_rpc_proxy = task_exec_ctx->get_common_rpc())) {
ret = OB_NOT_INIT;
LOG_WARN("get common rpc proxy failed");
} else if (stmt.get_has_warning()) {
//do nothing
} else {
switch (stmt.get_grant_level()) {
case OB_PRIV_USER_LEVEL: {
if (OB_FAIL(revoke_user(common_rpc_proxy, stmt))) {
LOG_WARN("grant_revoke_user error", K(ret));
}
break;
}
case OB_PRIV_DB_LEVEL: {
if (OB_FAIL(revoke_db(common_rpc_proxy, stmt))) {
LOG_WARN("grant_revoke_db error", K(ret));
}
break;
}
case OB_PRIV_TABLE_LEVEL: {
if (OB_FAIL(revoke_table(common_rpc_proxy, stmt, ctx))) {
LOG_WARN("grant_revoke_table error", K(ret));
}
break;
}
case OB_PRIV_ROUTINE_LEVEL: {
if (OB_FAIL(revoke_routine(common_rpc_proxy, stmt, ctx))) {
LOG_WARN("grant_revoke_routine error", K(ret));
}
break;
}
case OB_PRIV_CATALOG_LEVEL : {
if (OB_FAIL(revoke_catalog(common_rpc_proxy, stmt))) {
LOG_WARN("grant_revoke_catalog error", K(ret));
}
break;
}
case OB_PRIV_OBJECT_LEVEL: {
if (OB_FAIL(revoke_object(common_rpc_proxy, stmt, ctx))) {
LOG_WARN("grant_revoke_object error", K(ret));
}
break;
}
default: {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("Resolver may be error, invalid grant_level",
"grant_level", ob_priv_level_str(stmt.get_grant_level()), K(ret));
break;
}
}
}
return ret;
}
int ObRevokeExecutor::revoke_user(obrpc::ObCommonRpcProxy *rpc_proxy, ObRevokeStmt &stmt)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(rpc_proxy)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("Input argument error", K(rpc_proxy), K(ret));
} else {
obrpc::ObRevokeUserArg &arg = static_cast<obrpc::ObRevokeUserArg &>(stmt.get_ddl_arg());
arg.tenant_id_ = stmt.get_tenant_id();
const ObIArray<uint64_t> &user_ids = stmt.get_users();
const bool is_role = arg.role_ids_.count() > 0;
if (is_role) {
for (int i = 0; OB_SUCC(ret) && i < user_ids.count(); ++i) {
arg.user_id_ = user_ids.at(i);
if (OB_FAIL(rpc_proxy->revoke_user(arg))) {
LOG_WARN("revoke user error", K(arg), K(ret));
}
}
} else if (0 == user_ids.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("User ids is empty, resolver may be error", K(ret));
} else {
arg.revoke_all_ = stmt.get_revoke_all();
arg.priv_set_ = stmt.get_priv_set();
for (int i = 0; OB_SUCC(ret) && i < user_ids.count(); i++) {
arg.user_id_ = user_ids.at(i);
if (OB_FAIL(rpc_proxy->revoke_user(arg))) {
LOG_WARN("revoke user error", K(arg), K(ret));
}
}
}
}
return ret;
}
int ObRevokeExecutor::revoke_catalog(obrpc::ObCommonRpcProxy *rpc_proxy, ObRevokeStmt &stmt)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(rpc_proxy)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("Input argument error", K(rpc_proxy), K(ret));
} else {
obrpc::ObRevokeCatalogArg &arg = static_cast<obrpc::ObRevokeCatalogArg &>(stmt.get_ddl_arg());
arg.tenant_id_ = stmt.get_tenant_id();
arg.priv_set_ = stmt.get_priv_set();
// arg.catalog_ has been set in resolve phase
const ObIArray<uint64_t> &user_ids = stmt.get_users();
if (0 == user_ids.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("User ids is empty, resolver may be error", K(ret));
} else {
for (int i = 0; OB_SUCC(ret) && i < user_ids.count(); i++) {
arg.user_id_ = user_ids.at(i);
if (OB_FAIL(rpc_proxy->revoke_catalog(arg))) {
LOG_WARN("revoke user error", K(arg), K(ret));
}
}
}
}
return ret;
}
int ObRevokeExecutor::revoke_db(obrpc::ObCommonRpcProxy *rpc_proxy, ObRevokeStmt &stmt)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(rpc_proxy)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("Input argument error", K(rpc_proxy), K(ret));
} else {
obrpc::ObRevokeDBArg &arg = static_cast<obrpc::ObRevokeDBArg &>(stmt.get_ddl_arg());
arg.tenant_id_ = stmt.get_tenant_id();
arg.priv_set_ = stmt.get_priv_set();
arg.db_ = stmt.get_database_name();
const ObIArray<uint64_t> &user_ids = stmt.get_users();
if (0 == user_ids.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("User ids is empty, resolver may be error", K(ret));
} else {
for (int i = 0; OB_SUCC(ret) && i < user_ids.count(); i++) {
arg.user_id_ = user_ids.at(i);
if (OB_FAIL(rpc_proxy->revoke_database(arg))) {
LOG_WARN("revoke user error", K(arg), K(ret));
}
}
}
}
return ret;
}
int ObRevokeExecutor::revoke_table(obrpc::ObCommonRpcProxy *rpc_proxy,
ObRevokeStmt &stmt,
ObExecContext &ctx)
{
int ret = OB_SUCCESS;
ObSQLSessionInfo *session_info = NULL;
ObSchemaGetterGuard schema_guard;
const ObUserInfo *user_info = NULL;
if (OB_ISNULL(rpc_proxy) || OB_ISNULL(GCTX.schema_service_)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("Input argument error", K(rpc_proxy), K(ret));
} else if (OB_ISNULL(session_info = ctx.get_my_session())) {
ret = OB_NOT_INIT;
LOG_WARN("Get my session error");
} else {
obrpc::ObRevokeTableArg &arg = static_cast<obrpc::ObRevokeTableArg &>(stmt.get_ddl_arg());
arg.tenant_id_ = stmt.get_tenant_id();
arg.priv_set_ = stmt.get_priv_set();
arg.db_ = stmt.get_database_name();
arg.table_ = stmt.get_table_name();
arg.obj_id_ = stmt.get_object_id();
arg.obj_type_ = static_cast<uint64_t>(stmt.get_object_type());
arg.grantor_id_ = stmt.get_grantor_id();
arg.revoke_all_ora_ = stmt.get_revoke_all_ora();
arg.based_schema_object_infos_.reset();
if (OB_FAIL(append(arg.column_names_priv_, stmt.get_column_privs()))) {
LOG_WARN("append failed", K(ret));
} else if (stmt.get_object_type() == ObObjectType::TABLE
&& (arg.column_names_priv_.count() > 0)) {
if (arg.obj_id_ == OB_INVALID) {
//do nothing
//todo: oracle every object will use id, and should also record the schema version in future.
} else if (lib::is_mysql_mode() && stmt.get_table_schema_version()!= 0 &&
OB_FAIL(arg.based_schema_object_infos_.push_back(ObBasedSchemaObjectInfo(arg.obj_id_,
TABLE_SCHEMA,
stmt.get_table_schema_version())))) {
LOG_WARN("push back failed", K(ret));
}
} else {
//todo: pl routine and others
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(arg.tenant_id_, schema_guard))) {
LOG_WARN("failed to get tenant schema guard", K(ret));
} else if (OB_FAIL(schema_guard.get_user_info(arg.tenant_id_,
session_info->get_priv_user_id(),
user_info))) {
LOG_WARN("failed to get user info", K(ret));
} else if (OB_ISNULL(user_info)) {
// ignore ret
LOG_WARN("user info is unexpected null", K(ret));
} else if (OB_FAIL(ob_write_string(ctx.get_allocator(), user_info->get_user_name_str(), arg.grantor_))) {
LOG_WARN("failed to write string", K(ret));
} else if (OB_FAIL(ob_write_string(ctx.get_allocator(), user_info->get_host_name_str(), arg.grantor_host_))) {
LOG_WARN("failed to write string", K(ret));
}
int tmp_ret = OB_SUCCESS;
if (OB_TMP_FAIL(schema_guard.reset())) {
LOG_WARN("failed to reset schema guard", K(tmp_ret));
if (OB_SUCC(ret)) {
ret = tmp_ret;
}
}
const ObIArray<uint64_t> &user_ids = stmt.get_users();
if (OB_FAIL(ret)) {
} else if (0 == user_ids.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("User ids is empty, resolver may be error", K(ret));
} else {
for (int i = 0; OB_SUCC(ret) && i < user_ids.count(); i++) {
arg.user_id_ = user_ids.at(i);
if (OB_FAIL(rpc_proxy->revoke_table(arg))) {
LOG_WARN("revoke user error", K(arg), K(ret));
}
}
}
}
return ret;
}
int ObRevokeExecutor::revoke_routine(obrpc::ObCommonRpcProxy *rpc_proxy,
ObRevokeStmt &stmt,
ObExecContext &ctx)
{
int ret = OB_SUCCESS;
ObSQLSessionInfo *session_info = NULL;
ObSchemaGetterGuard schema_guard;
const ObUserInfo *user_info = NULL;
if (OB_ISNULL(rpc_proxy)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("Input argument error", K(rpc_proxy), K(ret));
} else if (OB_ISNULL(session_info = ctx.get_my_session())) {
ret = OB_NOT_INIT;
LOG_WARN("Get my session error");
} else {
obrpc::ObRevokeRoutineArg &arg = static_cast<obrpc::ObRevokeRoutineArg &>(stmt.get_ddl_arg());
arg.tenant_id_ = stmt.get_tenant_id();
arg.priv_set_ = stmt.get_priv_set();
arg.db_ = stmt.get_database_name();
arg.routine_ = stmt.get_table_name();
arg.obj_id_ = stmt.get_object_id();
arg.obj_type_ = static_cast<uint64_t>(stmt.get_object_type());
arg.grantor_id_ = stmt.get_grantor_id();
arg.revoke_all_ora_ = stmt.get_revoke_all_ora();
if (OB_FAIL(ret)) {
} else if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(arg.tenant_id_, schema_guard))) {
LOG_WARN("failed to get tenant schema guard", K(ret));
} else if (OB_FAIL(schema_guard.get_user_info(arg.tenant_id_,
session_info->get_priv_user_id(),
user_info))) {
LOG_WARN("failed to get user info", K(ret));
} else if (OB_ISNULL(user_info)) {
// ignore ret
LOG_WARN("user info is unexpected null", K(ret));
} else if (OB_FAIL(ob_write_string(ctx.get_allocator(), user_info->get_user_name_str(), arg.grantor_))) {
LOG_WARN("failed to write string", K(ret));
} else if (OB_FAIL(ob_write_string(ctx.get_allocator(), user_info->get_host_name_str(), arg.grantor_host_))) {
LOG_WARN("failed to write string", K(ret));
}
int tmp_ret = OB_SUCCESS;
if (OB_TMP_FAIL(schema_guard.reset())) {
LOG_WARN("failed to reset schema guard", K(tmp_ret));
if (OB_SUCC(ret)) {
ret = tmp_ret;
}
}
const ObIArray<uint64_t> &user_ids = stmt.get_users();
if (OB_FAIL(ret)) {
} else if (0 == user_ids.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("User ids is empty, resolver may be error", K(ret));
} else {
for (int i = 0; OB_SUCC(ret) && i < user_ids.count(); i++) {
arg.user_id_ = user_ids.at(i);
if (OB_FAIL(rpc_proxy->revoke_routine(arg))) {
LOG_WARN("revoke user error", K(arg), K(ret));
}
}
}
}
return ret;
}
int ObRevokeExecutor::revoke_object(obrpc::ObCommonRpcProxy *rpc_proxy,
ObRevokeStmt &stmt,
ObExecContext &ctx)
{
int ret = OB_SUCCESS;
ObSQLSessionInfo *session_info = NULL;
ObSchemaGetterGuard schema_guard;
const ObUserInfo *user_info = NULL;
if (OB_ISNULL(rpc_proxy)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("Input argument error", K(rpc_proxy), K(ret));
} else if (OB_ISNULL(session_info = ctx.get_my_session())) {
ret = OB_NOT_INIT;
LOG_WARN("Get my session error");
} else {
obrpc::ObRevokeObjMysqlArg &arg = static_cast<obrpc::ObRevokeObjMysqlArg &>(stmt.get_ddl_arg());
arg.tenant_id_ = stmt.get_tenant_id();
arg.priv_set_ = stmt.get_priv_set();
arg.obj_name_ = stmt.get_table_name();
arg.obj_type_ = static_cast<uint64_t>(stmt.get_object_type());
if (OB_FAIL(ret)) {
} else if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(arg.tenant_id_, schema_guard))) {
LOG_WARN("failed to get tenant schema guard", K(ret));
} else if (OB_FAIL(schema_guard.get_user_info(arg.tenant_id_,
session_info->get_priv_user_id(),
user_info))) {
LOG_WARN("failed to get user info", K(ret));
} else if (OB_ISNULL(user_info)) {
// ignore ret
LOG_WARN("user info is unexpected null", K(ret));
} else if (OB_FAIL(ob_write_string(ctx.get_allocator(), user_info->get_user_name_str(), arg.grantor_))) {
LOG_WARN("failed to write string", K(ret));
} else if (OB_FAIL(ob_write_string(ctx.get_allocator(), user_info->get_host_name_str(), arg.grantor_host_))) {
LOG_WARN("failed to write string", K(ret));
}
int tmp_ret = OB_SUCCESS;
if (OB_TMP_FAIL(schema_guard.reset())) {
LOG_WARN("failed to reset schema guard", K(tmp_ret));
if (OB_SUCC(ret)) {
ret = tmp_ret;
}
}
const ObIArray<uint64_t> &user_ids = stmt.get_users();
if (OB_FAIL(ret)) {
} else if (0 == user_ids.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("User ids is empty, resolver may be error", K(ret));
} else {
for (int i = 0; OB_SUCC(ret) && i < user_ids.count(); i++) {
arg.user_id_ = user_ids.at(i);
if (OB_FAIL(rpc_proxy->revoke_object(arg))) {
LOG_WARN("revoke user error", K(arg), K(ret));
}
}
}
}
return ret;
}
}// ns sql
}// ns oceanbase