xref: /titanic_41/usr/src/lib/krb5/kadm5/adb.h (revision 54925bf60766fbb4f1f2d7c843721406a7b7a3fb)
1 /*
2  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
10  *
11  *	Openvision retains the copyright to derivative works of
12  *	this source code.  Do *NOT* create a derivative of this
13  *	source code before consulting with your legal department.
14  *	Do *NOT* integrate *ANY* of this source code into another
15  *	product before consulting with your legal department.
16  *
17  *	For further information, read the top-level Openvision
18  *	copyright which is contained in the top-level MIT Kerberos
19  *	copyright.
20  *
21  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
22  *
23  */
24 
25 
26 /*
27  * Data Types for policys, and principal information that
28  * exist in the respective databases.
29  *
30  * $Header: /cvs/krbdev/krb5/src/lib/kadm5/adb.h,v 1.21 1998/02/14 02:34:09 tlyu Exp $
31  *
32  * This file was originally created with rpcgen.
33  * It has been hacked up since then.
34  */
35 
36 #ifndef __ADB_H__
37 #define __ADB_H__
38 #include <sys/types.h>
39 #include <rpc/types.h>	/* SUNWresync121 - no need to change to gssrpc/ */
40 #include "k5-int.h"
41 #include <krb5/kdb.h>
42 #include <db.h>
43 #include <kadm5/admin.h>
44 #include <kdb/adb_err.h>
45 #include <com_err.h>
46 
47 typedef	long		osa_adb_ret_t;
48 
49 #define OSA_ADB_POLICY_DB_MAGIC	0x12345A00
50 #define OSA_ADB_PRINC_DB_MAGIC	0x12345B00
51 
52 #define OSA_ADB_SHARED		0x7001
53 #define OSA_ADB_EXCLUSIVE	0x7002
54 #define OSA_ADB_PERMANENT	0x7003
55 
56 #define OSA_ADB_PRINC_VERSION_MASK	0x12345C00
57 #define OSA_ADB_PRINC_VERSION_1		0x12345C01
58 #define OSA_ADB_POLICY_VERSION_MASK	0x12345D00
59 #define OSA_ADB_POLICY_VERSION_1	0x12345D01
60 
61 typedef struct _osa_adb_db_lock_ent_t {
62      FILE	*lockfile;
63      char	*filename;
64      int	refcnt, lockmode, lockcnt;
65      krb5_context context;
66 } osa_adb_lock_ent, *osa_adb_lock_t;
67 
68 typedef struct _osa_adb_db_ent_t {
69      int	magic;
70      DB		*db;
71      HASHINFO	info;
72      BTREEINFO	btinfo;
73      char	*filename;
74      osa_adb_lock_t lock;
75      int	opencnt;
76 } osa_adb_db_ent, *osa_adb_db_t, *osa_adb_princ_t, *osa_adb_policy_t;
77 
78 /* an osa_pw_hist_ent stores all the key_datas for a single password */
79 typedef struct _osa_pw_hist_t {
80      int n_key_data;
81      krb5_key_data *key_data;
82 } osa_pw_hist_ent, *osa_pw_hist_t;
83 
84 typedef struct _osa_princ_ent_t {
85     int				version;
86     char			*policy;
87     long			aux_attributes;
88     unsigned int		old_key_len;
89     unsigned int		old_key_next;
90     krb5_kvno			admin_history_kvno;
91     osa_pw_hist_ent		*old_keys;
92 } osa_princ_ent_rec, *osa_princ_ent_t;
93 
94 typedef struct _osa_policy_ent_t {
95     int		version;
96     char	*name;
97     uint32_t	pw_min_life;
98     uint32_t	pw_max_life;
99     uint32_t	pw_min_length;
100     uint32_t	pw_min_classes;
101     uint32_t	pw_history_num;
102     uint32_t	policy_refcnt;
103 } osa_policy_ent_rec, *osa_policy_ent_t;
104 
105 typedef	void	(*osa_adb_iter_princ_func) (void *, osa_princ_ent_t);
106 typedef	void	(*osa_adb_iter_policy_func) (void *, osa_policy_ent_t);
107 
108 /*
109  * Return Code (the rest are in adb_err.h)
110  */
111 
112 #define OSA_ADB_OK		0
113 
114 /*
115  * xdr functions
116  */
117 bool_t		xdr_osa_princ_ent_rec(XDR *xdrs, osa_princ_ent_t objp);
118 bool_t		xdr_osa_policy_ent_rec(XDR *xdrs, osa_policy_ent_t objp);
119 bool_t		xdr_osa_pw_hist_ent(XDR *xdrs, osa_pw_hist_ent *objp);
120 bool_t          xdr_krb5_key_data(XDR *xdrs, krb5_key_data *objp);
121 
122 /*
123  * Functions
124  */
125 
126 osa_adb_ret_t	osa_adb_create_db(char *filename, char *lockfile, int magic);
127 osa_adb_ret_t	osa_adb_destroy_db(char *filename, char *lockfile, int magic);
128 osa_adb_ret_t   osa_adb_rename_db(char *filefrom, char *lockfrom,
129 				  char *fileto, char *lockto, int magic);
130 osa_adb_ret_t   osa_adb_rename_policy_db(kadm5_config_params *fromparams,
131 					 kadm5_config_params *toparams);
132 osa_adb_ret_t	osa_adb_init_db(osa_adb_db_t *dbp, char *filename,
133 				char *lockfile, int magic);
134 osa_adb_ret_t	osa_adb_fini_db(osa_adb_db_t db, int magic);
135 osa_adb_ret_t	osa_adb_get_lock(osa_adb_db_t db, int mode);
136 osa_adb_ret_t	osa_adb_release_lock(osa_adb_db_t db);
137 osa_adb_ret_t	osa_adb_open_and_lock(osa_adb_princ_t db, int locktype);
138 osa_adb_ret_t	osa_adb_close_and_unlock(osa_adb_princ_t db);
139 
140 osa_adb_ret_t	osa_adb_create_policy_db(kadm5_config_params *params);
141 osa_adb_ret_t	osa_adb_destroy_policy_db(kadm5_config_params *params);
142 osa_adb_ret_t	osa_adb_open_princ(osa_adb_princ_t *db, char *filename);
143 osa_adb_ret_t	osa_adb_open_policy(osa_adb_policy_t *db,
144 				    kadm5_config_params *rparams);
145 osa_adb_ret_t	osa_adb_close_princ(osa_adb_princ_t db);
146 osa_adb_ret_t	osa_adb_close_policy(osa_adb_policy_t db);
147 osa_adb_ret_t	osa_adb_create_princ(osa_adb_princ_t db,
148 				 osa_princ_ent_t entry);
149 osa_adb_ret_t	osa_adb_create_policy(osa_adb_policy_t db,
150 				      osa_policy_ent_t entry);
151 osa_adb_ret_t	osa_adb_destroy_princ(osa_adb_princ_t db,
152 				      kadm5_princ_t name);
153 osa_adb_ret_t	osa_adb_destroy_policy(osa_adb_policy_t db,
154 				       kadm5_policy_t name);
155 osa_adb_ret_t	osa_adb_get_princ(osa_adb_princ_t db,
156 				  kadm5_princ_t name,
157 				  osa_princ_ent_t *entry);
158 osa_adb_ret_t	osa_adb_get_policy(osa_adb_policy_t db,
159 				   kadm5_policy_t name,
160 				   osa_policy_ent_t *entry);
161 osa_adb_ret_t	osa_adb_put_princ(osa_adb_princ_t db,
162 				  osa_princ_ent_t entry);
163 osa_adb_ret_t	osa_adb_put_policy(osa_adb_policy_t db,
164 				   osa_policy_ent_t entry);
165 osa_adb_ret_t	osa_adb_iter_policy(osa_adb_policy_t db,
166 				    osa_adb_iter_policy_func func,
167 				    void * data);
168 osa_adb_ret_t	osa_adb_iter_princ(osa_adb_princ_t db,
169 				       osa_adb_iter_princ_func func,
170 				       void *data);
171 void		osa_free_policy_ent(osa_policy_ent_t val);
172 void		osa_free_princ_ent(osa_princ_ent_t val);
173 #endif /* __ADB_H__ */
174