login_prompt: Simplify login_prompt API

The only user of login_prompt is the login tool. This implies that the
first argument is always the same.

It is much easier to verify printf's format string and its argument if
both are next to each other.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
This commit is contained in:
Samanta Navarro 2023-04-28 11:57:23 +00:00 committed by Serge Hallyn
parent 3010ec11ae
commit 7109b7c066
3 changed files with 14 additions and 16 deletions

View File

@ -233,7 +233,7 @@ extern void dolastlog (
extern int login_access (const char *user, const char *from); extern int login_access (const char *user, const char *from);
/* loginprompt.c */ /* loginprompt.c */
extern void login_prompt (const char *, char *, int); extern void login_prompt (char *, int);
/* mail.c */ /* mail.c */
extern void mailcheck (void); extern void mailcheck (void);

View File

@ -32,7 +32,7 @@ static void login_exit (unused int sig)
* is set in login.defs, this file is displayed before the prompt. * is set in login.defs, this file is displayed before the prompt.
*/ */
void login_prompt (const char *prompt, char *name, int namesize) void login_prompt (char *name, int namesize)
{ {
char buf[1024]; char buf[1024];
@ -41,6 +41,7 @@ void login_prompt (const char *prompt, char *name, int namesize)
char *cp; char *cp;
int i; int i;
FILE *fp; FILE *fp;
const char *fname = getdef_str ("ISSUE_FILE");
sighandler_t sigquit; sighandler_t sigquit;
sighandler_t sigtstp; sighandler_t sigtstp;
@ -59,22 +60,19 @@ void login_prompt (const char *prompt, char *name, int namesize)
* be displayed and display it before the prompt. * be displayed and display it before the prompt.
*/ */
if (NULL != prompt) { if (NULL != fname) {
const char *fname = getdef_str ("ISSUE_FILE"); fp = fopen (fname, "r");
if (NULL != fname) { if (NULL != fp) {
fp = fopen (fname, "r"); while ((i = getc (fp)) != EOF) {
if (NULL != fp) { (void) putc (i, stdout);
while ((i = getc (fp)) != EOF) {
(void) putc (i, stdout);
}
(void) fclose (fp);
} }
(void) fclose (fp);
} }
(void) gethostname (buf, sizeof buf);
printf (prompt, buf);
(void) fflush (stdout);
} }
(void) gethostname (buf, sizeof buf);
printf (_("\n%s login: "), buf);
(void) fflush (stdout);
/* /*
* Read the user's response. The trailing newline will be * Read the user's response. The trailing newline will be

View File

@ -910,7 +910,7 @@ int main (int argc, char **argv)
preauth_flag = false; preauth_flag = false;
username = XMALLOCARRAY (USER_NAME_MAX_LENGTH + 1, char); username = XMALLOCARRAY (USER_NAME_MAX_LENGTH + 1, char);
username[USER_NAME_MAX_LENGTH] = '\0'; username[USER_NAME_MAX_LENGTH] = '\0';
login_prompt (_("\n%s login: "), username, USER_NAME_MAX_LENGTH); login_prompt (username, USER_NAME_MAX_LENGTH);
if ('\0' == username[0]) { if ('\0' == username[0]) {
/* Prompt for a new login */ /* Prompt for a new login */