pidentd  3.0.19
About: implementation of the RFC1413 identification server (more or less complete rewrite compared to version 2)
  Fossies Dox: pidentd-3.0.19.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

conf.c
Go to the documentation of this file.
1 /*
2 ** conf.c - Parse the config file
3 **
4 ** Copyright (c) 1997-1998 Peter Eriksson <pen@lysator.liu.se>
5 **
6 ** This program is free software; you can redistribute it and/or
7 ** modify it as you wish - as long as you don't claim that you wrote
8 ** it.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 */
14 
15 #include "config.h"
16 
17 #include <stdio.h>
18 #include <ctype.h>
19 #include <string.h>
20 #include <syslog.h>
21 
22 #include "pidentd.h"
23 
24 
25 int
26 conf_parse(const char *path,
27  int silent)
28 {
29  FILE *fp;
30  char buf[1024], *cp, *sp, *arg;
31  int line;
32 
33 
34  fp = fopen(path, "r");
35  if (fp == NULL)
36  {
37  if (!silent)
38  syslog(LOG_ERR, "fopen(\"%s\"): %m", path);
39 
40  return -1;
41  }
42 
43  line = 0;
44  while (fgets(buf, sizeof(buf), fp))
45  {
46  ++line;
47 
48  cp = strchr(buf, '#');
49  if (cp != NULL)
50  *cp = '\0';
51 
52  cp = s_strtok_r(buf, " \t\r\n", &sp);
53  if (cp == NULL)
54  continue;
55 
56  arg = s_strtok_r(NULL, " \t\r\n", &sp);
57  if (arg == NULL || strcmp(arg, "=") != 0)
58  {
59  syslog(LOG_ERR, "%s: %d: missing '='", path, line);
60  continue;
61  }
62 
63  arg = s_strtok_r(NULL, "\r\n", &sp);
64  if (arg == NULL)
65  {
66  syslog(LOG_ERR, "%s: %d: missing argument", path, line);
67  continue;
68  }
69 
70 
71  if (debug)
72  fprintf(stderr, "conf_parse(\"%s\"), line #%d: %s = %s\n",
73  path, line, cp, arg ? arg : "");
74 
75 
76  /* Global directives */
77 
78  if (strcasecmp(cp, "include") == 0)
79  {
80  conf_parse(arg, silent);
81  }
82 
83 
84 
85  /* Global variables */
86 
87  else if (strcasecmp(cp, "syslog:facility") == 0)
88  {
89  int code = syslog_str2fac(arg);
90 
91  if (code < 0)
92  syslog(LOG_ERR, "%s: %d: invalid syslog facility: %s",
93  path, line, arg);
94  else
95  {
96  closelog();
97  s_openlog(argv0, LOG_PID|LOG_ODELAY, code);
98  }
99  }
100 
101 
102  /* Server variables */
103 
104  else if (strcasecmp(cp, "server:port") == 0)
105  {
106  if (str2port(arg, &listen_port) < 0)
107  syslog(LOG_ERR, "%s: %d: invalid port: %s",
108  path, line, arg);
109  }
110 
111  else if (strcasecmp(cp, "server:backlog") == 0)
112  {
113  if (str2int(arg, &listen_backlog) < 0)
114  syslog(LOG_ERR, "%s: %d: invalid number: %s",
115  path, line, arg);
116  }
117 
118 #if 0 /* Enable when we have a str2addr() */
119  else if (strcasecmp(cp, "server:address") == 0)
120  {
121  if (str2addr(arg, &listen_address) < 0)
122  syslog(LOG_ERR, "%s: %d: invalid address: %s",
123  path, line, arg);
124  }
125 #endif
126 
127  else if (strcasecmp(cp, "server:user") == 0)
128  {
129  if (str2uid(arg, &server_uid, &server_gid) < 0)
130  syslog(LOG_ERR, "%s: %d: invalid user: %s",
131  path, line, arg);
132  }
133 
134 
135  else if (strcasecmp(cp, "server:group") == 0)
136  {
137  if (str2gid(arg, &server_gid) < 0)
138  syslog(LOG_ERR, "%s: %d: invalid group: %s",
139  path, line, arg);
140  }
141 
142 
143  else if (strcasecmp(cp, "server:pid-file") == 0)
144  {
145  if (str2str(arg, &pidfile_path) < 0)
146  syslog(LOG_ERR, "%s: %d: invalid string: %s",
147  path, line, arg);
148  }
149 
150  else if (strcasecmp(cp, "server:max-requests") == 0)
151  {
152  if (str2int(arg, &requests_max) < 0)
153  syslog(LOG_ERR, "%s: %d: invalid integer: %s",
154  path, line, arg);
155  }
156 
157 
158  /* Protocol variables */
159 
160  else if (strcasecmp(cp, "protocol:extensions") == 0)
161  {
162  if (str2bool(arg, &extensions_enabled) < 0)
163  syslog(LOG_ERR, "%s: %d: invalid bool: %s",
164  path, line, arg);
165  }
166 
167  else if (strcasecmp(cp, "protocol:multiquery") == 0)
168  {
169  if (str2bool(arg, &multiquery_enabled) < 0)
170  syslog(LOG_ERR, "%s: %d: invalid bool: %s",
171  path, line, arg);
172  }
173 
174  else if (strcasecmp(cp, "protocol:timeout") == 0)
175  {
176  if (str2int(arg, &request_timeout) < 0)
177  syslog(LOG_ERR, "%s: %d: invalid integer: %s",
178  path, line, arg);
179  }
180 
181 
182  /* Result variables */
183 
184  else if (strcasecmp(cp, "result:noident") == 0)
185  {
186  if (str2bool(arg, &noident_flag) < 0)
187  syslog(LOG_ERR, "%s: %d: invalid bool: %s",
188  path, line, arg);
189  }
190 
191 
192  else if (strcasecmp(cp, "result:uid-only") == 0)
193  {
194  if (str2bool(arg, &uidonly_flag) < 0)
195  syslog(LOG_ERR, "%s: %d: invalid bool: %s",
196  path, line, arg);
197  }
198 
199 #ifdef HAVE_LIBDES
200  else if (strcasecmp(cp, "result:encrypt") == 0)
201  {
202  if (str2bool(arg, &encrypt_flag) < 0)
203  syslog(LOG_ERR, "%s: %d: invalid bool: %s",
204  path, line, arg);
205  }
206 #endif
207 
208  else if (strcasecmp(cp, "result:charset") == 0)
209  {
210  if (str2str(arg, &charset) < 0)
211  syslog(LOG_ERR, "%s: %d: invalid string: %s",
212  path, line, arg);
213  }
214 
215  else if (strcasecmp(cp, "result:opsys") == 0)
216  {
217  if (str2str(arg, &opsys) < 0)
218  syslog(LOG_ERR, "%s: %d: invalid string: %s",
219  path, line, arg);
220  }
221 
222  else if (strcasecmp(cp, "result:syslog-level") == 0)
223  {
224  if (arg && strcasecmp(arg, "none") == 0)
225  result_syslog_level = -1;
226  else
227  {
228  int code = syslog_str2lev(arg);
229 
230  if (code < 0)
231  syslog(LOG_ERR, "%s: %d: invalid syslog level: %s",
232  path, line, arg);
233  else
234  result_syslog_level = code;
235  }
236  }
237 
238 
239  /* Kernel variables */
240 
241  else if (strcasecmp(cp, "kernel:threads") == 0)
242  {
243  if (str2int(arg, &kernel_threads) < 0)
244  syslog(LOG_ERR, "%s: %d: invalid integer: %s",
245  path, line, arg);
246  }
247 
248  else if (strcasecmp(cp, "kernel:attempts") == 0)
249  {
250  if (str2int(arg, &kernel_attempts) < 0)
251  syslog(LOG_ERR, "%s: %d: invalid integer: %s",
252  path, line, arg);
253  }
254 
255  else if (strcasecmp(cp, "kernel:buffers") == 0)
256  {
257  if (str2int(arg, &kernel_buffers) < 0)
258  syslog(LOG_ERR, "%s: %d: invalid integer: %s",
259  path, line, arg);
260  }
261 
262 #ifdef HAVE_LIBDES
263  else if (strcasecmp(cp, "encrypt:key-file") == 0)
264  {
265  if (str2str(arg, &encrypt_keyfile) < 0)
266  syslog(LOG_ERR, "%s: %d: invalid string: %s",
267  path, line, arg);
268  }
269 #endif
270 
271  else
272  syslog(LOG_ERR, "%s: %d: unknown option: %s", path, line, cp);
273  }
274 
275  fclose(fp);
276  return 0;
277 }
opsys
char * opsys
Definition: send.c:36
extensions_enabled
int extensions_enabled
Definition: request.c:29
result_syslog_level
int result_syslog_level
Definition: send.c:33
request_timeout
int request_timeout
Definition: request.c:31
server_uid
uid_t server_uid
Definition: main.c:38
uidonly_flag
int uidonly_flag
Definition: send.c:31
syslog_str2fac
int syslog_str2fac(const char *name)
Definition: support.c:411
pidentd.h
argv0
char * argv0
Definition: main.c:35
kernel_threads
int kernel_threads
Definition: kernel.c:34
charset
char * charset
Definition: send.c:35
pidfile_path
char * pidfile_path
Definition: main.c:40
conf_parse
int conf_parse(const char *path, int silent)
Definition: conf.c:26
LOG_ODELAY
#define LOG_ODELAY
Definition: system.h:32
str2gid
int str2gid(const char *str, gid_t *out)
Definition: str2.c:159
s_strtok_r
char * s_strtok_r(char *s, const char *d, char **bp)
Definition: support.c:106
server_gid
gid_t server_gid
Definition: main.c:39
debug
int debug
Definition: gen_osinfo.c:23
str2port
int str2port(const char *str, int *out)
Definition: str2.c:136
noident_flag
int noident_flag
Definition: send.c:32
multiquery_enabled
int multiquery_enabled
Definition: request.c:30
str2int
int str2int(const char *buf, int *out)
Definition: str2.c:50
listen_backlog
int listen_backlog
Definition: server.c:31
str2str
int str2str(char *buf, char **out)
Definition: str2.c:62
syslog_str2lev
int syslog_str2lev(const char *name)
kernel_attempts
int kernel_attempts
Definition: kernel.c:36
s_openlog
void s_openlog(const char *ident, int logopt, int facility)
Definition: support.c:348
kernel_buffers
int kernel_buffers
Definition: kernel.c:35
listen_port
int listen_port
Definition: server.c:29
str2uid
int str2uid(const char *str, uid_t *uid, gid_t *gid)
Definition: str2.c:180
requests_max
int requests_max
Definition: request.c:33
str2bool
int str2bool(const char *buf, int *out)
Definition: str2.c:105