* Deactivate some color code from Pico (as standalone editor) until
[alpine.git] / alpine / kblock.c
bloba10d52bc7f3f4861316a8fcece0c6e09727d4d6e
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: kblock.c 1025 2008-04-08 22:59:38Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2013-2017 Eduardo Chappa
8 * Copyright 2006-2008 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 #include "headers.h"
20 #include "kblock.h"
21 #include "status.h"
22 #include "titlebar.h"
23 #include "radio.h"
24 #include "../pith/conf.h"
25 #include "../pith/state.h"
27 #ifdef KEYBOARD_LOCK
31 * Internal prototypes
33 void redraw_kl_body(void);
34 void redraw_klocked_body(void);
35 void draw_klocked_body(char *, char *);
38 static char *klockin, *klockame;
41 void
42 redraw_kl_body(void)
44 ClearScreen();
46 set_titlebar(_("KEYBOARD LOCK"), ps_global->mail_stream,
47 ps_global->context_current, ps_global->cur_folder, NULL,
48 1, FolderName, 0, 0, NULL);
50 PutLine0(6,3 ,
51 _("You may lock this keyboard so that no one else can access your mail"));
52 PutLine0(8, 3 ,
53 _("while you are away. The screen will be locked after entering the "));
54 PutLine0(10, 3 ,
55 _("password to be used for unlocking the keyboard when you return."));
56 fflush(stdout);
60 void
61 redraw_klocked_body(void)
63 ClearScreen();
65 set_titlebar(_("KEYBOARD LOCK"), ps_global->mail_stream,
66 ps_global->context_current, ps_global->cur_folder, NULL,
67 1, FolderName, 0, 0, NULL);
69 PutLine2(6, 3, _("This keyboard is locked by %s <%s>."),klockame, klockin);
70 PutLine0(8, 3, _("To unlock, enter password used to lock the keyboard."));
71 fflush(stdout);
75 void
76 draw_klocked_body(char *login, char *username)
78 klockin = login;
79 klockame = username;
80 redraw_klocked_body();
84 /*----------------------------------------------------------------------
85 Execute the lock keyboard command
87 Args: None
89 Result: keyboard is locked until user gives password
90 ---*/
92 int
93 lock_keyboard(void)
95 struct pine *ps = ps_global;
96 char inpasswd[80], passwd[80], pw[80];
97 HelpType help = NO_HELP;
98 int i, times, old_suspend, flags;
100 passwd[0] = '\0';
101 redraw_kl_body();
102 ps->redrawer = redraw_kl_body;
104 times = atoi(ps->VAR_KBLOCK_PASSWD_COUNT);
105 if(times < 1 || times > 5){
106 dprint((2,
107 "Kblock-passwd-count var out of range (1 to 5) [%d]\n", times));
108 times = 1;
111 inpasswd[0] = '\0';
113 for(i = 0; i < times; i++){
114 pw[0] = '\0';
115 while(1){ /* input pasword to use for locking */
116 int rc;
117 char prompt[50];
119 if(i > 1)
120 snprintf(prompt, sizeof(prompt), _("Retype password to LOCK keyboard (Yes, again) : "));
121 else if(i)
122 snprintf(prompt, sizeof(prompt), _("Retype password to LOCK keyboard : "));
123 else
124 snprintf(prompt, sizeof(prompt), _("Enter password to LOCK keyboard : "));
126 flags = F_ON(F_QUELL_ASTERISKS, ps_global) ? OE_PASSWD_NOAST : OE_PASSWD;
127 rc = optionally_enter(pw, -FOOTER_ROWS(ps), 0, sizeof(pw),
128 prompt, NULL, help, &flags);
130 if(rc == 3)
131 help = help == NO_HELP ? h_kb_lock : NO_HELP;
132 else if(rc == 1 || pw[0] == '\0'){
133 q_status_message(SM_ORDER, 0, 2, _("Keyboard lock cancelled"));
134 return(-1);
136 else if(rc != 4)
137 break;
140 if(!inpasswd[0]){
141 strncpy(inpasswd, pw, sizeof(inpasswd));
142 inpasswd[sizeof(inpasswd)-1] = '\0';
144 else if(strcmp(inpasswd, pw)){
145 q_status_message(SM_ORDER, 0, 2,
146 _("Mismatch with initial password: keyboard lock cancelled"));
147 return(-1);
151 if(want_to(_("Really lock keyboard with entered password"), 'y', 'n',
152 NO_HELP, WT_NORM) != 'y'){
153 q_status_message(SM_ORDER, 0, 2, _("Keyboard lock cancelled"));
154 return(-1);
157 draw_klocked_body(ps->VAR_USER_ID ? ps->VAR_USER_ID : "<no-user>",
158 ps->VAR_PERSONAL_NAME ? ps->VAR_PERSONAL_NAME : "<no-name>");
160 ps->redrawer = redraw_klocked_body;
161 if((old_suspend = F_ON(F_CAN_SUSPEND, ps_global)) != 0)
162 F_TURN_OFF(F_CAN_SUSPEND, ps_global);
164 while(strcmp(inpasswd, passwd)){
165 if(passwd[0])
166 q_status_message(SM_ORDER | SM_DING, 3, 3,
167 _("Password to UNLOCK doesn't match password used to LOCK"));
169 help = NO_HELP;
170 while(1){
171 int rc;
173 flags = OE_DISALLOW_CANCEL
174 | (F_ON(F_QUELL_ASTERISKS, ps_global) ? OE_PASSWD_NOAST : OE_PASSWD);
175 rc = optionally_enter(passwd, -FOOTER_ROWS(ps), 0, sizeof(passwd),
176 _("Enter password to UNLOCK keyboard : "),NULL,
177 help, &flags);
178 if(rc == 3) {
179 help = help == NO_HELP ? h_oe_keylock : NO_HELP;
180 continue;
183 if(rc != 4)
184 break;
188 if(old_suspend)
189 F_TURN_ON(F_CAN_SUSPEND, ps_global);
191 q_status_message(SM_ORDER, 0, 3, _("Keyboard Unlocked"));
192 return(0);
196 #endif /* KEYBOARD_LOCK */