lib: Add AUTH_MSG_DECRYPT
[petitboot] / lib / types / types.c
1 #include <string.h>
2 #include <types/types.h>
3 #include <i18n/i18n.h>
4
5 const char *ipmi_bootdev_display_name(enum ipmi_bootdev bootdev)
6 {
7         switch (bootdev) {
8         case IPMI_BOOTDEV_NONE:
9                 return _("None");
10         case IPMI_BOOTDEV_NETWORK:
11                 return _("Network");
12         case IPMI_BOOTDEV_DISK:
13                 return _("Disk");
14         case IPMI_BOOTDEV_SAFE:
15                 return _("Safe Mode");
16         case IPMI_BOOTDEV_CDROM:
17                 return _("Optical");
18         case IPMI_BOOTDEV_SETUP:
19                 return _("Setup Mode");
20         default:
21                 return _("Unknown");
22         }
23 }
24
25 const char *device_type_display_name(enum device_type type)
26 {
27         switch (type) {
28         case DEVICE_TYPE_DISK:
29                 return _("Disk");
30         case DEVICE_TYPE_USB:
31                 return _("USB");
32         case DEVICE_TYPE_OPTICAL:
33                 return _("CD/DVD");
34         case DEVICE_TYPE_NETWORK:
35                 return _("Network");
36         case DEVICE_TYPE_ANY:
37                 return _("Any");
38         case DEVICE_TYPE_LUKS:
39                 return _("Encrypted Device");
40         case DEVICE_TYPE_UNKNOWN:
41         default:
42                 return _("Unknown");
43         }
44 }
45
46 const char *device_type_name(enum device_type type)
47 {
48         switch (type) {
49         case DEVICE_TYPE_DISK:
50                 return "disk";
51         case DEVICE_TYPE_USB:
52                 return "usb";
53         case DEVICE_TYPE_OPTICAL:
54                 return "optical";
55         case DEVICE_TYPE_NETWORK:
56                 return "network";
57         case DEVICE_TYPE_ANY:
58                 return "any";
59         case DEVICE_TYPE_LUKS:
60                 return "encrypted";
61         case DEVICE_TYPE_UNKNOWN:
62         default:
63                 return "unknown";
64         }
65 }
66
67 enum device_type find_device_type(const char *str)
68 {
69         if (!strncmp(str, "disk", strlen("disk")))
70                 return DEVICE_TYPE_DISK;
71         if (!strncmp(str, "usb", strlen("usb")))
72                 return DEVICE_TYPE_USB;
73         if (!strncmp(str, "optical", strlen("optical")))
74                 return DEVICE_TYPE_OPTICAL;
75         if (!strncmp(str, "network", strlen("network")))
76                 return DEVICE_TYPE_NETWORK;
77         if (!strncmp(str, "any", strlen("any")))
78                 return DEVICE_TYPE_ANY;
79         if (!strncmp(str, "encrypted", strlen("encrypted")))
80                 return DEVICE_TYPE_LUKS;
81
82         return DEVICE_TYPE_UNKNOWN;
83 }
84
85 bool config_autoboot_active(const struct config *config)
86 {
87         enum ipmi_bootdev bootdev = config->ipmi_bootdev;
88
89         if (!config->autoboot_enabled)
90                 return false;
91         if (bootdev == IPMI_BOOTDEV_SETUP || bootdev == IPMI_BOOTDEV_SAFE)
92                 return false;
93
94         return true;
95 }