2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
4 Ben Kibbey <bjk@luxsci.net>
6 This file is part of pwmd.
8 Pwmd is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 Pwmd is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
27 #include <sys/types.h>
35 #include "pwmd-error.h"
38 #include "util-misc.h"
40 #include "util-slist.h"
41 #include "util-string.h"
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
47 #define DEFAULT_BACKLOG "128"
48 #define DEFAULT_CIPHER_PRIORITY "SECURE256:SECURE192:SECURE128:-VERS-SSL3.0:-VERS-TLS1.0"
50 #define INVALID_VALUE(file, line) do { \
52 log_write(_("%s(%i): invalid value for parameter."), file, line); \
57 PARAM_INT
, PARAM_CHARP
, PARAM_LONG
, PARAM_LONGLONG
, PARAM_CHARPP
,
58 PARAM_BOOL
, PARAM_INVALID
61 static struct config_params_s
67 { "backup", PARAM_BOOL
, "true"},
68 { "socket_path", PARAM_CHARP
, NULL
},
69 { "socket_perms", PARAM_CHARP
, NULL
},
70 { "backlog", PARAM_INT
, DEFAULT_BACKLOG
},
71 { "passphrase_file", PARAM_CHARP
, NULL
},
72 { "log_path", PARAM_CHARP
, "~/.pwmd/log"},
73 { "enable_logging", PARAM_BOOL
, "0"},
74 { "log_keepopen", PARAM_BOOL
, "true"},
75 { "log_level", PARAM_INT
, "0"},
76 { "disable_mlockall", PARAM_BOOL
, "true"},
77 { "cache_timeout", PARAM_INT
, DEFAULT_CACHE_TIMEOUT
},
78 { "cache_push", PARAM_CHARPP
, NULL
},
79 { "disable_list_and_dump", PARAM_BOOL
, "false"},
80 { "recursion_depth", PARAM_INT
, "100"},
81 { "syslog", PARAM_BOOL
, "false"},
82 { "xfer_progress", PARAM_INT
, "8196"},
83 { "allowed", PARAM_CHARPP
, NULL
},
84 { "allowed_file", PARAM_CHARP
, NULL
},
85 { "priority", PARAM_INT
, INVALID_PRIORITY
},
86 { "keepalive_interval", PARAM_INT
, DEFAULT_KEEPALIVE_INTERVAL
},
87 { "tcp_port", PARAM_INT
, "6466"},
88 { "enable_tcp", PARAM_BOOL
, "false"},
89 { "tcp_require_key", PARAM_BOOL
, "false"},
90 { "tcp_bind", PARAM_CHARP
, "any"},
91 { "tcp_interface", PARAM_CHARP
, NULL
},
92 { "tls_timeout", PARAM_INT
, "300"},
93 { "tls_cipher_suite", PARAM_CHARP
, DEFAULT_CIPHER_PRIORITY
},
94 { "tls_dh_params_file", PARAM_CHARP
, NULL
},
95 { "require_save_key", PARAM_BOOL
, "true"},
96 { "invoking_user", PARAM_CHARPP
, NULL
},
97 { "invoking_file", PARAM_CHARP
, NULL
},
98 { "encrypt_to", PARAM_BOOL
, "false"},
99 { "always_trust", PARAM_BOOL
, "false"},
100 { "gpg_homedir", PARAM_CHARP
, NULL
},
101 { "strict_kill", PARAM_BOOL
, "false"},
102 { "lock_timeout", PARAM_INT
, DEFAULT_LOCK_TIMEOUT
},
103 { "kill_scd", PARAM_BOOL
, "false"},
104 { NULL
, PARAM_INVALID
, NULL
},
107 struct config_param_s
128 static struct config_section_s
*config_find_section (struct slist_s
*config
,
130 static int new_param (struct config_section_s
*section
, const char *filename
,
131 int lineno
, const char *name
, const char *value
,
133 static void free_section (struct config_section_s
*s
);
134 static int set_defaults (struct slist_s
**config
, int reload
);
137 section_remove_param (struct config_section_s
*section
, const char *name
)
139 unsigned i
, t
= slist_length (section
->params
);
141 for (i
= 0; i
< t
; i
++)
143 struct config_param_s
*p
= slist_nth_data (section
->params
, i
);
148 if (!strcmp (p
->name
, name
))
153 xfree (p
->value
.cptype
);
156 strv_free (p
->value
.cpptype
);
160 section
->params
= slist_remove (section
->params
, p
);
168 static struct config_param_s
*
169 config_has_param (struct config_section_s
*s
, const char *what
)
171 unsigned i
, t
= slist_length (s
->params
);
173 for (i
= 0; i
< t
; i
++)
175 struct config_param_s
*p
= slist_nth_data (s
->params
, i
);
179 if (!strcmp (p
->name
, what
))
186 static struct config_param_s
*
187 config_get_param (struct slist_s
*config
,
188 const char *section
, const char *what
, int *exists
)
190 unsigned i
, t
= slist_length (config
);
194 for (i
= 0; i
< t
; i
++)
196 struct config_param_s
*p
;
197 struct config_section_s
*s
= slist_nth_data (config
, i
);
202 if (strcmp (s
->name
, section
))
205 p
= config_has_param (s
, what
);
216 static struct config_section_s
*
217 new_section (struct slist_s
**config
, const char *name
)
220 struct config_section_s
*s
= xcalloc (1, sizeof (struct config_section_s
));
225 s
->name
= str_dup (name
);
228 log_write ("%s", pwmd_strerror (ENOMEM
));
233 tmp
= slist_append (*config
, s
);
236 log_write ("%s", pwmd_strerror (ENOMEM
));
247 config_set_string_param (struct slist_s
**config
, const char *section
,
248 const char *name
, const char *value
)
250 struct config_section_s
*s
= config_find_section (*config
, section
);
254 s
= new_section (config
, section
);
259 return new_param (s
, NULL
, 0, name
, value
, PARAM_CHARP
);
263 config_get_string_param (struct slist_s
*config
, const char *section
,
264 const char *what
, int *exists
)
266 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
267 return *exists
&& p
->value
.cptype
? str_dup (p
->value
.cptype
) : NULL
;
271 config_set_int_param (struct slist_s
**config
, const char *section
,
272 const char *name
, const char *value
)
274 struct config_section_s
*s
= config_find_section (*config
, section
);
278 s
= new_section (config
, section
);
283 return new_param (s
, NULL
, 0, name
, value
, PARAM_INT
);
287 config_get_int_param (struct slist_s
*config
, const char *section
,
288 const char *what
, int *exists
)
290 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
291 return *exists
? p
->value
.itype
: -1;
295 config_set_bool_param (struct slist_s
**config
, const char *section
,
296 const char *name
, const char *value
)
298 struct config_section_s
*s
= config_find_section (*config
, section
);
302 s
= new_section (config
, section
);
307 return new_param (s
, NULL
, 0, name
, value
, PARAM_BOOL
);
311 config_get_bool_param (struct slist_s
*config
, const char *section
,
312 const char *what
, int *exists
)
314 return config_get_int_param (config
, section
, what
, exists
);
318 config_set_long_param (struct slist_s
**config
, const char *section
,
319 const char *name
, const char *value
)
321 struct config_section_s
*s
= config_find_section (*config
, section
);
325 s
= new_section (config
, section
);
330 return new_param (s
, NULL
, 0, name
, value
, PARAM_LONG
);
334 config_get_long_param (struct slist_s
*config
, const char *section
,
335 const char *what
, int *exists
)
337 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
338 return *exists
? p
->value
.ltype
: -1;
342 config_set_longlong_param (struct slist_s
**config
, const char *section
,
343 const char *name
, const char *value
)
345 struct config_section_s
*s
= config_find_section (*config
, section
);
349 s
= new_section (config
, section
);
354 return new_param (s
, NULL
, 0, name
, value
, PARAM_LONGLONG
);
358 config_get_longlong_param (struct slist_s
*config
,
359 const char *section
, const char *what
, int *exists
)
361 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
362 return *exists
? p
->value
.lltype
: -1;
366 config_set_list_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_CHARPP
);
382 config_get_list_param (struct slist_s
*config
, const char *section
,
383 const char *what
, int *exists
)
385 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
386 return *exists
&& p
->value
.cpptype
? strv_dup (p
->value
.cpptype
) : NULL
;
390 config_get_string (const char *section
, const char *what
)
393 const char *where
= section
? section
: "global";
396 MUTEX_LOCK (&rcfile_mutex
);
397 val
= config_get_string_param (global_config
, where
, what
, &exists
);
398 if (!exists
&& strcmp (section
? section
: "", "global"))
399 val
= config_get_string_param (global_config
, "global", what
, &exists
);
401 MUTEX_UNLOCK (&rcfile_mutex
);
406 config_get_list (const char *section
, const char *what
)
409 const char *where
= section
? section
: "global";
412 MUTEX_LOCK (&rcfile_mutex
);
413 val
= config_get_list_param (global_config
, where
, what
, &exists
);
414 if (!exists
&& strcmp (section
? section
: "", "global"))
415 val
= config_get_list_param (global_config
, "global", what
, &exists
);
417 MUTEX_UNLOCK (&rcfile_mutex
);
422 config_get_integer (const char *section
, const char *what
)
425 const char *where
= section
? section
: "global";
428 MUTEX_LOCK (&rcfile_mutex
);
429 val
= config_get_int_param (global_config
, where
, what
, &exists
);
430 if (!exists
&& strcmp (section
? section
: "", "global"))
431 val
= config_get_int_param (global_config
, "global", what
, &exists
);
433 MUTEX_UNLOCK (&rcfile_mutex
);
438 config_get_longlong (const char *section
, const char *what
)
441 const char *where
= section
? section
: "global";
444 MUTEX_LOCK (&rcfile_mutex
);
445 val
= config_get_longlong_param (global_config
, where
, what
, &exists
);
446 if (!exists
&& strcmp (section
? section
: "", "global"))
447 val
= config_get_longlong_param (global_config
, "global", what
, &exists
);
449 MUTEX_UNLOCK (&rcfile_mutex
);
454 config_get_long (const char *section
, const char *what
)
457 const char *where
= section
? section
: "global";
460 MUTEX_LOCK (&rcfile_mutex
);
461 val
= config_get_long_param (global_config
, where
, what
, &exists
);
462 if (!exists
&& strcmp (section
? section
: "", "global"))
463 val
= config_get_long_param (global_config
, "global", what
, &exists
);
465 MUTEX_UNLOCK (&rcfile_mutex
);
470 config_get_boolean (const char *section
, const char *what
)
472 return config_get_integer (section
, what
);
476 config_get_value (const char *section
, const char *what
)
478 const char *where
= section
? section
: "global";
488 MUTEX_LOCK (&rcfile_mutex
);
490 for (i
= 0; config_params
[i
].name
; i
++)
492 if (!strcmp (config_params
[i
].name
, what
))
494 switch (config_params
[i
].type
)
498 ival
= config_get_int_param (global_config
, where
, what
,
500 if (!exists
&& strcmp (section
? section
: "", "global"))
501 ival
= config_get_int_param (global_config
, "global", what
,
503 result
= str_asprintf ("%i", ival
);
506 cpval
= config_get_string_param (global_config
, where
, what
,
508 if (!exists
&& strcmp (section
? section
: "", "global"))
510 config_get_string_param (global_config
, "global", what
,
515 lval
= config_get_long_param (global_config
, where
, what
,
517 if (!exists
&& strcmp (section
? section
: "", "global"))
518 lval
= config_get_long_param (global_config
, "global", what
,
520 result
= str_asprintf ("%li", lval
);
523 llval
= config_get_longlong_param (global_config
, where
, what
,
525 if (!exists
&& strcmp (section
? section
: "", "global"))
526 llval
= config_get_longlong_param (global_config
, "global",
528 result
= str_asprintf ("%lli", llval
);
531 cppval
= config_get_list_param (global_config
, where
, what
,
533 if (!exists
&& strcmp (section
? section
: "", "global"))
534 cppval
= config_get_list_param (global_config
, "global", what
,
538 result
= strv_join (",", cppval
);
546 MUTEX_UNLOCK (&rcfile_mutex
);
550 /* 'file' is the list parameter file to load into the list parameter 'what'.
551 * The parsing of the parameter is not done here. */
553 parse_list_file (struct slist_s
*config
, const char *section
,
554 const char *file
, const char *what
)
557 char buf
[LINE_MAX
] = {0};
561 char *p
= config_get_string_param (config
, section
, file
, &exists
);
570 tmp
= expand_homedir (p
);
576 rc
= gpg_error_from_errno (errno
);
577 log_write ("%s: %s", p
, pwmd_strerror (rc
));
583 list
= config_get_list_param (config
, section
, what
, &exists
);
587 log_write ("%s", pwmd_strerror (ENOMEM
));
588 return gpg_error (ENOMEM
);
591 while ((p
= fgets (buf
, sizeof (buf
)-1, fp
)))
595 if (p
[strlen(p
)-1] == '\n')
598 while (*p
&& isspace (*p
))
601 if (!*p
|| *p
== ';')
606 pp
= strv_cat (list
, str_dup (p
));
613 log_write ("%s", strerror (ENOMEM
));
614 return gpg_error (ENOMEM
);
625 p
= strv_join (",", list
);
630 log_write ("%s", pwmd_strerror (ENOMEM
));
631 return gpg_error (ENOMEM
);
634 config_set_list_param (&config
, section
, what
, p
);
640 fixup_allowed_once (struct slist_s
**config
, const char *section
)
642 char **list
, **pp
, *p
;
646 rc
= parse_list_file (*config
, section
, "allowed_file", "allowed");
650 list
= config_get_list_param (*config
, section
, "allowed", &exists
);
651 for (pp
= list
; pp
&& *pp
; pp
++)
655 for (p
= *pp
; p
&& *p
; p
++)
663 if (!strcmp (section
, "global"))
665 p
= get_username (getuid());
667 if (config_set_list_param (config
, section
, "allowed", p
))
677 list
= config_get_list_param (*config
, "global", "allowed", &exists
);
680 p
= strv_join (",", list
);
682 if (config_set_list_param (config
, section
, "allowed", p
))
697 fixup_allowed (struct slist_s
**config
)
699 int n
, t
= slist_length (*config
);
701 for (n
= 0; n
< t
; n
++)
703 struct config_section_s
*section
;
705 section
= slist_nth_data (*config
, n
);
706 if (fixup_allowed_once (config
, section
->name
))
714 add_invoking_user (struct invoking_user_s
**users
, char *id
,
715 struct slist_s
**config
)
717 struct passwd
*pwd
= NULL
;
718 struct group
*grp
= NULL
;
719 struct invoking_user_s
*user
, *p
;
722 if (id
&& (*id
== '!' || *id
== '-'))
731 pwd
= getpwuid (getuid ());
734 log_write (_("could not set any invoking user: %s"),
735 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
741 grp
= getgrnam (id
+1);
744 log_write (_("could not parse group '%s': %s"), id
+1,
745 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
752 if (!grp
&& !pwd
&& id
&& *id
!= '#')
755 log_write (_("could not set invoking user '%s': %s"), id
,
756 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
758 log_write (_("could not set any invoking user!"));
763 user
= xcalloc (1, sizeof (struct invoking_user_s
));
766 log_write ("%s", pwmd_strerror (ENOMEM
));
771 user
->type
= pwd
? INVOKING_UID
: grp
? INVOKING_GID
: INVOKING_TLS
;
773 user
->uid
= pwd
->pw_uid
;
775 user
->id
= str_dup (id
+1);
780 for (s
= id
; s
&& *s
; s
++)
783 user
->id
= str_dup (id
+1);
786 /* Set the default invoking_user since it doesn't exist. */
788 config_set_list_param (config
, "global", "invoking_user", pwd
->pw_name
);
796 for (p
= *users
; p
; p
= p
->next
)
809 parse_invoking_users (struct slist_s
**config
)
811 struct invoking_user_s
*users
= NULL
;
815 if (parse_list_file (*config
, "global", "invoking_file", "invoking_user"))
818 list
= config_get_list_param (*config
, "global", "invoking_user", &exists
);
819 for (l
= list
; l
&& *l
; l
++)
821 if (add_invoking_user (&users
, *l
, config
))
824 free_invoking_users (users
);
831 if (add_invoking_user (&users
, NULL
, config
))
838 free_invoking_users (invoking_users
);
839 invoking_users
= users
;
845 set_defaults (struct slist_s
**config
, int reload
)
852 for (i
= 0; config_params
[i
].name
; i
++)
854 switch (config_params
[i
].type
)
857 config_get_bool_param (*config
, "global", config_params
[i
].name
,
861 if (config_set_bool_param
862 (config
, "global", config_params
[i
].name
,
863 config_params
[i
].value
))
868 config_get_int_param (*config
, "global", config_params
[i
].name
,
872 if (config_set_int_param
873 (config
, "global", config_params
[i
].name
,
874 config_params
[i
].value
))
879 s
= config_get_string_param (*config
, "global",
880 config_params
[i
].name
, &exists
);
882 if (!exists
&& config_params
[i
].value
)
884 if (config_set_string_param (config
, "global",
885 config_params
[i
].name
,
886 config_params
[i
].value
))
891 list
= config_get_list_param (*config
, "global",
892 config_params
[i
].name
, &exists
);
894 if (!exists
&& config_params
[i
].value
)
896 if (config_set_list_param (config
, "global",
897 config_params
[i
].name
,
898 config_params
[i
].value
))
903 config_get_long_param (*config
, "global", config_params
[i
].name
,
907 if (config_set_long_param
908 (config
, "global", config_params
[i
].name
,
909 config_params
[i
].value
))
914 config_get_longlong_param (*config
, "global", config_params
[i
].name
,
918 if (config_set_longlong_param (config
, "global",
919 config_params
[i
].name
,
920 config_params
[i
].value
))
928 if (!reload
&& fixup_allowed (config
))
931 if (!reload
&& parse_invoking_users (config
))
934 log_level
= config_get_int_param (*config
, "global",
935 "log_level", &exists
);
936 log_keepopen
= config_get_int_param (*config
, "global",
937 "log_keepopen", &exists
);
938 max_recursion_depth
= config_get_int_param (*config
, "global",
939 "recursion_depth", &exists
);
940 disable_list_and_dump
= config_get_bool_param (*config
, "global",
941 "disable_list_and_dump",
945 config_get_bool_param (*config
, "global", "disable_mlockall", &exists
);
956 static struct config_section_s
*
957 config_find_section (struct slist_s
*config
, const char *name
)
959 unsigned i
, t
= slist_length (config
);
961 for (i
= 0; i
< t
; i
++)
963 struct config_section_s
*s
= slist_nth_data (config
, i
);
965 if (!strcmp (s
->name
, name
))
972 /* Append a new parameter to the list of parameters for a file
973 * section. When an existing parameter of the same name exists, its
977 new_param (struct config_section_s
*section
, const char *filename
, int lineno
,
978 const char *name
, const char *value
, int type
)
980 struct config_param_s
*param
= NULL
;
983 unsigned i
, t
= slist_length (section
->params
);
986 for (i
= 0; i
< t
; i
++)
988 struct config_param_s
*p
= slist_nth_data (section
->params
, i
);
992 if (!strcmp (name
, p
->name
))
1002 param
= xcalloc (1, sizeof (struct config_param_s
));
1005 log_write ("%s", pwmd_strerror (ENOMEM
));
1009 param
->name
= str_dup (name
);
1013 log_write ("%s", pwmd_strerror (ENOMEM
));
1023 if (!strcasecmp (value
, "no") || !strcasecmp (value
, "0")
1024 || !strcasecmp (value
, "false"))
1025 param
->value
.itype
= 0;
1026 else if (!strcasecmp (value
, "yes") || !strcasecmp (value
, "1")
1027 || !strcasecmp (value
, "true"))
1028 param
->value
.itype
= 1;
1031 INVALID_VALUE (filename
, lineno
);
1034 param
->type
= PARAM_INT
;
1037 xfree (param
->value
.cptype
);
1038 param
->value
.cptype
= NULL
;
1039 param
->value
.cptype
= value
&& *value
? str_dup (value
) : NULL
;
1040 if (value
&& *value
&& !param
->value
.cptype
)
1042 log_write ("%s", pwmd_strerror (ENOMEM
));
1047 strv_free (param
->value
.cpptype
);
1048 param
->value
.cpptype
= NULL
;
1049 param
->value
.cpptype
= value
&& *value
?
1050 str_split_ws (value
, ",", 0) : NULL
;
1051 if (value
&& *value
&& !param
->value
.cpptype
)
1053 log_write ("%s", pwmd_strerror (ENOMEM
));
1058 param
->value
.itype
= strtol (value
, &e
, 10);
1061 INVALID_VALUE (filename
, lineno
);
1066 param
->value
.ltype
= strtol (value
, &e
, 10);
1069 INVALID_VALUE (filename
, lineno
);
1073 case PARAM_LONGLONG
:
1074 param
->value
.lltype
= strtoll (value
, &e
, 10);
1077 INVALID_VALUE (filename
, lineno
);
1086 tmp
= slist_append (section
->params
, param
);
1089 log_write ("%s", pwmd_strerror (ENOMEM
));
1093 section
->params
= tmp
;
1097 xfree (param
->name
);
1103 config_parse (const char *filename
, int reload
)
1105 struct slist_s
*tmpconfig
= NULL
, *tmp
;
1106 struct config_section_s
*cur_section
= NULL
;
1107 char buf
[LINE_MAX
] = {0};
1110 int have_global
= 0;
1111 FILE *fp
= fopen (filename
, "r");
1115 log_write ("%s: %s", filename
,
1116 pwmd_strerror (gpg_error_from_errno (errno
)));
1118 if (errno
!= ENOENT
)
1121 log_write (_("Using defaults!"));
1125 for (; (s
= fgets (buf
, sizeof (buf
), fp
)); lineno
++)
1127 char line
[LINE_MAX
] = { 0 };
1138 /* New file section. */
1141 struct config_section_s
*section
;
1142 char *p
= strchr (++s
, ']');
1146 log_write (_("%s(%i): unbalanced braces"), filename
, lineno
);
1152 log_write (_("%s(%i): trailing characters"), filename
, lineno
);
1156 len
= strlen (s
) - strlen (p
);
1157 memcpy (line
, s
, len
);
1160 section
= config_find_section (tmpconfig
, line
);
1163 log_write (_("%s(%i): section '%s' already exists!"),
1164 filename
, lineno
, line
);
1168 if (!strcmp (line
, "global"))
1171 section
= xcalloc (1, sizeof (struct config_section_s
));
1172 section
->name
= str_dup (line
);
1176 tmp
= slist_append (tmpconfig
, cur_section
);
1179 log_write ("%s", pwmd_strerror (ENOMEM
));
1186 cur_section
= section
;
1192 log_write (_("%s(%i): parameter outside of section!"), filename
,
1197 /* Parameters for each section. */
1198 for (int m
= 0; config_params
[m
].name
; m
++)
1200 len
= strlen (config_params
[m
].name
);
1201 if (!strncmp (s
, config_params
[m
].name
, len
))
1205 while (*p
&& *p
== ' ')
1208 if (!*p
|| *p
!= '=')
1212 while (*p
&& isspace (*p
))
1216 if (new_param (cur_section
, filename
, lineno
, s
, p
,
1217 config_params
[m
].type
))
1227 log_write (_("%s(%i): unknown parameter"), filename
, lineno
);
1234 tmp
= slist_append (tmpconfig
, cur_section
);
1237 log_write ("%s", pwmd_strerror (ENOMEM
));
1247 ("WARNING: %s: could not find a [global] configuration section!"),
1251 if (set_defaults (&tmpconfig
, reload
))
1263 config_free (tmpconfig
);
1264 free_section (cur_section
);
1269 free_section (struct config_section_s
*s
)
1276 struct config_param_s
*p
= slist_nth_data (s
->params
, 0);
1281 section_remove_param (s
, p
->name
);
1290 config_free (struct slist_s
*config
)
1294 struct config_section_s
*s
= slist_nth_data (config
, 0);
1299 config
= slist_remove (config
, s
);
1305 free_invoking_users (struct invoking_user_s
*users
)
1307 struct invoking_user_s
*p
;
1311 struct invoking_user_s
*next
= p
->next
;
1313 if (p
->type
== INVOKING_TLS
|| p
->type
== INVOKING_GID
)
1322 param_type (const char *name
)
1326 for (i
= 0; config_params
[i
].name
; i
++)
1328 if (!strcmp (config_params
[i
].name
, name
))
1329 return config_params
[i
].type
;
1332 return PARAM_INVALID
;
1336 keep_parse (struct config_keep_s
*k
, const char *section
, const char *key
)
1344 int type
= param_type (key
);
1351 ival
= config_get_int_param (global_config
, section
, key
, &exists
);
1353 value
= str_asprintf ("%i", ival
);
1356 lval
= config_get_long_param (global_config
, section
, key
, &exists
);
1358 value
= str_asprintf ("%li", lval
);
1360 case PARAM_LONGLONG
:
1361 llval
= config_get_longlong_param (global_config
, section
, key
, &exists
);
1363 value
= str_asprintf ("%lli", llval
);
1366 cpval
= config_get_string_param (global_config
, section
, key
, &exists
);
1371 cppval
= config_get_list_param (global_config
, section
, key
, &exists
);
1374 char *s
= strv_join (",", cppval
);
1387 k
->section
= str_dup(section
);
1388 k
->name
= str_dup(key
);
1393 static struct slist_s
*
1394 keep_add (struct slist_s
*k
, const char *s
, const char *key
)
1396 int n
, t
= slist_length (global_config
);
1398 for (n
= 0; n
< t
; n
++)
1400 struct config_section_s
*section
;
1401 struct config_keep_s
*tmp
;
1404 section
= slist_nth_data (global_config
, n
);
1405 tmp
= xcalloc (1, sizeof(struct config_keep_s
));
1407 // Process all sections.
1409 ret
= keep_parse (tmp
, section
->name
, key
);
1411 ret
= keep_parse (tmp
, s
, key
);
1414 k
= slist_append (k
, tmp
);
1422 /* Keep security sensitive settings across SIGHUP. */
1426 struct slist_s
*keep
= NULL
;
1429 keep
= keep_add (keep
, NULL
, "tcp_require_key");
1431 keep
= keep_add (keep
, NULL
, "require_save_key");
1432 keep
= keep_add (keep
, NULL
, "allowed");
1433 keep
= keep_add (keep
, "global", "encrypt_to");
1434 keep
= keep_add (keep
, "global", "always_trust");
1435 keep
= keep_add (keep
, "global", "invoking_user");
1439 /* Restore parameters previously saved with config_keep_save(). This will also
1443 config_keep_restore (struct slist_s
*keep
)
1445 int n
, t
= slist_length (keep
);
1447 for (n
= 0; n
< t
; n
++)
1449 struct config_keep_s
*k
= slist_nth_data (keep
, n
);
1450 int type
= param_type (k
->name
);
1455 config_set_bool_param (&global_config
, k
->section
, k
->name
, k
->value
);
1458 config_set_int_param (&global_config
, k
->section
, k
->name
, k
->value
);
1461 config_set_long_param (&global_config
, k
->section
, k
->name
, k
->value
);
1463 case PARAM_LONGLONG
:
1464 config_set_longlong_param (&global_config
, k
->section
, k
->name
,
1468 config_set_string_param (&global_config
, k
->section
, k
->name
,
1472 config_set_list_param (&global_config
, k
->section
, k
->name
, k
->value
);