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

systemd / systemd / 15057632786

15 May 2025 09:01PM UTC coverage: 72.267% (+0.02%) from 72.244%
15057632786

push

github

bluca
man: document how to hook stuff into system wakeup

Fixes: #6364

298523 of 413084 relevant lines covered (72.27%)

738132.88 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-bus.h"
9
#include "sd-id128.h"
10

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

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

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

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

105
        assert(rfd >= 0);
7✔
106

107
        if (!arg_welcome)
7✔
108
                return;
109

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

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

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

126
        (void) terminal_reset_defensive_locked(STDOUT_FILENO, /* flags= */ 0);
6✔
127

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

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

141
        any_key_to_proceed();
6✔
142

143
        done = true;
6✔
144
}
145

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

151
        int r;
×
152

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

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

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

166
        *ret_list = TAKE_PTR(copy);
×
167
        return 0;
×
168
}
169

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

178
        int r;
7✔
179

180
        assert(text);
7✔
181
        assert(is_valid);
7✔
182
        assert(ret);
7✔
183

184
        for (;;) {
7✔
185
                _cleanup_free_ char *p = NULL;
7✔
186

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

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

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

213
                                putchar('\n');
×
214
                                continue;
×
215
                        }
216

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

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

230
                if (is_valid(rfd, p))
7✔
231
                        return free_and_replace(*ret, p);
7✔
232

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

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

246
        assert(dir_fd >= 0);
1,064✔
247
        assert(filename);
1,064✔
248

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

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

262
        if (!passwd)
642✔
263
                return false;
264

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

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

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

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

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

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

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

318
        assert(rfd >= 0);
10✔
319

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

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

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

332
        assert(rfd >= 0);
10✔
333

334
        if (arg_locale || arg_locale_messages)
10✔
335
                return 0;
336

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

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

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

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

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

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

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

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

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

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

386
                if (isempty(arg_locale))
11✔
387
                        return 0;
388

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

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

399
        return 0;
400
}
401

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

409
        assert(rfd >= 0);
133✔
410

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

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

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

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

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

438
        r = prompt_locale(rfd);
10✔
439
        if (r < 0)
10✔
440
                return r;
441

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

447
        if (i == 0)
10✔
448
                return 0;
449

450
        locales[i] = NULL;
6✔
451

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

456
        log_info("/etc/locale.conf written.");
6✔
457
        return 1;
458
}
459

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

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

467
        assert(rfd >= 0);
4✔
468

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

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

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

480
        assert(rfd >= 0);
12✔
481

482
        if (arg_keymap)
12✔
483
                return 0;
484

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

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

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

504
        print_welcome(rfd);
1✔
505

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

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

516
        assert(rfd >= 0);
133✔
517

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

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

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

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

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

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

551
        if (isempty(arg_keymap))
137✔
552
                return 0;
553

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

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

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

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

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

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

578
        return timezone_is_valid(name, LOG_DEBUG);
1✔
579
}
580

581
static int prompt_timezone(int rfd) {
71✔
582
        _cleanup_strv_free_ char **zones = NULL;
71✔
583
        int r;
71✔
584

585
        assert(rfd >= 0);
71✔
586

587
        if (arg_timezone)
71✔
588
                return 0;
589

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

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

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

607
        print_welcome(rfd);
1✔
608

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

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

619
        assert(rfd >= 0);
133✔
620

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

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

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

637
        if (arg_copy_timezone && r == 0) {
73✔
638
                _cleanup_free_ char *s = NULL;
2✔
639

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

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

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

654
        r = prompt_timezone(rfd);
71✔
655
        if (r < 0)
71✔
656
                return r;
657

658
        if (isempty(arg_timezone))
194✔
659
                return 0;
660

661
        e = strjoina("../usr/share/zoneinfo/", arg_timezone);
305✔
662

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

667
        log_info("/etc/localtime written");
61✔
668
        return 0;
669
}
670

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

674
        return hostname_is_valid(name, VALID_HOSTNAME_TRAILING_DOT);
1✔
675
}
676

677
static int prompt_hostname(int rfd) {
119✔
678
        int r;
119✔
679

680
        assert(rfd >= 0);
119✔
681

682
        if (arg_hostname)
119✔
683
                return 0;
684

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

690
        print_welcome(rfd);
1✔
691

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

697
        if (arg_hostname)
1✔
698
                hostname_cleanup(arg_hostname);
1✔
699

700
        return 0;
701
}
702

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

708
        assert(rfd >= 0);
133✔
709

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

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

722
        r = prompt_hostname(rfd);
