Commit | Line | Data |
---|---|---|
805e021f CE |
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 | #define _krb5_config_get_entry _cmd_config_get_entry | |
41 | ||
42 | struct krb5_context_data { | |
43 | krb5_config_section *cf; | |
44 | }; | |
45 | ||
46 | typedef struct krb5_context_data * krb5_context; | |
47 | typedef int krb5_error_code; | |
48 | typedef int krb5_boolean; | |
49 | typedef time_t krb5_deltat; | |
50 | ||
51 | static void krb5_set_error_message(krb5_context context, krb5_error_code ret, | |
52 | const char *fmt, ...) { | |
53 | return; | |
54 | } | |
55 | ||
56 | static krb5_error_code | |
57 | krb5_enomem(krb5_context context) | |
58 | { | |
59 | return ENOMEM; | |
60 | } | |
61 | ||
62 | #ifdef EXPAND_PATH_HEADER | |
63 | ||
64 | #include <shlobj.h> | |
65 | ||
66 | static int _krb5_expand_path_tokens(krb5_context, const char *, char**); | |
67 | ||
68 | int | |
69 | _cmd_ExpandPathTokens(krb5_context context, const char *in, char **out) { | |
70 | return _krb5_expand_path_tokens(context, in, out); | |
71 | } | |
72 | ||
73 | HINSTANCE _krb5_hInstance = NULL; | |
74 | ||
75 | /* This bodge avoids the need for everything linking against cmd to also | |
76 | * link against the shell library on Windows */ | |
77 | #undef SHGetFolderPath | |
78 | #define SHGetFolderPath internal_getpath | |
79 | ||
80 | HRESULT internal_getpath(void *a, int b, void *c, DWORD d, LPTSTR out) { | |
81 | return E_INVALIDARG; | |
82 | } | |
83 | ||
84 | #else | |
85 | ||
86 | #define KRB5_CONFIG_BADFORMAT CMD_BADFORMAT | |
87 | ||
88 | #define _krb5_expand_path_tokens _cmd_ExpandPathTokens | |
89 | ||
90 | extern int _cmd_ExpandPathTokens(krb5_context, const char *, char **); | |
91 | ||
92 | static const void *_krb5_config_vget(krb5_context, | |
93 | const krb5_config_section *, int, | |
94 | va_list); | |
95 | static const void *_krb5_config_vget_next(krb5_context, | |
96 | const krb5_config_section *, | |
97 | const krb5_config_binding **, | |
98 | int, va_list); | |
99 | static const char *krb5_config_vget_string(krb5_context, | |
100 | const krb5_config_section *, | |
101 | va_list); | |
102 | static const char *krb5_config_vget_string_default(krb5_context, | |
103 | const krb5_config_section *, | |
104 | const char *, | |
105 | va_list); | |
106 | static const krb5_config_binding * krb5_config_vget_list | |
107 | (krb5_context, const krb5_config_section *, va_list); | |
108 | static krb5_error_code krb5_config_parse_file_multi | |
109 | (krb5_context, const char *, krb5_config_section **); | |
110 | static krb5_error_code krb5_config_parse_file | |
111 | (krb5_context, const char *, krb5_config_section **); | |
112 | static krb5_error_code krb5_config_file_free | |
113 | (krb5_context, krb5_config_section *); | |
114 | static krb5_boolean krb5_config_vget_bool_default | |
115 | (krb5_context, const krb5_config_section *, int, va_list); | |
116 | static int krb5_config_vget_int_default | |
117 | (krb5_context, const krb5_config_section *, int, va_list); | |
118 | ||
119 | static krb5_error_code | |
120 | krb5_string_to_deltat(const char *str, krb5_deltat *t) { | |
121 | return 1; | |
122 | } | |
123 | ||
124 | KRB5_LIB_FUNCTION void krb5_clear_error_message(krb5_context context) { | |
125 | return; | |
126 | } | |
127 | ||
128 | ||
129 | static int _krb5_homedir_access(krb5_context context) { | |
130 | return 0; | |
131 | } | |
132 | ||
133 | static krb5_error_code | |
134 | krb5_abortx(krb5_context context, const char *fmt, ...) | |
135 | { | |
136 | va_list ap; | |
137 | va_start(ap, fmt); | |
138 | ||
139 | vfprintf(stderr, fmt, ap); | |
140 | va_end(ap); | |
141 | ||
142 | abort(); | |
143 | } | |
144 | ||
145 | /* Wrappers */ | |
146 | ||
147 | ||
148 | int | |
149 | cmd_RawConfigParseFileMulti(const char *fname, cmd_config_section **res) { | |
150 | return krb5_config_parse_file_multi(NULL, fname, res); | |
151 | } | |
152 | ||
153 | int | |
154 | cmd_RawConfigParseFile(const char *fname, cmd_config_section **res) { | |
155 | return krb5_config_parse_file(NULL, fname, res); | |
156 | } | |
157 | ||
158 | int | |
159 | cmd_RawConfigFileFree(cmd_config_section *s) { | |
160 | return krb5_config_file_free(NULL, s); | |
161 | } | |
162 | ||
163 | const char* | |
164 | cmd_RawConfigGetString(const cmd_config_section *c, | |
165 | const char *defval, ...) | |
166 | { | |
167 | const char *ret; | |
168 | va_list args; | |
169 | ||
170 | assert(c != NULL); | |
171 | ||
172 | va_start(args, defval); | |
173 | ret = krb5_config_vget_string_default (NULL, c, defval, args); | |
174 | va_end(args); | |
175 | return ret; | |
176 | } | |
177 | ||
178 | int | |
179 | cmd_RawConfigGetBool(const cmd_config_section *c, int defval, ...) | |
180 | { | |
181 | va_list ap; | |
182 | krb5_boolean ret; | |
183 | ||
184 | assert(c != NULL); | |
185 | ||
186 | va_start(ap, defval); | |
187 | ret = krb5_config_vget_bool_default (NULL, c, defval, ap); | |
188 | va_end(ap); | |
189 | return ret; | |
190 | } | |
191 | ||
192 | int | |
193 | cmd_RawConfigGetInt(const cmd_config_section *c, int defval, ...) | |
194 | { | |
195 | va_list ap; | |
196 | int ret; | |
197 | ||
198 | assert(c != NULL); | |
199 | ||
200 | va_start(ap, defval); | |
201 | ret = krb5_config_vget_int_default (NULL, c, defval, ap); | |
202 | va_end(ap); | |
203 | return ret; | |
204 | } | |
205 | ||
206 | const cmd_config_binding * | |
207 | cmd_RawConfigGetList(const cmd_config_section *c, ...) | |
208 | { | |
209 | va_list ap; | |
210 | const cmd_config_binding *ret; | |
211 | ||
212 | assert(c != NULL); | |
213 | ||
214 | va_start(ap, c); | |
215 | ret = krb5_config_vget_list (NULL, c, ap); | |
216 | va_end(ap); | |
217 | ||
218 | return ret; | |
219 | } | |
220 | #endif |