• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 13877892945

15 Mar 2025 08:56PM UTC coverage: 71.915% (+0.2%) from 71.757%
13877892945

push

github

web-flow
Fix bootctl status to not print strange glyphs in logs (#36745)

146 of 198 new or added lines in 57 files covered. (73.74%)

153 existing lines in 28 files now uncovered.

296065 of 411690 relevant lines covered (71.91%)

715276.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.45
/src/firstboot/firstboot.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <fcntl.h>
4
#include <getopt.h>
5
#include <linux/loop.h>
6
#include <unistd.h>
7

8
#include "sd-id128.h"
9

10
#include "alloc-util.h"
11
#include "ask-password-api.h"
12
#include "build.h"
13
#include "bus-error.h"
14
#include "bus-locator.h"
15
#include "bus-unit-util.h"
16
#include "bus-util.h"
17
#include "bus-wait-for-jobs.h"
18
#include "chase.h"
19
#include "copy.h"
20
#include "creds-util.h"
21
#include "dissect-image.h"
22
#include "env-file.h"
23
#include "errno-util.h"
24
#include "fd-util.h"
25
#include "fileio.h"
26
#include "fs-util.h"
27
#include "glyph-util.h"
28
#include "hostname-util.h"
29
#include "kbd-util.h"
30
#include "libcrypt-util.h"
31
#include "locale-util.h"
32
#include "lock-util.h"
33
#include "main-func.h"
34
#include "memory-util.h"
35
#include "mkdir.h"
36
#include "mount-util.h"
37
#include "os-util.h"
38
#include "parse-argument.h"
39
#include "parse-util.h"
40
#include "password-quality-util.h"
41
#include "path-util.h"
42
#include "pretty-print.h"
43
#include "proc-cmdline.h"
44
#include "random-util.h"
45
#include "smack-util.h"
46
#include "string-util.h"
47
#include "strv.h"
48
#include "terminal-util.h"
49
#include "time-util.h"
50
#include "tmpfile-util-label.h"
51
#include "tmpfile-util.h"
52
#include "umask-util.h"
53
#include "user-util.h"
54
#include "vconsole-util.h"
55

56
static char *arg_root = NULL;
57
static char *arg_image = NULL;
58
static char *arg_locale = NULL;  /* $LANG */
59
static char *arg_locale_messages = NULL; /* $LC_MESSAGES */
60
static char *arg_keymap = NULL;
61
static char *arg_timezone = NULL;
62
static char *arg_hostname = NULL;
63
static sd_id128_t arg_machine_id = {};
64
static char *arg_root_password = NULL;
65
static char *arg_root_shell = NULL;
66
static char *arg_kernel_cmdline = NULL;
67
static bool arg_prompt_locale = false;
68
static bool arg_prompt_keymap = false;
69
static bool arg_prompt_timezone = false;
70
static bool arg_prompt_hostname = false;
71
static bool arg_prompt_root_password = false;
72
static bool arg_prompt_root_shell = false;
73
static bool arg_copy_locale = false;
74
static bool arg_copy_keymap = false;
75
static bool arg_copy_timezone = false;
76
static bool arg_copy_root_password = false;
77
static bool arg_copy_root_shell = false;
78
static bool arg_force = false;
79
static bool arg_delete_root_password = false;
80
static bool arg_root_password_is_hashed = false;
81
static bool arg_welcome = true;
82
static bool arg_reset = false;
83
static ImagePolicy *arg_image_policy = NULL;
84

85
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
136✔
86
STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
136✔
87
STATIC_DESTRUCTOR_REGISTER(arg_locale, freep);
136✔
88
STATIC_DESTRUCTOR_REGISTER(arg_locale_messages, freep);
136✔
89
STATIC_DESTRUCTOR_REGISTER(arg_keymap, freep);
136✔
90
STATIC_DESTRUCTOR_REGISTER(arg_timezone, freep);
136✔
91
STATIC_DESTRUCTOR_REGISTER(arg_hostname, freep);
136✔
92
STATIC_DESTRUCTOR_REGISTER(arg_root_password, erase_and_freep);
136✔
93
STATIC_DESTRUCTOR_REGISTER(arg_root_shell, freep);
136✔
94
STATIC_DESTRUCTOR_REGISTER(arg_kernel_cmdline, freep);
136✔
95
STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
136✔
96

97
static void print_welcome(int rfd) {
7✔
98
        _cleanup_free_ char *pretty_name = NULL, *os_name = NULL, *ansi_color = NULL;
7✔
99
        static bool done = false;
7✔
100
        const char *pn, *ac;
7✔
101
        int r;
7✔
102

103
        assert(rfd >= 0);
7✔
104

105
        if (!arg_welcome)
7✔
106
                return;
107

108
        if (done) {
6✔
109
                putchar('\n'); /* Add some breathing room between multiple prompts */
1✔
110
                return;
111
        }
112

113
        r = parse_os_release_at(rfd,
6✔
114
                                "PRETTY_NAME", &pretty_name,
115
                                "NAME", &os_name,
116
                                "ANSI_COLOR", &ansi_color);
117
        if (r < 0)
6✔
118
                log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
6✔
119
                               "Failed to read os-release file, ignoring: %m");
120

121
        pn = os_release_pretty_name(pretty_name, os_name);
6✔
122
        ac = isempty(ansi_color) ? "0" : ansi_color;
6✔
123

124
        (void) terminal_reset_defensive_locked(STDOUT_FILENO, /* flags= */ 0);
6✔
125

126
        if (colors_enabled())
6✔
127
                printf("\n"
×
128
                       ANSI_HIGHLIGHT "Welcome to your new installation of " ANSI_NORMAL "\x1B[%sm%s" ANSI_HIGHLIGHT "!" ANSI_NORMAL "\n", ac, pn);
129
        else
130
                printf("\nWelcome to your new installation of %s!\n", pn);
6✔
131

132
        putchar('\n');
6✔
133
        if (emoji_enabled()) {
6✔
NEW
134
                fputs(glyph(GLYPH_SPARKLES), stdout);
×
135
                putchar(' ');
×
136
        }
137
        printf("Please configure your new system!\n");
6✔
138

139
        any_key_to_proceed();
6✔
140

141
        done = true;
6✔
142
}
143

144
static int get_completions(
×
145
                const char *key,
146
                char ***ret_list,
147
                void *userdata) {
148

149
        int r;
×
150

151
        if (!userdata) {
×
152
                *ret_list = NULL;
×
153
                return 0;
×
154
        }
155

156
        _cleanup_strv_free_ char **copy = strv_copy(userdata);
×
157
        if (!copy)
×
158
                return -ENOMEM;
159

160
        r = strv_extend(&copy, "list");
×
161
        if (r < 0)
×
162
                return r;
163

164
        *ret_list = TAKE_PTR(copy);
×
165
        return 0;
×
166
}
167

168
static int prompt_loop(
7✔
169
                int rfd,
170
                const char *text,
171
                char **l,
172
                unsigned ellipsize_percentage,
173
                bool (*is_valid)(int rfd, const char *name),
174
                char **ret) {
175

176
        int r;
7✔
177

178
        assert(text);
7✔
179
        assert(is_valid);
7✔
180
        assert(ret);
7✔
181

182
        for (;;) {
7✔
183
                _cleanup_free_ char *p = NULL;
7✔
184

185
                r = ask_string_full(
7✔
186
                                &p,
187
                                get_completions,
188
                                l,
189
                                strv_isempty(l) ? "%s %s (empty to skip): "
7✔
190
                                                : "%s %s (empty to skip, \"list\" to list options): ",
191
                                glyph(GLYPH_TRIANGULAR_BULLET), text);
192
                if (r < 0)
7✔
193
                        return log_error_errno(r, "Failed to query user: %m");
×
194

195
                if (isempty(p)) {
7✔
196
                        log_info("No data entered, skipping.");
×
197
                        return 0;
×
198
                }
199

200
                if (!strv_isempty(l)) {
7✔
201
                        if (streq(p, "list")) {
4✔
202
                                r = show_menu(l,
×
203
                                              /* n_columns= */ 3,
204
                                              /* column_width= */ 20,
205
                                              ellipsize_percentage,
206
                                              /* grey_prefix= */ NULL,
207
                                              /* with_numbers= */ true);
208
                                if (r < 0)
×
209
                                        return log_error_errno(r, "Failed to show menu: %m");
×
210

211
                                putchar('\n');
×
212
                                continue;
×
213
                        }
214

215
                        unsigned u;
4✔
216
                        r = safe_atou(p, &u);
4✔
217
                        if (r >= 0) {
4✔
218
                                if (u <= 0 || u > strv_length(l)) {
×
219
                                        log_error("Specified entry number out of range.");
×
220
                                        continue;
×
221
                                }
222

223
                                log_info("Selected '%s'.", l[u-1]);
×
224
                                return free_and_strdup_warn(ret, l[u-1]);
×
225
                        }
226
                }
227

228
                if (is_valid(rfd, p))
7✔
229
                        return free_and_replace(*ret, p);
7✔
230

231
                /* Be more helpful to the user, and give a hint what the user might have wanted to type. */
232
                const char *best_match = strv_find_closest(l, p);
×
233
                if (best_match)
×
234
                        log_error("Invalid data '%s', did you mean '%s'?", p, best_match);
×
235
                else
236
                        log_error("Invalid data '%s'.", p);
×
237
        }
238
}
239

