Deleted Added
full compact
check-password.4th (256281) check-password.4th (281843)
1\ Copyright (c) 2006-2012 Devin Teske <dteske@FreeBSD.org>
1\ Copyright (c) 2006-2015 Devin Teske <dteske@FreeBSD.org>
2\ All rights reserved.
3\
4\ Redistribution and use in source and binary forms, with or without
5\ modification, are permitted provided that the following conditions
6\ are met:
7\ 1. Redistributions of source code must retain the above copyright
8\ notice, this list of conditions and the following disclaimer.
9\ 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

17\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23\ SUCH DAMAGE.
24\
2\ All rights reserved.
3\
4\ Redistribution and use in source and binary forms, with or without
5\ modification, are permitted provided that the following conditions
6\ are met:
7\ 1. Redistributions of source code must retain the above copyright
8\ notice, this list of conditions and the following disclaimer.
9\ 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

17\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23\ SUCH DAMAGE.
24\
25\ $FreeBSD: stable/10/sys/boot/forth/check-password.4th 244158 2012-12-12 17:49:01Z dteske $
25\ $FreeBSD: stable/10/sys/boot/forth/check-password.4th 281843 2015-04-22 01:08:40Z dteske $
26
27marker task-check-password.4th
28
29include /boot/screen.4th
30
26
27marker task-check-password.4th
28
29include /boot/screen.4th
30
3113 constant enter_key \ The decimal ASCII value for Enter key
328 constant bs_key \ The decimal ASCII value for Backspace key
3316 constant readmax \ Maximum number of characters for the password
31vocabulary password-processing
32only forth also password-processing definitions
34
33
35variable readX \ Current X offset (column)(used by read)
36variable read-start \ Starting X offset (column)(used by read)
3413 constant enter_key \ The decimal ASCII value for Enter key
358 constant bs_key \ The decimal ASCII value for Backspace key
3621 constant ctrl_u \ The decimal ASCII value for Ctrl-U sequence
37255 constant readmax \ Maximum number of characters for the password
37
38
38create readval 16 allot \ input obtained (maximum 16 characters)
39variable readlen \ input length
39variable read-tick \ Twiddle position (used by read)
40variable read-start \ Starting X offset (column)(used by read)
40
41
42create readval readmax allot \ input obtained (up to readmax characters)
43variable readlen \ input length
44
41\ This function blocks program flow (loops forever) until a key is pressed.
42\ The key that was pressed is added to the top of the stack in the form of its
43\ decimal ASCII representation. Note: the stack cannot be empty when this
44\ function starts or an underflow exception will occur. Simplest way to prevent
45\ this is to pass 0 as a stack parameter (ie. `0 sgetkey'). This function is
46\ called by the read function. You need not call it directly. NOTE: arrow keys
47\ show as 0 on the stack
48\
49: sgetkey ( -- )
50
45\ This function blocks program flow (loops forever) until a key is pressed.
46\ The key that was pressed is added to the top of the stack in the form of its
47\ decimal ASCII representation. Note: the stack cannot be empty when this
48\ function starts or an underflow exception will occur. Simplest way to prevent
49\ this is to pass 0 as a stack parameter (ie. `0 sgetkey'). This function is
50\ called by the read function. You need not call it directly. NOTE: arrow keys
51\ show as 0 on the stack
52\
53: sgetkey ( -- )
54
51 begin \ Loop forever
52 key? if \ Was a key pressed? (see loader(8))
55 begin \ Loop forever
56 key? if \ Was a key pressed? (see loader(8))
57 drop \ Remove stack-cruft
58 key \ Get the key that was pressed
53
59
54 drop \ Remove stack-cruft
55 key \ Get the key that was pressed
60 \ Check key pressed (see loader(8)) and input limit
61 dup 0<> if ( and ) readlen @ readmax < if
62 \ Spin the twiddle and then exit this function
63 read-tick @ dup 1+ 4 mod read-tick !
64 2 spaces
65 dup 0 = if ( 1 ) ." /" else
66 dup 1 = if ( 2 ) ." -" else
67 dup 2 = if ( 3 ) ." \" else
68 dup 3 = if ( 4 ) ." |" else
69 1 spaces
70 then then then then drop
71 read-start @ 25 at-xy
72 exit
73 then then
56
74
57 \ Check key pressed (see loader(8)) and input limit
58 dup 0<> if ( and ) readlen @ readmax < if
75 \ Always allow Backspace, Enter, and Ctrl-U
76 dup bs_key = if exit then
77 dup enter_key = if exit then
78 dup ctrl_u = if exit then
79 then
80 50 ms \ Sleep for 50 milliseconds (see loader(8))
81 again
82;
59
83
60 \ Echo an asterisk (unless Backspace/Enter)
61 dup bs_key <> if ( and ) dup enter_key <> if
62 ." *" \ Echo an asterisk
63 then then
84: cfill ( c c-addr/u -- )
85 begin dup 0> while
86 -rot 2dup c! 1+ rot 1-
87 repeat 2drop drop
88;
64
89
65 exit \ Exit from the function
66 then then
67
68 \ Always allow Backspace and Enter
69 dup bs_key = if exit then
70 dup enter_key = if exit then
71
72 then
73 50 ms \ Sleep for 50 milliseconds (see loader(8))
74 again
90: read-reset ( -- )
91 0 readlen !
92 0 readval readmax cfill
75;
76
93;
94
77: read ( String prompt -- )
95: read ( c-addr/u -- ) \ Expects string prompt as stack input
78
79 0 25 at-xy \ Move the cursor to the bottom-left
80 dup 1+ read-start ! \ Store X offset after the prompt
96
97 0 25 at-xy \ Move the cursor to the bottom-left
98 dup 1+ read-start ! \ Store X offset after the prompt
81 read-start @ readX ! \ copy value to the current X offset
82 0 readlen ! \ Initialize the read length
83 type \ Print the prompt
84
85 begin \ Loop forever
86
87 0 sgetkey \ Block here, waiting for a key to be pressed
88
89 \ We are not going to echo the password to the screen (for
90 \ security reasons). If Enter is pressed, we process the
91 \ password, otherwise augment the key to a string.
92
99 0 readlen ! \ Initialize the read length
100 type \ Print the prompt
101
102 begin \ Loop forever
103
104 0 sgetkey \ Block here, waiting for a key to be pressed
105
106 \ We are not going to echo the password to the screen (for
107 \ security reasons). If Enter is pressed, we process the
108 \ password, otherwise augment the key to a string.
109
93 \ If the key that was entered was not Enter, advance
94 dup enter_key <> if
95 readX @ 1+ readX ! \ Advance the column
96 readlen @ 1+ readlen ! \ Increment input length
97 then
98
99 \ Handle backspacing
100 dup bs_key = if
101 readX @ 2 - readX ! \ Set new cursor position
102 readlen @ 2 - readlen ! \ Decrement input length
103
104 \ Don't move behind starting position
105 readX @ read-start @ < if
106 read-start @ readX !
107 then
108 readlen @ 0< if
109 0 readlen !
110 then
111
112 \ Reposition cursor and erase character
113 readX @ 25 at-xy 1 spaces readX @ 25 at-xy
114 then
115
116 dup enter_key = if
110 dup enter_key = if
117 drop \ Clean up stack cruft
118 10 emit \ Echo new line
111 drop \ Clean up stack cruft
112 3 spaces \ Erase the twiddle
113 10 emit \ Echo new line
119 exit
114 exit
120 then
115 else dup ctrl_u = if
116 3 spaces read-start @ 25 at-xy \ Erase the twiddle
117 0 readlen ! \ Reset input to NULL
118 else dup bs_key = if
119 readlen @ 1 - dup readlen ! \ Decrement input length
120 dup 0< if drop 0 dup readlen ! then \ Don't go negative
121 0= if 3 spaces read-start @ 25 at-xy then \ Twiddle
122 else dup \ Store the character
123 \ NB: sgetkey prevents overflow by way of blocking
124 \ at readmax except for Backspace or Enter
125 readlen @ 1+ dup readlen ! 1- readval + c!
126 then then then
121
127
122 \ If not Backspace or Enter, store the character
123 dup bs_key <> if ( and ) dup enter_key <> if
124
125 \ store the character in our buffer
126 dup readval readlen @ 1- + c!
127
128 then then
129
130 drop \ drop the last key that was entered
131
128 drop \ last key pressed
132 again \ Enter was not pressed; repeat
133;
134
129 again \ Enter was not pressed; repeat
130;
131
132only forth definitions also password-processing
133
135: check-password ( -- )
136
137 \ Do not allow the user to proceed beyond this point if a boot-lock
138 \ password has been set (preventing even boot from proceeding)
139 s" bootlock_password" getenv dup -1 <> if
134: check-password ( -- )
135
136 \ Do not allow the user to proceed beyond this point if a boot-lock
137 \ password has been set (preventing even boot from proceeding)
138 s" bootlock_password" getenv dup -1 <> if
139 dup readmax > if drop readmax then
140 begin
141 s" Boot Password: " read ( prompt -- )
142 2dup readval readlen @ compare 0<>
143 while
144 3000 ms ." loader: incorrect password" 10 emit
145 repeat
140 begin
141 s" Boot Password: " read ( prompt -- )
142 2dup readval readlen @ compare 0<>
143 while
144 3000 ms ." loader: incorrect password" 10 emit
145 repeat
146 2drop ( c-addr/u )
147 else
148 drop ( -1 ) \ getenv cruft
149 then
146 2drop read-reset
147 else drop then
150
148
149 \ Prompt for GEOM ELI (geli(8)) passphrase if enabled
150 s" geom_eli_passphrase_prompt" getenv dup -1 <> if
151 s" YES" compare-insensitive 0= if
152 s" GELI Passphrase: " read ( prompt -- )
153 readval readlen @ s" kern.geom.eli.passphrase" setenv
154 read-reset
155 then
156 else drop then
157
151 \ Exit if a password was not set
152 s" password" getenv -1 = if exit else drop then
153
154 \ We should prevent the user from visiting the menu or dropping to the
155 \ interactive loader(8) prompt, but still allow the machine to boot...
156
157 0 autoboot
158
159 \ Only reached if autoboot fails for any reason (including if/when
160 \ the user aborts/escapes the countdown sequence leading to boot).
161
158 \ Exit if a password was not set
159 s" password" getenv -1 = if exit else drop then
160
161 \ We should prevent the user from visiting the menu or dropping to the
162 \ interactive loader(8) prompt, but still allow the machine to boot...
163
164 0 autoboot
165
166 \ Only reached if autoboot fails for any reason (including if/when
167 \ the user aborts/escapes the countdown sequence leading to boot).
168
162 s" password" getenv
169 s" password" getenv dup readmax > if drop readmax then
163 begin
164 s" Password: " read ( prompt -- )
170 begin
171 s" Password: " read ( prompt -- )
165 2dup readval readlen @ compare 0= if
166 2drop exit \ Correct password
172 2dup readval readlen @ compare 0= if \ Correct password?
173 2drop read-reset exit
167 then
168 3000 ms ." loader: incorrect password" 10 emit
169 again
170;
174 then
175 3000 ms ." loader: incorrect password" 10 emit
176 again
177;
178
179only forth definitions