diff options
| author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-01-21 20:59:34 +0000 |
|---|---|---|
| committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-01-21 20:59:34 +0000 |
| commit | 6af21c2afac80e96cdea57508eabcfe2ea1aac01 (patch) | |
| tree | 868c327620e903ebfc5522b7f93eaaace57d6720 | |
| parent | 9e5d6c002ca589fb2e767fc8bafd6ceddaa12d39 (diff) | |
| download | busybox-w32-6af21c2afac80e96cdea57508eabcfe2ea1aac01.tar.gz busybox-w32-6af21c2afac80e96cdea57508eabcfe2ea1aac01.tar.bz2 busybox-w32-6af21c2afac80e96cdea57508eabcfe2ea1aac01.zip | |
Login prompt function, part of waldi's telnetd from inetd patch
| -rw-r--r-- | libbb/login.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/libbb/login.c b/libbb/login.c new file mode 100644 index 000000000..9b33f6c40 --- /dev/null +++ b/libbb/login.c | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /* | ||
| 2 | * issue.c: issue printing code | ||
| 3 | * | ||
| 4 | * Copyright (C) 2003 Bastian Blank <waldi@tuxbox.org> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 19 | * | ||
| 20 | * $Id: login.c,v 1.1 2003/01/21 20:59:34 bug1 Exp $ | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include <stdio.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | #include "busybox.h" | ||
| 26 | |||
| 27 | #include <sys/utsname.h> | ||
| 28 | #include <time.h> | ||
| 29 | |||
| 30 | #define LOGIN " login: " | ||
| 31 | |||
| 32 | static char fmtstr_d[] = { "%A, %d %B %Y" }; | ||
| 33 | static char fmtstr_t[] = { "%H:%M:%S" }; | ||
| 34 | |||
| 35 | void print_login_issue(const char *issue_file, const char *tty) | ||
| 36 | { | ||
| 37 | FILE *fd; | ||
| 38 | int c; | ||
| 39 | char buf[256]; | ||
| 40 | char *ret; | ||
| 41 | time_t t; | ||
| 42 | struct utsname uts; | ||
| 43 | |||
| 44 | time(&t); | ||
| 45 | uname(&uts); | ||
| 46 | |||
| 47 | puts(""); /* start a new line */ | ||
| 48 | |||
| 49 | if ((fd = fopen(issue_file, "r"))) { | ||
| 50 | while ((c = fgetc(fd)) != EOF) { | ||
| 51 | if (c == '\\' || c == '%') { | ||
| 52 | c = fgetc(fd); | ||
| 53 | |||
| 54 | switch (c) { | ||
| 55 | case 's': | ||
| 56 | fputs(uts.sysname, stdout); | ||
| 57 | break; | ||
| 58 | |||
| 59 | case 'n': | ||
| 60 | fputs(uts.nodename, stdout); | ||
| 61 | break; | ||
| 62 | |||
| 63 | case 'r': | ||
| 64 | fputs(uts.release, stdout); | ||
| 65 | break; | ||
| 66 | |||
| 67 | case 'v': | ||
| 68 | fputs(uts.version, stdout); | ||
| 69 | break; | ||
| 70 | |||
| 71 | case 'm': | ||
| 72 | fputs(uts.machine, stdout); | ||
| 73 | break; | ||
| 74 | |||
| 75 | case 'D': | ||
| 76 | case 'o': | ||
| 77 | getdomainname(buf, sizeof(buf)); | ||
| 78 | buf[sizeof(buf) - 1] = '\0'; | ||
| 79 | fputs(buf, stdout); | ||
| 80 | break; | ||
| 81 | |||
| 82 | case 'd': | ||
| 83 | strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); | ||
| 84 | fputs(buf, stdout); | ||
| 85 | break; | ||
| 86 | |||
| 87 | case 't': | ||
| 88 | strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); | ||
| 89 | fputs(buf, stdout); | ||
| 90 | break; | ||
| 91 | |||
| 92 | case 'h': | ||
| 93 | gethostname(buf, sizeof(buf)); | ||
| 94 | fputs(buf, stdout); | ||
| 95 | break; | ||
| 96 | |||
| 97 | case 'l': | ||
| 98 | printf("%s", tty); | ||
| 99 | |||
| 100 | default: | ||
| 101 | putchar(c); | ||
| 102 | } | ||
| 103 | } else | ||
| 104 | putchar(c); | ||
| 105 | } | ||
| 106 | |||
| 107 | puts(""); /* start a new line */ | ||
| 108 | fflush(stdout); | ||
| 109 | |||
| 110 | fclose(fd); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | void print_login_prompt(void) | ||
| 115 | { | ||
| 116 | char buf[MAXHOSTNAMELEN]; | ||
| 117 | |||
| 118 | gethostname(buf, MAXHOSTNAMELEN); | ||
| 119 | fputs(buf, stdout); | ||
| 120 | |||
| 121 | fputs(LOGIN, stdout); | ||
| 122 | fflush(stdout); | ||
| 123 | } | ||
| 124 | |||
