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_CLASS_LOWER "Password must contain a lowercase letter"
37 #define ERROR_CLASS_UPPER "Password must contain an uppercase letter"
38 #define ERROR_CLASS_DIGIT "Password must contain a number"
39 #define ERROR_CLASS_SYMBOL \
40 "Password must contain a space or punctuation character"
41 #define ERROR_CLASS_MIN \
42 "Password must contain %lu types of characters (lowercase, uppercase," \
44 #define ERROR_DICT "Password found in list of common passwords"
45 #define ERROR_LETTER "Password is only letters and spaces"
46 #define ERROR_MINDIFF "Password does not contain enough unique characters"
47 #define ERROR_SHORT "Password is too short"
48 #define ERROR_USERNAME "Password based on username or principal"
51 * A character class rule, which consists of a minimum length to which the
52 * rule is applied, a maximum length to which the rule is applied, and a set
53 * of flags for which character classes are required. The symbol class
54 * includes everything that isn't in one of the other classes, including
64 unsigned long num_classes;
65 struct class_rule *next;
68 /* Used to store a list of strings, managed by the sync_vector_* functions. */
76 * MIT Kerberos uses this type as an abstract data type for any data that a
77 * password quality check needs to carry. Reuse it since then we get type
78 * checking for at least the MIT plugin.
80 struct krb5_pwqual_moddata_st {
81 long minimum_different; /* Minimum number of different characters */
82 long minimum_length; /* Minimum password length */
83 bool ascii; /* Whether to require printable ASCII */
84 bool nonletter; /* Whether to require a non-letter */
85 struct class_rule *rules; /* Linked list of character class rules */
86 char *dictionary; /* Base path to CrackLib dictionary */
87 long cracklib_maxlen; /* Longer passwords skip CrackLib checks */
88 bool have_cdb; /* Whether we have a CDB dictionary */
89 int cdb_fd; /* File descriptor of CDB dictionary */
91 struct cdb cdb; /* Open CDB dictionary data */
94 sqlite3 *sqlite; /* Open SQLite database handle */
95 sqlite3_stmt *prefix_query; /* Query using the password prefix */
96 sqlite3_stmt *suffix_query; /* Query using the reversed password suffix */
102 /* Default to a hidden visibility for all internal functions. */
103 #pragma GCC visibility push(hidden)
105 /* Initialize the plugin and set up configuration. */
106 krb5_error_code strength_init(krb5_context, const char *dictionary,
107 krb5_pwqual_moddata *);
110 * Check a password. Returns 0 if okay. On error, sets the Kerberos error
111 * message and returns a Kerberos status code.
113 krb5_error_code strength_check(krb5_context, krb5_pwqual_moddata,
114 const char *principal, const char *password);
116 /* Free the internal plugin state. */
117 void strength_close(krb5_context, krb5_pwqual_moddata);
120 * CDB handling. strength_init_cdb gets the dictionary configuration and sets
121 * up the CDB database, strength_check_cdb checks it, and strength_close_cdb
122 * handles freeing resources.
124 * If not built with CDB support, provide some stubs for check and close.
125 * init is always a real function, which reports an error if CDB is
126 * requested and not available.
128 krb5_error_code strength_init_cdb(krb5_context, krb5_pwqual_moddata);
130 krb5_error_code strength_check_cdb(krb5_context, krb5_pwqual_moddata,
131 const char *password);
132 void strength_close_cdb(krb5_context, krb5_pwqual_moddata);
134 # define strength_check_cdb(c, d, p) 0
135 # define strength_close_cdb(c, d) /* empty */
139 * CrackLib handling. strength_init_cracklib gets the dictionary
140 * configuration does some sanity checks on it, and strength_check_cracklib
141 * checks the password against CrackLib.
143 krb5_error_code strength_init_cracklib(krb5_context, krb5_pwqual_moddata,
144 const char *dictionary);
145 krb5_error_code strength_check_cracklib(krb5_context, krb5_pwqual_moddata,
146 const char *password);
149 * SQLite handling. strength_init_sqlite gets the database configuration and
150 * sets up the SQLite internal data, strength_check_sqlite checks a password,
151 * and strength_close_sqlite handles freeing resources.
153 * If not built with SQLite support, provide some stubs for check and close.
154 * init is always a real function, which reports an error if SQLite is
155 * requested and not available.
157 krb5_error_code strength_init_sqlite(krb5_context, krb5_pwqual_moddata);
159 krb5_error_code strength_check_sqlite(krb5_context, krb5_pwqual_moddata,
160 const char *password);
161 void strength_close_sqlite(krb5_context, krb5_pwqual_moddata);
163 # define strength_check_sqlite(c, d, p) 0
164 # define strength_close_sqlite(c, d) /* empty */
167 /* Check whether the password statisfies character class requirements. */
168 krb5_error_code strength_check_classes(krb5_context, krb5_pwqual_moddata,
169 const char *password);
171 /* Check whether the password is based on the principal in some way. */
172 krb5_error_code strength_check_principal(krb5_context, krb5_pwqual_moddata,
173 const char *principal,
174 const char *password);
177 * Manage vectors, which are counted lists of strings. The functions that
178 * return a boolean return false if memory allocation fails.
180 struct vector *strength_vector_new(void)
181 __attribute__((__malloc__));
182 bool strength_vector_add(struct vector *, const char *string)
183 __attribute__((__nonnull__));
184 void strength_vector_free(struct vector *);
187 * vector_split_multi splits on a set of characters. If the vector argument
188 * is NULL, a new vector is allocated; otherwise, the provided one is reused.
189 * Returns NULL on memory allocation failure, after which the provided vector
190 * may have been modified to only have partial results.
192 * Empty strings will yield zero-length vectors. Adjacent delimiters are
193 * treated as a single delimiter by vector_split_multi. Any leading or
194 * trailing delimiters are ignored, so this function will never create
195 * zero-length strings (similar to the behavior of strtok).
197 struct vector *strength_vector_split_multi(const char *string,
198 const char *seps, struct vector *)
199 __attribute__((__nonnull__(1, 2)));
202 * Obtain configuration settings from krb5.conf. These are wrappers around
203 * the krb5_appdefault_* APIs that handle setting the section name, obtaining
204 * the local default realm and using it to find settings, and doing any
205 * necessary conversion.
207 void strength_config_boolean(krb5_context, const char *, bool *)
208 __attribute__((__nonnull__));
209 krb5_error_code strength_config_list(krb5_context, const char *,
211 __attribute__((__nonnull__));
212 void strength_config_number(krb5_context, const char *, long *)
213 __attribute__((__nonnull__));
214 void strength_config_string(krb5_context, const char *, char **)
215 __attribute__((__nonnull__));
217 /* Parse the more complex configuration of required character classes. */
218 krb5_error_code strength_config_classes(krb5_context, const char *,
219 struct class_rule **)
220 __attribute__((__nonnull__));
223 * Store a particular password quality error in the Kerberos context. The
224 * _system variant uses errno for the error code and appends the strerror
225 * results to the message. All versions return the error code set.
227 krb5_error_code strength_error_class(krb5_context, const char *format, ...)
228 __attribute__((__nonnull__, __format__(printf, 2, 3)));
229 krb5_error_code strength_error_config(krb5_context, const char *format, ...)
230 __attribute__((__nonnull__, __format__(printf, 2, 3)));
231 krb5_error_code strength_error_dict(krb5_context, const char *format, ...)
232 __attribute__((__nonnull__, __format__(printf, 2, 3)));
233 krb5_error_code strength_error_generic(krb5_context, const char *format, ...)
234 __attribute__((__nonnull__, __format__(printf, 2, 3)));
235 krb5_error_code strength_error_system(krb5_context, const char *format, ...)
236 __attribute__((__nonnull__, __format__(printf, 2, 3)));
237 krb5_error_code strength_error_tooshort(krb5_context, const char *format, ...)
238 __attribute__((__nonnull__, __format__(printf, 2, 3)));
240 /* Undo default visibility change. */
241 #pragma GCC visibility pop
245 #endif /* !PLUGIN_INTERNAL_H */