s3: rpc_client: Allocate struct db_context * off the local frame, as all other variab...
[Samba.git] / source4 / kdc / mit-kdb / kdb_samba_common.c
blobe89aed6aeba7dca10c523790ac9572b2f20ba5fc
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 struct mit_samba_context *ks_get_context(krb5_context kcontext)
35 void *db_ctx;
36 krb5_error_code code;
38 code = krb5_db_get_context(kcontext, &db_ctx);
39 if (code != 0) {
40 return NULL;
43 return (struct mit_samba_context *)db_ctx;
46 bool ks_data_eq_string(krb5_data d, const char *s)
48 int rc;
50 if (d.length != strlen(s) || d.length == 0) {
51 return false;
54 rc = memcmp(d.data, s, d.length);
55 if (rc != 0) {
56 return false;
59 return true;
62 krb5_data ks_make_data(void *data, unsigned int len)
64 krb5_data d;
66 d.magic = KV5M_DATA;
67 d.data = data;
68 d.length = len;
70 return d;
73 krb5_boolean ks_is_kadmin(krb5_context context,
74 krb5_const_principal princ)
76 return krb5_princ_size(context, princ) >= 1 &&
77 ks_data_eq_string(princ->data[0], "kadmin");
80 krb5_boolean ks_is_kadmin_history(krb5_context context,
81 krb5_const_principal princ)
83 return krb5_princ_size(context, princ) == 2 &&
84 ks_data_eq_string(princ->data[0], "kadmin") &&
85 ks_data_eq_string(princ->data[1], "history");
88 krb5_boolean ks_is_kadmin_changepw(krb5_context context,
89 krb5_const_principal princ)
91 return krb5_princ_size(context, princ) == 2 &&
92 ks_data_eq_string(princ->data[0], "kadmin") &&
93 ks_data_eq_string(princ->data[1], "changepw");
96 krb5_boolean ks_is_kadmin_admin(krb5_context context,
97 krb5_const_principal princ)
99 return krb5_princ_size(context, princ) == 2 &&
100 ks_data_eq_string(princ->data[0], "kadmin") &&
101 ks_data_eq_string(princ->data[1], "admin");