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
24 #include <stdio_ext.h>
28 #include <sys/param.h>
29 #include <sys/types.h>
34 /* Wrapper functions with error checking for standard functions. */
35 extern char *xstrdup (const char *s
);
38 /* Names of the databases. */
39 const char *dbnames
[lastdb
] =
47 nscd_parse_file (const char *fname
, struct database_dyn dbs
[lastdb
])
50 char *line
, *cp
, *entry
, *arg1
, *arg2
;
54 /* Open the configuration file. */
55 fp
= fopen (fname
, "r");
59 /* The stream is not used by more than one thread. */
60 (void) __fsetlocking (fp
, FSETLOCKING_BYCALLER
);
67 ssize_t n
= getline (&line
, &len
, fp
);
70 if (line
[n
- 1] == '\n')
73 /* Because the file format does not know any form of quoting we
74 can search forward for the next '#' character and if found
75 make it terminating the line. */
76 *strchrnul (line
, '#') = '\0';
78 /* If the line is blank it is ignored. */
83 while (isspace (*entry
) && *entry
!= '\0')
86 while (!isspace (*cp
) && *cp
!= '\0')
91 if (strlen (entry
) == 0)
92 dbg_log (_("Parse error: %s"), line
);
93 while (isspace (*arg1
) && *arg1
!= '\0')
96 while (!isspace (*cp
) && *cp
!= '\0')
101 if (strlen (arg2
) > 0)
103 while (isspace (*arg2
) && *arg2
!= '\0')
106 while (!isspace (*cp
) && *cp
!= '\0')
111 if (strcmp (entry
, "positive-time-to-live") == 0)
113 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
114 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
116 dbs
[cnt
].postimeout
= atol (arg2
);
120 dbg_log ("database %s is not supported\n", arg1
);
122 else if (strcmp (entry
, "negative-time-to-live") == 0)
124 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
125 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
127 dbs
[cnt
].negtimeout
= atol (arg2
);
131 dbg_log ("database %s is not supported\n", arg1
);
133 else if (strcmp (entry
, "suggested-size") == 0)
135 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
136 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
138 dbs
[cnt
].suggested_module
= atol (arg2
);
142 dbg_log ("database %s is not supported\n", arg1
);
144 else if (strcmp (entry
, "enable-cache") == 0)
146 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
147 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
149 if (strcmp (arg2
, "no") == 0)
150 dbs
[cnt
].enabled
= 0;
151 else if (strcmp (arg2
, "yes") == 0)
152 dbs
[cnt
].enabled
= 1;
156 dbg_log ("database %s is not supported\n", arg1
);
158 else if (strcmp (entry
, "check-files") == 0)
160 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
161 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
163 if (strcmp (arg2
, "no") == 0)
164 dbs
[cnt
].check_file
= 0;
165 else if (strcmp (arg2
, "yes") == 0)
166 dbs
[cnt
].check_file
= 1;
170 dbg_log ("database %s is not supported\n", arg1
);
172 else if (strcmp (entry
, "logfile") == 0)
174 else if (strcmp (entry
, "debug-level") == 0)
176 int level
= atoi (arg1
);
180 else if (strcmp (entry
, "threads") == 0)
183 nthreads
= MAX (atol (arg1
), lastdb
);
185 else if (strcmp (entry
, "server-user") == 0)
188 dbg_log (_("Must specify user name for server-user option"));
190 server_user
= xstrdup (arg1
);
192 else if (strcmp (entry
, "stat-user") == 0)
195 dbg_log (_("Must specify user name for stat-user option"));
198 stat_user
= xstrdup (arg1
);
200 struct passwd
*pw
= getpwnam (stat_user
);
202 stat_uid
= pw
->pw_uid
;
205 else if (strcmp (entry
, "persistent") == 0)
207 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
208 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
210 if (strcmp (arg2
, "no") == 0)
211 dbs
[cnt
].persistent
= 0;
212 else if (strcmp (arg2
, "yes") == 0)
213 dbs
[cnt
].persistent
= 1;
217 dbg_log ("database %s is not supported\n", arg1
);
219 else if (strcmp (entry
, "shared") == 0)
221 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
222 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
224 if (strcmp (arg2
, "no") == 0)
226 else if (strcmp (arg2
, "yes") == 0)
227 #ifndef atomic_supports_shared
228 #define atomic_supports_shared 1
230 dbs
[cnt
].shared
= atomic_supports_shared
;
234 dbg_log ("database %s is not supported\n", arg1
);
236 else if (strcmp (entry
, "reload-count") == 0)
238 if (strcasecmp (arg1
, "unlimited") == 0)
239 reload_count
= UINT_MAX
;
242 unsigned int count
= strtoul (arg1
, NULL
, 0);
243 if (count
> UINT8_MAX
- 1)
244 reload_count
= UINT_MAX
;
246 reload_count
= count
;
248 dbg_log (_("invalid value for 'reload-count': %u"), count
);
252 dbg_log (_("Unknown option: %s %s %s"), entry
, arg1
, arg2
);
254 while (!feof_unlocked (fp
));
256 /* Free the buffer. */
258 /* Close configuration file. */