-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmytap-user-576.sql
142 lines (107 loc) · 3.51 KB
/
mytap-user-576.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
User features introduced in MySQL 5.7.6
Schema changes added columns
password_expired
password_last_changed
password_lifetime
account_locked
*/
USE tap;
DELIMITER //
/****************************************************************************/
-- check user is not disabled
-- _user_ok( host, user )
DROP FUNCTION IF EXISTS _user_ok //
CREATE FUNCTION _user_ok(hname CHAR(60), uname CHAR(32))
RETURNS BOOLEAN
DETERMINISTIC
BEGIN
DECLARE ret BOOLEAN;
SELECT 1 INTO ret
FROM tap.mysql__user
WHERE `host` = hname
AND `user` = uname
AND `password_expired` <> 'Y'
AND `account_locked` <> 'Y';
RETURN COALESCE(ret, 0);
END //
-- user_ok(host, user, description )
DROP FUNCTION IF EXISTS user_ok //
CREATE FUNCTION user_ok(hname CHAR(60), uname CHAR(32), description TEXT)
RETURNS TEXT
DETERMINISTIC
BEGIN
IF description = '' THEN
SET description = CONCAT('User \'', uname, '\'@\'',
hname, '\' should not be locked or have expired password');
END IF;
IF NOT _has_user(hname, uname) THEN
RETURN CONCAT(ok(FALSE, description), '\n',
diag(CONCAT('User \'', uname, '\'@\'', hname, '\' does not exist')));
END IF;
RETURN ok(_user_ok(hname, uname), description);
END //
-- user_not_ok(host, user, description )
DROP FUNCTION IF EXISTS user_not_ok //
CREATE FUNCTION user_not_ok(hname CHAR(60), uname CHAR(32), description TEXT)
RETURNS TEXT
DETERMINISTIC
BEGIN
IF description = '' THEN
SET description = CONCAT('User \'', uname, '\'@\'',
hname, '\' should be locked out or have an expired password');
END IF;
IF NOT _has_user(hname, uname) THEN
RETURN CONCAT(ok(FALSE, description), '\n',
diag(CONCAT('User \'', uname, '\'@\'', hname, '\' does not exist')));
END IF;
RETURN ok(NOT _user_ok( hname, uname ), description);
END //
/****************************************************************************/
-- PASSWORD LIFETIME
-- _user_has_lifetime( host, user )
DROP FUNCTION IF EXISTS _user_has_lifetime //
CREATE FUNCTION _user_has_lifetime (hname CHAR(60), uname CHAR(32))
RETURNS BOOLEAN
DETERMINISTIC
BEGIN
DECLARE ret BOOLEAN;
SELECT 1 INTO ret
FROM tap.mysql__user
WHERE `Host` = hname
AND `User` = uname
AND `password_lifetime` IS NOT NULL AND `password_lifetime` != 0;
RETURN COALESCE(ret, 0);
END //
-- user_has_lifetime( host, user, description )
DROP FUNCTION IF EXISTS user_has_lifetime//
CREATE FUNCTION user_has_lifetime(hname CHAR(60), uname CHAR(32), description TEXT)
RETURNS TEXT
DETERMINISTIC
BEGIN
IF description = '' THEN
SET description = CONCAT('User \'', uname, '\'@\'', hname, '\' Password should expire');
END IF;
IF NOT _has_user(hname, uname) THEN
RETURN CONCAT(ok(FALSE, description), '\n',
diag(CONCAT('User \'', uname, '\'@\'', hname, '\' does not exist')));
END IF;
RETURN ok(_user_has_lifetime(hname, uname), description);
END //
-- user_hasnt_lifetime( host, user, description )
DROP FUNCTION IF EXISTS user_hasnt_lifetime //
CREATE FUNCTION user_hasnt_lifetime(hname CHAR(60), uname CHAR(32), description TEXT)
RETURNS TEXT
DETERMINISTIC
BEGIN
IF description = '' THEN
SET description = CONCAT('User \'', uname, '\'@\'', hname, '\' Password should not expire');
END IF;
IF NOT _has_user(hname, uname) THEN
RETURN CONCAT(ok(FALSE, description), '\n',
diag(CONCAT('User \'', uname, '\'@\'', hname, '\' does not exist')));
END IF;
RETURN ok(NOT _user_has_lifetime(hname, uname), description);
END //
/****************************************************************************/
DELIMITER ;