Changeset 5f8ab6a9 for unix.c


Ignore:
Timestamp:
2010-06-03T10:41:03Z (14 years ago)
Author:
Sven Moritz Hallberg <pesco@…>
Branches:
master
Children:
814aa52
Parents:
3f81999 (diff), f9928cb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge in bitlbee 1.2.5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • unix.c

    r3f81999 r5f8ab6a9  
    2525
    2626#include "bitlbee.h"
     27
     28#include "arc.h"
     29#include "base64.h"
    2730#include "commands.h"
    2831#include "crypting.h"
     
    3235#include "ipc.h"
    3336#include "lib/ssl_client.h"
     37#include "md5.h"
     38#include "misc.h"
    3439#include <signal.h>
    3540#include <unistd.h>
     
    4247static void sighandler( int signal );
    4348
     49static int crypt_main( int argc, char *argv[] );
     50
    4451int main( int argc, char *argv[] )
    4552{
     
    4754        char *old_cwd = NULL;
    4855        struct sigaction sig, old;
     56       
     57        if( argc > 1 && strcmp( argv[1], "-x" ) == 0 )
     58                return crypt_main( argc, argv );
    4959       
    5060        log_init();
     
    168178}
    169179
     180static int crypt_main( int argc, char *argv[] )
     181{
     182        int pass_len;
     183        unsigned char *pass_cr, *pass_cl;
     184       
     185        if( argc < 4 || ( strcmp( argv[2], "hash" ) != 0 &&
     186                          strcmp( argv[2], "unhash" ) != 0 && argc < 5 ) )
     187        {
     188                printf( "Supported:\n"
     189                        "  %s -x enc <key> <cleartext password>\n"
     190                        "  %s -x dec <key> <encrypted password>\n"
     191                        "  %s -x hash <cleartext password>\n"
     192                        "  %s -x unhash <hashed password>\n"
     193                        "  %s -x chkhash <hashed password> <cleartext password>\n",
     194                        argv[0], argv[0], argv[0], argv[0], argv[0] );
     195        }
     196        else if( strcmp( argv[2], "enc" ) == 0 )
     197        {
     198                pass_len = arc_encode( argv[4], strlen( argv[4] ), (unsigned char**) &pass_cr, argv[3], 12 );
     199                printf( "%s\n", base64_encode( pass_cr, pass_len ) );
     200        }
     201        else if( strcmp( argv[2], "dec" ) == 0 )
     202        {
     203                pass_len = base64_decode( argv[4], (unsigned char**) &pass_cr );
     204                arc_decode( pass_cr, pass_len, (char**) &pass_cl, argv[3] );
     205                printf( "%s\n", pass_cl );
     206        }
     207        else if( strcmp( argv[2], "hash" ) == 0 )
     208        {
     209                md5_byte_t pass_md5[21];
     210                md5_state_t md5_state;
     211               
     212                random_bytes( pass_md5 + 16, 5 );
     213                md5_init( &md5_state );
     214                md5_append( &md5_state, (md5_byte_t*) argv[3], strlen( argv[3] ) );
     215                md5_append( &md5_state, pass_md5 + 16, 5 ); /* Add the salt. */
     216                md5_finish( &md5_state, pass_md5 );
     217               
     218                printf( "%s\n", base64_encode( pass_md5, 21 ) );
     219        }
     220        else if( strcmp( argv[2], "unhash" ) == 0 )
     221        {
     222                printf( "Hash %s submitted to a massive Beowulf cluster of\n"
     223                        "overclocked 486s. Expect your answer next year somewhere around this time. :-)\n", argv[3] );
     224        }
     225        else if( strcmp( argv[2], "chkhash" ) == 0 )
     226        {
     227                char *hash = strncmp( argv[3], "md5:", 4 ) == 0 ? argv[3] + 4 : argv[3];
     228                int st = md5_verify_password( argv[4], hash );
     229               
     230                printf( "Hash %s given password.\n", st == 0 ? "matches" : "does not match" );
     231               
     232                return st;
     233        }
     234       
     235        return 0;
     236}
     237
    170238static void sighandler( int signal )
    171239{
Note: See TracChangeset for help on using the changeset viewer.