Changeset 7c9db24 for unix.c


Ignore:
Timestamp:
2010-03-08T02:10:41Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
3e1ef92c
Parents:
b52e478
Message:

Replaced obsolete (useless for the current .xml files) encode/decode tools
with a few command-line options to the BitlBee binary. Type "bitlbee -x"
for more info.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • unix.c

    rb52e478 r7c9db24  
    2525
    2626#include "bitlbee.h"
     27
     28#include "arc.h"
     29#include "base64.h"
    2730#include "commands.h"
    28 #include "crypting.h"
    2931#include "protocols/nogaim.h"
    3032#include "help.h"
    3133#include "ipc.h"
     34#include "md5.h"
     35#include "misc.h"
    3236#include <signal.h>
    3337#include <unistd.h>
     
    4044static void sighandler( int signal );
    4145
     46static int crypt_main( int argc, char *argv[] );
     47
    4248int main( int argc, char *argv[] )
    4349{
     
    4551        char *old_cwd = NULL;
    4652        struct sigaction sig, old;
     53       
     54        if( argc > 1 && strcmp( argv[1], "-x" ) == 0 )
     55                return crypt_main( argc, argv );
    4756       
    4857        log_init();
     
    159168}
    160169
     170static int crypt_main( int argc, char *argv[] )
     171{
     172        int pass_len;
     173        unsigned char *pass_cr, *pass_cl;
     174       
     175        if( argc < 3 )
     176        {
     177                printf( "Supported:\n"
     178                        "  %s -x enc <key> <cleartext password>\n"
     179                        "  %s -x dec <key> <encrypted password>\n"
     180                        "  %s -x hash <cleartext password>\n"
     181                        "  %s -x unhash <hashed password>\n"
     182                        "  %s -x chkhash <hashed password> <cleartext password>\n",
     183                        argv[0], argv[0], argv[0], argv[0], argv[0] );
     184        }
     185        else if( strcmp( argv[2], "enc" ) == 0 )
     186        {
     187                pass_len = arc_encode( argv[4], strlen( argv[4] ), (unsigned char**) &pass_cr, argv[3], 12 );
     188                printf( "%s\n", base64_encode( pass_cr, pass_len ) );
     189        }
     190        else if( strcmp( argv[2], "dec" ) == 0 )
     191        {
     192                pass_len = base64_decode( argv[4], (unsigned char**) &pass_cr );
     193                arc_decode( pass_cr, pass_len, (char**) &pass_cl, argv[3] );
     194                printf( "%s\n", pass_cl );
     195        }
     196        else if( strcmp( argv[2], "hash" ) == 0 )
     197        {
     198                md5_byte_t pass_md5[21];
     199                md5_state_t md5_state;
     200               
     201                random_bytes( pass_md5 + 16, 5 );
     202                md5_init( &md5_state );
     203                md5_append( &md5_state, (md5_byte_t*) argv[3], strlen( argv[3] ) );
     204                md5_append( &md5_state, pass_md5 + 16, 5 ); /* Add the salt. */
     205                md5_finish( &md5_state, pass_md5 );
     206               
     207                printf( "%s\n", base64_encode( pass_md5, 21 ) );
     208        }
     209        else if( strcmp( argv[2], "unhash" ) == 0 )
     210        {
     211                printf( "Hash %s submitted to a massive Beowulf cluster of\n"
     212                        "overclocked 486s. Expect your answer next year somewhere around this time. :-)\n", argv[3] );
     213        }
     214        else if( strcmp( argv[2], "chkhash" ) == 0 )
     215        {
     216                int st = md5_verify_password( argv[4], argv[3] );
     217               
     218                printf( "Hash %s given password.\n", st == 0 ? "matches" : "does not match" );
     219               
     220                return st;
     221        }
     222       
     223        return 0;
     224}
     225
    161226static void sighandler( int signal )
    162227{
     
    214279        return( (double) time->tv_sec + (double) time->tv_usec / 1000000 );
    215280}
    216 
    217 
Note: See TracChangeset for help on using the changeset viewer.