1 /* screenlock - lock a terminal */
9 char pic[] = "/lib/bunny.bit";
19 blankscreen(int blank)
24 if(fprint(vgactl, blank? "blank": "unblank") < 0)
25 fprint(2, "blankscreen: can't blank: %r\n");
35 fmtfdinit(&f, 1, buf, sizeof buf);
36 fmtprint(&f, "screenlock: ");
38 fmtvprint(&f, fmt, arg);
42 threadexitsall("fatal error");
48 fprint(2, "usage: %s\n", argv0);
54 readfile(char *name, char *buf, int nbuf, int addnul)
58 fd = open(name, OREAD);
60 error("%s - can't open: %r", name);
61 nbuf = read(fd, buf, nbuf-addnul);
64 error("%s - can't can't read: %r", name);
70 readline(char *buf, int nbuf)
77 if(read(0, &c, 1) != 1 || c == '\04' || c == '\177'){
82 else if(c == '\b' && i > 0)
84 else if(c == ('u' & 037))
94 int fd, consctl, must;
101 fd = open("/dev/cons", OREAD);
103 error("can't open cons: %r");
106 fd = open("/dev/cons", OWRITE);
108 error("can't open cons: %r");
112 consctl = open("/dev/consctl", OWRITE);
114 error("can't open consctl: %r");
115 if(write(consctl, "rawon", 5) != 5)
116 error("can't turn off echo\n");
122 fprint(2, "%s's screenlock password: ", user);
123 memset(buf, 0, sizeof buf);
124 readline(buf, sizeof buf);
128 if(buf[0] == '\0' || buf[0] == '\04'){
131 error("no password typed");
135 ai = auth_userpasswd(user, buf);
136 if(ai != nil && ai->cap != nil)
141 fprint(2, "password mismatch\n");
144 memset(buf, 0, sizeof buf);
159 if(tics > 0 && --tics == 0)
169 char ibuf[256], obuf[256];
173 fd = open("/dev/mouse", ORDWR);
175 error("can't open /dev/mouse: %r");
177 snprint(obuf, sizeof obuf, "m %d %d",
178 screen->r.min.x + Dx(screen->r)/2,
179 screen->r.min.y + Dy(screen->r)/2);
180 while(read(fd, ibuf, sizeof ibuf) > 0){
185 if(x != screen->r.min.x + Dx(screen->r)/2 ||
186 y != screen->r.min.y + Dy(screen->r)/2){
187 fprint(fd, "%s", obuf);
193 /* lay down text at `p' */
195 screenstring(Point p, char *s)
197 string(screen, p, screen->display->white, ZP, font, s);
198 flushimage(display, 1);
204 enum { Nfld = 5, Fldlen = 12, Cursorlen = 2*4 + 2*2*16, };
206 char buf[Nfld*Fldlen], *flds[Nfld], newcmd[128], cbuf[Cursorlen];
213 fd = open("/dev/screen", OREAD);
215 error("can't open /dev/screen: %r");
216 if(read(fd, buf, Nfld*Fldlen) != Nfld*Fldlen)
217 error("can't read /dev/screen: %r");
219 buf[sizeof buf-1] = 0;
220 if(tokenize(buf, flds, Nfld) != Nfld)
221 error("can't tokenize /dev/screen header");
222 snprint(newcmd, sizeof newcmd, "-r %s %s %d %d",
223 flds[1], flds[2], atoi(flds[3]) - 1, atoi(flds[4]) - 1);
225 if (initdraw(nil, nil, "screenlock") < 0)
226 sysfatal("initdraw failed");
230 /* screen is now open and covered. grab mouse and hold on tight */
231 procrfork(grabmouse, nil, 4096, RFFDG);
232 procrfork(blanker, nil, 4096, RFFDG);
233 fd = open(pic, OREAD);
235 i = readimage(display, fd, 0);
238 p = Pt(r.max.x / 2, r.max.y * 2 / 3);
239 dx = (Dx(screen->r) - Dx(i->r)) / 2;
242 dy = (Dy(screen->r) - Dy(i->r)) / 2;
245 draw(screen, screen->r, display->black, nil, ZP);
246 draw(screen, r, i, nil, i->r.min);
247 flushimage(display, 1);
251 /* identify the user on screen, centered */
252 tm = localtime(time(0));
253 s = smprint("user %s at %d:%02.2d", getuser(), tm->hour, tm->min);
254 p = subpt(p, Pt(stringwidth(font, "m") * strlen(s) / 2, 0));
258 /* clear the cursor */
259 fd = open("/dev/cursor", OWRITE);
261 memset(cbuf, 0, sizeof cbuf);
262 write(fd, cbuf, sizeof cbuf);
268 threadmain(int argc, char *argv[])
270 readfile("#c/user", user, sizeof user, 1);
272 if((vgactl = open("/dev/vgactl", OWRITE)) < 0)
273 vgactl = open("#v/vgactl", OWRITE);