1 /* Copyright (c) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include <stdio_ext.h>
30 #include <sys/param.h>
31 #include <sys/types.h>
36 /* Wrapper functions with error checking for standard functions. */
37 extern char *xstrdup (const char *s
);
40 /* Names of the databases. */
41 const char *dbnames
[lastdb
] =
49 nscd_parse_file (const char *fname
, struct database_dyn dbs
[lastdb
])
52 char *line
, *cp
, *entry
, *arg1
, *arg2
;
56 /* Open the configuration file. */
57 fp
= fopen (fname
, "r");
61 /* The stream is not used by more than one thread. */
62 (void) __fsetlocking (fp
, FSETLOCKING_BYCALLER
);
69 ssize_t n
= getline (&line
, &len
, fp
);
72 if (line
[n
- 1] == '\n')
75 /* Because the file format does not know any form of quoting we
76 can search forward for the next '#' character and if found
77 make it terminating the line. */
78 *strchrnul (line
, '#') = '\0';
80 /* If the line is blank it is ignored. */
85 while (isspace (*entry
) && *entry
!= '\0')
88 while (!isspace (*cp
) && *cp
!= '\0')
93 if (strlen (entry
) == 0)
94 dbg_log (_("Parse error: %s"), line
);
95 while (isspace (*arg1
) && *arg1
!= '\0')
98 while (!isspace (*cp
) && *cp
!= '\0')
103 if (strlen (arg2
) > 0)
105 while (isspace (*arg2
) && *arg2
!= '\0')
108 while (!isspace (*cp
) && *cp
!= '\0')
113 if (strcmp (entry
, "positive-time-to-live") == 0)
115 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
116 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
118 dbs
[cnt
].postimeout
= atol (arg2
);
122 dbg_log ("database %s is not supported\n", arg1
);
124 else if (strcmp (entry
, "negative-time-to-live") == 0)
126 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
127 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
129 dbs
[cnt
].negtimeout
= atol (arg2
);
133 dbg_log ("database %s is not supported\n", arg1
);
135 else if (strcmp (entry
, "suggested-size") == 0)
137 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
138 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
140 dbs
[cnt
].suggested_module
= atol (arg2
);
144 dbg_log ("database %s is not supported\n", arg1
);
146 else if (strcmp (entry
, "enable-cache") == 0)
148 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
149 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
151 if (strcmp (arg2
, "no") == 0)
152 dbs
[cnt
].enabled
= 0;
153 else if (strcmp (arg2
, "yes") == 0)
154 dbs
[cnt
].enabled
= 1;
158 dbg_log ("database %s is not supported\n", arg1
);
160 else if (strcmp (entry
, "check-files") == 0)
162 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
163 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
165 if (strcmp (arg2
, "no") == 0)
166 dbs
[cnt
].check_file
= 0;
167 else if (strcmp (arg2
, "yes") == 0)
168 dbs
[cnt
].check_file
= 1;
172 dbg_log ("database %s is not supported\n", arg1
);
174 else if (strcmp (entry
, "logfile") == 0)
176 else if (strcmp (entry
, "debug-level") == 0)
178 int level
= atoi (arg1
);
182 else if (strcmp (entry
, "threads") == 0)
185 nthreads
= MAX (atol (arg1
), lastdb
);
187 else if (strcmp (entry
, "max-threads") == 0)
189 max_nthreads
= MAX (atol (arg1
), lastdb
);
191 else if (strcmp (entry
, "server-user") == 0)
194 dbg_log (_("Must specify user name for server-user option"));
196 server_user
= xstrdup (arg1
);
198 else if (strcmp (entry
, "stat-user") == 0)
201 dbg_log (_("Must specify user name for stat-user option"));
204 stat_user
= xstrdup (arg1
);
206 struct passwd
*pw
= getpwnam (stat_user
);
208 stat_uid
= pw
->pw_uid
;
211 else if (strcmp (entry
, "persistent") == 0)
213 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
214 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
216 if (strcmp (arg2
, "no") == 0)
217 dbs
[cnt
].persistent
= 0;
218 else if (strcmp (arg2
, "yes") == 0)
219 dbs
[cnt
].persistent
= 1;
223 dbg_log ("database %s is not supported\n", arg1
);
225 else if (strcmp (entry
, "shared") == 0)
227 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
228 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
230 if (strcmp (arg2
, "no") == 0)
232 else if (strcmp (arg2
, "yes") == 0)
237 dbg_log ("database %s is not supported\n", arg1
);
239 else if (strcmp (entry
, "reload-count") == 0)
241 if (strcasecmp (arg1
, "unlimited") == 0)
242 reload_count
= UINT_MAX
;
245 unsigned int count
= strtoul (arg1
, NULL
, 0);
246 if (count
> UINT8_MAX
- 1)
247 reload_count
= UINT_MAX
;
249 reload_count
= count
;
251 dbg_log (_("invalid value for 'reload-count': %u"), count
);
254 else if (strcmp (entry
, "paranoia") == 0)
256 if (strcmp (arg1
, "no") == 0)
258 else if (strcmp (arg1
, "yes") == 0)
261 else if (strcmp (entry
, "restart-interval") == 0)
264 restart_interval
= atol (arg1
);
266 dbg_log (_("Must specify value for restart-interval option"));
269 dbg_log (_("Unknown option: %s %s %s"), entry
, arg1
, arg2
);
271 while (!feof_unlocked (fp
));
275 restart_time
= time (NULL
) + restart_interval
;
277 /* Save the old current workding directory if we are in paranoia
278 mode. We have to change back to it. */
279 oldcwd
= get_current_dir_name ();
283 cannot get current working directory: %s; disabling paranoia mode"),
289 /* Enforce sanity. */
290 if (max_nthreads
< nthreads
)
291 max_nthreads
= nthreads
;
293 /* Free the buffer. */
295 /* Close configuration file. */