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.

xmlapi adduser fails silently

Discussion in 'cPanel Developers' started by KateYoak, Oct 11, 2010.

  1. KateYoak

    KateYoak Registered

    Joined:
    Oct 11, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Hi everyone,

    I have just completed the development of an automated database management process and everything is working perfectly, except adduser. I am using the "Fast" method for generating the request and here is the url:

    http://174.121.39.13:2082/xml-api/c...r&cpanel_xmlapi_module=Mysql&arg-0=mytestuser

    This request fails silently, sending not meaningful data back and no user is created. I know that authentication is not a problem. What am I missing?

    The response I get is:

    <cpanelresult>
    <module>Mysql</module>
    <func>adduser</func>
    <type>event</type>
    <source>internal</source>
    <apiversion>1</apiversion>

    <data>
    <result/>
    </data>

    <event>
    <result>1</result>
    </event>

    <postevent>
    <result>1</result>
    </postevent>

    <preevent>
    <result>1</result>
    </preevent>
    </cpanelresult>
     
  2. 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
    Hi Kate,

    I'm pretty certain the reason your call is failing is because the new MySQL user's username is too long. When creating 'virtual database users' cPanel will prefix the given name based on the cPanel username. MySQL restricts usernames to a maximum of 16 characters.

    example:
    cPanel user = 'dave'
    db username passed to adduser = 'zebra'

    cPanel will attempt to create a MySQL username = 'dave_zebra'
    'dave_' + 'zebra' = 10 characters PASS
    ------
    in your example
    cPanel user = 'katetest'
    db username passed to adduser = 'cbaabc132'

    cPanel will attempt to create 'katetest_cbaabc132'
    'katetest_' + 'cbaabc132' = 18 characters FAIL

    -------------
    The one exception to database prefixing is if you're cPanel server version is 11.25.1, 11.27.x or greater AND the 'Disable DB Prefixing' has been performed in WHM >> SQL Services (while useful, this operation comes with caveats).


    As far as the silent error, that will occur with nearly all the Mysql create/delete/modify functions because they are API1.

    API1 modules usually print their output to STDOUT within a cPanel runtime process, but because we're invoking the API1 function via the XML-API, it's output will not be properly captured/buffered and error status cannot be determined appropriately.

    From a programmatic stand point, the best course of action is perform one of the MysqlFE API2 calls which list databases or database users immediately following your API1 function in order to verify that the database resource was properly created/deleted/modified.

    Best Regards,
    -DavidN
     
  3. KateYoak

    KateYoak Registered

    Joined:
    Oct 11, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Thanks! You were absolutely right. It all works now!

    Kate
     
  4. 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
    Glad it was so simple!

    Regards,
    -DavidN
     
Loading...

Share This Page