1 /* Copyright (c) 1998, 2000, 2003 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
27 #include <sys/param.h>
28 #include <sys/types.h>
33 /* Wrapper functions with error checking for standard functions. */
34 extern char *xstrdup (const char *s
);
37 /* Names of the databases. */
38 const char *dbnames
[lastdb
] =
46 nscd_parse_file (const char *fname
, struct database dbs
[lastdb
])
49 char *line
, *cp
, *entry
, *arg1
, *arg2
;
53 /* Open the configuration file. */
54 fp
= fopen (fname
, "r");
63 ssize_t n
= getline (&line
, &len
, fp
);
66 if (line
[n
- 1] == '\n')
69 /* Because the file format does not know any form of quoting we
70 can search forward for the next '#' character and if found
71 make it terminating the line. */
72 *strchrnul (line
, '#') = '\0';
74 /* If the line is blank it is ignored. */
79 while (isspace (*entry
) && *entry
!= '\0')
82 while (!isspace (*cp
) && *cp
!= '\0')
87 if (strlen (entry
) == 0)
88 dbg_log (_("Parse error: %s"), line
);
89 while (isspace (*arg1
) && *arg1
!= '\0')
92 while (!isspace (*cp
) && *cp
!= '\0')
97 if (strlen (arg2
) > 0)
99 while (isspace (*arg2
) && *arg2
!= '\0')
102 while (!isspace (*cp
) && *cp
!= '\0')
107 if (strcmp (entry
, "positive-time-to-live") == 0)
109 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
110 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
112 dbs
[cnt
].postimeout
= atol (arg2
);
116 dbg_log ("server %s is not supported\n", arg1
);
118 else if (strcmp (entry
, "negative-time-to-live") == 0)
120 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
121 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
123 dbs
[cnt
].negtimeout
= atol (arg2
);
127 dbg_log ("server %s is not supported\n", arg1
);
129 else if (strcmp (entry
, "suggested-size") == 0)
131 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
132 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
134 dbs
[cnt
].module
= atol (arg2
);
138 dbg_log ("server %s is not supported\n", arg1
);
140 else if (strcmp (entry
, "enable-cache") == 0)
142 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
143 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
145 if (strcmp (arg2
, "no") == 0)
146 dbs
[cnt
].enabled
= 0;
147 else if (strcmp (arg2
, "yes") == 0)
148 dbs
[cnt
].enabled
= 1;
152 dbg_log ("server %s is not supported\n", arg1
);
154 else if (strcmp (entry
, "check-files") == 0)
156 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
157 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
159 if (strcmp (arg2
, "no") == 0)
160 dbs
[cnt
].check_file
= 0;
161 else if (strcmp (arg2
, "yes") == 0)
162 dbs
[cnt
].check_file
= 1;
166 dbg_log ("server %s is not supported\n", arg1
);
168 else if (strcmp (entry
, "logfile") == 0)
170 if (!set_logfile (arg1
))
171 dbg_log (_("Could not create log file \"%s\""), arg1
);
173 else if (strcmp (entry
, "debug-level") == 0)
175 int level
= atoi (arg1
);
179 else if (strcmp (entry
, "threads") == 0)
182 nthreads
= MAX (atol (arg1
), lastdb
);
184 else if (strcmp (entry
, "server-user") == 0)
187 dbg_log (_("Must specify user name for server-user option"));
189 server_user
= xstrdup (arg1
);
191 else if (strcmp (entry
, "stat-user") == 0)
194 dbg_log (_("Must specify user name for stat-user option"));
197 stat_user
= xstrdup (arg1
);
199 struct passwd
*pw
= getpwnam (stat_user
);
201 stat_uid
= pw
->pw_uid
;
205 dbg_log (_("Unknown option: %s %s %s"), entry
, arg1
, arg2
);
209 /* Free the buffer. */
211 /* Close configuration file. */