Results 1 to 12 of 12

Thread: I need help with C!

  1. #1
    Senior Member
    Join Date
    Sep 2008
    Posts
    85
    Credits
    295
    Mentioned
    0 Post(s)

    Wink I need help with C!

    Okay, so in AIX, there are various subroutines that is built in to the OS. The subroutine is I want to use is passwdpolicy(). So I want to construct a C program that will be able to pass credentials into the program and thusly into the subroutine.

    Here is the subroutine:

    #include <pwdpolicy.h>
    int passwdpolicy (const char *name, int type, const char *old_password,
    const char *new_password, time64_t last_update);


    Now. Let's say I want to test the password for the user testy, with an old password of a1s2d3f4 and a new password of q1w2e3r4.

    Here is the link to the subroutine, via IBM: http://publib.boulder.ibm.com/infoce...sswdpolicy.htm

    I don't know much about C, so everytime I try to compile this, I get syntax errors because I have no idea how to define it, call it, etc.

    Anyone know C can help me?

  2. #2
    Mega Bore Atomic's Avatar
    Join Date
    Sep 2008
    Location
    los Estados Unidos de América
    Posts
    3,267
    Credits
    3,110
    Mentioned
    0 Post(s)

    Default

    old_password.equals(new_password)

    Oh wait that's java. Maybe C has something similar.

  3. #3
    Senior Member
    Join Date
    Sep 2008
    Posts
    85
    Credits
    295
    Mentioned
    0 Post(s)

    Default

    Oh it's way different unfortunately

  4. #4
    Mega Bore Atomic's Avatar
    Join Date
    Sep 2008
    Location
    los Estados Unidos de América
    Posts
    3,267
    Credits
    3,110
    Mentioned
    0 Post(s)

    Default

    In java it would actually be oldPassword for the naming. The equals is just a way to test if something is true or false. I guess that's what you're looking for. If the old password is the same as new password then what's the point of changing right...

    I do know that some things in java are the same as in C and C++ or so I'm told. I tried C and C++ as well as many other languages. I didn't get much past Hello World...

  5. #5
    Mega Bore Atomic's Avatar
    Join Date
    Sep 2008
    Location
    los Estados Unidos de América
    Posts
    3,267
    Credits
    3,110
    Mentioned
    0 Post(s)

    Default

    This is the first thing I could find on testing strings in c.

    http://markmail.org/message/iorxka6mu5h3cmhj

  6. #6
    Senior Member
    Join Date
    Sep 2008
    Posts
    10
    Credits
    192
    Mentioned
    0 Post(s)

    Default

    Quote Originally Posted by sudo View Post
    Okay, so in AIX, there are various subroutines that is built in to the OS. The subroutine is I want to use is passwdpolicy(). So I want to construct a C program that will be able to pass credentials into the program and thusly into the subroutine.

    Here is the subroutine:

    #include <pwdpolicy.h>
    int passwdpolicy (const char *name, int type, const char *old_password,
    const char *new_password, time64_t last_update);


    Now. Let's say I want to test the password for the user testy, with an old password of a1s2d3f4 and a new password of q1w2e3r4.

    Here is the link to the subroutine, via IBM: http://publib.boulder.ibm.com/infoce...sswdpolicy.htm

    I don't know much about C, so everytime I try to compile this, I get syntax errors because I have no idea how to define it, call it, etc.

    Anyone know C can help me?
    for what exactly are you trying to do this?

  7. #7
    Senior Member
    Join Date
    Sep 2008
    Posts
    810
    Credits
    799
    Mentioned
    0 Post(s)

    Default

    Quote Originally Posted by sudo View Post
    Okay, so in AIX, there are various subroutines that is built in to the OS. The subroutine is I want to use is passwdpolicy(). So I want to construct a C program that will be able to pass credentials into the program and thusly into the subroutine.

    Here is the subroutine:

    #include <pwdpolicy.h>
    int passwdpolicy (const char *name, int type, const char *old_password,
    const char *new_password, time64_t last_update);


    Now. Let's say I want to test the password for the user testy, with an old password of a1s2d3f4 and a new password of q1w2e3r4.

    Here is the link to the subroutine, via IBM: http://publib.boulder.ibm.com/infoce...sswdpolicy.htm

    I don't know much about C, so everytime I try to compile this, I get syntax errors because I have no idea how to define it, call it, etc.

    Anyone know C can help me?
    I'm not familiar with the function but based on the description it looks like if you just define an int like:

    int x = passwdpolicy ("testy", PWP_USERNAME, "oldpass", "newpass", 0);

    It'll return if it's a valid password based on that user's policy (0 is the ideal return value). But I mean I really have no idea I've never dealt with this in C

  8. #8
    Senior Member
    Join Date
    Sep 2008
    Posts
    85
    Credits
    295
    Mentioned
    0 Post(s)

    Default

    Quote Originally Posted by jared View Post
    I'm not familiar with the function but based on the description it looks like if you just define an int like:

    int x = passwdpolicy ("testy", PWP_USERNAME, "oldpass", "newpass", 0);

    It'll return if it's a valid password based on that user's policy (0 is the ideal return value). But I mean I really have no idea I've never dealt with this in C
    Do I need to echo the variable then?

    Like

    printf("The return value is", x);

    ??

    Quote Originally Posted by Supersonic View Post
    for what exactly are you trying to do this?
    I'm building a script to have non-users have limited sudo access to a script to change their passwords across 400+ servers. I'm writing a script that checks for password strength.

  9. #9
    Senior Member
    Join Date
    Sep 2008
    Posts
    810
    Credits
    799
    Mentioned
    0 Post(s)

    Default

    I don't know why you'd want to echo it, just do whatever you want it to do depending upon the return value, like:

    if(passwdpolicy ("testy", PWP_USERNAME, "oldpass", "newpass", 0) == 0) {
    //allow user to change password to new password
    }
    else {
    //invalid password change, etc...
    }

  10. #10
    Mega Bore Atomic's Avatar
    Join Date
    Sep 2008
    Location
    los Estados Unidos de América
    Posts
    3,267
    Credits
    3,110
    Mentioned
    0 Post(s)

    Default

    If you were doing that then wouldn't you need to check each character for conditions pw.length hasCapitol hasNumbers hasLowercase if all are true re enter pw else or wait the else would be on each conditional so if it fails length print PW Failed must be x length then print rules.

    You've probably already figured out what you want though.

  11. #11
    Senior Member
    Join Date
    Sep 2008
    Posts
    85
    Credits
    295
    Mentioned
    0 Post(s)

    Default

    Quote Originally Posted by Atomic View Post
    If you were doing that then wouldn't you need to check each character for conditions pw.length hasCapitol hasNumbers hasLowercase if all are true re enter pw else or wait the else would be on each conditional so if it fails length print PW Failed must be x length then print rules.

    You've probably already figured out what you want though.
    I'm already doing that in ksh. I'm only using the C to test the password history, to make sure they're not using the same password over and over again.

  12. #12
    Senior Member
    Join Date
    Sep 2008
    Posts
    85
    Credits
    295
    Mentioned
    0 Post(s)

    Default

    Thanks for all your help guys, it worked perfectly. My shell script passes arguments into the C program, which spits out a return code which determines the course of action in the rest of my shell script. It's beautiful!

    I would post the code but I can't because of NDA's.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •