MysqlFE::userdbprivs() syntax

lvt

Well-Known Member
May 23, 2009
49
0
56
cPanel Access Level
Reseller Owner
Can you please tell me the complete syntax of this function ? I tried with an user having several privileges but the API only returns one.

Here is the XML result :

<cpanelresult>
<apiversion>2</apiversion>
<data>
<ALTER>1</ALTER>
</data>
<func>userdbprivs</func>
<module>MysqlFE</module>
</cpanelresult>
How to use this function to show a full list of privileges ?

My API call is the following

PHP:
<cpanelaction><module>MysqlFE</module><func>userdbprivs</func><apiversion>2</apiversion><args><user>{$info['user']}</user><db>{$info['db']}</db></args></cpanelaction>
Thanks.
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
Can you please tell me the complete syntax of this function ? I tried with an user having several privileges but the API only returns one.

Here is the XML result :



How to use this function to show a full list of privileges ?

My API call is the following

PHP:
<cpanelaction><module>MysqlFE</module><func>userdbprivs</func><apiversion>2</apiversion><args><user>{$info['user']}</user><db>{$info['db']}</db></args></cpanelaction>
Thanks.
Your function call is returning all privileges for me. Are you seeing this user as having all privileges via the cPanel interface?
 

lvt

Well-Known Member
May 23, 2009
49
0
56
cPanel Access Level
Reseller Owner
Your function call is returning all privileges for me. Are you seeing this user as having all privileges via the cPanel interface?
You're right, this function works fine, thanks to your suggestion I use the cPanel interface to check and I see that the API function "adduserdb" doesn't work at all. Some days ago I posted an entry about this problem here :

http://forums.cpanel.net/developer-corner/118293-create-db-php-2.html#post531025

I think it worked but it was just an inlusion, it only works with "ALL" option, any other input will fails.
 

lvt

Well-Known Member
May 23, 2009
49
0
56
cPanel Access Level
Reseller Owner
Let's do some tests

#1

PHP:
<cpanelaction><module>Mysql</module><func>adduserdb</func><apiversion>1</apiversion><args>{$info['db']}</args><args>{$info['user']}</args><args>ALL</args></cpanelaction>
OK I have ALL checked, no problem here.

#2

PHP:
<cpanelaction><module>Mysql</module><func>adduserdb</func><apiversion>1</apiversion><args>{$info['db']}</args><args>{$info['user']}</args><args>INSERT DELETE</args></cpanelaction>
This query failed !

#3

PHP:
<cpanelaction><module>Mysql</module><func>adduserdb</func><apiversion>1</apiversion><args>{$info['db']}</args><args>{$info['user']}</args><args>INSERTDELETE</args></cpanelaction>
For this #3 (no space between values) I only have the "DELETE" value checked.

So how can I do to use this API properly ? Because it's important to not to give all privileges to anyone as it poses some security risk. Most of users will only need "INSERT SELECT UPDATE DELETE".
 
Last edited:

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
Code:
https://SERVER:2083/xml-api/cpanel?user=cPanelUser&xmlin=<cpanelaction> <module>Mysql</module><func>adduserdb</func><apiversion>1</apiversion><args>cpanel_DB</args><args>cpanel_USER</args><args>INSERT DELETE</args></cpanelaction>
Works for me.

Acceptable values are as follows:

ALL SELECT CREATE INSERT ALTER UPDATE DROP DELETE LOCK INDEX REFERENCES CREATETEMPORARYTABLES

The X3 interface places spaces between these values and uses these values in the above order.
 

lvt

Well-Known Member
May 23, 2009
49
0
56
cPanel Access Level
Reseller Owner
Code:
https://SERVER:2083/xml-api/cpanel?user=cPanelUser&xmlin=<cpanelaction> <module>Mysql</module><func>adduserdb</func><apiversion>1</apiversion><args>cpanel_DB</args><args>cpanel_USER</args><args>INSERT DELETE</args></cpanelaction>
Works for me.

Acceptable values are as follows:

