Update.
[glibc.git] / nscd / nscd_conf.c
blob62a1e6cbd180ddef96740b202e67b1be7d2ecb99
1 /* Copyright (c) 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.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. */
20 #include <ctype.h>
21 #include <malloc.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/types.h>
27 #include "dbg_log.h"
28 #include "nscd.h"
30 int
31 nscd_parse_file (const char *fname)
33 FILE *fp;
34 char *line, *cp, *entry, *arg1, *arg2;
35 size_t len;
37 /* Open the configuration file. */
38 fp = fopen (fname, "r");
39 if (fp == NULL)
40 return -1;
42 line = NULL;
43 len = 0;
47 ssize_t n = getline (&line, &len, fp);
48 if (n < 0)
49 break;
50 if (line[n - 1] == '\n')
51 line[n - 1] = '\0';
53 /* Because the file format does not know any form of quoting we
54 can search forward for the next '#' character and if found
55 make it terminating the line. */
56 cp = strchr (line, '#');
57 if (cp != NULL)
58 *cp = '\0';
60 /* If the line is blank it is ignored. */
61 if (line[0] == '\0')
62 continue;
64 entry = line;
65 while (isspace (*entry) && *entry != '\0')
66 ++entry;
67 cp = entry;
68 while (!isspace (*cp) && *cp != '\0')
69 ++cp;
70 arg1 = cp;
71 ++arg1;
72 *cp = '\0';
73 if (*cp = '\0' || strlen (entry) == 0)
74 dbg_log (_("Parse error: %s"), line);
75 while (isspace (*arg1) && *arg1 != '\0')
76 ++arg1;
77 cp = arg1;
78 while (!isspace (*cp) && *cp != '\0')
79 ++cp;
80 arg2 = cp;
81 ++arg2;
82 *cp = '\0';
83 if (strlen (arg2) > 0)
85 while (isspace (*arg2) && *arg2 != '\0')
86 ++arg2;
87 cp = arg2;
88 while (!isspace (*cp) && *cp != '\0')
89 ++cp;
90 *cp = '\0';
93 if (strcmp (entry, "positive-time-to-live") == 0)
95 if (strcmp (arg1, "passwd") == 0)
96 set_pos_pwd_ttl (atol (arg2));
97 else if (strcmp (arg1, "group") == 0)
98 set_pos_grp_ttl (atol (arg2));
99 else
100 dbg_log ("server %s is not supported\n", arg1);
102 else if (strcmp (entry, "negative-time-to-live") == 0)
104 if (strcmp (arg1, "passwd") == 0)
105 set_neg_pwd_ttl (atol (arg2));
106 else if (strcmp (arg1, "group") == 0)
107 set_neg_grp_ttl (atol (arg2));
108 else
109 dbg_log (_("service %s is not supported"), arg1);
111 else if (strcmp (entry, "suggested-size") == 0)
113 if (strcmp (arg1, "passwd") == 0)
114 set_pwd_modulo (atol (arg2));
115 else if (strcmp (arg1, "group") == 0)
116 set_grp_modulo (atol (arg2));
117 else
118 dbg_log (_("service %s is not supported"), arg1);
120 else if (strcmp (entry, "enable-cache") ==0)
122 if (strcmp (arg1, "passwd") == 0
123 && strcmp (arg2, "no") == 0)
124 disabled_passwd = 1;
125 else if (strcmp (arg1, "group") == 0
126 && strcmp (arg2, "no") == 0)
127 disabled_group = 1;
128 else
129 dbg_log (_("service %s is not supported"), arg1);
131 else if (strcmp (entry, "logfile") == 0)
133 if (!set_logfile (arg1))
134 dbg_log (_("Could not create log file \"%s\""), arg1);
136 else if (strcmp (entry, "debug-level") == 0)
138 int level = atoi (arg1);
139 if (level > 0)
140 debug_flag = level;
142 else
143 dbg_log (_("Unknown option: %s %s %s"), entry, arg1, arg2);
145 while (!feof (fp));
147 /* Free the buffer. */
148 free (line);
149 /* Close configuration file. */
150 fclose (fp);
152 return 0;