set_mysql_password in postwwwacctuser fails
Hi there,
So I'm refactoring my old trusty postwwwacctuser bash script, part of which creates a database user with strong password and adds its credentials to .my.cnf -- basically for later use with the famous automysqlbackup script.
Now, instead of creating a new user, I started trying to update the default MySQL user for an account with the new password.
All excited about the new(ish) WHM API, I was trying to update the password doing it this way:
The problem is with the cpuser parameter: - if it's the newly created account user then error looks like API failure: (XID 94f5bn) The system user "db" does not control a MySQL user named "db".
- if it's root, API failure: (XID wq359f) The cPanel user "root" does not exist in the database map.
Both messages do not make any sense to me. So my questions are: - why interactive "SQL Services > Change MySQL User Password" feature works and API call doesn't? - what's wrong with the default MySQL user? should I leave it alone? why?
#!/bin/bash
CPUSER=$1
DBUSER=${CPUSER}
DBPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 16)
CNF=/home/${CPUSER}/.my.cnf
#https://confluence2.cpanel.net/display/SDK/WHM+API+1+Functions+-+set_mysql_password
whmapi1 set_mysql_password user=${DBUSER} password=${DBPASS} cpuser=${CPUSER}
The problem is with the cpuser parameter: - if it's the newly created account user then error looks like API failure: (XID 94f5bn) The system user "db" does not control a MySQL user named "db".
- if it's root, API failure: (XID wq359f) The cPanel user "root" does not exist in the database map.
Both messages do not make any sense to me. So my questions are: - why interactive "SQL Services > Change MySQL User Password" feature works and API call doesn't? - what's wrong with the default MySQL user? should I leave it alone? why?
-
Thanks Benny, Unfortunately uapi doesn't work either when I try to do things with the default user, similar error messages. Just to clarify, the original idea was to create a user with access to all account databases (before they exist!) to facilitate daily backups. We do that because it's convenient to have a pile of database dumps aside of huge account archives. At first I was auto-creating a user with access to accountname\_% and it kinda worked fine except cPanel interface didn't know how to deal with these users and I had a huge pain mass-migrating accounts. That was years ago, can I ask -- do cPanel GUI, API, migration script etc. support wildcard database names now, in 2016? Then I wanted to make use of the invisible and barely documented default MySQL user, which has access to every database already. The only issue is feeding credentials to the backup script: it can parse .my.cfg file all right but I'm not comfortable leaving account password there, and wanted to change the password to a different one. Still not terribly secure but much better. Apparently this doesn't work through API. I'm wondering if there's a way for the automysqlbackup script to pick credentials the way phpmyadmin does, is it documented anywhere? 0 -
At first I was auto-creating a user with access to accountname\_% and it kinda worked fine except cPanel interface didn't know how to deal with these users and I had a huge pain mass-migrating accounts. That was years ago, can I ask -- do cPanel GUI, API, migration script etc. support wildcard database names now, in 2016?
Hello, I don't recommend using a wildcard for database names, however you may find this script helpful for assigning ownership of a database or database username to a cPanel account: /usr/local/cpanel/bin/dbmaptool It's documented at: The dbmaptool script - Documentation - cPanel Documentation This thread may also help: Creating DB, USER, GRANTS and map to an account via SSH Thank you.0 -
Thanks Michael, I've been using dbmaptool previously in my script, just wanted to move on from it. Sorry I don't know how to express it any clearer: I don't want to create new users, I just want to modify the existing, default one. 0 -
I'm wondering if there's a way for the automysqlbackup script to pick credentials the way phpmyadmin does, is it documented anywhere?
Yes, you can make use of the single sign on functionality documented at: Guide to API Authentication - Software Development Kit - cPanel Documentation Thank you.0
Please sign in to leave a comment.
Comments
4 comments