I have already set up a proftpd server with a MySQL connection.
Everything works fine.
I would like to set specific permissions for each user from the database using (PathAllowFilter, PathDenyFilter, ...)
The server running on Ubuntu 12.04 LTS distribution.
It is not so easy, there is no single module to do this. But I found a solution for this.
It's not optimal because you have to restart ProFTPd server each time you change MySQL configuration, but it works.
As you have a ProFTPd server that already run with MySQL, i will explain only the part of specific user configuration.
For this solution you need ProFTPd to be compiled with these modules:
mod_ifsession (with this module you will be able to configure <IfUser> conditions)
mod_conf_sql (with this module you will be able to load configuration from MySQL)
To help you with ProFTPd recompilation, you can run this command proftpd -V to see how your version is configured. You can found some documentation here.
Once you have compiled your ProFTPd server and it's run, you will have to log on your MySQL server.
If you read mod_conf_sql, they say to create 3 tables ftpctxt, ftpconf, ftpmap. We will not create these tables unless you want to have global configuration from MySQL.
We will fake the MySQL configuration with "views".
1. First you add each specific configuration as user column (make sure to have a default value):
ALTER TABLE ftpuser #
ADD PathDenyFilter VARCHAR( 255 ) NOT NULL DEFAULT '(\.ftp)|(\.hta)[a-z]+$';`
ALTER TABLE ftpuser
ADD PathAllowFilter VARCHAR( 255 ) NOT NULL DEFAULT '.*$';`
....
2. Create the conf view:
User's id and configuration column are concatenated to make an unique id
User's configuration column is used as type
User's configuration value is used as info
View is an union of selects (for every column an union is required)
CREATE VIEW ftpuser_conf AS SELECT concat(ftpuser.id,'-PathDenyFilter')
AS id,'PathDenyFilter' AS type,ftpuser.PathDenyFilter AS info from ftpuser
UNION
SELECT concat(ftpuser.id,'-PathAllowFilter')
AS id,'PathAllowFilter' AS type, ftpuser.PathAllowFilter AS info
from ftpuser;
3. Create the ctxt view
This view is a concatenation of a "Default" row and user's rows ("Default" row has 1 as id and user's rows have user's id + 1 as id.
Concatenate "userconf-" and user's id as name
"IfUser" as type
User's username as info
CREATE VIEW ftpuser_ctxt AS
SELECT 1 AS id,NULL AS parent_id, 'default' AS name, 'default' AS type, NULL AS info
UNION
SELECT (ftpuser.id + 1) AS id,1 AS parent_id,
concat('userconf-',ftpuser.userid) AS name,
'IfUser' AS type,ftpuser.userid AS info
FRON ftpuser;
4. Create the map view
User's id and configuration column are concatenated for conf_id
User's id + 1 for ctxt_id
View is an union of selects (for every column an union is required)
CREATE VIEW ftpuser_map
AS SELECT concat(ftpuser.id,'-PathDenyFilter')
AS conf_id,(ftpuser.id + 1) AS ctxt_id
from ftpuser
union
select concat(ftpuser.id,'-PathAllowFilter')
AS conf_id,(ftpuser.id + 1) AS ctxt_id
from ftpuser;
5. Add these lines to your ProFTPd configuration
<IfModule mod_conf_sql.c>
Include sql://user:password#host/db:database/ctxt:ftpuser_ctxt:id,parent_id,type,info/conf:ftpuser_conf:id,type,info/map:ftpuser_map:conf_id,ctxt_id/base_id=1
</IfModule>
Where:
user => your MySQL username
password => your MySQL password
host => your MySQL host
database => your MySQL database
6. Restart your ProFTPd server
I hope this will help you. Good luck
Related
I was able to implement a connection from R through RMariaDB and DBI to a remote MariaDB-database. However, I am currently encountering a strange change of numbers when querying the database through R. I'll explain the differences:
I inserted one simple entry in my database with the following command:
INSERT INTO respondent ( id, name ) VALUES ( 2388793051, 'testuser' )
When I connect to this database directly on the remote server and execute a statement like this:
SELECT * FROM respondent;
it delivers these value
id: 2388793051, name: testuser
So I should also be able to connect to the database via R and receive the same results. So when I execute the following code in R, I expect to receive this inserted and saved information displayed above:
library(DBI)
library(RMariaDB)
conn <- DBI::dbConnect(drv=RMariaDB::MariaDB(), user="myusername", password="mypassword", host="127.0.0.1", port="1111", dbname="mydbname")
res <- dbGetQuery(conn, "SELECT * FROM respondent")
print(res)
However, the result of this query is the following
id name
-1906174245 testuser
As you can see, the id is now -1906174245 instead of the saved 2388793051 in the database. I don't understand this weird conversion of integers in the id-field. Can someone explain how this problem emerges and how I might solve it?
EDIT: I don't expect this to be a problem, but just to inform you: I am using an SSH tunnel to enable a connection via these specified ports from my local to my remote machine.
SOLUTION: What made the difference was to specify the id of a respondent in the database specification already as BIGINT instead of INT. Thanks to #JonnyCrunch
On my test SQL Server 2014 installation, I was "cleaning" the master database.
With the following command, I was checking which user objects there are:
SELECT
'DROP ' +
CASE
WHEN [sys].[all_objects].type IN ('AF','FN','FS','FT','IF','TF') THEN 'FUNCTION '
WHEN [sys].[all_objects].type IN ('D','C','F','PK','UQ') THEN 'CONSTRAINT '
WHEN [sys].[all_objects].type IN ('IT','S','U') THEN 'TABLE '
WHEN [sys].[all_objects].type IN ('P','PC','RF','X') THEN 'PROCEDURE '
WHEN [sys].[all_objects].type IN ('TA','TR') THEN 'TRIGGER '
WHEN [sys].[all_objects].type = 'R' THEN 'RULE '
WHEN [sys].[all_objects].type = 'SN' THEN 'SYNONYM '
WHEN [sys].[all_objects].type = 'TT' THEN 'TYPE '
WHEN [sys].[all_objects].type = 'V' THEN 'VIEW '
END +
SCHEMA_NAME(sys.[all_objects].[schema_id]) + '.' + OBJECT_NAME(object_id) + '; ' as [Command],
OBJECT_NAME(object_id) as [ObjectName],
[sys].[all_objects].[type_desc] as [TypeDesc],
[sys].[all_objects].[type] as [Type],
SCHEMA_NAME(sys.[all_objects].[schema_id]) as [Schema]
FROM
sys.[all_objects] WITH (NOLOCK)
WHERE SCHEMA_NAME(sys.[all_objects].[schema_id]) like '%dbo%'
One of the results was the view spt_values.
Command | ObjectName | TypeDesc | Type | Schema
------------------------|------------|----_-----|------|-------
DROP VIEW dbo.spt_values; spt_values VIEW V dbo
As it was not one of the views I knew, I deleted it (along with other objects).
Later that day, I wanted to check the properties of a database in SSMS 2016 and got the following error:
After some searching, I found that I could recreate the missing view with the script u_tables.sql (which is in the SQL Server installation folder on your server). Information from here: https://ashishgilhotra.wordpress.com/tag/u_tables-sql/
The code in that script to create the view is the following:
create view spt_values as
select name collate database_default as name,
number,
type collate database_default as type,
low, high, status
from sys.spt_values
go
EXEC sp_MS_marksystemobject 'spt_values'
go
grant select on spt_values to public
go
Already when looking at the code, I doubted that it would work, as there is no sys.spt_values table anywhere to be found.
As expected I get the error
Msg 208, Level 16, State 1, Procedure spt_values, Line 6
Invalid object name 'sys.spt_values'.
On my other server with SQL Server 2008 on it, there is a table master.dbo.spt_values (but no view)!
After some more searching, I found that I could just create a table with the same name.. Link here https://www.mssqltips.com/sqlservertip/3694/fix-invalid-object-name-masterdbosptvalues-when-viewing-sql-server-database-properties/
Now I create a table with the values from another SQL Server 2014 installation, and everything seems to be working again.
But, it is not correct!
When I check the new created object on the test server with this command
select [name] , [type], [type_desc]
from sys.objects
where name like 'spt_v%'
It shows a user_table object. On my other server, it shows a view...
So, my question is: How can I create the view spt_values which gets its data from a table spt_values?
Ok, after some fiddling arround, I found the solution..
The table sys.spt_values is in the ressources database (mssqlsystemresource). This database is only accessible when the SQL Service is started in single user mode..
To re-create the view I had to do the following steps:
Stop all SQL Services
2. Start the SQL Service in single user mode
Open a DOS Command prompt and start the sqlservice with the switch -m
sqlservr.exe -sSQLT01 –m
Connect SSMS to the instance
Just connect the query window, but not the Object Explorer window. The service only accepts one single connection! If there is a problem, you can see it in the DOS Window where the service is running.
Delete the wrong table spt_values
As I created a table spt_values on the master database, I have to delete it first
use master
go
drop table dbo.spt_values
5. Create the view
Now I finally can create the view dbo.spt_values, which points to the table sys.spt_values
use master
go
create view spt_values as
select name collate database_default as name,
number,
type collate database_default as type,
low, high, status
from sys.spt_values
go
EXEC sp_MS_marksystemobject 'spt_values'
go
grant select on spt_values to public
go
6. Check the dbo.spt_values object
use master
select schema_name(schema_id), object_id('spt_values'), *
from sys.objects
where name like 'spt_v%'
It should show a view now
Query the view dbo.spt_values and the table sys.spt_values
Just for the fun of it... You can now query the table sys.spt_values, which is in the ressources database
use mssqlsystemresource
Select * from sys.spt_values
And you can query the view dbo.spt_values, which is in the master database
use master
Select * from dbo.spt_values
8. Restart the services
You can now quit the DOS window with the SQL Service running and start the SQL Services. Or you just restart the whole server
Hope this post will help others in the future
The u_tables.sql script will create master.dbo.spt_values, but I had to run it with the Dedicated Administrator Connection (DAC).
Solution:
Step 1: Open the Command Prompt as Admin
Step 2: Run the following:
sqlcmd -S -U sa -P -A -i "C:\Program Files\Microsoft SQL Server\MSSQL14.SQL2017\MSSQL\Install\u_tables.sql"
Swap out and with your values. If you don't have the password to sa you will need to find a user with sufficient rights (and replace 'sa' with your user name).
The -A runs the command as the DAC. This should be used sparingly. See MS documentation on the DAC.
Find the u_tables.sql file in your installation directory. The path above is where it is on my machine with SQL 2017 installed in the default location on the C: drive.
I am currently working on the website that uses ADODB library. In entire website all the queries are written in UPPERCASE.
The problem is when I run the query it doesn't work because of table name which is UPPERCASE. But when I change the table name to lowercase it works.
$sql = "SELECT * FROM MEMBERS where USERNAME = '$username'";
$db = ADONewConnection('mysql');
$db->debug = true;
$db->Connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_NAME);
$resultFriends = $db->Execute($sql);
while ($row = $resultFriends->FetchRow()) {
var_dump($row);
die;
}
Here is the error I get:
ADOConnection._Execute(SELECT * FROM MEMBERS where USERNAME = 'fury', false) % line 1012, file: adodb.inc.php
ADOConnection.Execute(SELECT * FROM MEMBERS where USERNAME = 'fury') % line 15, file: index.php
Bear in mind I don't want to change the scripts. There are 1000 files and 10000 places.
Is there any library or are there any way that I can run this queries without error?
The version for live sire was linux kernel. but the new dev site is ubuntu.
I have done this on ubuntu/ mysql CML and it didn't work.
The solution is I had to reconfigure the mySql database in AWS/rdbs
You have to modify the “lower_case_table_names” parameter for your DB Instance(s). Prior to today, the lower_case_table_names parameter was not modifiable, with a system default of zero (0) or “table names stored as specified and comparisons are case sensitive.” Beginning immediately, values of zero and one (table names are stored in lowercase and comparisons are not case sensitive) are allowed. See the MySQL documentation for more information on the lower_case_table_names parameter.
The lower_case_table_names parameter can be specified via the rds-modify-db-parameter-group API. Simply include the parameter name and specify the desired value, such as in the following example:
rds-modify-db-parameter-group example --parameters "name=lower_case_table_names, value=1, method=pending-reboot" --region us-east-1
Support for modifying parameters via the AWS Management Console is expected to be added later this year.
setting the lower_case_table_names parameter via a custom DB Parameter Group and doing so before creating an associated DB Instance. Changing the parameter for existing DB Instances could cause inconsistencies with point-in-time recovery backups and with Read Replicas.
Amazon RDS
In SQL Server (i'm using 2008) is it possible to dynamically access server by server name?
My scenario: I have a production server, a development server, and a test server. Their structure is the same. There is a fourth server with some additional data - let's call it a data server.
On the data server there is a procedure. One of it's parameters is a name of the requesting server:
proc sp_myProcedure(#myId int, #serverName nvarchar(100))
The procedure accesses tables from the data server and from the requesting server. At the moment, to query the requesting server I'm using a case expression:
-- code on the data server
select additionalData = case #serverName
-- if the requesting server is production - query production
when 'ProdServer' then (select field1 from [ProdServer].[MyDataBase].[dbo].[MyTable] ...
-- if the requesting server is test - query test
when 'TestServer' then (select field1 from [TestServer].[MyDataBase].[dbo].[MyTable] ...
-- if the requesting server is development - query development
when 'DevServer' then (select field1 from [DevServer].[MyDataBase].[dbo].[MyTable] ...
end
My question is if there is any other way to access the requesting server. I'd like to replace ifs and cases with something more dynamic. Is it, for instance, possible to use the server name variable to dynamically access specific server. Something similar to the following (mocked) query:
declare myServer <server type> = Get_Server(#serverName)
-- the query
additionalData = select field1 from [myServer].[MyDataBase].[dbo].[MyTable]
I liked this approach
SELECT
SERVERPROPERTY('MachineName') AS [ServerName],
SERVERPROPERTY('ServerName') AS [ServerInstanceName],
SERVERPROPERTY('InstanceName') AS [Instance],
SERVERPROPERTY('Edition') AS [Edition],
SERVERPROPERTY('ProductVersion') AS [ProductVersion],
Left(##Version, Charindex('-', ##version) - 2) As VersionName
Link
Another approach which we were using was
Creating one database called database_yourprojectname
So, for the explanation I'm using database name as northwind
after that you can create one new database called northwind_db
Which has a following fields:
Servername,username(encrypted),password(encrypted),active
And then you can either make one page to insert/update/delete current database used there
or you can add statically data to it..so, you can use the database which is active currently.
Or use simple one:
SELECT ##SERVERNAME
Which is already stated here
SELECT `aversio`.`module`.`module` AS `module`
FROM
`projectmodule`
JOIN `module` ON `aversio`.`projectmodule`.`moduleID` = `aversio`.`module`.`moduleID`
JOIN `project` ON `aversio`.`project`.`projectID` = `aversio`.`projectmodule`.`projectID`
WHERE `aversio`.`module`.`actief` = _utf8'1'
AND `aversio`.`projectmodule`.`verwijderd` = _utf8'0'
AND `aversio`.`projectmodule`.`verwijderd` = _utf8'0'
MYSQL Error : There is no 'aversio'#'%' registered
What this error mean
That actually looks like a permissions issue, like you are trying to connect as aversio to a MySQL server instance which is not configured to allow that user from any (%) domain.
The syntax 'aversio'#'%' looks like the format 'username'#'host', and mysql uses % as the catch-all (any) host wildcard.
Make sure that you create the MySQL user named aversio, and give them the correct permissions on your DB.
EDIT:
IIRC, a user of that name may exist, but with a different domain (i.e. the users table is keyed on the combo of user and host. I've seen this kind of thing happen when I move code from a dev server to a staging server and try to connect fro mthe new host, having forgotten to modify the permissions in MySQL.