~ubuntu-branches/debian/stretch/alpine/stretch

« back to all changes in this revision

Viewing changes to alpine/kblock.c

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2007-02-17 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070217131742-99x5c6cpg1pbkdhw
Tags: upstream-0.82+dfsg
ImportĀ upstreamĀ versionĀ 0.82+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if !defined(lint) && !defined(DOS)
 
2
static char rcsid[] = "$Id: kblock.c 140 2006-09-26 19:30:49Z hubert@u.washington.edu $";
 
3
#endif
 
4
 
 
5
/*
 
6
 * ========================================================================
 
7
 * Copyright 2006 University of Washington
 
8
 *
 
9
 * Licensed under the Apache License, Version 2.0 (the "License");
 
10
 * you may not use this file except in compliance with the License.
 
11
 * You may obtain a copy of the License at
 
12
 *
 
13
 *     http://www.apache.org/licenses/LICENSE-2.0
 
14
 *
 
15
 * ========================================================================
 
16
 */
 
17
 
 
18
#ifndef NO_KEYBOARD_LOCK
 
19
 
 
20
#include "headers.h"
 
21
#include "kblock.h"
 
22
#include "status.h"
 
23
#include "titlebar.h"
 
24
#include "radio.h"
 
25
#include "../pith/conf.h"
 
26
#include "../pith/state.h"
 
27
 
 
28
 
 
29
/*
 
30
 * Internal prototypes
 
31
 */
 
32
void     redraw_kl_body(void);
 
33
void     redraw_klocked_body(void);
 
34
void     draw_klocked_body(char *, char *);
 
35
 
 
36
 
 
37
static char *klockin, *klockame;
 
38
 
 
39
 
 
40
void
 
41
redraw_kl_body(void)
 
42
{
 
43
    ClearScreen();
 
44
 
 
45
    set_titlebar(_("KEYBOARD LOCK"), ps_global->mail_stream,
 
46
                 ps_global->context_current, ps_global->cur_folder, NULL,
 
47
                 1, FolderName, 0, 0, NULL);
 
48
 
 
49
    PutLine0(6,3 ,
 
50
       _("You may lock this keyboard so that no one else can access your mail"));
 
51
    PutLine0(8, 3 ,
 
52
       _("while you are away.  The screen will be locked after entering the "));
 
53
    PutLine0(10, 3 ,
 
54
       _("password to be used for unlocking the keyboard when you return."));
 
55
    fflush(stdout);
 
56
}
 
57
 
 
58
 
 
59
void
 
60
redraw_klocked_body(void)
 
61
{
 
62
    ClearScreen();
 
63
 
 
64
    set_titlebar(_("KEYBOARD LOCK"), ps_global->mail_stream,
 
65
                 ps_global->context_current, ps_global->cur_folder, NULL,
 
66
                 1, FolderName, 0, 0, NULL);
 
67
 
 
68
    PutLine2(6, 3, _("This keyboard is locked by %s <%s>."),klockame, klockin);
 
69
    PutLine0(8, 3, _("To unlock, enter password used to lock the keyboard."));
 
70
    fflush(stdout);
 
71
}
 
72
 
 
73
 
 
74
void
 
75
draw_klocked_body(char *login, char *username)
 
76
{
 
77
    klockin = login;
 
78
    klockame = username;
 
79
    redraw_klocked_body();
 
80
}
 
81
 
 
82
 
 
83
/*----------------------------------------------------------------------
 
84
          Execute the lock keyboard command
 
85
 
 
86
    Args: None
 
87
 
 
88
  Result: keyboard is locked until user gives password
 
89
  ---*/
 
90
 
 
91
lock_keyboard(void)
 
