Changes in unix.c [5674207:8b6b740]
Legend:
- Unmodified
- Added
- Removed
-
unix.c
r5674207 r8b6b740 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 { … … 46 52 struct sigaction sig, old; 47 53 54 if( argc > 1 && strcmp( argv[1], "-x" ) == 0 ) 55 return crypt_main( argc, argv ); 56 48 57 log_init(); 49 50 58 global.conf_file = g_strdup( CONF_FILE_DEF ); 51 59 global.conf = conf_load( argc, argv ); … … 54 62 55 63 b_main_init(); 64 nogaim_init(); 56 65 57 66 srand( time( NULL ) ^ getpid() ); 58 59 67 global.helpfile = g_strdup( HELP_FILE ); 60 if( help_init( &global.help, global.helpfile ) == NULL )61 log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE );62 63 global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage );64 if( global.storage == NULL )65 {66 log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage );67 return( 1 );68 }69 68 70 69 if( global.conf->runmode == RUNMODE_INETD ) … … 114 113 setuid( pw->pw_uid ); 115 114 } 115 } 116 117 global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage ); 118 if( global.storage == NULL ) 119 { 120 log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage ); 121 return( 1 ); 116 122 } 117 123 … … 133 139 if( !getuid() || !geteuid() ) 134 140 log_message( LOGLVL_WARNING, "BitlBee is running with root privileges. Why?" ); 141 if( help_init( &global.help, global.helpfile ) == NULL ) 142 log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE ); 135 143 136 144 b_main_run(); … … 158 166 159 167 return( 0 ); 168 } 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; 160 226 } 161 227 … … 215 281 return( (double) time->tv_sec + (double) time->tv_usec / 1000000 ); 216 282 } 217 218
Note: See TracChangeset
for help on using the changeset viewer.