119✔
723
        if (r < 0)
119✔
724
                return r;
725

726
        if (isempty(arg_hostname))
136✔
727
                return 0;
728

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

734
        log_info("/etc/hostname written.");
3✔
735
        return 0;
736
}
737

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

743
        assert(rfd >= 0);
133✔
744

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

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

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

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

767
        log_info("/etc/machine-id written.");
3✔
768
        return 0;
769
}
770

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

775
        assert(rfd >= 0);
27✔
776

777
        if (arg_root_password)
27✔
778
                return 0;
779

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

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

788
        print_welcome(rfd);
1✔
789

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

793
        suggest_passwords();
1✔
794

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

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

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

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

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

826
                req.message = msg2;
×
827

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

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

840
                arg_root_password = TAKE_PTR(*a);
×
841
                break;
×
842
        }
843

844
        return 0;
1✔
845
}
846

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

850
        assert(path);
7✔
851

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

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

859
        return 0;
860
}
861

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

865
        return find_shell(rfd, path) >= 0;
2✔
866
}
867

868
static int prompt_root_shell(int rfd) {
27✔
869
        int r;
27✔
870

871
        assert(rfd >= 0);
27✔
872

873
        if (arg_root_shell)
27✔
874
                return 0;
875

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

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

889
        print_welcome(rfd);
2✔
890

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

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

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

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

909
        if (original) {
15✔
910
                struct passwd *i;
4✔
911

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

916
                while ((r = fgetpwent_sane(original, &i)) > 0) {
7✔
917

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

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

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

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

950
                if (errno != ENOENT)
12✔
951
                        return -errno;
×
952

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

958
        r = fflush_sync_and_check(passwd);
15✔
959
        if (r < 0)
15✔
960
                return r;
961

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

966
        return 0;
967
}
968

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

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

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

983
        if (original) {
15✔
984
                struct spwd *i;
4✔
985

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

990
                while ((r = fgetspent_sane(original, &i)) > 0) {
7✔
991

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

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

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

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

1026
                if (errno != ENOENT)
12✔
1027
                        return -errno;
×
1028

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

1034
        r = fflush_sync_and_check(shadow);
15✔
1035
        if (r < 0)
15✔
1036
                return r;
1037

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

1042
        return 0;
1043
}
1044

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

1052
        assert(rfd >= 0);
133✔
1053

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

1060
        /* Ensure that passwd and shadow are in the same directory and are not symlinks. */
1061

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

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

1071
                k += r;
266✔
1072
        }
1073

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

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

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

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

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

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

1099
        r = prompt_root_shell(rfd);
27✔
1100
        if (r < 0)
27✔
1101
                return r;
1102

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

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

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

1115
                arg_root_password_is_hashed = true;
2✔
1116
        }
1117

1118
        r = prompt_root_password(rfd);
27✔
1119
        if (r < 0)
27✔
1120
                return r;
1121

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

1130
                password = PASSWORD_SEE_SHADOW;
4✔
1131
                hashed_password = _hashed_password;
4✔
1132

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

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

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

1154
        log_info("/etc/passwd written.");
15✔
1155

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

1160
        log_info("/etc/shadow written.");
15✔
1161
        return 0;
1162
}
1163

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

1169
        assert(rfd >= 0);
133✔
1170

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

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

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

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

1193
        log_info("/etc/kernel/cmdline written.");
2✔
1194
        return 0;
1195
}
1196

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

1201
        assert(rfd >= 0);
6✔
1202
        assert(path);
6✔
1203

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

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

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

1217
static int process_reset(int rfd) {
133✔
1218
        int r;
133✔
1219

1220
        assert(rfd >= 0);
133✔
1221

1222
        if (!arg_reset)
133✔
1223
                return 0;
1224

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

1237
        return 0;
1✔
1238
}
1239

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

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

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

1289
        return 0;
1290
}
1291

