New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running under Ubuntu 64 #4

Open
cassianotartari opened this Issue Jun 26, 2014 · 9 comments

Comments

Projects
None yet
3 participants
@cassianotartari

cassianotartari commented Jun 26, 2014

I'm trying it with Ubuntu 64 without success...

My MakeFile I've changed to this:

LIBDIR=/usr/lib/mysql/plugin

install:
    gcc -Wall -m64 -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o $(LIBDIR)/lib_mysqludf_sys.so -fPIC

I've added this in /etc/mysql/my.conf

plugin_dir      = /usr/lib/mysql/plugin

Changed the permissions of /usr/lib/mysql/plugin

$ sudo chown mysql: mysql -R /var/lib/mysql/plugin 

Restarted mysql

sudo service mysql restart

When I run you example command:

mysql> SELECT sys_exec ('touch /var/lib/mysql/test.txt ');
+---------------------------------------------+
| sys_exec ('touch /var/lib/mysql/test.txt ') |
+---------------------------------------------+
| 32512 |
+---------------------------------------------+
1 row in set (0.00 sec)

or

mysql> SELECT sys_eval('id');
+----------------+
| sys_eval('id') |
+----------------+
| NULL           |
+----------------+
1 row in set (0.40 sec)

or

mysql> SELECT sys_eval('cp /home/cassiano/Desktop/index.html /home/cassiano/');
+------------------------------------------------------------------+
| sys_eval('cp /home/cassiano/Desktop/index.html /home/cassiano/') |
+------------------------------------------------------------------+
|                                                                  |
+------------------------------------------------------------------+
1 row in set (0.02 sec)

Nothing happens...
I've already checked /var/log/mysql/error.log and it is empty

Any ideas?

@daper

This comment has been minimized.

Show comment
Hide comment
@daper

daper Jul 9, 2014

In my case:

This problem is caused by apparmor and i solved it by disabling its profile. This may help http://www.cyberciti.biz/faq/ubuntu-linux-howto-disable-apparmor-commands/

And i see a bit difference in the compile sentence, i used this one: "gcc -DMYSQL_DYNAMIC_PLUGIN -fPIC -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o $(LIBDIR)/lib_mysqludf_sys.so"

daper commented Jul 9, 2014

In my case:

This problem is caused by apparmor and i solved it by disabling its profile. This may help http://www.cyberciti.biz/faq/ubuntu-linux-howto-disable-apparmor-commands/

And i see a bit difference in the compile sentence, i used this one: "gcc -DMYSQL_DYNAMIC_PLUGIN -fPIC -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o $(LIBDIR)/lib_mysqludf_sys.so"

@cassianotartari

This comment has been minimized.

Show comment
Hide comment
@cassianotartari

cassianotartari Jul 9, 2014

Thank you!

Now improved somewhat but still not doing what I would like to do. Execute a ffmpeg command or a php script, or even copy a file from a path to another.

I've tested with the compile command that I've posted and yours, both the same result.

Now at least it is working some test commands:

mysql> SELECT sys_eval('id');
+-------------------------------------------------+
| sys_eval('id')                                  |
+-------------------------------------------------+
| uid=116(mysql) gid=125(mysql) groups=125(mysql) |
+-------------------------------------------------+
1 row in set (0.09 sec)
mysql> SELECT sys_eval('pwd');
+-----------------+
| sys_eval('pwd') |
+-----------------+
| /var/lib/mysql  |
+-----------------+
1 row in set (0.01 sec)

But others like these not:

mysql> SELECT sys_eval('cp /home/cassiano/Desktop/index.html /home/cassiano/');
+------------------------------------------------------------------+
| sys_eval('cp /home/cassiano/Desktop/index.html /home/cassiano/') |
+------------------------------------------------------------------+
| NULL                                                             |
+------------------------------------------------------------------+
1 row in set (0.02 sec)

mysql> SELECT sys_exec('cp /home/cassiano/Desktop/index.html /home/cassiano/');
+------------------------------------------------------------------+
| sys_exec('cp /home/cassiano/Desktop/index.html /home/cassiano/') |
+------------------------------------------------------------------+
|                                                              256 |
+------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT sys_exec('ffmpeg -i ~/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 ~/teste/img%03d.jpg');
+----------------------------------------------------------------------------------------------------------------+
| sys_exec('ffmpeg -i ~/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 ~/teste/img%03d.jpg') |
+----------------------------------------------------------------------------------------------------------------+
|                                                                                                            256 |
+----------------------------------------------------------------------------------------------------------------+
1 row in set (2.03 sec)

