Account lockout
[krb5.git] / src / plugins / kdb / db2 / kdb_db2.h
1 /*
2  * lib/kdb/kdb_db2.h
3  *
4  * Copyright 1997 by the Massachusetts Institute of Technology.
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  * 
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  * 
26  *
27  * KDC Database backend definitions for Berkely DB.
28  */
29 #ifndef KRB5_KDB_DB2_H
30 #define KRB5_KDB_DB2_H
31
32 #include "policy_db.h"
33
34 typedef struct _krb5_db2_context {
35     krb5_boolean        db_inited;      /* Context initialized          */
36     char *              db_name;        /* Name of database             */
37     DB *                db;             /* DB handle                    */
38     krb5_boolean        hashfirst;      /* Try hash database type first */
39     char *              db_lf_name;     /* Name of lock file            */
40     int                 db_lf_file;     /* File descriptor of lock file */
41     time_t              db_lf_time;     /* Time last updated            */
42     int                 db_locks_held;  /* Number of times locked       */
43     int                 db_lock_mode;   /* Last lock mode, e.g. greatest*/
44     krb5_boolean        db_nb_locks;    /* [Non]Blocking lock modes     */
45     krb5_keyblock      *db_master_key; /* Master key of database */
46     krb5_keylist_node *db_master_key_list;  /* Master key list of database */
47     osa_adb_policy_t    policy_db;
48     krb5_boolean tempdb;
49 } krb5_db2_context;
50
51 #define KRB5_DB2_MAX_RETRY 5
52
53 #define KDB2_LOCK_EXT ".ok"
54 #define KDB2_TEMP_LOCK_EXT "~.ok"
55
56 krb5_error_code krb5_db2_db_init 
57         (krb5_context);
58 krb5_error_code krb5_db2_db_fini 
59         (krb5_context);
60 krb5_error_code krb5_db2_db_get_age 
61         (krb5_context,
62                    char *,
63                    time_t * );
64 krb5_error_code krb5_db2_db_create 
65         (krb5_context,
66                    char *,
67                    krb5_int32);
68 krb5_error_code krb5_db2_db_destroy 
69         (krb5_context,
70                    char * );
71 krb5_error_code krb5_db2_db_rename 
72         (krb5_context,
73                    char *,
74                    char *,
75                    int );
76 krb5_error_code krb5_db2_db_get_principal 
77         (krb5_context,
78                    krb5_const_principal,
79                    krb5_db_entry *,
80                    int *,
81                    krb5_boolean * );
82 krb5_error_code krb5_db2_db_free_principal 
83         (krb5_context,
84                    krb5_db_entry *,
85                    int );
86 krb5_error_code krb5_db2_db_put_principal 
87         (krb5_context,
88          krb5_db_entry *,
89          int *,
90          char **db_args
91          );
92 krb5_error_code krb5_db2_db_iterate_ext
93         (krb5_context,
94                    krb5_error_code (*) (krb5_pointer,
95                                                   krb5_db_entry *),
96                    krb5_pointer, int, int );
97 krb5_error_code krb5_db2_db_iterate
98 (krb5_context,char *,
99                    krb5_error_code (*) (krb5_pointer,
100                                                   krb5_db_entry *),
101                    krb5_pointer );
102 krb5_error_code krb5_db2_db_set_nonblocking 
103         (krb5_context,
104                    krb5_boolean,
105                    krb5_boolean * );
106 krb5_boolean krb5_db2_db_set_lockmode
107         (krb5_context,
108                    krb5_boolean );
109 krb5_error_code krb5_db2_db_open_database 
110         (krb5_context);
111 krb5_error_code krb5_db2_db_close_database 
112         (krb5_context);
113
114 krb5_error_code 
115 krb5_db2_set_master_key_ext ( krb5_context kcontext, 
116                               char *pwd, 
117                               krb5_keyblock *key);
118
119 krb5_error_code
120 krb5_db2_db_set_mkey( krb5_context context,
121                       krb5_keyblock *key);
122
123 krb5_error_code
124 krb5_db2_db_get_mkey( krb5_context context,
125                       krb5_keyblock **key);
126 krb5_error_code
127 krb5_db2_db_set_mkey_list( krb5_context context,
128                       krb5_keylist_node *keylist);
129
130 krb5_error_code
131 krb5_db2_db_get_mkey_list( krb5_context context,
132                       krb5_keylist_node **keylist);
133
134 krb5_error_code
135 krb5_db2_db_put_principal( krb5_context context,
136                            krb5_db_entry *entries,
137                            register int *nentries,
138                            char **db_args);
139
140 krb5_error_code
141 krb5_db2_db_delete_principal(krb5_context context,
142                              krb5_const_principal searchfor,
143                              int *nentries);
144
145 krb5_error_code krb5_db2_lib_init(void);
146
147 krb5_error_code krb5_db2_lib_cleanup(void);
148
149 krb5_error_code 
150 krb5_db2_db_unlock(krb5_context);
151
152 krb5_error_code
153 krb5_db2_promote_db(krb5_context kcontext,
154                     char *conf_section,
155                     char **db_args);
156
157 krb5_error_code 
158 krb5_db2_db_set_option ( krb5_context kcontext, 
159                          int option, 
160                          void *value );
161
162 krb5_error_code
163 krb5_db2_db_lock( krb5_context    context,
164                   int             in_mode);
165
166
167 krb5_error_code 
168 krb5_db2_open( krb5_context kcontext,
169                                char *conf_section,
170                                char **db_args,
171                                int mode );
172
173 krb5_error_code krb5_db2_create( krb5_context kcontext,
174                                  char *conf_section,
175                                  char **db_args );
176
177 krb5_error_code krb5_db2_destroy( krb5_context kcontext,
178                                   char *conf_section,
179                                   char **db_args );
180
181 const char * krb5_db2_err2str( krb5_context kcontext,
182                                long err_code );
183
184 void * 
185 krb5_db2_alloc( krb5_context kcontext,  
186                 void *ptr, 
187                 size_t size );
188
189 void 
190 krb5_db2_free( krb5_context kcontext, 
191                     void *ptr );
192
193
194
195
196
197 /* policy management functions */
198 krb5_error_code
199 krb5_db2_create_policy(krb5_context context, osa_policy_ent_t entry);
200
201 krb5_error_code krb5_db2_get_policy ( krb5_context kcontext,
202                                       char *name,
203                                       osa_policy_ent_t *policy,
204                                       int *cnt);
205
206 krb5_error_code krb5_db2_put_policy ( krb5_context kcontext,
207                                       osa_policy_ent_t policy );
208
209 krb5_error_code krb5_db2_iter_policy ( krb5_context kcontext,
210                                        char *match_entry,
211                                        osa_adb_iter_policy_func func,
212                                        void *data );
213
214 krb5_error_code krb5_db2_delete_policy ( krb5_context kcontext,
215                                          char *policy );
216
217 void krb5_db2_free_policy( krb5_context kcontext,
218                            osa_policy_ent_t entry );
219
220 /* Thread-safety wrapper slapped on top of original implementation.  */
221 extern k5_mutex_t *krb5_db2_mutex;
222
223 /* lockout */
224 krb5_error_code
225 krb5_db2_lockout_check_policy(krb5_context context,
226                               krb5_db_entry *entry,
227                               krb5_timestamp stamp);
228
229 krb5_error_code
230 krb5_db2_lockout_audit(krb5_context context,
231                        krb5_db_entry *entry,
232                        krb5_timestamp stamp,
233                        krb5_error_code status);
234
235 /* methods */
236 krb5_error_code
237 krb5_db2_invoke(krb5_context context,
238                 unsigned int method,
239                 const krb5_data *req,
240                 krb5_data *rep);
241
242 #endif /* KRB5_KDB_DB2_H */