]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
login_prompt: Simplify login_prompt API
authorSamanta Navarro <ferivoz@riseup.net>
Fri, 28 Apr 2023 11:57:23 +0000 (11:57 +0000)
committerSerge Hallyn <serge@hallyn.com>
Wed, 3 May 2023 12:54:28 +0000 (07:54 -0500)
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>
lib/prototypes.h
libmisc/loginprompt.c
src/login.c

index 012652a9e841fdcd112c1fea5f9374015867b72d..83014202e92a8af0d75dd8d45c5b8c216d348ca0 100644 (file)
@@ -233,7 +233,7 @@ extern void dolastlog (
 extern int login_access (const char *user, const char *from);
 
 /* loginprompt.c */
-extern void login_prompt (const char *, char *, int);
+extern void login_prompt (char *, int);
 
 /* mail.c */
 extern void mailcheck (void);
index 2efafd11eca34d3f902808711356248d4512f0d8..d1af0e3989fe5d800dd92e7b231e6896d5076af5 100644 (file)
@@ -32,7 +32,7 @@ static void login_exit (unused int sig)
  * 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];
 
@@ -41,6 +41,7 @@ void login_prompt (const char *prompt, char *name, int namesize)
        char *cp;
        int i;
        FILE *fp;
+       const char *fname = getdef_str ("ISSUE_FILE");
 
        sighandler_t sigquit;
        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.
         */
 
-       if (NULL != prompt) {
-               const char *fname = getdef_str ("ISSUE_FILE");
-               if (NULL != fname) {
-                       fp = fopen (fname, "r");
-                       if (NULL != fp) {
-                               while ((i = getc (fp)) != EOF) {
-                                       (void) putc (i, stdout);
-                               }
-
-                               (void) fclose (fp);
+       if (NULL != fname) {
+               fp = fopen (fname, "r");
+               if (NULL != fp) {
+                       while ((i = getc (fp)) != EOF) {
+                               (void) putc (i, stdout);
                        }
+
+                       (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
index e5c6beff66c93c7fc4d98375c5232766a017550b..01e4f174b4867a46b66b1ad1cdf442a234bdc4f7 100644 (file)
@@ -910,7 +910,7 @@ int main (int argc, char **argv)
                        preauth_flag = false;
                        username = XMALLOCARRAY (USER_NAME_MAX_LENGTH + 1, char);
                        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]) {
                                /* Prompt for a new login */