s3:vfs: Correctly check if OFD locks should be enabled or not
[Samba.git] / lib / util / params.c
blobc5c252613d396af556485d38b1eab47bc8ded757
1 /* -------------------------------------------------------------------------- **
2 * Microsoft Network Services for Unix, AKA., Andrew Tridgell's SAMBA.
4 * This module Copyright (C) 1990-1998 Karl Auer
6 * Rewritten almost completely by Christopher R. Hertel
7 * at the University of Minnesota, September, 1997.
8 * This module Copyright (C) 1997-1998 by the University of Minnesota
9 * -------------------------------------------------------------------------- **
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 * -------------------------------------------------------------------------- **
26 * Module name: params
28 * -------------------------------------------------------------------------- **
30 * This module performs lexical analysis and initial parsing of a
31 * Windows-like parameter file. It recognizes and handles four token
32 * types: section-name, parameter-name, parameter-value, and
33 * end-of-file. Comments and line continuation are handled
34 * internally.
36 * The entry point to the module is function pm_process(). This
37 * function opens the source file, calls the Parse() function to parse
38 * the input, and then closes the file when either the EOF is reached
39 * or a fatal error is encountered.
41 * A sample parameter file might look like this:
43 * [section one]
44 * parameter one = value string
45 * parameter two = another value
46 * [section two]
47 * new parameter = some value or t'other
49 * The parameter file is divided into sections by section headers:
50 * section names enclosed in square brackets (eg. [section one]).
51 * Each section contains parameter lines, each of which consist of a
52 * parameter name and value delimited by an equal sign. Roughly, the
53 * syntax is:
55 * <file> :== { <section> } EOF
57 * <section> :== <section header> { <parameter line> }
59 * <section header> :== '[' NAME ']'
61 * <parameter line> :== NAME '=' VALUE '\n'
63 * Blank lines and comment lines are ignored. Comment lines are lines
64 * beginning with either a semicolon (';') or a pound sign ('#').
66 * All whitespace in section names and parameter names is compressed
67 * to single spaces. Leading and trailing whitespace is stipped from
68 * both names and values.
70 * Only the first equals sign in a parameter line is significant.
71 * Parameter values may contain equals signs, square brackets and
72 * semicolons. Internal whitespace is retained in parameter values,
73 * with the exception of the '\r' character, which is stripped for
74 * historic reasons. Parameter names may not start with a left square
75 * bracket, an equal sign, a pound sign, or a semicolon, because these
76 * are used to identify other tokens.
78 * -------------------------------------------------------------------------- **
81 #include "replace.h"
82 #include "lib/util/samba_util.h"
83 #include "tini.h"
85 bool pm_process(const char *filename,
86 bool (*sfunc)(const char *section, void *private_data),
87 bool (*pfunc)(const char *name, const char *value,
88 void *private_data),
89 void *private_data)
91 FILE *f;
92 bool ret;
94 f = fopen(filename, "r");
95 if (f == NULL) {
96 return false;
99 ret = tini_parse(f, false, sfunc, pfunc, private_data);
101 fclose(f);
103 return ret;
107 bool pm_process_with_flags(const char *filename,
108 bool allow_empty_values,
109 bool (*sfunc)(const char *section, void *private_data),
110 bool (*pfunc)(const char *name, const char *value,
111 void *private_data),
112 void *private_data)
114 FILE *f;
115 bool ret;
117 f = fopen(filename, "r");
118 if (f == NULL) {
119 return false;
122 ret = tini_parse(f, allow_empty_values, sfunc, pfunc, private_data);
124 fclose(f);
126 return ret;