Release bumped to "gts4".
[tac_plus.git] / parse.c
1 /*
2    Copyright (c) 1995-1998 by Cisco systems, Inc.
3
4    Permission to use, copy, modify, and distribute this software for
5    any purpose and without fee is hereby granted, provided that this
6    copyright and permission notice appear on all copies of the
7    software and supporting documentation, the name of Cisco Systems,
8    Inc. not be used in advertising or publicity pertaining to
9    distribution of the program without specific prior permission, and
10    notice be given in supporting documentation that modification,
11    copying and distribution is by permission of Cisco Systems, Inc.
12
13    Cisco Systems, Inc. makes no representations about the suitability
14    of this software for any purpose.  THIS SOFTWARE IS PROVIDED ``AS
15    IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
16    WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17    FITNESS FOR A PARTICULAR PURPOSE.
18 */
19
20 /* Keywords of the configuration language */
21
22
23 #include "tac_plus.h"
24
25 #include "parse.h"
26 #include "utils.h"
27 #include "report.h"
28 #include "hash.h"
29
30
31 static void *wordtable[HASH_TAB_SIZE];  /* Table of keyword declarations */
32
33 struct keyword {
34     char *word;
35     void *hash;
36     u_char value;
37 };
38
39 typedef struct keyword KEYWORD;
40
41 static void declare TAC_ARGS((char *name, int value));
42
43 static void
44 declare(name, value)
45     char *name;
46     int value;
47 {
48     KEYWORD *n;
49     KEYWORD *k = (KEYWORD *)tac_malloc(sizeof(KEYWORD));
50
51     k->word = tac_strdup(name);
52     k->value = value;
53
54     n = hash_add_entry(wordtable, (void *) k);
55
56     if (n) {
57         report(LOG_ERR, "Attempt to multiply define keyword %s",
58                name);
59         tac_exit(1);
60     }
61 }
62
63 /* Declare keywords of the "configuration language". */
64
65 void parser_init TAC_ARGS((void));
66
67 void
68 parser_init()
69 {
70     bzero(wordtable, sizeof(wordtable));
71
72     declare("access", S_access);
73     declare("accounting", S_accounting);
74     declare("after", S_after);
75     declare("arap", S_arap);
76     declare("attribute", S_attr);
77     declare("authentication", S_authentication);
78     declare("authorization", S_authorization);
79     declare("before", S_before);
80     declare("chap", S_chap);
81 #ifdef MSCHAP
82     declare("ms-chap", S_mschap);
83 #endif /* MSCHAP */
84     declare("cleartext", S_cleartext);
85 #ifdef USE_PAM
86     declare("pam", S_pam);
87 #endif /*USE_PAM */
88     declare("nopassword", S_nopasswd);
89     declare("cmd", S_cmd);
90     declare("default", S_default);
91     declare("deny", S_deny);
92     declare("des", S_des);
93     declare("exec", S_exec);
94     declare("expires", S_expires);
95     declare("file", S_file);
96     declare("group", S_group);
97     declare("global", S_global);
98     declare("host", S_host);
99     declare("ip", S_ip);
100     declare("ipx", S_ipx);
101     declare("key", S_key);
102     declare("lcp", S_lcp);
103 #ifdef MAXSESS
104     declare("maxsess", S_maxsess);
105 #endif
106 #ifdef DB
107     declare("db", S_db);
108     declare("db_accounting",S_db_accounting);
109 #endif
110 #ifdef USE_LDAP
111     declare ("ldap", S_ldap);
112 #endif
113     declare("member", S_member);
114     declare("message", S_message);
115     declare("name", S_name);
116     declare("optional", S_optional);
117     declare("login", S_login);
118     declare("permit", S_permit);
119     declare("pap", S_pap);
120     declare("opap", S_opap);
121     declare("ppp", S_ppp);
122     declare("protocol", S_protocol);
123     declare("skey", S_skey);
124     declare("slip", S_slip);
125     declare("service", S_svc);
126     declare("user", S_user);
127     declare("time", S_time);
128     declare("and", S_and);
129     declare("closeparen", S_closeparen);
130     declare("enlist", S_enlist);
131     declare("first", S_first);
132     declare("not", S_not);
133     declare("openparen", S_openparen);
134     declare("or", S_or);
135     declare("recursive", S_recursive);
136     declare("when", S_when);
137 }
138
139 int keycode TAC_ARGS((const char *keyword));
140
141 /* Return a keyword code if a keyword is recognized. 0 otherwise */
142 int
143 keycode(keyword)
144 const char *keyword;
145 {
146     KEYWORD *k = hash_lookup(wordtable, keyword);
147
148     if (k)
149         return (k->value);
150     return (S_unknown);
151 }
152
153 const char *codestring TAC_ARGS((int type));
154
155 const char *
156 codestring(type)
157 int type;
158 {
159     switch (type) {
160     default:
161         return ("<unknown symbol>");
162     case S_eof:
163         return ("end-of-file");
164     case S_unknown:
165         return ("unknown");
166     case S_separator:
167         return ("=");
168     case S_string:
169         return ("<string>");
170     case S_openbra:
171         return ("{");
172     case S_closebra:
173         return ("}");
174     case S_key:
175         return ("key");
176     case S_user:
177         return ("user");
178     case S_group:
179         return ("group");
180     case S_host:
181         return ("host");
182     case S_file:
183         return ("file");
184     case S_skey:
185         return ("skey");
186     case S_name:
187         return ("name");
188     case S_login:
189         return ("login");
190     case S_member:
191         return ("member");
192 #ifdef MAXSESS
193     case S_maxsess:
194         return ("maxsess");
195 #endif
196 #ifdef DB
197     case S_db:
198         return ("db");
199     case S_db_accounting:
200         return ("db_accounting");
201 #endif
202    case S_expires:
203         return ("expires");
204     case S_after:
205         return ("after");
206     case S_before:
207         return ("before");
208     case S_message:
209         return ("message");
210     case S_arap:
211         return ("arap");
212     case S_global:
213         return ("global");
214     case S_chap:
215         return ("chap");
216 #ifdef MSCHAP
217     case S_mschap:
218         return ("ms-chap");
219 #endif /* MSCHAP */
220     case S_pap:
221         return ("pap");
222     case S_opap:
223         return ("opap");
224     case S_cleartext:
225         return ("cleartext");
226 #ifdef USE_PAM
227     case S_pam:
228         return ("pam");
229 #endif /*USE_PAM */
230     case S_nopasswd:
231         return("nopassword");
232     case S_des:
233         return("des");
234     case S_svc:
235         return ("service");
236     case S_default:
237         return ("default");
238     case S_access:
239         return ("access");
240     case S_deny:
241         return ("deny");
242     case S_permit:
243         return ("permit");
244     case S_exec:
245         return ("exec");
246     case S_protocol:
247         return ("protocol");
248     case S_optional:
249         return ("optional");
250     case S_ip:
251         return ("ip");
252     case S_ipx:
253         return ("ipx");
254     case S_slip:
255         return ("slip");
256     case S_ppp:
257         return ("ppp");
258     case S_authentication:
259         return ("authentication");
260     case S_authorization:
261         return ("authorization");
262     case S_cmd:
263         return ("cmd");
264     case S_attr:
265         return ("attribute");
266     case S_svc_dflt:
267         return ("svc_dflt");
268     case S_accounting:
269         return ("accounting");
270     case S_lcp:
271         return("lcp");
272     case S_time:
273         return("time");
274     case S_and:
275         return("and");
276     case S_closeparen:
277         return(")");
278     case S_enlist:
279         return("enlist");
280     case S_first:
281         return("first");
282     case S_not:
283         return("not");
284     case S_openparen:
285         return("(");
286     case S_or:
287         return("or");
288     case S_recursive:
289         return("recursive");
290     case S_when:
291         return("when");
292     }
293 }