Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/loginutils/passwd.c

    r1765 r2725  
    11/* vi: set sw=4 ts=4: */
    22/*
    3  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    44 */
    5 
    65#include "libbb.h"
    76#include <syslog.h>
    8 
    97
    108static void nuke_str(char *str)
     
    1816    char *orig = (char*)"";
    1917    char *newp = NULL;
    20     char *cipher = NULL;
    2118    char *cp = NULL;
    2219    char *ret = NULL; /* failure so far */
    2320
    2421    if (myuid && pw->pw_passwd[0]) {
    25         orig = bb_askpass(0, "Old password:"); /* returns ptr to static */
     22        char *encrypted;
     23
     24        orig = bb_ask_stdin("Old password: "); /* returns ptr to static */
    2625        if (!orig)
    2726            goto err_ret;
    28         cipher = pw_encrypt(orig, pw->pw_passwd); /* returns ptr to static */
    29         if (strcmp(cipher, pw->pw_passwd) != 0) {
    30             syslog(LOG_WARNING, "incorrect password for '%s'",
     27        encrypted = pw_encrypt(orig, pw->pw_passwd, 1); /* returns malloced str */
     28        if (strcmp(encrypted, pw->pw_passwd) != 0) {
     29            syslog(LOG_WARNING, "incorrect password for %s",
    3130                pw->pw_name);
    3231            bb_do_delay(FAIL_DELAY);
     
    3433            goto err_ret;
    3534        }
    36     }
    37     orig = xstrdup(orig); /* or else bb_askpass() will destroy it */
    38     newp = bb_askpass(0, "New password:"); /* returns ptr to static */
     35        if (ENABLE_FEATURE_CLEAN_UP) free(encrypted);
     36    }
     37    orig = xstrdup(orig); /* or else bb_ask_stdin() will destroy it */
     38    newp = bb_ask_stdin("New password: "); /* returns ptr to static */
    3939    if (!newp)
    4040        goto err_ret;
    41     newp = xstrdup(newp); /* we are going to bb_askpass() again, so save it */
     41    newp = xstrdup(newp); /* we are going to bb_ask_stdin() again, so save it */
    4242    if (ENABLE_FEATURE_PASSWD_WEAK_CHECK
    4343     && obscure(orig, newp, pw) && myuid)
    4444        goto err_ret; /* non-root is not allowed to have weak passwd */
    4545
    46     cp = bb_askpass(0, "Retype password:");
     46    cp = bb_ask_stdin("Retype password: ");
    4747    if (!cp)
    4848        goto err_ret;
     
    5757        crypt_make_salt(salt + 3, 4, 0);
    5858    }
    59     /* pw_encrypt returns ptr to static */
    60     ret = xstrdup(pw_encrypt(newp, salt));
     59    /* pw_encrypt returns malloced str */
     60    ret = pw_encrypt(newp, salt, 1);
    6161    /* whee, success! */
    6262
     
    6666    nuke_str(newp);
    6767    if (ENABLE_FEATURE_CLEAN_UP) free(newp);
    68     nuke_str(cipher);
    6968    nuke_str(cp);
    7069    return ret;
    7170}
    7271
    73 int passwd_main(int argc, char **argv);
    74 int passwd_main(int argc, char **argv)
     72int passwd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     73int passwd_main(int argc UNUSED_PARAM, char **argv)
    7574{
    7675    enum {
     
    9493    struct rlimit rlimit_fsize;
    9594    char c;
    96 
    9795#if ENABLE_FEATURE_SHADOWPASSWDS
    9896    /* Using _r function to avoid pulling in static buffers */
    9997    struct spwd spw;
    100     struct spwd *result;
    10198    char buffer[256];
    10299#endif
    103100
    104101    logmode = LOGMODE_BOTH;
    105     openlog(applet_name, LOG_NOWAIT, LOG_AUTH);
     102    openlog(applet_name, 0, LOG_AUTH);
    106103    opt = getopt32(argv, "a:lud", &opt_a);
    107104    //argc -= optind;
     
    118115
    119116    /* Will complain and die if username not found */
    120     myname = xstrdup(bb_getpwuid(NULL, -1, myuid));
     117    myname = xstrdup(xuid2uname(myuid));
    121118    name = argv[0] ? argv[0] : myname;
    122119
    123     pw = getpwnam(name);
    124     if (!pw) bb_error_msg_and_die("unknown user %s", name);
     120    pw = xgetpwnam(name);
    125121    if (myuid && pw->pw_uid != myuid) {
    126122        /* LOGMODE_BOTH */
     
    129125
    130126#if ENABLE_FEATURE_SHADOWPASSWDS
    131     /* getspnam_r() can lie! Even if user isn't in shadow, it can
    132      * return success (pwd field was seen set to "!" in this case) */
    133     if (getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result)
    134      || LONE_CHAR(spw.sp_pwdp, '!')) {
    135         /* LOGMODE_BOTH */
    136         bb_error_msg("no record of %s in %s, using %s",
    137                 name, bb_path_shadow_file,
    138                 bb_path_passwd_file);
    139     } else {
    140         pw->pw_passwd = spw.sp_pwdp;
     127    {
     128        /* getspnam_r may return 0 yet set result to NULL.
     129         * At least glibc 2.4 does this. Be extra paranoid here. */
     130        struct spwd *result = NULL;
     131        errno = 0;
     132        if (getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result) != 0
     133         || !result /* no error, but no record found either */
     134         || strcmp(result->sp_namp, pw->pw_name) != 0 /* paranoia */
     135        ) {
     136            if (errno != ENOENT) {
     137                /* LOGMODE_BOTH */
     138                bb_perror_msg("no record of %s in %s, using %s",
     139                    name, bb_path_shadow_file,
     140                    bb_path_passwd_file);
     141            }
     142            /* else: /etc/shadow does not exist,
     143             * apparently we are on a shadow-less system,
     144             * no surprise there */
     145        } else {
     146            pw->pw_passwd = result->sp_pwdp;
     147        }
    141148    }
    142149#endif
     
    148155        if (myuid && !c) { /* passwd starts with '!' */
    149156            /* LOGMODE_BOTH */
    150             bb_error_msg_and_die("cannot change "
     157            bb_error_msg_and_die("can't change "
    151158                    "locked password for %s", name);
    152159        }
     
    162169    } else if (opt & OPT_unlock) {
    163170        if (c) goto skip; /* not '!' */
    164         /* pw->pw_passwd pints to static storage,
     171        /* pw->pw_passwd points to static storage,
    165172         * strdup'ing to avoid nasty surprizes */
    166173        newp = xstrdup(&pw->pw_passwd[1]);
     
    172179    rlimit_fsize.rlim_cur = rlimit_fsize.rlim_max = 512L * 30000;
    173180    setrlimit(RLIMIT_FSIZE, &rlimit_fsize);
    174     signal(SIGHUP, SIG_IGN);
    175     signal(SIGINT, SIG_IGN);
    176     signal(SIGQUIT, SIG_IGN);
     181    bb_signals(0
     182        + (1 << SIGHUP)
     183        + (1 << SIGINT)
     184        + (1 << SIGQUIT)
     185        , SIG_IGN);
    177186    umask(077);
    178187    xsetuid(0);
     
    180189#if ENABLE_FEATURE_SHADOWPASSWDS
    181190    filename = bb_path_shadow_file;
    182     rc = update_passwd(bb_path_shadow_file, name, newp);
     191    rc = update_passwd(bb_path_shadow_file, name, newp, NULL);
    183192    if (rc == 0) /* no lines updated, no errors detected */
    184193#endif
    185194    {
    186195        filename = bb_path_passwd_file;
    187         rc = update_passwd(bb_path_passwd_file, name, newp);
     196        rc = update_passwd(bb_path_passwd_file, name, newp, NULL);
    188197    }
    189198    /* LOGMODE_BOTH */
    190199    if (rc < 0)
    191         bb_error_msg_and_die("cannot update password file %s",
     200        bb_error_msg_and_die("can't update password file %s",
    192201                filename);
    193202    bb_info_msg("Password for %s changed by %s", name, myname);
Note: See TracChangeset for help on using the changeset viewer.