1292
static int parse_argv(int argc, char *argv[]) {
136✔
1293

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

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

1368
        int r, c;
136✔
1369

1370
        assert(argc >= 0);
136✔
1371
        assert(argv);
136✔
1372

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

1375
                switch (c) {
503✔
1376

1377
                case 'h':
×
1378
                        return help();
×
1379

1380
                case ARG_VERSION:
×
1381
                        return version();
×
1382

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

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

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

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

1406
                        break;
1407

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

1413
                        break;
1414

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

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

1424
                        break;
1425

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

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

1435
                        break;
1436

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

1442
                        arg_root_password_is_hashed = false;
4✔
1443
                        break;
4✔
1444

1445
                case ARG_ROOT_PASSWORD_FILE:
1✔
1446
                        arg_root_password = mfree(arg_root_password);
1✔
1447

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

1452
                        arg_root_password_is_hashed = false;
1✔
1453
                        break;
1✔
1454

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

1460
                        arg_root_password_is_hashed = true;
4✔
1461
                        break;
4✔
1462

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

1468
                        break;
1469

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

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

1479
                        hostname_cleanup(arg_hostname);
3✔
1480
                        break;
3✔
1481

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

1487
                        break;
1488

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

1494
                        break;
1495

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

1501
                        break;
1502

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

1508
                case ARG_PROMPT_LOCALE:
103✔
1509
                        arg_prompt_locale = true;
103✔
1510
                        break;
103✔
1511

1512
                case ARG_PROMPT_KEYMAP:
103✔
1513
                        arg_prompt_keymap = true;
103✔
1514
                        break;
103✔
1515

1516
                case ARG_PROMPT_TIMEZONE:
103✔
1517
                        arg_prompt_timezone = true;
103✔
1518
                        break;
103✔
1519

1520
                case ARG_PROMPT_HOSTNAME:
1✔
1521
                        arg_prompt_hostname = true;
1✔
1522
                        break;
1✔
1523

1524
                case ARG_PROMPT_ROOT_PASSWORD:
103✔
1525
                        arg_prompt_root_password = true;
103✔
1526
                        break;
103✔
1527

1528
                case ARG_PROMPT_ROOT_SHELL:
4✔
1529
                        arg_prompt_root_shell = true;
4✔
1530
                        break;
4✔
1531

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

1537
                case ARG_COPY_LOCALE:
1✔
1538
                        arg_copy_locale = true;
1✔
1539
                        break;
1✔
1540

1541
                case ARG_COPY_KEYMAP:
1✔
1542
                        arg_copy_keymap = true;
1✔
1543
                        break;
1✔
1544

1545
                case ARG_COPY_TIMEZONE:
1✔
1546
                        arg_copy_timezone = true;
1✔
1547
                        break;
1✔
1548

1549
                case ARG_COPY_ROOT_PASSWORD:
1✔
1550
                        arg_copy_root_password = true;
1✔
1551
                        break;
1✔
1552

1553
                case ARG_COPY_ROOT_SHELL:
1✔
1554
                        arg_copy_root_shell = true;
1✔
1555
                        break;
1✔
1556

1557
                case ARG_FORCE:
2✔
1558
                        arg_force = true;
2✔
1559
                        break;
2✔
1560

1561
                case ARG_DELETE_ROOT_PASSWORD:
1✔
1562
                        arg_delete_root_password = true;
1✔
1563
                        break;
1✔
1564

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

1570
                        arg_welcome = r;
1✔
1571
                        break;
1✔
1572

1573
                case ARG_RESET:
1✔
1574
                        arg_reset = true;
1✔
1575
                        break;
1✔
1576

1577
                case '?':
1578
                        return -EINVAL;
1579

1580
                default:
×
1581
                        assert_not_reached();
×
1582
                }
1583

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

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

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

1596
        return 1;
1597
}
1598

1599
static int reload_system_manager(sd_bus **bus) {
×
1600
        int r;
×
1601

1602
        assert(bus);
×
1603

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

1610
        r = bus_service_manager_reload(*bus);
×
1611
        if (r < 0)
×
1612
                return r;
1613

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

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

1625
        assert(bus);
×
1626

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

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

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

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

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

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

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

1663
        log_setup();
134✔
1664

1665
        umask(0022);
134✔
1666

1667
        bool offline = arg_root || arg_image;
134✔
1668

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

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

1684
        if (arg_image) {
134✔
1685
                assert(!arg_root);
×
1686

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

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

1712
        LOG_SET_PREFIX(arg_image ?: arg_root);
270✔
1713

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

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

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

1730
        r = process_reset(rfd);
133✔
1731
        if (r < 0)
133✔
1732
                return r;
1733

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

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

1746
        r = process_timezone(rfd);
133✔
1747
        if (r < 0)
133✔
1748
                return r;
1749

1750
        r = process_hostname(rfd);
133✔
1751
        if (r < 0)
133✔
1752
                return r;
1753

1754
        r = process_root_account(rfd);
133✔
1755
        if (r < 0)
133✔
1756
                return r;
1757

1758
        r = process_kernel_cmdline(rfd);
133✔
1759
        if (r < 0)
133✔
1760
                return r;
1761

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

1766
        return 0;
1767
}
1768

1769
DEFINE_MAIN_FUNCTION(run);
136✔
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