mysql> SELECT sys_eval('ffmpeg -i ~/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 ~/teste/img%03d.jpg');
+----------------------------------------------------------------------------------------------------------------+
| sys_eval('ffmpeg -i ~/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 ~/teste/img%03d.jpg') |
+----------------------------------------------------------------------------------------------------------------+
| NULL                                                                                                           |
+----------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

cassianotartari commented Jul 9, 2014

Thank you!

Now improved somewhat but still not doing what I would like to do. Execute a ffmpeg command or a php script, or even copy a file from a path to another.

I've tested with the compile command that I've posted and yours, both the same result.

Now at least it is working some test commands:

mysql> SELECT sys_eval('id');
+-------------------------------------------------+
| sys_eval('id')                                  |
+-------------------------------------------------+
| uid=116(mysql) gid=125(mysql) groups=125(mysql) |
+-------------------------------------------------+
1 row in set (0.09 sec)
mysql> SELECT sys_eval('pwd');
+-----------------+
| sys_eval('pwd') |
+-----------------+
| /var/lib/mysql  |
+-----------------+
1 row in set (0.01 sec)

But others like these not:

mysql> SELECT sys_eval('cp /home/cassiano/Desktop/index.html /home/cassiano/');
+------------------------------------------------------------------+
| sys_eval('cp /home/cassiano/Desktop/index.html /home/cassiano/') |
+------------------------------------------------------------------+
| NULL                                                             |
+------------------------------------------------------------------+
1 row in set (0.02 sec)

mysql> SELECT sys_exec('cp /home/cassiano/Desktop/index.html /home/cassiano/');
+------------------------------------------------------------------+
| sys_exec('cp /home/cassiano/Desktop/index.html /home/cassiano/') |
+------------------------------------------------------------------+
|                                                              256 |
+------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT sys_exec('ffmpeg -i ~/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 ~/teste/img%03d.jpg');
+----------------------------------------------------------------------------------------------------------------+
| sys_exec('ffmpeg -i ~/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 ~/teste/img%03d.jpg') |
+----------------------------------------------------------------------------------------------------------------+
|                                                                                                            256 |
+----------------------------------------------------------------------------------------------------------------+
1 row in set (2.03 sec)

mysql> SELECT sys_eval('ffmpeg -i ~/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 ~/teste/img%03d.jpg');
+----------------------------------------------------------------------------------------------------------------+
| sys_eval('ffmpeg -i ~/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 ~/teste/img%03d.jpg') |
+----------------------------------------------------------------------------------------------------------------+
| NULL                                                                                                           |
+----------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
@daper

This comment has been minimized.

Show comment
Hide comment
@daper

daper Jul 10, 2014

sys_exec and sys_eval are quite similar, both can run arbitrary code, but the first one returns the exit code and second one the output. Some times i have had to do an explicit cast due to a blob type response (with gui). These are good tests:

mysql> select 
    -> sys_eval('curl http://ipecho.net/plain') as plain,
    -> CAST(sys_eval('curl http://ipecho.net/plain') AS CHAR(10000) CHARACTER SET utf8) as cast,
    -> sys_exec('curl http://ipecho.net/plain') as sys_exec;
+---------------+---------------+----------+
| plain         | cast          | sys_exec |
+---------------+---------------+----------+
| xxx.xx.xx.xxx | xxx.xx.xx.xxx |        0 |
+---------------+---------------+----------+
1 row in set (3.52 sec)

Your ffmpeg issue could be a permissions problem, checkout this command:

which ffmpeg | xargs ls -lh

Anyway make sure in the filesystem that it doesn't run.

"cp", "touch", "mv" does not return anything on success. You should check your fs and confirm the copy.

daper commented Jul 10, 2014

sys_exec and sys_eval are quite similar, both can run arbitrary code, but the first one returns the exit code and second one the output. Some times i have had to do an explicit cast due to a blob type response (with gui). These are good tests:

