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