Debian Codegraph @

debian/patches/031_pam_include

raw
1 From: Sam Hartman <[email protected]>
2 Date: Mon, 11 Sep 2023 14:00:42 -0600
3 Subject: _pam_include
4
5 Patch to implement an @include directive for use in pam.d config files.
6
7 Authors: Jan Christoph Nordholz <[email protected]>
8
9 Updated for pam 1.7.0 by Sam Hartman <[email protected]>
10
11 Upstream status: not yet submitted
12 ---
13 libpam/pam_handlers.c | 36 ++++++++++++++++++++++++++++++++----
14 1 file changed, 32 insertions(+), 4 deletions(-)
15
16 diff --git a/libpam/pam_handlers.c b/libpam/pam_handlers.c
17 index 7fd6ce8..1df5e40 100644
18 --- a/libpam/pam_handlers.c
19 +++ b/libpam/pam_handlers.c
20 @@ -127,6 +127,10 @@ static int _pam_parse_conf_file(pam_handle_t *pamh, FILE *f
21 module_type = PAM_T_ACCT;
22 } else if (!strcasecmp("password", tok)) {
23 module_type = PAM_T_PASS;
24 + } else if (!strcasecmp("@include", tok)) {
25 + pam_include = 1;
26 + module_type = requested_module_type;
27 + goto parsing_done;
28 } else {
29 /* Illegal module type */
30 D(("bad module type: %s", tok));
31 @@ -197,8 +201,10 @@ static int _pam_parse_conf_file(pam_handle_t *pamh, FILE *f
32 _pam_set_default_control(actions, _PAM_ACTION_BAD);
33 }
34
35 +parsing_done:
36 tok = _pam_tokenize(NULL, &nexttok);
37 if (pam_include) {
38 + struct stat include_dir;
39 if (substack) {
40 res = _pam_add_handler(pamh, PAM_HT_SUBSTACK, other,
41 stack_level, module_type, actions, tok,
42 @@ -209,13 +215,35 @@ static int _pam_parse_conf_file(pam_handle_t *pamh, FILE *f
43 return PAM_ABORT;
44 }
45 }
46 - if (_pam_load_conf_file(pamh, tok, this_service, module_type,
47 - include_level + 1, stack_level + substack
48 + if (tok[0] == '/') {
49 + if (_pam_load_conf_file(pamh, tok, this_service,
50 + module_type, include_level+1, stack_level + substack
51 +#ifdef PAM_READ_BOTH_CONFS
52 + , !other
53 +#endif /* PAM_READ_BOTH_CONFS */
54 + ) == PAM_SUCCESS)
55 + continue;
56 + }
57 + else if (!stat(PAM_CONFIG_D, &include_dir)
58 + && S_ISDIR(include_dir.st_mode))
59 + {
60 + char *include_file;
61 + if (asprintf (&include_file, PAM_CONFIG_DF, tok) < 0) {
62 + pam_syslog(pamh, LOG_CRIT, "asprintf failed");
63 + return PAM_ABORT;
64 + }
65 + if (_pam_load_conf_file(pamh, include_file, this_service,
66 + module_type, include_level+1, stack_level + substack
67 #ifdef PAM_READ_BOTH_CONFS
68 , !other
69 #endif /* PAM_READ_BOTH_CONFS */
70 - ) == PAM_SUCCESS)
71 - continue;
72 + ) == PAM_SUCCESS)
73 + {
74 + free(include_file);
75 + continue;
76 + }
77 + free(include_file);
78 + }
79 _pam_set_default_control(actions, _PAM_ACTION_BAD);
80 mod_path = NULL;
81 handler_type = PAM_HT_MUST_FAIL;