xref: /titanic_50/usr/src/lib/krb5/kadm5/server_internal.h (revision bbfe764ef179c2f606b093b6ec6bb149cde0e31b)
1 /*
2  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 #pragma ident	"%Z%%M%	%I%	%E% SMI"
6 
7 /*
8  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
9  *
10  *	Openvision retains the copyright to derivative works of
11  *	this source code.  Do *NOT* create a derivative of this
12  *	source code before consulting with your legal department.
13  *	Do *NOT* integrate *ANY* of this source code into another
14  *	product before consulting with your legal department.
15  *
16  *	For further information, read the top-level Openvision
17  *	copyright which is contained in the top-level MIT Kerberos
18  *	copyright.
19  *
20  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
21  *
22  */
23 
24 
25 /*
26  * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
27  *
28  * $Header: /cvs/krbdev/krb5/src/lib/kadm5/server_internal.h,v 1.31 2001/07/08 12:24:56 epeisach Exp $
29  */
30 
31 /*
32  * This header file is used internally by the Admin API server
33  * libraries and Admin server.  IF YOU THINK YOU NEED TO USE THIS FILE
34  * FOR ANYTHING, YOU'RE ALMOST CERTAINLY WRONG.
35  */
36 
37 #ifndef __KADM5_SERVER_INTERNAL_H__
38 #define __KADM5_SERVER_INTERNAL_H__
39 
40 #ifdef HAVE_MEMORY_H
41 #include    <memory.h>
42 #endif
43 #include    <stdlib.h>
44 #include    "k5-int.h"
45 #include    <krb5/kdb.h>
46 #include    <kadm5/admin.h>
47 #include    <rpc/xdr.h>
48 #include    "admin_internal.h"
49 
50 typedef struct _kadm5_server_handle_t {
51 	krb5_ui_4	magic_number;
52 	krb5_ui_4	struct_version;
53 	krb5_ui_4	api_version;
54 	krb5_context	context;
55 	krb5_principal	current_caller;
56 	kadm5_config_params  params;
57 	struct _kadm5_server_handle_t *lhandle;
58 	char **db_args;
59 	krb5_keyblock	master_keyblock;
60 } kadm5_server_handle_rec, *kadm5_server_handle_t;
61 
62 #define OSA_ADB_PRINC_VERSION_1  0x12345C01
63 
64 typedef struct _osa_pw_hist_t {
65   int n_key_data;
66   krb5_key_data *key_data;
67 } osa_pw_hist_ent, *osa_pw_hist_t;
68 
69 typedef struct _osa_princ_ent_t {
70   int                         version;
71   char                        *policy;
72   long                        aux_attributes;
73   unsigned int                old_key_len;
74   unsigned int                old_key_next;
75   krb5_kvno                   admin_history_kvno;
76   osa_pw_hist_ent             *old_keys;
77 } osa_princ_ent_rec, *osa_princ_ent_t;
78 
79 kadm5_ret_t    adb_policy_init(kadm5_server_handle_t handle);
80 kadm5_ret_t    adb_policy_close(kadm5_server_handle_t handle);
81 kadm5_ret_t    passwd_check(kadm5_server_handle_t handle,
82 			    char *pass, int use_policy,
83 			    kadm5_policy_ent_t policy,
84 			    krb5_principal principal);
85 kadm5_ret_t    principal_exists(krb5_principal principal);
86 krb5_error_code	    kdb_init_master(kadm5_server_handle_t handle,
87 				    char *r, int from_keyboard);
88 krb5_error_code	    kdb_init_hist(kadm5_server_handle_t handle,
89 				  char *r);
90 krb5_error_code     kdb_get_entry(kadm5_server_handle_t handle,
91 				  krb5_principal principal, krb5_db_entry *kdb,
92 				  osa_princ_ent_rec *adb);
93 krb5_error_code     kdb_free_entry(kadm5_server_handle_t handle,
94 				   krb5_db_entry *kdb, osa_princ_ent_rec *adb);
95 krb5_error_code     kdb_put_entry(kadm5_server_handle_t handle,
96 				  krb5_db_entry *kdb, osa_princ_ent_rec *adb);
97 krb5_error_code     kdb_delete_entry(kadm5_server_handle_t handle,
98 				     krb5_principal name);
99 krb5_error_code     kdb_iter_entry(kadm5_server_handle_t handle, char *,
100 				   void (*iter_fct)(void *, krb5_principal),
101 				   void *data);
102 
103 int		    init_dict(kadm5_config_params *);
104 int		    find_word(const char *word);
105 void		    destroy_dict(void);
106 
107 /* XXX this ought to be in libkrb5.a, but isn't */
108 kadm5_ret_t krb5_copy_key_data_contents(krb5_context context,
109 					krb5_key_data *from,
110 					krb5_key_data *to);
111 kadm5_ret_t krb5_free_key_data_contents(krb5_context context,
112 					krb5_key_data *key);
113 
114 /*
115  * *Warning*
116  * *Warning*	    This is going to break if we
117  * *Warning*	    ever go multi-threaded
118  * *Warning*
119  */
120 extern	krb5_principal	current_caller;
121 
122 /*
123  * Why is this (or something similar) not defined *anywhere* in krb5?
124  */
125 #define KSUCCESS	0
126 #define WORD_NOT_FOUND	1
127 
128 /*
129  * all the various mask bits or'd together
130  */
131 
132 #define	ALL_PRINC_MASK \
133  (KADM5_PRINCIPAL | KADM5_PRINC_EXPIRE_TIME | KADM5_PW_EXPIRATION | \
134   KADM5_LAST_PWD_CHANGE | KADM5_ATTRIBUTES | KADM5_MAX_LIFE | \
135   KADM5_MOD_TIME | KADM5_MOD_NAME | KADM5_KVNO | KADM5_MKVNO | \
136   KADM5_AUX_ATTRIBUTES | KADM5_POLICY_CLR | KADM5_POLICY | \
137   KADM5_MAX_RLIFE | KADM5_TL_DATA | KADM5_KEY_DATA)
138 
139 #define ALL_POLICY_MASK \
140  (KADM5_POLICY | KADM5_PW_MAX_LIFE | KADM5_PW_MIN_LIFE | \
141   KADM5_PW_MIN_LENGTH | KADM5_PW_MIN_CLASSES | KADM5_PW_HISTORY_NUM | \
142   KADM5_REF_COUNT)
143 
144 #define SERVER_CHECK_HANDLE(handle) \
145 { \
146 	kadm5_server_handle_t srvr = \
147 	     (kadm5_server_handle_t) handle; \
148  \
149 	if (! srvr->current_caller) \
150 		return KADM5_BAD_SERVER_HANDLE; \
151 	if (! srvr->lhandle) \
152 	        return KADM5_BAD_SERVER_HANDLE; \
153 }
154 
155 #define CHECK_HANDLE(handle) \
156      GENERIC_CHECK_HANDLE(handle, KADM5_OLD_SERVER_API_VERSION, \
157 			  KADM5_NEW_SERVER_API_VERSION) \
158      SERVER_CHECK_HANDLE(handle)
159 
160 bool_t          xdr_osa_princ_ent_rec(XDR *xdrs, osa_princ_ent_t objp);
161 
162 void
163 osa_free_princ_ent(osa_princ_ent_t val);
164 #endif /* __KADM5_SERVER_INTERNAL_H__ */
165