1 /* Copyright (c) 1998, 2000 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
26 #include <sys/param.h>
27 #include <sys/types.h>
32 /* Names of the databases. */
33 const char *dbnames
[lastdb
] =
41 nscd_parse_file (const char *fname
, struct database dbs
[lastdb
])
44 char *line
, *cp
, *entry
, *arg1
, *arg2
;
48 /* Open the configuration file. */
49 fp
= fopen (fname
, "r");
58 ssize_t n
= getline (&line
, &len
, fp
);
61 if (line
[n
- 1] == '\n')
64 /* Because the file format does not know any form of quoting we
65 can search forward for the next '#' character and if found
66 make it terminating the line. */
67 *strchrnul (line
, '#') = '\0';
69 /* If the line is blank it is ignored. */
74 while (isspace (*entry
) && *entry
!= '\0')
77 while (!isspace (*cp
) && *cp
!= '\0')
82 if (strlen (entry
) == 0)
83 dbg_log (_("Parse error: %s"), line
);
84 while (isspace (*arg1
) && *arg1
!= '\0')
87 while (!isspace (*cp
) && *cp
!= '\0')
92 if (strlen (arg2
) > 0)
94 while (isspace (*arg2
) && *arg2
!= '\0')
97 while (!isspace (*cp
) && *cp
!= '\0')
102 if (strcmp (entry
, "positive-time-to-live") == 0)
104 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
105 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
107 dbs
[cnt
].postimeout
= atol (arg2
);
111 dbg_log ("server %s is not supported\n", arg1
);
113 else if (strcmp (entry
, "negative-time-to-live") == 0)
115 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
116 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
118 dbs
[cnt
].negtimeout
= atol (arg2
);
122 dbg_log ("server %s is not supported\n", arg1
);
124 else if (strcmp (entry
, "suggested-size") == 0)
126 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
127 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
129 dbs
[cnt
].module
= atol (arg2
);
133 dbg_log ("server %s is not supported\n", arg1
);
135 else if (strcmp (entry
, "enable-cache") == 0)
137 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
138 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
140 if (strcmp (arg2
, "no") == 0)
141 dbs
[cnt
].enabled
= 0;
142 else if (strcmp (arg2
, "yes") == 0)
143 dbs
[cnt
].enabled
= 1;
147 dbg_log ("server %s is not supported\n", arg1
);
149 else if (strcmp (entry
, "check-files") == 0)
151 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
152 if (strcmp (arg1
, dbnames
[cnt
]) == 0)
154 if (strcmp (arg2
, "no") == 0)
155 dbs
[cnt
].check_file
= 0;
156 else if (strcmp (arg2
, "yes") == 0)
157 dbs
[cnt
].check_file
= 1;
161 dbg_log ("server %s is not supported\n", arg1
);
163 else if (strcmp (entry
, "logfile") == 0)
165 if (!set_logfile (arg1
))
166 dbg_log (_("Could not create log file \"%s\""), arg1
);
168 else if (strcmp (entry
, "debug-level") == 0)
170 int level
= atoi (arg1
);
174 else if (strcmp (entry
, "threads") == 0)
177 nthreads
= MAX (atol (arg1
), lastdb
);
179 else if (strcmp (entry
, "server-user") == 0)
182 dbg_log (_("Must specify user name for server-user option"));
184 server_user
= strdup (arg1
);
187 dbg_log (_("Unknown option: %s %s %s"), entry
, arg1
, arg2
);
191 /* Free the buffer. */
193 /* Close configuration file. */