Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/loginutils


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (8 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 added
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/loginutils/Config.src

    r3232 r3621  
    55
    66menu "Login/Password Management Utilities"
    7 
    8 INSERT
    97
    108config FEATURE_SHADOWPASSWDS
     
    9492      user which has password encrypted with these algorithms.
    9593
    96 config ADDUSER
    97     bool "adduser"
    98     default y
    99     help
    100       Utility for creating a new user account.
    101 
    102 config FEATURE_ADDUSER_LONG_OPTIONS
    103     bool "Enable long options"
    104     default y
    105     depends on ADDUSER && LONG_OPTS
    106     help
    107       Support long options for the adduser applet.
    108 
    109 config FEATURE_CHECK_NAMES
    110     bool "Enable sanity check on user/group names in adduser and addgroup"
    111     default n
    112     depends on ADDUSER || ADDGROUP
    113     help
    114       Enable sanity check on user and group names in adduser and addgroup.
    115       To avoid problems, the user or group name should consist only of
    116       letters, digits, underscores, periods, at signs and dashes,
    117       and not start with a dash (as defined by IEEE Std 1003.1-2001).
    118       For compatibility with Samba machine accounts "$" is also supported
    119       at the end of the user or group name.
    120 
    121 config FIRST_SYSTEM_ID
    122     int "First valid system uid or gid for adduser and addgroup"
    123     depends on ADDUSER || ADDGROUP
    124     range 0 64900
    125     default 100
    126     help
    127       First valid system uid or gid for adduser and addgroup
    128 
    129 config LAST_SYSTEM_ID
    130     int "Last valid system uid or gid for adduser and addgroup"
    131     depends on ADDUSER || ADDGROUP
    132     range 0 64900
    133     default 999
    134     help
    135       Last valid system uid or gid for adduser and addgroup
    136 
    137 config ADDGROUP
    138     bool "addgroup"
    139     default y
    140     help
    141       Utility for creating a new group account.
    142 
    143 config FEATURE_ADDGROUP_LONG_OPTIONS
    144     bool "Enable long options"
    145     default y
    146     depends on ADDGROUP && LONG_OPTS
    147     help
    148       Support long options for the addgroup applet.
    149 
    150 config FEATURE_ADDUSER_TO_GROUP
    151     bool "Support for adding users to groups"
    152     default y
    153     depends on ADDGROUP
    154     help
    155       If  called  with two non-option arguments,
    156       addgroup will add an existing user to an
    157       existing group.
    158 
    159 config DELUSER
    160     bool "deluser"
    161     default y
    162     help
    163       Utility for deleting a user account.
    164 
    165 config DELGROUP
    166     bool "delgroup"
    167     default y
    168     help
    169       Utility for deleting a group account.
    170 
    171 config FEATURE_DEL_USER_FROM_GROUP
    172     bool "Support for removing users from groups"
    173     default y
    174     depends on DELGROUP
    175     help
    176       If called with two non-option arguments, deluser
    177       or delgroup will remove an user from a specified group.
    178 
    179 config GETTY
    180     bool "getty"
    181     default y
    182     select FEATURE_SYSLOG
    183     help
    184       getty lets you log in on a tty. It is normally invoked by init.
    185 
    186       Note that you can save a few bytes by disabling it and
    187       using login applet directly.
    188       If you need to reset tty attributes before calling login,
    189       this script approximates getty:
    190 
    191       exec </dev/$1 >/dev/$1 2>&1 || exit 1
    192       reset
    193       stty sane; stty ispeed 38400; stty ospeed 38400
    194       printf "%s login: " "`hostname`"
    195       read -r login
    196       exec /bin/login "$login"
    197 
    198 config LOGIN
    199     bool "login"
    200     default y
    201     select FEATURE_SYSLOG
    202     help
    203       login is used when signing onto a system.
    204 
    205       Note that Busybox binary must be setuid root for this applet to
    206       work properly.
    207 
    208 config LOGIN_SESSION_AS_CHILD
    209     bool "Run logged in session in a child process"
    210     default y if PAM
    211     depends on LOGIN
    212     help
    213       Run the logged in session in a child process.  This allows
    214       login to clean up things such as utmp entries or PAM sessions
    215       when the login session is complete.  If you use PAM, you
    216       almost always would want this to be set to Y, else PAM session
    217       will not be cleaned up.
    218 
    219 config PAM
    220     bool "Support for PAM (Pluggable Authentication Modules)"
    221     default n
    222     depends on LOGIN
    223     help
    224       Use PAM in login(1) instead of direct access to password database.
    225 
    226 config LOGIN_SCRIPTS
    227     bool "Support for login scripts"
    228     depends on LOGIN
    229     default y
    230     help
    231       Enable this if you want login to execute $LOGIN_PRE_SUID_SCRIPT
    232       just prior to switching from root to logged-in user.
    233 
    234 config FEATURE_NOLOGIN
    235     bool "Support for /etc/nologin"
    236     default y
    237     depends on LOGIN
    238     help
    239       The file /etc/nologin is used by (some versions of) login(1).
    240       If it exists, non-root logins are prohibited.
    241 
    242 config FEATURE_SECURETTY
    243     bool "Support for /etc/securetty"
    244     default y
    245     depends on LOGIN
    246     help
    247       The file /etc/securetty is used by (some versions of) login(1).
    248       The file contains the device names of tty lines (one per line,
    249       without leading /dev/) on which root is allowed to login.
    250 
    251 config PASSWD
    252     bool "passwd"
    253     default y
    254     select FEATURE_SYSLOG
    255     help
    256       passwd changes passwords for user and group accounts. A normal user
    257       may only change the password for his/her own account, the super user
    258       may change the password for any account. The administrator of a group
    259       may change the password for the group.
    260 
    261       Note that Busybox binary must be setuid root for this applet to
    262       work properly.
    263 
    264 config FEATURE_PASSWD_WEAK_CHECK
    265     bool "Check new passwords for weakness"
    266     default y
    267     depends on PASSWD
    268     help
    269       With this option passwd will refuse new passwords which are "weak".
    270 
    271 config CRYPTPW
    272     bool "cryptpw"
    273     default y
    274     help
    275       Encrypts the given password with the crypt(3) libc function
    276       using the given salt. Debian has this utility under mkpasswd
    277       name. Busybox provides mkpasswd as an alias for cryptpw.
    278 
    279 config CHPASSWD
    280     bool "chpasswd"
    281     default y
    282     help
    283       Reads a file of user name and password pairs from standard input
    284       and uses this information to update a group of existing users.
    285 
    286 config FEATURE_DEFAULT_PASSWD_ALGO
    287     string "Default password encryption method (passwd -a, cryptpw -m parameter)"
    288     default "des"
    289     depends on PASSWD || CRYPTPW
    290     help
    291       Possible choices are "d[es]", "m[d5]", "s[ha256]" or "sha512".
    292 
    293 config SU
    294     bool "su"
    295     default y
    296     select FEATURE_SYSLOG
    297     help
    298       su is used to become another user during a login session.
    299       Invoked without a username, su defaults to becoming the super user.
    300 
    301       Note that Busybox binary must be setuid root for this applet to
    302       work properly.
    303 
    304 config FEATURE_SU_SYSLOG
    305     bool "Enable su to write to syslog"
    306     default y
    307     depends on SU
    308 
    309 config FEATURE_SU_CHECKS_SHELLS
    310     bool "Enable su to check user's shell to be listed in /etc/shells"
    311     depends on SU
    312     default y
    313 
    314 config SULOGIN
    315     bool "sulogin"
    316     default y
    317     select FEATURE_SYSLOG
    318     help
    319       sulogin is invoked when the system goes into single user
    320       mode (this is done through an entry in inittab).
    321 
    322 config VLOCK
    323     bool "vlock"
    324     default y
    325     help
    326       Build the "vlock" applet which allows you to lock (virtual) terminals.
    327 
    328       Note that Busybox binary must be setuid root for this applet to
    329       work properly.
     94INSERT
    33095
    33196endmenu
  • branches/3.3/mindi-busybox/loginutils/Kbuild.src

    r2725 r3621  
    88
    99INSERT
    10 lib-$(CONFIG_ADDGROUP)  += addgroup.o
    11 lib-$(CONFIG_ADDUSER)   += adduser.o
    12 lib-$(CONFIG_CRYPTPW)   += cryptpw.o
    13 lib-$(CONFIG_CHPASSWD)  += chpasswd.o
    14 lib-$(CONFIG_GETTY) += getty.o
    15 lib-$(CONFIG_LOGIN) += login.o
    16 lib-$(CONFIG_PASSWD)    += passwd.o
    17 lib-$(CONFIG_SU)    += su.o
    18 lib-$(CONFIG_SULOGIN)   += sulogin.o
    19 lib-$(CONFIG_VLOCK) += vlock.o
    20 lib-$(CONFIG_DELUSER)   += deluser.o
    21 lib-$(CONFIG_DELGROUP)  += deluser.o
  • branches/3.3/mindi-busybox/loginutils/add-remove-shell.c

    r3232 r3621  
    88 * for details.
    99 */
    10 
    11 //applet:IF_ADD_SHELL(   APPLET_ODDNAME(add-shell   , add_remove_shell, BB_DIR_USR_SBIN, BB_SUID_DROP, add_shell   ))
    12 //applet:IF_REMOVE_SHELL(APPLET_ODDNAME(remove-shell, add_remove_shell, BB_DIR_USR_SBIN, BB_SUID_DROP, remove_shell))
    13 
    14 //kbuild:lib-$(CONFIG_ADD_SHELL)    += add-remove-shell.o
    15 //kbuild:lib-$(CONFIG_REMOVE_SHELL) += add-remove-shell.o
    16 
    1710//config:config ADD_SHELL
    1811//config:       bool "add-shell"
     
    2619//config:       help
    2720//config:         Remove shells from /etc/shells.
     21
     22//applet:IF_ADD_SHELL(   APPLET_ODDNAME(add-shell   , add_remove_shell, BB_DIR_USR_SBIN, BB_SUID_DROP, add_shell   ))
     23//applet:IF_REMOVE_SHELL(APPLET_ODDNAME(remove-shell, add_remove_shell, BB_DIR_USR_SBIN, BB_SUID_DROP, remove_shell))
     24
     25//kbuild:lib-$(CONFIG_ADD_SHELL)    += add-remove-shell.o
     26//kbuild:lib-$(CONFIG_REMOVE_SHELL) += add-remove-shell.o
    2827
    2928//usage:#define add_shell_trivial_usage
     
    101100            }
    102101            /* copy shell name from old to new file */
    103             printf("%s\n", line);
     102            puts(line);
    104103 next_line:
    105104            free(line);
     
    113112        while (*cpp) {
    114113            if (*cpp != dont_add)
    115                 printf("%s\n", *cpp);
     114                puts(*cpp);
    116115            cpp++;
    117116        }
  • branches/3.3/mindi-busybox/loginutils/addgroup.c

    r3232 r3621  
    1010 *
    1111 */
     12//config:config ADDGROUP
     13//config:   bool "addgroup"
     14//config:   default y
     15//config:   help
     16//config:     Utility for creating a new group account.
     17//config:
     18//config:config FEATURE_ADDGROUP_LONG_OPTIONS
     19//config:   bool "Enable long options"
     20//config:   default y
     21//config:   depends on ADDGROUP && LONG_OPTS
     22//config:   help
     23//config:     Support long options for the addgroup applet.
     24//config:
     25//config:config FEATURE_ADDUSER_TO_GROUP
     26//config:   bool "Support for adding users to groups"
     27//config:   default y
     28//config:   depends on ADDGROUP
     29//config:   help
     30//config:     If  called  with two non-option arguments,
     31//config:     addgroup will add an existing user to an
     32//config:     existing group.
     33
     34//applet:IF_ADDGROUP(APPLET(addgroup, BB_DIR_USR_SBIN, BB_SUID_DROP))
     35
     36//kbuild:lib-$(CONFIG_ADDGROUP) += addgroup.o
    1237
    1338//usage:#define addgroup_trivial_usage
    14 //usage:       "[-g GID] " IF_FEATURE_ADDUSER_TO_GROUP("[USER] ") "GROUP"
     39//usage:       "[-g GID] [-S] " IF_FEATURE_ADDUSER_TO_GROUP("[USER] ") "GROUP"
    1540//usage:#define addgroup_full_usage "\n\n"
    16 //usage:       "Add a group " IF_FEATURE_ADDUSER_TO_GROUP("or add a user to a group") "\n"
     41//usage:       "Add a group" IF_FEATURE_ADDUSER_TO_GROUP(" or add a user to a group") "\n"
    1742//usage:     "\n    -g GID  Group id"
    1843//usage:     "\n    -S  Create a system group"
     
    2348#error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config
    2449#endif
     50#if CONFIG_LAST_ID < CONFIG_LAST_SYSTEM_ID
     51#error Bad LAST_ID or LAST_SYSTEM_ID in .config
     52#endif
    2553
    2654#define OPT_GID                       (1 << 0)
    2755#define OPT_SYSTEM_ACCOUNT            (1 << 1)
    2856
    29 /* We assume GID_T_MAX == INT_MAX */
    3057static void xgroup_study(struct group *g)
    3158{
    32     unsigned max = INT_MAX;
     59    unsigned max = CONFIG_LAST_ID;
    3360
    3461    /* Make sure gr_name is unused */
     
    4774        } else {
    4875            g->gr_gid = CONFIG_LAST_SYSTEM_ID + 1;
    49             max = 64999;
    5076        }
    5177    }
     
    126152{
    127153    unsigned opts;
    128     unsigned gid = 0;
     154    const char *gid = "0";
    129155
    130156    /* need to be root */
     
    140166     *  addgroup user group
    141167     * Check for min, max and missing args */
    142     opt_complementary = "-1:?2:g+";
     168    opt_complementary = "-1:?2";
    143169    opts = getopt32(argv, "g:S", &gid);
    144170    /* move past the commandline options */
     
    176202    {
    177203        die_if_bad_username(argv[0]);
    178         new_group(argv[0], gid);
     204        new_group(argv[0], xatou_range(gid, 0, CONFIG_LAST_ID));
    179205    }
    180206    /* Reached only on success */
  • branches/3.3/mindi-busybox/loginutils/adduser.c

    r3232 r3621  
    88 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99 */
     10//config:config ADDUSER
     11//config:   bool "adduser"
     12//config:   default y
     13//config:   help
     14//config:     Utility for creating a new user account.
     15//config:
     16//config:config FEATURE_ADDUSER_LONG_OPTIONS
     17//config:   bool "Enable long options"
     18//config:   default y
     19//config:   depends on ADDUSER && LONG_OPTS
     20//config:   help
     21//config:     Support long options for the adduser applet.
     22//config:
     23//config:config FEATURE_CHECK_NAMES
     24//config:   bool "Enable sanity check on user/group names in adduser and addgroup"
     25//config:   default n
     26//config:   depends on ADDUSER || ADDGROUP
     27//config:   help
     28//config:     Enable sanity check on user and group names in adduser and addgroup.
     29//config:     To avoid problems, the user or group name should consist only of
     30//config:     letters, digits, underscores, periods, at signs and dashes,
     31//config:     and not start with a dash (as defined by IEEE Std 1003.1-2001).
     32//config:     For compatibility with Samba machine accounts "$" is also supported
     33//config:     at the end of the user or group name.
     34//config:
     35//config:config LAST_ID
     36//config:   int "Last valid uid or gid for adduser and addgroup"
     37//config:   depends on ADDUSER || ADDGROUP
     38//config:   default 60000
     39//config:   help
     40//config:     Last valid uid or gid for adduser and addgroup
     41//config:
     42//config:config FIRST_SYSTEM_ID
     43//config:   int "First valid system uid or gid for adduser and addgroup"
     44//config:   depends on ADDUSER || ADDGROUP
     45//config:   range 0 LAST_ID
     46//config:   default 100
     47//config:   help
     48//config:     First valid system uid or gid for adduser and addgroup
     49//config:
     50//config:config LAST_SYSTEM_ID
     51//config:   int "Last valid system uid or gid for adduser and addgroup"
     52//config:   depends on ADDUSER || ADDGROUP
     53//config:   range FIRST_SYSTEM_ID LAST_ID
     54//config:   default 999
     55//config:   help
     56//config:     Last valid system uid or gid for adduser and addgroup
     57
     58//applet:IF_ADDUSER(APPLET(adduser, BB_DIR_USR_SBIN, BB_SUID_DROP))
     59
     60//kbuild:lib-$(CONFIG_ADDUSER) += adduser.o
    1061
    1162//usage:#define adduser_trivial_usage
     
    2172//usage:     "\n    -H      Don't create home directory"
    2273//usage:     "\n    -u UID      User id"
     74//usage:     "\n    -k SKEL     Skeleton directory (/etc/skel)"
    2375
    2476#include "libbb.h"
     
    2779#error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config
    2880#endif
     81#if CONFIG_LAST_ID < CONFIG_LAST_SYSTEM_ID
     82#error Bad LAST_ID or LAST_SYSTEM_ID in .config
     83#endif
     84
    2985
    3086/* #define OPT_HOME           (1 << 0) */ /* unused */
     
    3692#define OPT_DONT_MAKE_HOME (1 << 6)
    3793#define OPT_UID            (1 << 7)
    38 
    39 /* We assume UID_T_MAX == INT_MAX */
     94#define OPT_SKEL           (1 << 8)
     95
    4096/* remix */
    4197/* recoded such that the uid may be passed in *p */
    4298static void passwd_study(struct passwd *p)
    4399{
    44     int max = UINT_MAX;
     100    int max = CONFIG_LAST_ID;
    45101
    46102    if (getpwnam(p->pw_name)) {
     
    55111        } else {
    56112            p->pw_uid = CONFIG_LAST_SYSTEM_ID + 1;
    57             max = 64999;
    58113        }
    59114    }
     
    133188        "no-create-home\0"      No_argument       "H"
    134189        "uid\0"                 Required_argument "u"
     190        "skel\0"                Required_argument "k"
    135191        ;
    136192#endif
     
    148204    char *p;
    149205    unsigned opts;
     206    char *uid;
     207    const char *skel = "/etc/skel";
    150208
    151209#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
     
    163221    pw.pw_dir = NULL;
    164222
    165     /* at most two non-option args */
     223    /* at least one and at most two non-option args */
    166224    /* disable interactive passwd for system accounts */
    167     opt_complementary = "?2:SD:u+";
    168     if (sizeof(pw.pw_uid) == sizeof(int)) {
    169         opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &pw.pw_uid);
    170     } else {
    171         unsigned uid;
    172         opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid);
    173         if (opts & OPT_UID) {
    174             pw.pw_uid = uid;
    175         }
    176     }
     225    opt_complementary = "-1:?2:SD";
     226    opts = getopt32(argv, "h:g:s:G:DSHu:k:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid, &skel);
     227    if (opts & OPT_UID)
     228        pw.pw_uid = xatou_range(uid, 0, CONFIG_LAST_ID);
     229
    177230    argv += optind;
    178231    pw.pw_name = argv[0];
     
    253306            };
    254307            /* Be silent on any errors (like: no /etc/skel) */
    255             logmode = LOGMODE_NONE;
    256             copy_file("/etc/skel", pw.pw_dir, FILEUTILS_RECUR);
     308            if (!(opts & OPT_SKEL))
     309                logmode = LOGMODE_NONE;
     310            copy_file(skel, pw.pw_dir, FILEUTILS_RECUR);
    257311            logmode = LOGMODE_STDIO;
    258312            chown_main(4, (char**)args);
  • branches/3.3/mindi-busybox/loginutils/chpasswd.c

    r3232 r3621  
    66 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    77 */
    8 #include "libbb.h"
     8//config:config CHPASSWD
     9//config:   bool "chpasswd"
     10//config:   default y
     11//config:   help
     12//config:     Reads a file of user name and password pairs from standard input
     13//config:     and uses this information to update a group of existing users.
     14//config:
     15//config:config FEATURE_DEFAULT_PASSWD_ALGO
     16//config:   string "Default password encryption method (passwd -a, cryptpw -m parameter)"
     17//config:   default "des"
     18//config:   depends on PASSWD || CRYPTPW
     19//config:   help
     20//config:     Possible choices are "d[es]", "m[d5]", "s[ha256]" or "sha512".
     21
     22//applet:IF_CHPASSWD(APPLET(chpasswd, BB_DIR_USR_SBIN, BB_SUID_DROP))
     23
     24//kbuild:lib-$(CONFIG_CHPASSWD) += chpasswd.o
    925
    1026//usage:#define chpasswd_trivial_usage
    11 //usage:    IF_LONG_OPTS("[--md5|--encrypted]") IF_NOT_LONG_OPTS("[-m|-e]")
     27//usage:    IF_LONG_OPTS("[--md5|--encrypted|--crypt-method]") IF_NOT_LONG_OPTS("[-m|-e|-c]")
    1228//usage:#define chpasswd_full_usage "\n\n"
    1329//usage:       "Read user:password from stdin and update /etc/passwd\n"
    1430//usage:    IF_LONG_OPTS(
    15 //usage:     "\n    -e,--encrypted  Supplied passwords are in encrypted form"
    16 //usage:     "\n    -m,--md5    Use MD5 encryption instead of DES"
     31//usage:     "\n    -e,--encrypted      Supplied passwords are in encrypted form"
     32//usage:     "\n    -m,--md5        Use MD5 encryption instead of DES"
     33//usage:     "\n    -c,--crypt-method   Use the specified method to encrypt the passwords"
    1734//usage:    )
    1835//usage:    IF_NOT_LONG_OPTS(
    1936//usage:     "\n    -e  Supplied passwords are in encrypted form"
    2037//usage:     "\n    -m  Use MD5 encryption instead of DES"
     38//usage:     "\n    -c  Use the specified method to encrypt the passwords"
    2139//usage:    )
    2240
    23 //TODO: implement -c ALGO
     41#include "libbb.h"
    2442
    2543#if ENABLE_LONG_OPTS
    2644static const char chpasswd_longopts[] ALIGN1 =
    27     "encrypted\0" No_argument "e"
    28     "md5\0"       No_argument "m"
     45    "encrypted\0"    No_argument       "e"
     46    "md5\0"          No_argument       "m"
     47    "crypt-method\0" Required_argument "c"
    2948    ;
    3049#endif
     
    3756{
    3857    char *name;
     58    const char *algo = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO;
    3959    int opt;
    4060
     
    4262        bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
    4363
    44     opt_complementary = "m--e:e--m";
     64    opt_complementary = "m--ec:e--mc:c--em";
    4565    IF_LONG_OPTS(applet_long_options = chpasswd_longopts;)
    46     opt = getopt32(argv, "em");
     66    opt = getopt32(argv, "emc:", &algo);
    4767
    4868    while ((name = xmalloc_fgetline(stdin)) != NULL) {
     
    6080        free_me = NULL;
    6181        if (!(opt & OPT_ENC)) {
    62             char salt[sizeof("$N$XXXXXXXX")];
     82            char salt[MAX_PW_SALT_LEN];
    6383
    64             crypt_make_salt(salt, 1);
    6584            if (opt & OPT_MD5) {
    66                 salt[0] = '$';
    67                 salt[1] = '1';
    68                 salt[2] = '$';
    69                 crypt_make_salt(salt + 3, 4);
     85                /* Force MD5 if the -m flag is set */
     86                algo = "md5";
    7087            }
     88
     89            crypt_make_pw_salt(salt, algo);
    7190            free_me = pass = pw_encrypt(pass, salt, 0);
    7291        }
     
    87106            bb_error_msg_and_die("an error occurred updating password for %s", name);
    88107        if (rc)
    89             bb_info_msg("Password for '%s' changed", name);
     108            bb_error_msg("password for '%s' changed", name);
    90109        logmode = LOGMODE_STDIO;
    91110        free(name);
  • branches/3.3/mindi-busybox/loginutils/cryptpw.c

    r3232 r3621  
    1010 * Licensed under GPLv2, see file LICENSE in this source tree.
    1111 */
     12//config:config CRYPTPW
     13//config:   bool "cryptpw"
     14//config:   default y
     15//config:   help
     16//config:     Encrypts the given password with the crypt(3) libc function
     17//config:     using the given salt.
     18//config:
     19//config:config MKPASSWD
     20//config:   bool "mkpasswd"
     21//config:   default y
     22//config:   help
     23//config:     Encrypts the given password with the crypt(3) libc function
     24//config:     using the given salt. Debian has this utility under mkpasswd
     25//config:     name. Busybox provides mkpasswd as an alias for cryptpw.
     26
     27//applet:IF_CRYPTPW(APPLET(cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP))
     28//                   APPLET_ODDNAME:name      main     location        suid_type     help
     29//applet:IF_MKPASSWD(APPLET_ODDNAME(mkpasswd, cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP, cryptpw))
     30
     31//kbuild:lib-$(CONFIG_CRYPTPW) += cryptpw.o
     32//kbuild:lib-$(CONFIG_MKPASSWD) += cryptpw.o
    1233
    1334//usage:#define cryptpw_trivial_usage
     
    1536/* We do support -s, we just don't mention it */
    1637//usage:#define cryptpw_full_usage "\n\n"
    17 //usage:       "Crypt PASSWORD using crypt(3)\n"
    18 //usage:    IF_LONG_OPTS(
    19 //usage:     "\n    -P,--password-fd=N  Read password from fd N"
    20 /* //usage:  "\n    -s,--stdin      Use stdin; like -P0" */
    21 //usage:     "\n    -m,--method=TYPE    Encryption method"
    22 //usage:     "\n    -S,--salt=SALT"
    23 //usage:    )
    24 //usage:    IF_NOT_LONG_OPTS(
    25 //usage:     "\n    -P N    Read password from fd N"
    26 /* //usage:  "\n    -s  Use stdin; like -P0" */
    27 //usage:     "\n    -m TYPE Encryption method TYPE"
    28 //usage:     "\n    -S SALT"
    29 //usage:    )
    30 
    31 /* mkpasswd is an alias to cryptpw */
    32 //usage:#define mkpasswd_trivial_usage
    33 //usage:       "[OPTIONS] [PASSWORD] [SALT]"
    34 /* We do support -s, we just don't mention it */
    35 //usage:#define mkpasswd_full_usage "\n\n"
    3638//usage:       "Crypt PASSWORD using crypt(3)\n"
    3739//usage:    IF_LONG_OPTS(
     
    9395    char salt[MAX_PW_SALT_LEN];
    9496    char *salt_ptr;
     97    char *password;
    9598    const char *opt_m, *opt_S;
    9699    int fd;
     
    124127    xmove_fd(fd, STDIN_FILENO);
    125128
    126     puts(pw_encrypt(
    127         argv[0] ? argv[0] : (
    128             /* Only mkpasswd, and only from tty, prompts.
    129             * Otherwise it is a plain read. */
    130             (isatty(STDIN_FILENO) && applet_name[0] == 'm')
     129    password = argv[0];
     130    if (!password) {
     131        /* Only mkpasswd, and only from tty, prompts.
     132        * Otherwise it is a plain read. */
     133        password = (ENABLE_MKPASSWD && isatty(STDIN_FILENO) && applet_name[0] == 'm')
    131134            ? bb_ask_stdin("Password: ")
    132135            : xmalloc_fgetline(stdin)
    133         ),
    134         salt, 1));
     136        ;
     137        /* may still be NULL on EOF/error */
     138    }
     139
     140    if (password)
     141        puts(pw_encrypt(password, salt, 1));
    135142
    136143    return EXIT_SUCCESS;
  • branches/3.3/mindi-busybox/loginutils/deluser.c

    r3232 r3621  
    88 *
    99 * Licensed under GPLv2, see file LICENSE in this source tree.
    10  *
    1110 */
     11//config:config DELUSER
     12//config:   bool "deluser"
     13//config:   default y
     14//config:   help
     15//config:     Utility for deleting a user account.
     16//config:
     17//config:config DELGROUP
     18//config:   bool "delgroup"
     19//config:   default y
     20//config:   help
     21//config:     Utility for deleting a group account.
     22//config:
     23//config:config FEATURE_DEL_USER_FROM_GROUP
     24//config:   bool "Support for removing users from groups"
     25//config:   default y
     26//config:   depends on DELGROUP
     27//config:   help
     28//config:     If called with two non-option arguments, deluser
     29//config:     or delgroup will remove an user from a specified group.
     30
     31//applet:IF_DELUSER(APPLET(deluser, BB_DIR_USR_SBIN, BB_SUID_DROP))
     32//applet:IF_DELGROUP(APPLET_ODDNAME(delgroup, deluser, BB_DIR_USR_SBIN, BB_SUID_DROP, delgroup))
     33
     34//kbuild:lib-$(CONFIG_DELUSER) += deluser.o
     35//kbuild:lib-$(CONFIG_DELGROUP) += deluser.o
    1236
    1337//usage:#define deluser_trivial_usage
    14 //usage:       "USER"
     38//usage:       IF_LONG_OPTS("[--remove-home] ") "USER"
    1539//usage:#define deluser_full_usage "\n\n"
    1640//usage:       "Delete USER from the system"
     41//  --remove-home is self-explanatory enough to put it in --help
    1742
    1843//usage:#define delgroup_trivial_usage
     
    3863    int do_deluser = (ENABLE_DELUSER && (!ENABLE_DELGROUP || applet_name[3] == 'u'));
    3964
     65#if !ENABLE_LONG_OPTS
     66    const int opt_delhome = 0;
     67#else
     68    int opt_delhome = 0;
     69    if (do_deluser) {
     70        applet_long_options =
     71            "remove-home\0" No_argument "\xff";
     72        opt_delhome = getopt32(argv, "");
     73        argv += opt_delhome;
     74        argc -= opt_delhome;
     75    }
     76#endif
     77
    4078    if (geteuid() != 0)
    4179        bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
     
    5694        if (do_deluser) {
    5795            /* "deluser USER" */
    58             xgetpwnam(name); /* bail out if USER is wrong */
     96            struct passwd *pw;
     97
     98            pw = xgetpwnam(name); /* bail out if USER is wrong */
    5999            pfile = bb_path_passwd_file;
    60100            if (ENABLE_FEATURE_SHADOWPASSWDS)
    61101                sfile = bb_path_shadow_file;
     102            if (opt_delhome)
     103                remove_file(pw->pw_dir, FILEUTILS_RECUR);
    62104        } else {
    63105            struct group *gr;
     
    74116                /* "delgroup GROUP" */
    75117                struct passwd *pw;
    76                 struct passwd pwent;
    77118                /* Check if the group is in use */
    78 #define passwd_buf bb_common_bufsiz1
    79                 while (!getpwent_r(&pwent, passwd_buf, sizeof(passwd_buf), &pw)) {
    80                     if (pwent.pw_gid == gr->gr_gid)
    81                         bb_error_msg_and_die("'%s' still has '%s' as their primary group!", pwent.pw_name, name);
     119                while ((pw = getpwent()) != NULL) {
     120                    if (pw->pw_gid == gr->gr_gid)
     121                        bb_error_msg_and_die("'%s' still has '%s' as their primary group!",
     122                            pw->pw_name, name);
    82123                }
    83124                //endpwent();
     
    98139        } while (ENABLE_FEATURE_SHADOWPASSWDS && pfile);
    99140
    100         if (ENABLE_DELGROUP && do_deluser > 0) {
    101             /* "deluser USER" also should try to delete
    102              * same-named group. IOW: do "delgroup USER"
    103              */
     141        if (do_deluser > 0) {
     142            /* Delete user from all groups */
     143            if (update_passwd(bb_path_group_file, NULL, NULL, name) == -1)
     144                return EXIT_FAILURE;
     145
     146            if (ENABLE_DELGROUP) {
     147                /* "deluser USER" also should try to delete
     148                 * same-named group. IOW: do "delgroup USER"
     149                 */
    104150// On debian deluser is a perl script that calls userdel.
    105151// From man userdel:
    106152//  If USERGROUPS_ENAB is defined to yes in /etc/login.defs, userdel will
    107153//  delete the group with the same name as the user.
    108             do_deluser = -1;
    109             goto do_delgroup;
     154                do_deluser = -1;
     155                goto do_delgroup;
     156            }
    110157        }
    111158        return EXIT_SUCCESS;
  • branches/3.3/mindi-busybox/loginutils/getty.c

    r3232 r3621  
    2222 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    2323 */
     24//config:config GETTY
     25//config:   bool "getty"
     26//config:   default y
     27//config:   select FEATURE_SYSLOG
     28//config:   help
     29//config:     getty lets you log in on a tty. It is normally invoked by init.
     30//config:
     31//config:     Note that you can save a few bytes by disabling it and
     32//config:     using login applet directly.
     33//config:     If you need to reset tty attributes before calling login,
     34//config:     this script approximates getty:
     35//config:
     36//config:     exec </dev/$1 >/dev/$1 2>&1 || exit 1
     37//config:     reset
     38//config:     stty sane; stty ispeed 38400; stty ospeed 38400
     39//config:     printf "%s login: " "`hostname`"
     40//config:     read -r login
     41//config:     exec /bin/login "$login"
     42
     43//applet:IF_GETTY(APPLET(getty, BB_DIR_SBIN, BB_SUID_DROP))
     44
     45//kbuild:lib-$(CONFIG_GETTY) += getty.o
    2446
    2547#include "libbb.h"
     
    335357     */
    336358
    337     /* line buffered input (NL or EOL or EOF chars end a line);
    338      * recognize INT/QUIT/SUSP chars;
    339      * echo input chars;
    340      * echo BS-SP-BS on erase character;
    341      * echo kill char specially, not as ^c (ECHOKE controls how exactly);
    342      * erase all input via BS-SP-BS on kill char (else go to next line)
    343      */
    344     G.tty_attrs.c_lflag |= ICANON | ISIG | ECHO | ECHOE | ECHOK | ECHOKE;
     359    /* ICANON  line buffered input (NL or EOL or EOF chars end a line);
     360     * ISIG    recognize INT/QUIT/SUSP chars;
     361     * ECHO    echo input chars;
     362     * ECHOE   echo BS-SP-BS on erase character;
     363     * ECHOK   echo kill char specially, not as ^c (ECHOKE controls how exactly);
     364     * ECHOKE  erase all input via BS-SP-BS on kill char (else go to next line)
     365     * ECHOCTL Echo ctrl chars as ^c (else echo verbatim:
     366     *         e.g. up arrow emits "ESC-something" and thus moves cursor up!)
     367     */
     368    G.tty_attrs.c_lflag |= ICANON | ISIG | ECHO | ECHOE | ECHOK | ECHOKE | ECHOCTL;
    345369    /* Other bits in c_lflag:
    346370     * XCASE   Map uppercase to \lowercase [tried, doesn't work]
    347371     * ECHONL  Echo NL even if ECHO is not set
    348      * ECHOCTL Echo ctrl chars as ^c (else don't echo) - maybe set this?
    349372     * ECHOPRT On erase, echo erased chars
    350373     *         [qwe<BS><BS><BS> input looks like "qwe\ewq/" on screen]
     
    520543}
    521544
     545static void sleep10(void)
     546{
     547    sleep(10);
     548}
     549
    522550int getty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    523551int getty_main(int argc UNUSED_PARAM, char **argv)
     
    557585            //  getsid(0), getpgid(0));
    558586            bb_perror_msg_and_die("setsid");
     587            /*
     588             * When we can end up here?
     589             * Example: setsid() fails when run alone in interactive shell:
     590             *  # getty 115200 /dev/tty2
     591             * because shell's child (getty) is put in a new process group.
     592             * But doesn't fail if shell is not interactive
     593             * (and therefore doesn't create process groups for pipes),
     594             * or if getty is not the first process in the process group:
     595             *  # true | getty 115200 /dev/tty2
     596             */
    559597        }
    560598        /* Looks like we are already a session leader.
     
    589627
    590628    /* Logging. We want special flavor of error_msg_and_die */
    591     die_sleep = 10;
     629    die_func = sleep10;
    592630    msg_eol = "\r\n";
    593631    /* most likely will internally use fd #3 in CLOEXEC mode: */
     
    696734     * and getty is not suid-root applet */
    697735    /* With -n, logname == NULL, and login will ask for username instead */
    698     BB_EXECLP(G.login, G.login, "--", logname, NULL);
     736    BB_EXECLP(G.login, G.login, "--", logname, (char *)0);
    699737    bb_error_msg_and_die("can't execute '%s'", G.login);
    700738}
  • branches/3.3/mindi-busybox/loginutils/login.c

    r3232 r3621  
    33 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    44 */
     5//config:config LOGIN
     6//config:   bool "login"
     7//config:   default y
     8//config:   select FEATURE_SYSLOG
     9//config:   help
     10//config:     login is used when signing onto a system.
     11//config:
     12//config:     Note that Busybox binary must be setuid root for this applet to
     13//config:     work properly.
     14//config:
     15//config:config LOGIN_SESSION_AS_CHILD
     16//config:   bool "Run logged in session in a child process"
     17//config:   default y if PAM
     18//config:   depends on LOGIN
     19//config:   help
     20//config:     Run the logged in session in a child process.  This allows
     21//config:     login to clean up things such as utmp entries or PAM sessions
     22//config:     when the login session is complete.  If you use PAM, you
     23//config:     almost always would want this to be set to Y, else PAM session
     24//config:     will not be cleaned up.
     25//config:
     26//config:config LOGIN_SCRIPTS
     27//config:   bool "Support for login scripts"
     28//config:   depends on LOGIN
     29//config:   default y
     30//config:   help
     31//config:     Enable this if you want login to execute $LOGIN_PRE_SUID_SCRIPT
     32//config:     just prior to switching from root to logged-in user.
     33//config:
     34//config:config FEATURE_NOLOGIN
     35//config:   bool "Support for /etc/nologin"
     36//config:   default y
     37//config:   depends on LOGIN
     38//config:   help
     39//config:     The file /etc/nologin is used by (some versions of) login(1).
     40//config:     If it exists, non-root logins are prohibited.
     41//config:
     42//config:config FEATURE_SECURETTY
     43//config:   bool "Support for /etc/securetty"
     44//config:   default y
     45//config:   depends on LOGIN
     46//config:   help
     47//config:     The file /etc/securetty is used by (some versions of) login(1).
     48//config:     The file contains the device names of tty lines (one per line,
     49//config:     without leading /dev/) on which root is allowed to login.
     50
     51//applet:/* Needs to be run by root or be suid root - needs to change uid and gid: */
     52//applet:IF_LOGIN(APPLET(login, BB_DIR_BIN, BB_SUID_REQUIRE))
     53
     54//kbuild:lib-$(CONFIG_LOGIN) += login.o
    555
    656//usage:#define login_trivial_usage
     
    959//usage:       "Begin a new session on the system\n"
    1060//usage:     "\n    -f  Don't authenticate (user already authenticated)"
    11 //usage:     "\n    -h  Name of the remote host"
     61//usage:     "\n    -h HOST Host user came from (for network logins)"
    1262//usage:     "\n    -p  Preserve environment"
    1363
    1464#include "libbb.h"
     65#include "common_bufsiz.h"
    1566#include <syslog.h>
    1667#include <sys/resource.h>
     
    2980# include <security/pam_appl.h>
    3081# include <security/pam_misc.h>
     82
     83# if 0
     84/* This supposedly can be used to avoid double password prompt,
     85 * if used instead of standard misc_conv():
     86 *
     87 * "When we want to authenticate first with local method and then with tacacs for example,
     88 *  the password is asked for local method and if not good is asked a second time for tacacs.
     89 *  So if we want to authenticate a user with tacacs, and the user exists localy, the password is
     90 *  asked two times before authentication is accepted."
     91 *
     92 * However, code looks shaky. For example, why misc_conv() return value is ignored?
     93 * Are msg[i] and resp[i] indexes handled correctly?
     94 */
     95static char *passwd = NULL;
     96static int my_conv(int num_msg, const struct pam_message **msg,
     97        struct pam_response **resp, void *data)
     98{
     99    int i;
     100    for (i = 0; i < num_msg; i++) {
     101        switch (msg[i]->msg_style) {
     102        case PAM_PROMPT_ECHO_OFF:
     103            if (passwd == NULL) {
     104                misc_conv(num_msg, msg, resp, data);
     105                passwd = xstrdup(resp[i]->resp);
     106                return PAM_SUCCESS;
     107            }
     108
     109            resp[0] = xzalloc(sizeof(struct pam_response));
     110            resp[0]->resp = passwd;
     111            passwd = NULL;
     112            resp[0]->resp_retcode = PAM_SUCCESS;
     113            resp[1] = NULL;
     114            return PAM_SUCCESS;
     115
     116        default:
     117            break;
     118        }
     119    }
     120
     121    return PAM_SUCCESS;
     122}
     123# endif
     124
    31125static const struct pam_conv conv = {
    32126    misc_conv,
     
    46140    struct termios tty_attrs;
    47141} FIX_ALIASING;
    48 #define G (*(struct globals*)&bb_common_bufsiz1)
    49 #define INIT_G() do { } while (0)
     142#define G (*(struct globals*)bb_common_bufsiz1)
     143#define INIT_G() do { setup_common_bufsiz(); } while (0)
    50144
    51145
     
    421515         * If we get interrupted by SIGALRM, we need to restore attrs.
    422516         */
    423         if (correct_password(pw))
     517        if (ask_and_check_password(pw) > 0)
    424518            break;
    425519#endif /* ENABLE_PAM */
     
    455549            if (safe_waitpid(child_pid, NULL, 0) == -1)
    456550                bb_perror_msg("waitpid");
    457             update_utmp(child_pid, DEAD_PROCESS, NULL, NULL, NULL);
     551            update_utmp_DEAD_PROCESS(child_pid);
    458552        }
    459553        IF_PAM(login_pam_end(pamh);)
     
    490584#endif
    491585
    492     motd();
     586    if (access(".hushlogin", F_OK) != 0)
     587        motd();
    493588
    494589    if (pw->pw_uid == 0)
  • branches/3.3/mindi-busybox/loginutils/passwd.c

    r3232 r3621  
    33 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    44 */
     5//config:config PASSWD
     6//config:   bool "passwd"
     7//config:   default y
     8//config:   select FEATURE_SYSLOG
     9//config:   help
     10//config:     passwd changes passwords for user and group accounts. A normal user
     11//config:     may only change the password for his/her own account, the super user
     12//config:     may change the password for any account. The administrator of a group
     13//config:     may change the password for the group.
     14//config:
     15//config:     Note that Busybox binary must be setuid root for this applet to
     16//config:     work properly.
     17//config:
     18//config:config FEATURE_PASSWD_WEAK_CHECK
     19//config:   bool "Check new passwords for weakness"
     20//config:   default y
     21//config:   depends on PASSWD
     22//config:   help
     23//config:     With this option passwd will refuse new passwords which are "weak".
     24
     25//applet:/* Needs to be run by root or be suid root - needs to change /etc/{passwd,shadow}: */
     26//applet:IF_PASSWD(APPLET(passwd, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
     27
     28//kbuild:lib-$(CONFIG_PASSWD) += passwd.o
    529
    630//usage:#define passwd_trivial_usage
     
    1741#include <syslog.h>
    1842#include <sys/resource.h> /* setrlimit */
    19 
    20 static void nuke_str(char *str)
    21 {
    22     if (str) memset(str, 0, strlen(str));
    23 }
    2443
    2544static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo)
     
    212231    if (rc < 0)
    213232        bb_error_msg_and_die("can't update password file %s", filename);
    214     bb_info_msg("Password for %s changed by %s", name, myname);
     233    bb_error_msg("password for %s changed by %s", name, myname);
    215234
    216235    /*if (ENABLE_FEATURE_CLEAN_UP) free(newp); - can't, it may be non-malloced */
  • branches/3.3/mindi-busybox/loginutils/su.c

    r3232 r3621  
    55 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    66 */
     7//config:config SU
     8//config:   bool "su"
     9//config:   default y
     10//config:   select FEATURE_SYSLOG
     11//config:   help
     12//config:     su is used to become another user during a login session.
     13//config:     Invoked without a username, su defaults to becoming the super user.
     14//config:
     15//config:     Note that Busybox binary must be setuid root for this applet to
     16//config:     work properly.
     17//config:
     18//config:config FEATURE_SU_SYSLOG
     19//config:   bool "Enable su to write to syslog"
     20//config:   default y
     21//config:   depends on SU
     22//config:
     23//config:config FEATURE_SU_CHECKS_SHELLS
     24//config:   bool "Enable su to check user's shell to be listed in /etc/shells"
     25//config:   depends on SU
     26//config:   default y
    727
    8 #include "libbb.h"
    9 #include <syslog.h>
     28//applet:/* Needs to be run by root or be suid root - needs to change uid and gid: */
     29//applet:IF_SU(APPLET(su, BB_DIR_BIN, BB_SUID_REQUIRE))
     30
     31//kbuild:lib-$(CONFIG_SU) += su.o
    1032
    1133//usage:#define su_trivial_usage
     
    1739//usage:     "\n    -c CMD  Command to pass to 'sh -c'"
    1840//usage:     "\n    -s SH   Shell to use instead of user's default"
     41
     42#include "libbb.h"
     43#include <syslog.h>
    1944
    2045#if ENABLE_FEATURE_SU_CHECKS_SHELLS
     
    94119    pw = xgetpwnam(opt_username);
    95120
    96     if (cur_uid == 0 || correct_password(pw)) {
     121    if (cur_uid == 0 || ask_and_check_password(pw) > 0) {
    97122        if (ENABLE_FEATURE_SU_SYSLOG)
    98123            syslog(LOG_NOTICE, "%c %s %s:%s",
     
    102127            syslog(LOG_NOTICE, "%c %s %s:%s",
    103128                '-', tty, old_user, opt_username);
     129        bb_do_delay(LOGIN_FAIL_DELAY);
    104130        bb_error_msg_and_die("incorrect password");
    105131    }
  • branches/3.3/mindi-busybox/loginutils/sulogin.c

    r3232 r3621  
    55 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    66 */
     7//config:config SULOGIN
     8//config:   bool "sulogin"
     9//config:   default y
     10//config:   select FEATURE_SYSLOG
     11//config:   help
     12//config:     sulogin is invoked when the system goes into single user
     13//config:     mode (this is done through an entry in inittab).
     14
     15//applet:IF_SULOGIN(APPLET(sulogin, BB_DIR_SBIN, BB_SUID_DROP))
     16
     17//kbuild:lib-$(CONFIG_SULOGIN) += sulogin.o
    718
    819//usage:#define sulogin_trivial_usage
     
    1526#include <syslog.h>
    1627
    17 //static void catchalarm(int UNUSED_PARAM junk)
    18 //{
    19 //  exit(EXIT_FAILURE);
    20 //}
    21 
    22 
    2328int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    2429int sulogin_main(int argc UNUSED_PARAM, char **argv)
    2530{
    26     char *cp;
    2731    int timeout = 0;
    2832    struct passwd *pwd;
    2933    const char *shell;
    30 #if ENABLE_FEATURE_SHADOWPASSWDS
    31     /* Using _r function to avoid pulling in static buffers */
    32     char buffer[256];
    33     struct spwd spw;
    34 #endif
     34
     35    /* Note: sulogin is not a suid app. It is meant to be run by init
     36     * for single user / emergency mode. init starts it as root.
     37     * Normal users (potentially malisious ones) can only run it under
     38     * their UID, therefore no paranoia here is warranted:
     39     * $LD_LIBRARY_PATH in env, TTY = /dev/sda
     40     * are no more dangerous here than in e.g. cp applet.
     41     */
    3542
    3643    logmode = LOGMODE_BOTH;
     
    4956    }
    5057
    51     /* Malicious use like "sulogin /dev/sda"? */
    52     if (!isatty(0) || !isatty(1) || !isatty(2)) {
    53         logmode = LOGMODE_SYSLOG;
    54         bb_error_msg_and_die("not a tty");
     58    pwd = getpwuid(0);
     59    if (!pwd) {
     60        bb_error_msg_and_die("no password entry for root");
    5561    }
    5662
    57     /* Clear dangerous stuff, set PATH */
    58     sanitize_env_if_suid();
    59 
    60     pwd = getpwuid(0);
    61     if (!pwd) {
    62         goto auth_error;
    63     }
    64 
    65 #if ENABLE_FEATURE_SHADOWPASSWDS
    66     {
    67         /* getspnam_r may return 0 yet set result to NULL.
    68          * At least glibc 2.4 does this. Be extra paranoid here. */
    69         struct spwd *result = NULL;
    70         int r = getspnam_r(pwd->pw_name, &spw, buffer, sizeof(buffer), &result);
    71         if (r || !result) {
    72             goto auth_error;
    73         }
    74         pwd->pw_passwd = result->sp_pwdp;
    75     }
    76 #endif
    77 
    7863    while (1) {
    79         char *encrypted;
    8064        int r;
    8165
    82         /* cp points to a static buffer that is zeroed every time */
    83         cp = bb_ask(STDIN_FILENO, timeout,
    84                 "Give root password for system maintenance\n"
    85                 "(or type Control-D for normal startup):");
    86 
    87         if (!cp || !*cp) {
    88             bb_info_msg("Normal startup");
     66        r = ask_and_check_password_extended(pwd, timeout,
     67            "Give root password for system maintenance\n"
     68            "(or type Control-D for normal startup):"
     69        );
     70        if (r < 0) {
     71            /* ^D, ^C, timeout, or read error */
     72            bb_error_msg("normal startup");
    8973            return 0;
    9074        }
    91         encrypted = pw_encrypt(cp, pwd->pw_passwd, 1);
    92         r = strcmp(encrypted, pwd->pw_passwd);
    93         free(encrypted);
    94         if (r == 0) {
     75        if (r > 0) {
    9576            break;
    9677        }
    9778        bb_do_delay(LOGIN_FAIL_DELAY);
    98         bb_info_msg("Login incorrect");
     79        bb_error_msg("Login incorrect");
    9980    }
    100     memset(cp, 0, strlen(cp));
    101 //  signal(SIGALRM, SIG_DFL);
    10281
    103     bb_info_msg("System Maintenance Mode");
     82    bb_error_msg("starting shell for system maintenance");
    10483
    10584    IF_SELINUX(renew_current_security_context());
     
    11392    /* Exec login shell with no additional parameters. Never returns. */
    11493    run_shell(shell, 1, NULL, NULL);
    115 
    116  auth_error:
    117     bb_error_msg_and_die("no password entry for root");
    11894}
  • branches/3.3/mindi-busybox/loginutils/vlock.c

    r3232 r3621  
    1414 */
    1515/* Fixed by Erik Andersen to do passwords the tinylogin way...
    16  * It now works with md5, sha1, etc passwords. */
     16 * It now works with md5, sha1, etc passwords.
     17 */
     18//config:config VLOCK
     19//config:   bool "vlock"
     20//config:   default y
     21//config:   help
     22//config:     Build the "vlock" applet which allows you to lock (virtual) terminals.
     23//config:
     24//config:     Note that Busybox binary must be setuid root for this applet to
     25//config:     work properly.
     26
     27//applet:/* Needs to be run by root or be suid root - needs to change uid and gid: */
     28//applet:IF_VLOCK(APPLET(vlock, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
     29
     30//kbuild:lib-$(CONFIG_VLOCK) += vlock.o
    1731
    1832//usage:#define vlock_trivial_usage
     
    105119                pw->pw_name
    106120        );
    107         if (correct_password(pw)) {
     121        if (ask_and_check_password(pw) > 0) {
    108122            break;
    109123        }
Note: See TracChangeset for help on using the changeset viewer.