1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 
3 /*
4  * lib/krb5/ccache/stdio/scc.h
5  *
6  * Copyright 1990,1991 by the Massachusetts Institute of Technology.
7  * All Rights Reserved.
8  *
9  * Export of this software from the United States of America may
10  *   require a specific license from the United States Government.
11  *   It is the responsibility of any person or organization contemplating
12  *   export to obtain such a license before exporting.
13  *
14  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
15  * distribute this software and its documentation for any purpose and
16  * without fee is hereby granted, provided that the above copyright
17  * notice appear in all copies and that both that copyright notice and
18  * this permission notice appear in supporting documentation, and that
19  * the name of M.I.T. not be used in advertising or publicity pertaining
20  * to distribution of the software without specific, written prior
21  * permission.  Furthermore if you modify this software you must label
22  * your software as modified software and not distribute it in such a
23  * fashion that it might be confused with the original M.I.T. software.
24  * M.I.T. makes no representations about the suitability of
25  * this software for any purpose.  It is provided "as is" without express
26  * or implied warranty.
27  *
28  *
29  * This file contains constant and function declarations used in the
30  * file-based credential cache routines.
31  */
32 
33 #ifndef __KRB5_FILE_CCACHE__
34 #define __KRB5_FILE_CCACHE__
35 
36 #include "k5-int.h"
37 #include <stdio.h>
38 
39 #define KRB5_OK 0
40 
41 #define KRB5_SCC_MAXLEN 100
42 
43 /*
44  * SCC version 2 contains type information for principals.  SCC
45  * version 1 does not.  The code will accept either, and depending on
46  * what KRB5_SCC_DEFAULT_FVNO is set to, it will create version 1 or
47  * version 2 SCC caches.
48  *
49  */
50 
51 #define KRB5_SCC_FVNO_1   0x0501	/* krb v5, scc v1 */
52 #define KRB5_SCC_FVNO_2   0x0502	/* krb v5, scc v2 */
53 #define KRB5_SCC_FVNO_3   0x0503	/* krb v5, scc v3 */
54 #define KRB5_SCC_FVNO_4   0x0504	/* krb v5, scc v4 */
55 
56 #define	SCC_OPEN_AND_ERASE	1
57 #define	SCC_OPEN_RDWR		2
58 #define	SCC_OPEN_RDONLY		3
59 
60 /* Credential file header tags.
61  * The header tags are constructed as:
62  *     krb5_ui_2       tag
63  *     krb5_ui_2       len
64  *     krb5_octet      data[len]
65  * This format allows for older versions of the fcc processing code to skip
66  * past unrecognized tag formats.
67  */
68 #define SCC_TAG_DELTATIME	1
69 
70 #ifndef TKT_ROOT
71 #define TKT_ROOT "/tmp/tkt"
72 #endif
73 
74 /* macros to make checking flags easier */
75 #define OPENCLOSE(id) (((krb5_scc_data *)id->data)->flags & KRB5_TC_OPENCLOSE)
76 
77 typedef struct _krb5_scc_data {
78      char *filename;
79      FILE *file;
80      krb5_flags flags;
81      char stdio_buffer[BUFSIZ];
82      int version;
83 } krb5_scc_data;
84 
85 /* An off_t can be arbitrarily complex */
86 typedef struct _krb5_scc_cursor {
87     long pos;
88 } krb5_scc_cursor;
89 
90 #define MAYBE_OPEN(context, ID, MODE) \
91 {									\
92     if (OPENCLOSE (ID)) {						\
93 	krb5_error_code maybe_open_ret = krb5_scc_open_file (context, ID,MODE);	\
94 	if (maybe_open_ret) return maybe_open_ret; } }
95 
96 #define MAYBE_CLOSE(context, ID, RET) \
97 {									\
98     if (OPENCLOSE (ID)) {						\
99 	krb5_error_code maybe_close_ret = krb5_scc_close_file (context, ID);	\
100 	if (!(RET)) RET = maybe_close_ret; } }
101 
102 /* DO NOT ADD ANYTHING AFTER THIS #endif */
103 #endif /* __KRB5_FILE_CCACHE__ */
104