2 * Prototypes for the kadmin password strength checking plugin.
4 * Developed by Derrick Brashear and Ken Hornstein of Sine Nomine Associates,
5 * on behalf of Stanford University
6 * Extensive modifications by Russ Allbery <eagle@eyrie.org>
7 * Copyright 2006, 2007, 2009, 2012, 2013, 2014
8 * The Board of Trustees of the Leland Stanford Junior University
10 * See LICENSE for licensing terms.
13 #ifndef PLUGIN_INTERNAL_H
14 #define PLUGIN_INTERNAL_H 1
17 #include <portable/krb5.h>
18 #include <portable/macros.h>
28 #ifdef HAVE_KRB5_PWQUAL_PLUGIN_H
29 # include <krb5/pwqual_plugin.h>
31 typedef struct krb5_pwqual_moddata_st *krb5_pwqual_moddata;
34 /* Error strings returned (and displayed to the user) for various failures. */
35 #define ERROR_ASCII "password contains non-ASCII or control characters"
36 #define ERROR_DICT "password found in list of common passwords"
37 #define ERROR_LETTER "password is only letters and spaces"
38 #define ERROR_MINDIFF "password does not contain enough unique characters"
39 #define ERROR_SHORT "password is too short"
40 #define ERROR_USERNAME "password based on username or principal"
43 * A character class rule, which consists of a minimum length to which the
44 * rule is applied, a maximum length to which the rule is applied, and a set
45 * of flags for which character classes are required. The symbol class
46 * includes everything that isn't in one of the other classes, including
56 struct class_rule *next;
59 /* Used to store a list of strings, managed by the sync_vector_* functions. */
67 * MIT Kerberos uses this type as an abstract data type for any data that a
68 * password quality check needs to carry. Reuse it since then we get type
69 * checking for at least the MIT plugin.
71 struct krb5_pwqual_moddata_st {
72 long minimum_different; /* Minimum number of different characters */
73 long minimum_length; /* Minimum password length */
74 bool ascii; /* Whether to require printable ASCII */
75 bool nonletter; /* Whether to require a non-letter */
76 struct class_rule *rules; /* Linked list of character class rules */
77 char *dictionary; /* Base path to CrackLib dictionary */
78 bool have_cdb; /* Whether we have a CDB dictionary */
79 int cdb_fd; /* File descriptor of CDB dictionary */
81 struct cdb cdb; /* Open CDB dictionary data */
84 sqlite3 *sqlite; /* Open SQLite database handle */
85 sqlite3_stmt *prefix_query; /* Query using the password prefix */
86 sqlite3_stmt *suffix_query; /* Query using the reversed password suffix */
92 /* Default to a hidden visibility for all internal functions. */
93 #pragma GCC visibility push(hidden)
95 /* Initialize the plugin and set up configuration. */
96 krb5_error_code strength_init(krb5_context, const char *dictionary,
97 krb5_pwqual_moddata *);
100 * Check a password. Returns 0 if okay. On error, sets the Kerberos error
101 * message and returns a Kerberos status code.
103 krb5_error_code strength_check(krb5_context, krb5_pwqual_moddata,
104 const char *principal, const char *password);
106 /* Free the internal plugin state. */
107 void strength_close(krb5_context, krb5_pwqual_moddata);
110 * CDB handling. strength_init_cdb gets the dictionary configuration and sets
111 * up the CDB database, strength_check_cdb checks it, and strength_close_cdb
112 * handles freeing resources.
114 * If not built with CDB support, provide some stubs for check and close.
115 * init is always a real function, which reports an error if CDB is
116 * requested and not available.
118 krb5_error_code strength_init_cdb(krb5_context, krb5_pwqual_moddata);
120 krb5_error_code strength_check_cdb(krb5_context, krb5_pwqual_moddata,
121 const char *password);
122 void strength_close_cdb(krb5_context, krb5_pwqual_moddata);
124 # define strength_check_cdb(c, d, p) 0
125 # define strength_close_cdb(c, d) /* empty */
129 * CrackLib handling. strength_init_cracklib gets the dictionary
130 * configuration does some sanity checks on it, and strength_check_cracklib
131 * checks the password against CrackLib.
133 krb5_error_code strength_init_cracklib(krb5_context, krb5_pwqual_moddata,
134 const char *dictionary);
135 krb5_error_code strength_check_cracklib(krb5_context, krb5_pwqual_moddata,
136 const char *password);
139 * SQLite handling. strength_init_sqlite gets the database configuration and
140 * sets up the SQLite internal data, strength_check_sqlite checks a password,
141 * and strength_close_sqlite handles freeing resources.
143 * If not built with SQLite support, provide some stubs for check and close.
144 * init is always a real function, which reports an error if SQLite is
145 * requested and not available.
147 krb5_error_code strength_init_sqlite(krb5_context, krb5_pwqual_moddata);
149 krb5_error_code strength_check_sqlite(krb5_context, krb5_pwqual_moddata,
150 const char *password);
151 void strength_close_sqlite(krb5_context, krb5_pwqual_moddata);
153 # define strength_check_sqlite(c, d, p) 0
154 # define strength_close_sqlite(c, d) /* empty */
157 /* Check whether the password statisfies character class requirements. */
158 krb5_error_code strength_check_classes(krb5_context, krb5_pwqual_moddata,
159 const char *password);
161 /* Check whether the password is based on the principal in some way. */
162 krb5_error_code strength_check_principal(krb5_context, krb5_pwqual_moddata,
163 const char *principal,
164 const char *password);
167 * Manage vectors, which are counted lists of strings. The functions that
168 * return a boolean return false if memory allocation fails.
170 struct vector *strength_vector_new(void)
171 __attribute__((__malloc__));
172 bool strength_vector_add(struct vector *, const char *string)
173 __attribute__((__nonnull__));
174 void strength_vector_free(struct vector *);
177 * vector_split_multi splits on a set of characters. If the vector argument
178 * is NULL, a new vector is allocated; otherwise, the provided one is reused.
179 * Returns NULL on memory allocation failure, after which the provided vector
180 * may have been modified to only have partial results.
182 * Empty strings will yield zero-length vectors. Adjacent delimiters are
183 * treated as a single delimiter by vector_split_multi. Any leading or
184 * trailing delimiters are ignored, so this function will never create
185 * zero-length strings (similar to the behavior of strtok).
187 struct vector *strength_vector_split_multi(const char *string,
188 const char *seps, struct vector *)
189 __attribute__((__nonnull__(1, 2)));
192 * Obtain configuration settings from krb5.conf. These are wrappers around
193 * the krb5_appdefault_* APIs that handle setting the section name, obtaining
194 * the local default realm and using it to find settings, and doing any
195 * necessary conversion.
197 void strength_config_boolean(krb5_context, const char *, bool *)
198 __attribute__((__nonnull__));
199 krb5_error_code strength_config_list(krb5_context, const char *,
201 __attribute__((__nonnull__));
202 void strength_config_number(krb5_context, const char *, long *)
203 __attribute__((__nonnull__));
204 void strength_config_string(krb5_context, const char *, char **)
205 __attribute__((__nonnull__));
207 /* Parse the more complex configuration of required character classes. */
208 krb5_error_code strength_config_classes(krb5_context, const char *,
209 struct class_rule **)
210 __attribute__((__nonnull__));
213 * Store a particular password quality error in the Kerberos context. The
214 * _system variant uses errno for the error code and appends the strerror
215 * results to the message. All versions return the error code set.
217 krb5_error_code strength_error_class(krb5_context, const char *format, ...)
218 __attribute__((__nonnull__, __format__(printf, 2, 3)));
219 krb5_error_code strength_error_config(krb5_context, const char *format, ...)
220 __attribute__((__nonnull__, __format__(printf, 2, 3)));
221 krb5_error_code strength_error_dict(krb5_context, const char *format, ...)
222 __attribute__((__nonnull__, __format__(printf, 2, 3)));
223 krb5_error_code strength_error_generic(krb5_context, const char *format, ...)
224 __attribute__((__nonnull__, __format__(printf, 2, 3)));
225 krb5_error_code strength_error_system(krb5_context, const char *format, ...)
226 __attribute__((__nonnull__, __format__(printf, 2, 3)));
227 krb5_error_code strength_error_tooshort(krb5_context, const char *format, ...)
228 __attribute__((__nonnull__, __format__(printf, 2, 3)));
230 /* Undo default visibility change. */
231 #pragma GCC visibility pop
235 #endif /* !PLUGIN_INTERNAL_H */