240
static int should_configure(int dir_fd, const char *filename) {
1,064✔
241
        _cleanup_fclose_ FILE *passwd = NULL, *shadow = NULL;
1,064✔
242
        int r;
1,064✔
243

244
        assert(dir_fd >= 0);
1,064✔
245
        assert(filename);
1,064✔
246

247
        if (streq(filename, "passwd") && !arg_force)
1,064✔
248
                /* We may need to do additional checks, so open the file. */
249
                r = xfopenat(dir_fd, filename, "re", O_NOFOLLOW, &passwd);
131✔
250
        else
251
                r = RET_NERRNO(faccessat(dir_fd, filename, F_OK, AT_SYMLINK_NOFOLLOW));
933✔
252

253
        if (r == -ENOENT)
517✔
254
                return true; /* missing */
255
        if (r < 0)
655✔
256
                return log_error_errno(r, "Failed to access %s: %m", filename);
×
257
        if (arg_force)
655✔
258
                return true; /* exists, but if --force was given we should still configure the file. */
259

260
        if (!passwd)
641✔
261
                return false;
262

263
        /* In case of /etc/passwd, do an additional check for the root password field.
264
         * We first check that passwd redirects to shadow, and then we check shadow.
265
         */
266
        struct passwd *i;
267
        while ((r = fgetpwent_sane(passwd, &i)) > 0) {
108✔
268
                if (!streq(i->pw_name, "root"))
107✔
269
                        continue;
×
270

271
                if (streq_ptr(i->pw_passwd, PASSWORD_SEE_SHADOW))
107✔
272
                        break;
273
                log_debug("passwd: root account with non-shadow password found, treating root as configured");
×
274
                return false;
275
        }
276
        if (r < 0)
108✔
277
                return log_error_errno(r, "Failed to read %s: %m", filename);
×
278
        if (r == 0) {
108✔
279
                log_debug("No root account found in %s, assuming root is not configured.", filename);
1✔
280
                return true;
1✔
281
        }
282

283
        r = xfopenat(dir_fd, "shadow", "re", O_NOFOLLOW, &shadow);
107✔
284
        if (r == -ENOENT) {
107✔
285
                log_debug("No shadow file found, assuming root is not configured.");
×
286
                return true; /* missing */
×
287
        }
288
        if (r < 0)
107✔
289
                return log_error_errno(r, "Failed to access shadow: %m");
×
290

291
        struct spwd *j;
292
        while ((r = fgetspent_sane(shadow, &j)) > 0) {
107✔
293
                if (!streq(j->sp_namp, "root"))
107✔
294
                        continue;
×
295

296
                bool unprovisioned = streq_ptr(j->sp_pwdp, PASSWORD_UNPROVISIONED);
107✔
297
                log_debug("Root account found, %s.",
208✔
298
                          unprovisioned ? "with unprovisioned password, treating root as not configured" :
299
                                          "treating root as configured");
300
                return unprovisioned;
107✔
301
        }
302
        if (r < 0)
×
303
                return log_error_errno(r, "Failed to read shadow: %m");
×
304
        assert(r == 0);
×
305
        log_debug("No root account found in shadow, assuming root is not configured.");
1,064✔
306
        return true;
307
}
308

309
static bool locale_is_installed_bool(const char *name) {
×
310
        return locale_is_installed(name) > 0;
×
311
}
312

313
static bool locale_is_ok(int rfd, const char *name) {
10✔
314
        int r;
10✔
315

316
        assert(rfd >= 0);
10✔
317

318
        r = dir_fd_is_root(rfd);
10✔
319
        if (r < 0)
10✔
320
                log_debug_errno(r, "Unable to determine if operating on host root directory, assuming we are: %m");
×
321

322
        return r != 0 ? locale_is_installed_bool(name) : locale_is_valid(name);
10✔
323
}
324

325
static int prompt_locale(int rfd) {
10✔
326
        _cleanup_strv_free_ char **locales = NULL;
×
327
        bool acquired_from_creds = false;
10✔
328
        int r;
10✔
329

330
        assert(rfd >= 0);
10✔
331

332
        if (arg_locale || arg_locale_messages)
10✔
333
                return 0;
334

335
        r = read_credential("firstboot.locale", (void**) &arg_locale, NULL);
6✔
336
        if (r < 0)
6✔
337
                log_debug_errno(r, "Failed to read credential firstboot.locale, ignoring: %m");
5✔
338
        else
339
                acquired_from_creds = true;
340

341
        r = read_credential("firstboot.locale-messages", (void**) &arg_locale_messages, NULL);
6✔
342
        if (r < 0)
6✔
343
                log_debug_errno(r, "Failed to read credential firstboot.locale-messages, ignoring: %m");
5✔
344
        else
345
                acquired_from_creds = true;
346

347
        if (acquired_from_creds) {
5✔
348
                log_debug("Acquired locale from credentials.");
1✔
349
                return 0;
1✔
350
        }
351

352
        if (!arg_prompt_locale) {
5✔
353
                log_debug("Prompting for locale was not requested.");
4✔
354
                return 0;
4✔
355
        }
356

357
        r = get_locales(&locales);
1✔
358
        if (r < 0)
1✔
359
                return log_error_errno(r, "Cannot query locales list: %m");
×
360

361
        if (strv_isempty(locales))
1✔
362
                log_debug("No locales found, skipping locale selection.");
×
363
        else if (strv_length(locales) == 1) {
1✔
364

365
                if (streq(locales[0], SYSTEMD_DEFAULT_LOCALE))
×
366
                        log_debug("Only installed locale is default locale anyway, not setting locale explicitly.");
×
367
                else {
368
                        log_debug("Only a single locale available (%s), selecting it as default.", locales[0]);
×
369

370
                        arg_locale = strdup(locales[0]);
×
371
                        if (!arg_locale)
×
372
                                return log_oom();
×
373

374
                        /* Not setting arg_locale_message here, since it defaults to LANG anyway */
375
                }
376
        } else {
377
                print_welcome(rfd);
1✔
378

379
                r = prompt_loop(rfd, "Please enter the new system locale name or number",
1✔
380
                                locales, 60, locale_is_ok, &arg_locale);
381
                if (r < 0)
1✔
382
                        return r;
383

384
                if (isempty(arg_locale))
11✔
385
                        return 0;
386

387
                r = prompt_loop(rfd, "Please enter the new system message locale name or number",
1✔
388
                                locales, 60, locale_is_ok, &arg_locale_messages);
389
                if (r < 0)
1✔
390
                        return r;
391

392
                /* Suppress the messages setting if it's the same as the main locale anyway */
393
                if (streq_ptr(arg_locale, arg_locale_messages))
1✔
394
                        arg_locale_messages = mfree(arg_locale_messages);
×
395
        }
396

397
        return 0;
398
}
399

400
static int process_locale(int rfd) {
133✔
401
        _cleanup_close_ int pfd = -EBADF;
133✔
402
        _cleanup_free_ char *f = NULL;
133✔
403
        char* locales[3];
133✔
404
        unsigned i = 0;
133✔
405
        int r;
133✔
406

407
        assert(rfd >= 0);
133✔
408

409
        pfd = chase_and_open_parent_at(rfd, "/etc/locale.conf",
133✔
410
                                       CHASE_AT_RESOLVE_IN_ROOT|CHASE_MKDIR_0755|CHASE_WARN|CHASE_NOFOLLOW,
411
                                       &f);
412
        if (pfd < 0)
133✔
413
                return log_error_errno(pfd, "Failed to chase /etc/locale.conf: %m");
×
414

415
        r = should_configure(pfd, f);
133✔
416
        if (r == 0)
133✔
417
                log_debug("Found /etc/locale.conf, assuming locale information has been configured.");
121✔
418
        if (r <= 0)
133✔
419
                return r;
420

421
        r = dir_fd_is_root(rfd);
12✔
422
        if (r < 0)
12✔
423
                return log_error_errno(r, "Failed to check if directory file descriptor is root: %m");
×
424

425
        if (arg_copy_locale && r == 0) {
12✔
426
                r = copy_file_atomic_at(AT_FDCWD, "/etc/locale.conf", pfd, f, 0644, COPY_REFLINK);
2✔
427
                if (r != -ENOENT) {
2✔
428
                        if (r < 0)
2✔
429
                                return log_error_errno(r, "Failed to copy host's /etc/locale.conf: %m");
×
430

431
                        log_info("Copied host's /etc/locale.conf.");
2✔
432
                        return 0;
2✔
433
                }
434
        }
435

436
        r = prompt_locale(rfd);
10✔
437
        if (r < 0)
10✔
438
                return r;
439

440
        if (!isempty(arg_locale))
10✔
441
                locales[i++] = strjoina("LANG=", arg_locale);
25✔
442
        if (!isempty(arg_locale_messages) && !streq_ptr(arg_locale_messages, arg_locale))
15✔
443
                locales[i++] = strjoina("LC_MESSAGES=", arg_locale_messages);
25✔
444

445
        if (i == 0)
10✔
446
                return 0;
447

448
        locales[i] = NULL;
6✔
449

450
        r = write_env_file(pfd, f, NULL, locales);
6✔
451
        if (r < 0)
6✔
452
                return log_error_errno(r, "Failed to write /etc/locale.conf: %m");
×
453

454
        log_info("/etc/locale.conf written.");
133✔
455
        return 1;
456
}
457

458
static bool keymap_exists_bool(const char *name) {
×
459
        return keymap_exists(name) > 0;
×
460
}
461

