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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
/* x11-ssh-askpass.h: A generic X11-based password dialog for OpenSSH.
* created 1999-Nov-17 03:40 Jim Knoble <jmknoble@jmknoble.cx>
* autodate: 2001-Feb-14 04:00
*
* by Jim Knoble <jmknoble@jmknoble.cx>
* Copyright (C) 1999,2000,2001 Jim Knoble
*
* Disclaimer:
*
* The software is provided "as is", without warranty of any kind,
* express or implied, including but not limited to the warranties of
* merchantability, fitness for a particular purpose and
* noninfringement. In no event shall the author(s) be liable for any
* claim, damages or other liability, whether in an action of
* contract, tort or otherwise, arising from, out of or in connection
* with the software or the use or other dealings in the software.
*
* Portions of this code are distantly derived from code in xscreensaver
* by Jamie Zawinski <jwz@jwz.org>. That code says:
*
* --------8<------------------------------------------------8<--------
* xscreensaver, Copyright (c) 1991-1999 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
* --------8<------------------------------------------------8<--------
*
* The remainder of this code falls under the same permissions and
* provisions as those of the xscreensaver code.
*/
#ifndef H_X11_SSH_ASKPASS
#define H_X11_SSH_ASKPASS
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#define EXIT_STATUS_ACCEPT 0
#define EXIT_STATUS_CANCEL 1
#define EXIT_STATUS_NO_MEMORY 2
#define EXIT_STATUS_ERROR 3
#define EXIT_STATUS_TIMEOUT 4
#define EXIT_STATUS_ANOMALY 127
typedef struct
{
Pixel foreground;
Pixel background;
Dimension width;
Dimension height;
Position x;
Position y;
} WidgetInfo;
typedef struct
{
WidgetInfo w;
Pixel topShadowColor;
Pixel bottomShadowColor;
Dimension shadowThickness;
Pixel borderColor;
Dimension borderWidth;
Dimension interiorWidth;
Dimension interiorHeight;
Dimension horizontalSpacing;
Dimension verticalSpacing;
} Widget3dInfo;
typedef struct TextObjectStruct
{
char *text;
int textLength;
int direction;
int ascent;
int descent;
XCharStruct overall;
struct TextObjectStruct *next;
} TextObject;
typedef struct
{
char *fullText;
XFontStruct *font;
TextObject *multiText;
WidgetInfo w;
} LabelInfo;
typedef struct
{
Widget3dInfo w3;
LabelInfo label;
Bool pressed;
} ButtonInfo;
typedef struct
{
Widget3dInfo w3;
int count;
int current;
int minimumCount;
int maximumCount;
} MasterIndicatorInfo;
typedef struct
{
MasterIndicatorInfo *parent;
WidgetInfo w;
Bool isLit;
} IndicatorElement;
typedef struct
{
Window dialogWindow;
XSizeHints *sizeHints;
XWMHints *wmHints;
XClassHint *classHints;
XTextProperty windowName;
char *title;
Widget3dInfo w3;
LabelInfo label;
MasterIndicatorInfo indicator;
IndicatorElement *indicators;
ButtonInfo okButton;
ButtonInfo cancelButton;
int pressedButton;
} DialogInfo;
#define NO_BUTTON 0
#define OK_BUTTON 1
#define CANCEL_BUTTON 2
typedef struct
{
char *appName;
char *appClass;
int argc;
char **argv;
pid_t pid;
char *buf;
int bufSize;
int bufIndex;
Display *dpy;
Screen *screen;
long screen_width;
long screen_height;
Window rootWindow;
Pixel black;
Pixel white;
Colormap colormap;
/* Resolution measurements are normalized to dots/meter. */
long xResolution;
long yResolution;
long defaultXResolution;
long defaultYResolution;
long xFuzz;
long yFuzz;
XtAppContext appContext;
Widget toplevelShell;
XrmDatabase resourceDb;
Atom wmDeleteWindowAtom;
GC fillGC;
GC borderGC;
GC textGC;
GC brightGC;
GC dimGC;
long eventMask;
Bool grabKeyboard;
Bool grabPointer;
Bool grabServer;
Bool isKeyboardGrabbed;
Bool isPointerGrabbed;
Bool isServerGrabbed;
unsigned int grabFailTimeout;
unsigned int grabRetryInterval;
unsigned long inputTimeout;
XtIntervalId inputTimeoutTimerId;
Bool inputTimeoutActive;
DialogInfo *dialog;
} AppInfo;
void outOfMemory(AppInfo *app, int line);
void freeIf(void *p);
void freeFontIf(AppInfo *app, XFontStruct *f);
XFontStruct *getFontResource(AppInfo *app, char *instanceName, char *className);
char *getStringResourceWithDefault(char *instanceName, char *className,
char *defaultText);
unsigned int getUnsignedIntegerResource(AppInfo *app, char *instanceName,
char *className,
unsigned int defaultValue);
long getResolutionResource(AppInfo *app, char *instanceName, char *className,
char *defaultResolutionSpec);
void calcLabelTextExtents(LabelInfo *label);
void calcTotalButtonExtents(ButtonInfo *button);
void calcButtonExtents(ButtonInfo *button);
void balanceButtonExtents(ButtonInfo *button1, ButtonInfo *button2);
void calcButtonLabelPosition(ButtonInfo *button);
Dimension scaleXDimension(AppInfo *app, Dimension unscaled);
Dimension scaleYDimension(AppInfo *app, Dimension unscaled);
void createDialog(AppInfo *app);
void destroyDialog(AppInfo *app);
void createDialogWindow(AppInfo *app);
void createGCs(AppInfo *app);
void destroyGCs(AppInfo *app);
void paintLabel(AppInfo *app, Drawable draw, LabelInfo label);
void paintButton(AppInfo *app, Drawable draw, ButtonInfo button);
void paintIndicator(AppInfo *app, Drawable draw, IndicatorElement indicator);
void updateIndicatorElement(AppInfo *app, int i);
void updateIndicators(AppInfo *app, int condition);
void paintDialog(AppInfo *app);
#define GRAB_KEYBOARD 0
#define GRAB_POINTER 1
void performGrab(AppInfo *app, int grabType, char *grabTypeName,
Bool shouldGrab, Bool *isGrabbed);
void grabKeyboard(AppInfo *app);
void ungrabKeyboard(AppInfo *app);
void grabPointer(AppInfo *app);
void ungrabPointer(AppInfo *app);
void grabServer(AppInfo *app);
void ungrabServer(AppInfo *app);
void cleanUp(AppInfo *app);
void exitApp(AppInfo *app, int exitCode);
void acceptAction(AppInfo *app);
void cancelAction(AppInfo *app);
void backspacePassphrase(AppInfo *app);
void erasePassphrase(AppInfo *app);
void addToPassphrase(AppInfo *app, char c);
void handleKeyPress(AppInfo *app, XEvent *event);
Bool eventIsInsideButton(AppInfo *app, XEvent *event, ButtonInfo button);
void handleButtonPress(AppInfo *app, XEvent *event);
void handlePointerMotion(AppInfo *app, XEvent *event);
void handleInputTimeout(XtPointer data, XtIntervalId *timerId);
void cancelInputTimeout(AppInfo *app);
#endif /* H_X11_SSH_ASKPASS */
|