diff options
author | Bill Nottingham <notting@redhat.com> | 2012-08-06 15:18:23 -0400 |
---|---|---|
committer | Bill Nottingham <notting@redhat.com> | 2012-08-06 15:18:23 -0400 |
commit | d85174edb7389f670705595804b48aee0278ed2f (patch) | |
tree | 0cba6c19ef0420ec21bb56c0fe962d13ee3bee4f /src | |
parent | 164d1ede7161233a2a2fe6e4cf413b44a08923e4 (diff) | |
download | initscripts-d85174edb7389f670705595804b48aee0278ed2f.tar initscripts-d85174edb7389f670705595804b48aee0278ed2f.tar.gz initscripts-d85174edb7389f670705595804b48aee0278ed2f.tar.bz2 initscripts-d85174edb7389f670705595804b48aee0278ed2f.tar.xz initscripts-d85174edb7389f670705595804b48aee0278ed2f.zip |
Initial removal of support for non-systemd systems.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 15 | ||||
-rw-r--r-- | src/console_check.c | 207 | ||||
-rw-r--r-- | src/console_init.c | 168 | ||||
-rw-r--r-- | src/securetty.8 | 15 | ||||
-rw-r--r-- | src/securetty.c | 127 |
5 files changed, 1 insertions, 531 deletions
diff --git a/src/Makefile b/src/Makefile index b478cb9f..68833182 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,8 +1,7 @@ CFLAGS+=$(RPM_OPT_FLAGS) -Wall -D_GNU_SOURCE PROGS=usernetctl netreport testd usleep ipcalc \ - fstab-decode getkey ppp-watch consoletype genhostid rename_device \ - console_init console_check securetty + fstab-decode getkey ppp-watch consoletype genhostid rename_device PPPWATCH_OBJS=ppp-watch.o shvar.o CONSOLE_INIT_OBJS=console_init.o shvar.o USLEEP_OBJS=usleep.o @@ -28,11 +27,8 @@ install: install -m 755 getkey $(ROOT)/sbin/getkey install -m 755 ppp-watch $(ROOT)/sbin/ppp-watch install -m 755 consoletype $(ROOT)/sbin/consoletype - install -m 755 securetty $(ROOT)/sbin/securetty install -m 755 sushell $(ROOT)/sbin/sushell install -m 755 rename_device $(ROOT)/lib/udev/rename_device - install -m 755 console_init $(ROOT)/lib/udev/console_init - install -m 755 console_check $(ROOT)/lib/udev/console_check install -m 644 genhostid.1 $(ROOT)$(mandir)/man1 install -m 644 getkey.1 $(ROOT)$(mandir)/man1 install -m 644 netreport.1 $(ROOT)$(mandir)/man1 @@ -44,7 +40,6 @@ install: install -m 644 consoletype.1 $(ROOT)$(mandir)/man1 install -m 644 ifup.8 $(ROOT)$(mandir)/man8 install -m 644 setsysfont.8 $(ROOT)$(mandir)/man8 - install -m 644 securetty.8 $(ROOT)$(mandir)/man8 install -m 644 sushell.8 $(ROOT)$(mandir)/man8 ln -s ifup.8 $(ROOT)$(mandir)/man8/ifdown.8 @@ -72,9 +67,6 @@ usernetctl.o: usernetctl.c usernetctl: usernetctl.c usernetctl.o $(CC) $(LDFLAGS) -pie -o $@ $@.o -securetty: securetty.o - $(CC) $(LDFLAGS) -o $@ $< - shvar.o: shvar.c $(CC) $(CFLAGS) `pkg-config glib-2.0 --cflags` -c shvar.c -o shvar.o @@ -84,8 +76,3 @@ ppp-watch.o: ppp-watch.c rename_device: rename_device.c $(CC) $(CFLAGS) `pkg-config glib-2.0 --cflags` -o $@ $< `pkg-config glib-2.0 --libs` -console_init.o: console_init.c - $(CC) $(CFLAGS) `pkg-config glib-2.0 --cflags` -c console_init.c -o console_init.o - -console_init: $(CONSOLE_INIT_OBJS) - $(CC) $(LDFLAGS) -o $@ $(CONSOLE_INIT_OBJS) `pkg-config glib-2.0 --libs` diff --git a/src/console_check.c b/src/console_check.c deleted file mode 100644 index 8d01d829..00000000 --- a/src/console_check.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2008-2009 Red Hat, Inc. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <termios.h> -#include <unistd.h> - -#include <sys/ioctl.h> - -#include <linux/serial.h> -#include <linux/serial_core.h> - -#ifndef PORT_OMAP -/* from linux-2.6/include/linux/serial_core.h commit b612633b */ -#define PORT_OMAP 96 -#endif - -struct speeds -{ - speed_t speed; - unsigned long value; -}; - -struct speeds speed_map[] = -{ - {B50, 50}, - {B75, 75}, - {B110, 110}, - {B134, 134}, - {B150, 150}, - {B200, 200}, - {B300, 300}, - {B600, 600}, - {B1200, 1200}, - {B1800, 1800}, - {B2400, 2400}, - {B4800, 4800}, - {B9600, 9600}, - {B19200, 19200}, - {B38400, 38400}, -#ifdef B57600 - {B57600, 57600}, -#endif -#ifdef B115200 - {B115200, 115200}, -#endif -#ifdef B230400 - {B230400, 230400}, -#endif -#ifdef B460800 - {B460800, 460800}, -#endif - {0, 0} -}; - -int termcmp(struct termios *a, struct termios *b) { - if (a->c_iflag != b->c_iflag || a->c_oflag != b->c_oflag || - a->c_cflag != b->c_cflag || a->c_lflag != b->c_lflag || - cfgetispeed(a) != cfgetispeed(b) || cfgetospeed(a) != cfgetospeed(b)) - return 1; - return memcmp(a->c_cc, b->c_cc, sizeof(a->c_cc)); -} - -int get_serial_speed(int fd) { - struct termios mode; - - if (!tcgetattr(fd, &mode)) { - int i; - speed_t speed; - - speed = cfgetospeed(&mode); - for (i = 0; speed_map[i].value != 0; i++) - if (speed_map[i].speed == speed) - return speed_map[i].value; - } - return 0; -} - -int compare_termios_to_console(char *dev, int *speed) { - struct termios cmode, mode; - int fd, cfd; - - cfd = open ("/dev/console", O_RDONLY); - tcgetattr(cfd, &cmode); - close(cfd); - - fd = open(dev, O_RDONLY|O_NONBLOCK); - tcgetattr(fd, &mode); - - if (!termcmp(&cmode, &mode)) { - *speed = get_serial_speed(fd); - close(fd); - return 1; - } - close(fd); - return 0; -} - -char *serial_tty_name(int type) { - switch (type) { - case PORT_8250...PORT_MAX_8250: - return "ttyS"; - case PORT_PMAC_ZILOG: - return "ttyPZ"; - case PORT_MPSC: - return "ttyMM"; - case PORT_CPM: - return "ttyCPM"; - case PORT_MPC52xx: - return "ttyPSC"; - case PORT_IMX: - return "ttymxc"; - case PORT_OMAP: - return "ttyO"; - default: - return NULL; - } -} - -char *check_serial_console(int *speed) { - int fd; - char *ret = NULL, *device; - char twelve = 12; - struct serial_struct si, si2; - char *tty_name; - - memset(&si, 0, sizeof(si)); - memset(&si2, 0, sizeof(si)); - - fd = open("/dev/console", O_RDWR); - if (ioctl (fd, TIOCLINUX, &twelve) >= 0) - goto out; - - if (ioctl(fd, TIOCGSERIAL, &si) < 0) - goto out; - close(fd); - - tty_name = serial_tty_name(si.type); - if (!tty_name) - goto out; - - asprintf(&device, "%s%d", tty_name, si.line); - fd = open(device, O_RDWR|O_NONBLOCK); - if (fd == -1) - goto out; - - if (ioctl(fd, TIOCGSERIAL, &si2) < 0) - goto out; - - if (memcmp(&si,&si2, sizeof(si))) - goto out; - - *speed = get_serial_speed(fd); - ret = device; -out: - close(fd); - return ret; -} - -int emit_console_event(char *dev, int speed) { - char *args[] = { "initctl", "emit", "--no-wait", "fedora.serial-console-available", NULL, NULL, NULL }; - - if (dev) - asprintf(&args[4],"DEV=%s",dev); - if (speed) - asprintf(&args[5],"SPEED=%d",speed); - execv("/sbin/initctl", args); - return 1; -} - -int main(int argc, char **argv) { - char *device; - int speed; - - if (argc < 2) { - printf("usage: console_check <device>\n"); - exit(1); - } - chdir("/dev"); - device = argv[1]; - if (!strcmp(device, "console")) { - device = check_serial_console(&speed); - if (device) - return emit_console_event(device, speed); - } else if (compare_termios_to_console(device, &speed)) { - return emit_console_event(device, speed); - } - return 0; -} diff --git a/src/console_init.c b/src/console_init.c deleted file mode 100644 index 446433d0..00000000 --- a/src/console_init.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2008-2009 Red Hat, Inc. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include <sys/ioctl.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/wait.h> - -#include <linux/kd.h> - -#include "shvar.h" - -static char *lang = NULL; -static char *font = NULL; -static char *acm = NULL; -static char *unimap = NULL; -static char *keymap = NULL; - -static int linux_console(int fd) { - unsigned char twelve = 12; - - if (ioctl(fd, TIOCLINUX, &twelve) >= 0) - return 1; - return 0; -} - -static int configured_as_utf8() { - shvarFile *i18nfile = NULL; - - if ((i18nfile = svNewFile("/etc/sysconfig/i18n")) == NULL) - return 1; /* assume UTF-8 */ - - lang = svGetValue(i18nfile, "LANG"); - font = svGetValue(i18nfile, "SYSFONT"); - acm = svGetValue(i18nfile, "SYSFONTACM"); - unimap = svGetValue(i18nfile, "UNIMAP"); - svCloseFile(i18nfile); - if (!lang) - return 1; - if (g_str_has_suffix(lang,".utf8") || g_str_has_suffix(lang,".UTF-8")) - return 1; - return 0; -} - -static int read_keymap() { - shvarFile *keyboard = NULL; - char *tmp; - struct stat sb; - - if (!stat("/etc/sysconfig/console/default.kmap",&sb)) { - keymap = "/etc/sysconfig/console/default.kmap"; - return 0; - } - - if ((keyboard = svNewFile("/etc/sysconfig/keyboard")) == NULL) - return 0; - - tmp = svGetValue(keyboard, "KEYMAP"); - if (tmp) - keymap = tmp; - tmp = svGetValue(keyboard, "KEYTABLE"); - if (tmp) { - if (keymap) free(keymap); - asprintf(&keymap, "%s.map", tmp); - } - return 0; -} - -static void set_font(char *device) { - int pid; - - if ( (pid = fork()) == 0) { - char *args[] = { "setfont", "latarcyrheb-sun16", "-C", NULL, - NULL, NULL, NULL, NULL, NULL }; - - if (font) - args[1] = font; - args[3] = device; - if (acm) { - args[4] = "-m"; - args[5] = acm; - if (unimap) { - args[6] = "-u"; - args[7] = unimap; - } - } else if (unimap) { - args[4] = "-u"; - args[5] = unimap; - } - execv("/bin/setfont", args); - exit(1); - } -} - -static void set_keyboard(int fd, int utf8) { - if (ioctl(fd, KDSKBMODE, utf8 ? K_UNICODE : K_XLATE)) - perror("could not set keyboard mode"); -} - -static void set_terminal(int fd, int utf8) { - if (utf8) - write(fd, "\033%G", 3); - else - write(fd, "\033%@", 3); -} - -static void set_keymap(int fd, int utf8) { - int pid; - - if ((pid = fork()) == 0) { - char *args[] = { "loadkeys", "-q", NULL, NULL, NULL }; - dup2(fd, 0); - dup2(fd, 1); - - if (utf8) { - args[2] = "-u"; - args[3] = keymap; - } else { - args[2] = keymap; - } - execv("/bin/loadkeys", args); - exit(1); - } -} - -int main(int argc, char **argv) { - char *device; - int dev; - - if (argc < 2) { - printf("usage: console_init <device>\n"); - exit(1); - } - chdir("/dev"); - device = argv[1]; - dev = open(device, O_RDWR); - if (linux_console(dev)) { - int utf8 = configured_as_utf8(); - - set_keyboard(dev, utf8); - set_terminal(dev, utf8); - set_font(device); - read_keymap(); - if (keymap) - set_keymap(dev,utf8); - } - return 0; -} diff --git a/src/securetty.8 b/src/securetty.8 deleted file mode 100644 index 2aad6bca..00000000 --- a/src/securetty.8 +++ /dev/null @@ -1,15 +0,0 @@ -.\" Copyright 2009 Petr Lautrbach (plautrba@redhat.com) -.TH securetty 8 2009-10-27 "" "System Administration tools and Daemons" -.SH NAME -securetty \- add a tty to /etc/securetty -.SH SYNOPSIS -.B securetty \fItty\fP -.SH DESCRIPTION -.B securetty -safely adds \fItty\fP to /etc/securetty. -.SH NOTES -.B securetty -is not normally meant to be run by hand; it is invoked by the upstart job that -sets up the system serial console. -.SH "SEE ALSO" -.BR securetty(5) diff --git a/src/securetty.c b/src/securetty.c deleted file mode 100644 index 59abb6e9..00000000 --- a/src/securetty.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2008 Red Hat, Inc. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include <errno.h> -#include <fcntl.h> -#include <limits.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <unistd.h> - -#include <sys/mman.h> -#include <sys/types.h> -#include <sys/stat.h> - -void alarm_handler(int num) { - return; -} - -int open_and_lock_securetty() { - int fd; - struct flock lock; - struct sigaction act, oldact; - - lock.l_type = F_WRLCK; - lock.l_whence = SEEK_SET; - lock.l_start = 0; - lock.l_len = 0; - - fd = open("/etc/securetty", O_RDWR); - if (fd == -1) { - syslog(LOG_ERR, "Couldn't open /etc/securetty: %s",strerror(errno)); - return -1; - } - act.sa_handler = alarm_handler; - act.sa_flags = 0; - sigaction(SIGALRM, &act, &oldact); - alarm(2); - while (fcntl(fd, F_SETLKW, &lock) == -1) { - if (errno == EINTR) { - syslog(LOG_ERR, "Couldn't lock /etc/securetty: Timeout exceeded"); - } else { - syslog(LOG_ERR, "Couldn't lock /etc/securetty: %s",strerror(errno)); - } - return -1; - } - alarm(0); - sigaction(SIGALRM, &oldact, NULL); - return fd; -} - -int rewrite_securetty(char *terminal) { - int fd; - - fd = open_and_lock_securetty(); - if (fd == -1) - return 1; - if (lseek(fd, 0, SEEK_END) == -1) { - close(fd); - syslog(LOG_ERR, "Couldn't seek to end of /etc/securetty: %s",strerror(errno)); - return 1; - } - write(fd, terminal, strlen(terminal)); - write(fd, "\n", 1); - close(fd); - return 0; -} - -int check_securetty(char *terminal) { - int fd, rc = 1; - char *buf, term[PATH_MAX]; - struct stat sb; - - fd = open("/etc/securetty", O_RDONLY); - if (fd == -1) - goto out; - fstat(fd, &sb); - buf = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (buf == ((caddr_t) -1)) { - close(fd); - return 1; - } - snprintf(term,PATH_MAX,"%s\n",terminal); - if (!strncmp(buf,term,strlen(term))) { - rc = 0; - goto out_unmap; - } - snprintf(term,PATH_MAX,"\n%s\n",terminal); - if (strstr(buf,term)) { - rc = 0; - goto out_unmap; - } -out_unmap: - munmap(buf, sb.st_size); -out: - close(fd); - return rc; -} - -int main(int argc, char **argv) { - if (argc < 2 ) { - fprintf(stderr, "Usage: securetty <device>\n"); - exit(1); - } - openlog("securetty", LOG_CONS, LOG_DAEMON); - if (check_securetty(argv[1])) - return rewrite_securetty(argv[1]); - else - return 0; -} |