Ejemplo n.º 1
0
static void irc_cmd_pass( irc_t *irc, char **cmd )
{
	if( irc->status & USTATUS_LOGGED_IN )
	{
		char *send_cmd[] = { "identify", cmd[1], NULL };
		
		/* We're already logged in, this client seems to send the PASS
		   command last. (Possibly it won't send it at all if it turns
		   out we don't require it, which will break this feature.)
		   Try to identify using the given password. */
		root_command( irc, send_cmd );
		return;
	}
	/* Handling in pre-logged-in state, first see if this server is
	   password-protected: */
	else if( global.conf->auth_pass &&
	    ( strncmp( global.conf->auth_pass, "md5:", 4 ) == 0 ?
	        md5_verify_password( cmd[1], global.conf->auth_pass + 4 ) == 0 :
	        strcmp( cmd[1], global.conf->auth_pass ) == 0 ) )
	{
		irc->status |= USTATUS_AUTHORIZED;
		irc_check_login( irc );
	}
	else if( global.conf->auth_pass )
	{
		irc_send_num( irc, 464, ":Incorrect password" );
	}
	else
	{
		/* Remember the password and try to identify after USER/NICK. */
		irc_setpass( irc, cmd[1] );
		irc_check_login( irc );
	}
}
Ejemplo n.º 2
0
static int crypt_main( int argc, char *argv[] )
{
	int pass_len;
	unsigned char *pass_cr, *pass_cl;
	
	if( argc < 4 || ( strcmp( argv[2], "hash" ) != 0 &&
	                  strcmp( argv[2], "unhash" ) != 0 && argc < 5 ) )
	{
		printf( "Supported:\n"
		        "  %s -x enc <key> <cleartext password>\n"
		        "  %s -x dec <key> <encrypted password>\n"
		        "  %s -x hash <cleartext password>\n"
		        "  %s -x unhash <hashed password>\n"
		        "  %s -x chkhash <hashed password> <cleartext password>\n",
		        argv[0], argv[0], argv[0], argv[0], argv[0] );
	}
	else if( strcmp( argv[2], "enc" ) == 0 )
	{
		pass_len = arc_encode( argv[4], strlen( argv[4] ), (unsigned char**) &pass_cr, argv[3], 12 );
		printf( "%s\n", base64_encode( pass_cr, pass_len ) );
	}
	else if( strcmp( argv[2], "dec" ) == 0 )
	{
		pass_len = base64_decode( argv[4], (unsigned char**) &pass_cr );
		arc_decode( pass_cr, pass_len, (char**) &pass_cl, argv[3] );
		printf( "%s\n", pass_cl );
	}
	else if( strcmp( argv[2], "hash" ) == 0 )
	{
		md5_byte_t pass_md5[21];
		md5_state_t md5_state;
		
		random_bytes( pass_md5 + 16, 5 );
		md5_init( &md5_state );
		md5_append( &md5_state, (md5_byte_t*) argv[3], strlen( argv[3] ) );
		md5_append( &md5_state, pass_md5 + 16, 5 ); /* Add the salt. */
		md5_finish( &md5_state, pass_md5 );
		
		printf( "%s\n", base64_encode( pass_md5, 21 ) );
	}
	else if( strcmp( argv[2], "unhash" ) == 0 )
	{
		printf( "Hash %s submitted to a massive Beowulf cluster of\n"
		        "overclocked 486s. Expect your answer next year somewhere around this time. :-)\n", argv[3] );
	}
	else if( strcmp( argv[2], "chkhash" ) == 0 )
	{
		char *hash = strncmp( argv[3], "md5:", 4 ) == 0 ? argv[3] + 4 : argv[3];
		int st = md5_verify_password( argv[4], hash );
		
		printf( "Hash %s given password.\n", st == 0 ? "matches" : "does not match" );
		
		return st;
	}
	
	return 0;
}
Ejemplo n.º 3
0
static void irc_cmd_oper( irc_t *irc, char **cmd )
{
	/* Very non-standard evil but useful/secure hack, see below. */
	if( irc->status & OPER_HACK_ANY )
		return irc_cmd_oper_hack( irc, cmd );
	
	if( global.conf->oper_pass &&
	    ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ?
	        md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 :
	        strcmp( cmd[2], global.conf->oper_pass ) == 0 ) )
	{
		irc_umode_set( irc, "+o", 1 );
		irc_send_num( irc, 381, ":Password accepted" );
	}
	else
	{
		irc_send_num( irc, 491, ":Incorrect password" );
	}
}
Ejemplo n.º 4
0
static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_name, const gchar **attr_names, const gchar **attr_values, gpointer data, GError **error )
{
	struct xml_parsedata *xd = data;
	irc_t *irc = xd->irc;
	
	if( xd->unknown_tag > 0 )
	{
		xd->unknown_tag ++;
	}
	else if( g_strcasecmp( element_name, "user" ) == 0 )
	{
		char *nick = xml_attr( attr_names, attr_values, "nick" );
		char *pass = xml_attr( attr_names, attr_values, "password" );
		int st;
		
		if( !nick || !pass )
		{
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
		}
		else if( ( st = md5_verify_password( xd->given_pass, pass ) ) == -1 )
		{
			xd->pass_st = XML_PASS_WRONG;
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Error while decoding password attribute" );
		}
		else if( st == 0 )
		{
			if( xd->pass_st != XML_PASS_CHECK_ONLY )
				xd->pass_st = XML_PASS_OK;
		}
		else
		{
			xd->pass_st = XML_PASS_WRONG;
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Password mismatch" );
		}
	}
	else if( xd->pass_st < XML_PASS_OK )
	{
		/* Let's not parse anything else if we only have to check
		   the password. */
	}
	else if( g_strcasecmp( element_name, "account" ) == 0 )
	{
		char *protocol, *handle, *server, *password = NULL, *autoconnect, *tag;
		char *pass_b64 = NULL;
		unsigned char *pass_cr = NULL;
		int pass_len;
		struct prpl *prpl = NULL;
		
		handle = xml_attr( attr_names, attr_values, "handle" );
		pass_b64 = xml_attr( attr_names, attr_values, "password" );
		server = xml_attr( attr_names, attr_values, "server" );
		autoconnect = xml_attr( attr_names, attr_values, "autoconnect" );
		tag = xml_attr( attr_names, attr_values, "tag" );
		
		protocol = xml_attr( attr_names, attr_values, "protocol" );
		if( protocol )
			prpl = find_protocol( protocol );
		
		if( !handle || !pass_b64 || !protocol )
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
		else if( !prpl )
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Unknown protocol: %s", protocol );
		else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_cr ) ) &&
		         arc_decode( pass_cr, pass_len, &password, xd->given_pass ) >= 0 )
		{
			xd->current_account = account_add( irc->b, prpl, handle, password );
			if( server )
				set_setstr( &xd->current_account->set, "server", server );
			if( autoconnect )
				set_setstr( &xd->current_account->set, "auto_connect", autoconnect );
			if( tag )
				set_setstr( &xd->current_account->set, "tag", tag );
		}
		else
		{
			/* Actually the _decode functions don't even return error codes,
			   but maybe they will later... */
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Error while decrypting account password" );
		}
		
		g_free( pass_cr );
		g_free( password );
	}
	else if( g_strcasecmp( element_name, "setting" ) == 0 )
	{
		char *setting;
		
		if( xd->current_setting )
		{
			g_free( xd->current_setting );
			xd->current_setting = NULL;
		}
		
		if( ( setting = xml_attr( attr_names, attr_values, "name" ) ) )
		{
			if( xd->current_channel != NULL )
				xd->current_set_head = &xd->current_channel->set;
			else if( xd->current_account != NULL )
				xd->current_set_head = &xd->current_account->set;
			else
				xd->current_set_head = &xd->irc->b->set;
			
			xd->current_setting = g_strdup( setting );
		}
		else
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
	}
	else if( g_strcasecmp( element_name, "buddy" ) == 0 )
	{
		char *handle, *nick;
		
		handle = xml_attr( attr_names, attr_values, "handle" );
		nick = xml_attr( attr_names, attr_values, "nick" );
		
		if( xd->current_account && handle && nick )
		{
			nick_set_raw( xd->current_account, handle, nick );
		}
		else
		{
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
		}
	}
	else if( g_strcasecmp( element_name, "channel" ) == 0 )
	{
		char *name, *type;
		
		name = xml_attr( attr_names, attr_values, "name" );
		type = xml_attr( attr_names, attr_values, "type" );
		
		if( !name || !type )
		{
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
			return;
		}
		
		/* The channel may exist already, for example if it's &bitlbee.
		   Also, it's possible that the user just reconnected and the
		   IRC client already rejoined all channels it was in. They
		   should still get the right settings. */
		if( ( xd->current_channel = irc_channel_by_name( irc, name ) ) ||
		    ( xd->current_channel = irc_channel_new( irc, name ) ) )
			set_setstr(&xd->current_channel->set, "type", type );
	}
	/* Backward compatibility: Keep this around for a while for people
	   switching from BitlBee 1.2.4+. */
	else if( g_strcasecmp( element_name, "chat" ) == 0 )
	{
		char *handle, *channel;
		
		handle = xml_attr( attr_names, attr_values, "handle" );
		channel = xml_attr( attr_names, attr_values, "channel" );
		
		if( xd->current_account && handle && channel )
		{
			irc_channel_t *ic;
			
			if( ( ic = irc_channel_new( irc, channel ) ) &&
			    set_setstr( &ic->set, "type", "chat" ) &&
			    set_setstr( &ic->set, "chat_type", "room" ) &&
			    set_setstr( &ic->set, "account", xd->current_account->tag ) &&
			    set_setstr( &ic->set, "room", handle ) )
			{
				/* Try to pick up some settings where possible. */
				xd->current_channel = ic;
			}
			else if( ic )
				irc_channel_free( ic );
		}
		else
		{
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
		}
	}
	else
	{
		xd->unknown_tag ++;
		irc_rootmsg( irc, "Warning: Unknown XML tag found in configuration file (%s). "
		                  "This may happen when downgrading BitlBee versions. "
		                  "This tag will be skipped and the information will be lost "
		                  "once you save your settings.", element_name );
		/*
		g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
		             "Unkown element: %s", element_name );
		*/
	}
}
Ejemplo n.º 5
0
static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const char *password, xml_pass_st action )
{
	struct xml_parsedata xd[1];
	char *fn, buf[2048];
	int fd, st;
	struct xt_parser *xp = NULL;
	struct xt_node *node;
	storage_status_t ret = STORAGE_OTHER_ERROR;
	
	xd->irc = irc;
	strncpy( xd->given_nick, my_nick, MAX_NICK_LENGTH );
	xd->given_nick[MAX_NICK_LENGTH] = '\0';
	nick_lc( NULL, xd->given_nick );
	xd->given_pass = (char*) password;
	
	fn = g_strconcat( global.conf->configdir, xd->given_nick, ".xml", NULL );
	if( ( fd = open( fn, O_RDONLY ) ) < 0 )
	{
		ret = STORAGE_NO_SUCH_USER;
		goto error;
	}
	
	xp = xt_new( handlers, xd );
	while( ( st = read( fd, buf, sizeof( buf ) ) ) > 0 )
	{
		st = xt_feed( xp, buf, st );
		if( st != 1 )
			break;
	}
	close( fd );
	if( st != 0 )
		goto error;
	
	node = xp->root;
	if( node == NULL || node->next != NULL || strcmp( node->name, "user" ) != 0 )
		goto error;
	
	{
		char *nick = xt_find_attr( node, "nick" );
		char *pass = xt_find_attr( node, "password" );
		
		if( !nick || !pass )
		{
			goto error;
		}
		else if( ( st = md5_verify_password( xd->given_pass, pass ) ) != 0 )
		{
			ret = STORAGE_INVALID_PASSWORD;
			goto error;
		}
	}
	
	if( action == XML_PASS_CHECK_ONLY )
	{
		ret = STORAGE_OK;
		goto error;
	}
	
	/* DO NOT call xt_handle() before verifying the password! */
	if( xt_handle( xp, NULL, 1 ) == XT_HANDLED )
		ret = STORAGE_OK;
	
	handle_settings( node, &xd->irc->b->set );
	
error:
	xt_free( xp );
	g_free( fn );
	return ret;
}
Ejemplo n.º 6
0
static storage_status_t xml_load_real(irc_t *irc, const char *my_nick, const char *password, xml_action action)
{
	struct xml_parsedata xd[1];
	char *fn, buf[2048];
	int fd, st;
	struct xt_parser *xp = NULL;
	struct xt_node *node;
	storage_status_t ret = STORAGE_OTHER_ERROR;

	xd->irc = irc;
	strncpy(xd->given_nick, my_nick, MAX_NICK_LENGTH);
	xd->given_nick[MAX_NICK_LENGTH] = '\0';
	nick_lc(NULL, xd->given_nick);
	xd->given_pass = (char *) password;

	fn = g_strconcat(global.conf->configdir, xd->given_nick, ".xml", NULL);
	if ((fd = open(fn, O_RDONLY)) < 0) {
		if (errno == ENOENT) {
			ret = STORAGE_NO_SUCH_USER;
		} else {
			irc_rootmsg(irc, "Error loading user config: %s", g_strerror(errno));
		}
		goto error;
	}

	xp = xt_new(handlers, xd);
	while ((st = read(fd, buf, sizeof(buf))) > 0) {
		st = xt_feed(xp, buf, st);
		if (st != 1) {
			break;
		}
	}
	close(fd);
	if (st != 0) {
		goto error;
	}

	node = xp->root;
	if (node == NULL || node->next != NULL || strcmp(node->name, "user") != 0) {
		goto error;
	}

	if (action == XML_PASS_CHECK) {
		char *nick = xt_find_attr(node, "nick");
		char *pass = xt_find_attr(node, "password");
		char *backend = xt_find_attr(node, "auth_backend");

		if (!nick || !(pass || backend)) {
			goto error;
		}

		if (backend) {
			g_free(xd->irc->auth_backend);
			xd->irc->auth_backend = g_strdup(backend);
			ret = STORAGE_CHECK_BACKEND;
		} else if ((st = md5_verify_password(xd->given_pass, pass)) != 0) {
			ret = STORAGE_INVALID_PASSWORD;
		} else {
			ret = STORAGE_OK;
		}
		goto error;
	}

	if (xt_handle(xp, NULL, 1) == XT_HANDLED) {
		ret = STORAGE_OK;
	}

	handle_settings(node, &xd->irc->b->set);

error:
	xt_free(xp);
	g_free(fn);
	return ret;
}