92
{
 
93
    struct pine *ps = ps_global;
 
94
    char inpasswd[80], passwd[80], pw[80];
 
95
    HelpType help = NO_HELP;
 
96
    int i, times, old_suspend, flags;
 
97
 
 
98
    passwd[0] = '\0';
 
99
    redraw_kl_body();
 
100
    ps->redrawer = redraw_kl_body;
 
101
 
 
102
    times = atoi(ps->VAR_KBLOCK_PASSWD_COUNT);
 
103
    if(times < 1 || times > 5){
 
104
        dprint((2,
 
105
        "Kblock-passwd-count var out of range (1 to 5) [%d]\n", times));
 
106
        times = 1;
 
107
    }
 
108
 
 
109
    inpasswd[0] = '\0';
 
110
 
 
111
    for(i = 0; i < times; i++){
 
112
        pw[0] = '\0';
 
113
        while(1){                       /* input pasword to use for locking */
 
114
            int rc;
 
115
            char prompt[50];
 
116
 
 
117
            if(i > 1)
 
118
              snprintf(prompt, sizeof(prompt), _("Retype password to LOCK keyboard (Yes, again) : "));
 
119
            else if(i)
 
120
              snprintf(prompt, sizeof(prompt), _("Retype password to LOCK keyboard : "));
 
121
            else
 
122
              snprintf(prompt, sizeof(prompt), _("Enter password to LOCK keyboard : "));
 
123
 
 
124
            flags = OE_PASSWD;
 
125
            rc =  optionally_enter(pw, -FOOTER_ROWS(ps), 0, sizeof(pw),
 
126
                                    prompt, NULL, help, &flags);
 
127
 
 
128
            if(rc == 3)
 
129
              help = help == NO_HELP ? h_kb_lock : NO_HELP;
 
130
            else if(rc == 1 || pw[0] == '\0'){
 
131
                q_status_message(SM_ORDER, 0, 2, _("Keyboard lock cancelled"));
 
132
                return(-1);
 
133
            }
 
134
            else if(rc != 4)
 
135
              break;
 
136
        }
 
137
 
 
138
        if(!inpasswd[0]){
 
139
            strncpy(inpasswd, pw, sizeof(inpasswd));
 
140
            inpasswd[sizeof(inpasswd)-1] = '\0';
 
141
        }
 
142
        else if(strcmp(inpasswd, pw)){
 
143
            q_status_message(SM_ORDER, 0, 2,
 
144
                _("Mismatch with initial password: keyboard lock cancelled"));
 
145
            return(-1);
 
146
        }
 
147
    }
 
148
 
 
149
    if(want_to(_("Really lock keyboard with entered password"), 'y', 'n',
 
150
               NO_HELP, WT_NORM) != 'y'){
 
151
        q_status_message(SM_ORDER, 0, 2, _("Keyboard lock cancelled"));
 
152
        return(-1);
 
153
    }
 
154
 
 
155
    draw_klocked_body(ps->VAR_USER_ID ? ps->VAR_USER_ID : "<no-user>",
 
156
                  ps->VAR_PERSONAL_NAME ? ps->VAR_PERSONAL_NAME : "<no-name>");
 
157
 
 
158
    ps->redrawer = redraw_klocked_body;
 
159
    if(old_suspend = F_ON(F_CAN_SUSPEND, ps_global))
 
160
      F_TURN_OFF(F_CAN_SUSPEND, ps_global);
 
161
 
 
162
    while(strcmp(inpasswd, passwd)){
 
163
        if(passwd[0])
 
164
          q_status_message(SM_ORDER | SM_DING, 3, 3,
 
165
                     _("Password to UNLOCK doesn't match password used to LOCK"));
 
166
        
 
167
        help = NO_HELP;
 
168
        while(1){
 
169
            int rc;
 
170
 
 
171
            flags = OE_PASSWD | OE_DISALLOW_CANCEL;
 
172
            rc =  optionally_enter(passwd, -FOOTER_ROWS(ps), 0, sizeof(passwd),
 
173
                                   _("Enter password to UNLOCK keyboard : "),NULL,
 
174
                                   help, &flags);
 
175
            if(rc == 3) {
 
176
                help = help == NO_HELP ? h_oe_keylock : NO_HELP;
 
177
                continue;
 
178
            }
 
179
 
 
180
            if(rc != 4)
 
181
              break;
 
182
        }
 
183
    }
 
184
 
 
185
    if(old_suspend)
 
186
      F_TURN_ON(F_CAN_SUSPEND, ps_global);
 
187
 
 
188
    q_status_message(SM_ORDER, 0, 3, _("Keyboard Unlocked"));
 
189
    return(0);
 
190
}
 
191
 
 
192
 
 
193
#endif /* !NO_KEYBOARD_LOCK */