462
static bool keymap_is_ok(int rfd, const char* name) {
4✔
463
        int r;
4✔
464

465
        assert(rfd >= 0);
4✔
466

467
        r = dir_fd_is_root(rfd);
4✔
468
        if (r < 0)
4✔
469
                log_debug_errno(r, "Unable to determine if operating on host root directory, assuming we are: %m");
×
470

471
        return r != 0 ? keymap_exists_bool(name) : keymap_is_valid(name);
4✔
472
}
473

474
static int prompt_keymap(int rfd) {
12✔
475
        _cleanup_strv_free_ char **kmaps = NULL;
12✔
476
        int r;
12✔
477

478
        assert(rfd >= 0);
12✔
479

480
        if (arg_keymap)
12✔
481
                return 0;
482

483
        r = read_credential("firstboot.keymap", (void**) &arg_keymap, NULL);
10✔
484
        if (r < 0)
10✔
485
                log_debug_errno(r, "Failed to read credential firstboot.keymap, ignoring: %m");
9✔
486
        else {
487
                log_debug("Acquired keymap from credential.");
1✔
488
                return 0;
1✔
489
        }
490

491
        if (!arg_prompt_keymap) {
9✔
492
                log_debug("Prompting for keymap was not requested.");
8✔
493
                return 0;
8✔
494
        }
495

496
        r = get_keymaps(&kmaps);
1✔
497
        if (r == -ENOENT) /* no keymaps installed */
1✔
498
                return log_debug_errno(r, "No keymaps are installed.");
×
499
        if (r < 0)
1✔
500
                return log_error_errno(r, "Failed to read keymaps: %m");
×
501

502
        print_welcome(rfd);
1✔
503

504
        return prompt_loop(rfd, "Please enter the new keymap name or number",
1✔
505
                           kmaps, 60, keymap_is_ok, &arg_keymap);
506
}
507

508
static int process_keymap(int rfd) {
133✔
509
        _cleanup_close_ int pfd = -EBADF;
133✔
510
        _cleanup_free_ char *f = NULL;
133✔
511
        _cleanup_strv_free_ char **keymap = NULL;
×
512
        int r;
133✔
513

514
        assert(rfd >= 0);
133✔
515

516
        pfd = chase_and_open_parent_at(rfd, "/etc/vconsole.conf",
133✔
517
                                       CHASE_AT_RESOLVE_IN_ROOT|CHASE_MKDIR_0755|CHASE_WARN|CHASE_NOFOLLOW,
518
                                       &f);
519
        if (pfd < 0)
133✔
520
                return log_error_errno(pfd, "Failed to chase /etc/vconsole.conf: %m");
×
521

522
        r = should_configure(pfd, f);
133✔
523
        if (r == 0)
133✔
524
                log_debug("Found /etc/vconsole.conf, assuming console has been configured.");
119✔
525
        if (r <= 0)
133✔
526
                return r;
527

528
        r = dir_fd_is_root(rfd);
14✔
529
        if (r < 0)
14✔
530
                return log_error_errno(r, "Failed to check if directory file descriptor is root: %m");
×
531

532
        if (arg_copy_keymap && r == 0) {
14✔
533
                r = copy_file_atomic_at(AT_FDCWD, "/etc/vconsole.conf", pfd, f, 0644, COPY_REFLINK);
2✔
534
                if (r != -ENOENT) {
2✔
535
                        if (r < 0)
2✔
536
                                return log_error_errno(r, "Failed to copy host's /etc/vconsole.conf: %m");
×
537

538
                        log_info("Copied host's /etc/vconsole.conf.");
2✔
539
                        return 0;
2✔
540
                }
541
        }
542

543
        r = prompt_keymap(rfd);
12✔
544
        if (r == -ENOENT)
12✔
545
                return 0; /* don't fail if no keymaps are installed */
546
        if (r < 0)
12✔
547
                return r;
548

549
        if (isempty(arg_keymap))
137✔
550
                return 0;
551

552
        VCContext vc = {
4✔
553
                .keymap = arg_keymap,
554
        };
555
        _cleanup_(x11_context_clear) X11Context xc = {};
×
556

557
        r = vconsole_convert_to_x11(&vc, /* verify= */ NULL, &xc);
4✔
558
        if (r < 0)
4✔
559
                return log_error_errno(r, "Failed to convert keymap data: %m");
×
560

561
        r = vconsole_serialize(&vc, &xc, &keymap);
4✔
562
        if (r < 0)
4✔
563
                return log_error_errno(r, "Failed to serialize keymap data: %m");
×
564

565
        r = write_vconsole_conf(pfd, f, keymap);
4✔
566
        if (r < 0)
4✔
567
                return log_error_errno(r, "Failed to write /etc/vconsole.conf: %m");
×
568

569
        log_info("/etc/vconsole.conf written.");
4✔
570
        return 1;
571
}
572

573
static bool timezone_is_ok(int rfd, const char *name) {
1✔
574
        assert(rfd >= 0);
1✔
575

576
        return timezone_is_valid(name, LOG_DEBUG);
1✔
577
}
578

579
static int prompt_timezone(int rfd) {
72✔
580
        _cleanup_strv_free_ char **zones = NULL;
72✔
581
        int r;
72✔
582

583
        assert(rfd >= 0);
72✔
584

585
        if (arg_timezone)
72✔
586
                return 0;
587

588
        r = read_credential("firstboot.timezone", (void**) &arg_timezone, NULL);
70✔
589
        if (r < 0)
70✔
590
                log_debug_errno(r, "Failed to read credential firstboot.timezone, ignoring: %m");
11✔
591
        else {
592
                log_debug("Acquired timezone from credential.");
59✔
593
                return 0;
59✔
594
        }
595

596
        if (!arg_prompt_timezone) {
11✔
597
                log_debug("Prompting for timezone was not requested.");
10✔
598
                return 0;
10✔
599
        }
600

601
        r = get_timezones(&zones);
1✔
602
        if (r < 0)
1✔
603
                return log_error_errno(r, "Cannot query timezone list: %m");
×
604

605
        print_welcome(rfd);
1✔
606

607
        return prompt_loop(rfd, "Please enter the new timezone name or number",
1✔
608
                           zones, 30, timezone_is_ok, &arg_timezone);
609
}
610

611
static int process_timezone(int rfd) {
133✔
612
        _cleanup_close_ int pfd = -EBADF;
133✔
613
        _cleanup_free_ char *f = NULL;
133✔
614
        const char *e;
133✔
615
        int r;
133✔
616

617
        assert(rfd >= 0);
133✔
618

619
        pfd = chase_and_open_parent_at(rfd, "/etc/localtime",
133✔
620
                                       CHASE_AT_RESOLVE_IN_ROOT|CHASE_MKDIR_0755|CHASE_WARN|CHASE_NOFOLLOW,
621
                                       &f);
622
        if (pfd < 0)
133✔
623
                return log_error_errno(pfd, "Failed to chase /etc/localtime: %m");
×
624

625
        r = should_configure(pfd, f);
133✔
626
        if (r == 0)
133✔
627
                log_debug("Found /etc/localtime, assuming timezone has been configured.");
59✔
628
        if (r <= 0)
133✔
629
                return r;
630

631
        r = dir_fd_is_root(rfd);
74✔
632
        if (r < 0)
74✔
633
                return log_error_errno(r, "Failed to check if directory file descriptor is root: %m");
×
634

635
        if (arg_copy_timezone && r == 0) {
74✔
636
                _cleanup_free_ char *s = NULL;
2✔
637

638
                r = readlink_malloc("/etc/localtime", &s);
2✔
639
                if (r != -ENOENT) {
2✔
640
                        if (r < 0)
2✔
641
                                return log_error_errno(r, "Failed to read host's /etc/localtime: %m");
×
642

643
                        r = symlinkat_atomic_full(s, pfd, f, /* make_relative= */ false);
2✔
644
                        if (r < 0)
2✔
645
                                return log_error_errno(r, "Failed to create /etc/localtime symlink: %m");
×
646

647
                        log_info("Copied host's /etc/localtime.");
2✔
648
                        return 0;
2✔
649
                }
650
        }
651

652
        r = prompt_timezone(rfd);
72✔
653
        if (r < 0)
72✔
654
                return r;
655

656
        if (isempty(arg_timezone))
72✔
657
                return 0;
658

659
        e = strjoina("../usr/share/zoneinfo/", arg_timezone);
310✔
660

661
        r = symlinkat_atomic_full(e, pfd, f, /* make_relative= */ false);
62✔
662
        if (r < 0)
62✔
663
                return log_error_errno(r, "Failed to create /etc/localtime symlink: %m");
×
664

665
        log_info("/etc/localtime written");
133✔
666
        return 0;
667
}
668

669
static bool hostname_is_ok(int rfd, const char *name) {
1✔
670
        assert(rfd >= 0);
1✔
671

672
        return hostname_is_valid(name, VALID_HOSTNAME_TRAILING_DOT);
1✔
673
}
674

675
static int prompt_hostname(int rfd) {
119✔
676
        int r;
119✔
677

678
        assert(rfd >= 0);
119✔
679

680
        if (arg_hostname)
119✔
681
                return 0;
682

683
        if (!arg_prompt_hostname) {
117✔
684
                log_debug("Prompting for hostname was not requested.");
116✔
685
                return 0;
116✔
686
        }
687

688
        print_welcome(rfd);
1✔
689

690
        r = prompt_loop(rfd, "Please enter the new hostname",
1✔
691
                        NULL, 0, hostname_is_ok, &arg_hostname);
692
        if (r < 0)
1✔
693
                return r;
694

695
        if (arg_hostname)
1✔
696
                hostname_cleanup(arg_hostname);
1✔
697

698
        return 0;
699
}
700

701
static int process_hostname(int rfd) {
133✔
702
        _cleanup_close_ int pfd = -EBADF;
133✔
703
        _cleanup_free_ char *f = NULL;
133✔
704
        int r;
133✔
705

706
        assert(rfd >= 0);
133✔
707

708
        pfd = chase_and_open_parent_at(rfd, "/etc/hostname",
133✔
709
                                       CHASE_AT_RESOLVE_IN_ROOT|CHASE_MKDIR_0755|CHASE_WARN,
710
                                       &f);
711
        if (pfd < 0)
133✔
712
                return log_error_errno(pfd, "Failed to chase /etc/hostname: %m");
×
713

714
        r = should_configure(pfd, f);
133✔
715
        if (r == 0)
133✔
716
                log_debug("Found /etc/hostname, assuming hostname has been configured.");
14✔
717
        if (r <= 0)
133✔
718
                return r;
719

720
        r = prompt_hostname(rfd);
119✔
721
        if (r < 0)
119✔
722
                return r;
723

724
        if (isempty(arg_hostname))
119✔
725
                return 0;
726

727
        r = write_string_file_at(pfd, f, arg_hostname,
3✔
728
                                 WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_SYNC|WRITE_STRING_FILE_ATOMIC);
729
        if (r < 0)
3✔
730
                return log_error_errno(r, "Failed to write /etc/hostname: %m");
×
731

732
        log_info("/etc/hostname written.");
133✔
733
        return 0;
734
}
735

736
static int process_machine_id(int rfd) {
133✔
737
        _cleanup_close_ int pfd = -EBADF;
133✔
738
        _cleanup_free_ char *f = NULL;
133✔
739
        int r;
133✔
740

741
        assert(rfd >= 0);
133✔
742

743
        pfd = chase_and_open_parent_at(rfd, "/etc/machine-id",
133✔
744
                                       CHASE_AT_RESOLVE_IN_ROOT|CHASE_MKDIR_0755|CHASE_WARN|CHASE_NOFOLLOW,
745
                                       &f);
746
        if (pfd < 0)
133✔
747
                return log_error_errno(pfd, "Failed to chase /etc/machine-id: %m");
×
748

749
        r = should_configure(pfd, f);
133✔
750
        if (r == 0)
133✔
751
                log_debug("Found /etc/machine-id, assuming machine-id has been configured.");
111✔
752
        if (r <= 0)
133✔
753
                return r;
754

755
        if (sd_id128_is_null(arg_machine_id)) {
22✔
756
                log_debug("Initialization of machine-id was not requested, skipping.");
19✔
757
                return 0;
19✔
758
        }
759

760
        r = write_string_file_at(pfd, "machine-id", SD_ID128_TO_STRING(arg_machine_id),
3✔
761
                                 WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_SYNC|WRITE_STRING_FILE_ATOMIC);
762
        if (r < 0)
3✔
763
                return log_error_errno(r, "Failed to write /etc/machine-id: %m");
×
764

765
        log_info("/etc/machine-id written.");
133✔
766
        return 0;
767
}
768

769
static int prompt_root_password(int rfd) {
27✔
770
        const char *msg1, *msg2;
27✔
771
        int r;
27✔
772

773
        assert(rfd >= 0);
27✔
774

775
        if (arg_root_password)
27✔
776
                return 0;
777

778
        if (get_credential_user_password("root", &arg_root_password, &arg_root_password_is_hashed) >= 0)
18✔
779
                return 0;
780

781
        if (!arg_prompt_root_password) {
17✔
782
                log_debug("Prompting for root password was not requested.");
16✔
783
                return 0;
16✔
784
        }
785

786
        print_welcome(rfd);
1✔
787

788
        msg1 = strjoina(glyph(GLYPH_TRIANGULAR_BULLET), " Please enter the new root password (empty to skip):");
5✔
789
        msg2 = strjoina(glyph(GLYPH_TRIANGULAR_BULLET), " Please enter the new root password again:");
5✔
790

791
        suggest_passwords();
1✔
792

793
        for (;;) {
×
794
                _cleanup_strv_free_erase_ char **a = NULL, **b = NULL;
1✔
795
                _cleanup_free_ char *error = NULL;
1✔
796

797
                AskPasswordRequest req = {
1✔
798
                        .tty_fd = -EBADF,
799
                        .message = msg1,
800
                        .until = USEC_INFINITY,
801
                        .hup_fd = -EBADF,
802
                };
803

804
                r = ask_password_tty(&req, /* flags= */ 0, &a);
1✔
805
                if (r < 0)
1✔
806
                        return log_error_errno(r, "Failed to query root password: %m");
×
807
                if (strv_length(a) != 1)
1✔
808
                        return log_error_errno(SYNTHETIC_ERRNO(EIO),
×
809
                                               "Received multiple passwords, where we expected one.");
810

811
                if (isempty(*a)) {
1✔
812
                        log_info("No password entered, skipping.");
1✔
813
                        break;
814
                }
815

816
                r = check_password_quality(*a, /* old */ NULL, "root", &error);
×
817
                if (ERRNO_IS_NEG_NOT_SUPPORTED(r))
×
818
                        log_warning("Password quality check is not supported, proceeding anyway.");
×
819
                else if (r < 0)
×
820
                        return log_error_errno(r, "Failed to check password quality: %m");
×
821
                else if (r == 0)
×
822
                        log_warning("Password is weak, accepting anyway: %s", error);
×
823

824
                req.message = msg2;
×
825

826
                r = ask_password_tty(&req, /* flags= */ 0, &b);
×
827
                if (r < 0)
×
828
                        return log_error_errno(r, "Failed to query root password: %m");
×
829
                if (strv_length(b) != 1)
×
830
                        return log_error_errno(SYNTHETIC_ERRNO(EIO),
×
831
                                               "Received multiple passwords, where we expected one.");
832

833
                if (!streq(*a, *b)) {
×
834
                        log_error("Entered passwords did not match, please try again.");
×
835
                        continue;
×
836
                }
837

838
                arg_root_password = TAKE_PTR(*a);
×
839
                break;
×
840
        }
841

842
        return 0;
1✔
843
}
844

845
static int find_shell(int rfd, const char *path) {
7✔
846
        int r;
7✔
847

848
        assert(path);
7✔
849

850
        if (!valid_shell(path))
7✔
851
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "%s is not a valid shell", path);
×
852

853
        r = chaseat(rfd, path, CHASE_AT_RESOLVE_IN_ROOT, NULL, NULL);
7✔
854
        if (r < 0)
7✔
855
                return log_error_errno(r, "Failed to resolve shell %s: %m", path);
1✔
856

857
        return 0;
858
}
859

860
static bool shell_is_ok(int rfd, const char *path) {
2✔
861
        assert(rfd >= 0);
2✔
862

863
        return find_shell(rfd, path) >= 0;
2✔
864
}
865

866
static int prompt_root_shell(int rfd) {
27✔
867
        int r;
27✔
868

869
        assert(rfd >= 0);
27✔
870

871
        if (arg_root_shell)
27✔
872
                return 0;
873

874
        r = read_credential("passwd.shell.root", (void**) &arg_root_shell, NULL);
22✔
875
        if (r < 0)
22✔
876
                log_debug_errno(r, "Failed to read credential passwd.shell.root, ignoring: %m");
21✔
877
        else {
878
                log_debug("Acquired root shell from credential.");
1✔
879
                return 0;
1✔
880
        }
881

882
        if (!arg_prompt_root_shell) {
21✔
883
                log_debug("Prompting for root shell was not requested.");
19✔
884
                return 0;
19✔
885
        }
886

887
        print_welcome(rfd);
2✔
888

889
        return prompt_loop(rfd, "Please enter the new root shell",
2✔
890
                           NULL, 0, shell_is_ok, &arg_root_shell);
891
}
892

