Import of tac_plus.v8.tar.gz: 173206 bytes, md5:
[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 #include "tac_plus.h"
23
24 static void *wordtable[HASH_TAB_SIZE];  /* Table of keyword declarations */
25
26 struct keyword {
27     char *word;
28     void *hash;
29     u_char value;
30 };
31
32 typedef struct keyword KEYWORD;
33
34 static void
35 declare(name, value)
36     char *name;
37     int value;
38 {
39     KEYWORD *n;
40     KEYWORD *k = (KEYWORD *)tac_malloc(sizeof(KEYWORD));
41
42     k->word = tac_strdup(name);
43     k->value = value;
44
45     n = hash_add_entry(wordtable, (void *) k);
46
47     if (n) {
48         report(LOG_ERR, "Attempt to multiply define keyword %s",
49                name);
50         tac_exit(1);
51     }
52 }
53
54 /* Declare keywords of the "configuration language". */
55
56 void 
57 parser_init()
58 {
59     bzero(wordtable, sizeof(wordtable));
60
61     declare("access", S_access);
62     declare("accounting", S_accounting);
63     declare("after", S_after);
64     declare("arap", S_arap);
65     declare("attribute", S_attr);
66     declare("authentication", S_authentication);
67     declare("authorization", S_authorization);
68     declare("before", S_before);
69     declare("chap", S_chap);
70 #ifdef MSCHAP
71     declare("ms-chap", S_mschap);
72 #endif /* MSCHAP */
73     declare("cleartext", S_cleartext);
74 #ifdef USE_PAM
75     declare("pam", S_pam);
76 #endif /*USE_PAM */
77     declare("nopassword", S_nopasswd);
78     declare("cmd", S_cmd);
79     declare("default", S_default);
80     declare("deny", S_deny);
81     declare("des", S_des);
82     declare("exec", S_exec);
83     declare("expires", S_expires);
84     declare("file", S_file);
85     declare("group", S_group);
86     declare("global", S_global);
87     declare("host", S_host);
88     declare("type", S_type);
89     declare("ip", S_ip);
90     declare("ipx", S_ipx);
91     declare("key", S_key);
92     declare("lcp", S_lcp);
93 #ifdef MAXSESS
94     declare("maxsess", S_maxsess);
95 #endif
96 #ifdef DB
97     declare("db", S_db);
98     declare("db_accounting",S_db_accounting);
99 #endif
100 #ifdef USE_LDAP
101     declare ("ldap", S_ldap);
102 #endif
103     declare("member", S_member);
104     declare("message", S_message);
105     declare("name", S_name);
106     declare("optional", S_optional);
107     declare("login", S_login);
108     declare("permit", S_permit);
109     declare("pap", S_pap);
110     declare("opap", S_opap);
111     declare("ppp", S_ppp);
112     declare("protocol", S_protocol);
113     declare("skey", S_skey);
114     declare("slip", S_slip);
115     declare("service", S_svc);
116     declare("user", S_user);
117     declare("time", S_time);
118 }
119
120 /* Return a keyword code if a keyword is recognized. 0 otherwise */
121 int
122 keycode(keyword)
123 char *keyword;
124 {
125     KEYWORD *k = hash_lookup(wordtable, keyword);
126
127     if (k)
128         return (k->value);
129     return (S_unknown);
130 }
131
132 char *
133 codestring(type)
134 int type;
135 {
136     switch (type) {
137     default:
138         return ("<unknown symbol>");
139     case S_eof:
140         return ("end-of-file");
141     case S_unknown:
142         return ("unknown");
143     case S_separator:
144         return ("=");
145     case S_string:
146         return ("<string>");
147     case S_openbra:
148         return ("{");
149     case S_closebra:
150         return ("}");
151     case S_key:
152         return ("key");
153     case S_user:
154         return ("user");
155     case S_group:
156         return ("group");
157     case S_host:
158         return ("host");
159     case S_type:
160         return ("type");
161     case S_file:
162         return ("file");
163     case S_skey:
164         return ("skey");
165     case S_name:
166         return ("name");
167     case S_login:
168         return ("login");
169     case S_member:
170         return ("member");
171 #ifdef MAXSESS
172     case S_maxsess:
173         return ("maxsess");
174 #endif
175 #ifdef DB
176     case S_db:
177         return ("db");
178     case S_db_accounting:
179         return ("db_accounting");
180 #endif
181    case S_expires:
182         return ("expires");
183     case S_after:
184         return ("after");
185     case S_before:
186         return ("before");
187     case S_message:
188         return ("message");
189     case S_arap:
190         return ("arap");
191     case S_global:
192         return ("global");
193     case S_chap:
194         return ("chap");
195 #ifdef MSCHAP
196     case S_mschap:
197         return ("ms-chap");
198 #endif /* MSCHAP */
199     case S_pap:
200         return ("pap");
201     case S_opap:
202         return ("opap");
203     case S_cleartext:
204         return ("cleartext");
205 #ifdef USE_PAM
206     case S_pam:
207         return ("pam");
208 #endif /*USE_PAM */     
209     case S_nopasswd:
210         return("nopassword");
211     case S_des:
212         return("des");
213     case S_svc:
214         return ("service");
215     case S_default:
216         return ("default");
217     case S_access:
218         return ("access");
219     case S_deny:
220         return ("deny");
221     case S_permit:
222         return ("permit");
223     case S_exec:
224         return ("exec");
225     case S_protocol:
226         return ("protocol");
227     case S_optional:
228         return ("optional");
229     case S_ip:
230         return ("ip");
231     case S_ipx:
232         return ("ipx");
233     case S_slip:
234         return ("slip");
235     case S_ppp:
236         return ("ppp");
237     case S_authentication:
238         return ("authentication");
239     case S_authorization:
240         return ("authorization");
241     case S_cmd:
242         return ("cmd");
243     case S_attr:
244         return ("attribute");
245     case S_svc_dflt:
246         return ("svc_dflt");
247     case S_accounting:
248         return ("accounting");
249     case S_lcp:
250         return("lcp");
251     case S_time:
252         return("time");
253     }
254 }