Debian Codegraph @

loadparm.c

raw symbols SCIP
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, visit the http://fsf.org website.
14 *
15 * This is based on loadparm.c from Samba, written by Andrew Tridgell
16 * and Karl Auer. Some of the changes are:
17 *
18 * Copyright (C) 2001, 2002 Martin Pool <[email protected]>
19 * Copyright (C) 2003-2020 Wayne Davison
20 */
21
22 /* Load parameters.
23 *
24 * This module provides suitable callback functions for the params
25 * module. It builds the internal table of section details which is
26 * then used by the rest of the server.
27 *
28 * To add a parameter:
29 *
30 * 1) add it to the global_vars or local_vars structure definition
31 * 2) add it to the parm_table
32 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
33 * 4) initialise it in the Defaults static structure
34 *
35 * Notes:
36 * The configuration file is processed sequentially for speed. For this
37 * reason, there is a fair bit of sequence-dependent code here - ie., code
38 * which assumes that certain things happen before others. In particular, the
39 * code which happens at the boundary between sections is delicately poised,
40 * so be careful!
41 */
42
43 #include "rsync.h"
44 #include "itypes.h"
45 #include "ifuncs.h"
46 #include "default-dont-compress.h"
47
48 extern item_list dparam_list;
49
50 #define strequal(a, b) (strcasecmp(a, b)==0)
51
52 #ifndef LOG_DAEMON
53 #define LOG_DAEMON 0
54 #endif
55
56 /* the following are used by loadparm for option lists */
57 typedef enum {
58 P_BOOL, P_BOOLREV, P_BOOL3, P_CHAR, P_INTEGER,
59 P_OCTAL, P_PATH, P_STRING, P_ENUM
60 } parm_type;
61
62 typedef enum {
63 P_LOCAL, P_GLOBAL, P_NONE
64 } parm_class;
65
66 struct enum_list {
67 int value;
68 const char *name;
69 };
70
71 struct parm_struct {
72 char *label;
73 parm_type type;
74 parm_class class;
75 void *ptr;
76 const struct enum_list *enum_list;
77 unsigned flags;
78 };
79
80 #ifndef GLOBAL_NAME
81 #define GLOBAL_NAME "global"
82 #endif
83
84 /* some helpful bits */
85 #define iSECTION(i) ((local_vars*)section_list.items)[i]
86 #define LP_SNUM_OK(i) ((i) >= 0 && (i) < (int)section_list.count)
87 #define SECTION_PTR(s, p) (((char*)(s)) + (ptrdiff_t)(((char*)(p))-(char*)&Vars.l))
88
89 /* Stack of "Vars" values used by the &include directive. */
90 static item_list Vars_stack = EMPTY_ITEM_LIST;
91
92 /* The array of section values that holds all the defined modules. */
93 static item_list section_list = EMPTY_ITEM_LIST;
94
95 static int iSectionIndex = -1;
96 static BOOL bInGlobalSection = True;
97
98 static const struct enum_list enum_syslog_facility[] = {
99 #ifdef LOG_AUTH
100 { LOG_AUTH, "auth" },
101 #endif
102 #ifdef LOG_AUTHPRIV
103 { LOG_AUTHPRIV, "authpriv" },
104 #endif
105 #ifdef LOG_CRON
106 { LOG_CRON, "cron" },
107 #endif
108 #ifdef LOG_DAEMON
109 { LOG_DAEMON, "daemon" },
110 #endif
111 #ifdef LOG_FTP
112 { LOG_FTP, "ftp" },
113 #endif
114 #ifdef LOG_KERN
115 { LOG_KERN, "kern" },
116 #endif
117 #ifdef LOG_LPR
118 { LOG_LPR, "lpr" },
119 #endif
120 #ifdef LOG_MAIL
121 { LOG_MAIL, "mail" },
122 #endif
123 #ifdef LOG_NEWS
124 { LOG_NEWS, "news" },
125 #endif
126 #ifdef LOG_AUTH
127 { LOG_AUTH, "security" },
128 #endif
129 #ifdef LOG_SYSLOG
130 { LOG_SYSLOG, "syslog" },
131 #endif
132 #ifdef LOG_USER
133 { LOG_USER, "user" },
134 #endif
135 #ifdef LOG_UUCP
136 { LOG_UUCP, "uucp" },
137 #endif
138 #ifdef LOG_LOCAL0
139 { LOG_LOCAL0, "local0" },
140 #endif
141 #ifdef LOG_LOCAL1
142 { LOG_LOCAL1, "local1" },
143 #endif
144 #ifdef LOG_LOCAL2
145 { LOG_LOCAL2, "local2" },
146 #endif
147 #ifdef LOG_LOCAL3
148 { LOG_LOCAL3, "local3" },
149 #endif
150 #ifdef LOG_LOCAL4
151 { LOG_LOCAL4, "local4" },
152 #endif
153 #ifdef LOG_LOCAL5
154 { LOG_LOCAL5, "local5" },
155 #endif
156 #ifdef LOG_LOCAL6
157 { LOG_LOCAL6, "local6" },
158 #endif
159 #ifdef LOG_LOCAL7
160 { LOG_LOCAL7, "local7" },
161 #endif
162 { -1, NULL }
163 };
164
165 /* Expand %VAR% references. Any unknown vars or unrecognized
166 * syntax leaves the raw chars unchanged. */
167 enum shell_quote_context {
168 SHELL_UNQUOTED,
169 SHELL_SINGLE_QUOTED,
170 SHELL_DOUBLE_QUOTED
171 };
172
173 /* Characters that can turn a substituted value into shell syntax rather than
174 * data, in any quoting context. Quoting alone cannot be relied on here:
175 * context-aware escaping is correct for exactly one level of shell parsing,
176 * and a hook such as `sh -c '... %RSYNC_USER_NAME% ...'` re-parses the word in
177 * a second shell that sees the value bare. Peer-supplied values carrying any
178 * of these are refused instead. */
179 static int shell_unsafe_value(const char *val)
180 {
181 const char *s;
182
183 for (s = val; *s; s++) {
184 /* '!' negates in command position (a hook `sh -c '%VAR% false'`
185 * becomes `! false` and reports success, inverting an access
186 * check); '~' is tilde-expanded; '{' and '}' brace-expand in
187 * bash and zsh. None of them execute anything on their own,
188 * which is why a set built from the obvious metacharacters
189 * missed them. */
190 if (strchr("'\"`$\\;&|<>()*?[]# !~{}", *s)
191 || (unsigned char)*s < 0x20 || (unsigned char)*s == 0x7f)
192 return 1;
193 }
194 return 0;
195 }
196
197 static char *expand_vars_shell_escape(const char *val, int quote_context)
198 {
199 const char *s;
200 char *ret, *t;
201 /* A double-quoted value is deliberately BOTH backslash-escaped and
202 * wrapped in single quotes. The wrap is redundant for one level of
203 * shell parsing (and shows up as literal quotes in the value), but a
204 * hook such as `sh -c "... %RSYNC_USER_NAME% ..."` re-parses the word
205 * in a second shell, where the backslashes are already gone and only
206 * the quotes still protect it. */
207 size_t len = quote_context == SHELL_SINGLE_QUOTED ? 0 : 2;
208
209 for (s = val; *s; s++) {
210 if (quote_context == SHELL_DOUBLE_QUOTED
211 && strchr("\\\"`$", *s))
212 len += 2;
213 else
214 len += *s == '\'' ? 4 : 1;
215 }
216 ret = new_array(char, len + 1);
217 t = ret;
218 if (quote_context != SHELL_SINGLE_QUOTED)
219 *t++ = '\'';
220 for (s = val; *s; s++) {
221 if (quote_context == SHELL_DOUBLE_QUOTED
222 && strchr("\\\"`$", *s)) {
223 *t++ = '\\';
224 *t++ = *s;
225 } else if (*s == '\'') {
226 memcpy(t, "'\\''", 4);
227 t += 4;
228 } else
229 *t++ = *s;
230 }
231 if (quote_context != SHELL_SINGLE_QUOTED)
232 *t++ = '\'';
233 *t = '\0';
234 return ret;
235 }
236
237 static char *expand_vars(const char *str, int shell_escape)
238 {
239 char *buf, *t;
240 const char *f;
241 int bufsize, quote_context = SHELL_UNQUOTED, escaped_char = 0;
242
243 if (!str || !strchr(str, '%'))
244 return (char *)str; /* TODO change return value to const char* at some point. */
245
246 bufsize = strlen(str) + 2048;
247 buf = new_array(char, bufsize+1); /* +1 for trailing '\0' */
248
249 for (t = buf, f = str; bufsize && *f; ) {
250 if (*f == '%' && isUpper(f+1)) {
251 const char *percent = strchr(f+1, '%');
252 if (percent && percent - f < bufsize) {
253 char *val;
254 strlcpy(t, f+1, percent - f);
255 val = getenv(t);
256 if (val) {
257 char *escaped = NULL;
258 int len;
259 /* %RSYNC_*% values originate from the peer request/args.
260 * When the result is fed to a shell-executed hook, escape it
261 * for the template's current shell quote context so a value
262 * containing shell metacharacters can't inject. For ordinary string
263 * params (path, uid, gid, ...) leave them verbatim --
264 * quoting there would corrupt the value (e.g. a documented
265 * `path = /home/%RSYNC_USER_NAME%` would become /home/'x'). */
266 if (shell_escape && strncmp(t, "RSYNC_", 6) == 0) {
267 if (shell_unsafe_value(val)) {
268 /* Fail closed: the hook may be an access
269 * check, so skipping it is not an option. */
270 rprintf(FLOG,
271 "refusing to run shell hook: %%%s%% holds a shell metacharacter\n",
272 t);
273 exit_cleanup(RERR_UNSUPPORTED);
274 }
275 val = escaped = expand_vars_shell_escape(val, quote_context);
276 }
277 len = strlcpy(t, val, bufsize+1);
278 if (escaped)
279 free(escaped);
280 if (len > bufsize)
281 break;
282 bufsize -= len;
283 t += len;
284 f = percent + 1;
285 continue;
286 }
287 }
288 }
289 if (shell_escape) {
290 if (quote_context == SHELL_SINGLE_QUOTED) {
291 /* Nothing is special inside '...', not even a backslash;
292 * only the closing quote ends it. */
293 if (*f == '\'')
294 quote_context = SHELL_UNQUOTED;
295 } else if (escaped_char)
296 escaped_char = 0;
297 else if (*f == '\\')
298 escaped_char = 1;
299 else if (quote_context == SHELL_DOUBLE_QUOTED) {
300 /* A single quote inside "..." is literal and must not be
301 * taken as opening a single-quoted run -- doing so would
302 * de-sync the tracker and escape a later value for the
303 * wrong context. */
304 if (*f == '"')
305 quote_context = SHELL_UNQUOTED;
306 } else if (*f == '\'')
307 quote_context = SHELL_SINGLE_QUOTED;
308 else if (*f == '"')
309 quote_context = SHELL_DOUBLE_QUOTED;
310 }
311 *t++ = *f++;
312 bufsize--;
313 }
314 *t = '\0';
315
316 if (*f) {
317 rprintf(FLOG, "Overflowed buf in expand_vars() trying to expand: %s\n", str);
318 exit_cleanup(RERR_MALLOC);
319 }
320
321 if (bufsize && (buf = realloc(buf, t - buf + 1)) == NULL)
322 out_of_memory("expand_vars");
323
324 return buf;
325 }
326
327 /* Each "char* foo" has an associated "BOOL foo_EXP" that tracks if the string has been expanded yet or not. */
328
329 /* NOTE: use this function and all the FN_{GLOBAL,LOCAL} ones WITHOUT a trailing semicolon! */
330 #define RETURN_EXPANDED(val) {if (!val ## _EXP) {val = expand_vars(val, 0); val ## _EXP = True;} return val ? val : "";}
331 /* Variant for params whose expansion is fed to a shell-executed hook: quote
332 * %RSYNC_*% peer-controlled values to prevent shell injection. */
333 #define RETURN_EXPANDED_SHELL(val) {if (!val ## _EXP) {val = expand_vars(val, 1); val ## _EXP = True;} return val ? val : "";}
334
335 /* In this section all the functions that are used to access the
336 * parameters from the rest of the program are defined. */
337
338 #define FN_GLOBAL_STRING(fn_name, val) \
339 char *fn_name(void) RETURN_EXPANDED(Vars.g.val)
340 #define FN_GLOBAL_BOOL(fn_name, val) \
341 BOOL fn_name(void) {return Vars.g.val;}
342 #define FN_GLOBAL_CHAR(fn_name, val) \
343 char fn_name(void) {return Vars.g.val;}
344 #define FN_GLOBAL_INTEGER(fn_name, val) \
345 int fn_name(void) {return Vars.g.val;}
346
347 #define FN_LOCAL_STRING(fn_name, val) \
348 char *fn_name(int i) {if (LP_SNUM_OK(i) && iSECTION(i).val) RETURN_EXPANDED(iSECTION(i).val) else RETURN_EXPANDED(Vars.l.val)}
349 #define FN_LOCAL_STRING_SHELL(fn_name, val) \
350 char *fn_name(int i) {if (LP_SNUM_OK(i) && iSECTION(i).val) RETURN_EXPANDED_SHELL(iSECTION(i).val) else RETURN_EXPANDED_SHELL(Vars.l.val)}
351 #define FN_LOCAL_BOOL(fn_name, val) \
352 BOOL fn_name(int i) {return LP_SNUM_OK(i)? iSECTION(i).val : Vars.l.val;}
353 #define FN_LOCAL_CHAR(fn_name, val) \
354 char fn_name(int i) {return LP_SNUM_OK(i)? iSECTION(i).val : Vars.l.val;}
355 #define FN_LOCAL_INTEGER(fn_name, val) \
356 int fn_name(int i) {return LP_SNUM_OK(i)? iSECTION(i).val : Vars.l.val;}
357
358 /* The following include file contains:
359 *
360 * typedef global_vars - describes global (ie., server-wide) parameters.
361 * typedef local_vars - describes a single section.
362 * typedef all_vars - a combination of global_vars & local_vars.
363 * all_vars Defaults - the default values for all the variables.
364 * all_vars Vars - the currently configured values for all the variables.
365 * struct parm_struct parm_table - the strings & variables for the parser.
366 * FN_{LOCAL,GLOBAL}_{TYPE}() definition for all the lp_var_name() accessors.
367 */
368
369 #include "daemon-parm.h"
370
371 /* Initialise the Default all_vars structure. */
372 void reset_daemon_vars(void)
373 {
374 memcpy(&Vars, &Defaults, sizeof Vars);
375 }
376
377 /* Assign a copy of v to *s. Handles NULL strings. We don't worry
378 * about overwriting a malloc'd string because the long-running
379 * (port-listening) daemon only loads the config file once, and the
380 * per-job (forked or xinitd-ran) daemon only re-reads the file at
381 * the start, so any lost memory is inconsequential. */
382 static inline void string_set(char **s, const char *v)
383 {
384 *s = v ? strdup(v) : NULL;
385 }
386
387 /* Copy local_vars into a new section. No need to strdup since we don't free. */
388 static void copy_section(local_vars *psectionDest, local_vars *psectionSource)
389 {
390 memcpy(psectionDest, psectionSource, sizeof psectionDest[0]);
391 }
392
393 /* Initialise a section to the defaults. */
394 static void init_section(local_vars *psection)
395 {
396 memset(psection, 0, sizeof (local_vars));
397 copy_section(psection, &Vars.l);
398 }
399
400 /* Do a case-insensitive, whitespace-ignoring string equality check. */
401 static int strwiEQ(char *psz1, char *psz2)
402 {
403 /* If one or both strings are NULL, we return equality right away. */
404 if (psz1 == psz2)
405 return 1;
406 if (psz1 == NULL || psz2 == NULL)
407 return 0;
408
409 /* sync the strings on first non-whitespace */
410 while (1) {
411 while (isSpace(psz1))
412 psz1++;
413 while (isSpace(psz2))
414 psz2++;
415 if (*psz1 == '\0' || *psz2 == '\0')
416 break;
417 if (toUpper(psz1) != toUpper(psz2))
418 break;
419 psz1++;
420 psz2++;
421 }
422 return *psz1 == *psz2;
423 }
424
425 /* Find a section by name. Otherwise works like get_section. */
426 static int getsectionbyname(char *name)
427 {
428 int i;
429
430 for (i = section_list.count - 1; i >= 0; i--) {
431 if (strwiEQ(iSECTION(i).name, name))
432 break;
433 }
434
435 return i;
436 }
437
438 /* Add a new section to the sections array w/the default values. */
439 static int add_a_section(char *name)
440 {
441 int i;
442 local_vars *s;
443
444 /* it might already exist */
445 if (name) {
446 i = getsectionbyname(name);
447 if (i >= 0)
448 return i;
449 }
450
451 i = section_list.count;
452 s = EXPAND_ITEM_LIST(&section_list, local_vars, 2);
453
454 init_section(s);
455 if (name)
456 string_set(&s->name, name);
457
458 return i;
459 }
460
461 /* Map a parameter's string representation to something we can use.
462 * Returns False if the parameter string is not recognised, else TRUE. */
463 static int map_parameter(char *parmname)
464 {
465 int iIndex;
466
467 if (*parmname == '-')
468 return -1;
469
470 for (iIndex = 0; parm_table[iIndex].label; iIndex++) {
471 if (strwiEQ(parm_table[iIndex].label, parmname))
472 return iIndex;
473 }
474
475 rprintf(FLOG, "Unknown Parameter encountered: \"%s\"\n", parmname);
476 return -1;
477 }
478
479 /* Set a boolean variable from the text value stored in the passed string.
480 * Returns True in success, False if the passed string does not correctly
481 * represent a boolean. */
482 static BOOL set_boolean(BOOL *pb, char *parmvalue, int allow_unset)
483 {
484 if (strwiEQ(parmvalue, "yes") || strwiEQ(parmvalue, "true") || strwiEQ(parmvalue, "1"))
485 *pb = True;
486 else if (strwiEQ(parmvalue, "no") || strwiEQ(parmvalue, "false") || strwiEQ(parmvalue, "0"))
487 *pb = False;
488 else if (allow_unset && (strwiEQ(parmvalue, "unset") || strwiEQ(parmvalue, "-1")))
489 *pb = Unset;
490 else {
491 rprintf(FLOG, "Badly formed boolean in configuration file: \"%s\".\n", parmvalue);
492 return False;
493 }
494 return True;
495 }
496
497 /* Process a parameter. */
498 static BOOL do_parameter(char *parmname, char *parmvalue)
499 {
500 int parmnum, i;
501 void *parm_ptr; /* where we are going to store the result */
502 void *def_ptr;
503 char *cp;
504
505 parmnum = map_parameter(parmname);
506
507 if (parmnum < 0) {
508 rprintf(FLOG, "IGNORING unknown parameter \"%s\"\n", parmname);
509 return True;
510 }
511
512 def_ptr = parm_table[parmnum].ptr;
513
514 if (bInGlobalSection)
515 parm_ptr = def_ptr;
516 else {
517 if (parm_table[parmnum].class == P_GLOBAL) {
518 rprintf(FLOG, "Global parameter %s found in module section!\n", parmname);
519 return True;
520 }
521 parm_ptr = SECTION_PTR(&iSECTION(iSectionIndex), def_ptr);
522 }
523
524 /* now switch on the type of variable it is */
525 switch (parm_table[parmnum].type) {
526 case P_PATH:
527 case P_STRING:
528 /* delay expansion of %VAR% strings */
529 break;
530 default:
531 /* expand any %VAR% strings now */
532 parmvalue = expand_vars(parmvalue, 0);
533 break;
534 }
535
536 switch (parm_table[parmnum].type) {
537 case P_BOOL:
538 set_boolean(parm_ptr, parmvalue, False);
539 break;
540
541 case P_BOOL3:
542 set_boolean(parm_ptr, parmvalue, True);
543 break;
544
545 case P_BOOLREV:
546 set_boolean(parm_ptr, parmvalue, False);
547 *(BOOL *)parm_ptr = ! *(BOOL *)parm_ptr;
548 break;
549
550 case P_INTEGER:
551 *(int *)parm_ptr = atoi(parmvalue);
552 break;
553
554 case P_CHAR:
555 *(char *)parm_ptr = *parmvalue;
556 break;
557
558 case P_OCTAL:
559 sscanf(parmvalue, "%o", (unsigned int *)parm_ptr);
560 break;
561
562 case P_PATH:
563 string_set(parm_ptr, parmvalue);
564 if ((cp = *(char**)parm_ptr) != NULL) {
565 int len = strlen(cp);
566 while (len > 1 && cp[len-1] == '/') len--;
567 cp[len] = '\0';
568 }
569 break;
570
571 case P_STRING:
572 string_set(parm_ptr, parmvalue);
573 break;
574
575 case P_ENUM:
576 for (i=0; parm_table[parmnum].enum_list[i].name; i++) {
577 if (strequal(parmvalue, parm_table[parmnum].enum_list[i].name)) {
578 *(int *)parm_ptr = parm_table[parmnum].enum_list[i].value;
579 break;
580 }
581 }
582 if (!parm_table[parmnum].enum_list[i].name) {
583 if (atoi(parmvalue) > 0)
584 *(int *)parm_ptr = atoi(parmvalue);
585 }
586 break;
587 }
588
589 return True;
590 }
591
592 /* Process a new section (rsync module).
593 * Returns True on success, False on failure. */
594 static BOOL do_section(char *sectionname)
595 {
596 BOOL isglobal;
597
598 if (*sectionname == ']') { /* A special push/pop/reset directive from params.c */
599 bInGlobalSection = 1;
600 if (strcmp(sectionname+1, "push") == 0) {
601 all_vars *vp = EXPAND_ITEM_LIST(&Vars_stack, all_vars, 2);
602 memcpy(vp, &Vars, sizeof Vars);
603 } else if (strcmp(sectionname+1, "pop") == 0
604 || strcmp(sectionname+1, "reset") == 0) {
605 all_vars *vp = ((all_vars*)Vars_stack.items) + Vars_stack.count - 1;
606 if (!Vars_stack.count)
607 return False;
608 memcpy(&Vars, vp, sizeof Vars);
609 if (sectionname[1] == 'p')
610 Vars_stack.count--;
611 } else
612 return False;
613 return True;
614 }
615
616 isglobal = strwiEQ(sectionname, GLOBAL_NAME);
617
618 /* At the end of the global section, add any --dparam items. */
619 if (bInGlobalSection && !isglobal) {
620 if (!section_list.count)
621 set_dparams(0);
622 }
623
624 /* if we've just struck a global section, note the fact. */
625 bInGlobalSection = isglobal;
626
627 /* check for multiple global sections */
628 if (bInGlobalSection)
629 return True;
630
631 #if 0
632 /* If we have a current section, tidy it up before moving on. */
633 if (iSectionIndex >= 0) {
634 /* Add any tidy work as needed ... */
635 if (problem)
636 return False;
637 }
638 #endif
639
640 if (strchr(sectionname, '/') != NULL) {
641 rprintf(FLOG, "Warning: invalid section name in configuration file: %s\n", sectionname);
642 return False;
643 }
644
645 if ((iSectionIndex = add_a_section(sectionname)) < 0) {
646 rprintf(FLOG, "Failed to add a new module\n");
647 bInGlobalSection = True;
648 return False;
649 }
650
651 return True;
652 }
653
654 /* Load the modules from the config file. Return True on success,
655 * False on failure. */
656 int lp_load(char *pszFname, int globals_only)
657 {
658 bInGlobalSection = True;
659
660 reset_daemon_vars();
661
662 /* We get sections first, so have to start 'behind' to make up. */
663 iSectionIndex = -1;
664 return pm_process(pszFname, globals_only ? NULL : do_section, do_parameter);
665 }
666
667 BOOL set_dparams(int syntax_check_only)
668 {
669 char *equal, *val, **params = dparam_list.items;
670 unsigned j;
671
672 for (j = 0; j < dparam_list.count; j++) {
673 equal = strchr(params[j], '='); /* options.c verified this */
674 *equal = '\0';
675 if (syntax_check_only) {
676 if (map_parameter(params[j]) < 0) {
677 rprintf(FERROR, "Unknown parameter \"%s\"\n", params[j]);
678 *equal = '=';
679 return False;
680 }
681 } else {
682 for (val = equal+1; isSpace(val); val++) {}
683 do_parameter(params[j], val);
684 }
685 *equal = '=';
686 }
687
688 return True;
689 }
690
691 /* Return the max number of modules (sections). */
692 int lp_num_modules(void)
693 {
694 return section_list.count;
695 }
696
697 /* Return the number of the module with the given name, or -1 if it doesn't
698 * exist. Note that this is a DIFFERENT ANIMAL from the internal function
699 * getsectionbyname()! This works ONLY if all sections have been loaded,
700 * and does not copy the found section. */
701 int lp_number(char *name)
702 {
703 int i;
704
705 for (i = section_list.count - 1; i >= 0; i--) {
706 if (strcmp(lp_name(i), name) == 0)
707 break;
708 }
709
710 return i;
711 }