Beispiel #1
0
static t_account * account_load_new(char const * name, unsigned uid)
{
    t_account *account;
    t_attrgroup *attrgroup;

    if (name && account_check_name(name)) return NULL;

    force_account_add = 1; /* disable the protection */

    attrgroup = attrgroup_create_nameuid(name, uid);
    if (!attrgroup) {
	force_account_add = 0;
	return NULL;
    }

    if (!(account = account_load(attrgroup))) {
        eventlog(eventlog_level_error, __FUNCTION__,"could not load account");
        attrgroup_destroy(attrgroup);
	force_account_add = 0;
        return NULL;
    }

    if (!accountlist_add_account(account)) {
        eventlog(eventlog_level_error, __FUNCTION__,"could not add account to list");
        account_destroy(account);
	force_account_add = 0;
        return NULL;
    }

    force_account_add = 0;

    return account;
}
static int _handle_privmsg_command(t_connection * conn, int numparams, char ** params, char * text)
{
    if ((numparams>=1)&&(text))
    {
        int i;
        char ** e;

        e = irc_get_listelems(params[0]);
        /* FIXME: support wildcards! */

        /* start amadeo: code was sent by some unkown fellow of pvpgn (maybe u wanna give us your name
           for any credits), it adds nick-registration, i changed some things here and there... */
        for (i=0; ((e)&&(e[i])); i++) {
            if (strcasecmp(e[i],"NICKSERV")==0) {
                char * pass;
                char * p;

                pass = std::strchr(text,' ');
                if (pass)
                    *pass++ = '\0';

                if (strcasecmp(text,"identify")==0) {
                    switch (conn_get_state(conn)) {
                    case conn_state_bot_password:
                    {
                        if (pass) {
                            t_hash h;

                            for (p = pass; *p; p++)
                                if (std::isupper((int)*p)) *p = std::tolower(*p);
                            bnet_hash(&h,std::strlen(pass),pass);
                            irc_authenticate(conn,hash_get_str(h));
                        }
                        else {
                            message_send_text(conn,message_type_notice,NULL,"Syntax: IDENTIFY <password> (max 16 characters)");
                        }
                        break;
                    }
                    case conn_state_loggedin:
                    {
                        message_send_text(conn,message_type_notice,NULL,"You don't need to IDENTIFY");
                        break;
                    }
                    default:
                        ;
                        eventlog(eventlog_level_trace,__FUNCTION__,"got /msg in unexpected connection state (%s)",conn_state_get_str(conn_get_state(conn)));
                    }
                }
                else if (strcasecmp(text,"register")==0) {
                    unsigned int j;
                    t_hash       passhash;
                    t_account  * temp;
                    char         msgtemp[MAX_IRC_MESSAGE_LEN];
                    char       * username=(char *)conn_get_loggeduser(conn);

                    if (account_check_name(username)<0) {
                        message_send_text(conn,message_type_error,conn,"Account name contains invalid symbol!");
                        break;
                    }

                    if(!prefs_get_allow_new_accounts()) {
                        message_send_text(conn,message_type_error,conn,"Account creation is not allowed");
                        break;
                    }

                    if (!pass || pass[0]=='\0' || (std::strlen(pass)>16) ) {
                        message_send_text(conn,message_type_error,conn,"Syntax: REGISTER <password> (max 16 characters)");
                        break;
                    }

                    for (j=0; j<std::strlen(pass); j++)
                        if (std::isupper((int)pass[j])) pass[j] = std::tolower((int)pass[j]);

                    bnet_hash(&passhash,std::strlen(pass),pass);

                    snprintf(msgtemp, sizeof(msgtemp), "Trying to create account \"%s\" with password \"%s\"",username,pass);
                    message_send_text(conn,message_type_info,conn,msgtemp);

                    temp = accountlist_create_account(username,hash_get_str(passhash));
                    if (!temp) {
                        message_send_text(conn,message_type_error,conn,"Failed to create account!");
                        eventlog(eventlog_level_debug,__FUNCTION__,"[%d] account \"%s\" not created (failed)",conn_get_socket(conn),username);
                        conn_unget_chatname(conn,username);
                        break;
                    }

                    snprintf(msgtemp, sizeof(msgtemp), "Account "UID_FORMAT" created.",account_get_uid(temp));
                    message_send_text(conn,message_type_info,conn,msgtemp);
                    eventlog(eventlog_level_debug,__FUNCTION__,"[%d] account \"%s\" created",conn_get_socket(conn),username);
                    conn_unget_chatname(conn,username);
                }
                else {
                    char tmp[MAX_IRC_MESSAGE_LEN+1];
                    message_send_text(conn,message_type_notice,NULL,"Invalid arguments for NICKSERV");
                    snprintf(tmp, sizeof(tmp), ":Unrecognized command \"%s\"", text);
                    message_send_text(conn,message_type_notice,NULL,tmp);
                }
            }
            else if (conn_get_state(conn)==conn_state_loggedin) {
                if (e[i][0]=='#') {
                    /* channel message */
                    t_channel * channel;

                    if ((channel = channellist_find_channel_by_name(irc_convert_ircname(e[i]),NULL,NULL))) {
                        if ((std::strlen(text)>=9)&&(std::strncmp(text,"\001ACTION ",8)==0)&&(text[std::strlen(text)-1]=='\001')) {
                            /* at least "\001ACTION \001" */
                            /* it's a CTCP ACTION message */
                            text = text + 8;
                            text[std::strlen(text)-1] = '\0';
                            channel_message_send(channel,message_type_emote,conn,text);
                        }
                        else {
                            channel_message_log(channel, conn, 1, text);
                            channel_message_send(channel,message_type_talk,conn,text);
                        }
                    }
                    else {
                        irc_send(conn,ERR_NOSUCHCHANNEL,":No such channel");
                    }
                }
                else {
                    /* whisper */
                    t_connection * user;

                    if ((user = connlist_find_connection_by_accountname(e[i])))
                    {
                        message_send_text(user,message_type_whisper,conn,text);
                    }
                    else
                    {
                        irc_send(conn,ERR_NOSUCHNICK,":No such user");
                    }
                }
            }
        }
        if (e)
            irc_unget_listelems(e);
    }
    else
        irc_send(conn,ERR_NEEDMOREPARAMS,"PRIVMSG :Not enough parameters");
    return 0;
}
Beispiel #3
0
static t_account * account_create3(char const * username, char const * passhash1, char const * email)
{
    t_account * account;
    
    if (username && !passhash1) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL passhash1");
	return NULL;
    }

    if (username && account_check_name(username)) {
	eventlog(eventlog_level_error,__FUNCTION__,"got invalid chars in username");
	return NULL;
    }

    account = xmalloc(sizeof(t_account));

    account->name     = NULL;
    account->clanmember = NULL;
    account->attrgroup   = NULL;
    account->friends  = NULL;
    account->teams    = NULL;
    account->conn = NULL;
    FLAG_ZERO(&account->flags);

    account->namehash = 0; /* hash it later before inserting */
    account->uid      = 0; /* hash it later before inserting */

    if (username) { /* actually making a new account */
	/* first check if such a username already owns an account.
	 * we search in the memory hash mainly for non-indexed storage types.
	 * indexed storage types check themselves if the username exists already 
	 * in the storage (see storage_sql.c) */
	if (accountlist_find_account(username)) {
		eventlog(eventlog_level_debug,__FUNCTION__,"user \"%s\" already has an account",username);
		goto err;
	}

	account->attrgroup =  attrgroup_create_newuser(username);
	if(!account->attrgroup) {
	    eventlog(eventlog_level_error,__FUNCTION__,"failed to add user");
	    goto err;
	}

	account->name = xstrdup(username);

        if (account_set_strattr(account,"BNET\\acct\\username",username)<0) {
            eventlog(eventlog_level_error,__FUNCTION__,"could not set username");
            goto err;
        }

        if (account_set_numattr(account,"BNET\\acct\\userid",maxuserid+1)<0) {
            eventlog(eventlog_level_error,__FUNCTION__,"could not set userid");
            goto err;
        }

		if (account_set_strattr(account,"BNET\\acct\\passhash1",passhash1)<0) {
            eventlog(eventlog_level_error,__FUNCTION__,"could not set passhash1");
            goto err;
        }

        if (account_set_numattr(account,"BNET\\acct\\ctime",(unsigned int)now)) {
            eventlog(eventlog_level_error,__FUNCTION__,"could not set ctime");
            goto err;
        }

		if (account_set_strattr(account,"BNET\\acct\\email",email)<0) {
            eventlog(eventlog_level_error,__FUNCTION__,"could not set email");
            goto err;
        }

        if (account_set_numattr(account,"BNET\\auth\\vip_expire",(unsigned int)now+prefs_get_vip_experience())) {
            eventlog(eventlog_level_error,__FUNCTION__,"could not set vip_expire");
            goto err;
        }
    }

    return account;

