Changeset 7c9db24


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.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    rb52e478 r7c9db24  
    4949
    5050clean: $(subdirs)
    51         rm -f *.o $(OUTFILE) core utils/bitlbeed encode decode
     51        rm -f *.o $(OUTFILE) core utils/bitlbeed
    5252        $(MAKE) -C tests clean
    5353
     
    124124endif
    125125
    126 encode: crypting.c
    127         $(CC) crypting.c lib/md5.c $(CFLAGS) -o encode -DCRYPTING_MAIN $(CFLAGS) $(EFLAGS) $(LFLAGS)
    128 
    129 decode: encode
    130         cp encode decode
    131 
    132126ctags:
    133127        ctags `find . -name "*.c"` `find . -name "*.h"`
  • conf.c

    rb52e478 r7c9db24  
    127127                {
    128128                        printf( "Usage: bitlbee [-D/-F [-i <interface>] [-p <port>] [-n] [-v]] [-I]\n"
    129                                 "               [-c <file>] [-d <dir>] [-h]\n"
     129                                "               [-c <file>] [-d <dir>] [-x] [-h]\n"
    130130                                "\n"
    131131                                "An IRC-to-other-chat-networks gateway\n"
     
    143143                                "  -c  Load alternative configuration file\n"
    144144                                "  -d  Specify alternative user configuration directory\n"
     145                                "  -x  Command-line interface to password encryption/hashing\n"
    145146                                "  -h  Show this help page.\n" );
    146147                        return NULL;
  • crypting.c

    rb52e478 r7c9db24  
    132132        return (rv);
    133133}
    134 
    135 #ifdef CRYPTING_MAIN
    136 
    137 /* A little main() function for people who want a stand-alone program to
    138    encode/decode BitlCrypted files. */
    139 
    140 int main( int argc, char *argv[] )
    141 {
    142         char *hash, *action, line[256];
    143         char* (*func)( char *, const char * );
    144        
    145         if( argc < 2 )
    146         {
    147                 fprintf( stderr, "Usage: %s <password>\n\n"
    148                                  "Reads from stdin, writes to stdout.\n"
    149                                  "Call as \"encode\" to encode, \"decode\" to decode.\n", argv[0] );
    150                 return( 1 );
    151         }
    152        
    153         hash = hashpass( argv[1] );
    154         action = argv[0] + strlen( argv[0] ) - strlen( "encode" );
    155        
    156         if( strcmp( action, "encode" ) == 0 )
    157         {
    158                 fwrite( hash, 32, 1, stdout );
    159                 func = obfucrypt;
    160         }
    161         else if( strcmp( action, "decode" ) == 0 )
    162         {
    163                 char hash2[32];
    164                
    165                 fread( hash2, 32, 1, stdin );
    166                 if( memcmp( hash, hash2, 32 ) != 0 )
    167                 {
    168                         fprintf( stderr, "Passwords don't match. Can't decode.\n" );
    169                         return( 1 );
    170                 }
    171                 func = deobfucrypt;
    172         }
    173         else
    174         {
    175                 return( main( 0, NULL ) );
    176         }
    177        
    178         while( fscanf( stdin, "%[^\n]255s", line ) > 0 )
    179         {
    180                 char *out;
    181                
    182                 /* Flush the newline */
    183                 fgetc( stdin );
    184                
    185                 out = func( line, argv[1] );
    186                 printf( "%s\n", out );
    187                 g_free( out );
    188         }
    189        
    190         return( 0 );
    191 }
    192 
    193 #endif
  • 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.