Example #1
0
storage_status_t storage_save (irc_t *irc, char *password, int overwrite)
{
	storage_status_t st;
	GSList *l;
	
	if (password != NULL) {
		/* Should only use this in the "register" command. */
		if (irc->password || overwrite)
			return STORAGE_OTHER_ERROR;
		
		irc_setpass(irc, password);
	} else if ((irc->status & USTATUS_IDENTIFIED) == 0) {
		return STORAGE_NO_SUCH_USER;
	}
	
	st = ((storage_t *)global.storage->data)->save(irc, overwrite);
	
	for( l = irc_plugins; l; l = l->next )
	{
		irc_plugin_t *p = l->data;
		if( p->storage_save )
			p->storage_save( irc );
	}
	
	if (password != NULL) {
		irc_setpass(irc, NULL);
	}
	
	return st;
}
Example #2
0
static void cmd_drop(irc_t *irc, char **cmd)
{
	storage_status_t status;

	status = auth_check_pass(irc, irc->user->nick, cmd[1]);
	if (status == STORAGE_OK) {
		status = storage_remove(irc->user->nick);
	}

	switch (status) {
	case STORAGE_NO_SUCH_USER:
		irc_rootmsg(irc, "That account does not exist");
		break;
	case STORAGE_INVALID_PASSWORD:
		irc_rootmsg(irc, "Password invalid");
		break;
	case STORAGE_OK:
		irc_setpass(irc, NULL);
		irc->status &= ~USTATUS_IDENTIFIED;
		irc_umode_set(irc, "-R", 1);
		irc_rootmsg(irc, "Account `%s' removed", irc->user->nick);
		break;
	default:
		irc_rootmsg(irc, "Error: `%d'", status);
		break;
	}
}
Example #3
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 );
	}
}
Example #4
0
File: irc.c Project: dgruss/bitlbee
static char *set_eval_password(set_t *set, char *value)
{
	irc_t *irc = set->data;

	if (irc->status & USTATUS_IDENTIFIED && value) {
		irc_setpass(irc, value);
		return NULL;
	} else {
		return SET_INVALID;
	}
}
Example #5
0
static void ipc_child_cmd_takeover_yes( void *data )
{
	irc_t *irc = data, *old = NULL;
	char *to_auth[] = { "TAKEOVER", "AUTH", irc->user->nick, irc->password, NULL };
	
	/* Master->New connection */
	ipc_to_master_str( "TAKEOVER AUTH %s :%s\r\n",
	                   irc->user->nick, irc->password );
	
	if( global.conf->runmode == RUNMODE_DAEMON )
	{
		GSList *l;
		
		for( l = irc_connection_list; l; l = l->next )
		{
			old = l->data;
			
			if( irc != old &&
			    irc->user->nick && old->user->nick &&
			    irc->password && old->password &&
			    strcmp( irc->user->nick, old->user->nick ) == 0 &&
			    strcmp( irc->password, old->password ) == 0 )
				break;
		}
		if( l == NULL )
		{
			to_auth[1] = "FAIL";
			ipc_child_cmd_takeover( irc, to_auth );
			return;
		}
	}
	
	/* Drop credentials, we'll shut down soon and shouldn't overwrite
	   any settings. */
	irc_rootmsg( irc, "Trying to take over existing session" );
	
	irc_desync( irc );
	
	if( old )
	{
		ipc_child_recv_fd = dup( irc->fd );
		ipc_child_cmd_takeover( old, to_auth );
	}
	
	/* TODO: irc_setpass() should do all of this. */
	irc_setpass( irc, NULL );
	irc->status &= ~USTATUS_IDENTIFIED;
	irc_umode_set( irc, "-R", 1 );
	
	if( old )
		irc_abort( irc, FALSE, NULL );
}
Example #6
0
static void cmd_register(irc_t *irc, char **cmd)
{
	char s[16];

	if (global.conf->authmode == AUTHMODE_REGISTERED) {
		irc_rootmsg(irc, "This server does not allow registering new accounts");
		return;
	}

	if (cmd[1] == NULL) {
		irc_rootmsg(irc, "About to register, use /OPER to enter the password");
		irc->status |= OPER_HACK_REGISTER;
		return;
	}

	switch (storage_save(irc, cmd[1], FALSE)) {
	case STORAGE_ALREADY_EXISTS:
		irc_rootmsg(irc, "Nick is already registered");
		break;

	case STORAGE_OK:
		irc_rootmsg(irc, "Account successfully created");
		irc_setpass(irc, cmd[1]);
		irc->status |= USTATUS_IDENTIFIED;
		irc_umode_set(irc, "+R", 1);

		if (irc->caps & CAP_SASL) {
			irc_user_t *iu = irc->user;
			irc_send_num(irc, 900, "%s!%s@%s %s :You are now logged in as %s",
				iu->nick, iu->user, iu->host, iu->nick, iu->nick);
		}

		/* Set this var now, or anyone who logs in to his/her
		   newly created account for the first time gets the
		   whatsnew story. */
		g_snprintf(s, sizeof(s), "%d", BITLBEE_VERSION_CODE);
		set_setstr(&irc->b->set, "last_version", s);
		break;

	default:
		irc_rootmsg(irc, "Error registering");
		break;
	}
}
Example #7
0
static void irc_cmd_nick( irc_t *irc, char **cmd )
{
	irc_user_t *iu;
	
	if( ( iu = irc_user_by_name( irc, cmd[1] ) ) && iu != irc->user )
	{
		irc_send_num( irc, 433, "%s :This nick is already in use", cmd[1] );
	}
	else if( !nick_ok( cmd[1] ) )
	{
		/* [SH] Invalid characters. */
		irc_send_num( irc, 432, "%s :This nick contains invalid characters", cmd[1] );
	}
	else if( irc->status & USTATUS_LOGGED_IN )
	{
		/* WATCH OUT: iu from the first if reused here to check if the
		   new nickname is the same (other than case, possibly). If it
		   is, no need to reset identify-status. */
		if( ( irc->status & USTATUS_IDENTIFIED ) && iu != irc->user )
		{
			irc_setpass( irc, NULL );
			irc->status &= ~USTATUS_IDENTIFIED;
			irc_umode_set( irc, "-R", 1 );
			irc_rootmsg( irc, "Changing nicks resets your identify status. "
			             "Re-identify or register a new account if you want "
			             "your configuration to be saved. See \x02help "
			             "nick_changes\x02." );
		}
		
		if( strcmp( cmd[1], irc->user->nick ) != 0 )
			irc_user_set_nick( irc->user, cmd[1] );
	}
	else
	{
		g_free( irc->user->nick );
		irc->user->nick = g_strdup( cmd[1] );
		
		irc_check_login( irc );
	}
}
Example #8
0
static void irc_cmd_nick( irc_t *irc, char **cmd )
{
	irc_user_t *iu;
	
	if( ( iu = irc_user_by_name( irc, cmd[1] ) ) && iu != irc->user )
	{
		irc_send_num( irc, 433, "%s :This nick is already in use", cmd[1] );
	}
	else if( !nick_ok( cmd[1] ) )
	{
		/* [SH] Invalid characters. */
		irc_send_num( irc, 432, "%s :This nick contains invalid characters", cmd[1] );
	}
	else if( irc->status & USTATUS_LOGGED_IN )
	{
		if( irc->status & USTATUS_IDENTIFIED )
		{
			irc_setpass( irc, NULL );
			irc->status &= ~USTATUS_IDENTIFIED;
			irc_umode_set( irc, "-R", 1 );
			irc_usermsg( irc, "Changing nicks resets your identify status. "
			             "Re-identify or register a new account if you want "
			             "your configuration to be saved. See \x02help "
			             "nick_changes\x02." );
		}
		
		irc_user_set_nick( irc->user, cmd[1] );
	}
	else
	{
		g_free( irc->user->nick );
		irc->user->nick = g_strdup( cmd[1] );
		
		irc_check_login( irc );
	}
}