xref: /illumos-gate/usr/src/lib/krb5/plugins/kdb/db2/kdb_db2.h (revision 628e3cbed6489fa1db545d8524a06cd6535af456)
1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 /*
3  * lib/kdb/kdb_db2.h
4  *
5  * Copyright 1997 by the Massachusetts Institute of Technology.
6  * All Rights Reserved.
7  *
8  * Export of this software from the United States of America may
9  *   require a specific license from the United States Government.
10  *   It is the responsibility of any person or organization contemplating
11  *   export to obtain such a license before exporting.
12  *
13  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14  * distribute this software and its documentation for any purpose and
15  * without fee is hereby granted, provided that the above copyright
16  * notice appear in all copies and that both that copyright notice and
17  * this permission notice appear in supporting documentation, and that
18  * the name of M.I.T. not be used in advertising or publicity pertaining
19  * to distribution of the software without specific, written prior
20  * permission.  Furthermore if you modify this software you must label
21  * your software as modified software and not distribute it in such a
22  * fashion that it might be confused with the original M.I.T. software.
23  * M.I.T. makes no representations about the suitability of
24  * this software for any purpose.  It is provided "as is" without express
25  * or implied warranty.
26  *
27  *
28  * KDC Database backend definitions for Berkely DB.
29  */
30 #ifndef KRB5_KDB_DB2_H
31 #define KRB5_KDB_DB2_H
32 
33 #include "policy_db.h"
34 
35 typedef struct _krb5_db2_context {
36     krb5_boolean        db_inited;      /* Context initialized          */
37     char *              db_name;        /* Name of database             */
38     DB *		db;		/* DB handle			*/
39     krb5_boolean	hashfirst;	/* Try hash database type first	*/
40     char *              db_lf_name;     /* Name of lock file            */
41     int                 db_lf_file;     /* File descriptor of lock file */
42     time_t              db_lf_time;     /* Time last updated            */
43     int                 db_locks_held;  /* Number of times locked       */
44     int                 db_lock_mode;   /* Last lock mode, e.g. greatest*/
45     krb5_boolean        db_nb_locks;    /* [Non]Blocking lock modes     */
46     krb5_keyblock      *db_master_key;  /* Master key 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 krb5_error_code krb5_db2_db_get_principal
76 	(krb5_context,
77 		   krb5_const_principal,
78 		   krb5_db_entry *,
79 		   int *,
80 		   krb5_boolean * );
81 krb5_error_code krb5_db2_db_free_principal
82 	(krb5_context,
83 		   krb5_db_entry *,
84 		   int );
85 krb5_error_code krb5_db2_db_put_principal
86 	(krb5_context,
87 	 krb5_db_entry *,
88 	 int *,
89 	 char **db_args
90 	 );
91 krb5_error_code krb5_db2_db_iterate_ext
92     	(krb5_context,
93 		   krb5_error_code (*) (krb5_pointer,
94 					          krb5_db_entry *),
95 	           krb5_pointer, int, int );
96 /* Solaris Kerberos: adding support for db_args */
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 		   char **db_args );
103 krb5_error_code krb5_db2_db_set_nonblocking
104 	(krb5_context,
105 		   krb5_boolean,
106 		   krb5_boolean * );
107 krb5_boolean krb5_db2_db_set_lockmode
108 	(krb5_context,
109 		   krb5_boolean );
110 krb5_error_code krb5_db2_db_open_database
111 	(krb5_context);
112 krb5_error_code krb5_db2_db_close_database
113 	(krb5_context);
114 
115 krb5_error_code
116 krb5_db2_set_master_key_ext ( krb5_context kcontext,
117 			      char *pwd,
118 			      krb5_keyblock *key);
119 
120 krb5_error_code
121 krb5_db2_db_set_mkey( krb5_context context,
122 		      krb5_keyblock *key);
123 
124 krb5_error_code
125 krb5_db2_db_get_mkey( krb5_context context,
126 		      krb5_keyblock **key);
127 
128 krb5_error_code
129 krb5_db2_db_put_principal( krb5_context context,
130 			   krb5_db_entry *entries,
131 			   register int *nentries,
132 			   char **db_args);
133 
134 krb5_error_code
135 krb5_db2_db_delete_principal(krb5_context context,
136 			     krb5_const_principal searchfor,
137 			     int *nentries);
138 
139 krb5_error_code krb5_db2_lib_init(void);
140 
141 krb5_error_code krb5_db2_lib_cleanup(void);
142 
143 krb5_error_code
144 krb5_db2_db_unlock(krb5_context);
145 
146 krb5_error_code
147 krb5_db2_promote_db(krb5_context kcontext,
148 		    char *conf_section,
149 		    char **db_args);
150 
151 krb5_error_code
152 krb5_db2_db_set_option ( krb5_context kcontext,
153 			 int option,
154 			 void *value );
155 
156 krb5_error_code
157 krb5_db2_db_lock( krb5_context 	  context,
158 		  int 	 	  in_mode);
159 
160 
161 krb5_error_code
162 krb5_db2_open( krb5_context kcontext,
163 			       char *conf_section,
164 			       char **db_args,
165 			       int mode );
166 
167 krb5_error_code krb5_db2_create( krb5_context kcontext,
168 				 char *conf_section,
169 				 char **db_args );
170 
171 krb5_error_code krb5_db2_destroy( krb5_context kcontext,
172 				  char *conf_section,
173 				  char **db_args );
174 
175 const char * krb5_db2_err2str( krb5_context kcontext,
176 			       long err_code );
177 
178 void *
179 krb5_db2_alloc( krb5_context kcontext,
180 		void *ptr,
181 		size_t size );
182 
183 void
184 krb5_db2_free( krb5_context kcontext,
185 		    void *ptr );
186 
187 const char *
188 krb5_db2_errcode_2_string(krb5_context kcontext,
189 		    long err_code);
190 
191 void
192 krb5_db2_release_errcode_string(krb5_context kcontext,
193 		    const char *msg);
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 #endif /* KRB5_KDB_DB2_H */
221