2 * Copyright (c) 1989 - 1993, Julianne Frances Haugh
3 * Copyright (c) 1996 - 2000, Marek Michałkiewicz
4 * Copyright (c) 2003 - 2005, Tomasz Kłoczko
5 * Copyright (c) 2008 , Nicolas François
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the copyright holders or contributors may not be used to
17 * endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include "prototypes.h"
44 static void login_exit (unused int sig)
50 * login_prompt - prompt the user for their login name
52 * login_prompt() displays the standard login prompt. If ISSUE_FILE
53 * is set in login.defs, this file is displayed before the prompt.
56 void login_prompt (const char *prompt, char *name, int namesize)
67 RETSIGTYPE (*sigquit) (int);
69 RETSIGTYPE (*sigtstp) (int);
73 * There is a small chance that a QUIT character will be part of
74 * some random noise during a prompt. Deal with this by exiting
75 * instead of core dumping. If SIGTSTP is defined, do the same
76 * thing for that signal.
79 sigquit = signal (SIGQUIT, login_exit);
81 sigtstp = signal (SIGTSTP, login_exit);
85 * See if the user has configured the issue file to
86 * be displayed and display it before the prompt.
90 cp = getdef_str ("ISSUE_FILE");
94 while ((i = getc (fp)) != EOF) {
101 gethostname (buf, sizeof buf);
102 printf (prompt, buf);
103 (void) fflush (stdout);
107 * Read the user's response. The trailing newline will be
111 memzero (buf, sizeof buf);
112 if (fgets (buf, (int) sizeof buf, stdin) != buf) {
116 cp = strchr (buf, '\n');
120 *cp = '\0'; /* remove \n [ must be there ] */
123 * Skip leading whitespace. This makes " username" work right.
124 * Then copy the rest (up to the end or the first "non-graphic"
125 * character into the username.
128 for (cp = buf; *cp == ' ' || *cp == '\t'; cp++);
130 for (i = 0; i < namesize - 1 && isgraph (*cp); name[i++] = *cp++);
131 while (isgraph (*cp)) {
142 * This is a disaster, at best. The user may have entered extra
143 * environmental variables at the prompt. There are several ways
144 * to do this, and I just take the easy way out.
147 if ('\0' != *cp) { /* process new variables */
151 for (envc = 0; envc < MAX_ENV; envc++) {
152 nvar = strtok ((0 != envc) ? (char *) 0 : cp, " \t,");
156 if (strchr (nvar, '=') != NULL) {
159 envp[envc] = xmalloc (strlen (nvar) + 32);
160 sprintf (envp[envc], "L%d=%s", count++, nvar);
163 set_env (envc, envp);
167 * Set the SIGQUIT handler back to its original value
170 (void) signal (SIGQUIT, sigquit);
172 (void) signal (SIGTSTP, sigtstp);