893
static int write_root_passwd(int rfd, int etc_fd, const char *password, const char *shell) {
15✔
894
        _cleanup_fclose_ FILE *original = NULL, *passwd = NULL;
15✔
895
        _cleanup_(unlink_and_freep) char *passwd_tmp = NULL;
15✔
896
        int r;
15✔
897
        bool found = false;
15✔
898

899
        r = fopen_temporary_at_label(etc_fd, "passwd", "passwd", &passwd, &passwd_tmp);
15✔
900
        if (r < 0)
15✔
901
                return r;
902

903
        r = xfopenat(etc_fd, "passwd", "re", O_NOFOLLOW, &original);
15✔
904
        if (r < 0 && r != -ENOENT)
15✔
905
                return r;
906

907
        if (original) {
15✔
908
                struct passwd *i;
4✔
909

910
                r = copy_rights(fileno(original), fileno(passwd));
4✔
911
                if (r < 0)
4✔
912
                        return r;
×
913

914
                while ((r = fgetpwent_sane(original, &i)) > 0) {
7✔
915

916
                        if (streq(i->pw_name, "root")) {
3✔
917
                                if (password)
3✔
918
                                        i->pw_passwd = (char *) password;
2✔
919
                                if (shell)
3✔
920
                                        i->pw_shell = (char *) shell;
2✔
921
                                found = true;
922
                        }
923

924
                        r = putpwent_sane(i, passwd);
3✔
925
                        if (r < 0)
3✔
926
                                return r;
927
                }
928
                if (r < 0)
4✔
929
                        return r;
930

931
        } else {
932
                r = fchmod(fileno(passwd), 0644);
11✔
933
                if (r < 0)
11✔
934
                        return -errno;
×
935
        }
936

937
        if (!found) {
4✔
938
                struct passwd root = {
12✔
939
                        .pw_name = (char *) "root",
940
                        .pw_passwd = (char *) (password ?: PASSWORD_SEE_SHADOW),
12✔
941
                        .pw_uid = 0,
942
                        .pw_gid = 0,
943
                        .pw_gecos = (char *) "Super User",
944
                        .pw_dir = (char *) "/root",
945
                        .pw_shell = (char *) (shell ?: default_root_shell_at(rfd)),
6✔
946
                };
947

948
                if (errno != ENOENT)
12✔
949
                        return -errno;
×
950

951
                r = putpwent_sane(&root, passwd);
12✔
952
                if (r < 0)
12✔
953
                        return r;
954
        }
955

956
        r = fflush_sync_and_check(passwd);
15✔
957
        if (r < 0)
15✔
958
                return r;
959

960
        r = renameat_and_apply_smack_floor_label(etc_fd, passwd_tmp, etc_fd, "passwd");
15✔
961
        if (r < 0)
15✔
962
                return r;
×
963

964
        return 0;
965
}
966

967
static int write_root_shadow(int etc_fd, const char *hashed_password) {
15✔
968
        _cleanup_fclose_ FILE *original = NULL, *shadow = NULL;
15✔
969
        _cleanup_(unlink_and_freep) char *shadow_tmp = NULL;
15✔
970
        int r;
15✔
971
        bool found = false;
15✔
972

973
        r = fopen_temporary_at_label(etc_fd, "shadow", "shadow", &shadow, &shadow_tmp);
15✔
974
        if (r < 0)
15✔
975
                return r;
976

977
        r = xfopenat(etc_fd, "shadow", "re", O_NOFOLLOW, &original);
15✔
978
        if (r < 0 && r != -ENOENT)
15✔
979
                return r;
980

981
        if (original) {
15✔
982
                struct spwd *i;
4✔
983

984
                r = copy_rights(fileno(original), fileno(shadow));
4✔
985
                if (r < 0)
4✔
986
                        return r;
×
987

988
                while ((r = fgetspent_sane(original, &i)) > 0) {
7✔
989

990
                        if (streq(i->sp_namp, "root")) {
3✔
991
                                if (hashed_password) {
3✔
992
                                        i->sp_pwdp = (char *) hashed_password;
2✔
993
                                        i->sp_lstchg = (long) (now(CLOCK_REALTIME) / USEC_PER_DAY);
2✔
994
                                }
995
                                found = true;
996
                        }
997

998
                        r = putspent_sane(i, shadow);
3✔
999
                        if (r < 0)
3✔
1000
                                return r;
1001
                }
1002
                if (r < 0)
4✔
1003
                        return r;
1004

1005
        } else {
1006
                r = fchmod(fileno(shadow), 0000);
11✔
1007
                if (r < 0)
11✔
1008
                        return -errno;
×
1009
        }
1010

1011
        if (!found) {
4✔
1012
                struct spwd root = {
36✔
1013
                        .sp_namp = (char*) "root",
1014
                        .sp_pwdp = (char *) (hashed_password ?: PASSWORD_LOCKED_AND_INVALID),
12✔
1015
                        .sp_lstchg = (long) (now(CLOCK_REALTIME) / USEC_PER_DAY),
12✔
1016
                        .sp_min = -1,
1017
                        .sp_max = -1,
1018
                        .sp_warn = -1,
1019
                        .sp_inact = -1,
1020
                        .sp_expire = -1,
1021
                        .sp_flag = ULONG_MAX, /* this appears to be what everybody does ... */
1022
                };
1023

1024
                if (errno != ENOENT)
12✔
1025
                        return -errno;
×
1026

1027
                r = putspent_sane(&root, shadow);
12✔
1028
                if (r < 0)
12✔
1029
                        return r;
1030
        }
1031

1032
        r = fflush_sync_and_check(shadow);
15✔
1033
        if (r < 0)
15✔
1034
                return r;
1035

1036
        r = renameat_and_apply_smack_floor_label(etc_fd, shadow_tmp, etc_fd, "shadow");
15✔
1037
        if (r < 0)
15✔
1038
                return r;
×
1039

1040
        return 0;
1041
}
1042

1043
static int process_root_account(int rfd) {
133✔
1044
        _cleanup_close_ int pfd = -EBADF;
133✔
1045
        _cleanup_(release_lock_file) LockFile lock = LOCK_FILE_INIT;
×
1046
        _cleanup_(erase_and_freep) char *_hashed_password = NULL;
133✔
1047
        const char *password, *hashed_password;
133✔
1048
        int k = 0, r;
133✔
1049

1050
        assert(rfd >= 0);
133✔
1051

1052
        pfd = chase_and_open_parent_at(rfd, "/etc/passwd",
133✔
1053
                                       CHASE_AT_RESOLVE_IN_ROOT|CHASE_MKDIR_0755|CHASE_WARN|CHASE_NOFOLLOW,
1054
                                       NULL);
1055
        if (pfd < 0)
133✔
1056
                return log_error_errno(pfd, "Failed to chase /etc/passwd: %m");
×
1057

1058
        /* Ensure that passwd and shadow are in the same directory and are not symlinks. */
1059

1060
        FOREACH_STRING(s, "passwd", "shadow") {
399✔
1061
                r = verify_regular_at(pfd, s, /* follow = */ false);
266✔
1062
                if (r < 0 && r != -ENOENT)
266✔
1063
                        return log_error_errno(r, "Verification of /etc/%s being regular file failed: %m", s);
×
1064

1065
                r = should_configure(pfd, s);
266✔
1066
                if (r < 0)
266✔
1067
                        return r;
1068

1069
                k += r;
266✔
1070
        }
1071

1072
        if (k == 0) {
133✔
1073
                log_debug("Found /etc/passwd and /etc/shadow, assuming root account has been initialized.");
106✔
1074
                return 0;
106✔
1075
        }
1076

1077
        r = make_lock_file_at(pfd, ETC_PASSWD_LOCK_FILENAME, LOCK_EX, &lock);
27✔
1078
        if (r < 0)
27✔
1079
                return log_error_errno(r, "Failed to take a lock on /etc/passwd: %m");
×
1080

1081
        k = dir_fd_is_root(rfd);
27✔
1082
        if (k < 0)
27✔
1083
                return log_error_errno(k, "Failed to check if directory file descriptor is root: %m");
×
1084

1085
        if (arg_copy_root_shell && k == 0) {
27✔
1086
                _cleanup_free_ struct passwd *p = NULL;
2✔
1087

1088
                r = getpwnam_malloc("root", &p);
2✔
1089
                if (r < 0)
2✔
1090
                        return log_error_errno(r, "Failed to find passwd entry for root: %m");
×
1091

1092
                r = free_and_strdup(&arg_root_shell, p->pw_shell);
2✔
1093
                if (r < 0)
2✔
1094
                        return log_oom();
×
1095
        }
1096

1097
        r = prompt_root_shell(rfd);
27✔
1098
        if (r < 0)
27✔
1099
                return r;
1100

1101
        if (arg_copy_root_password && k == 0) {
27✔
1102
                struct spwd *p;
2✔
1103

1104
                errno = 0;
2✔
1105
                p = getspnam("root");
2✔
1106
                if (!p)
2✔
1107
                        return log_error_errno(errno_or_else(EIO), "Failed to find shadow entry for root: %m");
×
1108

1109
                r = free_and_strdup(&arg_root_password, p->sp_pwdp);
2✔
1110
                if (r < 0)
2✔
1111
                        return log_oom();
×
1112

1113
                arg_root_password_is_hashed = true;
2✔
1114
        }
1115

1116
        r = prompt_root_password(rfd);
27✔
1117
        if (r < 0)
27✔
1118
                return r;
1119

1120
        if (arg_root_password && arg_root_password_is_hashed) {
27✔
1121
                password = PASSWORD_SEE_SHADOW;
1122
                hashed_password = arg_root_password;
1123
        } else if (arg_root_password) {
21✔
1124
                r = hash_password(arg_root_password, &_hashed_password);
4✔
1125
                if (r < 0)
4✔
1126
                        return log_error_errno(r, "Failed to hash password: %m");
×
1127

1128
                password = PASSWORD_SEE_SHADOW;
4✔
1129
                hashed_password = _hashed_password;
4✔
1130

1131
        } else if (arg_delete_root_password) {
17✔
1132
                password = PASSWORD_SEE_SHADOW;
1133
                hashed_password = PASSWORD_NONE;
1134
        } else if (!arg_root_password && arg_prompt_root_password) {
16✔
1135
                /* If the user was prompted, but no password was supplied, lock the account. */
1136
                password = PASSWORD_SEE_SHADOW;
1137
                hashed_password = PASSWORD_LOCKED_AND_INVALID;
1138
        } else
1139
                /* Leave the password as is. */
1140
                password = hashed_password = NULL;
15✔
1141

1142
        /* Don't create/modify passwd and shadow if there's nothing to do. */
1143
        if (!(password || hashed_password || arg_root_shell)) {
27✔
1144
                log_debug("Initialization of root account was not requested, skipping.");
12✔
1145
                return 0;
12✔
1146
        }
1147

1148
        r = write_root_passwd(rfd, pfd, password, arg_root_shell);
15✔
1149
        if (r < 0)
15✔
1150
                return log_error_errno(r, "Failed to write /etc/passwd: %m");
×
1151

1152
        log_info("/etc/passwd written.");
15✔
1153

1154
        r = write_root_shadow(pfd, hashed_password);
15✔
1155
        if (r < 0)
15✔
1156
                return log_error_errno(r, "Failed to write /etc/shadow: %m");
×
1157

1158
        log_info("/etc/shadow written.");
133✔
1159
        return 0;
1160
}
1161

