The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

MysqlFE::userdbprivs() syntax

Discussion in 'cPanel Developers' started by lvt, Jun 29, 2009.

  1. lvt

    lvt Well-Known Member

    Joined:
    May 23, 2009
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    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 :

    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.
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Your function call is returning all privileges for me. Are you seeing this user as having all privileges via the cPanel interface?
     
  3. lvt

    lvt Well-Known Member

    Joined:
    May 23, 2009
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Reseller Owner
    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.
     
  4. lvt

    lvt Well-Known Member

    Joined:
    May 23, 2009
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    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".
     
    #4 lvt, Jun 29, 2009
    Last edited: Jun 29, 2009
  5. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    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.
     
  6. lvt

    lvt Well-Known Member

    Joined:
    May 23, 2009
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Reseller Owner
    Can you please test with the following cPanel version ?

    11.24.4-RELEASE
     
  7. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I'll provision a server with the latest RELEASE tonight, should be able to test on it when I'm back in the office tomorrow :).
     
  8. lvt

    lvt Well-Known Member

    Joined:
    May 23, 2009
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Reseller Owner
    Thanks David :p
     
  9. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    It's still working for me on:

    cPanel 11.24.4-R36167 - WHM 11.24.2 - X 3.9
    CENTOS 4.7 i686 standard
     
  10. lvt

    lvt Well-Known Member

    Joined:
    May 23, 2009
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Reseller Owner
    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.
     
  11. testpgm

    testpgm Member

    Joined:
    May 25, 2010
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    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?
     
  12. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    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.
     
  13. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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
     
  14. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,456
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    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.
     
Loading...

Share This Page