2 Unix SMB/CIFS implementation.
4 Database Glue between Samba and the KDC
6 Copyright (C) Guenther Deschner <gd@samba.org> 2014
7 Copyright (C) Andreas Schneider <asn@samba.org> 2014
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.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "lib/krb5_wrap/krb5_samba.h"
29 #include "librpc/gen_ndr/security.h"
30 #include "kdc/samba_kdc.h"
33 #define DBGC_CLASS DBGC_KERBEROS
35 static void sdb_flags_to_hdb_flags(const struct SDBFlags *s,
38 SMB_ASSERT(sizeof(struct SDBFlags) == sizeof(HDBFlags));
40 h->initial = s->initial;
41 h->forwardable = s->forwardable;
42 h->proxiable = s->proxiable;
43 h->renewable = s->renewable;
44 h->postdate = s->postdate;
45 h->server = s->server;
46 h->client = s->client;
47 h->invalid = s->invalid;
48 h->require_preauth = s->require_preauth;
49 h->change_pw = s->change_pw;
50 h->require_hwauth = s->require_hwauth;
51 h->ok_as_delegate = s->ok_as_delegate;
52 h->user_to_user = s->user_to_user;
53 h->immutable = s->immutable;
54 h->trusted_for_delegation = s->trusted_for_delegation;
55 h->allow_kerberos4 = s->allow_kerberos4;
56 h->allow_digest = s->allow_digest;
57 h->locked_out = s->locked_out;
58 h->require_pwchange = s->require_pwchange;
59 h->materialize = s->materialize;
60 h->virtual_keys = s->virtual_keys;
61 h->virtual = s->virtual;
62 h->synthetic = s->synthetic;
63 h->no_auth_data_reqd = s->no_auth_data_reqd;
64 h->auth_data_reqd = s->auth_data_reqd;
65 h->_unused25 = s->_unused25;
66 h->_unused26 = s->_unused26;
67 h->_unused27 = s->_unused27;
68 h->_unused28 = s->_unused28;
69 h->_unused29 = s->_unused29;
70 h->force_canonicalize = s->force_canonicalize;
71 h->do_not_store = s->do_not_store;
74 static int sdb_salt_to_Salt(const struct sdb_salt *s, Salt *h)
78 *h = (struct Salt) {};
81 ret = smb_krb5_copy_data_contents(&h->salt, s->salt.data, s->salt.length);
90 static int sdb_key_to_Key(const struct sdb_key *s, Key *h)
96 h->key.keytype = s->key.keytype;
97 rc = smb_krb5_copy_data_contents(&h->key.keyvalue,
99 s->key.keyvalue.length);
104 if (s->salt != NULL) {
105 h->salt = malloc(sizeof(Salt));
106 if (h->salt == NULL) {
110 rc = sdb_salt_to_Salt(s->salt,
124 static int sdb_keys_to_Keys(const struct sdb_keys *s, Keys *h)
128 *h = (struct Keys) {};
130 if (s->val != NULL) {
131 h->val = malloc(s->len * sizeof(Key));
132 if (h->val == NULL) {
135 for (i = 0; i < s->len; i++) {
136 ret = sdb_key_to_Key(&s->val[i],
150 static int sdb_keys_to_HistKeys(krb5_context context,
151 const struct sdb_keys *s,
157 for (i = 0; i < s->len; i++) {
161 ret = sdb_key_to_Key(&s->val[i], &k);
165 ret = hdb_add_history_key(context, h, kvno, &k);
175 static int sdb_event_to_Event(krb5_context context,
176 const struct sdb_event *s, Event *h)
180 *h = (struct Event) {};
182 if (s->principal != NULL) {
183 ret = krb5_copy_principal(context,
196 int sdb_entry_to_hdb_entry(krb5_context context,
197 const struct sdb_entry *s,
200 struct samba_kdc_entry *ske = s->skdc_entry;
206 if (s->principal != NULL) {
207 rc = krb5_copy_principal(context,
217 rc = sdb_keys_to_Keys(&s->keys, &h->keys);
223 rc = sdb_keys_to_HistKeys(context,
233 rc = sdb_keys_to_HistKeys(context,
242 rc = sdb_event_to_Event(context,
249 if (s->modified_by) {
250 h->modified_by = malloc(sizeof(Event));
251 if (h->modified_by == NULL) {
256 rc = sdb_event_to_Event(context,
264 if (s->valid_start != NULL) {
265 h->valid_start = malloc(sizeof(KerberosTime));
266 if (h->valid_start == NULL) {
270 *h->valid_start = *s->valid_start;
273 if (s->valid_end != NULL) {
274 h->valid_end = malloc(sizeof(KerberosTime));
275 if (h->valid_end == NULL) {
279 *h->valid_end = *s->valid_end;
282 if (s->pw_end != NULL) {
283 h->pw_end = malloc(sizeof(KerberosTime));
284 if (h->pw_end == NULL) {
288 *h->pw_end = *s->pw_end;
291 if (s->max_life != NULL) {
292 h->max_life = malloc(sizeof(*h->max_life));
293 if (h->max_life == NULL) {
297 *h->max_life = *s->max_life;
300 if (s->max_renew != NULL) {
301 h->max_renew = malloc(sizeof(*h->max_renew));
302 if (h->max_renew == NULL) {
306 *h->max_renew = *s->max_renew;
309 sdb_flags_to_hdb_flags(&s->flags, &h->flags);
311 if (s->etypes != NULL) {
312 h->etypes = malloc(sizeof(*h->etypes));
313 if (h->etypes == NULL) {
318 h->etypes->len = s->etypes->len;
320 h->etypes->val = calloc(h->etypes->len, sizeof(int));
321 if (h->etypes->val == NULL) {
326 for (i = 0; i < h->etypes->len; i++) {
327 h->etypes->val[i] = s->etypes->val[i];
331 if (s->session_etypes != NULL) {
332 h->session_etypes = malloc(sizeof(*h->session_etypes));
333 if (h->session_etypes == NULL) {
338 h->session_etypes->len = s->session_etypes->len;
340 h->session_etypes->val = calloc(h->session_etypes->len, sizeof(*h->session_etypes->val));
341 if (h->session_etypes->val == NULL) {
346 for (i = 0; i < h->session_etypes->len; ++i) {
347 h->session_etypes->val[i] = s->session_etypes->val[i];