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.

How to check for existing username

Discussion in 'General Discussion' started by jeffsims, Dec 12, 2004.

  1. jeffsims

    jeffsims Registered

    Joined:
    Dec 12, 2004
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Hi,

    I have a reseller account with limited permissions on the server. I am writing a program that automates account creation using perl and cpanel::Accounting. I am running into a problem I can't seem to find an answer for. Since I am on a shared server and a shared IP, but with limited permissions, I cannot see the other usernames that are in use on the system.

    Is there anyway using cpanel::Accounting or any other method to query if a username already exists before trying to create the account?

    This could make it very difficult and time consumming to choose a valid username.

    Any Ideas?

    Thanks

    Jeff
    ___________________________
    Don't Believe Everything You Think
     
  2. sleddog

    sleddog Active Member

    Joined:
    Jun 13, 2004
    Messages:
    44
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Labrador, Canada
    I don't know cpanel::Accounting, here's a couple of other ideas off the top of my head...

    You could check to see if /home/userName exists. You can't access other home directories but you can check to see if one exists. You would need to know the base directory for user directories on your server (is it /home or something else?).

    Or maybe try to fetch http://IPaddress/~userName with wget if browsing by username is allowed on your server.
     
  3. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    There are various options.

    One would be to check the way the wwwacct script does:
    if (getpwnam($user) || getgrnam($user)) {
    deaderror("Ouch, sorry that username is taken");
    }

    Another would be to get the directory listing of /var/cpanel/users/ which would show all usernames for the sites on the server.
     
  4. jeffsims

    jeffsims Registered

    Joined:
    Dec 12, 2004
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    do you know if the getpwnam technique will work through jailshell?
     
  5. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    This will:

    Code:
    #!/usr/bin/perl
    
    $user = "usernametocheck";
    
    if (getpwnam($user) || getgrnam($user)) {
    print "Ouch, sorry that username is taken\n";
    }
    else {
    print "Username $user is available\n";
    }
    
    Save it as check.pl or whatever you want to call it. put the username you want to check, and in shell, do
    perl path/to/check.pl
     
  6. sleddog

    sleddog Active Member

    Joined:
    Jun 13, 2004
    Messages:
    44
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Labrador, Canada
    Thanks for that squirrel. For the record, I've found a similar function in PHP: posix_getpwnam().
     
Loading...

Share This Page