s4/heimdal/lib/krb5/pac.c: Align PAC buffers to match Windows
[Samba.git] / source4 / kdc / mit-kdb / kdb_samba.c
blob02bbdca9f548b90d37f2c2966f24a8f4d556bcc2
1 /*
2 Unix SMB/CIFS implementation.
4 Samba KDB plugin for MIT Kerberos
6 Copyright (c) 2010 Simo Sorce <idra@samba.org>.
7 Copyright (c) 2014 Andreas Schneider <asn@samba.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
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 for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "includes.h"
25 #include "system/kerberos.h"
27 #include <profile.h>
28 #include <kdb.h>
30 #include "kdc/mit_samba.h"
31 #include "kdb_samba.h"
33 static krb5_error_code kdb_samba_init_library(void)
35 return 0;
38 static krb5_error_code kdb_samba_fini_library(void)
40 return 0;
43 static krb5_error_code kdb_samba_init_module(krb5_context context,
44 char *conf_section,
45 char **db_args,
46 int mode)
48 /* TODO mit_samba_context_init */
49 struct mit_samba_context *mit_ctx;
50 krb5_error_code code;
51 int rc;
53 rc = mit_samba_context_init(&mit_ctx);
54 if (rc != 0) {
55 return ENOMEM;
59 code = krb5_db_set_context(context, mit_ctx);
61 return code;
63 static krb5_error_code kdb_samba_fini_module(krb5_context context)
65 struct mit_samba_context *mit_ctx;
67 mit_ctx = ks_get_context(context);
68 if (mit_ctx == NULL) {
69 return 0;
72 mit_samba_context_free(mit_ctx);
74 return 0;
77 static krb5_error_code kdb_samba_db_create(krb5_context context,
78 char *conf_section,
79 char **db_args)
81 /* NOTE: used only by kadmin */
82 return KRB5_KDB_DBTYPE_NOSUP;
85 static krb5_error_code kdb_samba_db_destroy(krb5_context context,
86 char *conf_section,
87 char **db_args)
89 /* NOTE: used only by kadmin */
90 return KRB5_KDB_DBTYPE_NOSUP;
93 static krb5_error_code kdb_samba_db_get_age(krb5_context context,
94 char *db_name,
95 time_t *age)
97 /* TODO: returns last modification time of the db */
99 /* NOTE: used by and affects only lookaside cache,
100 * defer implementation until needed as samba doesn't keep this
101 * specific value readily available and it would require a full
102 * database search to get it. */
104 *age = time(NULL);
106 return 0;
109 static krb5_error_code kdb_samba_db_lock(krb5_context context, int kmode)
112 /* NOTE: important only for kadmin */
113 /* NOTE: deferred as samba's DB cannot be easily locked and doesn't
114 * really make sense to do so anyway as the db is shared and support
115 * transactions */
116 return 0;
119 static krb5_error_code kdb_samba_db_unlock(krb5_context context)
122 /* NOTE: important only for kadmin */
123 /* NOTE: deferred as samba's DB cannot be easily locked and doesn't
124 * really make sense to do so anyway as the db is shared and support
125 * transactions */
126 return 0;
129 static void kdb_samba_db_free_principal_e_data(krb5_context context,
130 krb5_octet *e_data)
132 struct samba_kdc_entry *skdc_entry;
134 skdc_entry = talloc_get_type_abort(e_data,
135 struct samba_kdc_entry);
136 talloc_set_destructor(skdc_entry, NULL);
137 TALLOC_FREE(skdc_entry);
140 kdb_vftabl kdb_function_table = {
141 .maj_ver = KRB5_KDB_DAL_MAJOR_VERSION,
142 .min_ver = KRB5_KDB_DAL_MAJOR_VERSION == 6 ? 1 : 0,
144 .init_library = kdb_samba_init_library,
145 .fini_library = kdb_samba_fini_library,
146 .init_module = kdb_samba_init_module,
147 .fini_module = kdb_samba_fini_module,
149 .create = kdb_samba_db_create,
150 .destroy = kdb_samba_db_destroy,
151 .get_age = kdb_samba_db_get_age,
152 .lock = kdb_samba_db_lock,
153 .unlock = kdb_samba_db_unlock,
155 .get_principal = kdb_samba_db_get_principal,
156 .put_principal = kdb_samba_db_put_principal,
157 .delete_principal = kdb_samba_db_delete_principal,
159 .iterate = kdb_samba_db_iterate,
161 .fetch_master_key = kdb_samba_fetch_master_key,
162 .fetch_master_key_list = kdb_samba_fetch_master_key_list,
164 .change_pwd = kdb_samba_change_pwd,
166 .decrypt_key_data = kdb_samba_dbekd_decrypt_key_data,
167 .encrypt_key_data = kdb_samba_dbekd_encrypt_key_data,
169 .sign_authdata = kdb_samba_db_sign_auth_data,
170 .check_policy_as = kdb_samba_db_check_policy_as,
171 .audit_as_req = kdb_samba_db_audit_as_req,
172 .check_allowed_to_delegate = kdb_samba_db_check_allowed_to_delegate,
174 .free_principal_e_data = kdb_samba_db_free_principal_e_data,