コード例 #1
0
ファイル: account.c プロジェクト: 91D2/pvpgn
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;
}
コード例 #2
0
ファイル: bits_va.c プロジェクト: Danteoriginal/bnetd
extern int bits_va_unlock_account(t_account * account)
{
	if (!account)
	{
		eventlog(eventlog_level_error,"bits_va_unlock_account","got NULL account");
		return -1;
	}
	if (!bits_uplink_connection)
	{
		eventlog(eventlog_level_error,"bits_va_unlock_account","FIXME: bits master should never (un)lock account");
		return 0;
	}
	eventlog(eventlog_level_debug,"bits_va_unlock_account","unlocking account #%u",account_get_uid(account));
	bits_va_locklist_del(bits_uplink_connection,bits_va_locklist_byuid(bits_uplink_connection,account_get_uid(account)));
	if (account_get_bits_state(account)!=account_state_invalid)
	{
		if (!bits_va_locklist_is_locked_by(account_get_uid(account)))
		{
			send_bits_va_unlock(account_get_uid(account));
		}
	}
	if (accountlist_remove_account(account)<0) eventlog(eventlog_level_error,"bits_va_unlock_account","account is not in accountlist");
	account_destroy(account);
	return 0;
}
コード例 #3
0
ファイル: account.c プロジェクト: Danteoriginal/bnetd
extern t_account * create_vaccount(const char *username, unsigned int uid)
{
    /* this is a modified(?) version of account_create */
    t_account * account;

    account = malloc(sizeof(t_account));
    if (!account)
    {
		eventlog(eventlog_level_error,"create_vaccount","could not allocate memory for account");
		return NULL;
    }
    account->attrs    = NULL;
    account->age      = 0;
    CLEAR_FLAGS(account);

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

    account->filename = NULL;	/* there is no local account file */
    account->bits_state = account_state_unknown;

    if (username)
    {
		if (username[0]!='#') {
			if (strchr(username,' '))
			{
				eventlog(eventlog_level_error,"create_vaccount","username contains spaces");
				account_destroy(account);
				return NULL;
			}
			if (strlen(username)>=MAX_USER_NAME)
			{
				eventlog(eventlog_level_error,"create_vaccount","username \"%s\" is too long (%u chars)",username,strlen(username));
				account_destroy(account);
				return NULL;
			}
			account_set_strattr(account,"BNET\\acct\\username",username);
            account->namehash = account_hash(username);
		} else {
			if (str_to_uint(&username[1],&account->uid)<0) {
				eventlog(eventlog_level_warn,"create_vaccount","invalid username \"%s\"",username);
			}
		}
    }
    account_set_numattr(account,"BNET\\acct\\userid",account->uid);
    return account;
}
コード例 #4
0
ファイル: account.c プロジェクト: 91D2/pvpgn
extern int accountlist_destroy(void)
{
    t_entry *   curr;
    t_account * account;

    HASHTABLE_TRAVERSE(accountlist_head,curr)
    {
	if (!(account = entry_get_data(curr)))
	    eventlog(eventlog_level_error,__FUNCTION__,"found NULL account in list");
	else
	{
	    if (account_flush(account, FS_FORCE)<0)
		eventlog(eventlog_level_error,__FUNCTION__,"could not save account");

	    account_destroy(account);
	}
	hashtable_remove_entry(accountlist_head,curr);
    }

    HASHTABLE_TRAVERSE(accountlist_uid_head,curr)
    {
	    hashtable_remove_entry(accountlist_head,curr);
    }
コード例 #5
0
ファイル: account.c プロジェクト: 91D2/pvpgn
static int _cb_read_accounts(t_attrgroup *attrgroup, void *data)
{
    unsigned int *count = (unsigned int *)data;
    t_account *account;

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

    if (!accountlist_add_account(account)) {
        eventlog(eventlog_level_error, __FUNCTION__,"could not add account to list");
        account_destroy(account);
        return -1;
    }

    /* might as well free up the memory since we probably won't need it */
    account_flush(account,FS_FORCE); /* force unload */

    (*count)++;

    return 0;
}
コード例 #6
0
ファイル: account.c プロジェクト: 91D2/pvpgn
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;
}
コード例 #7
0
ファイル: account.c プロジェクト: Danteoriginal/bnetd
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;
}