diff options
author | Lukas Nykryn <lnykryn@redhat.com> | 2012-10-08 12:47:23 +0200 |
---|---|---|
committer | Lukas Nykryn <lnykryn@redhat.com> | 2012-10-08 12:48:22 +0200 |
commit | e182e58e886c6e5cb105055b76646113f2c3bc2d (patch) | |
tree | caeed2d3c67dd118bc78f4d8e34f7364e1dda552 /src/securetty.c | |
parent | 30483d5b4a4763e03dcc2462a4621b76568ab1b3 (diff) | |
download | initscripts-e182e58e886c6e5cb105055b76646113f2c3bc2d.tar initscripts-e182e58e886c6e5cb105055b76646113f2c3bc2d.tar.gz initscripts-e182e58e886c6e5cb105055b76646113f2c3bc2d.tar.bz2 initscripts-e182e58e886c6e5cb105055b76646113f2c3bc2d.tar.xz initscripts-e182e58e886c6e5cb105055b76646113f2c3bc2d.zip |
Revert patches which should not be in 6.4
Revert "Process rule6-* for sit devices (#840009)"
This reverts commit f082f9e64eadbf68ef9bb67744c97c0974af9115.
Revert "securetty: check if the device is in the file before attempting to write to it"
This reverts commit 10c72ce532c1d4f6d0b17fdc9448c9bd2d0b5ef5.
Revert "Killproc -d should parse same values as sleep"
This reverts commit 763b7dcf6bf9e47d90546be1aabf1f724dd527f8.
Revert "Make killproc more granular when delay is passed. (#428029, <xjakub@fi.muni.cz>)"
This reverts commit 6e62c51f3162081cc05ef546929aa98b8448b1cb.
Revert "Allow dhclient configuration files for DHCPv6 as well. (#815676)"
This reverts commit 9987361e94ec6f26e557053b27af6e43a9ee13e1.
Diffstat (limited to 'src/securetty.c')
-rw-r--r-- | src/securetty.c | 58 |
1 files changed, 21 insertions, 37 deletions
diff --git a/src/securetty.c b/src/securetty.c index a4768e35..9ec8e7ef 100644 --- a/src/securetty.c +++ b/src/securetty.c @@ -18,7 +18,6 @@ #include <errno.h> #include <fcntl.h> -#include <limits.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -26,7 +25,6 @@ #include <syslog.h> #include <unistd.h> -#include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> @@ -68,50 +66,39 @@ int open_and_lock_securetty() { int rewrite_securetty(char *terminal) { int fd; + char *buf, *pos; + struct stat sbuf; fd = open_and_lock_securetty(); if (fd == -1) return 1; - if (lseek(fd, 0, SEEK_END) == -1) { + if (fstat(fd, &sbuf) == -1) { close(fd); - syslog(LOG_ERR, "Couldn't seek to end of /etc/securetty: %s",strerror(errno)); + syslog(LOG_ERR, "Couldn't stat /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)) { + buf = malloc(sbuf.st_size + 1); + if (read(fd, buf, sbuf.st_size) != sbuf.st_size) { close(fd); + syslog(LOG_ERR, "Couldn't read /etc/securetty: %s",strerror(errno)); return 1; } - snprintf(term,PATH_MAX,"%s\n",terminal); - if (!strncmp(buf,term,strlen(term))) { - rc = 0; - goto out_unmap; + if (!strncmp(buf,terminal,strlen(terminal)) && buf[strlen(terminal)] == '\n') + goto out_ok; + if ((pos = strstr(buf, terminal))) { + if (pos[strlen(terminal)] == '\n' && *(pos-1) == '\n') + goto out_ok; } - snprintf(term,PATH_MAX,"\n%s\n",terminal); - if (strstr(buf,term)) { - rc = 0; - goto out_unmap; + 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; } -out_unmap: - munmap(buf, sb.st_size); -out: + write(fd, terminal, strlen(terminal)); + write(fd, "\n", 1); +out_ok: close(fd); - return rc; + return 0; } int main(int argc, char **argv) { @@ -120,8 +107,5 @@ int main(int argc, char **argv) { exit(1); } openlog("securetty", LOG_CONS, LOG_DAEMON); - if (check_securetty(argv[1])) - return rewrite_securetty(argv[1]); - else - return 0; + return rewrite_securetty(argv[1]); } |