1162
static int process_kernel_cmdline(int rfd) {
133✔
1163
        _cleanup_close_ int pfd = -EBADF;
133✔
1164
        _cleanup_free_ char *f = NULL;
133✔
1165
        int r;
133✔
1166

1167
        assert(rfd >= 0);
133✔
1168

1169
        pfd = chase_and_open_parent_at(rfd, "/etc/kernel/cmdline",
133✔
1170
                                       CHASE_AT_RESOLVE_IN_ROOT|CHASE_MKDIR_0755|CHASE_WARN|CHASE_NOFOLLOW,
1171
                                       &f);
1172
        if (pfd < 0)
133✔
1173
                return log_error_errno(pfd, "Failed to chase /etc/kernel/cmdline: %m");
×
1174

1175
        r = should_configure(pfd, f);
133✔
1176
        if (r == 0)
133✔
1177
                log_debug("Found /etc/kernel/cmdline, assuming kernel command line has been configured.");
1✔
1178
        if (r <= 0)
133✔
1179
                return r;
1180

1181
        if (!arg_kernel_cmdline) {
132✔
1182
                log_debug("Creation of /etc/kernel/cmdline was not requested, skipping.");
130✔
1183
                return 0;
130✔
1184
        }
1185

1186
        r = write_string_file_at(pfd, "cmdline", arg_kernel_cmdline,
2✔
1187
                                 WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_SYNC|WRITE_STRING_FILE_ATOMIC);
1188
        if (r < 0)
2✔
1189
                return log_error_errno(r, "Failed to write /etc/kernel/cmdline: %m");
×
1190

1191
        log_info("/etc/kernel/cmdline written.");
133✔
1192
        return 0;
1193
}
1194

1195
static int reset_one(int rfd, const char *path) {
6✔
1196
        _cleanup_close_ int pfd = -EBADF;
6✔
1197
        _cleanup_free_ char *f = NULL;
6✔
1198

1199
        assert(rfd >= 0);
6✔
1200
        assert(path);
6✔
1201

1202
        pfd = chase_and_open_parent_at(rfd, path, CHASE_AT_RESOLVE_IN_ROOT|CHASE_WARN|CHASE_NOFOLLOW, &f);
6✔
1203
        if (pfd == -ENOENT)
6✔
1204
                return 0;
1205
        if (pfd < 0)
6✔
1206
                return log_error_errno(pfd, "Failed to resolve %s: %m", path);
×
1207

1208
        if (unlinkat(pfd, f, 0) < 0)
6✔
1209
                return errno == ENOENT ? 0 : log_error_errno(errno, "Failed to remove %s: %m", path);
×
1210

1211
        log_info("Removed %s", path);
6✔
1212
        return 0;
1213
}
1214

1215
static int process_reset(int rfd) {
133✔
1216
        int r;
133✔
1217

1218
        assert(rfd >= 0);
133✔
1219

1220
        if (!arg_reset)
133✔
1221
                return 0;
1222

1223
        FOREACH_STRING(p,
7✔
1224
                       "/etc/locale.conf",
1225
                       "/etc/vconsole.conf",
1226
                       "/etc/hostname",
1227
                       "/etc/machine-id",
1228
                       "/etc/kernel/cmdline",
1229
                       "/etc/localtime") {
1230
                r = reset_one(rfd, p);
6✔
1231
                if (r < 0)
6✔
1232
                        return r;
×
1233
        }
1234

1235
        return 0;
1✔
1236
}
1237

1238
static int help(void) {
×
1239
        _cleanup_free_ char *link = NULL;
×
1240
        int r;
×
1241

1242
        r = terminal_urlify_man("systemd-firstboot", "1", &link);
×
1243
        if (r < 0)
×
1244
                return log_oom();
×
1245

1246
        printf("%s [OPTIONS...]\n\n"
×
1247
               "Configures basic settings of the system.\n\n"
1248
               "  -h --help                       Show this help\n"
1249
               "     --version                    Show package version\n"
1250
               "     --root=PATH                  Operate on an alternate filesystem root\n"
1251
               "     --image=PATH                 Operate on disk image as filesystem root\n"
1252
               "     --image-policy=POLICY        Specify disk image dissection policy\n"
1253
               "     --locale=LOCALE              Set primary locale (LANG=)\n"
1254
               "     --locale-messages=LOCALE     Set message locale (LC_MESSAGES=)\n"
1255
               "     --keymap=KEYMAP              Set keymap\n"
1256
               "     --timezone=TIMEZONE          Set timezone\n"
1257
               "     --hostname=NAME              Set hostname\n"
1258
               "     --setup-machine-id           Set a random machine ID\n"
1259
               "     --machine-id=ID              Set specified machine ID\n"
1260
               "     --root-password=PASSWORD     Set root password from plaintext password\n"
1261
               "     --root-password-file=FILE    Set root password from file\n"
1262
               "     --root-password-hashed=HASH  Set root password from hashed password\n"
1263
               "     --root-shell=SHELL           Set root shell\n"
1264
               "     --kernel-command-line=CMDLINE\n"
1265
               "                                  Set kernel command line\n"
1266
               "     --prompt-locale              Prompt the user for locale settings\n"
1267
               "     --prompt-keymap              Prompt the user for keymap settings\n"
1268
               "     --prompt-timezone            Prompt the user for timezone\n"
1269
               "     --prompt-hostname            Prompt the user for hostname\n"
1270
               "     --prompt-root-password       Prompt the user for root password\n"
1271
               "     --prompt-root-shell          Prompt the user for root shell\n"
1272
               "     --prompt                     Prompt for all of the above\n"
1273
               "     --copy-locale                Copy locale from host\n"
1274
               "     --copy-keymap                Copy keymap from host\n"
1275
               "     --copy-timezone              Copy timezone from host\n"
1276
               "     --copy-root-password         Copy root password from host\n"
1277
               "     --copy-root-shell            Copy root shell from host\n"
1278
               "     --copy                       Copy locale, keymap, timezone, root password\n"
1279
               "     --force                      Overwrite existing files\n"
1280
               "     --delete-root-password       Delete root password\n"
1281
               "     --welcome=no                 Disable the welcome text\n"
1282
               "     --reset                      Remove existing files\n"
1283
               "\nSee the %s for details.\n",
1284
               program_invocation_short_name,
1285
               link);
1286

1287
        return 0;
1288
}
1289

