Exemple #1
0
/**
 * Add user
 *
 * @param uname         Name of the new user
 * @param passwd        Password for the new user
 * @return      NULL on success or an error string on failure
 */
char *
admin_add_user(char *uname, char *passwd)
{
    FILE *fp;
    char fname[1024], *home, *cpasswd;

    initialise();

    if (access(get_datadir(), F_OK) != 0)
    {
        if (mkdir(get_datadir(), S_IRWXU) != 0 && errno != EEXIST)
        {
            return ADMIN_ERR_PWDFILEOPEN;
        }
    }

    snprintf(fname,1023, "%s/passwd", get_datadir());
    fname[1023] = '\0';
    if (users == NULL)
    {
        MXS_NOTICE("Create initial password file.");

        if ((users = users_alloc()) == NULL)
        {
            return ADMIN_ERR_NOMEM;
        }
        if ((fp = fopen(fname, "w")) == NULL)
        {
            MXS_ERROR("Unable to create password file %s.", fname);
            return ADMIN_ERR_PWDFILEOPEN;
        }
        fclose(fp);
    }
    if (users_fetch(users, uname) != NULL)
    {
        return ADMIN_ERR_DUPLICATE;
    }
    struct crypt_data cdata;
    cdata.initialized = 0;
    cpasswd = crypt_r(passwd, ADMIN_SALT, &cdata);
    users_add(users, uname, cpasswd);
    if ((fp = fopen(fname, "a")) == NULL)
    {
        MXS_ERROR("Unable to append to password file %s.", fname);
        return ADMIN_ERR_FILEAPPEND;
    }
    fprintf(fp, "%s:%s\n", uname, cpasswd);
    fclose(fp);
    return ADMIN_SUCCESS;
}
Exemple #2
0
/**
 * Add user
 *
 * @param uname		Name of the new user
 * @param passwd	Password for the new user
 * @return	NULL on success or an error string on failure
 */
char *
admin_add_user(char *uname, char *passwd)
{
FILE	*fp;
char	fname[1024], *home, *cpasswd;

	initialise();
    sprintf(fname, "%s/passwd", get_datadir());
        
	if (users == NULL)
	{
                LOGIF(LM,
                      (skygw_log_write(LOGFILE_MESSAGE,
                                       "Create initial password file.")));
                
		if ((users = users_alloc()) == NULL)
			return ADMIN_ERR_NOMEM;
		if ((fp = fopen(fname, "w")) == NULL)
		{
                    LOGIF(LE,
                          (skygw_log_write_flush(
                                  LOGFILE_ERROR,
                                  "Error : Unable to create password file %s.",
                                  fname)));
                    return ADMIN_ERR_PWDFILEOPEN;
		}
		fclose(fp);
	}
	if (users_fetch(users, uname) != NULL)
	{
		return ADMIN_ERR_DUPLICATE;
	}
	cpasswd = crypt(passwd, ADMIN_SALT);
	users_add(users, uname, cpasswd);
	if ((fp = fopen(fname, "a")) == NULL)
	{
            LOGIF(LE,
                  (skygw_log_write_flush(LOGFILE_ERROR,
                                         "Error : Unable to append to password file %s.",
                                         fname)));
            return ADMIN_ERR_FILEAPPEND;
	}
	fprintf(fp, "%s:%s\n", uname, cpasswd);
	fclose(fp);
	return ADMIN_SUCCESS;
}
Exemple #3
0
void vent_user_login( uint16_t userid, uint16_t channelid ) {
	printf( "channel: %i, usr: %i\n", channelid, userid );
	users_add( userid );

	v3_channel* chan = channels_get( channelid );
	v3_user* user = users_get( userid );

	if ( chan == NULL ) {
		printf( "channl is null\n" );
		return;
	}

	if ( user == NULL ) {
		printf( "user is null\n " );
		return;
	}
	
	printf( "user login: %s (%s) joined %s ( %s )\n", user->name, user->comment, chan->name, chan->comment );
}