xref: /illumos-gate/usr/src/lib/krb5/plugins/kdb/db2/kdb_db2.h (revision d5b563f27eb78296f57dddced6755afe7445c4b9)
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     osa_adb_policy_t    policy_db;
47     krb5_boolean tempdb;
48 } krb5_db2_context;
49 
50 #define KRB5_DB2_MAX_RETRY 5
51 
52 #define KDB2_LOCK_EXT ".ok"
53 #define KDB2_TEMP_LOCK_EXT "~.ok"
54 
55 krb5_error_code krb5_db2_db_init
56 	(krb5_context);
57 krb5_error_code krb5_db2_db_fini
58 	(krb5_context);
59 krb5_error_code krb5_db2_db_get_age
60 	(krb5_context,
61 		   char *,
62 		   time_t * );
63 krb5_error_code krb5_db2_db_create
64 	(krb5_context,
65 		   char *,
66 		   krb5_int32);
67 krb5_error_code krb5_db2_db_destroy
68 	(krb5_context,
69 		   char * );
70 krb5_error_code krb5_db2_db_rename
71 	(krb5_context,
72 		   char *,
73 		   char * );
74 krb5_error_code krb5_db2_db_get_principal
75 	(krb5_context,
76 		   krb5_const_principal,
77 		   krb5_db_entry *,
78 		   int *,
79 		   krb5_boolean * );
80 krb5_error_code krb5_db2_db_free_principal
81 	(krb5_context,
82 		   krb5_db_entry *,
83 		   int );
84 krb5_error_code krb5_db2_db_put_principal
85 	(krb5_context,
86 	 krb5_db_entry *,
87 	 int *,
88 	 char **db_args
89 	 );
90 krb5_error_code krb5_db2_db_iterate_ext
91     	(krb5_context,
92 		   krb5_error_code (*) (krb5_pointer,
93 					          krb5_db_entry *),
94 	           krb5_pointer, int, int );
95 /* Solaris Kerberos: adding support for db_args */
96 krb5_error_code krb5_db2_db_iterate
97 (krb5_context,char *,
98 		   krb5_error_code (*) (krb5_pointer,
99 					          krb5_db_entry *),
100 	           krb5_pointer,
101 		   char **db_args );
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 
127 krb5_error_code
128 krb5_db2_db_put_principal( krb5_context context,
129 			   krb5_db_entry *entries,
130 			   register int *nentries,
131 			   char **db_args);
132 
133 krb5_error_code
134 krb5_db2_db_delete_principal(krb5_context context,
135 			     krb5_const_principal searchfor,
136 			     int *nentries);
137 
138 krb5_error_code krb5_db2_lib_init(void);
139 
140 krb5_error_code krb5_db2_lib_cleanup(void);
141 
142 krb5_error_code
143 krb5_db2_db_unlock(krb5_context);
144 
145 krb5_error_code
146 krb5_db2_promote_db(krb5_context kcontext,
147 		    char *conf_section,
148 		    char **db_args);
149 
150 krb5_error_code
151 krb5_db2_db_set_option ( krb5_context kcontext,
152 			 int option,
153 			 void *value );
154 
155 krb5_error_code
156 krb5_db2_db_lock( krb5_context 	  context,
157 		  int 	 	  in_mode);
158 
159 
160 krb5_error_code
161 krb5_db2_open( krb5_context kcontext,
162 			       char *conf_section,
163 			       char **db_args,
164 			       int mode );
165 
166 krb5_error_code krb5_db2_create( krb5_context kcontext,
167 				 char *conf_section,
168 				 char **db_args );
169 
170 krb5_error_code krb5_db2_destroy( krb5_context kcontext,
171 				  char *conf_section,
172 				  char **db_args );
173 
174 const char * krb5_db2_err2str( krb5_context kcontext,
175 			       long err_code );
176 
177 void *
178 krb5_db2_alloc( krb5_context kcontext,
179 		void *ptr,
180 		size_t size );
181 
182 void
183 krb5_db2_free( krb5_context kcontext,
184 		    void *ptr );
185 
186 const char *
187 krb5_db2_errcode_2_string(krb5_context kcontext,
188 		    long err_code);
189 
190 void
191 krb5_db2_release_errcode_string(krb5_context kcontext,
192 		    const char *msg);
193 
194 
195 
196 /* policy management functions */
197 krb5_error_code
198 krb5_db2_create_policy(krb5_context context, osa_policy_ent_t entry);
199 
200 krb5_error_code krb5_db2_get_policy ( krb5_context kcontext,
201 				      char *name,
202 				      osa_policy_ent_t *policy,
203 				      int *cnt);
204 
205 krb5_error_code krb5_db2_put_policy ( krb5_context kcontext,
206 				      osa_policy_ent_t policy );
207 
208 krb5_error_code krb5_db2_iter_policy ( krb5_context kcontext,
209 				       char *match_entry,
210 				       osa_adb_iter_policy_func func,
211 				       void *data );
212 
213 krb5_error_code krb5_db2_delete_policy ( krb5_context kcontext,
214 					 char *policy );
215 
216 void krb5_db2_free_policy( krb5_context kcontext,
217 			   osa_policy_ent_t entry );
218 
219 #endif /* KRB5_KDB_DB2_H */
220