1 /*
2  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  *
5  * lib/krb5/keytab/file/ktfile.h
6  *
7  * Copyright 1990 by the Massachusetts Institute of Technology.
8  * All Rights Reserved.
9  *
10  * Export of this software from the United States of America may
11  *   require a specific license from the United States Government.
12  *   It is the responsibility of any person or organization contemplating
13  *   export to obtain such a license before exporting.
14  *
15  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
16  * distribute this software and its documentation for any purpose and
17  * without fee is hereby granted, provided that the above copyright
18  * notice appear in all copies and that both that copyright notice and
19  * this permission notice appear in supporting documentation, and that
20  * the name of M.I.T. not be used in advertising or publicity pertaining
21  * to distribution of the software without specific, written prior
22  * permission.  Furthermore if you modify this software you must label
23  * your software as modified software and not distribute it in such a
24  * fashion that it might be confused with the original M.I.T. software.
25  * M.I.T. makes no representations about the suitability of
26  * this software for any purpose.  It is provided "as is" without express
27  * or implied warranty.
28  *
29  *
30  * This header file contains information needed by internal routines
31  * of the file-based ticket cache implementation.
32  */
33 
34 #ifndef	_KRB5_KTFILE
35 #define	_KRB5_KTFILE
36 
37 #include <stdio.h>
38 #include <sys/mman.h>
39 
40 /*
41  * Constants
42  */
43 #define IGNORE_VNO 0
44 #define IGNORE_ENCTYPE 0
45 
46 #define KRB5_KT_VNO_1	0x0501	/* krb v5, keytab version 1 (DCE compat) */
47 #define KRB5_KT_VNO	0x0502	/* krb v5, keytab version 2 (standard)  */
48 
49 #define KRB5_KT_DEFAULT_VNO KRB5_KT_VNO
50 
51 /*
52  * Types
53  */
54 typedef struct _krb5_ktfile_data {
55     char *name;			/* Name of the file */
56     char *datap;		/* ptr to the file data */
57     int	version;		/* Version number of keytab */
58     offset_t offset;		/* current offset into the data buffer */
59     size_t filesize;		/* size of original file */
60     size_t bufsize;		/* total size of data buffer */
61     uchar_t writable:1;		/* Was the file opened for writing? */
62 } krb5_ktfile_data;
63 
64 /*
65  * Macros
66  */
67 #define KTPRIVATE(id) ((krb5_ktfile_data *)(id)->data)
68 #define KTFILENAME(id) (((krb5_ktfile_data *)(id)->data)->name)
69 /*
70 #define KTFILEP(id) (((krb5_ktfile_data *)(id)->data)->openf)
71 */
72 #define	KTDATAP(id) (((krb5_ktfile_data *)(id)->data)->datap)
73 #define KTVERSION(id) (((krb5_ktfile_data *)(id)->data)->version)
74 #define	KTOFFSET(id) (((krb5_ktfile_data *)(id)->data)->offset)
75 
76 extern struct _krb5_kt_ops krb5_ktf_ops;
77 extern struct _krb5_kt_ops krb5_ktf_writable_ops;
78 
79 krb5_error_code KRB5_CALLCONV krb5_ktfile_resolve
80 	(krb5_context,
81 		   const char *,
82 		   krb5_keytab *);
83 
84 krb5_error_code KRB5_CALLCONV krb5_ktfile_wresolve
85 	(krb5_context,
86 		   const char *,
87 		   krb5_keytab *);
88 
89 krb5_error_code KRB5_CALLCONV krb5_ktfile_get_name
90 	(krb5_context,
91 		   krb5_keytab,
92 		   char *,
93 		   int);
94 
95 krb5_error_code KRB5_CALLCONV krb5_ktfile_close
96 	(krb5_context,
97 		   krb5_keytab);
98 
99 krb5_error_code KRB5_CALLCONV krb5_ktfile_get_entry
100 	(krb5_context,
101 		   krb5_keytab,
102 		   krb5_const_principal,
103 		   krb5_kvno,
104 		   krb5_enctype,
105 		   krb5_keytab_entry *);
106 
107 krb5_error_code KRB5_CALLCONV krb5_ktfile_start_seq_get
108 	(krb5_context,
109 		   krb5_keytab,
110 		   krb5_kt_cursor *);
111 
112 krb5_error_code KRB5_CALLCONV krb5_ktfile_get_next
113 	(krb5_context,
114 		   krb5_keytab,
115 		   krb5_keytab_entry *,
116 		   krb5_kt_cursor *);
117 
118 krb5_error_code KRB5_CALLCONV krb5_ktfile_end_get
119 	(krb5_context,
120 		   krb5_keytab,
121 		   krb5_kt_cursor *);
122 
123 /* routines to be included on extended version (write routines) */
124 krb5_error_code KRB5_CALLCONV krb5_ktfile_add
125 	(krb5_context,
126 		   krb5_keytab,
127 		   krb5_keytab_entry *);
128 
129 krb5_error_code KRB5_CALLCONV krb5_ktfile_remove
130 	(krb5_context,
131 		   krb5_keytab,
132 		   krb5_keytab_entry *);
133 
134 krb5_error_code krb5_ktfileint_openr
135 	(krb5_context,
136 		   krb5_keytab);
137 
138 krb5_error_code krb5_ktfileint_openw
139 	(krb5_context,
140 		   krb5_keytab);
141 
142 krb5_error_code krb5_ktfileint_close
143 	(krb5_context,
144 		   krb5_keytab);
145 
146 krb5_error_code krb5_ktfileint_read_entry
147 	(krb5_context,
148 		   krb5_keytab,
149 		   krb5_keytab_entry *);
150 
151 krb5_error_code krb5_ktfileint_write_entry
152 	(krb5_context,
153 		   krb5_keytab,
154 		   krb5_keytab_entry *);
155 
156 krb5_error_code krb5_ktfileint_delete_entry
157 	(krb5_context,
158 		   krb5_keytab,
159                    krb5_int32);
160 
161 krb5_error_code krb5_ktfileint_internal_read_entry
162 	(krb5_context,
163 		   krb5_keytab,
164 		   krb5_keytab_entry *,
165                    krb5_int32 *);
166 
167 krb5_error_code krb5_ktfileint_size_entry
168 	(krb5_context,
169 		   krb5_keytab_entry *,
170                    krb5_int32 *);
171 
172 krb5_error_code krb5_ktfileint_find_slot
173 	(krb5_context,
174 		   krb5_keytab,
175                    krb5_int32 *,
176                    krb5_int32 *);
177 
178 
179 #endif /* _KRB5_KTFILE */
180