]> eyrie.org Git - kerberos/krb5-strength.git/blob - plugin/internal.h
Refactor the CrackLib code into a separate source file
[kerberos/krb5-strength.git] / plugin / internal.h
1 /*
2  * Prototypes for the kadmin password strength checking plugin.
3  *
4  * Developed by Derrick Brashear and Ken Hornstein of Sine Nomine Associates,
5  *     on behalf of Stanford University.
6  * Extensive modifications by Russ Allbery <rra@stanford.edu>
7  * Copyright 2006, 2007, 2009, 2012, 2013
8  *     The Board of Trustees of the Leland Stanford Junior Unversity
9  *
10  * See LICENSE for licensing terms.
11  */
12
13 #ifndef PLUGIN_INTERNAL_H
14 #define PLUGIN_INTERNAL_H 1
15
16 #include <config.h>
17 #include <portable/krb5.h>
18 #include <portable/macros.h>
19
20 #ifdef HAVE_CDB_H
21 # include <cdb.h>
22 #endif
23
24 #ifdef HAVE_KRB5_PWQUAL_PLUGIN_H
25 # include <krb5/pwqual_plugin.h>
26 #else
27 typedef struct krb5_pwqual_moddata_st *krb5_pwqual_moddata;
28 #endif
29
30 /* Error strings returned (and displayed to the user) for various failures. */
31 #define ERROR_ASCII    "password contains non-ASCII or control characters"
32 #define ERROR_DICT     "password is based on a dictionary word"
33 #define ERROR_LETTER   "password is only letters and spaces"
34 #define ERROR_SHORT    "password is too short"
35 #define ERROR_USERNAME "password based on username"
36
37 /*
38  * MIT Kerberos uses this type as an abstract data type for any data that a
39  * password quality check needs to carry.  Reuse it since then we get type
40  * checking for at least the MIT plugin.
41  */
42 struct krb5_pwqual_moddata_st {
43     long min_length;            /* Minimum password length */
44     bool ascii;                 /* Whether to require printable ASCII */
45     bool nonletter;             /* Whether to require a non-letter */
46     char *dictionary;           /* Base path to CrackLib dictionary */
47     bool have_cdb;              /* Whether we have a CDB dictionary */
48     int cdb_fd;                 /* File descriptor of CDB dictionary */
49 #ifdef HAVE_CDB_H
50     struct cdb cdb;             /* Open CDB dictionary data */
51 #endif
52 };
53
54 BEGIN_DECLS
55
56 /* Default to a hidden visibility for all internal functions. */
57 #pragma GCC visibility push(hidden)
58
59 /* Initialize the plugin and set up configuration. */
60 krb5_error_code strength_init(krb5_context, const char *dictionary,
61                               krb5_pwqual_moddata *);
62
63 /* Initialize the internal data used by the CDB dictionary checks. */
64 krb5_error_code strength_init_cdb(krb5_context, krb5_pwqual_moddata,
65                                   const char *dictionary);
66
67 /* Initialize the internal data used by the CrackLib dictionary checks. */
68 krb5_error_code strength_init_cracklib(krb5_context, krb5_pwqual_moddata);
69
70 /*
71  * Check a password.  Returns 0 if okay.  On error, sets the Kerberos error
72  * message and returns a Kerberos status code.
73  */
74 krb5_error_code strength_check(krb5_context, krb5_pwqual_moddata,
75                                const char *password, const char *principal);
76
77 /* Check a password (and some permutations) against a CDB database. */
78 krb5_error_code strength_check_cdb(krb5_context, krb5_pwqual_moddata,
79                                    const char *password);
80
81 /* Check a password using CrackLib. */
82 krb5_error_code strength_check_cracklib(krb5_context, krb5_pwqual_moddata,
83                                         const char *password);
84
85 /* Finished checking passwords.  Free internal data. */
86 void strength_close(krb5_context, krb5_pwqual_moddata);
87
88 /* Free the subset of internal data used by the CDB dictionary checks. */
89 void strength_close_cdb(krb5_context, krb5_pwqual_moddata);
90
91 /*
92  * Store a particular password quality error in the Kerberos context.  The
93  * _system variant uses errno for the error code and appends the strerror
94  * results to the message.  All versions return the error code set.
95  */
96 krb5_error_code strength_error_class(krb5_context, const char *format, ...)
97     __attribute__((__nonnull__, __format__(printf, 2, 3)));
98 krb5_error_code strength_error_dict(krb5_context, const char *format, ...)
99     __attribute__((__nonnull__, __format__(printf, 2, 3)));
100 krb5_error_code strength_error_generic(krb5_context, const char *format, ...)
101     __attribute__((__nonnull__, __format__(printf, 2, 3)));
102 krb5_error_code strength_error_system(krb5_context, const char *format, ...)
103     __attribute__((__nonnull__, __format__(printf, 2, 3)));
104 krb5_error_code strength_error_tooshort(krb5_context, const char *format, ...)
105     __attribute__((__nonnull__, __format__(printf, 2, 3)));
106
107 /* Undo default visibility change. */
108 #pragma GCC visibility pop
109
110 END_DECLS
111
112 #endif /* !PLUGIN_INTERNAL_H */