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