xref: /minix3/crypto/external/bsd/heimdal/dist/kcm/kcm_locl.h (revision ebfedea0ce5bbe81e252ddf32d732e40fb633fae)
1*ebfedea0SLionel Sambuc /*	$NetBSD: kcm_locl.h,v 1.1.1.2 2011/04/14 14:08:11 elric Exp $	*/
2*ebfedea0SLionel Sambuc 
3*ebfedea0SLionel Sambuc /*
4*ebfedea0SLionel Sambuc  * Copyright (c) 2005, PADL Software Pty Ltd.
5*ebfedea0SLionel Sambuc  * All rights reserved.
6*ebfedea0SLionel Sambuc  *
7*ebfedea0SLionel Sambuc  * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8*ebfedea0SLionel Sambuc  *
9*ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
10*ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
11*ebfedea0SLionel Sambuc  * are met:
12*ebfedea0SLionel Sambuc  *
13*ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
14*ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
15*ebfedea0SLionel Sambuc  *
16*ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
17*ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
18*ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
19*ebfedea0SLionel Sambuc  *
20*ebfedea0SLionel Sambuc  * 3. Neither the name of PADL Software nor the names of its contributors
21*ebfedea0SLionel Sambuc  *    may be used to endorse or promote products derived from this software
22*ebfedea0SLionel Sambuc  *    without specific prior written permission.
23*ebfedea0SLionel Sambuc  *
24*ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
25*ebfedea0SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26*ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27*ebfedea0SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
28*ebfedea0SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29*ebfedea0SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30*ebfedea0SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31*ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32*ebfedea0SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33*ebfedea0SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34*ebfedea0SLionel Sambuc  * SUCH DAMAGE.
35*ebfedea0SLionel Sambuc  */
36*ebfedea0SLionel Sambuc 
37*ebfedea0SLionel Sambuc /*
38*ebfedea0SLionel Sambuc  * Id
39*ebfedea0SLionel Sambuc  */
40*ebfedea0SLionel Sambuc 
41*ebfedea0SLionel Sambuc #ifndef __KCM_LOCL_H__
42*ebfedea0SLionel Sambuc #define __KCM_LOCL_H__
43*ebfedea0SLionel Sambuc 
44*ebfedea0SLionel Sambuc #include "headers.h"
45*ebfedea0SLionel Sambuc 
46*ebfedea0SLionel Sambuc #include <krb5/kcm.h>
47*ebfedea0SLionel Sambuc 
48*ebfedea0SLionel Sambuc #define KCM_LOG_REQUEST(_context, _client, _opcode)	do { \
49*ebfedea0SLionel Sambuc     kcm_log(1, "%s request by process %d/uid %d", \
50*ebfedea0SLionel Sambuc 	    kcm_op2string(_opcode), (_client)->pid, (_client)->uid); \
51*ebfedea0SLionel Sambuc     } while (0)
52*ebfedea0SLionel Sambuc 
53*ebfedea0SLionel Sambuc #define KCM_LOG_REQUEST_NAME(_context, _client, _opcode, _name)	do { \
54*ebfedea0SLionel Sambuc     kcm_log(1, "%s request for cache %s by process %d/uid %d", \
55*ebfedea0SLionel Sambuc 	    kcm_op2string(_opcode), (_name), (_client)->pid, (_client)->uid); \
56*ebfedea0SLionel Sambuc     } while (0)
57*ebfedea0SLionel Sambuc 
58*ebfedea0SLionel Sambuc /* Cache management */
59*ebfedea0SLionel Sambuc 
60*ebfedea0SLionel Sambuc #define KCM_FLAGS_VALID			0x0001
61*ebfedea0SLionel Sambuc #define KCM_FLAGS_USE_KEYTAB		0x0002
62*ebfedea0SLionel Sambuc #define KCM_FLAGS_RENEWABLE		0x0004
63*ebfedea0SLionel Sambuc #define KCM_FLAGS_OWNER_IS_SYSTEM	0x0008
64*ebfedea0SLionel Sambuc #define KCM_FLAGS_USE_CACHED_KEY	0x0010
65*ebfedea0SLionel Sambuc 
66*ebfedea0SLionel Sambuc #define KCM_MASK_KEY_PRESENT		( KCM_FLAGS_USE_KEYTAB | \
67*ebfedea0SLionel Sambuc 					  KCM_FLAGS_USE_CACHED_KEY )
68*ebfedea0SLionel Sambuc 
69*ebfedea0SLionel Sambuc struct kcm_ccache_data;
70*ebfedea0SLionel Sambuc struct kcm_creds;
71*ebfedea0SLionel Sambuc 
72*ebfedea0SLionel Sambuc struct kcm_default_cache {
73*ebfedea0SLionel Sambuc     uid_t uid;
74*ebfedea0SLionel Sambuc     pid_t session; /* really au_asid_t */
75*ebfedea0SLionel Sambuc     char *name;
76*ebfedea0SLionel Sambuc     struct kcm_default_cache *next;
77*ebfedea0SLionel Sambuc };
78*ebfedea0SLionel Sambuc 
79*ebfedea0SLionel Sambuc extern struct kcm_default_cache *default_caches;
80*ebfedea0SLionel Sambuc 
81*ebfedea0SLionel Sambuc struct kcm_creds {
82*ebfedea0SLionel Sambuc     kcmuuid_t uuid;
83*ebfedea0SLionel Sambuc     krb5_creds cred;
84*ebfedea0SLionel Sambuc     struct kcm_creds *next;
85*ebfedea0SLionel Sambuc };
86*ebfedea0SLionel Sambuc 
87*ebfedea0SLionel Sambuc typedef struct kcm_ccache_data {
88*ebfedea0SLionel Sambuc     char *name;
89*ebfedea0SLionel Sambuc     kcmuuid_t uuid;
90*ebfedea0SLionel Sambuc     unsigned refcnt;
91*ebfedea0SLionel Sambuc     uint16_t flags;
92*ebfedea0SLionel Sambuc     uint16_t mode;
93*ebfedea0SLionel Sambuc     uid_t uid;
94*ebfedea0SLionel Sambuc     gid_t gid;
95*ebfedea0SLionel Sambuc     pid_t session; /* really au_asid_t */
96*ebfedea0SLionel Sambuc     krb5_principal client; /* primary client principal */
97*ebfedea0SLionel Sambuc     krb5_principal server; /* primary server principal (TGS if NULL) */
98*ebfedea0SLionel Sambuc     struct kcm_creds *creds;
99*ebfedea0SLionel Sambuc     krb5_deltat tkt_life;
100*ebfedea0SLionel Sambuc     krb5_deltat renew_life;
101*ebfedea0SLionel Sambuc     int32_t kdc_offset;
102*ebfedea0SLionel Sambuc     union {
103*ebfedea0SLionel Sambuc 	krb5_keytab keytab;
104*ebfedea0SLionel Sambuc 	krb5_keyblock keyblock;
105*ebfedea0SLionel Sambuc     } key;
106*ebfedea0SLionel Sambuc     HEIMDAL_MUTEX mutex;
107*ebfedea0SLionel Sambuc     struct kcm_ccache_data *next;
108*ebfedea0SLionel Sambuc } kcm_ccache_data;
109*ebfedea0SLionel Sambuc 
110*ebfedea0SLionel Sambuc #define KCM_ASSERT_VALID(_ccache)		do { \
111*ebfedea0SLionel Sambuc     if (((_ccache)->flags & KCM_FLAGS_VALID) == 0) \
112*ebfedea0SLionel Sambuc 	krb5_abortx(context, "kcm_free_ccache_data: ccache invalid"); \
113*ebfedea0SLionel Sambuc     else if ((_ccache)->refcnt == 0) \
114*ebfedea0SLionel Sambuc 	krb5_abortx(context, "kcm_free_ccache_data: ccache refcnt == 0"); \
115*ebfedea0SLionel Sambuc     } while (0)
116*ebfedea0SLionel Sambuc 
117*ebfedea0SLionel Sambuc typedef kcm_ccache_data *kcm_ccache;
118*ebfedea0SLionel Sambuc 
119*ebfedea0SLionel Sambuc /* Event management */
120*ebfedea0SLionel Sambuc 
121*ebfedea0SLionel Sambuc typedef struct kcm_event {
122*ebfedea0SLionel Sambuc     int valid;
123*ebfedea0SLionel Sambuc     time_t fire_time;
124*ebfedea0SLionel Sambuc     unsigned fire_count;
125*ebfedea0SLionel Sambuc     time_t expire_time;
126*ebfedea0SLionel Sambuc     time_t backoff_time;
127*ebfedea0SLionel Sambuc     enum {
128*ebfedea0SLionel Sambuc 	KCM_EVENT_NONE = 0,
129*ebfedea0SLionel Sambuc 	KCM_EVENT_ACQUIRE_CREDS,
130*ebfedea0SLionel Sambuc 	KCM_EVENT_RENEW_CREDS,
131*ebfedea0SLionel Sambuc 	KCM_EVENT_DESTROY_CREDS,
132*ebfedea0SLionel Sambuc 	KCM_EVENT_DESTROY_EMPTY_CACHE
133*ebfedea0SLionel Sambuc     } action;
134*ebfedea0SLionel Sambuc     kcm_ccache ccache;
135*ebfedea0SLionel Sambuc     struct kcm_event *next;
136*ebfedea0SLionel Sambuc } kcm_event;
137*ebfedea0SLionel Sambuc 
138*ebfedea0SLionel Sambuc /* wakeup interval for event queue */
139*ebfedea0SLionel Sambuc #define KCM_EVENT_QUEUE_INTERVAL		60
140*ebfedea0SLionel Sambuc #define KCM_EVENT_DEFAULT_BACKOFF_TIME		5
141*ebfedea0SLionel Sambuc #define KCM_EVENT_MAX_BACKOFF_TIME		(12 * 60 * 60)
142*ebfedea0SLionel Sambuc 
143*ebfedea0SLionel Sambuc 
144*ebfedea0SLionel Sambuc /* Request format is  LENGTH | MAJOR | MINOR | OPERATION | request */
145*ebfedea0SLionel Sambuc /* Response format is LENGTH | STATUS | response */
146*ebfedea0SLionel Sambuc 
147*ebfedea0SLionel Sambuc typedef struct kcm_client {
148*ebfedea0SLionel Sambuc     pid_t pid;
149*ebfedea0SLionel Sambuc     uid_t uid;
150*ebfedea0SLionel Sambuc     gid_t gid;
151*ebfedea0SLionel Sambuc     pid_t session;
152*ebfedea0SLionel Sambuc } kcm_client;
153*ebfedea0SLionel Sambuc 
154*ebfedea0SLionel Sambuc #define CLIENT_IS_ROOT(client) ((client)->uid == 0)
155*ebfedea0SLionel Sambuc 
156*ebfedea0SLionel Sambuc /* Dispatch table */
157*ebfedea0SLionel Sambuc /* passed in OPERATION | ... ; returns STATUS | ... */
158*ebfedea0SLionel Sambuc typedef krb5_error_code (*kcm_method)(krb5_context, kcm_client *, kcm_operation, krb5_storage *, krb5_storage *);
159*ebfedea0SLionel Sambuc 
160*ebfedea0SLionel Sambuc struct kcm_op {
161*ebfedea0SLionel Sambuc     const char *name;
162*ebfedea0SLionel Sambuc     kcm_method method;
163*ebfedea0SLionel Sambuc };
164*ebfedea0SLionel Sambuc 
165*ebfedea0SLionel Sambuc #define DEFAULT_LOG_DEST    "0/FILE:" LOCALSTATEDIR "/log/kcmd.log"
166*ebfedea0SLionel Sambuc #define _PATH_KCM_CONF	    SYSCONFDIR "/kcm.conf"
167*ebfedea0SLionel Sambuc 
168*ebfedea0SLionel Sambuc extern krb5_context kcm_context;
169*ebfedea0SLionel Sambuc extern char *socket_path;
170*ebfedea0SLionel Sambuc extern char *door_path;
171*ebfedea0SLionel Sambuc extern size_t max_request;
172*ebfedea0SLionel Sambuc extern sig_atomic_t exit_flag;
173*ebfedea0SLionel Sambuc extern int name_constraints;
174*ebfedea0SLionel Sambuc #ifdef SUPPORT_DETACH
175*ebfedea0SLionel Sambuc extern int detach_from_console;
176*ebfedea0SLionel Sambuc #endif
177*ebfedea0SLionel Sambuc extern int launchd_flag;
178*ebfedea0SLionel Sambuc extern int disallow_getting_krbtgt;
179*ebfedea0SLionel Sambuc 
180*ebfedea0SLionel Sambuc #if 0
181*ebfedea0SLionel Sambuc extern const krb5_cc_ops krb5_kcmss_ops;
182*ebfedea0SLionel Sambuc #endif
183*ebfedea0SLionel Sambuc 
184*ebfedea0SLionel Sambuc void	kcm_service(void *, const heim_idata *, const heim_icred,
185*ebfedea0SLionel Sambuc 		    heim_ipc_complete, heim_sipc_call);
186*ebfedea0SLionel Sambuc 
187*ebfedea0SLionel Sambuc #include <krb5/kcm-protos.h>
188*ebfedea0SLionel Sambuc 
189*ebfedea0SLionel Sambuc #endif /* __KCM_LOCL_H__ */
190*ebfedea0SLionel Sambuc 
191