3 * The Regents of the University of Michigan
6 * Permission is granted to use, copy, create derivative works
7 * and redistribute this software and such derivative works
8 * for any purpose, so long as the name of The University of
9 * Michigan is not used in any advertising or publicity
10 * pertaining to the use of distribution of this software
11 * without specific, written prior authorization. If the
12 * above copyright notice or any other identification of the
13 * University of Michigan is included in any copy of any
14 * portion of this software, then the disclaimer below must
17 * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
18 * FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
19 * PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY OF
20 * MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
21 * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
23 * REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
24 * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
25 * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
26 * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
27 * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
33 #endif /* HAVE_CONFIG_H */
41 #include <gssapi/gssapi.h>
47 #include "svcgssd_krb5.h"
48 #include "../mount/version.h"
52 char *supported_enctypes_filename = "/proc/fs/nfsd/supported_krb5_enctypes";
53 int parsed_num_enctypes = 0;
54 krb5_enctype *parsed_enctypes = NULL;
55 char *cached_enctypes = NULL;
57 /*==========================*/
58 /*=== Internal routines ===*/
59 /*==========================*/
62 * Parse the supported encryption type information
65 parse_enctypes(char *enctypes)
71 /* Don't parse the same string over and over... */
72 if (cached_enctypes && strcmp(cached_enctypes, enctypes) == 0)
75 /* Free any existing cached_enctypes */
76 free(cached_enctypes);
78 if (parsed_enctypes != NULL) {
79 free(parsed_enctypes);
80 parsed_enctypes = NULL;
81 parsed_num_enctypes = 0;
84 /* count the number of commas */
85 for (curr = enctypes; curr && *curr != '\0'; curr = ++comma) {
86 comma = strchr(curr, ',');
93 /* If no more commas and we're not at the end, there's one more value */
97 /* Empty string, return an error */
101 /* Allocate space for enctypes array */
102 if ((parsed_enctypes = (int *) calloc(n, sizeof(int))) == NULL) {
106 /* Now parse each value into the array */
107 for (curr = enctypes, i = 0; curr && *curr != '\0'; curr = ++comma) {
108 parsed_enctypes[i++] = atoi(curr);
109 comma = strchr(curr, ',');
114 parsed_num_enctypes = n;
115 if ((cached_enctypes = malloc(strlen(enctypes)+1)))
116 strcpy(cached_enctypes, enctypes);
122 get_kernel_supported_enctypes(void)
126 char buffer[MYBUFLEN + 1];
128 memset(buffer, '\0', sizeof(buffer));
130 s_e = fopen(supported_enctypes_filename, "r");
132 goto out_clean_parsed;
134 ret = fread(buffer, 1, MYBUFLEN, s_e);
137 goto out_clean_parsed;
140 if (parse_enctypes(buffer)) {
141 goto out_clean_parsed;
147 if (parsed_enctypes != NULL) {
148 free(parsed_enctypes);
149 parsed_num_enctypes = 0;
154 /*==========================*/
155 /*=== External routines ===*/
156 /*==========================*/
159 * Get encryption types supported by the kernel, and then
160 * call gss_krb5_set_allowable_enctypes() to limit the
161 * encryption types negotiated.
165 * -1 => there was an error
169 svcgssd_limit_krb5_enctypes(void)
171 #ifdef HAVE_SET_ALLOWABLE_ENCTYPES
172 u_int maj_stat, min_stat;
173 krb5_enctype old_kernel_enctypes[] = {
176 ENCTYPE_DES_CBC_MD4 };
177 krb5_enctype new_kernel_enctypes[] = {
178 ENCTYPE_AES256_CTS_HMAC_SHA1_96,
179 ENCTYPE_AES128_CTS_HMAC_SHA1_96,
180 ENCTYPE_DES3_CBC_SHA1,
181 ENCTYPE_ARCFOUR_HMAC,
184 ENCTYPE_DES_CBC_MD4 };
185 krb5_enctype *default_enctypes, *enctypes;
186 int default_num_enctypes, num_enctypes;
189 if (linux_version_code() < MAKE_VERSION(2, 6, 35)) {
190 default_enctypes = old_kernel_enctypes;
191 default_num_enctypes =
192 sizeof(old_kernel_enctypes) / sizeof(old_kernel_enctypes[0]);
194 default_enctypes = new_kernel_enctypes;
195 default_num_enctypes =
196 sizeof(new_kernel_enctypes) / sizeof(new_kernel_enctypes[0]);
199 get_kernel_supported_enctypes();
201 if (parsed_enctypes != NULL) {
202 enctypes = parsed_enctypes;
203 num_enctypes = parsed_num_enctypes;
204 printerr(2, "%s: Calling gss_set_allowable_enctypes with %d "
205 "enctypes from the kernel\n", __func__, num_enctypes);
207 enctypes = default_enctypes;
208 num_enctypes = default_num_enctypes;
209 printerr(2, "%s: Calling gss_set_allowable_enctypes with %d "
210 "enctypes from defaults\n", __func__, num_enctypes);
213 maj_stat = gss_set_allowable_enctypes(&min_stat, gssd_creds,
214 &krb5oid, num_enctypes, enctypes);
215 if (maj_stat != GSS_S_COMPLETE) {
216 printerr(1, "WARNING: gss_set_allowable_enctypes failed\n");
217 pgsserr("svcgssd_limit_krb5_enctypes: gss_set_allowable_enctypes",
218 maj_stat, min_stat, &krb5oid);