Changes in unix.c [8b6b740:5674207]
Legend:
- Unmodified
- Added
- Removed
-
unix.c
r8b6b740 r5674207 25 25 26 26 #include "bitlbee.h" 27 28 #include "arc.h"29 #include "base64.h"30 27 #include "commands.h" 28 #include "crypting.h" 31 29 #include "protocols/nogaim.h" 32 30 #include "help.h" 33 31 #include "ipc.h" 34 #include "md5.h"35 #include "misc.h"36 32 #include <signal.h> 37 33 #include <unistd.h> … … 44 40 static void sighandler( int signal ); 45 41 46 static int crypt_main( int argc, char *argv[] );47 48 42 int main( int argc, char *argv[] ) 49 43 { … … 52 46 struct sigaction sig, old; 53 47 54 if( argc > 1 && strcmp( argv[1], "-x" ) == 0 )55 return crypt_main( argc, argv );56 57 48 log_init(); 49 58 50 global.conf_file = g_strdup( CONF_FILE_DEF ); 59 51 global.conf = conf_load( argc, argv ); … … 62 54 63 55 b_main_init(); 64 nogaim_init();65 56 66 57 srand( time( NULL ) ^ getpid() ); 58 67 59 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 } 68 69 69 70 if( global.conf->runmode == RUNMODE_INETD ) … … 113 114 setuid( pw->pw_uid ); 114 115 } 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 );122 116 } 123 117 … … 139 133 if( !getuid() || !geteuid() ) 140 134 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 );143 135 144 136 b_main_run(); … … 166 158 167 159 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;226 160 } 227 161 … … 281 215 return( (double) time->tv_sec + (double) time->tv_usec / 1000000 ); 282 216 } 217 218
Note: See TracChangeset
for help on using the changeset viewer.