hush: fix handling of backslashes in variable assignment
[oweals/busybox.git] / loginutils / passwd.c
index c1481c65ee8f0c9e854c86fcd8d18b96929340aa..728e6186760ee5e997d1bbd7920aaf682f6b6473 100644 (file)
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 #include "libbb.h"
 #include <syslog.h>
@@ -128,12 +128,20 @@ int passwd_main(int argc UNUSED_PARAM, char **argv)
                /* getspnam_r may return 0 yet set result to NULL.
                 * At least glibc 2.4 does this. Be extra paranoid here. */
                struct spwd *result = NULL;
-               if (getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result)
-                || !result || strcmp(result->sp_namp, pw->pw_name) != 0) {
-                       /* LOGMODE_BOTH */
-                       bb_error_msg("no record of %s in %s, using %s",
+               errno = 0;
+               if (getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result) != 0
+                || !result /* no error, but no record found either */
+                || strcmp(result->sp_namp, pw->pw_name) != 0 /* paranoia */
+               ) {
+                       if (errno != ENOENT) {
+                               /* LOGMODE_BOTH */
+                               bb_perror_msg("no record of %s in %s, using %s",
                                        name, bb_path_shadow_file,
                                        bb_path_passwd_file);
+                       }
+                       /* else: /etc/shadow does not exist,
+                        * apparently we are on a shadow-less system,
+                        * no surprise there */
                } else {
                        pw->pw_passwd = result->sp_pwdp;
                }