2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3 Ben Kibbey <bjk@luxsci.net>
5 This file is part of pwmd.
7 Pwmd is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 2 of the License, or
10 (at your option) any later version.
12 Pwmd is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
26 #include <sys/types.h>
33 #include "pwmd-error.h"
37 #include "util-misc.h"
39 #include "util-slist.h"
40 #include "util-string.h"
43 #define DEFAULT_PINENTRY_TIMEOUT "30"
44 #define DEFAULT_CACHE_TIMEOUT "600"
45 #define DEFAULT_KEEPALIVE_INTERVAL "60"
46 #define DEFAULT_LOCK_TIMEOUT "50" // MUTEX_TRYLOCK in tenths of a second
48 #define INVALID_VALUE(file, line) do { \
50 log_write(_("%s(%i): invalid value for parameter."), file, line); \
55 PARAM_INT
, PARAM_CHARP
, PARAM_LONG
, PARAM_LONGLONG
, PARAM_CHARPP
,
56 PARAM_BOOL
, PARAM_ULONG
, PARAM_ULONGLONG
59 static struct config_params_s
65 { "backup", PARAM_BOOL
, "true"},
66 { "socket_path", PARAM_CHARP
, NULL
},
67 { "socket_perms", PARAM_CHARP
, NULL
},
68 { "passphrase", PARAM_CHARP
, NULL
},
69 { "passphrase_file", PARAM_CHARP
, NULL
},
70 { "gpg_agent_socket", PARAM_CHARP
, NULL
},
71 { "log_path", PARAM_CHARP
, "~/.pwmd/log"},
72 { "enable_logging", PARAM_BOOL
, "0"},
73 { "log_keepopen", PARAM_BOOL
, "true"},
74 { "log_level", PARAM_INT
, "0"},
75 { "disable_mlockall", PARAM_BOOL
, "true"},
76 { "cache_timeout", PARAM_INT
, DEFAULT_CACHE_TIMEOUT
},
77 { "cache_push", PARAM_CHARPP
, NULL
},
78 { "disable_list_and_dump", PARAM_BOOL
, "false"},
79 { "recursion_depth", PARAM_INT
, "100"},
80 { "syslog", PARAM_BOOL
, "false"},
81 { "xfer_progress", PARAM_INT
, "8196"},
82 { "allowed", PARAM_CHARPP
, NULL
},
83 { "allowed_file", PARAM_CHARP
, NULL
},
84 { "keyparam", PARAM_CHARP
, "(genkey (rsa (nbits 4:2048)))"},
85 { "cipher", PARAM_CHARP
, "aes256"},
86 { "kill_scd", PARAM_BOOL
, "false"},
87 { "cipher_iterations", PARAM_ULONGLONG
, "0"},
88 { "cipher_progress", PARAM_LONG
, DEFAULT_ITERATION_PROGRESS
},
89 { "priority", PARAM_INT
, INVALID_PRIORITY
},
90 { "keepalive_interval", PARAM_INT
, DEFAULT_KEEPALIVE_INTERVAL
},
91 { "tcp_port", PARAM_INT
, "6466"},
92 { "enable_tcp", PARAM_BOOL
, "false"},
93 { "tcp_require_key", PARAM_BOOL
, "false"},
94 { "tcp_wait", PARAM_INT
, "0"},
95 { "tcp_bind", PARAM_CHARP
, "any"},
96 { "tcp_interface", PARAM_CHARP
, NULL
},
97 { "tls_timeout", PARAM_INT
, "300"},
98 { "tls_cipher_suite", PARAM_CHARP
, "SECURE256"},
99 { "pinentry_path", PARAM_CHARP
, PINENTRY_PATH
},
100 { "pinentry_timeout", PARAM_INT
, DEFAULT_PINENTRY_TIMEOUT
},
101 { "use_agent", PARAM_BOOL
, "false"},
102 { "require_save_key", PARAM_BOOL
, "true"},
103 { "invoking_user", PARAM_CHARP
, NULL
},
104 { "invoking_tls", PARAM_CHARP
, NULL
},
105 { "lock_timeout", PARAM_INT
, DEFAULT_LOCK_TIMEOUT
},
106 { "send_state", PARAM_INT
, "2"},
110 struct config_param_s
121 unsigned long ultype
;
122 unsigned long long ulltype
;
126 static struct config_section_s
*config_find_section (struct slist_s
*config
,
128 static int new_param (struct config_section_s
*section
, const char *filename
,
129 int lineno
, const char *name
, const char *value
,
131 static void free_section (struct config_section_s
*s
);
132 static int set_defaults (struct slist_s
**config
);
135 section_remove_param (struct config_section_s
*section
, const char *name
)
137 unsigned i
, t
= slist_length (section
->params
);
139 for (i
= 0; i
< t
; i
++)
141 struct config_param_s
*p
= slist_nth_data (section
->params
, i
);
146 if (!strcmp (p
->name
, name
))
151 xfree (p
->value
.cptype
);
154 strv_free (p
->value
.cpptype
);
158 section
->params
= slist_remove (section
->params
, p
);
169 MUTEX_LOCK (&rcfile_mutex
);
170 unsigned i
, t
= slist_length (global_config
);
172 for (i
= 0; i
< t
; i
++)
174 struct config_section_s
*s
= slist_nth_data (global_config
, i
);
178 section_remove_param (s
, "passphrase");
181 MUTEX_UNLOCK (&rcfile_mutex
);
184 static struct config_param_s
*
185 config_has_param (struct config_section_s
*s
, const char *what
)
187 unsigned i
, t
= slist_length (s
->params
);
189 for (i
= 0; i
< t
; i
++)
191 struct config_param_s
*p
= slist_nth_data (s
->params
, i
);
195 if (!strcmp (p
->name
, what
))
202 static struct config_param_s
*
203 config_get_param (struct slist_s
*config
,
204 const char *section
, const char *what
, int *exists
)
206 unsigned i
, t
= slist_length (config
);
210 for (i
= 0; i
< t
; i
++)
212 struct config_param_s
*p
;
213 struct config_section_s
*s
= slist_nth_data (config
, i
);
218 if (strcmp (s
->name
, section
))
221 p
= config_has_param (s
, what
);
232 static struct config_section_s
*
233 new_section (struct slist_s
**config
, const char *name
)
236 struct config_section_s
*s
= xcalloc (1, sizeof (struct config_section_s
));
241 s
->name
= str_dup (name
);
244 log_write ("%s", pwmd_strerror (ENOMEM
));
249 tmp
= slist_append (*config
, s
);
252 log_write ("%s", pwmd_strerror (ENOMEM
));
263 config_set_string_param (struct slist_s
**config
, const char *section
,
264 const char *name
, const char *value
)
266 struct config_section_s
*s
= config_find_section (*config
, section
);
270 s
= new_section (config
, section
);
275 return new_param (s
, NULL
, 0, name
, value
, PARAM_CHARP
);
279 config_get_string_param (struct slist_s
*config
, const char *section
,
280 const char *what
, int *exists
)
282 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
283 return *exists
&& p
->value
.cptype
? str_dup (p
->value
.cptype
) : NULL
;
287 config_set_int_param (struct slist_s
**config
, const char *section
,
288 const char *name
, const char *value
)
290 struct config_section_s
*s
= config_find_section (*config
, section
);
294 s
= new_section (config
, section
);
299 return new_param (s
, NULL
, 0, name
, value
, PARAM_INT
);
303 config_get_int_param (struct slist_s
*config
, const char *section
,
304 const char *what
, int *exists
)
306 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
307 return *exists
? p
->value
.itype
: -1;
311 config_set_bool_param (struct slist_s
**config
, const char *section
,
312 const char *name
, const char *value
)
314 struct config_section_s
*s
= config_find_section (*config
, section
);
318 s
= new_section (config
, section
);
323 return new_param (s
, NULL
, 0, name
, value
, PARAM_BOOL
);
327 config_get_bool_param (struct slist_s
*config
, const char *section
,
328 const char *what
, int *exists
)
330 return config_get_int_param (config
, section
, what
, exists
);
334 config_set_long_param (struct slist_s
**config
, const char *section
,
335 const char *name
, const char *value
)
337 struct config_section_s
*s
= config_find_section (*config
, section
);
341 s
= new_section (config
, section
);
346 return new_param (s
, NULL
, 0, name
, value
, PARAM_LONG
);
350 config_get_ulong_param (struct slist_s
*config
, const char *section
,
351 const char *what
, int *exists
)
353 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
354 return *exists
? p
->value
.ultype
: 0;
358 config_get_long_param (struct slist_s
*config
, const char *section
,
359 const char *what
, int *exists
)
361 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
362 return *exists
? p
->value
.ltype
: -1;
366 config_set_longlong_param (struct slist_s
**config
, const char *section
,
367 const char *name
, const char *value
)
369 struct config_section_s
*s
= config_find_section (*config
, section
);
373 s
= new_section (config
, section
);
378 return new_param (s
, NULL
, 0, name
, value
, PARAM_LONGLONG
);
382 config_get_longlong_param (struct slist_s
*config
,
383 const char *section
, const char *what
, int *exists
)
385 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
386 return *exists
? p
->value
.lltype
: -1;
390 config_get_ulonglong_param (struct slist_s
*config
,
392 const char *what
, int *exists
)
394 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
395 return *exists
? p
->value
.ulltype
: 0;
399 config_set_list_param (struct slist_s
**config
, const char *section
,
400 const char *name
, const char *value
)
402 struct config_section_s
*s
= config_find_section (*config
, section
);
406 s
= new_section (config
, section
);
411 return new_param (s
, NULL
, 0, name
, value
, PARAM_CHARPP
);
415 config_get_list_param (struct slist_s
*config
, const char *section
,
416 const char *what
, int *exists
)
418 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
419 return *exists
&& p
->value
.cpptype
? strv_dup (p
->value
.cpptype
) : NULL
;
423 config_get_string (const char *section
, const char *what
)
426 const char *where
= section
? section
: "global";
429 MUTEX_LOCK (&rcfile_mutex
);
430 val
= config_get_string_param (global_config
, where
, what
, &exists
);
431 if (!exists
&& strcmp (section
? section
: "", "global"))
432 val
= config_get_string_param (global_config
, "global", what
, &exists
);
434 MUTEX_UNLOCK (&rcfile_mutex
);
439 config_get_list (const char *section
, const char *what
)
442 const char *where
= section
? section
: "global";
445 MUTEX_LOCK (&rcfile_mutex
);
446 val
= config_get_list_param (global_config
, where
, what
, &exists
);
447 if (!exists
&& strcmp (section
? section
: "", "global"))
448 val
= config_get_list_param (global_config
, "global", what
, &exists
);
450 MUTEX_UNLOCK (&rcfile_mutex
);
455 config_get_integer (const char *section
, const char *what
)
458 const char *where
= section
? section
: "global";
461 MUTEX_LOCK (&rcfile_mutex
);
462 val
= config_get_int_param (global_config
, where
, what
, &exists
);
463 if (!exists
&& strcmp (section
? section
: "", "global"))
464 val
= config_get_int_param (global_config
, "global", what
, &exists
);
466 MUTEX_UNLOCK (&rcfile_mutex
);
471 config_get_longlong (const char *section
, const char *what
)
474 const char *where
= section
? section
: "global";
477 MUTEX_LOCK (&rcfile_mutex
);
478 val
= config_get_longlong_param (global_config
, where
, what
, &exists
);
479 if (!exists
&& strcmp (section
? section
: "", "global"))
480 val
= config_get_longlong_param (global_config
, "global", what
, &exists
);
482 MUTEX_UNLOCK (&rcfile_mutex
);
487 config_get_ulonglong (const char *section
, const char *what
)
489 unsigned long long val
= 0;
490 const char *where
= section
? section
: "global";
493 MUTEX_LOCK (&rcfile_mutex
);
494 val
= config_get_ulonglong_param (global_config
, where
, what
, &exists
);
495 if (!exists
&& strcmp (section
? section
: "", "global"))
496 val
= config_get_ulonglong_param (global_config
, "global", what
, &exists
);
498 MUTEX_UNLOCK (&rcfile_mutex
);
503 config_get_long (const char *section
, const char *what
)
506 const char *where
= section
? section
: "global";
509 MUTEX_LOCK (&rcfile_mutex
);
510 val
= config_get_long_param (global_config
, where
, what
, &exists
);
511 if (!exists
&& strcmp (section
? section
: "", "global"))
512 val
= config_get_long_param (global_config
, "global", what
, &exists
);
514 MUTEX_UNLOCK (&rcfile_mutex
);
519 config_get_ulong (const char *section
, const char *what
)
521 unsigned long val
= 0;
522 const char *where
= section
? section
: "global";
525 MUTEX_LOCK (&rcfile_mutex
);
526 val
= config_get_ulong_param (global_config
, where
, what
, &exists
);
527 if (!exists
&& strcmp (section
? section
: "", "global"))
528 val
= config_get_ulong_param (global_config
, "global", what
, &exists
);
530 MUTEX_UNLOCK (&rcfile_mutex
);
535 config_get_boolean (const char *section
, const char *what
)
537 return config_get_integer (section
, what
);
541 config_get_value (const char *section
, const char *what
)
543 const char *where
= section
? section
: "global";
550 unsigned long long ullval
;
555 MUTEX_LOCK (&rcfile_mutex
);
557 for (i
= 0; config_params
[i
].name
; i
++)
559 if (!strcmp (config_params
[i
].name
, what
))
561 switch (config_params
[i
].type
)
565 ival
= config_get_int_param (global_config
, where
, what
,
567 if (!exists
&& strcmp (section
? section
: "", "global"))
568 ival
= config_get_int_param (global_config
, "global", what
,
570 result
= str_asprintf ("%i", ival
);
573 cpval
= config_get_string_param (global_config
, where
, what
,
575 if (!exists
&& strcmp (section
? section
: "", "global"))
577 config_get_string_param (global_config
, "global", what
,
582 lval
= config_get_long_param (global_config
, where
, what
,
584 if (!exists
&& strcmp (section
? section
: "", "global"))
585 lval
= config_get_long_param (global_config
, "global", what
,
587 result
= str_asprintf ("%li", lval
);
590 ulval
= config_get_ulong_param (global_config
, where
, what
,
592 if (!exists
&& strcmp (section
? section
: "", "global"))
593 ulval
= config_get_ulong_param (global_config
, "global", what
,
595 result
= str_asprintf ("%lu", ulval
);
598 llval
= config_get_longlong_param (global_config
, where
, what
,
600 if (!exists
&& strcmp (section
? section
: "", "global"))
601 llval
= config_get_longlong_param (global_config
, "global",
603 result
= str_asprintf ("%lli", llval
);
605 case PARAM_ULONGLONG
:
606 ullval
= config_get_ulonglong_param (global_config
, where
, what
,
608 if (!exists
&& strcmp (section
? section
: "", "global"))
609 ullval
= config_get_ulonglong_param (global_config
, "global",
611 result
= str_asprintf ("%llu", ullval
);
614 cppval
= config_get_list_param (global_config
, where
, what
,
616 if (!exists
&& strcmp (section
? section
: "", "global"))
617 cppval
= config_get_list_param (global_config
, "global", what
,
621 result
= strv_join (",", cppval
);
629 MUTEX_UNLOCK (&rcfile_mutex
);
634 parse_allowed_file (struct slist_s
*config
, const char *section
)
641 char *p
= config_get_string_param (config
, section
, "allowed_file", &exists
);
649 tmp
= expand_homedir (p
);
655 log_write ("%s: %s", p
, strerror (errno
));
661 list
= config_get_list_param (config
, section
, "allowed", &exists
);
665 log_write ("%s", strerror (ENOMEM
));
669 while ((p
= fgets (buf
, sizeof (buf
), fp
)))
673 if (p
[strlen(p
)-1] == '\n')
676 while (*p
&& isspace (*p
))
684 pp
= strv_cat (list
, str_dup (p
));
691 log_write ("%s", strerror (ENOMEM
));
703 p
= strv_join (",", list
);
708 log_write ("%s", strerror (ENOMEM
));
712 config_set_list_param (&config
, section
, "allowed", p
);
717 fixup_allowed_once (struct slist_s
**config
, const char *section
)
719 char **list
, **pp
, *p
;
722 parse_allowed_file (*config
, section
);
723 list
= config_get_list_param (*config
, section
, "allowed", &exists
);
724 for (pp
= list
; pp
&& *pp
; pp
++)
728 for (p
= *pp
; p
&& *p
; p
++)
736 if (!strcmp (section
, "global"))
738 p
= get_username (getuid());
740 if (config_set_list_param (config
, section
, "allowed", p
))
750 list
= config_get_list_param (*config
, "global", "allowed", &exists
);
753 p
= strv_join (",", list
);
755 if (config_set_list_param (config
, section
, "allowed", p
))
770 fixup_allowed (struct slist_s
**config
)
772 int n
, t
= slist_length (*config
);
774 for (n
= 0; n
< t
; n
++)
776 struct config_section_s
*section
;
778 section
= slist_nth_data (*config
, n
);
779 if (fixup_allowed_once (config
, section
->name
))
787 set_defaults (struct slist_s
**config
)
789 char *s
= NULL
, *tmp
;
795 for (i
= 0; config_params
[i
].name
; i
++)
797 switch (config_params
[i
].type
)
800 config_get_bool_param (*config
, "global", config_params
[i
].name
,
804 if (config_set_bool_param
805 (config
, "global", config_params
[i
].name
,
806 config_params
[i
].value
))
811 config_get_int_param (*config
, "global", config_params
[i
].name
,
815 if (config_set_int_param
816 (config
, "global", config_params
[i
].name
,
817 config_params
[i
].value
))
822 s
= config_get_string_param (*config
, "global",
823 config_params
[i
].name
, &exists
);
825 if (!exists
&& config_params
[i
].value
)
827 if (config_set_string_param (config
, "global",
828 config_params
[i
].name
,
829 config_params
[i
].value
))
834 list
= config_get_list_param (*config
, "global",
835 config_params
[i
].name
, &exists
);
837 if (!exists
&& config_params
[i
].value
)
839 if (config_set_list_param (config
, "global",
840 config_params
[i
].name
,
841 config_params
[i
].value
))
846 config_get_long_param (*config
, "global", config_params
[i
].name
,
850 if (config_set_long_param
851 (config
, "global", config_params
[i
].name
,
852 config_params
[i
].value
))
857 config_get_longlong_param (*config
, "global", config_params
[i
].name
,
861 if (config_set_longlong_param (config
, "global",
862 config_params
[i
].name
,
863 config_params
[i
].value
))
871 if (fixup_allowed (config
))
874 max_recursion_depth
= config_get_int_param (*config
, "global",
875 "recursion_depth", &exists
);
876 disable_list_and_dump
= config_get_bool_param (*config
, "global",
877 "disable_list_and_dump",
881 config_get_bool_param (*config
, "global", "disable_mlockall", &exists
);
884 s
= config_get_string_param(*config
, "global", "invoking_user", &exists
);
887 pwd
= getpwuid(getuid());
893 log_write (_("could not set invoking user: user '%s' is invalid"), s
);
898 config_set_string_param(config
, "global", "invoking_user", pwd
->pw_name
);
900 invoking_tls
= config_get_string_param(*config
, "global", "invoking_tls",
902 for (char *p
= invoking_tls
; p
&& *p
; p
++)
905 config_set_string_param(config
, "global", "invoking_tls", invoking_tls
);
907 invoking_uid
= pwd
->pw_uid
;
908 invoking_gid
= pwd
->pw_gid
;
910 s
= config_get_string_param(*config
, "global", "gpg_agent_socket", &exists
);
914 s
= str_asprintf ("%s/.gnupg/S.gpg-agent", get_home_dir());
915 config_set_string_param(config
, "global", "gpg_agent_socket", s
);
919 tmp
= expand_homedir (s
);
920 config_set_string_param(config
, "global", "gpg_agent_socket", tmp
);
932 static struct config_section_s
*
933 config_find_section (struct slist_s
*config
, const char *name
)
935 unsigned i
, t
= slist_length (config
);
937 for (i
= 0; i
< t
; i
++)
939 struct config_section_s
*s
= slist_nth_data (config
, i
);
941 if (!strcmp (s
->name
, name
))
948 /* Append a new parameter to the list of parameters for a file
949 * section. When an existing parameter of the same name exists, its
953 new_param (struct config_section_s
*section
, const char *filename
, int lineno
,
954 const char *name
, const char *value
, int type
)
956 struct config_param_s
*param
= NULL
;
959 unsigned i
, t
= slist_length (section
->params
);
962 for (i
= 0; i
< t
; i
++)
964 struct config_param_s
*p
= slist_nth_data (section
->params
, i
);
968 if (!strcmp (name
, p
->name
))
978 param
= xcalloc (1, sizeof (struct config_param_s
));
981 log_write ("%s", pwmd_strerror (ENOMEM
));
985 param
->name
= str_dup (name
);
989 log_write ("%s", pwmd_strerror (ENOMEM
));
999 if (!strcasecmp (value
, "no") || !strcasecmp (value
, "0")
1000 || !strcasecmp (value
, "false"))
1001 param
->value
.itype
= 0;
1002 else if (!strcasecmp (value
, "yes") || !strcasecmp (value
, "1")
1003 || !strcasecmp (value
, "true"))
1004 param
->value
.itype
= 1;
1007 INVALID_VALUE (filename
, lineno
);
1010 param
->type
= PARAM_INT
;
1013 xfree (param
->value
.cptype
);
1014 param
->value
.cptype
= NULL
;
1015 param
->value
.cptype
= value
&& *value
? str_dup (value
) : NULL
;
1016 if (value
&& *value
&& !param
->value
.cptype
)
1018 log_write ("%s", pwmd_strerror (ENOMEM
));
1023 strv_free (param
->value
.cpptype
);
1024 param
->value
.cpptype
= NULL
;
1025 param
->value
.cpptype
= value
&& *value
? str_split (value
, ",", 0) : NULL
;
1026 if (value
&& *value
&& !param
->value
.cpptype
)
1028 log_write ("%s", pwmd_strerror (ENOMEM
));
1033 param
->value
.itype
= strtol (value
, &e
, 10);
1036 INVALID_VALUE (filename
, lineno
);
1041 param
->value
.ltype
= strtol (value
, &e
, 10);
1044 INVALID_VALUE (filename
, lineno
);
1048 case PARAM_LONGLONG
:
1049 param
->value
.lltype
= strtoll (value
, &e
, 10);
1052 INVALID_VALUE (filename
, lineno
);
1056 case PARAM_ULONGLONG
:
1057 param
->value
.ulltype
= strtoull (value
, &e
, 10);
1060 INVALID_VALUE (filename
, lineno
);
1065 param
->value
.ultype
= strtoul (value
, &e
, 10);
1068 INVALID_VALUE (filename
, lineno
);
1077 tmp
= slist_append (section
->params
, param
);
1080 log_write ("%s", pwmd_strerror (ENOMEM
));
1084 section
->params
= tmp
;
1088 xfree (param
->name
);
1094 config_parse (const char *filename
)
1096 struct slist_s
*tmpconfig
= NULL
, *tmp
;
1097 struct config_section_s
*cur_section
= NULL
;
1101 int have_global
= 0;
1102 FILE *fp
= fopen (filename
, "r");
1106 log_write ("%s: %s", filename
,
1107 pwmd_strerror (gpg_error_from_errno (errno
)));
1109 if (errno
!= ENOENT
)
1112 log_write (_("Using defaults!"));
1116 for (; (s
= fgets (buf
, sizeof (buf
), fp
)); lineno
++)
1118 char line
[LINE_MAX
] = { 0 };
1125 for (; s
&& *s
; s
++)
1129 /* New file section. */
1132 struct config_section_s
*section
;
1133 char *p
= strchr (++s
, ']');
1137 log_write (_("%s(%i): unbalanced braces"), filename
,
1142 len
= strlen (s
) - strlen (p
);
1143 memcpy (line
, s
, len
);
1146 section
= config_find_section (tmpconfig
, line
);
1149 log_write (_("%s(%i): section '%s' already exists!"),
1150 filename
, lineno
, line
);
1154 if (!strcmp (line
, "global"))
1157 section
= xcalloc (1, sizeof (struct config_section_s
));
1158 section
->name
= str_dup (line
);
1162 tmp
= slist_append (tmpconfig
, cur_section
);
1165 log_write ("%s", pwmd_strerror (ENOMEM
));
1172 cur_section
= section
;
1178 log_write (_("%s(%i): parameter outside of section!"), filename
,
1183 /* Parameters for each section. */
1184 for (int m
= 0; config_params
[m
].name
; m
++)
1186 size_t len
= strlen (config_params
[m
].name
);
1188 if (!strncmp (s
, config_params
[m
].name
, len
))
1192 while (*p
&& *p
== ' ')
1195 if (!*p
|| *p
!= '=')
1199 while (*p
&& isspace (*p
))
1203 if (new_param (cur_section
, filename
, lineno
, s
, p
,
1204 config_params
[m
].type
))
1214 log_write (_("%s(%i): unknown parameter"), filename
, lineno
);
1224 tmp
= slist_append (tmpconfig
, cur_section
);
1227 log_write ("%s", pwmd_strerror (ENOMEM
));
1237 ("WARNING: %s: could not find a [global] configuration section!"),
1241 if (set_defaults (&tmpconfig
))
1253 config_free (tmpconfig
);
1254 free_section (cur_section
);
1259 free_section (struct config_section_s
*s
)
1266 struct config_param_s
*p
= slist_nth_data (s
->params
, 0);
1271 section_remove_param (s
, p
->name
);
1280 config_free (struct slist_s
*config
)
1284 struct config_section_s
*s
= slist_nth_data (config
, 0);
1289 config
= slist_remove (config
, s
);