- Timestamp:
- 2010-03-17T13:56:52Z (14 years ago)
- Branches:
- master
- Children:
- b788246
- Parents:
- e5e795d (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
unix.c
re5e795d r75554d0 25 25 26 26 #include "bitlbee.h" 27 28 #include "arc.h" 29 #include "base64.h" 27 30 #include "commands.h" 28 #include "crypting.h"29 31 #include "protocols/nogaim.h" 30 32 #include "help.h" 31 33 #include "ipc.h" 34 #include "md5.h" 35 #include "misc.h" 32 36 #include <signal.h> 33 37 #include <unistd.h> … … 40 44 static void sighandler( int signal ); 41 45 46 static int crypt_main( int argc, char *argv[] ); 47 42 48 int main( int argc, char *argv[] ) 43 49 { … … 45 51 char *old_cwd = NULL; 46 52 struct sigaction sig, old; 53 54 if( argc > 1 && strcmp( argv[1], "-x" ) == 0 ) 55 return crypt_main( argc, argv ); 47 56 48 57 log_init(); … … 159 168 } 160 169 170 static int crypt_main( int argc, char *argv[] ) 171 { 172 int pass_len; 173 unsigned char *pass_cr, *pass_cl; 174 175 if( argc < 4 || ( strcmp( argv[2], "hash" ) != 0 && 176 strcmp( argv[2], "unhash" ) != 0 && argc < 5 ) ) 177 { 178 printf( "Supported:\n" 179 " %s -x enc <key> <cleartext password>\n" 180 " %s -x dec <key> <encrypted password>\n" 181 " %s -x hash <cleartext password>\n" 182 " %s -x unhash <hashed password>\n" 183 " %s -x chkhash <hashed password> <cleartext password>\n", 184 argv[0], argv[0], argv[0], argv[0], argv[0] ); 185 } 186 else if( strcmp( argv[2], "enc" ) == 0 ) 187 { 188 pass_len = arc_encode( argv[4], strlen( argv[4] ), (unsigned char**) &pass_cr, argv[3], 12 ); 189 printf( "%s\n", base64_encode( pass_cr, pass_len ) ); 190 } 191 else if( strcmp( argv[2], "dec" ) == 0 ) 192 { 193 pass_len = base64_decode( argv[4], (unsigned char**) &pass_cr ); 194 arc_decode( pass_cr, pass_len, (char**) &pass_cl, argv[3] ); 195 printf( "%s\n", pass_cl ); 196 } 197 else if( strcmp( argv[2], "hash" ) == 0 ) 198 { 199 md5_byte_t pass_md5[21]; 200 md5_state_t md5_state; 201 202 random_bytes( pass_md5 + 16, 5 ); 203 md5_init( &md5_state ); 204 md5_append( &md5_state, (md5_byte_t*) argv[3], strlen( argv[3] ) ); 205 md5_append( &md5_state, pass_md5 + 16, 5 ); /* Add the salt. */ 206 md5_finish( &md5_state, pass_md5 ); 207 208 printf( "%s\n", base64_encode( pass_md5, 21 ) ); 209 } 210 else if( strcmp( argv[2], "unhash" ) == 0 ) 211 { 212 printf( "Hash %s submitted to a massive Beowulf cluster of\n" 213 "overclocked 486s. Expect your answer next year somewhere around this time. :-)\n", argv[3] ); 214 } 215 else if( strcmp( argv[2], "chkhash" ) == 0 ) 216 { 217 char *hash = strncmp( argv[3], "md5:", 4 ) == 0 ? argv[3] + 4 : argv[3]; 218 int st = md5_verify_password( argv[4], hash ); 219 220 printf( "Hash %s given password.\n", st == 0 ? "matches" : "does not match" ); 221 222 return st; 223 } 224 225 return 0; 226 } 227 161 228 static void sighandler( int signal ) 162 229 { … … 214 281 return( (double) time->tv_sec + (double) time->tv_usec / 1000000 ); 215 282 } 216 217
Note: See TracChangeset
for help on using the changeset viewer.