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_LONG
, 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 { "tls_use_crl", PARAM_BOOL
, "1"},
96 { "require_save_key", PARAM_BOOL
, "true"},
97 { "invoking_user", PARAM_CHARPP
, NULL
},
98 { "invoking_file", PARAM_CHARP
, NULL
},
99 { "encrypt_to", PARAM_BOOL
, "false"},
100 { "always_trust", PARAM_BOOL
, "false"},
101 { "gpg_homedir", PARAM_CHARP
, NULL
},
102 { "strict_kill", PARAM_BOOL
, "false"},
103 { "lock_timeout", PARAM_LONG
, DEFAULT_LOCK_TIMEOUT
},
104 { "kill_scd", PARAM_BOOL
, "false"},
105 { "strict_open", PARAM_BOOL
, "false"},
106 { NULL
, PARAM_INVALID
, NULL
},
109 struct config_param_s
130 static struct config_section_s
*config_find_section (struct slist_s
*config
,
132 static int new_param (struct config_section_s
*section
, const char *filename
,
133 int lineno
, const char *name
, const char *value
,
135 static void free_section (struct config_section_s
*s
);
136 static int set_defaults (struct slist_s
**config
, int reload
);
139 section_remove_param (struct config_section_s
*section
, const char *name
)
141 unsigned i
, t
= slist_length (section
->params
);
143 for (i
= 0; i
< t
; i
++)
145 struct config_param_s
*p
= slist_nth_data (section
->params
, i
);
150 if (!strcmp (p
->name
, name
))
155 xfree (p
->value
.cptype
);
158 strv_free (p
->value
.cpptype
);
162 section
->params
= slist_remove (section
->params
, p
);
170 static struct config_param_s
*
171 config_has_param (struct config_section_s
*s
, const char *what
)
173 unsigned i
, t
= slist_length (s
->params
);
175 for (i
= 0; i
< t
; i
++)
177 struct config_param_s
*p
= slist_nth_data (s
->params
, i
);
181 if (!strcmp (p
->name
, what
))
188 static struct config_param_s
*
189 config_get_param (struct slist_s
*config
,
190 const char *section
, const char *what
, int *exists
)
192 unsigned i
, t
= slist_length (config
);
196 for (i
= 0; i
< t
; i
++)
198 struct config_param_s
*p
;
199 struct config_section_s
*s
= slist_nth_data (config
, i
);
204 if (strcmp (s
->name
, section
))
207 p
= config_has_param (s
, what
);
218 static struct config_section_s
*
219 new_section (struct slist_s
**config
, const char *name
)
222 struct config_section_s
*s
= xcalloc (1, sizeof (struct config_section_s
));
227 s
->name
= str_dup (name
);
230 log_write ("%s", pwmd_strerror (ENOMEM
));
235 tmp
= slist_append (*config
, s
);
238 log_write ("%s", pwmd_strerror (ENOMEM
));
249 config_set_string_param (struct slist_s
**config
, const char *section
,
250 const char *name
, const char *value
)
252 struct config_section_s
*s
= config_find_section (*config
, section
);
256 s
= new_section (config
, section
);
261 return new_param (s
, NULL
, 0, name
, value
, PARAM_CHARP
);
265 config_get_string_param (struct slist_s
*config
, const char *section
,
266 const char *what
, int *exists
)
268 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
269 return *exists
&& p
->value
.cptype
? str_dup (p
->value
.cptype
) : NULL
;
273 config_set_int_param (struct slist_s
**config
, const char *section
,
274 const char *name
, const char *value
)
276 struct config_section_s
*s
= config_find_section (*config
, section
);
280 s
= new_section (config
, section
);
285 return new_param (s
, NULL
, 0, name
, value
, PARAM_INT
);
289 config_get_int_param (struct slist_s
*config
, const char *section
,
290 const char *what
, int *exists
)
292 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
293 return *exists
? p
->value
.itype
: -1;
297 config_set_bool_param (struct slist_s
**config
, const char *section
,
298 const char *name
, const char *value
)
300 struct config_section_s
*s
= config_find_section (*config
, section
);
304 s
= new_section (config
, section
);
309 return new_param (s
, NULL
, 0, name
, value
, PARAM_BOOL
);
313 config_get_bool_param (struct slist_s
*config
, const char *section
,
314 const char *what
, int *exists
)
316 return config_get_int_param (config
, section
, what
, exists
);
320 config_set_long_param (struct slist_s
**config
, const char *section
,
321 const char *name
, const char *value
)
323 struct config_section_s
*s
= config_find_section (*config
, section
);
327 s
= new_section (config
, section
);
332 return new_param (s
, NULL
, 0, name
, value
, PARAM_LONG
);
336 config_get_long_param (struct slist_s
*config
, const char *section
,
337 const char *what
, int *exists
)
339 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
340 return *exists
? p
->value
.ltype
: -1;
344 config_set_longlong_param (struct slist_s
**config
, const char *section
,
345 const char *name
, const char *value
)
347 struct config_section_s
*s
= config_find_section (*config
, section
);
351 s
= new_section (config
, section
);
356 return new_param (s
, NULL
, 0, name
, value
, PARAM_LONGLONG
);
360 config_get_longlong_param (struct slist_s
*config
,
361 const char *section
, const char *what
, int *exists
)
363 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
364 return *exists
? p
->value
.lltype
: -1;
368 config_set_list_param (struct slist_s
**config
, const char *section
,
369 const char *name
, const char *value
)
371 struct config_section_s
*s
= config_find_section (*config
, section
);
375 s
= new_section (config
, section
);
380 return new_param (s
, NULL
, 0, name
, value
, PARAM_CHARPP
);
384 config_get_list_param (struct slist_s
*config
, const char *section
,
385 const char *what
, int *exists
)
387 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
388 return *exists
&& p
->value
.cpptype
? strv_dup (p
->value
.cpptype
) : NULL
;
392 config_get_string (const char *section
, const char *what
)
395 const char *where
= section
? section
: "global";
398 MUTEX_LOCK (&rcfile_mutex
);
399 val
= config_get_string_param (global_config
, where
, what
, &exists
);
400 if (!exists
&& strcmp (section
? section
: "", "global"))
401 val
= config_get_string_param (global_config
, "global", what
, &exists
);
403 MUTEX_UNLOCK (&rcfile_mutex
);
408 config_get_list (const char *section
, const char *what
)
411 const char *where
= section
? section
: "global";
414 MUTEX_LOCK (&rcfile_mutex
);
415 val
= config_get_list_param (global_config
, where
, what
, &exists
);
416 if (!exists
&& strcmp (section
? section
: "", "global"))
417 val
= config_get_list_param (global_config
, "global", what
, &exists
);
419 MUTEX_UNLOCK (&rcfile_mutex
);
424 config_get_integer (const char *section
, const char *what
)
427 const char *where
= section
? section
: "global";
430 MUTEX_LOCK (&rcfile_mutex
);
431 val
= config_get_int_param (global_config
, where
, what
, &exists
);
432 if (!exists
&& strcmp (section
? section
: "", "global"))
433 val
= config_get_int_param (global_config
, "global", what
, &exists
);
435 MUTEX_UNLOCK (&rcfile_mutex
);
440 config_get_longlong (const char *section
, const char *what
)
443 const char *where
= section
? section
: "global";
446 MUTEX_LOCK (&rcfile_mutex
);
447 val
= config_get_longlong_param (global_config
, where
, what
, &exists
);
448 if (!exists
&& strcmp (section
? section
: "", "global"))
449 val
= config_get_longlong_param (global_config
, "global", what
, &exists
);
451 MUTEX_UNLOCK (&rcfile_mutex
);
456 config_get_long (const char *section
, const char *what
)
459 const char *where
= section
? section
: "global";
462 MUTEX_LOCK (&rcfile_mutex
);
463 val
= config_get_long_param (global_config
, where
, what
, &exists
);
464 if (!exists
&& strcmp (section
? section
: "", "global"))
465 val
= config_get_long_param (global_config
, "global", what
, &exists
);
467 MUTEX_UNLOCK (&rcfile_mutex
);
472 config_get_boolean (const char *section
, const char *what
)
474 return config_get_integer (section
, what
);
478 config_get_value (const char *section
, const char *what
)
480 const char *where
= section
? section
: "global";
490 MUTEX_LOCK (&rcfile_mutex
);
492 for (i
= 0; config_params
[i
].name
; i
++)
494 if (!strcmp (config_params
[i
].name
, what
))
496 switch (config_params
[i
].type
)
500 ival
= config_get_int_param (global_config
, where
, what
,
502 if (!exists
&& strcmp (section
? section
: "", "global"))
503 ival
= config_get_int_param (global_config
, "global", what
,
505 result
= str_asprintf ("%i", ival
);
508 cpval
= config_get_string_param (global_config
, where
, what
,
510 if (!exists
&& strcmp (section
? section
: "", "global"))
512 config_get_string_param (global_config
, "global", what
,
517 lval
= config_get_long_param (global_config
, where
, what
,
519 if (!exists
&& strcmp (section
? section
: "", "global"))
520 lval
= config_get_long_param (global_config
, "global", what
,
522 result
= str_asprintf ("%li", lval
);
525 llval
= config_get_longlong_param (global_config
, where
, what
,
527 if (!exists
&& strcmp (section
? section
: "", "global"))
528 llval
= config_get_longlong_param (global_config
, "global",
530 result
= str_asprintf ("%lli", llval
);
533 cppval
= config_get_list_param (global_config
, where
, what
,
535 if (!exists
&& strcmp (section
? section
: "", "global"))
536 cppval
= config_get_list_param (global_config
, "global", what
,
540 result
= strv_join (",", cppval
);
548 MUTEX_UNLOCK (&rcfile_mutex
);
552 /* 'file' is the list parameter file to load into the list parameter 'what'.
553 * The parsing of the parameter is not done here. */
555 parse_list_file (struct slist_s
*config
, const char *section
,
556 const char *file
, const char *what
)
559 char buf
[LINE_MAX
] = {0};
563 char *p
= config_get_string_param (config
, section
, file
, &exists
);
572 tmp
= expand_homedir (p
);
578 rc
= gpg_error_from_errno (errno
);
579 log_write ("%s: %s", p
, pwmd_strerror (rc
));
585 list
= config_get_list_param (config
, section
, what
, &exists
);
589 log_write ("%s", pwmd_strerror (ENOMEM
));
590 return gpg_error (ENOMEM
);
593 while ((p
= fgets (buf
, sizeof (buf
)-1, fp
)))
597 if (p
[strlen(p
)-1] == '\n')
600 while (*p
&& isspace (*p
))
603 if (!*p
|| *p
== ';')
608 pp
= strv_cat (list
, str_dup (p
));
615 log_write ("%s", strerror (ENOMEM
));
616 return gpg_error (ENOMEM
);
627 p
= strv_join (",", list
);
632 log_write ("%s", pwmd_strerror (ENOMEM
));
633 return gpg_error (ENOMEM
);
636 config_set_list_param (&config
, section
, what
, p
);
642 fixup_allowed_once (struct slist_s
**config
, const char *section
)
644 char **list
, **pp
, *p
;
648 rc
= parse_list_file (*config
, section
, "allowed_file", "allowed");
652 list
= config_get_list_param (*config
, section
, "allowed", &exists
);
653 for (pp
= list
; pp
&& *pp
; pp
++)
657 for (p
= *pp
; p
&& *p
; p
++)
665 if (!strcmp (section
, "global"))
667 p
= get_username (getuid());
669 if (config_set_list_param (config
, section
, "allowed", p
))
679 list
= config_get_list_param (*config
, "global", "allowed", &exists
);
682 p
= strv_join (",", list
);
684 if (config_set_list_param (config
, section
, "allowed", p
))
699 fixup_allowed (struct slist_s
**config
)
701 int n
, t
= slist_length (*config
);
703 for (n
= 0; n
< t
; n
++)
705 struct config_section_s
*section
;
707 section
= slist_nth_data (*config
, n
);
708 if (fixup_allowed_once (config
, section
->name
))
716 add_invoking_user (struct invoking_user_s
**users
, char *id
,
717 struct slist_s
**config
)
719 struct passwd
*pwd
= NULL
;
720 struct group
*grp
= NULL
;
721 struct invoking_user_s
*user
, *p
;
724 if (id
&& (*id
== '!' || *id
== '-'))
733 pwd
= getpwuid (getuid ());
736 log_write (_("could not set any invoking user: %s"),
737 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
743 grp
= getgrnam (id
+1);
746 log_write (_("could not parse group '%s': %s"), id
+1,
747 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
754 if (!grp
&& !pwd
&& id
&& *id
!= '#')
757 log_write (_("could not set invoking user '%s': %s"), id
,
758 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
760 log_write (_("could not set any invoking user!"));
765 user
= xcalloc (1, sizeof (struct invoking_user_s
));
768 log_write ("%s", pwmd_strerror (ENOMEM
));
773 user
->type
= pwd
? INVOKING_UID
: grp
? INVOKING_GID
: INVOKING_TLS
;
775 user
->uid
= pwd
->pw_uid
;
777 user
->id
= str_dup (id
+1);
782 for (s
= id
; s
&& *s
; s
++)
785 user
->id
= str_dup (id
+1);
788 /* Set the default invoking_user since it doesn't exist. */
789 if (pwd
&& (!id
|| !*id
))
790 config_set_list_param (config
, "global", "invoking_user", pwd
->pw_name
);
798 for (p
= *users
; p
; p
= p
->next
)
811 parse_invoking_users (struct slist_s
**config
)
813 struct invoking_user_s
*users
= NULL
;
817 if (parse_list_file (*config
, "global", "invoking_file", "invoking_user"))
820 list
= config_get_list_param (*config
, "global", "invoking_user", &exists
);
821 for (l
= list
; l
&& *l
; l
++)
823 if (add_invoking_user (&users
, *l
, config
))
826 free_invoking_users (users
);
833 if (add_invoking_user (&users
, NULL
, config
))
840 free_invoking_users (invoking_users
);
841 invoking_users
= users
;
847 set_defaults (struct slist_s
**config
, int reload
)
854 for (i
= 0; config_params
[i
].name
; i
++)
856 switch (config_params
[i
].type
)
859 config_get_bool_param (*config
, "global", config_params
[i
].name
,
863 if (config_set_bool_param
864 (config
, "global", config_params
[i
].name
,
865 config_params
[i
].value
))
870 config_get_int_param (*config
, "global", config_params
[i
].name
,
874 if (config_set_int_param
875 (config
, "global", config_params
[i
].name
,
876 config_params
[i
].value
))
881 s
= config_get_string_param (*config
, "global",
882 config_params
[i
].name
, &exists
);
884 if (!exists
&& config_params
[i
].value
)
886 if (config_set_string_param (config
, "global",
887 config_params
[i
].name
,
888 config_params
[i
].value
))
893 list
= config_get_list_param (*config
, "global",
894 config_params
[i
].name
, &exists
);
896 if (!exists
&& config_params
[i
].value
)
898 if (config_set_list_param (config
, "global",
899 config_params
[i
].name
,
900 config_params
[i
].value
))
905 config_get_long_param (*config
, "global", config_params
[i
].name
,
909 if (config_set_long_param
910 (config
, "global", config_params
[i
].name
,
911 config_params
[i
].value
))
916 config_get_longlong_param (*config
, "global", config_params
[i
].name
,
920 if (config_set_longlong_param (config
, "global",
921 config_params
[i
].name
,
922 config_params
[i
].value
))
930 if (!reload
&& fixup_allowed (config
))
933 if (!reload
&& parse_invoking_users (config
))
936 log_level
= config_get_int_param (*config
, "global",
937 "log_level", &exists
);
938 log_keepopen
= config_get_int_param (*config
, "global",
939 "log_keepopen", &exists
);
940 max_recursion_depth
= config_get_int_param (*config
, "global",
941 "recursion_depth", &exists
);
942 disable_list_and_dump
= config_get_bool_param (*config
, "global",
943 "disable_list_and_dump",
947 config_get_bool_param (*config
, "global", "disable_mlockall", &exists
);
958 static struct config_section_s
*
959 config_find_section (struct slist_s
*config
, const char *name
)
961 unsigned i
, t
= slist_length (config
);
963 for (i
= 0; i
< t
; i
++)
965 struct config_section_s
*s
= slist_nth_data (config
, i
);
967 if (!strcmp (s
->name
, name
))
974 /* Append a new parameter to the list of parameters for a file
975 * section. When an existing parameter of the same name exists, its
979 new_param (struct config_section_s
*section
, const char *filename
, int lineno
,
980 const char *name
, const char *value
, int type
)
982 struct config_param_s
*param
= NULL
;
985 unsigned i
, t
= slist_length (section
->params
);
988 for (i
= 0; i
< t
; i
++)
990 struct config_param_s
*p
= slist_nth_data (section
->params
, i
);
994 if (!strcmp (name
, p
->name
))
1004 param
= xcalloc (1, sizeof (struct config_param_s
));
1007 log_write ("%s", pwmd_strerror (ENOMEM
));
1011 param
->name
= str_dup (name
);
1015 log_write ("%s", pwmd_strerror (ENOMEM
));
1025 if (!strcasecmp (value
, "no") || !strcasecmp (value
, "0")
1026 || !strcasecmp (value
, "false"))
1027 param
->value
.itype
= 0;
1028 else if (!strcasecmp (value
, "yes") || !strcasecmp (value
, "1")
1029 || !strcasecmp (value
, "true"))
1030 param
->value
.itype
= 1;
1033 INVALID_VALUE (filename
, lineno
);
1036 param
->type
= PARAM_INT
;
1039 xfree (param
->value
.cptype
);
1040 param
->value
.cptype
= NULL
;
1041 param
->value
.cptype
= value
&& *value
? str_dup (value
) : NULL
;
1042 if (value
&& *value
&& !param
->value
.cptype
)
1044 log_write ("%s", pwmd_strerror (ENOMEM
));
1049 strv_free (param
->value
.cpptype
);
1050 param
->value
.cpptype
= NULL
;
1051 param
->value
.cpptype
= value
&& *value
?
1052 str_split_ws (value
, ",", 0) : NULL
;
1053 if (value
&& *value
&& !param
->value
.cpptype
)
1055 log_write ("%s", pwmd_strerror (ENOMEM
));
1060 param
->value
.itype
= strtol (value
, &e
, 10);
1063 INVALID_VALUE (filename
, lineno
);
1068 param
->value
.ltype
= strtol (value
, &e
, 10);
1071 INVALID_VALUE (filename
, lineno
);
1075 case PARAM_LONGLONG
:
1076 param
->value
.lltype
= strtoll (value
, &e
, 10);
1079 INVALID_VALUE (filename
, lineno
);
1088 tmp
= slist_append (section
->params
, param
);
1091 log_write ("%s", pwmd_strerror (ENOMEM
));
1095 section
->params
= tmp
;
1099 xfree (param
->name
);
1105 config_parse (const char *filename
, int reload
)
1107 struct slist_s
*tmpconfig
= NULL
, *tmp
;
1108 struct config_section_s
*cur_section
= NULL
;
1109 char buf
[LINE_MAX
] = {0};
1112 int have_global
= 0;
1113 FILE *fp
= fopen (filename
, "r");
1117 log_write ("%s: %s", filename
,
1118 pwmd_strerror (gpg_error_from_errno (errno
)));
1120 if (errno
!= ENOENT
)
1123 log_write (_("Using defaults!"));
1127 for (; (s
= fgets (buf
, sizeof (buf
), fp
)); lineno
++)
1129 char line
[LINE_MAX
] = { 0 };
1140 /* New file section. */
1143 struct config_section_s
*section
;
1144 char *p
= strchr (++s
, ']');
1148 log_write (_("%s(%i): unbalanced braces"), filename
, lineno
);
1154 log_write (_("%s(%i): trailing characters"), filename
, lineno
);
1158 len
= strlen (s
) - strlen (p
);
1159 memcpy (line
, s
, len
);
1162 section
= config_find_section (tmpconfig
, line
);
1165 log_write (_("%s(%i): section '%s' already exists!"),
1166 filename
, lineno
, line
);
1170 if (!strcmp (line
, "global"))
1173 section
= xcalloc (1, sizeof (struct config_section_s
));
1174 section
->name
= str_dup (line
);
1178 tmp
= slist_append (tmpconfig
, cur_section
);
1181 log_write ("%s", pwmd_strerror (ENOMEM
));
1188 cur_section
= section
;
1194 log_write (_("%s(%i): parameter outside of section!"), filename
,
1199 /* Parameters for each section. */
1200 for (int m
= 0; config_params
[m
].name
; m
++)
1202 len
= strlen (config_params
[m
].name
);
1203 if (!strncmp (s
, config_params
[m
].name
, len
))
1207 while (*p
&& *p
== ' ')
1210 if (!*p
|| *p
!= '=')
1214 while (*p
&& isspace (*p
))
1218 if (new_param (cur_section
, filename
, lineno
, s
, p
,
1219 config_params
[m
].type
))
1229 log_write (_("%s(%i): unknown parameter"), filename
, lineno
);
1236 tmp
= slist_append (tmpconfig
, cur_section
);
1239 log_write ("%s", pwmd_strerror (ENOMEM
));
1249 ("WARNING: %s: could not find a [global] configuration section!"),
1253 if (set_defaults (&tmpconfig
, reload
))
1265 config_free (tmpconfig
);
1266 free_section (cur_section
);
1271 free_section (struct config_section_s
*s
)
1278 struct config_param_s
*p
= slist_nth_data (s
->params
, 0);
1283 section_remove_param (s
, p
->name
);
1292 config_free (struct slist_s
*config
)
1296 struct config_section_s
*s
= slist_nth_data (config
, 0);
1301 config
= slist_remove (config
, s
);
1307 free_invoking_users (struct invoking_user_s
*users
)
1309 struct invoking_user_s
*p
;
1313 struct invoking_user_s
*next
= p
->next
;
1315 if (p
->type
== INVOKING_TLS
|| p
->type
== INVOKING_GID
)
1324 param_type (const char *name
)
1328 for (i
= 0; config_params
[i
].name
; i
++)
1330 if (!strcmp (config_params
[i
].name
, name
))
1331 return config_params
[i
].type
;
1334 return PARAM_INVALID
;
1338 keep_parse (struct config_keep_s
*k
, const char *section
, const char *key
)
1346 int type
= param_type (key
);
1353 ival
= config_get_int_param (global_config
, section
, key
, &exists
);
1355 value
= str_asprintf ("%i", ival
);
1358 lval
= config_get_long_param (global_config
, section
, key
, &exists
);
1360 value
= str_asprintf ("%li", lval
);
1362 case PARAM_LONGLONG
:
1363 llval
= config_get_longlong_param (global_config
, section
, key
, &exists
);
1365 value
= str_asprintf ("%lli", llval
);
1368 cpval
= config_get_string_param (global_config
, section
, key
, &exists
);
1373 cppval
= config_get_list_param (global_config
, section
, key
, &exists
);
1376 char *s
= strv_join (",", cppval
);
1389 k
->section
= str_dup(section
);
1390 k
->name
= str_dup(key
);
1395 static struct slist_s
*
1396 keep_add (struct slist_s
*k
, const char *s
, const char *key
)
1398 int n
, t
= slist_length (global_config
);
1400 for (n
= 0; n
< t
; n
++)
1402 struct config_section_s
*section
;
1403 struct config_keep_s
*tmp
;
1406 section
= slist_nth_data (global_config
, n
);
1407 tmp
= xcalloc (1, sizeof(struct config_keep_s
));
1409 // Process all sections.
1411 ret
= keep_parse (tmp
, section
->name
, key
);
1413 ret
= keep_parse (tmp
, s
, key
);
1416 k
= slist_append (k
, tmp
);
1424 /* Keep security sensitive settings across SIGHUP. */
1428 struct slist_s
*keep
= NULL
;
1431 keep
= keep_add (keep
, NULL
, "tcp_require_key");
1433 keep
= keep_add (keep
, NULL
, "require_save_key");
1434 keep
= keep_add (keep
, NULL
, "allowed");
1435 keep
= keep_add (keep
, NULL
, "allowed_file");
1436 keep
= keep_add (keep
, "global", "encrypt_to");
1437 keep
= keep_add (keep
, "global", "always_trust");
1438 keep
= keep_add (keep
, "global", "invoking_user");
1439 keep
= keep_add (keep
, "global", "invoking_file");
1440 keep
= keep_add (keep
, "global", "gpg_homedir");
1444 /* Restore parameters previously saved with config_keep_save(). This will also
1448 config_keep_restore (struct slist_s
*keep
)
1450 int n
, t
= slist_length (keep
);
1452 for (n
= 0; n
< t
; n
++)
1454 struct config_keep_s
*k
= slist_nth_data (keep
, n
);
1455 int type
= param_type (k
->name
);
1460 config_set_bool_param (&global_config
, k
->section
, k
->name
, k
->value
);
1463 config_set_int_param (&global_config
, k
->section
, k
->name
, k
->value
);
1466 config_set_long_param (&global_config
, k
->section
, k
->name
, k
->value
);
1468 case PARAM_LONGLONG
:
1469 config_set_longlong_param (&global_config
, k
->section
, k
->name
,
1473 config_set_string_param (&global_config
, k
->section
, k
->name
,
1477 config_set_list_param (&global_config
, k
->section
, k
->name
, k
->value
);