xref: /freebsd/crypto/krb5/src/kadmin/server/auth_self.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /* kadmin/server/auth_self.c - self-service kadm5_auth module */
3*7f2fe78bSCy Schubert /*
4*7f2fe78bSCy Schubert  * Copyright (C) 2017 by the Massachusetts Institute of Technology.
5*7f2fe78bSCy Schubert  * All rights reserved.
6*7f2fe78bSCy Schubert  *
7*7f2fe78bSCy Schubert  * Redistribution and use in source and binary forms, with or without
8*7f2fe78bSCy Schubert  * modification, are permitted provided that the following conditions
9*7f2fe78bSCy Schubert  * are met:
10*7f2fe78bSCy Schubert  *
11*7f2fe78bSCy Schubert  * * Redistributions of source code must retain the above copyright
12*7f2fe78bSCy Schubert  *   notice, this list of conditions and the following disclaimer.
13*7f2fe78bSCy Schubert  *
14*7f2fe78bSCy Schubert  * * Redistributions in binary form must reproduce the above copyright
15*7f2fe78bSCy Schubert  *   notice, this list of conditions and the following disclaimer in
16*7f2fe78bSCy Schubert  *   the documentation and/or other materials provided with the
17*7f2fe78bSCy Schubert  *   distribution.
18*7f2fe78bSCy Schubert  *
19*7f2fe78bSCy Schubert  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20*7f2fe78bSCy Schubert  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21*7f2fe78bSCy Schubert  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22*7f2fe78bSCy Schubert  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23*7f2fe78bSCy Schubert  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24*7f2fe78bSCy Schubert  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25*7f2fe78bSCy Schubert  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26*7f2fe78bSCy Schubert  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*7f2fe78bSCy Schubert  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28*7f2fe78bSCy Schubert  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29*7f2fe78bSCy Schubert  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30*7f2fe78bSCy Schubert  * OF THE POSSIBILITY OF SUCH DAMAGE.
31*7f2fe78bSCy Schubert  */
32*7f2fe78bSCy Schubert 
33*7f2fe78bSCy Schubert #include "k5-int.h"
34*7f2fe78bSCy Schubert #include <kadm5/admin.h>
35*7f2fe78bSCy Schubert #include <krb5/kadm5_auth_plugin.h>
36*7f2fe78bSCy Schubert #include "auth.h"
37*7f2fe78bSCy Schubert 
38*7f2fe78bSCy Schubert /* Authorize a principal to operate on itself.  Applies to cpw, chrand,
39*7f2fe78bSCy Schubert  * purgekeys, getprinc, and getstrs. */
40*7f2fe78bSCy Schubert static krb5_error_code
self_compare(krb5_context context,kadm5_auth_moddata data,krb5_const_principal client,krb5_const_principal target)41*7f2fe78bSCy Schubert self_compare(krb5_context context, kadm5_auth_moddata data,
42*7f2fe78bSCy Schubert              krb5_const_principal client, krb5_const_principal target)
43*7f2fe78bSCy Schubert {
44*7f2fe78bSCy Schubert     if (krb5_principal_compare(context, client, target))
45*7f2fe78bSCy Schubert         return 0;
46*7f2fe78bSCy Schubert     return KRB5_PLUGIN_NO_HANDLE;
47*7f2fe78bSCy Schubert }
48*7f2fe78bSCy Schubert 
49*7f2fe78bSCy Schubert /* Authorize a principal to get the policy record for its own policy. */
50*7f2fe78bSCy Schubert static krb5_error_code
self_getpol(krb5_context context,kadm5_auth_moddata data,krb5_const_principal client,const char * policy,const char * client_policy)51*7f2fe78bSCy Schubert self_getpol(krb5_context context, kadm5_auth_moddata data,
52*7f2fe78bSCy Schubert             krb5_const_principal client, const char *policy,
53*7f2fe78bSCy Schubert             const char *client_policy)
54*7f2fe78bSCy Schubert {
55*7f2fe78bSCy Schubert     if (client_policy != NULL && strcmp(policy, client_policy) == 0)
56*7f2fe78bSCy Schubert         return 0;
57*7f2fe78bSCy Schubert     return KRB5_PLUGIN_NO_HANDLE;
58*7f2fe78bSCy Schubert }
59*7f2fe78bSCy Schubert 
60*7f2fe78bSCy Schubert krb5_error_code
kadm5_auth_self_initvt(krb5_context context,int maj_ver,int min_ver,krb5_plugin_vtable vtable)61*7f2fe78bSCy Schubert kadm5_auth_self_initvt(krb5_context context, int maj_ver, int min_ver,
62*7f2fe78bSCy Schubert                        krb5_plugin_vtable vtable)
63*7f2fe78bSCy Schubert {
64*7f2fe78bSCy Schubert     kadm5_auth_vtable vt;
65*7f2fe78bSCy Schubert 
66*7f2fe78bSCy Schubert     if (maj_ver != 1)
67*7f2fe78bSCy Schubert         return KRB5_PLUGIN_VER_NOTSUPP;
68*7f2fe78bSCy Schubert     vt = (kadm5_auth_vtable)vtable;
69*7f2fe78bSCy Schubert     vt->name = "self";
70*7f2fe78bSCy Schubert     vt->cpw = self_compare;
71*7f2fe78bSCy Schubert     vt->chrand = self_compare;
72*7f2fe78bSCy Schubert     vt->purgekeys = self_compare;
73*7f2fe78bSCy Schubert     vt->getprinc = self_compare;
74*7f2fe78bSCy Schubert     vt->getstrs = self_compare;
75*7f2fe78bSCy Schubert     vt->getpol = self_getpol;
76*7f2fe78bSCy Schubert     return 0;
77*7f2fe78bSCy Schubert }
78