1 /* screenlock - lock a terminal */
9 char pic[] = "/lib/bunny.bit";
24 fmtfdinit(&f, 1, buf, sizeof buf);
25 fmtprint(&f, "screenlock: ");
27 fmtvprint(&f, fmt, arg);
31 threadexitsall("fatal error");
37 fprint(2, "usage: %s\n", argv0);
43 readfile(char *name, char *buf, int nbuf, int addnul)
47 fd = open(name, OREAD);
49 error("%s - can't open: %r", name);
50 nbuf = read(fd, buf, nbuf-addnul);
53 error("%s - can't can't read: %r", name);
59 readline(char *buf, int nbuf)
66 if(read(0, &c, 1) != 1 || c == '\04' || c == '\177'){
71 else if(c == '\b' && i > 0)
73 else if(c == ('u' & 037))
83 int fd, consctl, must;
90 fd = open("/dev/cons", OREAD);
92 error("can't open cons: %r");
95 fd = open("/dev/cons", OWRITE);
97 error("can't open cons: %r");
101 consctl = open("/dev/consctl", OWRITE);
103 error("can't open consctl: %r");
104 if(write(consctl, "rawon", 5) != 5)
105 error("can't turn off echo\n");
111 fprint(2, "%s's screenlock password: ", user);
112 memset(buf, 0, sizeof buf);
113 readline(buf, sizeof buf);
116 if(buf[0] == '\0' || buf[0] == '\04'){
119 error("no password typed");
123 ai = auth_userpasswd(user, buf);
124 if(ai != nil && ai->cap != nil)
129 fprint(2, "password mismatch\n");
132 memset(buf, 0, sizeof buf);
140 fd = open("/dev/mousectl", OWRITE);
149 if(tics > 0 && --tics == 0)
150 write(fd, "blank", 5);
159 char ibuf[256], obuf[256];
163 fd = open("/dev/mouse", ORDWR);
165 error("can't open /dev/mouse: %r");
167 snprint(obuf, sizeof obuf, "m %d %d",
168 screen->r.min.x + Dx(screen->r)/2,
169 screen->r.min.y + Dy(screen->r)/2);
170 while(read(fd, ibuf, sizeof ibuf) > 0){
175 if(x != screen->r.min.x + Dx(screen->r)/2 ||
176 y != screen->r.min.y + Dy(screen->r)/2){
177 fprint(fd, "%s", obuf);
183 /* lay down text at `p' */
185 screenstring(Point p, char *s)
187 string(screen, p, screen->display->white, ZP, font, s);
188 flushimage(display, 1);
194 enum { Nfld = 5, Fldlen = 12, Cursorlen = 2*4 + 2*2*16, };
196 char buf[Nfld*Fldlen], *flds[Nfld], newcmd[128], cbuf[Cursorlen];
203 fd = open("/dev/screen", OREAD);
205 error("can't open /dev/screen: %r");
206 if(read(fd, buf, Nfld*Fldlen) != Nfld*Fldlen)
207 error("can't read /dev/screen: %r");
209 buf[sizeof buf-1] = 0;
210 if(tokenize(buf, flds, Nfld) != Nfld)
211 error("can't tokenize /dev/screen header");
212 snprint(newcmd, sizeof newcmd, "-r %s %s %d %d",
213 flds[1], flds[2], atoi(flds[3]) - 1, atoi(flds[4]) - 1);
215 if (initdraw(nil, nil, "screenlock") < 0)
216 sysfatal("initdraw failed");
220 /* screen is now open and covered. grab mouse and hold on tight */
221 procrfork(grabmouse, nil, 4096, RFFDG);
222 procrfork(blanker, nil, 4096, RFFDG);
223 fd = open(pic, OREAD);
225 i = readimage(display, fd, 0);
228 p = Pt(r.max.x / 2, r.max.y * 2 / 3);
229 dx = (Dx(screen->r) - Dx(i->r)) / 2;
232 dy = (Dy(screen->r) - Dy(i->r)) / 2;
235 draw(screen, screen->r, display->black, nil, ZP);
236 draw(screen, r, i, nil, i->r.min);
237 flushimage(display, 1);
241 /* identify the user on screen, centered */
242 tm = localtime(time(0));
243 s = smprint("user %s at %d:%02.2d", getuser(), tm->hour, tm->min);
244 p = subpt(p, Pt(stringwidth(font, "m") * strlen(s) / 2, 0));
248 /* clear the cursor */
249 fd = open("/dev/cursor", OWRITE);
251 memset(cbuf, 0, sizeof cbuf);
252 write(fd, cbuf, sizeof cbuf);
258 threadmain(int argc, char *argv[])
260 readfile("#c/user", user, sizeof user, 1);