make mark-cstyle
[krb5.git] / src / kdc / policy.c
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * kdc/policy.c
4  *
5  * Copyright 1990 by the Massachusetts Institute of Technology.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  *
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  *
26  *
27  * Policy decision routines for KDC.
28  */
29 /*
30  * Copyright (c) 2006-2008, Novell, Inc.
31  * All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions are met:
35  *
36  *   * Redistributions of source code must retain the above copyright notice,
37  *       this list of conditions and the following disclaimer.
38  *   * Redistributions in binary form must reproduce the above copyright
39  *       notice, this list of conditions and the following disclaimer in the
40  *       documentation and/or other materials provided with the distribution.
41  *   * The copyright holder's name is not used to endorse or promote products
42  *       derived from this software without specific prior written permission.
43  *
44  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
45  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
48  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54  * POSSIBILITY OF SUCH DAMAGE.
55  */
56
57 #include "k5-int.h"
58 #include "kdc_util.h"
59 #include "extern.h"
60
61 int
62 against_local_policy_as(register krb5_kdc_req *request, krb5_db_entry client,
63                         krb5_db_entry server, krb5_timestamp kdc_time,
64                         const char **status, krb5_data *e_data)
65 {
66     krb5_error_code             code;
67     kdb_check_policy_as_req     req;
68     kdb_check_policy_as_rep     rep;
69     krb5_data                   req_data;
70     krb5_data                   rep_data;
71
72 #if 0
73     /* An AS request must include the addresses field */
74     if (request->addresses == 0) {
75         *status = "NO ADDRESS";
76         return KRB5KDC_ERR_POLICY;
77     }
78 #endif
79
80     memset(&req, 0, sizeof(req));
81     memset(&rep, 0, sizeof(rep));
82
83     req.request                 = request;
84     req.client                  = &client;
85     req.server                  = &server;
86     req.kdc_time                = kdc_time;
87
88     req_data.data = (void *)&req;
89     req_data.length = sizeof(req);
90
91     rep_data.data = (void *)&rep;
92     rep_data.length = sizeof(rep);
93
94     code = krb5_db_invoke(kdc_context,
95                           KRB5_KDB_METHOD_CHECK_POLICY_AS,
96                           &req_data,
97                           &rep_data);
98     if (code == KRB5_KDB_DBTYPE_NOSUP)
99         return 0;
100
101     *status = rep.status;
102     *e_data = rep.e_data;
103
104     if (code != 0) {
105         code -= ERROR_TABLE_BASE_krb5;
106         if (code < 0 || code > 128)
107             code = KRB_ERR_GENERIC;
108     }
109
110     return code;
111 }
112
113 /*
114  * This is where local policy restrictions for the TGS should placed.
115  */
116 krb5_error_code
117 against_local_policy_tgs(register krb5_kdc_req *request, krb5_db_entry server,
118                          krb5_ticket *ticket, const char **status,
119                          krb5_data *e_data)
120 {
121     krb5_error_code             code;
122     kdb_check_policy_tgs_req    req;
123     kdb_check_policy_tgs_rep    rep;
124     krb5_data                   req_data;
125     krb5_data                   rep_data;
126
127 #if 0
128     /*
129      * For example, if your site wants to disallow ticket forwarding,
130      * you might do something like this:
131      */
132
133     if (isflagset(request->kdc_options, KDC_OPT_FORWARDED)) {
134         *status = "FORWARD POLICY";
135         return KRB5KDC_ERR_POLICY;
136     }
137 #endif
138
139     memset(&req, 0, sizeof(req));
140     memset(&rep, 0, sizeof(rep));
141
142     req.request                 = request;
143     req.server                  = &server;
144     req.ticket                  = ticket;
145
146     req_data.data = (void *)&req;
147     req_data.length = sizeof(req);
148
149     rep_data.data = (void *)&rep;
150     rep_data.length = sizeof(rep);
151
152     code = krb5_db_invoke(kdc_context,
153                           KRB5_KDB_METHOD_CHECK_POLICY_TGS,
154                           &req_data,
155                           &rep_data);
156     if (code == KRB5_KDB_DBTYPE_NOSUP)
157         return 0;
158
159     *status = rep.status;
160     *e_data = rep.e_data;
161
162     if (code != 0) {
163         code -= ERROR_TABLE_BASE_krb5;
164         if (code < 0 || code > 128)
165             code = KRB_ERR_GENERIC;
166     }
167
168     return code;
169 }