;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013-2017, 2019-2021 Ludovic Courtès ;;; Copyright © 2023 Josselin Poiret ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu system pam) #:use-module (guix records) #:use-module (guix derivations) #:use-module (guix diagnostics) #:use-module (guix gexp) #:use-module (guix i18n) #:use-module (gnu services) #:use-module (gnu services shepherd) #:use-module (gnu system setuid) #:use-module (ice-9 match) #:use-module (srfi srfi-1)
aboutsummaryrefslogtreecommitdiff
blob: 460ff504cfe4cbd5f759511911a1aa2acdb32c63 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
regexp_simple: {
    input: {
        /rx/ig
    }
    expect_exact: "/rx/gi;"
}

regexp_slashes: {
    input: {
        /\\\/rx\/\\/ig
    }
    expect_exact: "/\\\\\\/rx\\/\\\\/gi;"
}

regexp_1: {
    input: {
        console.log(JSON.stringify("COMPASS? Overpass.".match(/([Sap]+)/ig)));
    }
    expect: {
        console.log(JSON.stringify("COMPASS? Overpass.".match(/([Sap]+)/gi)));
    }
    expect_stdout: '["PASS","pass"]'
}

regexp_2: {
    options = {
        evaluate: true,
        unsafe: true,
    }
    input: {
        console.log(JSON.stringify("COMPASS? Overpass.".match(new RegExp("([Sap]+)", "ig"))));
    }
    expect: {
        console.log(JSON.stringify("COMPASS? Overpass.".match(/([Sap]+)/gi)));
    }
    expect_stdout: '["PASS","pass"]'
}

regexp_properties: {
    options = {
        evaluate: true,
        unsafe: true,
    }
    input: {
        console.log(/abc/g.source, /abc/g.global, /abc/g.ignoreCase, /abc/g.lastIndex, /abc/g.multiline);
    }
    expect: {
        console.log("abc", true, false, /abc/g.lastIndex, false);
    }
    expect_stdout: "abc true false 0 false"
}

issue_3434_1: {
    options = {
        evaluate: true,
        unsafe: true,
    }
    beautify = {
        beautify: true,
    }
    input: {
        var o = {
            "\n": RegExp("\n"),
            "\r": RegExp("\r"),
            "\t": RegExp("\t"),
            "\b": RegExp("\b"),
            "\f": RegExp("\f"),
            "\0": RegExp("\0"),
            "\x0B": RegExp("\x0B"),
            "\u2028": RegExp("\u2028"),
            "\u2029": RegExp("\u2029"),
        };
        for (var c in o)
            console.log(o[c].test("\\"), o[c].test(c));
    }
    expect_exact: [
        "var o = {",
        '    "\\n": /\\n/,',
        '    "\\r": /\\r/,',
        '    "\\t": /\t/,',
        '    "\\b": /\b/,',
        '    "\\f": /\f/,',
        '    "\\0": /\0/,',
        '    "\\v": /\v/,',
        '    "\\u2028": /\\u2028/,',
        '    "\\u2029": /\\u2029/',
        "};",
        "",
        'for (var c in o) console.log(o[c].test("\\\\"), o[c].test(c));',
    ]
    expect_stdout: [
        "false true",
        "false true",
        "false true",
        "false true",
        "false true",
        "false true",
        "false true",
        "false true",
        "false true",
    ]
}

issue_3434_2: {
    options = {
        evaluate: true,
        unsafe: true,
    }
    beautify = {
        beautify: true,
    }
    input: {
        var o = {
            "\n": RegExp("\\\n"),
            "\r": RegExp("\\\r"),
            "\t": RegExp("\\\t"),
            "\b": RegExp("\\\b"),
            "\f": RegExp("\\\f"),
            "\0": RegExp("\\\0"),
            "\x0B": RegExp("\\\x0B"),
            "\u2028": RegExp("\\\u2028"),
            "\u2029": RegExp("\\\u2029"),
        };
        for (var c in o)
            console.log(o[c].test("\\"), o[c].test(c));
    }
    expect_exact: [
        "var o = {",
        '    "\\n": /\\n/,',
        '    "\\r": /\\r/,',
        '    "\\t": /\t/,',
        '    "\\b": /\b/,',
        '    "\\f": /\f/,',
        '    "\\0": /\0/,',
        '    "\\v": /\v/,',
        '    "\\u2028": /\\u2028/,',
        '    "\\u2029": /\\u2029/',
        "};",
        "",
        'for (var c in o) console.log(o[c].test("\\\\"), o[c].test(c));',
    ]
    expect_stdout: [
        "false true",
        "false true",
        "false true",
        "false true",
        "false true",
        "false true",
        "false true",
        "false true",
        "false true",
    ]
}

