This repository has been archived by the owner on Aug 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.c
234 lines (220 loc) · 4.96 KB
/
config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
* config.c: The efserv configuration file.
* This is part of efserv, a services.int implementation.
* efserv is Copyright(C) 2001 by Andrew Miller, and others.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA.
* $Id: config.c,v 1.13 2002/04/16 21:33:28 wcampbel Exp $
*/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "define.h"
#include "struct.h"
#include "utils.h"
#include "funcs.h"
#include "setup.h"
#ifdef HAVE_CRYPT_H
#include <crypt.h>
#endif
char *values[200][2];
int keyc;
FILE *yyin;
extern struct List *serv_admins;
extern int lineno;
void yyparse(void);
int
check_admin(struct User *usr, const char *name, const char *pass)
{
struct List *node;
struct ServAdmin *sa;
FORLIST(node, serv_admins, struct ServAdmin *, sa)
if (!strcasecmp(sa->name, name))
{
#ifdef USE_CRYPT
if (!strcmp(sa->pass, crypt(pass, sa->pass)))
#else
if (!strcmp(sa->pass, pass))
#endif
{
struct List *node;
struct AdminHost *ah;
/* Now we have to go through and check against their server and
* their host... */
FORLIST(node, sa->hosts, struct AdminHost *, ah)
if (match(ah->user, usr->user) &&
match(ah->server, usr->server->name) &&
match(ah->host, usr->host))
{
usr->flags |= UFLAG_SERVADMIN;
usr->caps = sa->caps;
if (usr->sa)
deref_admin(usr->sa);
usr->sa = sa;
usr->sa->refcount++;
return -1;
}
return 0;
}
else
return 0;
}
return 0;
}
struct VoteServer *
find_server_vote(const char *name)
{
struct List *node, *node2;
struct VoteServer *vs;
char *tname;
FORLIST(node, VoteServers, struct VoteServer *, vs)
FORLIST(node2, vs->names, char *, tname) if (match(tname, name))
return vs;
return NULL;
}
void
yyerror(char *msg)
{
log("[Config] Lex error, line %d: %s\n", lineno, msg);
return;
}
void
check_complete(void)
{
if (server_name == NULL || sn == NULL)
fatal_error("General block is missing or incomplete.\n");
}
void
read_config_file(const char *file)
{
FILE *fle;
if ((fle = fopen(file, "r")) == NULL)
{
fatal_error("Could not read from %s.\n", file);
return;
}
yyin = fle;
yyparse();
fclose(fle);
}
void
read_all_config(void)
{
read_config_file(ETCPATH "efserv.conf");
check_complete();
}
void
deref_admin(struct ServAdmin *ad)
{
struct List *node, *nnode;
struct AdminHost *ah;
ad->refcount--;
if (ad->refcount > 0)
return;
if (ad->name)
free(ad->name);
if (ad->pass)
free(ad->pass);
if (ad->hosts)
free(ad->hosts);
FORLISTDEL(node, nnode, ad->hosts, struct AdminHost *, ah)
{
free(ah->host);
free(ah->server);
free(ah->user);
free(ah);
free(node);
}
free(ad);
}
void
deref_voteserver(struct VoteServer *vs)
{
char *name;
struct List *node, *nnode;
vs->refcount--;
if (vs->refcount > 0)
return;
FORLISTDEL(node, nnode, vs->names, char *, name)
{
free(node);
free(name);
}
free(vs);
}
void
pick_a_hub(void)
{
struct List *node;
struct Hub *hub;
int hub_count = 0, hub_no;
FORLIST(node, Hubs, struct Hub *, hub) hub_count++;
if (hub_count == 0)
fatal_error("No hubs are defined, can't connect.\n");
hub_no = rand() % hub_count;
FORLIST(node, Hubs, struct Hub *, hub) if (hub_no-- == 0)
break;
server_host = hub->host;
port = hub->port;
server_pass = hub->pass;
}
void
do_rehash(void)
{
struct List *node, *nnode;
struct ServAdmin *sa;
struct VoteServer *vs;
struct JExempt *je;
struct Hub *hub;
char *kw;
FORLISTDEL(node, nnode, serv_admins, struct ServAdmin *, sa)
{
free(node);
if (sa->refcount == 0)
deref_admin(sa);
}
FORLISTDEL(node, nnode, VoteServers, struct VoteServer *, vs)
{
free(node);
if (vs->refcount == 0)
deref_voteserver(vs);
}
FORLISTDEL(node, nnode, Hubs, struct Hub *, hub)
{
free(hub->host);
free(hub->pass);
free(hub);
free(node);
}
FORLISTDEL(node, nnode, HKeywords, char *, kw)
{
free(kw);
free(node);
}
FORLISTDEL(node, nnode, JupeExempts, struct JExempt *, je)
{
free(je->name);
free(je);
}
VoteServers = NULL;
serv_admins = NULL;
Hubs = NULL;
HKeywords = NULL;
JupeExempts = NULL;
read_all_config();
}