mysql> select 
    -> sys_eval('curl http://ipecho.net/plain') as plain,
    -> CAST(sys_eval('curl http://ipecho.net/plain') AS CHAR(10000) CHARACTER SET utf8) as cast,
    -> sys_exec('curl http://ipecho.net/plain') as sys_exec;
+---------------+---------------+----------+
| plain         | cast          | sys_exec |
+---------------+---------------+----------+
| xxx.xx.xx.xxx | xxx.xx.xx.xxx |        0 |
+---------------+---------------+----------+
1 row in set (3.52 sec)

Your ffmpeg issue could be a permissions problem, checkout this command:

which ffmpeg | xargs ls -lh

Anyway make sure in the filesystem that it doesn't run.

"cp", "touch", "mv" does not return anything on success. You should check your fs and confirm the copy.

@cassianotartari

This comment has been minimized.

Show comment
Hide comment
@cassianotartari

cassianotartari Jul 10, 2014

Thank you again daper, I know that the functions are similar but was just to make sure.

Your test worked like expected, returned my ip address in plain and cast columns.

The ffmpeg is under my home folder because I've compiled it and has my user permission:

$ which ffmpeg | xargs ls -lh
-rwxr-xr-x 1 cassiano cassiano 16M Jun 10 16:13 /home/cassiano/bin/ffmpeg

The "cp", "touch", "mv" does not return and does not do anything. The same command line of my example:

cp /home/cassiano/Desktop/index.html /home/cassiano/

Works in the terminal (copy the file) and does not work under udf sys functions.

The command:

ffmpeg -i /home/cassiano/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 /home/cassiano/teste/img%03d.jpg

Works in terminal but not using "sys_exec"

cassianotartari commented Jul 10, 2014

Thank you again daper, I know that the functions are similar but was just to make sure.

Your test worked like expected, returned my ip address in plain and cast columns.

The ffmpeg is under my home folder because I've compiled it and has my user permission:

$ which ffmpeg | xargs ls -lh
-rwxr-xr-x 1 cassiano cassiano 16M Jun 10 16:13 /home/cassiano/bin/ffmpeg

The "cp", "touch", "mv" does not return and does not do anything. The same command line of my example:

cp /home/cassiano/Desktop/index.html /home/cassiano/

Works in the terminal (copy the file) and does not work under udf sys functions.

The command:

ffmpeg -i /home/cassiano/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 /home/cassiano/teste/img%03d.jpg

Works in terminal but not using "sys_exec"

@daper

This comment has been minimized.

Show comment
Hide comment
@daper

daper Jul 10, 2014

Ok... In copy command the output code you are receiving corresponds with errors like "No such file or directory" or "Not a directory". You can try something like:

