Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (7 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/loginutils/cryptpw.c

    r2725 r3232  
    1010 * Licensed under GPLv2, see file LICENSE in this source tree.
    1111 */
     12
     13//usage:#define cryptpw_trivial_usage
     14//usage:       "[OPTIONS] [PASSWORD] [SALT]"
     15/* We do support -s, we just don't mention it */
     16//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"
     36//usage:       "Crypt PASSWORD using crypt(3)\n"
     37//usage:    IF_LONG_OPTS(
     38//usage:     "\n    -P,--password-fd=N  Read password from fd N"
     39/* //usage:  "\n    -s,--stdin      Use stdin; like -P0" */
     40//usage:     "\n    -m,--method=TYPE    Encryption method"
     41//usage:     "\n    -S,--salt=SALT"
     42//usage:    )
     43//usage:    IF_NOT_LONG_OPTS(
     44//usage:     "\n    -P N    Read password from fd N"
     45/* //usage:  "\n    -s  Use stdin; like -P0" */
     46//usage:     "\n    -m TYPE Encryption method TYPE"
     47//usage:     "\n    -S SALT"
     48//usage:    )
    1249
    1350#include "libbb.h"
     
    5491int cryptpw_main(int argc UNUSED_PARAM, char **argv)
    5592{
    56     /* $N$ + sha_salt_16_bytes + NUL */
    57     char salt[3 + 16 + 1];
     93    char salt[MAX_PW_SALT_LEN];
    5894    char *salt_ptr;
    5995    const char *opt_m, *opt_S;
    60     int len;
    6196    int fd;
    6297
     
    71106#endif
    72107    fd = STDIN_FILENO;
    73     opt_m = "d";
     108    opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO;
    74109    opt_S = NULL;
    75110    /* at most two non-option arguments; -P NUM */
     
    83118        opt_S = argv[1];
    84119
    85     len = 2/2;
    86     salt_ptr = salt;
    87     if (opt_m[0] != 'd') { /* not des */
    88         len = 8/2; /* so far assuming md5 */
    89         *salt_ptr++ = '$';
    90         *salt_ptr++ = '1';
    91         *salt_ptr++ = '$';
    92 #if !ENABLE_USE_BB_CRYPT || ENABLE_USE_BB_CRYPT_SHA
    93         if (opt_m[0] == 's') { /* sha */
    94             salt[1] = '5' + (strcmp(opt_m, "sha512") == 0);
    95             len = 16/2;
    96         }
    97 #endif
    98     }
     120    salt_ptr = crypt_make_pw_salt(salt, opt_m);
    99121    if (opt_S)
    100         safe_strncpy(salt_ptr, opt_S, sizeof(salt) - 3);
    101     else
    102         crypt_make_salt(salt_ptr, len, 0);
     122        safe_strncpy(salt_ptr, opt_S, sizeof(salt) - (sizeof("$N$")-1));
    103123
    104124    xmove_fd(fd, STDIN_FILENO);
Note: See TracChangeset for help on using the changeset viewer.