s3:tests: Reformat test_timestamps.sh
[Samba.git] / source4 / kdc / sdb.c
blob0b8065b4934e658c11fc5066b488831a618b48cf
1 /*
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/>.
24 #include "includes.h"
25 #include "system/kerberos.h"
26 #include "sdb.h"
27 #include "samba_kdc.h"
28 #include "lib/krb5_wrap/krb5_samba.h"
30 void sdb_key_free(struct sdb_key *k)
32 if (k == NULL) {
33 return;
37 * Passing NULL as the Kerberos context is intentional here, as
38 * both Heimdal and MIT libraries don't use the context when
39 * clearing the keyblocks.
41 krb5_free_keyblock_contents(NULL, &k->key);
43 if (k->salt) {
44 smb_krb5_free_data_contents(NULL, &k->salt->salt);
45 SAFE_FREE(k->salt);
48 ZERO_STRUCTP(k);
51 void sdb_keys_free(struct sdb_keys *keys)
53 unsigned int i;
55 if (keys == NULL) {
56 return;
59 for (i=0; i < keys->len; i++) {
60 sdb_key_free(&keys->val[i]);
63 SAFE_FREE(keys->val);
64 ZERO_STRUCTP(keys);
67 void sdb_entry_free(struct sdb_entry *s)
69 if (s->skdc_entry != NULL) {
70 s->skdc_entry->db_entry = NULL;
71 TALLOC_FREE(s->skdc_entry);
75 * Passing NULL as the Kerberos context is intentional here, as both
76 * Heimdal and MIT libraries don't use the context when clearing the
77 * principals.
79 krb5_free_principal(NULL, s->principal);
81 sdb_keys_free(&s->keys);
82 sdb_keys_free(&s->old_keys);
83 sdb_keys_free(&s->older_keys);
84 krb5_free_principal(NULL, s->created_by.principal);
85 if (s->modified_by) {
86 krb5_free_principal(NULL, s->modified_by->principal);
88 SAFE_FREE(s->valid_start);
89 SAFE_FREE(s->valid_end);
90 SAFE_FREE(s->pw_end);
92 ZERO_STRUCTP(s);
95 struct SDBFlags int2SDBFlags(unsigned n)
97 struct SDBFlags flags;
99 memset(&flags, 0, sizeof(flags));
101 flags.initial = (n >> 0) & 1;
102 flags.forwardable = (n >> 1) & 1;
103 flags.proxiable = (n >> 2) & 1;
104 flags.renewable = (n >> 3) & 1;
105 flags.postdate = (n >> 4) & 1;
106 flags.server = (n >> 5) & 1;
107 flags.client = (n >> 6) & 1;
108 flags.invalid = (n >> 7) & 1;
109 flags.require_preauth = (n >> 8) & 1;
110 flags.change_pw = (n >> 9) & 1;
111 flags.require_hwauth = (n >> 10) & 1;
112 flags.ok_as_delegate = (n >> 11) & 1;
113 flags.user_to_user = (n >> 12) & 1;
114 flags.immutable = (n >> 13) & 1;
115 flags.trusted_for_delegation = (n >> 14) & 1;
116 flags.allow_kerberos4 = (n >> 15) & 1;
117 flags.allow_digest = (n >> 16) & 1;
118 flags.locked_out = (n >> 17) & 1;
119 flags.do_not_store = (n >> 31) & 1;
120 return flags;