select sys_exec('ffmpeg -i /home/cassiano/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 /home/cassiano/teste/img%03d.jpg &> /tmp/debug-exec.log'

And review the log file in /tmp/debug-exec.log... But i have no more relevant ideas.

daper commented Jul 10, 2014

Ok... In copy command the output code you are receiving corresponds with errors like "No such file or directory" or "Not a directory". You can try something like:

select sys_exec('ffmpeg -i /home/cassiano/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 /home/cassiano/teste/img%03d.jpg &> /tmp/debug-exec.log'

And review the log file in /tmp/debug-exec.log... But i have no more relevant ideas.

@cassianotartari

This comment has been minimized.

Show comment
Hide comment
@cassianotartari

cassianotartari Jul 10, 2014

Thank you for the time spent trying to help me.

I've tried your idea without success... The command has created the file but it is empty. Maybe is something wrong about permissions, that's the only option in my mind. Some commands run others not. Running "sys_eval('pwd')" return "/var/lib/mysql", running "sys_eval('whoami')" returns "mysql".

Tried to give root privileges to mysql user add the row:

mysql   ALL=(ALL:ALL) ALL

in "/etc/sudoers"

The commands still not working.

I've tried to create a php script to run a system command:

<?php

$file = 'results.txt';

$current = file_get_contents($file);

$current .= $argv[1]."\n";

$output = system($argv[1]);

$current .= $output."\n";

file_put_contents($file, $current);

?>

Again, it works in terminal but not using sys_exec

php5 -e "/var/www/html/do_job.php" "/bin/cp /home/cassiano/Desktop/index.html /home/cassiano/"

The weird thing is that this php script create the results.txt inside /var/lib/mysql with the parameter but the index.html it is not copied...

cassianotartari commented Jul 10, 2014

Thank you for the time spent trying to help me.

I've tried your idea without success... The command has created the file but it is empty. Maybe is something wrong about permissions, that's the only option in my mind. Some commands run others not. Running "sys_eval('pwd')" return "/var/lib/mysql", running "sys_eval('whoami')" returns "mysql".

Tried to give root privileges to mysql user add the row:

mysql   ALL=(ALL:ALL) ALL

in "/etc/sudoers"

The commands still not working.

I've tried to create a php script to run a system command:

<?php

$file = 'results.txt';

$current = file_get_contents($file);

$current .= $argv[1]."\n";

$output = system($argv[1]);

$current .= $output."\n";

file_put_contents($file, $current);

?>

Again, it works in terminal but not using sys_exec

php5 -e "/var/www/html/do_job.php" "/bin/cp /home/cassiano/Desktop/index.html /home/cassiano/"

The weird thing is that this php script create the results.txt inside /var/lib/mysql with the parameter but the index.html it is not copied...

@cassianotartari

This comment has been minimized.

Show comment
Hide comment
@cassianotartari

cassianotartari Jul 11, 2014

Something is going wrong here, I don't know what yet, but when I run:

SELECT sys_eval('/usr/bin/php5 -e "/var/www/html/do_jobs.php" "ffmpeg -i /home/cassiano/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 img%03d.jpg"');

The frame images are generate successfully but under "/var/lib/mysql", the path returned in my "sys_eval('pwd')" test.

When I try to run:

SELECT sys_eval('/usr/bin/php5 -e "/var/www/html/do_jobs.php" "ffmpeg -i /home/cassiano/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 /home/cassiano/teste/img%03d.jpg"');

Just adding the path "/home/cassiano/teste/" to the image that will be generated nothing happens, the ffmpeg don't generate the images, or even run.

EDITED ================================

WORKS! finally! I don't have enough knowledge to explain but after giving the permissions to the ffmpeg output folder:

sudo chown mysql:mysql /home/cassiano/teste/ -R

It works! I would like to understand because in the last post I mentioned that I gave root privileges to mysql user.

cassianotartari commented Jul 11, 2014

Something is going wrong here, I don't know what yet, but when I run:

SELECT sys_eval('/usr/bin/php5 -e "/var/www/html/do_jobs.php" "ffmpeg -i /home/cassiano/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 img%03d.jpg"');

The frame images are generate successfully but under "/var/lib/mysql", the path returned in my "sys_eval('pwd')" test.

When I try to run:

SELECT sys_eval('/usr/bin/php5 -e "/var/www/html/do_jobs.php" "ffmpeg -i /home/cassiano/teste/BigBuckBunny_320x180.mp4 -s 50x10 -f image2 -vf fps=fps=1/60 /home/cassiano/teste/img%03d.jpg"');

Just adding the path "/home/cassiano/teste/" to the image that will be generated nothing happens, the ffmpeg don't generate the images, or even run.

EDITED ================================

WORKS! finally! I don't have enough knowledge to explain but after giving the permissions to the ffmpeg output folder:

sudo chown mysql:mysql /home/cassiano/teste/ -R

It works! I would like to understand because in the last post I mentioned that I gave root privileges to mysql user.

@dbahar

This comment has been minimized.

Show comment
Hide comment
@dbahar

dbahar Jun 5, 2015

Hello, I have the same problem here... I cannot execute even a simple cp command :(

dbahar commented Jun 5, 2015

Hello, I have the same problem here... I cannot execute even a simple cp command :(

@dbahar

This comment has been minimized.

Show comment
Hide comment
@dbahar

dbahar Jun 5, 2015

Nothing happens :

mysql> SELECT sys_exec('cp /tmp/sefer /MYSQL') as sys_exec;
+----------+
| sys_exec |
+----------+
| 256 |
+----------+
1 row in set (0.02 sec)

dbahar commented Jun 5, 2015

Nothing happens :

mysql> SELECT sys_exec('cp /tmp/sefer /MYSQL') as sys_exec;
+----------+
| sys_exec |
+----------+
| 256 |
+----------+
1 row in set (0.02 sec)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment