]>
Commit | Line | Data |
---|---|---|
2d21ac55 | 1 | /* |
3e170ce0 | 2 | * Copyright (c) 2007-2015 Apple Inc. All rights reserved. |
2d21ac55 A |
3 | * |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #ifndef _NFS_NFS_GSS_H_ | |
30 | #define _NFS_NFS_GSS_H_ | |
31 | ||
39037602 | 32 | #include "gss/gss_krb5_mech.h" |
2d21ac55 | 33 | #include <gssd/gssd_mach.h> |
2d21ac55 | 34 | #include <sys/param.h> |
39236c6e | 35 | #include <nfs/nfs_ioctl.h> |
2d21ac55 A |
36 | |
37 | #define RPCSEC_GSS 6 | |
38 | #define RPCSEC_GSS_VERS_1 1 | |
39 | ||
40 | enum rpcsec_gss_proc { | |
41 | RPCSEC_GSS_DATA = 0, | |
42 | RPCSEC_GSS_INIT = 1, | |
43 | RPCSEC_GSS_CONTINUE_INIT = 2, | |
44 | RPCSEC_GSS_DESTROY = 3 | |
45 | }; | |
46 | ||
47 | enum rpcsec_gss_service { | |
48 | RPCSEC_GSS_SVC_NONE = 1, // sec=krb5 | |
49 | RPCSEC_GSS_SVC_INTEGRITY = 2, // sec=krb5i | |
50 | RPCSEC_GSS_SVC_PRIVACY = 3, // sec=krb5p | |
2d21ac55 A |
51 | }; |
52 | ||
6d2010ae | 53 | /* encoded krb5 OID */ |
39037602 | 54 | extern u_char krb5_mech_oid[11]; |
6d2010ae | 55 | |
39236c6e | 56 | |
2d21ac55 A |
57 | #define GSS_MAXSEQ 0x80000000 // The biggest sequence number |
58 | #define GSS_SVC_MAXCONTEXTS 500000 // Max contexts supported | |
59 | #define GSS_SVC_SEQWINDOW 256 // Server's sequence window | |
60 | #define GSS_CLNT_SEQLISTMAX 32 // Max length of req seq num list | |
2d21ac55 | 61 | |
39037602 A |
62 | #define MAX_SKEYLEN 32 |
63 | #define MAX_LUCIDLEN (sizeof (lucid_context) + MAX_SKEYLEN) | |
fe8ab488 A |
64 | #define GSS_MAX_NEG_CACHE_ENTRIES 16 |
65 | #define GSS_NEG_CACHE_TO 3 | |
66 | #define GSS_PRINT_DELAY (8 * 3600) // Wait day before printing the same error message | |
67 | ||
2d21ac55 A |
68 | /* |
69 | * The client's RPCSEC_GSS context information | |
70 | */ | |
71 | struct nfs_gss_clnt_ctx { | |
72 | lck_mtx_t *gss_clnt_mtx; | |
73 | thread_t gss_clnt_thread; // Thread creating context | |
74 | TAILQ_ENTRY(nfs_gss_clnt_ctx) gss_clnt_entries; | |
75 | uint32_t gss_clnt_flags; // Flag bits - see below | |
fe8ab488 | 76 | int32_t gss_clnt_refcnt; // Reference count |
39236c6e A |
77 | kauth_cred_t gss_clnt_cred; // Owner of this context |
78 | uint8_t *gss_clnt_principal; // Principal to use for this credential | |
79 | uint32_t gss_clnt_prinlen; // Length of principal | |
80 | gssd_nametype gss_clnt_prinnt; // Name type of principal | |
81 | char *gss_clnt_display; // display name of principal | |
2d21ac55 A |
82 | uint32_t gss_clnt_proc; // Current GSS proc for cred |
83 | uint32_t gss_clnt_seqnum; // GSS sequence number | |
84 | uint32_t gss_clnt_service; // Indicates krb5, krb5i or krb5p | |
39236c6e | 85 | uint8_t *gss_clnt_handle; // Identifies server context |
2d21ac55 | 86 | uint32_t gss_clnt_handle_len; // Size of server's ctx handle |
fe8ab488 | 87 | time_t gss_clnt_nctime; // When context was put in the negative cache |
2d21ac55 A |
88 | uint32_t gss_clnt_seqwin; // Server's seq num window |
89 | uint32_t *gss_clnt_seqbits; // Bitmap to track seq numbers in use | |
90 | mach_port_t gss_clnt_mport; // Mach port for gssd upcall | |
39037602 | 91 | uint32_t gss_clnt_verflen; // RPC verifier length from server |
39236c6e A |
92 | uint8_t *gss_clnt_verf; // RPC verifier from server |
93 | uint8_t *gss_clnt_svcname; // Service name e.g. "nfs/big.apple.com" | |
94 | uint32_t gss_clnt_svcnamlen; // Service name length | |
95 | gssd_nametype gss_clnt_svcnt; // Service name type | |
6d2010ae A |
96 | gssd_cred gss_clnt_cred_handle; // Opaque cred handle from gssd |
97 | gssd_ctx gss_clnt_context; // Opaque context handle from gssd | |
39037602 | 98 | gss_ctx_id_t gss_clnt_ctx_id; // Underlying gss context |
39236c6e | 99 | uint8_t *gss_clnt_token; // GSS token exchanged via gssd & server |
2d21ac55 | 100 | uint32_t gss_clnt_tokenlen; // Length of token |
b0d623f7 | 101 | uint32_t gss_clnt_gssd_flags; // Special flag bits to gssd |
2d21ac55 A |
102 | uint32_t gss_clnt_major; // GSS major result from gssd or server |
103 | uint32_t gss_clnt_minor; // GSS minor result from gssd or server | |
fe8ab488 | 104 | time_t gss_clnt_ptime; // When last error message was printed |
2d21ac55 A |
105 | }; |
106 | ||
107 | /* | |
108 | * gss_clnt_flags | |
109 | */ | |
110 | #define GSS_CTX_COMPLETE 0x00000001 // Context is complete | |
111 | #define GSS_CTX_INVAL 0x00000002 // Context is invalid | |
3e170ce0 | 112 | #define GSS_CTX_STICKY 0x00000004 // Context has been set by user |
39236c6e A |
113 | #define GSS_NEEDSEQ 0x00000008 // Need a sequence number |
114 | #define GSS_NEEDCTX 0x00000010 // Need the context | |
3e170ce0 | 115 | #define GSS_CTX_DESTROY 0x00000020 // Context is being destroyed, don't cache |
2d21ac55 A |
116 | |
117 | /* | |
118 | * The server's RPCSEC_GSS context information | |
119 | */ | |
120 | struct nfs_gss_svc_ctx { | |
121 | lck_mtx_t *gss_svc_mtx; | |
122 | LIST_ENTRY(nfs_gss_svc_ctx) gss_svc_entries; | |
123 | uint32_t gss_svc_handle; // Identifies server context to client | |
6d2010ae | 124 | uint32_t gss_svc_refcnt; // Reference count |
2d21ac55 A |
125 | uint32_t gss_svc_proc; // Current GSS proc from cred |
126 | uid_t gss_svc_uid; // UID of this user | |
127 | gid_t gss_svc_gids[NGROUPS]; // GIDs of this user | |
128 | uint32_t gss_svc_ngroups; // Count of gids | |
b0d623f7 | 129 | uint64_t gss_svc_incarnation; // Delete ctx if we exceed this + ttl value |
2d21ac55 A |
130 | uint32_t gss_svc_seqmax; // Current max GSS sequence number |
131 | uint32_t gss_svc_seqwin; // GSS sequence number window | |
132 | uint32_t *gss_svc_seqbits; // Bitmap to track seq numbers | |
6d2010ae | 133 | gssd_cred gss_svc_cred_handle; // Opaque cred handle from gssd |
39236c6e | 134 | gssd_ctx gss_svc_context; // Opaque context handle from gssd |
39037602 | 135 | gss_ctx_id_t gss_svc_ctx_id; // Underlying gss context |
2d21ac55 A |
136 | u_char *gss_svc_token; // GSS token exchanged via gssd & client |
137 | uint32_t gss_svc_tokenlen; // Length of token | |
2d21ac55 A |
138 | uint32_t gss_svc_major; // GSS major result from gssd |
139 | uint32_t gss_svc_minor; // GSS minor result from gssd | |
140 | }; | |
141 | ||
142 | #define SVC_CTX_HASHSZ 64 | |
143 | #define SVC_CTX_HASH(handle) ((handle) % SVC_CTX_HASHSZ) | |
144 | LIST_HEAD(nfs_gss_svc_ctx_hashhead, nfs_gss_svc_ctx); | |
145 | ||
146 | /* | |
147 | * Macros to manipulate bits in the sequence window | |
148 | */ | |
149 | #define win_getbit(bits, bit) ((bits[(bit) / 32] & (1 << (bit) % 32)) != 0) | |
150 | #define win_setbit(bits, bit) do { bits[(bit) / 32] |= (1 << (bit) % 32); } while (0) | |
151 | #define win_resetbit(bits, bit) do { bits[(bit) / 32] &= ~(1 << (bit) % 32); } while (0) | |
152 | ||
153 | /* | |
154 | * Server context stale times | |
155 | */ | |
156 | #define GSS_CTX_PEND 5 // seconds | |
157 | #define GSS_CTX_EXPIRE (8 * 3600) // seconds | |
b0d623f7 | 158 | #define GSS_CTX_TTL_MIN 1 // seconds |
2d21ac55 A |
159 | #define GSS_TIMER_PERIOD 300 // seconds |
160 | #define MSECS_PER_SEC 1000 | |
161 | ||
3e170ce0 A |
162 | #define auth_is_kerberized(auth) \ |
163 | (auth == RPCAUTH_KRB5 || \ | |
164 | auth == RPCAUTH_KRB5I || \ | |
165 | auth == RPCAUTH_KRB5P) | |
166 | ||
2d21ac55 A |
167 | __BEGIN_DECLS |
168 | ||
169 | void nfs_gss_init(void); | |
3e170ce0 | 170 | uid_t nfs_cred_getasid2uid(kauth_cred_t); |
2d21ac55 A |
171 | int nfs_gss_clnt_cred_put(struct nfsreq *, struct nfsm_chain *, mbuf_t); |
172 | int nfs_gss_clnt_verf_get(struct nfsreq *, struct nfsm_chain *, | |
173 | uint32_t, uint32_t, uint32_t *); | |
174 | void nfs_gss_clnt_rpcdone(struct nfsreq *); | |
175 | int nfs_gss_clnt_args_restore(struct nfsreq *); | |
176 | int nfs_gss_clnt_ctx_renew(struct nfsreq *); | |
177 | void nfs_gss_clnt_ctx_ref(struct nfsreq *, struct nfs_gss_clnt_ctx *); | |
178 | void nfs_gss_clnt_ctx_unref(struct nfsreq *); | |
6d2010ae | 179 | void nfs_gss_clnt_ctx_unmount(struct nfsmount *); |
3e170ce0 A |
180 | int nfs_gss_clnt_ctx_remove(struct nfsmount *, kauth_cred_t); |
181 | int nfs_gss_clnt_ctx_set_principal(struct nfsmount *, vfs_context_t, uint8_t *, uint32_t, uint32_t); | |
182 | int nfs_gss_clnt_ctx_get_principal(struct nfsmount *, vfs_context_t, struct user_nfs_gss_principal *); | |
2d21ac55 A |
183 | int nfs_gss_svc_cred_get(struct nfsrv_descript *, struct nfsm_chain *); |
184 | int nfs_gss_svc_verf_put(struct nfsrv_descript *, struct nfsm_chain *); | |
185 | int nfs_gss_svc_ctx_init(struct nfsrv_descript *, struct nfsrv_sock *, mbuf_t *); | |
186 | int nfs_gss_svc_prepare_reply(struct nfsrv_descript *, struct nfsm_chain *); | |
187 | int nfs_gss_svc_protect_reply(struct nfsrv_descript *, mbuf_t); | |
6d2010ae | 188 | void nfs_gss_svc_ctx_deref(struct nfs_gss_svc_ctx *); |
2d21ac55 A |
189 | void nfs_gss_svc_cleanup(void); |
190 | ||
191 | __END_DECLS | |
192 | #endif /* _NFS_NFS_GSS_H_ */ |