2 Copyright (C) 2006-2019 Ben Kibbey <bjk@luxsci.net>
4 This file is part of pwmd.
6 Pwmd is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
11 Pwmd is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/types.h>
33 #include "pwmd-error.h"
36 #include "util-misc.h"
38 #include "util-slist.h"
39 #include "util-string.h"
42 #define DEFAULT_CACHE_TIMEOUT "600"
43 #define DEFAULT_KEEPALIVE_INTERVAL "60"
44 #define DEFAULT_LOCK_TIMEOUT "50" // MUTEX_TRYLOCK in tenths of a second
45 #define DEFAULT_BACKLOG "128"
46 #define DEFAULT_CIPHER_PRIORITY "SECURE256:SECURE192:SECURE128:-VERS-SSL3.0:-VERS-TLS1.0:-VERS-TLS1.1:-AES-128-CBC:-AES-256-CBC"
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_INVALID
59 static struct config_params_s
65 { "backup", PARAM_BOOL
, "true"},
66 { "socket_path", PARAM_CHARP
, NULL
},
67 { "socket_perms", PARAM_CHARP
, NULL
},
68 { "backlog", PARAM_INT
, DEFAULT_BACKLOG
},
69 { "passphrase_file", PARAM_CHARP
, NULL
},
70 { "log_path", PARAM_CHARP
, "~/.pwmd/log"},
71 { "enable_logging", PARAM_BOOL
, "0"},
72 { "log_keepopen", PARAM_BOOL
, "true"},
73 { "log_level", PARAM_INT
, "0"},
74 { "disable_mlockall", PARAM_BOOL
, "true"},
75 { "cache_timeout", PARAM_LONG
, DEFAULT_CACHE_TIMEOUT
},
76 { "cache_push", PARAM_CHARPP
, NULL
},
77 { "disable_list_and_dump", PARAM_BOOL
, "false"},
78 { "recursion_depth", PARAM_INT
, "100"},
79 { "syslog", PARAM_BOOL
, "false"},
80 { "allowed", PARAM_CHARPP
, NULL
},
81 { "allowed_file", PARAM_CHARP
, NULL
},
82 { "priority", PARAM_INT
, INVALID_PRIORITY
},
83 { "keepalive_interval", PARAM_INT
, DEFAULT_KEEPALIVE_INTERVAL
},
84 { "tcp_port", PARAM_INT
, "6466"},
85 { "enable_tcp", PARAM_BOOL
, "false"},
86 { "tcp_require_key", PARAM_BOOL
, "false"},
87 { "tcp_bind", PARAM_CHARP
, "any"},
88 { "tcp_interface", PARAM_CHARP
, NULL
},
89 { "tls_timeout", PARAM_INT
, "300"},
90 { "tls_cipher_suite", PARAM_CHARP
, DEFAULT_CIPHER_PRIORITY
},
91 { "tls_dh_params_file", PARAM_CHARP
, NULL
},
92 { "tls_use_crl", PARAM_BOOL
, "false"},
93 { "require_save_key", PARAM_BOOL
, "true"},
94 { "invoking_user", PARAM_CHARPP
, NULL
},
95 { "invoking_file", PARAM_CHARP
, NULL
},
96 { "encrypt_to", PARAM_BOOL
, "false"},
97 { "always_trust", PARAM_BOOL
, "false"},
98 { "gpg_homedir", PARAM_CHARP
, NULL
},
99 { "strict_kill", PARAM_BOOL
, "false"},
100 { "lock_timeout", PARAM_LONG
, DEFAULT_LOCK_TIMEOUT
},
101 { "kill_scd", PARAM_BOOL
, "false"},
102 { "strict_open", PARAM_BOOL
, "false"},
103 { NULL
, PARAM_INVALID
, NULL
},
106 struct config_param_s
127 static struct config_section_s
*config_find_section (struct slist_s
*config
,
129 static int new_param (struct config_section_s
*section
, const char *filename
,
130 int lineno
, const char *name
, const char *value
,
132 static void free_section (struct config_section_s
*s
);
133 static int set_defaults (struct slist_s
**config
, int reload
);
136 section_remove_param (struct config_section_s
*section
, const char *name
)
138 unsigned i
, t
= slist_length (section
->params
);
140 for (i
= 0; i
< t
; i
++)
142 struct config_param_s
*p
= slist_nth_data (section
->params
, i
);
147 if (!strcmp (p
->name
, name
))
152 xfree (p
->value
.cptype
);
155 strv_free (p
->value
.cpptype
);
159 section
->params
= slist_remove (section
->params
, p
);
167 static struct config_param_s
*
168 config_has_param (struct config_section_s
*s
, const char *what
)
170 unsigned i
, t
= slist_length (s
->params
);
172 for (i
= 0; i
< t
; i
++)
174 struct config_param_s
*p
= slist_nth_data (s
->params
, i
);
178 if (!strcmp (p
->name
, what
))
185 static struct config_param_s
*
186 config_get_param (struct slist_s
*config
,
187 const char *section
, const char *what
, int *exists
)
189 unsigned i
, t
= slist_length (config
);
193 for (i
= 0; i
< t
; i
++)
195 struct config_param_s
*p
;
196 struct config_section_s
*s
= slist_nth_data (config
, i
);
201 if (strcmp (s
->name
, section
))
204 p
= config_has_param (s
, what
);
215 static struct config_section_s
*
216 new_section (struct slist_s
**config
, const char *name
)
219 struct config_section_s
*s
= xcalloc (1, sizeof (struct config_section_s
));
224 s
->name
= str_dup (name
);
227 log_write ("%s", pwmd_strerror (ENOMEM
));
232 tmp
= slist_append (*config
, s
);
235 log_write ("%s", pwmd_strerror (ENOMEM
));
246 config_set_string_param (struct slist_s
**config
, const char *section
,
247 const char *name
, const char *value
)
249 struct config_section_s
*s
= config_find_section (*config
, section
);
253 s
= new_section (config
, section
);
258 return new_param (s
, NULL
, 0, name
, value
, PARAM_CHARP
);
262 config_get_string_param (struct slist_s
*config
, const char *section
,
263 const char *what
, int *exists
)
265 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
266 return *exists
&& p
->value
.cptype
? str_dup (p
->value
.cptype
) : NULL
;
270 config_set_int_param (struct slist_s
**config
, const char *section
,
271 const char *name
, const char *value
)
273 struct config_section_s
*s
= config_find_section (*config
, section
);
277 s
= new_section (config
, section
);
282 return new_param (s
, NULL
, 0, name
, value
, PARAM_INT
);
286 config_get_int_param (struct slist_s
*config
, const char *section
,
287 const char *what
, int *exists
)
289 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
290 return *exists
? p
->value
.itype
: -1;
294 config_set_bool_param (struct slist_s
**config
, const char *section
,
295 const char *name
, const char *value
)
297 struct config_section_s
*s
= config_find_section (*config
, section
);
301 s
= new_section (config
, section
);
306 return new_param (s
, NULL
, 0, name
, value
, PARAM_BOOL
);
310 config_get_bool_param (struct slist_s
*config
, const char *section
,
311 const char *what
, int *exists
)
313 return config_get_int_param (config
, section
, what
, exists
);
317 config_set_long_param (struct slist_s
**config
, const char *section
,
318 const char *name
, const char *value
)
320 struct config_section_s
*s
= config_find_section (*config
, section
);
324 s
= new_section (config
, section
);
329 return new_param (s
, NULL
, 0, name
, value
, PARAM_LONG
);
333 config_get_long_param (struct slist_s
*config
, const char *section
,
334 const char *what
, int *exists
)
336 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
337 return *exists
? p
->value
.ltype
: -1;
341 config_set_longlong_param (struct slist_s
**config
, const char *section
,
342 const char *name
, const char *value
)
344 struct config_section_s
*s
= config_find_section (*config
, section
);
348 s
= new_section (config
, section
);
353 return new_param (s
, NULL
, 0, name
, value
, PARAM_LONGLONG
);
357 config_get_longlong_param (struct slist_s
*config
,
358 const char *section
, const char *what
, int *exists
)
360 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
361 return *exists
? p
->value
.lltype
: -1;
365 config_set_list_param (struct slist_s
**config
, const char *section
,
366 const char *name
, const char *value
)
368 struct config_section_s
*s
= config_find_section (*config
, section
);
372 s
= new_section (config
, section
);
377 return new_param (s
, NULL
, 0, name
, value
, PARAM_CHARPP
);
381 config_get_list_param (struct slist_s
*config
, const char *section
,
382 const char *what
, int *exists
)
384 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
385 return *exists
&& p
->value
.cpptype
? strv_dup (p
->value
.cpptype
) : NULL
;
389 config_get_string (const char *section
, const char *what
)
392 const char *where
= section
? section
: "global";
395 MUTEX_LOCK (&rcfile_mutex
);
396 val
= config_get_string_param (global_config
, where
, what
, &exists
);
397 if (!exists
&& strcmp (section
? section
: "", "global"))
398 val
= config_get_string_param (global_config
, "global", what
, &exists
);
400 MUTEX_UNLOCK (&rcfile_mutex
);
405 config_get_list (const char *section
, const char *what
)
408 const char *where
= section
? section
: "global";
411 MUTEX_LOCK (&rcfile_mutex
);
412 val
= config_get_list_param (global_config
, where
, what
, &exists
);
413 if (!exists
&& strcmp (section
? section
: "", "global"))
414 val
= config_get_list_param (global_config
, "global", what
, &exists
);
416 MUTEX_UNLOCK (&rcfile_mutex
);
421 config_get_integer (const char *section
, const char *what
)
424 const char *where
= section
? section
: "global";
427 MUTEX_LOCK (&rcfile_mutex
);
428 val
= config_get_int_param (global_config
, where
, what
, &exists
);
429 if (!exists
&& strcmp (section
? section
: "", "global"))
430 val
= config_get_int_param (global_config
, "global", what
, &exists
);
432 MUTEX_UNLOCK (&rcfile_mutex
);
437 config_get_longlong (const char *section
, const char *what
)
440 const char *where
= section
? section
: "global";
443 MUTEX_LOCK (&rcfile_mutex
);
444 val
= config_get_longlong_param (global_config
, where
, what
, &exists
);
445 if (!exists
&& strcmp (section
? section
: "", "global"))
446 val
= config_get_longlong_param (global_config
, "global", what
, &exists
);
448 MUTEX_UNLOCK (&rcfile_mutex
);
453 config_get_long (const char *section
, const char *what
)
456 const char *where
= section
? section
: "global";
459 MUTEX_LOCK (&rcfile_mutex
);
460 val
= config_get_long_param (global_config
, where
, what
, &exists
);
461 if (!exists
&& strcmp (section
? section
: "", "global"))
462 val
= config_get_long_param (global_config
, "global", what
, &exists
);
464 MUTEX_UNLOCK (&rcfile_mutex
);
469 config_get_boolean (const char *section
, const char *what
)
471 return config_get_integer (section
, what
);
475 config_get_value (const char *section
, const char *what
)
477 const char *where
= section
? section
: "global";
487 MUTEX_LOCK (&rcfile_mutex
);
489 for (i
= 0; config_params
[i
].name
; i
++)
491 if (!strcmp (config_params
[i
].name
, what
))
493 switch (config_params
[i
].type
)
497 ival
= config_get_int_param (global_config
, where
, what
,
499 if (!exists
&& strcmp (section
? section
: "", "global"))
500 ival
= config_get_int_param (global_config
, "global", what
,
502 result
= str_asprintf ("%i", ival
);
505 cpval
= config_get_string_param (global_config
, where
, what
,
507 if (!exists
&& strcmp (section
? section
: "", "global"))
509 config_get_string_param (global_config
, "global", what
,
514 lval
= config_get_long_param (global_config
, where
, what
,
516 if (!exists
&& strcmp (section
? section
: "", "global"))
517 lval
= config_get_long_param (global_config
, "global", what
,
519 result
= str_asprintf ("%li", lval
);
522 llval
= config_get_longlong_param (global_config
, where
, what
,
524 if (!exists
&& strcmp (section
? section
: "", "global"))
525 llval
= config_get_longlong_param (global_config
, "global",
527 result
= str_asprintf ("%lli", llval
);
530 cppval
= config_get_list_param (global_config
, where
, what
,
532 if (!exists
&& strcmp (section
? section
: "", "global"))
533 cppval
= config_get_list_param (global_config
, "global", what
,
537 result
= strv_join (",", cppval
);
545 MUTEX_UNLOCK (&rcfile_mutex
);
549 /* 'file' is the list parameter file to load into the list parameter 'what'.
550 * The parsing of the parameter is not done here. */
552 parse_list_file (struct slist_s
*config
, const char *section
,
553 const char *file
, const char *what
)
556 char buf
[LINE_MAX
] = {0};
560 char *p
= config_get_string_param (config
, section
, file
, &exists
);
569 tmp
= expand_homedir (p
);
575 rc
= gpg_error_from_errno (errno
);
576 log_write ("%s: %s", p
, pwmd_strerror (rc
));
582 list
= config_get_list_param (config
, section
, what
, &exists
);
586 log_write ("%s", pwmd_strerror (ENOMEM
));
587 return gpg_error (ENOMEM
);
590 while ((p
= fgets (buf
, sizeof (buf
)-1, fp
)))
594 if (p
[strlen(p
)-1] == '\n')
597 while (*p
&& isspace (*p
))
600 if (!*p
|| *p
== ';')
605 pp
= strv_cat (list
, str_dup (p
));
612 log_write ("%s", strerror (ENOMEM
));
613 return gpg_error (ENOMEM
);
624 p
= strv_join (",", list
);
629 log_write ("%s", pwmd_strerror (ENOMEM
));
630 return gpg_error (ENOMEM
);
633 config_set_list_param (&config
, section
, what
, p
);
639 fixup_allowed_once (struct slist_s
**config
, const char *section
)
641 char **list
, **pp
, *p
;
645 rc
= parse_list_file (*config
, section
, "allowed_file", "allowed");
649 list
= config_get_list_param (*config
, section
, "allowed", &exists
);
650 for (pp
= list
; pp
&& *pp
; pp
++)
654 for (p
= *pp
; p
&& *p
; p
++)
662 if (!strcmp (section
, "global"))
664 p
= get_username (getuid());
666 if (config_set_list_param (config
, section
, "allowed", p
))
676 list
= config_get_list_param (*config
, "global", "allowed", &exists
);
679 p
= strv_join (",", list
);
681 if (config_set_list_param (config
, section
, "allowed", p
))
696 fixup_allowed (struct slist_s
**config
)
698 int n
, t
= slist_length (*config
);
700 for (n
= 0; n
< t
; n
++)
702 struct config_section_s
*section
;
704 section
= slist_nth_data (*config
, n
);
705 if (fixup_allowed_once (config
, section
->name
))
713 add_invoking_user (struct invoking_user_s
**users
, char *id
,
714 struct slist_s
**config
)
716 struct passwd
*pwd
= NULL
;
717 struct group
*grp
= NULL
;
718 struct invoking_user_s
*user
, *p
;
721 if (id
&& (*id
== '!' || *id
== '-'))
730 pwd
= getpwuid (getuid ());
733 log_write (_("could not set any invoking user: %s"),
734 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
740 grp
= getgrnam (id
+1);
743 log_write (_("could not parse group '%s': %s"), id
+1,
744 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
751 if (!grp
&& !pwd
&& id
&& *id
!= '#')
754 log_write (_("could not set invoking user '%s': %s"), id
,
755 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
757 log_write (_("could not set any invoking user!"));
762 user
= xcalloc (1, sizeof (struct invoking_user_s
));
765 log_write ("%s", pwmd_strerror (ENOMEM
));
770 user
->type
= pwd
? INVOKING_UID
: grp
? INVOKING_GID
: INVOKING_TLS
;
772 user
->uid
= pwd
->pw_uid
;
774 user
->id
= str_dup (id
+1);
779 for (s
= id
; s
&& *s
; s
++)
782 user
->id
= str_dup (id
+1);
785 /* Set the default invoking_user since it doesn't exist. */
786 if (pwd
&& (!id
|| !*id
))
787 config_set_list_param (config
, "global", "invoking_user", pwd
->pw_name
);
795 for (p
= *users
; p
; p
= p
->next
)
808 parse_invoking_users (struct slist_s
**config
)
810 struct invoking_user_s
*users
= NULL
;
814 if (parse_list_file (*config
, "global", "invoking_file", "invoking_user"))
817 list
= config_get_list_param (*config
, "global", "invoking_user", &exists
);
818 for (l
= list
; l
&& *l
; l
++)
820 if (add_invoking_user (&users
, *l
, config
))
823 free_invoking_users (users
);
830 if (add_invoking_user (&users
, NULL
, config
))
837 free_invoking_users (invoking_users
);
838 invoking_users
= users
;
844 set_defaults (struct slist_s
**config
, int reload
)
851 for (i
= 0; config_params
[i
].name
; i
++)
853 switch (config_params
[i
].type
)
856 config_get_bool_param (*config
, "global", config_params
[i
].name
,
860 if (config_set_bool_param
861 (config
, "global", config_params
[i
].name
,
862 config_params
[i
].value
))
867 config_get_int_param (*config
, "global", config_params
[i
].name
,
871 if (config_set_int_param
872 (config
, "global", config_params
[i
].name
,
873 config_params
[i
].value
))
878 s
= config_get_string_param (*config
, "global",
879 config_params
[i
].name
, &exists
);
881 if (!exists
&& config_params
[i
].value
)
883 if (config_set_string_param (config
, "global",
884 config_params
[i
].name
,
885 config_params
[i
].value
))
890 list
= config_get_list_param (*config
, "global",
891 config_params
[i
].name
, &exists
);
893 if (!exists
&& config_params
[i
].value
)
895 if (config_set_list_param (config
, "global",
896 config_params
[i
].name
,
897 config_params
[i
].value
))
902 config_get_long_param (*config
, "global", config_params
[i
].name
,
906 if (config_set_long_param
907 (config
, "global", config_params
[i
].name
,
908 config_params
[i
].value
))
913 config_get_longlong_param (*config
, "global", config_params
[i
].name
,
917 if (config_set_longlong_param (config
, "global",
918 config_params
[i
].name
,
919 config_params
[i
].value
))
927 if (!reload
&& fixup_allowed (config
))
930 if (!reload
&& parse_invoking_users (config
))
933 log_level
= config_get_int_param (*config
, "global",
934 "log_level", &exists
);
935 log_keepopen
= config_get_int_param (*config
, "global",
936 "log_keepopen", &exists
);
937 max_recursion_depth
= config_get_int_param (*config
, "global",
938 "recursion_depth", &exists
);
939 disable_list_and_dump
= config_get_bool_param (*config
, "global",
940 "disable_list_and_dump",
944 config_get_bool_param (*config
, "global", "disable_mlockall", &exists
);
955 static struct config_section_s
*
956 config_find_section (struct slist_s
*config
, const char *name
)
958 unsigned i
, t
= slist_length (config
);
960 for (i
= 0; i
< t
; i
++)
962 struct config_section_s
*s
= slist_nth_data (config
, i
);
964 if (!strcmp (s
->name
, name
))
971 /* Append a new parameter to the list of parameters for a file
972 * section. When an existing parameter of the same name exists, its
976 new_param (struct config_section_s
*section
, const char *filename
, int lineno
,
977 const char *name
, const char *value
, int type
)
979 struct config_param_s
*param
= NULL
;
982 unsigned i
, t
= slist_length (section
->params
);
985 for (i
= 0; i
< t
; i
++)
987 struct config_param_s
*p
= slist_nth_data (section
->params
, i
);
991 if (!strcmp (name
, p
->name
))
1001 param
= xcalloc (1, sizeof (struct config_param_s
));
1004 log_write ("%s", pwmd_strerror (ENOMEM
));
1008 param
->name
= str_dup (name
);
1012 log_write ("%s", pwmd_strerror (ENOMEM
));
1022 if (!strcasecmp (value
, "no") || !strcasecmp (value
, "0")
1023 || !strcasecmp (value
, "false"))
1024 param
->value
.itype
= 0;
1025 else if (!strcasecmp (value
, "yes") || !strcasecmp (value
, "1")
1026 || !strcasecmp (value
, "true"))
1027 param
->value
.itype
= 1;
1030 INVALID_VALUE (filename
, lineno
);
1033 param
->type
= PARAM_INT
;
1036 xfree (param
->value
.cptype
);
1037 param
->value
.cptype
= NULL
;
1038 param
->value
.cptype
= value
&& *value
? str_dup (value
) : NULL
;
1039 if (value
&& *value
&& !param
->value
.cptype
)
1041 log_write ("%s", pwmd_strerror (ENOMEM
));
1046 strv_free (param
->value
.cpptype
);
1047 param
->value
.cpptype
= NULL
;
1048 param
->value
.cpptype
= value
&& *value
?
1049 str_split_ws (value
, ",", 0) : NULL
;
1050 if (value
&& *value
&& !param
->value
.cpptype
)
1052 log_write ("%s", pwmd_strerror (ENOMEM
));
1057 param
->value
.itype
= strtol (value
, &e
, 10);
1060 INVALID_VALUE (filename
, lineno
);
1065 param
->value
.ltype
= strtol (value
, &e
, 10);
1068 INVALID_VALUE (filename
, lineno
);
1072 case PARAM_LONGLONG
:
1073 param
->value
.lltype
= strtoll (value
, &e
, 10);
1076 INVALID_VALUE (filename
, lineno
);
1085 tmp
= slist_append (section
->params
, param
);
1088 log_write ("%s", pwmd_strerror (ENOMEM
));
1092 section
->params
= tmp
;
1096 xfree (param
->name
);
1102 config_parse (const char *filename
, int reload
)
1104 struct slist_s
*tmpconfig
= NULL
, *tmp
;
1105 struct config_section_s
*cur_section
= NULL
;
1106 char buf
[LINE_MAX
] = {0};
1109 int have_global
= 0;
1110 FILE *fp
= fopen (filename
, "r");
1114 log_write ("%s: %s", filename
,
1115 pwmd_strerror (gpg_error_from_errno (errno
)));
1117 if (errno
!= ENOENT
)
1120 log_write (_("Using defaults!"));
1124 for (; (s
= fgets (buf
, sizeof (buf
), fp
)); lineno
++)
1126 char line
[LINE_MAX
] = { 0 };
1137 /* New file section. */
1140 struct config_section_s
*section
;
1141 char *p
= strchr (++s
, ']');
1145 log_write (_("%s(%i): unbalanced braces"), filename
, lineno
);
1151 log_write (_("%s(%i): trailing characters"), filename
, lineno
);
1155 len
= strlen (s
) - strlen (p
);
1156 memcpy (line
, s
, len
);
1159 section
= config_find_section (tmpconfig
, line
);
1162 log_write (_("%s(%i): section '%s' already exists!"),
1163 filename
, lineno
, line
);
1167 if (!strcmp (line
, "global"))
1170 section
= xcalloc (1, sizeof (struct config_section_s
));
1171 section
->name
= str_dup (line
);
1175 tmp
= slist_append (tmpconfig
, cur_section
);
1178 log_write ("%s", pwmd_strerror (ENOMEM
));
1185 cur_section
= section
;
1191 log_write (_("%s(%i): parameter outside of section!"), filename
,
1196 /* Parameters for each section. */
1197 for (int m
= 0; config_params
[m
].name
; m
++)
1199 len
= strlen (config_params
[m
].name
);
1200 if (!strncmp (s
, config_params
[m
].name
, len
))
1204 while (*p
&& *p
== ' ')
1207 if (!*p
|| *p
!= '=')
1211 while (*p
&& isspace (*p
))
1215 if (new_param (cur_section
, filename
, lineno
, s
, p
,
1216 config_params
[m
].type
))
1226 log_write (_("%s(%i): unknown parameter"), filename
, lineno
);
1233 tmp
= slist_append (tmpconfig
, cur_section
);
1236 log_write ("%s", pwmd_strerror (ENOMEM
));
1246 ("WARNING: %s: could not find a [global] configuration section!"),
1250 if (set_defaults (&tmpconfig
, reload
))
1262 config_free (tmpconfig
);
1263 free_section (cur_section
);
1268 free_section (struct config_section_s
*s
)
1275 struct config_param_s
*p
= slist_nth_data (s
->params
, 0);
1280 section_remove_param (s
, p
->name
);
1289 config_free (struct slist_s
*config
)
1293 struct config_section_s
*s
= slist_nth_data (config
, 0);
1298 config
= slist_remove (config
, s
);
1304 free_invoking_users (struct invoking_user_s
*users
)
1306 struct invoking_user_s
*p
;
1310 struct invoking_user_s
*next
= p
->next
;
1312 if (p
->type
== INVOKING_TLS
|| p
->type
== INVOKING_GID
)
1321 param_type (const char *name
)
1325 for (i
= 0; config_params
[i
].name
; i
++)
1327 if (!strcmp (config_params
[i
].name
, name
))
1328 return config_params
[i
].type
;
1331 return PARAM_INVALID
;
1335 keep_parse (struct config_keep_s
*k
, const char *section
, const char *key
)
1343 int type
= param_type (key
);
1350 ival
= config_get_int_param (global_config
, section
, key
, &exists
);
1352 value
= str_asprintf ("%i", ival
);
1355 lval
= config_get_long_param (global_config
, section
, key
, &exists
);
1357 value
= str_asprintf ("%li", lval
);
1359 case PARAM_LONGLONG
:
1360 llval
= config_get_longlong_param (global_config
, section
, key
, &exists
);
1362 value
= str_asprintf ("%lli", llval
);
1365 cpval
= config_get_string_param (global_config
, section
, key
, &exists
);
1370 cppval
= config_get_list_param (global_config
, section
, key
, &exists
);
1373 char *s
= strv_join (",", cppval
);
1386 k
->section
= str_dup(section
);
1387 k
->name
= str_dup(key
);
1392 static struct slist_s
*
1393 keep_add (struct slist_s
*k
, const char *s
, const char *key
)
1395 int n
, t
= slist_length (global_config
);
1397 for (n
= 0; n
< t
; n
++)
1399 struct config_section_s
*section
;
1400 struct config_keep_s
*tmp
;
1403 section
= slist_nth_data (global_config
, n
);
1404 tmp
= xcalloc (1, sizeof(struct config_keep_s
));
1406 // Process all sections.
1408 ret
= keep_parse (tmp
, section
->name
, key
);
1410 ret
= keep_parse (tmp
, s
, key
);
1413 k
= slist_append (k
, tmp
);
1421 /* Keep security sensitive settings across SIGHUP. */
1425 struct slist_s
*keep
= NULL
;
1428 keep
= keep_add (keep
, NULL
, "tcp_require_key");
1430 keep
= keep_add (keep
, NULL
, "require_save_key");
1431 keep
= keep_add (keep
, NULL
, "allowed");
1432 keep
= keep_add (keep
, NULL
, "allowed_file");
1433 keep
= keep_add (keep
, "global", "encrypt_to");
1434 keep
= keep_add (keep
, "global", "always_trust");
1435 keep
= keep_add (keep
, "global", "invoking_user");
1436 keep
= keep_add (keep
, "global", "invoking_file");
1437 keep
= keep_add (keep
, "global", "gpg_homedir");
1441 /* Restore parameters previously saved with config_keep_save(). This will also
1445 config_keep_restore (struct slist_s
*keep
)
1447 int n
, t
= slist_length (keep
);
1449 for (n
= 0; n
< t
; n
++)
1451 struct config_keep_s
*k
= slist_nth_data (keep
, n
);
1452 int type
= param_type (k
->name
);
1457 config_set_bool_param (&global_config
, k
->section
, k
->name
, k
->value
);
1460 config_set_int_param (&global_config
, k
->section
, k
->name
, k
->value
);
1463 config_set_long_param (&global_config
, k
->section
, k
->name
, k
->value
);
1465 case PARAM_LONGLONG
:
1466 config_set_longlong_param (&global_config
, k
->section
, k
->name
,
1470 config_set_string_param (&global_config
, k
->section
, k
->name
,
1474 config_set_list_param (&global_config
, k
->section
, k
->name
, k
->value
);