Add support for tab-completion when selecting by rule
[alpine.git] / alpine / kblock.c
blob5b8658abd554e033db448f5c56814df6fb051509
1 /*
2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006-2008 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 #include "headers.h"
16 #include "kblock.h"
17 #include "status.h"
18 #include "titlebar.h"
19 #include "radio.h"
20 #include "../pith/conf.h"
21 #include "../pith/state.h"
23 #ifdef KEYBOARD_LOCK
27 * Internal prototypes
29 void redraw_kl_body(void);
30 void redraw_klocked_body(void);
31 void draw_klocked_body(char *, char *);
34 static char *klockin, *klockame;
37 void
38 redraw_kl_body(void)
40 ClearScreen();
42 set_titlebar(_("KEYBOARD LOCK"), ps_global->mail_stream,
43 ps_global->context_current, ps_global->cur_folder, NULL,
44 1, FolderName, 0, 0, NULL);
46 PutLine0(6,3 ,
47 _("You may lock this keyboard so that no one else can access your mail"));
48 PutLine0(8, 3 ,
49 _("while you are away. The screen will be locked after entering the "));
50 PutLine0(10, 3 ,
51 _("password to be used for unlocking the keyboard when you return."));
52 fflush(stdout);
56 void
57 redraw_klocked_body(void)
59 ClearScreen();
61 set_titlebar(_("KEYBOARD LOCK"), ps_global->mail_stream,
62 ps_global->context_current, ps_global->cur_folder, NULL,
63 1, FolderName, 0, 0, NULL);
65 PutLine2(6, 3, _("This keyboard is locked by %s <%s>."),klockame, klockin);
66 PutLine0(8, 3, _("To unlock, enter password used to lock the keyboard."));
67 fflush(stdout);
71 void
72 draw_klocked_body(char *login, char *username)
74 klockin = login;
75 klockame = username;
76 redraw_klocked_body();
80 /*----------------------------------------------------------------------
81 Execute the lock keyboard command
83 Args: None
85 Result: keyboard is locked until user gives password
86 ---*/
88 int
89 lock_keyboard(void)
91 struct pine *ps = ps_global;
92 char inpasswd[80], passwd[80], pw[80];
93 HelpType help = NO_HELP;
94 int i, times, old_suspend, flags;
96 passwd[0] = '\0';
97 redraw_kl_body();
98 ps->redrawer = redraw_kl_body;
100 times = atoi(ps->VAR_KBLOCK_PASSWD_COUNT);
101 if(times < 1 || times > 5){
102 dprint((2,
103 "Kblock-passwd-count var out of range (1 to 5) [%d]\n", times));
104 times = 1;
107 inpasswd[0] = '\0';
109 for(i = 0; i < times; i++){
110 pw[0] = '\0';
111 while(1){ /* input password to use for locking */
112 int rc;
113 char prompt[50];
115 if(i > 1)
116 snprintf(prompt, sizeof(prompt), _("Retype password to LOCK keyboard (Yes, again) : "));
117 else if(i)
118 snprintf(prompt, sizeof(prompt), _("Retype password to LOCK keyboard : "));
119 else
120 snprintf(prompt, sizeof(prompt), _("Enter password to LOCK keyboard : "));
122 flags = F_ON(F_QUELL_ASTERISKS, ps_global) ? OE_PASSWD_NOAST : OE_PASSWD;
123 rc = optionally_enter(pw, -FOOTER_ROWS(ps), 0, sizeof(pw),
124 prompt, NULL, help, &flags);
126 if(rc == 3)
127 help = help == NO_HELP ? h_kb_lock : NO_HELP;
128 else if(rc == 1 || pw[0] == '\0'){
129 q_status_message(SM_ORDER, 0, 2, _("Keyboard lock cancelled"));
130 return(-1);
132 else if(rc != 4)
133 break;
136 if(!inpasswd[0]){
137 strncpy(inpasswd, pw, sizeof(inpasswd));
138 inpasswd[sizeof(inpasswd)-1] = '\0';
140 else if(strcmp(inpasswd, pw)){
141 q_status_message(SM_ORDER, 0, 2,
142 _("Mismatch with initial password: keyboard lock cancelled"));
143 return(-1);
147 if(want_to(_("Really lock keyboard with entered password"), 'y', 'n',
148 NO_HELP, WT_NORM) != 'y'){
149 q_status_message(SM_ORDER, 0, 2, _("Keyboard lock cancelled"));
150 return(-1);
153 draw_klocked_body(ps->VAR_USER_ID ? ps->VAR_USER_ID : "<no-user>",
154 ps->VAR_PERSONAL_NAME ? ps->VAR_PERSONAL_NAME : "<no-name>");
156 ps->redrawer = redraw_klocked_body;
157 if((old_suspend = F_ON(F_CAN_SUSPEND, ps_global)) != 0)
158 F_TURN_OFF(F_CAN_SUSPEND, ps_global);
160 while(strcmp(inpasswd, passwd)){
161 if(passwd[0])
162 q_status_message(SM_ORDER | SM_DING, 3, 3,
163 _("Password to UNLOCK doesn't match password used to LOCK"));
165 help = NO_HELP;
166 while(1){
167 int rc;
169 flags = OE_DISALLOW_CANCEL
170 | (F_ON(F_QUELL_ASTERISKS, ps_global) ? OE_PASSWD_NOAST : OE_PASSWD);
171 rc = optionally_enter(passwd, -FOOTER_ROWS(ps), 0, sizeof(passwd),
172 _("Enter password to UNLOCK keyboard : "),NULL,
173 help, &flags);
174 if(rc == 3) {
175 help = help == NO_HELP ? h_oe_keylock : NO_HELP;
176 continue;
179 if(rc != 4)
180 break;
184 if(old_suspend)
185 F_TURN_ON(F_CAN_SUSPEND, ps_global);
187 q_status_message(SM_ORDER, 0, 3, _("Keyboard Unlocked"));
188 return(0);
192 #endif /* KEYBOARD_LOCK */