blob: f5f026aab34d1caf11a994e7815633941d873461 [file] [log] [blame]
Christopher N. Hessee74d3b72018-02-24 23:33:49 -08001/*
2 * Copyright (C) 2018 The LineageOS Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "verity_tool.h"
18
19#include <getopt.h>
20#include <stdio.h>
21#include <string.h>
22
23static void print_usage() {
24 printf("veritytool - toggle block device verification\n"
25 " --help show this help\n"
26 " --enable enable dm-verity\n"
27 " --disable disable dm-verity\n");
28}
29
30int main(int argc, char** argv) {
31 int c, rc;
32 int enable = 0;
33 bool flag_set = false;
34 struct option long_opts[] = {
35 {"disable", no_argument, &enable, 0},
36 {"enable", no_argument, &enable, 1},
37 {NULL, 0, NULL, 0},
38 };
39
40 while ((c = getopt_long(argc, argv, "de", long_opts, NULL)) != -1) {
41 switch (c) {
42 case 0:
43 flag_set = true;
44 break;
45 default:
46 print_usage();
47 exit(0);
48 }
49 }
50
51 if (!flag_set) {
52 print_usage();
53 exit(0);
54 }
55
56 if (!set_verity_enabled(enable)) {
57 printf("Error occurred in set_verity_enable\n");
58 exit(EXIT_FAILURE);
59 }
60
61 printf("Set verity mode to: %s\n", enable ? "enabled" : "disabled");
62 printf("Now reboot your device for settings to take effect\n");
63 return 0;
64}