issue_3434_3: {
    options = {
        evaluate: true,
        unsafe: true,
    }
    input: {
        RegExp("\n");
        RegExp("\r");
        RegExp("\\n");
        RegExp("\\\n");
        RegExp("\\\\n");
        RegExp("\\\\\n");
        RegExp("\\\\\\n");
        RegExp("\\\\\\\n");
        RegExp("\u2028");
        RegExp("\u2029");
        RegExp("\n\r\u2028\u2029");
        RegExp("\\\nfo\n[\n]o\\bbb");
    }
    expect: {
        /\n/;
        /\r/;
        /\n/;
        /\n/;
        /\\n/;
        /\\\n/;
        /\\\n/;
        /\\\n/;
        /\u2028/;
        /\u2029/;
        /\n\r\u2028\u2029/;
        /\nfo\n[\n]o\bbb/;
    }
}
pam-extension make-pam-extension pam-extension? (transformer pam-extension-transformer) (shepherd-requirements pam-extension-shepherd-requirements (default '()))) ;; Overall PAM configuration: a list of services, plus a procedure that takes ;; one and returns a . The procedure is used to ;; implement cross-cutting concerns such as the use of the 'elogind.so' ;; session module that keeps track of logged-in users. (define-record-type* pam-configuration make-pam-configuration pam-configuration? ;list of (services pam-configuration-services) ;list of procedures -> (transformers pam-configuration-transformers) ;list of symbols (shepherd-requirements pam-configuration-shepherd-requirements)) (define (/etc-entry config) "Return the /etc/pam.d entry corresponding to CONFIG." (match config (($ services transformers shepherd-requirements) (let ((services (map (apply compose identity transformers) services))) `(("pam.d" ,(pam-services->directory services))))))) (define (pam-shepherd-service config) "Return the PAM synchronization shepherd service corresponding to CONFIG." (match config (($ services transformers shepherd-requirements) (list (shepherd-service (documentation "Synchronization point for services that need to be started for PAM to work.") (provision '(pam)) (requirement shepherd-requirements) (start #~(const #t)) (stop #~(const #f))))))) (define (extend-configuration initial extensions) "Extend INITIAL with NEW." ;; TODO: Remove deprecation shim. (define cleaned-extensions (map (lambda (ext) (if (procedure? ext) (begin (warning (G_ "'pam-root-service-type' extensions should \ now use the record~%")) (pam-extension (transformer ext))) ext)) extensions)) (let-values (((services pam-extensions) (partition pam-service? cleaned-extensions))) (pam-configuration (services (append (pam-configuration-services initial) services)) (transformers (append (pam-configuration-transformers initial) (map pam-extension-transformer pam-extensions))) (shepherd-requirements (append (pam-configuration-shepherd-requirements initial) (append-map pam-extension-shepherd-requirements pam-extensions)))))) (define pam-root-service-type (service-type (name 'pam) (extensions (list (service-extension setuid-program-service-type (lambda (_) (list (file-like->setuid-program (file-append linux-pam "/sbin/unix_chkpwd"))))) (service-extension etc-service-type /etc-entry) (service-extension shepherd-root-service-type pam-shepherd-service))) ;; Arguments include as well as procedures. (compose concatenate) (extend extend-configuration) (description "Configure the Pluggable Authentication Modules (PAM) for all the specified @dfn{PAM services}. Each PAM service corresponds to a program, such as @command{login} or @command{sshd}, and specifies for instance how the program may authenticate users or what it should do when opening a new session."))) (define* (pam-root-service base #:key (transformers '()) (shepherd-requirements '())) "The \"root\" PAM service, which collects instance and turns them into a /etc/pam.d directory, including the listed in BASE. TRANSFORM is a procedure that takes a and returns a . It can be used to implement cross-cutting concerns that affect all the PAM services." (service pam-root-service-type (pam-configuration (services base) (transformers transformers) (shepherd-requirements shepherd-requirements))))