err:
    account_destroy(account);
    return NULL;
}
Beispiel #4
0
extern t_account * account_create(char const * username, char const * passhash1)
{
    t_account * account;

    if (username && account_check_name(username)<0)
    {
        eventlog(eventlog_level_error,"account_create","got bad account name");
        return NULL;
    }

    if (!(account = malloc(sizeof(t_account))))
    {
		eventlog(eventlog_level_error,"account_create","could not allocate memory for account");
		return NULL;
    }

    account->filename = NULL;
    account->attrs    = NULL;
    account->age      = 0;
    CLEAR_FLAGS(account);

    account->namehash = 0; /* hash it later before inserting */
#ifndef ACCT_DYN_LOAD
    account->uid      = 0;
#endif /* !ACCT_DYN_LOAD */
#ifdef ACCT_DYN_UNLOAD
    account->ref      = 0;
#endif /* ACCT_DYN_UNLOAD */


    if (username) /* actually making a new account */
    {
        char * temp;

		if (account_check_name(username)<0)
		{
	    	eventlog(eventlog_level_error,"account_create","invalid account name \"%s\"",username);
		    account_destroy(account);
		    return NULL;
		}
		if (!passhash1)
		{
            eventlog(eventlog_level_error,"account_create","got NULL passhash1");
            account_destroy(account);
            return NULL;
		}

#ifdef WITH_STORAGE_DB
	    /* In DB (MySQL) storage i always use the real login name as id */
	    if (!(temp = malloc(strlen(username)+1))) /* name + NUL */
	    {
	        eventlog(eventlog_level_error,"account_create","could not allocate memory for temp");
	        account_destroy(account);
	        return NULL;
	    }
	    sprintf(temp,"%s",username);
#else
# ifndef ACCT_DYN_LOAD
		if (prefs_get_savebyname()==0)
		{
	        if (!(temp = malloc(strlen(prefs_get_userdir())+1+8+1))) /* dir + / + uid + NUL */
	        {
				eventlog(eventlog_level_error,"account_create","could not allocate memory for temp");
				account_destroy(account);
				return NULL;
		    }
		    sprintf(temp,"%s/%06u",prefs_get_userdir(),maxuserid+1); /* FIXME: hmm, maybe up the %06 to %08... */
		}
		else
# endif /* ! ACCT_DYN_LOAD */
		{
		    char const * safename;
		    char *	 filename;

		    if (!(filename = strdup(username)))
		    {
				eventlog(eventlog_level_error,"account_create","could not allocate memory for filename");
				account_destroy(account);
				return NULL;
		    }
		    str_to_lower(filename);
		    if (!(safename = escape_fs_chars(filename,strlen(filename))))
		    {
				eventlog(eventlog_level_error,"account_create","could not escape username");
				account_destroy(account);
				free(filename);
				return NULL;
		    }
		    free(filename);
		    if (!(temp = malloc(strlen(prefs_get_userdir())+1+strlen(safename)+1))) /* dir + / + name + NUL */
		    {
				eventlog(eventlog_level_error,"account_create","could not allocate memory for temp");
				account_destroy(account);
				return NULL;
		    }
		    sprintf(temp,"%s/%s",prefs_get_userdir(),safename);
		    free((void *)safename); /* avoid warning */
		}
#endif /* WITH_DB_STORAGE */
		account->filename = temp;

	    SET_FLAG(account,account_flag_loaded);

		if (account_set_strattr(account,"BNET\\acct\\username",username)<0)
		{
	    	eventlog(eventlog_level_error,"account_create","could not set username");
		    account_destroy(account);
		    return NULL;
		}
#ifndef ACCT_DYN_LOAD
		if (account_set_numattr(account,"BNET\\acct\\userid",maxuserid+1)<0)
		{
		    eventlog(eventlog_level_error,"account_create","could not set userid");
		    account_destroy(account);
		    return NULL;
		}
#endif /* !ACCT_DYN_LOAD */
		if (account_set_strattr(account,"BNET\\acct\\passhash1",passhash1)<0)
		{
		    eventlog(eventlog_level_error,"account_create","could not set passhash1");
		    account_destroy(account);
		    return NULL;
		}

#ifdef WITH_BITS
		account_set_bits_state(account,account_state_valid);
		if (!bits_master) {
		    eventlog(eventlog_level_warn,"account_create","account_create should not be called on BITS clients");
		}
#endif /* WITH_BITS */
    }
#ifdef WITH_BITS
    else /* empty account to be filled in later */
		account_set_bits_state(account,account_state_valid);
#endif /* WITH_BITS */

    return account;
}