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