Skip to content

Commit a6df80d

Browse files
committed
Handel BS on password prompt as well
Drop spining code as systemd uses clear to end of line escape sequence (hard coded!) for its cylon lines. Signed-off-by: Werner Fink <werner@suse.de>
1 parent 54c8294 commit a6df80d

File tree

6 files changed

+76
-94
lines changed

6 files changed

+76
-94
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ BOOT_FIFO = /dev/blog
1515
DEBUG =
1616
DESTDIR =
1717
MAJOR := 2
18-
MINOR := 29
18+
MINOR := 31
1919
VERSION := $(MAJOR).$(MINOR)
2020
DATE = $(shell date +'%d%b%y' | tr '[:lower:]' '[:upper:]')
2121
COPTS =

blogd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ int main(int argc, char *argv[])
416416
} else {
417417
ioctl(fd, KDSETMODE, KD_TEXT); /* Enforce text mode */
418418

419-
c->otio.c_iflag |= (ICRNL | IGNBRK);
419+
c->otio.c_iflag |= (ICRNL | IXON);
420420
c->otio.c_iflag &= ~(INLCR | IGNCR | BRKINT);
421421
c->otio.c_oflag |= (ONLCR | OPOST);
422422
c->otio.c_oflag &= ~(OCRNL | ONLRET | OLCUC);

libconsole/console.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,10 @@ void safeIO (void)
410410

411411
ret = lstat("/var/log", &st);
412412
if (ret < 0) {
413-
warn("can not get file status of /var/log");
413+
if (errno != ENOENT)
414+
warn("can not get file status of /var/log: %m");
415+
else
416+
atboot = 1;
414417
goto skip;
415418
}
416419
if ((st.st_mode & S_IFMT) == S_IFLNK) {
@@ -1190,6 +1193,7 @@ static void socket_handler(int fd)
11901193
/*
11911194
* Do handle the connection in data
11921195
*/
1196+
char* currenttty;
11931197
static void ask_for_password(void)
11941198
{
11951199
struct timespec timeout = {0, 50000000};
@@ -1256,6 +1260,7 @@ static void ask_for_password(void)
12561260
dup2(1, 2);
12571261
dup2(c->fd, 0);
12581262
dup2(c->fd, 1);
1263+
currenttty = c->tty;
12591264

12601265
list_for_each_entry(d, &cons->node, node)
12611266
if (d->fd >= 0) {

libconsole/libconsole.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,18 @@ static inline void reset_virtual_console(struct termios *tp, int flags)
234234
/* Sane setting, allow eight bit characters, no carriage return delay
235235
* the same result as `stty sane cr0 pass8'
236236
*/
237-
tp->c_iflag |= (BRKINT | ICRNL | IMAXBEL);
238-
tp->c_iflag &= ~(IGNBRK | INLCR | IGNCR | IXOFF | IUCLC | IXANY | ISTRIP);
237+
tp->c_iflag |= (ICRNL | IXON);
238+
tp->c_iflag &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP| \
239+
INLCR | IGNCR | IXOFF | IUCLC | IXANY | IMAXBEL);
239240
tp->c_oflag |= (OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0);
240241
tp->c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | \
241-
NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
242-
tp->c_lflag |= (ISIG | ICANON | IEXTEN | ECHO|ECHOE|ECHOK|ECHOKE|ECHOCTL);
243-
tp->c_lflag &= ~(ECHONL|ECHOPRT | NOFLSH | TOSTOP);
242+
NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
243+
tp->c_lflag |= (ISIG | ICANON | IEXTEN | ECHO|ECHOE|ECHOK|ECHOKE);
244+
tp->c_lflag &= ~(ECHONL|ECHOPRT | NOFLSH | TOSTOP | FLUSHO | EXTPROC | ECHOCTL);
244245

245246
if ((flags & UL_TTY_KEEPCFLAGS) == 0) {
246247
tp->c_cflag |= (CREAD | CS8 | HUPCL);
247-
tp->c_cflag &= ~(PARODD | PARENB);
248+
tp->c_cflag &= ~(PARODD | PARENB | CMSPAR | CLOCAL | CRTSCTS);
248249
}
249250
#ifdef OFDEL
250251
tp->c_oflag &= ~OFDEL;

libconsole/log.c

Lines changed: 39 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,13 @@ enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey,
218218
ESpalette };
219219
#define NPAR 16
220220
static unsigned int state = ESnormal;
221-
static int npar, nl;
222-
static unsigned long int line;
221+
static int npar, nl, cr;
223222

224223
/*
225224
* Workaround for spinner of fsck/e2fsck
226225
* Uses ascii lines ending with '\r' only
227226
*/
228227
static int spin;
229-
#define PROGLEN 192
230-
static unsigned char prog[PROGLEN];
231228

232229
void parselog(const char *buf, const size_t s)
233230
{
@@ -259,6 +256,8 @@ void parselog(const char *buf, const size_t s)
259256
}
260257
}
261258

259+
nl = 0;
260+
262261
switch(state) {
263262
case ESnormal:
264263
default:
@@ -268,28 +267,26 @@ void parselog(const char *buf, const size_t s)
268267
case 16 ... 23:
269268
case 25:
270269
case 28 ... 31:
271-
nl = 0;
272270
follow = 0;
273271
addlog('^'); addlog(c + 64);
274272
break;
275273
case '\n':
276-
if (spin > 4) /* last spinner line */
277-
storelog((char*)prog, strlen((char*)prog));
278274
nl = 1;
279-
line++;
280-
follow = spin = 0;
275+
follow = 0;
276+
cr = spin = 0;
281277
addlog(c);
282278
break;
283279
case '\r':
284280
follow = 0;
285-
spin++;
286-
if (spin < 5) {
287-
// if (spin > 1)
288-
// addlog('\n');
289-
nl = 1;
281+
if (cr++ > 0)
282+
{
283+
spin++;
284+
#if 0
285+
storelog(">spin", 5);
286+
addlog(48+spin);
287+
addlog('<');
288+
#endif
290289
}
291-
if (spin == 5)
292-
storelog("\n<progress bar skipped>\n", 24);
293290
break;
294291
case 14:
295292
case 15:
@@ -305,82 +302,43 @@ void parselog(const char *buf, const size_t s)
305302
break;
306303
case '\t':
307304
case 32 ... 126:
308-
if (spin < 5) {
309-
// if (spin == 1 && nl)
310-
// addlog('\n');
311-
addlog(c);
312-
} else { /* Seems to be a lengthy spinner line */
313-
static int old = 0;
314-
static ssize_t p = 0;
315-
if (old != spin) {
316-
old = spin; /* Next line overwrite on tty */
317-
p = 0;
318-
bzero(prog, PROGLEN);
319-
}
320-
if (p < PROGLEN)
321-
prog[p++] = c; /* buffer always current line */
322-
}
323-
nl = 0;
305+
addlog(c);
324306
follow = 0;
325307
break;
326308
case 160 ... 255:
327-
if (spin < 5) {
328-
// if (spin == 1 && nl)
329-
// addlog('\n');
330-
if ((c & 0xc0) == 0x80) {
331-
if (follow) {
332-
addlog(c);
333-
follow--;
334-
break;
335-
}
336-
} if (follow) {
337-
addlog(c);
338-
break;
339-
}
340-
if ((up = snprintf((char*)uprt, sizeof(uprt), "\\%03o", c)) > 0)
341-
storelog((char*)uprt, (size_t)up);
342-
} else { /* Seems to be a lengthy spinner line */
343-
static int old = 0;
344-
static ssize_t p = 0;
345-
if (old != spin) {
346-
old = spin; /* Next line overwrite on tty */
347-
p = 0;
348-
bzero(prog, PROGLEN);
349-
}
350-
if (p < PROGLEN)
351-
prog[p++] = c; /* buffer always current line */
309+
if (follow) {
310+
if ((c & 0xc0) == 0x80)
311+
follow--;
312+
addlog(c);
313+
break;
352314
}
353-
nl = 0;
315+
if ((up = snprintf((char*)uprt, sizeof(uprt), "\\%03o", c)) > 0)
316+
storelog((char*)uprt, (size_t)up);
354317
break;
355318
case 127:
356-
nl = 0;
357319
follow = 0;
358320
addlog('^'); addlog('?');
359321
break;
360322
case 128 ... 159:
361-
nl = 0;
362-
if ((c & 0xc0) == 0x80) {
363-
if (follow) {
364-
addlog(c);
323+
if (follow) {
324+
if ((c & 0xc0) == 0x80)
365325
follow--;
366-
break;
367-
}
368-
} if (follow) {
369326
addlog(c);
370327
break;
371328
}
372329
if ((up = snprintf((char*)uprt, sizeof(uprt), "\\%03o", c)) > 0)
373330
storelog((char*)uprt, (size_t)up);
374331
break;
375332
default:
376-
nl = 0;
377-
follow = spin = 0;
333+
cr = 0;
334+
follow = 0;
378335
if ((up = snprintf((char*)uprt, sizeof(uprt), "0x%X", c)) > 0)
379336
storelog((char*)uprt, (size_t)up);
380337
break;
381338
}
382339
break;
383340
case ESesc:
341+
follow = 0;
384342
state = ESnormal;
385343
switch((unsigned char)c) {
386344
case '[':
@@ -394,12 +352,8 @@ void parselog(const char *buf, const size_t s)
394352
break;
395353
case 'E':
396354
case 'D':
397-
if (spin > 4) /* last spinner line */
398-
storelog((char*)prog, strlen((char*)prog));
355+
addlog('\n');
399356
nl = 1;
400-
line++;
401-
spin = 0;
402-
// addlog('\n');
403357
break;
404358
case '(':
405359
state = ESsetG0;
@@ -420,6 +374,7 @@ void parselog(const char *buf, const size_t s)
420374
}
421375
break;
422376
case ESnonstd:
377+
follow = 0;
423378
if (c == 'P') {
424379
npar = 0;
425380
state = ESpalette;
@@ -429,6 +384,7 @@ void parselog(const char *buf, const size_t s)
429384
state = ESnormal;
430385
break;
431386
case ESpalette:
387+
follow = 0;
432388
if ((c>='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f')) {
433389
npar++;
434390
if (npar==7)
@@ -437,15 +393,21 @@ void parselog(const char *buf, const size_t s)
437393
state = ESnormal;
438394
break;
439395
case ESsquare:
396+
follow = 0;
440397
npar = 0;
441398
state = ESgetpars;
442399
if (c == '[') {
443400
state = ESfunckey;
444401
break;
445402
}
403+
#if 0
404+
if (c == 'K')
405+
storelog(" el ", 4);
406+
#endif
446407
if (c == '?')
447408
break;
448409
case ESgetpars:
410+
follow = 0;
449411
if (c==';' && npar<NPAR-1) {
450412
npar++;
451413
break;
@@ -454,19 +416,23 @@ void parselog(const char *buf, const size_t s)
454416
} else
455417
state = ESgotpars;
456418
case ESgotpars:
419+
follow = 0;
457420
state = ESnormal;
458421
break;
459422
case ESpercent:
423+
follow = 0;
460424
state = ESnormal;
461425
break;
462426
case ESfunckey:
463427
case EShash:
464428
case ESsetG0:
465429
case ESsetG1:
430+
follow = 0;
466431
state = ESnormal;
467432
break;
468433
#ifdef BLOGD_EXT
469434
case ESignore: /* Boot log extension */
435+
follow = 0;
470436
state = ESesc;
471437
{
472438
unsigned char echo[64];

libconsole/readpw.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,26 @@ struct chardata {
2424
int capslock; /* upper case without lower case */
2525
};
2626

27+
static inline void wput(int fd, char c)
28+
{
29+
int ret;
30+
do {
31+
ret = write(fd, &c, 1);
32+
} while (ret < 0 && errno == EINTR);
33+
}
34+
35+
extern char* currenttty;
2736
ssize_t readpw(int fd, char *pass, int eightbit)
2837
{
2938
char *ptr = pass;
3039
struct chardata cp;
31-
int ret, rcw;
40+
int ret;
3241

3342
cp.eol = *ptr = '\0';
3443

3544
while (cp.eol == '\0') {
3645
char ascval, c;
46+
errno = 0;
3747

3848
ret = read(fd, &c, 1);
3949
if (ret < 0) {
@@ -42,14 +52,12 @@ ssize_t readpw(int fd, char *pass, int eightbit)
4252
continue;
4353
}
4454
switch (errno) {
45-
case 0:
4655
case EIO:
47-
case ESRCH:
48-
case EINVAL:
49-
case ENOENT:
50-
break;
56+
/* Not as in sulogin of util-linux we do nothing here */
5157
default:
52-
warn("cannot read passphrase");
58+
warn("cannot read passphrase on %s: %m", currenttty);
59+
break;
60+
case 0:
5361
break;
5462
}
5563
return -1;
@@ -78,13 +86,17 @@ ssize_t readpw(int fd, char *pass, int eightbit)
7886
case BS:
7987
case CERASE:
8088
cp.erase = ascval;
81-
if (ptr > pass)
89+
if (ptr > pass) {
8290
ptr--;
91+
wput(fd, BS);
92+
}
8393
break;
8494
case CKILL:
8595
cp.kill = ascval;
86-
while (ptr > pass)
96+
while (ptr > pass) {
8797
ptr--;
98+
wput(fd, BS);
99+
}
88100
break;
89101
case CEOF:
90102
return 0;
@@ -94,9 +106,7 @@ ssize_t readpw(int fd, char *pass, int eightbit)
94106
return -1;
95107
}
96108
*ptr++ = ascval;
97-
do {
98-
rcw = write(fd, "*", 1);
99-
} while(rcw == -1 && errno == EINTR);
109+
wput(fd, '*');
100110
break;
101111
}
102112
}

0 commit comments

Comments
 (0)