1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include <stdlib.h>
4 
5 #include "log.h"
6 #include "nspawn-patch-uid.h"
7 #include "user-util.h"
8 #include "string-util.h"
9 #include "tests.h"
10 
main(int argc,char * argv[])11 int main(int argc, char *argv[]) {
12         uid_t shift, range;
13         int r;
14 
15         test_setup_logging(LOG_DEBUG);
16 
17         if (argc != 4) {
18                 log_error("Expected PATH SHIFT RANGE parameters.");
19                 return EXIT_FAILURE;
20         }
21 
22         r = parse_uid(argv[2], &shift);
23         if (r < 0) {
24                 log_error_errno(r, "Failed to parse UID shift %s.", argv[2]);
25                 return EXIT_FAILURE;
26         }
27 
28         r = parse_gid(argv[3], &range);
29         if (r < 0) {
30                 log_error_errno(r, "Failed to parse UID range %s.", argv[3]);
31                 return EXIT_FAILURE;
32         }
33 
34         r = path_patch_uid(argv[1], shift, range);
35         if (r < 0) {
36                 log_error_errno(r, "Failed to patch directory tree: %m");
37                 return EXIT_FAILURE;
38         }
39 
40         log_info("Changed: %s", yes_no(r));
41 
42         return EXIT_SUCCESS;
43 }
44