xref: /freebsd/crypto/krb5/src/plugins/kdb/db2/kdb_db2.h (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /* plugins/kdb/db2/kdb_db2.h */
3*7f2fe78bSCy Schubert /*
4*7f2fe78bSCy Schubert  * Copyright 1997 by the Massachusetts Institute of Technology.
5*7f2fe78bSCy Schubert  * All Rights Reserved.
6*7f2fe78bSCy Schubert  *
7*7f2fe78bSCy Schubert  * Export of this software from the United States of America may
8*7f2fe78bSCy Schubert  *   require a specific license from the United States Government.
9*7f2fe78bSCy Schubert  *   It is the responsibility of any person or organization contemplating
10*7f2fe78bSCy Schubert  *   export to obtain such a license before exporting.
11*7f2fe78bSCy Schubert  *
12*7f2fe78bSCy Schubert  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13*7f2fe78bSCy Schubert  * distribute this software and its documentation for any purpose and
14*7f2fe78bSCy Schubert  * without fee is hereby granted, provided that the above copyright
15*7f2fe78bSCy Schubert  * notice appear in all copies and that both that copyright notice and
16*7f2fe78bSCy Schubert  * this permission notice appear in supporting documentation, and that
17*7f2fe78bSCy Schubert  * the name of M.I.T. not be used in advertising or publicity pertaining
18*7f2fe78bSCy Schubert  * to distribution of the software without specific, written prior
19*7f2fe78bSCy Schubert  * permission.  Furthermore if you modify this software you must label
20*7f2fe78bSCy Schubert  * your software as modified software and not distribute it in such a
21*7f2fe78bSCy Schubert  * fashion that it might be confused with the original M.I.T. software.
22*7f2fe78bSCy Schubert  * M.I.T. makes no representations about the suitability of
23*7f2fe78bSCy Schubert  * this software for any purpose.  It is provided "as is" without express
24*7f2fe78bSCy Schubert  * or implied warranty.
25*7f2fe78bSCy Schubert  */
26*7f2fe78bSCy Schubert 
27*7f2fe78bSCy Schubert /*
28*7f2fe78bSCy Schubert  *
29*7f2fe78bSCy Schubert  * KDC Database backend definitions for Berkely DB.
30*7f2fe78bSCy Schubert  */
31*7f2fe78bSCy Schubert #ifndef KRB5_KDB_DB2_H
32*7f2fe78bSCy Schubert #define KRB5_KDB_DB2_H
33*7f2fe78bSCy Schubert 
34*7f2fe78bSCy Schubert #include "policy_db.h"
35*7f2fe78bSCy Schubert 
36*7f2fe78bSCy Schubert typedef struct _krb5_db2_context {
37*7f2fe78bSCy Schubert     krb5_boolean        db_inited;      /* Context initialized          */
38*7f2fe78bSCy Schubert     char *              db_name;        /* Name of database             */
39*7f2fe78bSCy Schubert     DB *                db;             /* DB handle                    */
40*7f2fe78bSCy Schubert     krb5_boolean        hashfirst;      /* Try hash database type first */
41*7f2fe78bSCy Schubert     char *              db_lf_name;     /* Name of lock file            */
42*7f2fe78bSCy Schubert     int                 db_lf_file;     /* File descriptor of lock file */
43*7f2fe78bSCy Schubert     int                 db_locks_held;  /* Number of times locked       */
44*7f2fe78bSCy Schubert     int                 db_lock_mode;   /* Last lock mode, e.g. greatest*/
45*7f2fe78bSCy Schubert     krb5_boolean        db_nb_locks;    /* [Non]Blocking lock modes     */
46*7f2fe78bSCy Schubert     osa_adb_policy_t    policy_db;
47*7f2fe78bSCy Schubert     krb5_boolean        tempdb;
48*7f2fe78bSCy Schubert     krb5_boolean        disable_last_success;
49*7f2fe78bSCy Schubert     krb5_boolean        disable_lockout;
50*7f2fe78bSCy Schubert     krb5_boolean        unlockiter;
51*7f2fe78bSCy Schubert } krb5_db2_context;
52*7f2fe78bSCy Schubert 
53*7f2fe78bSCy Schubert krb5_error_code krb5_db2_init(krb5_context);
54*7f2fe78bSCy Schubert krb5_error_code krb5_db2_fini(krb5_context);
55*7f2fe78bSCy Schubert krb5_error_code krb5_db2_get_age(krb5_context, char *, time_t *);
56*7f2fe78bSCy Schubert krb5_error_code krb5_db2_get_principal(krb5_context, krb5_const_principal,
57*7f2fe78bSCy Schubert                                        unsigned int, krb5_db_entry **);
58*7f2fe78bSCy Schubert krb5_error_code krb5_db2_put_principal(krb5_context, krb5_db_entry *,
59*7f2fe78bSCy Schubert                                        char **db_args);
60*7f2fe78bSCy Schubert krb5_error_code krb5_db2_iterate(krb5_context, char *,
61*7f2fe78bSCy Schubert                                  krb5_error_code (*)(krb5_pointer,
62*7f2fe78bSCy Schubert                                                      krb5_db_entry *),
63*7f2fe78bSCy Schubert                                  krb5_pointer, krb5_flags);
64*7f2fe78bSCy Schubert krb5_error_code krb5_db2_set_nonblocking(krb5_context, krb5_boolean,
65*7f2fe78bSCy Schubert                                          krb5_boolean *);
66*7f2fe78bSCy Schubert krb5_boolean krb5_db2_set_lockmode(krb5_context, krb5_boolean);
67*7f2fe78bSCy Schubert krb5_error_code krb5_db2_open_database(krb5_context);
68*7f2fe78bSCy Schubert krb5_error_code krb5_db2_close_database(krb5_context);
69*7f2fe78bSCy Schubert 
70*7f2fe78bSCy Schubert krb5_error_code
71*7f2fe78bSCy Schubert krb5_db2_delete_principal(krb5_context context,
72*7f2fe78bSCy Schubert                           krb5_const_principal searchfor);
73*7f2fe78bSCy Schubert 
74*7f2fe78bSCy Schubert krb5_error_code krb5_db2_lib_init(void);
75*7f2fe78bSCy Schubert krb5_error_code krb5_db2_lib_cleanup(void);
76*7f2fe78bSCy Schubert krb5_error_code krb5_db2_unlock(krb5_context);
77*7f2fe78bSCy Schubert 
78*7f2fe78bSCy Schubert krb5_error_code
79*7f2fe78bSCy Schubert krb5_db2_promote_db(krb5_context kcontext, char *conf_section, char **db_args);
80*7f2fe78bSCy Schubert 
81*7f2fe78bSCy Schubert krb5_error_code
82*7f2fe78bSCy Schubert krb5_db2_lock(krb5_context context, int in_mode);
83*7f2fe78bSCy Schubert 
84*7f2fe78bSCy Schubert krb5_error_code
85*7f2fe78bSCy Schubert krb5_db2_open(krb5_context kcontext, char *conf_section, char **db_args,
86*7f2fe78bSCy Schubert               int mode);
87*7f2fe78bSCy Schubert 
88*7f2fe78bSCy Schubert krb5_error_code krb5_db2_create(krb5_context kcontext, char *conf_section,
89*7f2fe78bSCy Schubert                                 char **db_args);
90*7f2fe78bSCy Schubert 
91*7f2fe78bSCy Schubert krb5_error_code krb5_db2_destroy(krb5_context kcontext, char *conf_section,
92*7f2fe78bSCy Schubert                                  char **db_args);
93*7f2fe78bSCy Schubert 
94*7f2fe78bSCy Schubert const char *krb5_db2_err2str(krb5_context kcontext, long err_code);
95*7f2fe78bSCy Schubert 
96*7f2fe78bSCy Schubert 
97*7f2fe78bSCy Schubert /* policy management functions */
98*7f2fe78bSCy Schubert krb5_error_code
99*7f2fe78bSCy Schubert krb5_db2_create_policy(krb5_context context, osa_policy_ent_t entry);
100*7f2fe78bSCy Schubert 
101*7f2fe78bSCy Schubert krb5_error_code krb5_db2_get_policy(krb5_context kcontext,
102*7f2fe78bSCy Schubert                                     char *name, osa_policy_ent_t *policy);
103*7f2fe78bSCy Schubert 
104*7f2fe78bSCy Schubert krb5_error_code krb5_db2_put_policy(krb5_context kcontext,
105*7f2fe78bSCy Schubert                                     osa_policy_ent_t policy);
106*7f2fe78bSCy Schubert 
107*7f2fe78bSCy Schubert krb5_error_code krb5_db2_iter_policy(krb5_context kcontext, char *match_entry,
108*7f2fe78bSCy Schubert                                      osa_adb_iter_policy_func func,
109*7f2fe78bSCy Schubert                                      void *data);
110*7f2fe78bSCy Schubert 
111*7f2fe78bSCy Schubert krb5_error_code krb5_db2_delete_policy(krb5_context kcontext, char *policy);
112*7f2fe78bSCy Schubert 
113*7f2fe78bSCy Schubert 
114*7f2fe78bSCy Schubert /* Thread-safety wrapper slapped on top of original implementation.  */
115*7f2fe78bSCy Schubert extern k5_mutex_t *krb5_db2_mutex;
116*7f2fe78bSCy Schubert 
117*7f2fe78bSCy Schubert /* lockout */
118*7f2fe78bSCy Schubert krb5_error_code
119*7f2fe78bSCy Schubert krb5_db2_lockout_check_policy(krb5_context context,
120*7f2fe78bSCy Schubert                               krb5_db_entry *entry,
121*7f2fe78bSCy Schubert                               krb5_timestamp stamp);
122*7f2fe78bSCy Schubert 
123*7f2fe78bSCy Schubert krb5_error_code
124*7f2fe78bSCy Schubert krb5_db2_lockout_audit(krb5_context context,
125*7f2fe78bSCy Schubert                        krb5_db_entry *entry,
126*7f2fe78bSCy Schubert                        krb5_timestamp stamp,
127*7f2fe78bSCy Schubert                        krb5_error_code status);
128*7f2fe78bSCy Schubert 
129*7f2fe78bSCy Schubert krb5_error_code
130*7f2fe78bSCy Schubert krb5_db2_check_policy_as(krb5_context kcontext, krb5_kdc_req *request,
131*7f2fe78bSCy Schubert                          krb5_db_entry *client, krb5_db_entry *server,
132*7f2fe78bSCy Schubert                          krb5_timestamp kdc_time, const char **status,
133*7f2fe78bSCy Schubert                          krb5_pa_data ***e_data);
134*7f2fe78bSCy Schubert 
135*7f2fe78bSCy Schubert void
136*7f2fe78bSCy Schubert krb5_db2_audit_as_req(krb5_context kcontext, krb5_kdc_req *request,
137*7f2fe78bSCy Schubert                       const krb5_address *local_addr,
138*7f2fe78bSCy Schubert                       const krb5_address *remote_addr,
139*7f2fe78bSCy Schubert                       krb5_db_entry *client, krb5_db_entry *server,
140*7f2fe78bSCy Schubert                       krb5_timestamp authtime,
141*7f2fe78bSCy Schubert                       krb5_error_code error_code);
142*7f2fe78bSCy Schubert 
143*7f2fe78bSCy Schubert #endif /* KRB5_KDB_DB2_H */
144