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
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 { "passphrase_file", PARAM_CHARP
, NULL
},
69 { "log_path", PARAM_CHARP
, "~/.pwmd/log"},
70 { "enable_logging", PARAM_BOOL
, "0"},
71 { "log_keepopen", PARAM_BOOL
, "true"},
72 { "log_level", PARAM_INT
, "0"},
73 { "disable_mlockall", PARAM_BOOL
, "true"},
74 { "cache_timeout", PARAM_INT
, DEFAULT_CACHE_TIMEOUT
},
75 { "cache_push", PARAM_CHARPP
, NULL
},
76 { "disable_list_and_dump", PARAM_BOOL
, "false"},
77 { "recursion_depth", PARAM_INT
, "100"},
78 { "syslog", PARAM_BOOL
, "false"},
79 { "xfer_progress", PARAM_INT
, "8196"},
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
, "SECURE256:SECURE192:SECURE128:-VERS-SSL3.0:-VERS-TLS1.0"},
91 { "tls_dh_params_file", PARAM_CHARP
, NULL
},
92 { "require_save_key", PARAM_BOOL
, "true"},
93 { "invoking_user", PARAM_CHARPP
, NULL
},
94 { "invoking_file", PARAM_CHARP
, NULL
},
95 { "encrypt_to", PARAM_BOOL
, "false"},
96 { "always_trust", PARAM_BOOL
, "false"},
97 { "gpg_homedir", PARAM_CHARP
, NULL
},
98 { "strict_kill", PARAM_BOOL
, "false"},
99 { "lock_timeout", PARAM_INT
, DEFAULT_LOCK_TIMEOUT
},
100 { "send_state", PARAM_INT
, "2"},
101 { "kill_scd", PARAM_BOOL
, "false"},
102 { NULL
, PARAM_INVALID
, NULL
},
105 struct config_param_s
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
, int reload
);
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
);
166 static struct config_param_s
*
167 config_has_param (struct config_section_s
*s
, const char *what
)
169 unsigned i
, t
= slist_length (s
->params
);
171 for (i
= 0; i
< t
; i
++)
173 struct config_param_s
*p
= slist_nth_data (s
->params
, i
);
177 if (!strcmp (p
->name
, what
))
184 static struct config_param_s
*
185 config_get_param (struct slist_s
*config
,
186 const char *section
, const char *what
, int *exists
)
188 unsigned i
, t
= slist_length (config
);
192 for (i
= 0; i
< t
; i
++)
194 struct config_param_s
*p
;
195 struct config_section_s
*s
= slist_nth_data (config
, i
);
200 if (strcmp (s
->name
, section
))
203 p
= config_has_param (s
, what
);
214 static struct config_section_s
*
215 new_section (struct slist_s
**config
, const char *name
)
218 struct config_section_s
*s
= xcalloc (1, sizeof (struct config_section_s
));
223 s
->name
= str_dup (name
);
226 log_write ("%s", pwmd_strerror (ENOMEM
));
231 tmp
= slist_append (*config
, s
);
234 log_write ("%s", pwmd_strerror (ENOMEM
));
245 config_set_string_param (struct slist_s
**config
, const char *section
,
246 const char *name
, const char *value
)
248 struct config_section_s
*s
= config_find_section (*config
, section
);
252 s
= new_section (config
, section
);
257 return new_param (s
, NULL
, 0, name
, value
, PARAM_CHARP
);
261 config_get_string_param (struct slist_s
*config
, const char *section
,
262 const char *what
, int *exists
)
264 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
265 return *exists
&& p
->value
.cptype
? str_dup (p
->value
.cptype
) : NULL
;
269 config_set_int_param (struct slist_s
**config
, const char *section
,
270 const char *name
, const char *value
)
272 struct config_section_s
*s
= config_find_section (*config
, section
);
276 s
= new_section (config
, section
);
281 return new_param (s
, NULL
, 0, name
, value
, PARAM_INT
);
285 config_get_int_param (struct slist_s
*config
, const char *section
,
286 const char *what
, int *exists
)
288 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
289 return *exists
? p
->value
.itype
: -1;
293 config_set_bool_param (struct slist_s
**config
, const char *section
,
294 const char *name
, const char *value
)
296 struct config_section_s
*s
= config_find_section (*config
, section
);
300 s
= new_section (config
, section
);
305 return new_param (s
, NULL
, 0, name
, value
, PARAM_BOOL
);
309 config_get_bool_param (struct slist_s
*config
, const char *section
,
310 const char *what
, int *exists
)
312 return config_get_int_param (config
, section
, what
, exists
);
316 config_set_long_param (struct slist_s
**config
, const char *section
,
317 const char *name
, const char *value
)
319 struct config_section_s
*s
= config_find_section (*config
, section
);
323 s
= new_section (config
, section
);
328 return new_param (s
, NULL
, 0, name
, value
, PARAM_LONG
);
332 config_get_long_param (struct slist_s
*config
, const char *section
,
333 const char *what
, int *exists
)
335 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
336 return *exists
? p
->value
.ltype
: -1;
340 config_set_longlong_param (struct slist_s
**config
, const char *section
,
341 const char *name
, const char *value
)
343 struct config_section_s
*s
= config_find_section (*config
, section
);
347 s
= new_section (config
, section
);
352 return new_param (s
, NULL
, 0, name
, value
, PARAM_LONGLONG
);
356 config_get_longlong_param (struct slist_s
*config
,
357 const char *section
, const char *what
, int *exists
)
359 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
360 return *exists
? p
->value
.lltype
: -1;
364 config_set_list_param (struct slist_s
**config
, const char *section
,
365 const char *name
, const char *value
)
367 struct config_section_s
*s
= config_find_section (*config
, section
);
371 s
= new_section (config
, section
);
376 return new_param (s
, NULL
, 0, name
, value
, PARAM_CHARPP
);
380 config_get_list_param (struct slist_s
*config
, const char *section
,
381 const char *what
, int *exists
)
383 struct config_param_s
*p
= config_get_param (config
, section
, what
, exists
);
384 return *exists
&& p
->value
.cpptype
? strv_dup (p
->value
.cpptype
) : NULL
;
388 config_get_string (const char *section
, const char *what
)
391 const char *where
= section
? section
: "global";
394 MUTEX_LOCK (&rcfile_mutex
);
395 val
= config_get_string_param (global_config
, where
, what
, &exists
);
396 if (!exists
&& strcmp (section
? section
: "", "global"))
397 val
= config_get_string_param (global_config
, "global", what
, &exists
);
399 MUTEX_UNLOCK (&rcfile_mutex
);
404 config_get_list (const char *section
, const char *what
)
407 const char *where
= section
? section
: "global";
410 MUTEX_LOCK (&rcfile_mutex
);
411 val
= config_get_list_param (global_config
, where
, what
, &exists
);
412 if (!exists
&& strcmp (section
? section
: "", "global"))
413 val
= config_get_list_param (global_config
, "global", what
, &exists
);
415 MUTEX_UNLOCK (&rcfile_mutex
);
420 config_get_integer (const char *section
, const char *what
)
423 const char *where
= section
? section
: "global";
426 MUTEX_LOCK (&rcfile_mutex
);
427 val
= config_get_int_param (global_config
, where
, what
, &exists
);
428 if (!exists
&& strcmp (section
? section
: "", "global"))
429 val
= config_get_int_param (global_config
, "global", what
, &exists
);
431 MUTEX_UNLOCK (&rcfile_mutex
);
436 config_get_longlong (const char *section
, const char *what
)
439 const char *where
= section
? section
: "global";
442 MUTEX_LOCK (&rcfile_mutex
);
443 val
= config_get_longlong_param (global_config
, where
, what
, &exists
);
444 if (!exists
&& strcmp (section
? section
: "", "global"))
445 val
= config_get_longlong_param (global_config
, "global", what
, &exists
);
447 MUTEX_UNLOCK (&rcfile_mutex
);
452 config_get_long (const char *section
, const char *what
)
455 const char *where
= section
? section
: "global";
458 MUTEX_LOCK (&rcfile_mutex
);
459 val
= config_get_long_param (global_config
, where
, what
, &exists
);
460 if (!exists
&& strcmp (section
? section
: "", "global"))
461 val
= config_get_long_param (global_config
, "global", what
, &exists
);
463 MUTEX_UNLOCK (&rcfile_mutex
);
468 config_get_boolean (const char *section
, const char *what
)
470 return config_get_integer (section
, what
);
474 config_get_value (const char *section
, const char *what
)
476 const char *where
= section
? section
: "global";
486 MUTEX_LOCK (&rcfile_mutex
);
488 for (i
= 0; config_params
[i
].name
; i
++)
490 if (!strcmp (config_params
[i
].name
, what
))
492 switch (config_params
[i
].type
)
496 ival
= config_get_int_param (global_config
, where
, what
,
498 if (!exists
&& strcmp (section
? section
: "", "global"))
499 ival
= config_get_int_param (global_config
, "global", what
,
501 result
= str_asprintf ("%i", ival
);
504 cpval
= config_get_string_param (global_config
, where
, what
,
506 if (!exists
&& strcmp (section
? section
: "", "global"))
508 config_get_string_param (global_config
, "global", what
,
513 lval
= config_get_long_param (global_config
, where
, what
,
515 if (!exists
&& strcmp (section
? section
: "", "global"))
516 lval
= config_get_long_param (global_config
, "global", what
,
518 result
= str_asprintf ("%li", lval
);
521 llval
= config_get_longlong_param (global_config
, where
, what
,
523 if (!exists
&& strcmp (section
? section
: "", "global"))
524 llval
= config_get_longlong_param (global_config
, "global",
526 result
= str_asprintf ("%lli", llval
);
529 cppval
= config_get_list_param (global_config
, where
, what
,
531 if (!exists
&& strcmp (section
? section
: "", "global"))
532 cppval
= config_get_list_param (global_config
, "global", what
,
536 result
= strv_join (",", cppval
);
544 MUTEX_UNLOCK (&rcfile_mutex
);
548 /* 'file' is the list parameter file to load into the list parameter 'what'.
549 * The parsing of the parameter is not done here. */
551 parse_list_file (struct slist_s
*config
, const char *section
,
552 const char *file
, const char *what
)
555 char buf
[LINE_MAX
] = {0};
559 char *p
= config_get_string_param (config
, section
, file
, &exists
);
568 tmp
= expand_homedir (p
);
574 rc
= gpg_error_from_errno (errno
);
575 log_write ("%s: %s", p
, pwmd_strerror (rc
));
581 list
= config_get_list_param (config
, section
, what
, &exists
);
585 log_write ("%s", pwmd_strerror (ENOMEM
));
586 return gpg_error (ENOMEM
);
589 while ((p
= fgets (buf
, sizeof (buf
)-1, fp
)))
593 if (p
[strlen(p
)-1] == '\n')
596 while (*p
&& isspace (*p
))
599 if (!*p
|| *p
== ';')
604 pp
= strv_cat (list
, str_dup (p
));
611 log_write ("%s", strerror (ENOMEM
));
612 return gpg_error (ENOMEM
);
623 p
= strv_join (",", list
);
628 log_write ("%s", pwmd_strerror (ENOMEM
));
629 return gpg_error (ENOMEM
);
632 config_set_list_param (&config
, section
, what
, p
);
638 fixup_allowed_once (struct slist_s
**config
, const char *section
)
640 char **list
, **pp
, *p
;
644 rc
= parse_list_file (*config
, section
, "allowed_file", "allowed");
648 list
= config_get_list_param (*config
, section
, "allowed", &exists
);
649 for (pp
= list
; pp
&& *pp
; pp
++)
653 for (p
= *pp
; p
&& *p
; p
++)
661 if (!strcmp (section
, "global"))
663 p
= get_username (getuid());
665 if (config_set_list_param (config
, section
, "allowed", p
))
675 list
= config_get_list_param (*config
, "global", "allowed", &exists
);
678 p
= strv_join (",", list
);
680 if (config_set_list_param (config
, section
, "allowed", p
))
695 fixup_allowed (struct slist_s
**config
)
697 int n
, t
= slist_length (*config
);
699 for (n
= 0; n
< t
; n
++)
701 struct config_section_s
*section
;
703 section
= slist_nth_data (*config
, n
);
704 if (fixup_allowed_once (config
, section
->name
))
712 add_invoking_user (struct invoking_user_s
**users
, char *id
,
713 struct slist_s
**config
)
715 struct passwd
*pwd
= NULL
;
716 struct group
*grp
= NULL
;
717 struct invoking_user_s
*user
, *p
;
720 if (id
&& (*id
== '!' || *id
== '-'))
729 pwd
= getpwuid (getuid ());
732 log_write (_("could not set any invoking user: %s"),
733 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
739 grp
= getgrnam (id
+1);
742 log_write (_("could not parse group '%s': %s"), id
+1,
743 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
750 if (!grp
&& !pwd
&& id
&& *id
!= '#')
753 log_write (_("could not set invoking user '%s': %s"), id
,
754 pwmd_strerror (errno
? errno
: GPG_ERR_INV_VALUE
));
756 log_write (_("could not set any invoking user!"));
761 user
= xcalloc (1, sizeof (struct invoking_user_s
));
764 log_write ("%s", pwmd_strerror (ENOMEM
));
769 user
->type
= pwd
? INVOKING_UID
: grp
? INVOKING_GID
: INVOKING_TLS
;
771 user
->uid
= pwd
->pw_uid
;
773 user
->id
= str_dup (id
+1);
778 for (s
= id
; s
&& *s
; s
++)
781 user
->id
= str_dup (id
+1);
784 /* Set the default invoking_user since it doesn't exist. */
786 config_set_list_param (config
, "global", "invoking_user", pwd
->pw_name
);
794 for (p
= *users
; p
; p
= p
->next
)
807 parse_invoking_users (struct slist_s
**config
)
809 struct invoking_user_s
*users
= NULL
;
813 if (parse_list_file (*config
, "global", "invoking_file", "invoking_user"))
816 list
= config_get_list_param (*config
, "global", "invoking_user", &exists
);
817 for (l
= list
; l
&& *l
; l
++)
819 if (add_invoking_user (&users
, *l
, config
))
822 free_invoking_users (users
);
829 if (add_invoking_user (&users
, NULL
, config
))
836 free_invoking_users (invoking_users
);
837 invoking_users
= users
;
843 set_defaults (struct slist_s
**config
, int reload
)
850 for (i
= 0; config_params
[i
].name
; i
++)
852 switch (config_params
[i
].type
)
855 config_get_bool_param (*config
, "global", config_params
[i
].name
,
859 if (config_set_bool_param
860 (config
, "global", config_params
[i
].name
,
861 config_params
[i
].value
))
866 config_get_int_param (*config
, "global", config_params
[i
].name
,
870 if (config_set_int_param
871 (config
, "global", config_params
[i
].name
,
872 config_params
[i
].value
))
877 s
= config_get_string_param (*config
, "global",
878 config_params
[i
].name
, &exists
);
880 if (!exists
&& config_params
[i
].value
)
882 if (config_set_string_param (config
, "global",
883 config_params
[i
].name
,
884 config_params
[i
].value
))
889 list
= config_get_list_param (*config
, "global",
890 config_params
[i
].name
, &exists
);
892 if (!exists
&& config_params
[i
].value
)
894 if (config_set_list_param (config
, "global",
895 config_params
[i
].name
,
896 config_params
[i
].value
))
901 config_get_long_param (*config
, "global", config_params
[i
].name
,
905 if (config_set_long_param
906 (config
, "global", config_params
[i
].name
,
907 config_params
[i
].value
))
912 config_get_longlong_param (*config
, "global", config_params
[i
].name
,
916 if (config_set_longlong_param (config
, "global",
917 config_params
[i
].name
,
918 config_params
[i
].value
))
926 if (!reload
&& fixup_allowed (config
))
929 if (!reload
&& parse_invoking_users (config
))
932 log_level
= config_get_int_param (*config
, "global",
933 "log_level", &exists
);
934 log_keepopen
= config_get_int_param (*config
, "global",
935 "log_keepopen", &exists
);
936 max_recursion_depth
= config_get_int_param (*config
, "global",
937 "recursion_depth", &exists
);
938 disable_list_and_dump
= config_get_bool_param (*config
, "global",
939 "disable_list_and_dump",
943 config_get_bool_param (*config
, "global", "disable_mlockall", &exists
);
954 static struct config_section_s
*
955 config_find_section (struct slist_s
*config
, const char *name
)
957 unsigned i
, t
= slist_length (config
);
959 for (i
= 0; i
< t
; i
++)
961 struct config_section_s
*s
= slist_nth_data (config
, i
);
963 if (!strcmp (s
->name
, name
))
970 /* Append a new parameter to the list of parameters for a file
971 * section. When an existing parameter of the same name exists, its
975 new_param (struct config_section_s
*section
, const char *filename
, int lineno
,
976 const char *name
, const char *value
, int type
)
978 struct config_param_s
*param
= NULL
;
981 unsigned i
, t
= slist_length (section
->params
);
984 for (i
= 0; i
< t
; i
++)
986 struct config_param_s
*p
= slist_nth_data (section
->params
, i
);
990 if (!strcmp (name
, p
->name
))
1000 param
= xcalloc (1, sizeof (struct config_param_s
));
1003 log_write ("%s", pwmd_strerror (ENOMEM
));
1007 param
->name
= str_dup (name
);
1011 log_write ("%s", pwmd_strerror (ENOMEM
));
1021 if (!strcasecmp (value
, "no") || !strcasecmp (value
, "0")
1022 || !strcasecmp (value
, "false"))
1023 param
->value
.itype
= 0;
1024 else if (!strcasecmp (value
, "yes") || !strcasecmp (value
, "1")
1025 || !strcasecmp (value
, "true"))
1026 param
->value
.itype
= 1;
1029 INVALID_VALUE (filename
, lineno
);
1032 param
->type
= PARAM_INT
;
1035 xfree (param
->value
.cptype
);
1036 param
->value
.cptype
= NULL
;
1037 param
->value
.cptype
= value
&& *value
? str_dup (value
) : NULL
;
1038 if (value
&& *value
&& !param
->value
.cptype
)
1040 log_write ("%s", pwmd_strerror (ENOMEM
));
1045 strv_free (param
->value
.cpptype
);
1046 param
->value
.cpptype
= NULL
;
1047 param
->value
.cpptype
= value
&& *value
?
1048 str_split_ws (value
, ",", 0) : NULL
;
1049 if (value
&& *value
&& !param
->value
.cpptype
)
1051 log_write ("%s", pwmd_strerror (ENOMEM
));
1056 param
->value
.itype
= strtol (value
, &e
, 10);
1059 INVALID_VALUE (filename
, lineno
);
1064 param
->value
.ltype
= strtol (value
, &e
, 10);
1067 INVALID_VALUE (filename
, lineno
);
1071 case PARAM_LONGLONG
:
1072 param
->value
.lltype
= strtoll (value
, &e
, 10);
1075 INVALID_VALUE (filename
, lineno
);
1084 tmp
= slist_append (section
->params
, param
);
1087 log_write ("%s", pwmd_strerror (ENOMEM
));
1091 section
->params
= tmp
;
1095 xfree (param
->name
);
1101 config_parse (const char *filename
, int reload
)
1103 struct slist_s
*tmpconfig
= NULL
, *tmp
;
1104 struct config_section_s
*cur_section
= NULL
;
1105 char buf
[LINE_MAX
] = {0};
1108 int have_global
= 0;
1109 FILE *fp
= fopen (filename
, "r");
1113 log_write ("%s: %s", filename
,
1114 pwmd_strerror (gpg_error_from_errno (errno
)));
1116 if (errno
!= ENOENT
)
1119 log_write (_("Using defaults!"));
1123 for (; (s
= fgets (buf
, sizeof (buf
)-1, fp
)); lineno
++)
1125 char line
[LINE_MAX
] = { 0 };
1132 for (; s
&& *s
; s
++)
1136 /* New file section. */
1139 struct config_section_s
*section
;
1140 char *p
= strchr (++s
, ']');
1144 log_write (_("%s(%i): unbalanced braces"), filename
,
1149 len
= strlen (s
) - strlen (p
);
1150 memcpy (line
, s
, len
);
1153 section
= config_find_section (tmpconfig
, line
);
1156 log_write (_("%s(%i): section '%s' already exists!"),
1157 filename
, lineno
, line
);
1161 if (!strcmp (line
, "global"))
1164 section
= xcalloc (1, sizeof (struct config_section_s
));
1165 section
->name
= str_dup (line
);
1169 tmp
= slist_append (tmpconfig
, cur_section
);
1172 log_write ("%s", pwmd_strerror (ENOMEM
));
1179 cur_section
= section
;
1185 log_write (_("%s(%i): parameter outside of section!"), filename
,
1190 /* Parameters for each section. */
1191 for (int m
= 0; config_params
[m
].name
; m
++)
1193 size_t len
= strlen (config_params
[m
].name
);
1195 if (!strncmp (s
, config_params
[m
].name
, len
))
1199 while (*p
&& *p
== ' ')
1202 if (!*p
|| *p
!= '=')
1206 while (*p
&& isspace (*p
))
1210 if (new_param (cur_section
, filename
, lineno
, s
, p
,
1211 config_params
[m
].type
))
1221 log_write (_("%s(%i): unknown parameter"), filename
, lineno
);
1231 tmp
= slist_append (tmpconfig
, cur_section
);
1234 log_write ("%s", pwmd_strerror (ENOMEM
));
1244 ("WARNING: %s: could not find a [global] configuration section!"),
1248 if (set_defaults (&tmpconfig
, reload
))
1260 config_free (tmpconfig
);
1261 free_section (cur_section
);
1266 free_section (struct config_section_s
*s
)
1273 struct config_param_s
*p
= slist_nth_data (s
->params
, 0);
1278 section_remove_param (s
, p
->name
);
1287 config_free (struct slist_s
*config
)
1291 struct config_section_s
*s
= slist_nth_data (config
, 0);
1296 config
= slist_remove (config
, s
);
1302 free_invoking_users (struct invoking_user_s
*users
)
1304 struct invoking_user_s
*p
;
1308 struct invoking_user_s
*next
= p
->next
;
1310 if (p
->type
== INVOKING_TLS
|| p
->type
== INVOKING_GID
)
1319 param_type (const char *name
)
1323 for (i
= 0; config_params
[i
].name
; i
++)
1325 if (!strcmp (config_params
[i
].name
, name
))
1326 return config_params
[i
].type
;
1329 return PARAM_INVALID
;
1333 keep_parse (struct config_keep_s
*k
, const char *section
, const char *key
)
1341 int type
= param_type (key
);
1348 ival
= config_get_int_param (global_config
, section
, key
, &exists
);
1350 value
= str_asprintf ("%i", ival
);
1353 lval
= config_get_long_param (global_config
, section
, key
, &exists
);
1355 value
= str_asprintf ("%li", lval
);
1357 case PARAM_LONGLONG
:
1358 llval
= config_get_longlong_param (global_config
, section
, key
, &exists
);
1360 value
= str_asprintf ("%lli", llval
);
1363 cpval
= config_get_string_param (global_config
, section
, key
, &exists
);
1368 cppval
= config_get_list_param (global_config
, section
, key
, &exists
);
1371 char *s
= strv_join (",", cppval
);
1384 k
->section
= str_dup(section
);
1385 k
->name
= str_dup(key
);
1390 static struct slist_s
*
1391 keep_add (struct slist_s
*k
, const char *s
, const char *key
)
1393 int n
, t
= slist_length (global_config
);
1395 for (n
= 0; n
< t
; n
++)
1397 struct config_section_s
*section
;
1398 struct config_keep_s
*tmp
;
1401 section
= slist_nth_data (global_config
, n
);
1402 tmp
= xcalloc (1, sizeof(struct config_keep_s
));
1404 // Process all sections.
1406 ret
= keep_parse (tmp
, section
->name
, key
);
1408 ret
= keep_parse (tmp
, s
, key
);
1411 k
= slist_append (k
, tmp
);
1419 /* Keep security sensitive settings across SIGHUP. */
1423 struct slist_s
*keep
= NULL
;
1426 keep
= keep_add (keep
, NULL
, "tcp_require_key");
1428 keep
= keep_add (keep
, NULL
, "require_save_key");
1429 keep
= keep_add (keep
, NULL
, "allowed");
1430 keep
= keep_add (keep
, "global", "encrypt_to");
1431 keep
= keep_add (keep
, "global", "always_trust");
1432 keep
= keep_add (keep
, "global", "invoking_user");
1436 /* Restore parameters previously saved with config_keep_save(). This will also
1440 config_keep_restore (struct slist_s
*keep
)
1442 int n
, t
= slist_length (keep
);
1444 for (n
= 0; n
< t
; n
++)
1446 struct config_keep_s
*k
= slist_nth_data (keep
, n
);
1447 int type
= param_type (k
->name
);
1452 config_set_bool_param (&global_config
, k
->section
, k
->name
, k
->value
);
1455 config_set_int_param (&global_config
, k
->section
, k
->name
, k
->value
);
1458 config_set_long_param (&global_config
, k
->section
, k
->name
, k
->value
);
1460 case PARAM_LONGLONG
:
1461 config_set_longlong_param (&global_config
, k
->section
, k
->name
,
1465 config_set_string_param (&global_config
, k
->section
, k
->name
,
1469 config_set_list_param (&global_config
, k
->section
, k
->name
, k
->value
);