diff options
Diffstat (limited to 'security/tomoyo/util.c')
-rw-r--r-- | security/tomoyo/util.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/security/tomoyo/util.c b/security/tomoyo/util.c index daf7a45f70f1..7ff54c95e1f2 100644 --- a/security/tomoyo/util.c +++ b/security/tomoyo/util.c | |||
@@ -47,6 +47,47 @@ const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX] = { | |||
47 | }; | 47 | }; |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * tomoyo_convert_time - Convert time_t to YYYY/MM/DD hh/mm/ss. | ||
51 | * | ||
52 | * @time: Seconds since 1970/01/01 00:00:00. | ||
53 | * @stamp: Pointer to "struct tomoyo_time". | ||
54 | * | ||
55 | * Returns nothing. | ||
56 | * | ||
57 | * This function does not handle Y2038 problem. | ||
58 | */ | ||
59 | void tomoyo_convert_time(time_t time, struct tomoyo_time *stamp) | ||
60 | { | ||
61 | static const u16 tomoyo_eom[2][12] = { | ||
62 | { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, | ||
63 | { 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } | ||
64 | }; | ||
65 | u16 y; | ||
66 | u8 m; | ||
67 | bool r; | ||
68 | stamp->sec = time % 60; | ||
69 | time /= 60; | ||
70 | stamp->min = time % 60; | ||
71 | time /= 60; | ||
72 | stamp->hour = time % 24; | ||
73 | time /= 24; | ||
74 | for (y = 1970; ; y++) { | ||
75 | const unsigned short days = (y & 3) ? 365 : 366; | ||
76 | if (time < days) | ||
77 | break; | ||
78 | time -= days; | ||
79 | } | ||
80 | r = (y & 3) == 0; | ||
81 | for (m = 0; m < 11 && time >= tomoyo_eom[r][m]; m++) | ||
82 | ; | ||
83 | if (m) | ||
84 | time -= tomoyo_eom[r][m - 1]; | ||
85 | stamp->year = y; | ||
86 | stamp->month = ++m; | ||
87 | stamp->day = ++time; | ||
88 | } | ||
89 | |||
90 | /** | ||
50 | * tomoyo_permstr - Find permission keywords. | 91 | * tomoyo_permstr - Find permission keywords. |
51 | * | 92 | * |
52 | * @string: String representation for permissions in foo/bar/buz format. | 93 | * @string: String representation for permissions in foo/bar/buz format. |