be/src/common/kerberos/krb5_interface.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <krb5.h> |
21 | | |
22 | | #include <memory> |
23 | | #include <string> |
24 | | |
25 | | #include "common/status.h" |
26 | | |
27 | | namespace doris::kerberos { |
28 | | |
29 | | // Interface for krb5 operations, can be mocked for testing |
30 | | class Krb5Interface { |
31 | | public: |
32 | 6 | virtual ~Krb5Interface() = default; |
33 | | |
34 | | virtual Status init_context(krb5_context* context) = 0; |
35 | | virtual Status parse_name(krb5_context context, const char* name, |
36 | | krb5_principal* principal) = 0; |
37 | | virtual Status kt_resolve(krb5_context context, const char* name, krb5_keytab* keytab) = 0; |
38 | | virtual Status cc_resolve(krb5_context context, const char* name, krb5_ccache* ccache) = 0; |
39 | | virtual Status get_init_creds_opt_alloc(krb5_context context, |
40 | | krb5_get_init_creds_opt** opt) = 0; |
41 | | virtual Status get_init_creds_keytab(krb5_context context, krb5_creds* creds, |
42 | | krb5_principal client, krb5_keytab keytab, |
43 | | krb5_deltat start, const char* in_tkt_service, |
44 | | krb5_get_init_creds_opt* options) = 0; |
45 | | virtual Status cc_initialize(krb5_context context, krb5_ccache cache, |
46 | | krb5_principal principal) = 0; |
47 | | virtual Status cc_store_cred(krb5_context context, krb5_ccache cache, krb5_creds* creds) = 0; |
48 | | virtual Status timeofday(krb5_context context, krb5_timestamp* timeret) = 0; |
49 | | virtual Status cc_start_seq_get(krb5_context context, krb5_ccache cache, |
50 | | krb5_cc_cursor* cursor) = 0; |
51 | | virtual Status cc_next_cred(krb5_context context, krb5_ccache cache, krb5_cc_cursor* cursor, |
52 | | krb5_creds* creds) = 0; |
53 | | |
54 | | virtual void cc_end_seq_get(krb5_context context, krb5_ccache cache, |
55 | | krb5_cc_cursor* cursor) = 0; |
56 | | virtual void free_principal(krb5_context context, krb5_principal principal) = 0; |
57 | | virtual void free_cred_contents(krb5_context context, krb5_creds* creds) = 0; |
58 | | virtual void get_init_creds_opt_free(krb5_context context, krb5_get_init_creds_opt* opt) = 0; |
59 | | virtual void kt_close(krb5_context context, krb5_keytab keytab) = 0; |
60 | | virtual void cc_close(krb5_context context, krb5_ccache cache) = 0; |
61 | | virtual void free_context(krb5_context context) = 0; |
62 | | virtual const char* get_error_message(krb5_context context, krb5_error_code code) = 0; |
63 | | virtual void free_error_message(krb5_context context, const char* message) = 0; |
64 | | virtual Status unparse_name(krb5_context context, krb5_principal principal, char** name) = 0; |
65 | | virtual void free_unparsed_name(krb5_context context, char* name) = 0; |
66 | | }; |
67 | | |
68 | | // Factory to create Krb5Interface instances |
69 | | class Krb5InterfaceFactory { |
70 | | public: |
71 | | static std::unique_ptr<Krb5Interface> create(); |
72 | | }; |
73 | | |
74 | | } // namespace doris::kerberos |