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.

Load DBI in API2 Module

Discussion in 'cPanel Developers' started by cyon, Nov 2, 2010.

  1. cyon

    cyon Well-Known Member
    PartnerNOC

    Joined:
    Jan 15, 2003
    Messages:
    320
    Likes Received:
    0
    Trophy Points:
    16
    Similar to this thread I'm looking for a method to define my own cPanel API2 Module. I need access to the MySQL database to do some changes on mysql user privileges.
    The problem at the moment is, that the include path (@INC) does not include the DBI.pm file.

    This is the current include path.
    Code:
    /usr/local/cpanel
    /usr/local/cpanel/perl
    /usr/local/cpanel/Cpanel/CPAN/overload/__Digest
    /usr/local/cpanel/build-tools/stubs
    /usr/local/cpanel/perl/C214
    /usr/local/cpanel/perl/5.6.2/i686-linux
    /usr/local/cpanel/perl/5.6.2/i686-linux
    /usr/local/cpanel/perl/5.6.2
    /usr/local/cpanel/perl/site_perl/5.6.2/i686-linux
    /usr/local/cpanel/perl/site_perl/5.6.2/i686-linux
    /usr/local/cpanel/perl/site_perl/5.6.2
    /usr/local/cpanel/perl/site_perl/5.6.2/i686-linux
    /usr/local/cpanel/perl/site_perl/5.6.2
    /usr/local/cpanel/perl/site_perl
    But the DBI.pm is located at:
    Code:
    /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/
    The current perl version is:
    Code:
    perl, v5.8.8 built for i686-linux
    Does someone knows how to deal with this issue.
     
  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 cyon,

    I don't know that much about the Perl include paths and DBI via API2 custom modules. I'll need to look into that and get back with you.

    Hmm, I'm not sure exact what you need to do, but have you tried to include cPanel's Mysql or MysqlFE modules? These modules provide the API1 and API2 functions that cPanel uses. Is there some specific functionality that is not working for you in those modules?

    I highly recommend using the APIs if at all possible. As of cPanel 11.28, we use DB Mapping, a core addition to the cPanel code base. It's an abstraction layer that negotiates other cPanel related data. If you use the APIs that stuff is handled for you.

    If you make your module that alters Mysql data (privileges, resources, etc), cPanel will not receive these changes (if you simply use DBI to connect and alter). This may be your intention, but I wouldn't think so. You'll need to make sure your cPanel users' map file is updated correctly, along with some cPanel system files.

    Regards,
    -DavidN

    PS. You can get almost all of the technical information you need about DB Mapping from the white paper found here, http://www.cpanel.net/DBMappingWhitePaper_r12.pdf
     
  3. 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
    Due to the way that cpanel is compiled and MySQL licensing, we cannot include DBI in our compiled perl installation.

    If you could give me a better idea of what you are trying to achieve, I may be able to help you with some solutions (PM is acceptable)
     
  4. cyon

    cyon Well-Known Member
    PartnerNOC

    Joined:
    Jan 15, 2003
    Messages:
    320
    Likes Received:
    0
    Trophy Points:
    16
    I try to achieve to set a new password for mysql. Currently we have mysql configured to use old_passwords = 1. This mean, if you try to generate a password with the mysql-command PASSWORD it will generate always a old password hash. Due a upcoming migration of old mysql password to new ones (41 characters) we are looking for a method to save mysql password with a new hash. cPanel has the config option 'usemysqloldpass' (Cpanel/Mysql.pm) to use old password hashing. If you disable this, this will yield in using the PASSWORD() MySQL command for hashing. As described above, this will generate a old hash due the global Mysql-Setting 'old_passwords'. If we would change the global setting of Mysql, some of our customer webpages will stop working due incompatibilities and usage of the mysql PASSWORD command for user credentials in their application.
    I'm looking to by-pass this limitation by creating my own module to set a new password hash for a mysql user. This was quiet easy making a copy of Cpanel/Mysql.pm and and editing the passwduser to save the MySQL Password as an 41 characters hash.
    I've seen, that the API1 call Mysql::adduser is triggered through bin/mysqladmin. But I couldn't find out how this file includes all the necessary libraries. If I include MySQL.pm directly, it will yield with the same error (current version 11.27) by missing DBI.pm somewhere in the include path.
    I thought it's easy to copy/paste the existing source and add API2 method to the copy. Maybe this won't work due limitation on the included perl libraries available at the cPanel/WHM server level.
    I only have to do an MySQL call. It could be, that their is a easy method to do this?

    Thx DavidN for the Whitepaper. I will take a look into. Most server currently running on 11.27 and this feature is only available on 11.28.
     
  5. cyon

    cyon Well-Known Member
    PartnerNOC

    Joined:
    Jan 15, 2003
    Messages:
    320
    Likes Received:
    0
    Trophy Points:
    16
    I found the reason why this happened. If I understand the cPanel Server (cpsrvd) logic right, a call API1 call of Mysql::adduser will trigger a execution of bin/mysqladmin. If mysqladmin is started as a separate perl process, it will inherit the global path settings (which I was looking for) and not the path settings from the cpsrvd-Perl deamon. This was the "black magic", that I was looking for. Finally a stack trace helped me finding the reason why.
    To by pass my problem, I will invoke a perl process from my API2 script that is doing all the MySQL magic. IMHO it's not possible to set the include path correct within my module because some libraries are have already been loaded and this will cause some versioning problems. Maybe if a add my additional paths at the end of the include path.
     
  6. 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
    cyon,

    I'm glad to hear that you have gotten the information you needed. Sorry I could be more help in my earlier post.

    As for the actual functionality that you wish to perform, I thought cPanel's treatment of old_password was more dynamic than that, but it's been awhile since I've played with that.

    I'm going to hit up my colleagues for their thoughts and if it yields anything of value, I'll post back.

    Regards,
    -DavidN
     
  7. cyon

    cyon Well-Known Member
    PartnerNOC

    Joined:
    Jan 15, 2003
    Messages:
    320
    Likes Received:
    0
    Trophy Points:
    16
    No problem about your assistance. If you'd like, we can provide the two line changes of the Mysql.pm file to bypass the global Mysql setting of old password.

    Regards Dominic
     
Loading...

Share This Page