Make the cmd config file parser build on Windows
[openafs.git] / src / cmd / krb5_locl.h
1
2 /* This header file transforms the Heimdal config_parse.c profile
3  * parser into an AFS profile parser, hiding the krb5-ness of the parser
4  * behind the scenes.
5  */
6
7 #include <afsconfig.h>
8 #include <afs/stds.h>
9
10 #include <roken.h>
11
12 #include <assert.h>
13 #include <ctype.h>
14
15 #include "cmd.h"
16
17 #define PACKAGE "openafs"
18
19 #ifndef TRUE
20 # define TRUE 1
21 #endif
22 #ifndef FALSE
23 # define FALSE 0
24 #endif
25
26 #define KRB5_BUFSIZ 1024
27
28 #define KRB5_LIB_FUNCTION static AFS_UNUSED
29 #define KRB5_LIB_CALL
30
31 #define KRB5_DEPRECATED_FUNCTION(x)
32
33 #define N_(X,Y) X
34
35 typedef struct cmd_config_binding krb5_config_binding;
36 typedef struct cmd_config_binding krb5_config_section;
37
38 #define krb5_config_list cmd_config_list
39 #define krb5_config_string cmd_config_string
40
41 struct krb5_context_data {
42     krb5_config_section *cf;
43 };
44
45 typedef struct krb5_context_data * krb5_context;
46 typedef int krb5_error_code;
47 typedef int krb5_boolean;
48 typedef time_t krb5_deltat;
49
50 static void krb5_set_error_message(krb5_context context, krb5_error_code ret,
51                                    const char *fmt, ...) {
52     return;
53 }
54
55 #ifdef EXPAND_PATH_HEADER
56
57 #include <shlobj.h>
58
59 static int _krb5_expand_path_tokens(krb5_context, const char *, char**);
60
61 int
62 _cmd_ExpandPathTokens(krb5_context context, const char *in, char **out) {
63     return _krb5_expand_path_tokens(context, in, out);
64 }
65
66 HINSTANCE _krb5_hInstance = NULL;
67
68 /* This bodge avoids the need for everything linking against cmd to also
69  * link against the shell library on Windows */
70 #undef SHGetFolderPath
71 #define SHGetFolderPath internal_getpath
72
73 HRESULT internal_getpath(void *a, int b, void *c, DWORD d, LPTSTR out) {
74     return E_INVALIDARG;
75 }
76
77 #else
78
79 #define KRB5_CONFIG_BADFORMAT                    CMD_BADFORMAT
80
81 #define _krb5_expand_path_tokens _cmd_ExpandPathTokens
82
83 extern int _cmd_ExpandPathTokens(krb5_context, const char *, char **);
84
85 static const void *_krb5_config_vget(krb5_context,
86                                      const krb5_config_section *, int,
87                                      va_list);
88 static const void *_krb5_config_vget_next(krb5_context,
89                                           const krb5_config_section *,
90                                           const krb5_config_binding **,
91                                           int, va_list);
92 static const char *krb5_config_vget_string(krb5_context,
93                                            const krb5_config_section *,
94                                            va_list);
95 static const char *krb5_config_vget_string_default(krb5_context,
96                                            const krb5_config_section *,
97                                            const char *,
98                                            va_list);
99 static const krb5_config_binding * krb5_config_vget_list
100         (krb5_context, const krb5_config_section *, va_list);
101 static krb5_error_code krb5_config_parse_file_multi
102         (krb5_context, const char *, krb5_config_section **);
103 static krb5_error_code krb5_config_parse_file
104         (krb5_context, const char *, krb5_config_section **);
105 static krb5_error_code krb5_config_file_free
106         (krb5_context, krb5_config_section *);
107 static krb5_boolean krb5_config_vget_bool_default
108         (krb5_context, const krb5_config_section *, int, va_list);
109 static int krb5_config_vget_int_default
110         (krb5_context, const krb5_config_section *, int, va_list);
111
112 static krb5_error_code
113 krb5_string_to_deltat(const char *str, krb5_deltat *t) {
114     return 1;
115 }
116
117 KRB5_LIB_FUNCTION void krb5_clear_error_message(krb5_context context) {
118     return;
119 }
120
121
122 static int _krb5_homedir_access(krb5_context context) {
123     return 0;
124 }
125
126 static krb5_error_code
127 krb5_abortx(krb5_context context, const char *fmt, ...)
128 {
129     va_list ap;
130     va_start(ap, fmt);
131
132     vfprintf(stderr, fmt, ap);
133     va_end(ap);
134
135     abort();
136 }
137
138 /* Wrappers */
139
140
141 int
142 cmd_RawConfigParseFileMulti(const char *fname, cmd_config_section **res) {
143     return krb5_config_parse_file_multi(NULL, fname, res);
144 }
145
146 int
147 cmd_RawConfigParseFile(const char *fname, cmd_config_section **res) {
148     return krb5_config_parse_file(NULL, fname, res);
149 }
150
151 int
152 cmd_RawConfigFileFree(cmd_config_section *s) {
153     return krb5_config_file_free(NULL, s);
154 }
155
156 const char*
157 cmd_RawConfigGetString(const cmd_config_section *c,
158                        const char *defval, ...)
159 {
160     const char *ret;
161     va_list args;
162
163     assert(c != NULL);
164
165     va_start(args, defval);
166     ret = krb5_config_vget_string_default (NULL, c, defval, args);
167     va_end(args);
168     return ret;
169 }
170
171 int
172 cmd_RawConfigGetBool(const cmd_config_section *c, int defval, ...)
173 {
174     va_list ap;
175     krb5_boolean ret;
176
177     assert(c != NULL);
178
179     va_start(ap, defval);
180     ret = krb5_config_vget_bool_default (NULL, c, defval, ap);
181     va_end(ap);
182     return ret;
183 }
184
185 int
186 cmd_RawConfigGetInt(const cmd_config_section *c, int defval, ...)
187 {
188     va_list ap;
189     int ret;
190
191     assert(c != NULL);
192
193     va_start(ap, defval);
194     ret = krb5_config_vget_int_default (NULL, c, defval, ap);
195     va_end(ap);
196     return ret;
197 }
198
199 const cmd_config_binding *
200 cmd_RawConfigGetList(const cmd_config_section *c, ...)
201 {
202     va_list ap;
203     const cmd_config_binding *ret;
204
205     assert(c != NULL);
206
207     va_start(ap, c);
208     ret = krb5_config_vget_list (NULL, c, ap);
209     va_end(ap);
210
211     return ret;
212 }
213 #endif