use stderr for printing error and informational messages
authorrobert <robert@openbsd.org>
Sat, 28 Aug 2021 06:46:49 +0000 (06:46 +0000)
committerrobert <robert@openbsd.org>
Sat, 28 Aug 2021 06:46:49 +0000 (06:46 +0000)
this makes it easier to parse what passwd(1) is doing if
spawned from a GUI

ok millert@

usr.bin/passwd/local_passwd.c
usr.bin/passwd/pwd_check.c

index 9772001..9735b34 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: local_passwd.c,v 1.59 2021/07/12 15:09:20 beck Exp $  */
+/*     $OpenBSD: local_passwd.c,v 1.60 2021/08/28 06:46:49 robert Exp $        */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -176,14 +176,14 @@ getnewpasswd(struct passwd *pw, login_cap_t *lc, int authenticated)
        savequit = signal(SIGQUIT, kbintr);
 
        if (!authenticated) {
-               (void)printf("Changing password for %s.\n", pw->pw_name);
+               fprintf(stderr, "Changing password for %s.\n", pw->pw_name);
                if (uid != 0 && pw->pw_passwd[0] != '\0') {
                        char oldpass[1024];
 
                        p = readpassphrase("Old password:", oldpass,
                            sizeof(oldpass), RPP_ECHO_OFF);
                        if (p == NULL || *p == '\0') {
-                               (void)printf("%s\n", UNCHANGED_MSG);
+                               fprintf(stderr, "%s\n", UNCHANGED_MSG);
                                pw_abort();
                                exit(p == NULL ? 1 : 0);
                        }
@@ -204,12 +204,12 @@ getnewpasswd(struct passwd *pw, login_cap_t *lc, int authenticated)
                p = readpassphrase("New password:", newpass, sizeof(newpass),
                    RPP_ECHO_OFF);
                if (p == NULL || *p == '\0') {
-                       (void)printf("%s\n", UNCHANGED_MSG);
+                       fprintf(stderr, "%s\n", UNCHANGED_MSG);
                        pw_abort();
                        exit(p == NULL ? 1 : 0);
                }
                if (strcmp(p, "s/key") == 0) {
-                       printf("That password collides with a system feature. Choose another.\n");
+                       fprintf(stderr, "That password collides with a system feature. Choose another.\n");
                        continue;
                }
 
@@ -222,7 +222,7 @@ getnewpasswd(struct passwd *pw, login_cap_t *lc, int authenticated)
                        explicit_bzero(repeat, sizeof(repeat));
                        break;
                }
-               (void)printf("Mismatch; try again, EOF to quit.\n");
+               fprintf(stderr, "Mismatch; try again, EOF to quit.\n");
                explicit_bzero(repeat, sizeof(repeat));
                explicit_bzero(newpass, sizeof(newpass));
        }
@@ -232,7 +232,7 @@ getnewpasswd(struct passwd *pw, login_cap_t *lc, int authenticated)
 
        pref = login_getcapstr(lc, "localcipher", NULL, NULL);
        if (crypt_newhash(newpass, pref, hash, sizeof(hash)) != 0) {
-               (void)printf("Couldn't generate hash.\n");
+               fprintf(stderr, "Couldn't generate hash.\n");
                explicit_bzero(newpass, sizeof(newpass));
                pw_error(NULL, 0, 0);
        }
index cfdd1f6..a1b4eca 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pwd_check.c,v 1.16 2017/08/21 21:41:13 deraadt Exp $  */
+/*     $OpenBSD: pwd_check.c,v 1.17 2021/08/28 06:46:49 robert Exp $   */
 
 /*
  * Copyright 2000 Niels Provos <provos@citi.umich.edu>
@@ -97,7 +97,7 @@ pwd_check(login_cap_t *lc, char *password)
 
        min_len = (int)login_getcapnum(lc, "minpasswordlen", 6, 6);
        if (min_len > 0 && strlen(password) < min_len) {
-               printf("Please enter a longer password.\n");
+               fprintf(stderr, "Please enter a longer password.\n");
                return (0);
        }
 
@@ -146,7 +146,7 @@ pwd_check(login_cap_t *lc, char *password)
                                ret = regexec(&rgx, password, 0, NULL, 0);
                                regfree(&rgx);
                                if (ret == 0) {
-                                       printf("%s\n", patterns[i].response);
+                                       fprintf(stderr, "%s\n", patterns[i].response);
                                        exit(1);
                                }
                        }
@@ -194,8 +194,8 @@ pwd_check(login_cap_t *lc, char *password)
 
  out:
        free(checker);
-       printf("Please use a different password. Unusual capitalization,\n");
-       printf("control characters, or digits are suggested.\n");
+       fprintf(stderr, "Please use a different password. Unusual capitalization,\n");
+       fprintf(stderr, "control characters, or digits are suggested.\n");
 
        return (0);
 }