ALL SELECT CREATE INSERT ALTER UPDATE DROP DELETE LOCK INDEX REFERENCES CREATETEMPORARYTABLES

The X3 interface places spaces between these values and uses these values in the above order.
Can you please test with the following cPanel version ?

11.24.4-RELEASE
 

lvt

Well-Known Member
May 23, 2009
49
0
56
cPanel Access Level
Reseller Owner
It's still working for me on:

cPanel 11.24.4-R36167 - WHM 11.24.2 - X 3.9
CENTOS 4.7 i686 standard
With your prompt support I have solved the problem, in fact, cPanel's APIs don't accept spaces between argument values so we need to replace all spaces by "%20" (as urlencode() usually does).

Thanks again.
 

testpgm

Member
May 25, 2010
10
0
51
I have been using the function MysqlFE::userdbprivs() for an account. Am getting the result as 1. No boolean values are getting displayed in the result. The code is as below:
include("xmlapi.php");
$db_host = "aaa";
$cpuser = "bbbb";
$xmlapi = new xmlapi($db_host);
$xmlapi->password_auth(role,pass);
$result=$xmlapi->api2_query($cpuser,'MysqlFE','userdbprivs',array(dbname,username));
The result am getting is:

SimpleXMLElement Object
(
[apiversion] => 2
[data] => SimpleXMLElement Object
(
)

[event] => SimpleXMLElement Object
(
[result] => 1
)

[func] => userdbprivs
[module] => MysqlFE
)
Please help me to find where is the error?
 

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
Houston, TX
cPanel Access Level
Root Administrator
I have been using the function MysqlFE::userdbprivs() for an account. Am getting the result as 1. No boolean values are getting displayed in the result. The code is as below:
include("xmlapi.php");
$db_host = "aaa";
$cpuser = "bbbb";
$xmlapi = new xmlapi($db_host);
$xmlapi->password_auth(role,pass);
$result=$xmlapi->api2_query($cpuser,'MysqlFE','userdbprivs',array(dbname,username));
The result am getting is:

SimpleXMLElement Object
(
[apiversion] => 2
[data] => SimpleXMLElement Object
(
)

[event] => SimpleXMLElement Object
(
[result] => 1
)

[func] => userdbprivs
[module] => MysqlFE
)
Please help me to find where is the error?
What turns up in /usr/local/cpanel/logs/access_log when you execute this? It seems that you aren't passing in the proper parameters, but you may have editted your output.
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
What version of cPanel are you running? 11.25.0? 11.25.1?

If you're running 11.25.1, you may need to provide the literal database name.

ex:
Code:
$user = 'dave';
$result = $xmlapi->api1_query($user,'Mysql','adddb',array('adbname') ); //will create dave_adbname
$result = $xmlapi->api1_query($user,'Mysql','adduser',array('adbuser') ); //will create dave_adbuser

$result = $xmlapi->api1_query($user,'Mysql','adduserdb',array('dave_adbname','dave_adbuser','ALL') );

$result = $xmlapi->api2_query($user,'MysqlFE','userdbprivs', array('db'=>'dave_adbname','user'=>'dave_adbuser') );
Regards,
-DavidN
 

Infopro

Well-Known Member
May 20, 2003
17,075
524
613
Pennsylvania
cPanel Access Level
Root Administrator
Twitter
Important cPanel/WHM Version Number Designation Change

Please Note: Important cPanel/WHM Version Number Designation Change

As of July 28, 2010 the cPanel/WHM version number designations have been officially changed.

Version 11.25.1 is now designated 11.28 and version 11.25.2 is now designated 11.30.

These new changes were explained in some detail recently at the July 2010 - Quarterly Road map - Webinar direct from cPanel's PodCast Studio in Houston, Texas with speakers David Grega and Mario Rodriguez.

An official press release about these changes is forthcoming and can be accessed at this link as soon as it's made available to the Forum Team:
Important cPanel/WHM Version Number Designation Change (To be updated)

This post serves to update users who are subscribed to threads (where this message is posted) looking forward to upcoming enhancements in future versions of cPanel.