1290
static int parse_argv(int argc, char *argv[]) {
136✔
1291

1292
        enum {
136✔
1293
                ARG_VERSION = 0x100,
1294
                ARG_ROOT,
1295
                ARG_IMAGE,
1296
                ARG_IMAGE_POLICY,
1297
                ARG_LOCALE,
1298
                ARG_LOCALE_MESSAGES,
1299
                ARG_KEYMAP,
1300
                ARG_TIMEZONE,
1301
                ARG_HOSTNAME,
1302
                ARG_SETUP_MACHINE_ID,
1303
                ARG_MACHINE_ID,
1304
                ARG_ROOT_PASSWORD,
1305
                ARG_ROOT_PASSWORD_FILE,
1306
                ARG_ROOT_PASSWORD_HASHED,
1307
                ARG_ROOT_SHELL,
1308
                ARG_KERNEL_COMMAND_LINE,
1309
                ARG_PROMPT,
1310
                ARG_PROMPT_LOCALE,
1311
                ARG_PROMPT_KEYMAP,
1312
                ARG_PROMPT_TIMEZONE,
1313
                ARG_PROMPT_HOSTNAME,
1314
                ARG_PROMPT_ROOT_PASSWORD,
1315
                ARG_PROMPT_ROOT_SHELL,
1316
                ARG_COPY,
1317
                ARG_COPY_LOCALE,
1318
                ARG_COPY_KEYMAP,
1319
                ARG_COPY_TIMEZONE,
1320
                ARG_COPY_ROOT_PASSWORD,
1321
                ARG_COPY_ROOT_SHELL,
1322
                ARG_FORCE,
1323
                ARG_DELETE_ROOT_PASSWORD,
1324
                ARG_WELCOME,
1325
                ARG_RESET,
1326
        };
1327

1328
        static const struct option options[] = {
136✔
1329
                { "help",                    no_argument,       NULL, 'h'                         },
1330
                { "version",                 no_argument,       NULL, ARG_VERSION                 },
1331
                { "root",                    required_argument, NULL, ARG_ROOT                    },
1332
                { "image",                   required_argument, NULL, ARG_IMAGE                   },
1333
                { "image-policy",            required_argument, NULL, ARG_IMAGE_POLICY            },
1334
                { "locale",                  required_argument, NULL, ARG_LOCALE                  },
1335
                { "locale-messages",         required_argument, NULL, ARG_LOCALE_MESSAGES         },
1336
                { "keymap",                  required_argument, NULL, ARG_KEYMAP                  },
1337
                { "timezone",                required_argument, NULL, ARG_TIMEZONE                },
1338
                { "hostname",                required_argument, NULL, ARG_HOSTNAME                },
1339
                { "setup-machine-id",        no_argument,       NULL, ARG_SETUP_MACHINE_ID        },
1340
                { "machine-id",              required_argument, NULL, ARG_MACHINE_ID              },
1341
                { "root-password",           required_argument, NULL, ARG_ROOT_PASSWORD           },
1342
                { "root-password-file",      required_argument, NULL, ARG_ROOT_PASSWORD_FILE      },
1343
                { "root-password-hashed",    required_argument, NULL, ARG_ROOT_PASSWORD_HASHED    },
1344
                { "root-shell",              required_argument, NULL, ARG_ROOT_SHELL              },
1345
                { "kernel-command-line",     required_argument, NULL, ARG_KERNEL_COMMAND_LINE     },
1346
                { "prompt",                  no_argument,       NULL, ARG_PROMPT                  },
1347
                { "prompt-locale",           no_argument,       NULL, ARG_PROMPT_LOCALE           },
1348
                { "prompt-keymap",           no_argument,       NULL, ARG_PROMPT_KEYMAP           },
1349
                { "prompt-timezone",         no_argument,       NULL, ARG_PROMPT_TIMEZONE         },
1350
                { "prompt-hostname",         no_argument,       NULL, ARG_PROMPT_HOSTNAME         },
1351
                { "prompt-root-password",    no_argument,       NULL, ARG_PROMPT_ROOT_PASSWORD    },
1352
                { "prompt-root-shell",       no_argument,       NULL, ARG_PROMPT_ROOT_SHELL       },
1353
                { "copy",                    no_argument,       NULL, ARG_COPY                    },
1354
                { "copy-locale",             no_argument,       NULL, ARG_COPY_LOCALE             },
1355
                { "copy-keymap",             no_argument,       NULL, ARG_COPY_KEYMAP             },
1356
                { "copy-timezone",           no_argument,       NULL, ARG_COPY_TIMEZONE           },
1357
                { "copy-root-password",      no_argument,       NULL, ARG_COPY_ROOT_PASSWORD      },
1358
                { "copy-root-shell",         no_argument,       NULL, ARG_COPY_ROOT_SHELL         },
1359
                { "force",                   no_argument,       NULL, ARG_FORCE                   },
1360
                { "delete-root-password",    no_argument,       NULL, ARG_DELETE_ROOT_PASSWORD    },
1361
                { "welcome",                 required_argument, NULL, ARG_WELCOME                 },
1362
                { "reset",                   no_argument,       NULL, ARG_RESET                   },
1363
                {}
1364
        };
1365

1366
        int r, c;
136✔
1367

1368
        assert(argc >= 0);
136✔
1369
        assert(argv);
136✔
1370

1371
        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
637✔
1372

1373
                switch (c) {
503✔
1374

1375
                case 'h':
×
1376
                        return help();
×
1377

1378
                case ARG_VERSION:
×
1379
                        return version();
×
1380

1381
                case ARG_ROOT:
35✔
1382
                        r = parse_path_argument(optarg, true, &arg_root);
35✔
1383
                        if (r < 0)
35✔
1384
                                return r;
1385
                        break;
1386

1387
                case ARG_IMAGE:
×
1388
                        r = parse_path_argument(optarg, false, &arg_image);
×
1389
                        if (r < 0)
×
1390
                                return r;
1391
                        break;
1392

1393
                case ARG_IMAGE_POLICY:
×
1394
                        r = parse_image_policy_argument(optarg, &arg_image_policy);
×
1395
                        if (r < 0)
×
1396
                                return r;
1397
                        break;
1398

1399
                case ARG_LOCALE:
4✔
1400
                        r = free_and_strdup(&arg_locale, optarg);
4✔
1401
                        if (r < 0)
4✔
1402
                                return log_oom();
×
1403

1404
                        break;
1405

1406
                case ARG_LOCALE_MESSAGES:
4✔
1407
                        r = free_and_strdup(&arg_locale_messages, optarg);
4✔
1408
                        if (r < 0)
4✔
1409
                                return log_oom();
×
1410

1411
                        break;
1412

1413
                case ARG_KEYMAP:
3✔
1414
                        if (!keymap_is_valid(optarg))
3✔
1415
                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
1416
                                                       "Keymap %s is not valid.", optarg);
1417

1418
                        r = free_and_strdup(&arg_keymap, optarg);
3✔
1419
                        if (r < 0)
3✔
1420
                                return log_oom();
×
1421

1422
                        break;
1423

1424
                case ARG_TIMEZONE:
4✔
1425
                        if (!timezone_is_valid(optarg, LOG_ERR))
4✔
1426
                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
1✔
1427
                                                       "Timezone %s is not valid.", optarg);
1428

1429
                        r = free_and_strdup(&arg_timezone, optarg);
3✔
1430
                        if (r < 0)
3✔
1431
                                return log_oom();
×
1432

1433
                        break;
1434

1435
                case ARG_ROOT_PASSWORD:
4✔
1436
                        r = free_and_strdup(&arg_root_password, optarg);
4✔
1437
                        if (r < 0)
4✔
1438
                                return log_oom();
×
1439

1440
                        arg_root_password_is_hashed = false;
4✔
1441
                        break;
4✔
1442

1443
                case ARG_ROOT_PASSWORD_FILE:
1✔
1444
                        arg_root_password = mfree(arg_root_password);
1✔
1445

1446
                        r = read_one_line_file(optarg, &arg_root_password);
1✔
1447
                        if (r < 0)
1✔
1448
                                return log_error_errno(r, "Failed to read %s: %m", optarg);
×
1449

1450
                        arg_root_password_is_hashed = false;
1✔
1451
                        break;
1✔
1452

1453
                case ARG_ROOT_PASSWORD_HASHED:
4✔
1454
                        r = free_and_strdup(&arg_root_password, optarg);
4✔
1455
                        if (r < 0)
4✔
1456
                                return log_oom();
×
1457

1458
                        arg_root_password_is_hashed = true;
4✔
1459
                        break;
4✔
1460

1461
                case ARG_ROOT_SHELL:
5✔
1462
                        r = free_and_strdup(&arg_root_shell, optarg);
5✔
1463
                        if (r < 0)
5✔
1464
                                return log_oom();
×
1465

1466
                        break;
1467

1468
                case ARG_HOSTNAME:
3✔
1469
                        if (!hostname_is_valid(optarg, VALID_HOSTNAME_TRAILING_DOT|VALID_HOSTNAME_QUESTION_MARK))
3✔
1470
                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
1471
                                                       "Host name %s is not valid.", optarg);
1472

1473
                        r = free_and_strdup(&arg_hostname, optarg);
3✔
1474
                        if (r < 0)
3✔
1475
                                return log_oom();
×
1476

1477
                        hostname_cleanup(arg_hostname);
3✔
1478
                        break;
3✔
1479

1480
                case ARG_SETUP_MACHINE_ID:
1✔
1481
                        r = sd_id128_randomize(&arg_machine_id);
1✔
1482
                        if (r < 0)
1✔
1483
                                return log_error_errno(r, "Failed to generate randomized machine ID: %m");
×
1484

1485
                        break;
1486

1487
                case ARG_MACHINE_ID:
4✔
1488
                        r = sd_id128_from_string(optarg, &arg_machine_id);
4✔
1489
                        if (r < 0)
4✔
1490
                                return log_error_errno(r, "Failed to parse machine id %s.", optarg);
1✔
1491

1492
                        break;
1493

1494
                case ARG_KERNEL_COMMAND_LINE:
3✔
1495
                        r = free_and_strdup(&arg_kernel_cmdline, optarg);
3✔
1496
                        if (r < 0)
3✔
1497
                                return log_oom();
×
1498

1499
                        break;
1500

1501
                case ARG_PROMPT:
×
1502
                        arg_prompt_locale = arg_prompt_keymap = arg_prompt_timezone = arg_prompt_hostname =
×
1503
                                arg_prompt_root_password = arg_prompt_root_shell = true;
×
1504
                        break;
×
1505

1506
                case ARG_PROMPT_LOCALE:
103✔
1507
                        arg_prompt_locale = true;
103✔
1508
                        break;
103✔
1509

1510
                case ARG_PROMPT_KEYMAP:
103✔
1511
                        arg_prompt_keymap = true;
103✔
1512
                        break;
103✔
1513

1514
                case ARG_PROMPT_TIMEZONE:
103✔
1515
                        arg_prompt_timezone = true;
103✔
1516
                        break;
103✔
1517

1518
                case ARG_PROMPT_HOSTNAME:
1✔
1519
                        arg_prompt_hostname = true;
1✔
1520
                        break;
1✔
1521

1522
                case ARG_PROMPT_ROOT_PASSWORD:
103✔
1523
                        arg_prompt_root_password = true;
103✔
1524
                        break;
103✔
1525

1526
                case ARG_PROMPT_ROOT_SHELL:
4✔
1527
                        arg_prompt_root_shell = true;
4✔
1528
                        break;
4✔
1529

1530
                case ARG_COPY:
1✔
1531
                        arg_copy_locale = arg_copy_keymap = arg_copy_timezone = arg_copy_root_password =
1✔
1532
                                arg_copy_root_shell = true;
1✔
1533
                        break;
1✔
1534

1535
                case ARG_COPY_LOCALE:
1✔
1536
                        arg_copy_locale = true;
1✔
1537
                        break;
1✔
1538

1539
                case ARG_COPY_KEYMAP:
1✔
1540
                        arg_copy_keymap = true;
1✔
1541
                        break;
1✔
1542

1543
                case ARG_COPY_TIMEZONE:
1✔
1544
                        arg_copy_timezone = true;
1✔
1545
                        break;
1✔
1546

1547
                case ARG_COPY_ROOT_PASSWORD:
1✔
1548
                        arg_copy_root_password = true;
1✔
1549
                        break;
1✔
1550

1551
                case ARG_COPY_ROOT_SHELL:
1✔
1552
                        arg_copy_root_shell = true;
1✔
1553
                        break;
1✔
1554

1555
                case ARG_FORCE:
2✔
1556
                        arg_force = true;
2✔
1557
                        break;
2✔
1558

1559
                case ARG_DELETE_ROOT_PASSWORD:
1✔
1560
                        arg_delete_root_password = true;
1✔
1561
                        break;
1✔
1562

1563
                case ARG_WELCOME:
1✔
1564
                        r = parse_boolean(optarg);
1✔
1565
                        if (r < 0)
1✔
1566
                                return log_error_errno(r, "Failed to parse --welcome= argument: %s", optarg);
×
1567

1568
                        arg_welcome = r;
1✔
1569
                        break;
1✔
1570

1571
                case ARG_RESET:
1✔
1572
                        arg_reset = true;
1✔
1573
                        break;
1✔
1574

1575
                case '?':
1576
                        return -EINVAL;
1577

1578
                default:
×
1579
                        assert_not_reached();
×
1580
                }
1581

1582
        if (arg_delete_root_password && (arg_copy_root_password || arg_root_password || arg_prompt_root_password))
134✔
1583
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
1584
                                       "--delete-root-password cannot be combined with other root password options.");
1585

1586
        if (arg_image && arg_root)
134✔
1587
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
1588
                                       "--root= and --image= cannot be used together.");
1589

1590
        if (!sd_id128_is_null(arg_machine_id) && !(arg_image || arg_root) && !arg_force)
264✔
1591
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
1592
                                       "--machine-id=/--setup-machine-id only works with --root= or --image=.");
1593

1594
        return 1;
1595
}
1596

1597
static int reload_system_manager(sd_bus **bus) {
×
1598
        int r;
×
1599

1600
        assert(bus);
×
1601

1602
        if (!*bus) {
×
1603
                r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, RUNTIME_SCOPE_SYSTEM, bus);
×
1604
                if (r < 0)
×
1605
                        return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, RUNTIME_SCOPE_SYSTEM);
×
1606
        }
1607

1608
        r = bus_service_manager_reload(*bus);
×
1609
        if (r < 0)
×
1610
                return r;
1611

1612
        log_info("Requested manager reload to apply locale configuration.");
×
1613
        return 0;
1614
}
1615

1616
static int reload_vconsole(sd_bus **bus) {
×
1617
        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
×
1618
        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
×
1619
        _cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL;
×
1620
        const char *object;
×
1621
        int r;
×
1622

1623
        assert(bus);
×
1624

1625
        if (!*bus) {
×
1626
                r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, RUNTIME_SCOPE_SYSTEM, bus);
×
1627
                if (r < 0)
×
1628
                        return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL, RUNTIME_SCOPE_SYSTEM);
×
1629
        }
1630

1631
        r = bus_wait_for_jobs_new(*bus, &w);
×
1632
        if (r < 0)
×
1633
                return log_error_errno(r, "Could not watch jobs: %m");
×
1634

1635
        r = bus_call_method(*bus, bus_systemd_mgr, "RestartUnit", &error, &reply,
×
1636
                            "ss", "systemd-vconsole-setup.service", "replace");
1637
        if (r < 0)
×
1638
                return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, r));
×
1639

1640
        r = sd_bus_message_read(reply, "o", &object);
×
1641
        if (r < 0)
×
1642
                return bus_log_parse_error(r);
×
1643

1644
        r = bus_wait_for_jobs_one(w, object, BUS_WAIT_JOBS_LOG_ERROR, NULL);
×
1645
        if (r < 0)
×
1646
                return log_error_errno(r, "Failed to wait for systemd-vconsole-setup.service/restart: %m");
×
1647
        return 0;
1648
}
1649

1650
static int run(int argc, char *argv[]) {
136✔
1651
        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
136✔
1652
        _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
136✔
1653
        _cleanup_(umount_and_freep) char *mounted_dir = NULL;
×
1654
        _cleanup_close_ int rfd = -EBADF;
136✔
1655
        int r;
136✔
1656

1657
        r = parse_argv(argc, argv);
136✔
1658
        if (r <= 0)
136✔
1659
                return r;
1660

1661
        log_setup();
134✔
1662

1663
        umask(0022);
134✔
1664

1665
        bool offline = arg_root || arg_image;
134✔
1666

1667
        if (!offline) {
101✔
1668
                /* If we are called without --root=/--image= let's honour the systemd.firstboot kernel
1669
                 * command line option, because we are called to provision the host with basic settings (as
1670
                 * opposed to some other file system tree/image) */
1671

1672
                bool enabled;
101✔
1673
                r = proc_cmdline_get_bool("systemd.firstboot", /* flags = */ 0, &enabled);
101✔
1674
                if (r < 0)
101✔
1675
                        return log_error_errno(r, "Failed to parse systemd.firstboot= kernel command line argument, ignoring: %m");
×
1676
                if (r > 0 && !enabled) {
101✔
1677
                        log_debug("Found systemd.firstboot=no kernel command line argument, turning off all prompts.");
101✔
1678
                        arg_prompt_locale = arg_prompt_keymap = arg_prompt_timezone = arg_prompt_hostname = arg_prompt_root_password = arg_prompt_root_shell = false;
101✔
1679
                }
1680
        }
1681

1682
        if (arg_image) {
134✔
1683
                assert(!arg_root);
×
1684

1685
                r = mount_image_privately_interactively(
×
1686
                                arg_image,
1687
                                arg_image_policy,
1688
                                DISSECT_IMAGE_GENERIC_ROOT |
1689
                                DISSECT_IMAGE_REQUIRE_ROOT |
1690
                                DISSECT_IMAGE_VALIDATE_OS |
1691
                                DISSECT_IMAGE_RELAX_VAR_CHECK |
1692
                                DISSECT_IMAGE_FSCK |
1693
                                DISSECT_IMAGE_GROWFS |
1694
                                DISSECT_IMAGE_ALLOW_USERSPACE_VERITY,
1695
                                &mounted_dir,
1696
                                &rfd,
1697
                                &loop_device);
1698
                if (r < 0)
×
1699
                        return r;
1700

1701
                arg_root = strdup(mounted_dir);
×
1702
                if (!arg_root)
×
1703
                        return log_oom();
×
1704
        } else {
1705
                rfd = open(empty_to_root(arg_root), O_DIRECTORY|O_CLOEXEC);
167✔
1706
                if (rfd < 0)
134✔
1707
                        return log_error_errno(errno, "Failed to open %s: %m", empty_to_root(arg_root));
×
1708
        }
1709

1710
        LOG_SET_PREFIX(arg_image ?: arg_root);
270✔
1711

1712
        /* We check these conditions here instead of in parse_argv() so that we can take the root directory
1713
         * into account. */
1714

1715
        if (arg_keymap && !keymap_is_ok(rfd, arg_keymap))
134✔
1716
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Keymap %s is not installed.", arg_keymap);
×
1717
        if (arg_locale && !locale_is_ok(rfd, arg_locale))
134✔
1718
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Locale %s is not installed.", arg_locale);
×
1719
        if (arg_locale_messages && !locale_is_ok(rfd, arg_locale_messages))
134✔
1720
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Locale %s is not installed.", arg_locale_messages);
×
1721

1722
        if (arg_root_shell) {
134✔
1723
                r = find_shell(rfd, arg_root_shell);
5✔
1724
                if (r < 0)
5✔
1725
                        return r;
1726
        }
1727

1728
        r = process_reset(rfd);
133✔
1729
        if (r < 0)
133✔
1730
                return r;
1731

1732
        r = process_locale(rfd);
133✔
1733
        if (r < 0)
133✔
1734
                return r;
1735
        if (r > 0 && !offline)
133✔
1736
                (void) reload_system_manager(&bus);
×
1737

1738
        r = process_keymap(rfd);
133✔
1739
        if (r < 0)
133✔
1740
                return r;
1741
        if (r > 0 && !offline)
133✔
1742
                (void) reload_vconsole(&bus);
×
1743

1744
        r = process_timezone(rfd);
133✔
1745
        if (r < 0)
133✔
1746
                return r;
1747

1748
        r = process_hostname(rfd);
133✔
1749
        if (r < 0)
133✔
1750
                return r;
1751

1752
        r = process_root_account(rfd);
133✔
1753
        if (r < 0)
133✔
1754
                return r;
1755

1756
        r = process_kernel_cmdline(rfd);
133✔
1757
        if (r < 0)
133✔
1758
                return r;
1759

1760
        r = process_machine_id(rfd);
133✔
1761
        if (r < 0)
133✔
1762
                return r;
×
1763

1764
        return 0;
1765
}
1766

1767
DEFINE_MAIN_FUNCTION(run);
272✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc