1833053 Members
2240 Online
110049 Solutions
New Discussion

compile problem

 
Matt Williamson
Occasional Advisor

compile problem

Does anyone know why I can't compile this C program I got off of the ITRC for changing passwords.

Here is C code that may be used to programmatically change a user's password on a trusted system.


/*
* When run as root and given a "username" as a first argument
* and "password" as a second argument, this program modifies
* that user's password entry with a new encrypted password.
* This is for a trusted system.
*
* Compile with "-lsec" option.
*
* Exit values are:
* 0 : Success
* 1 : Incorrect argument count
* 2 : Failure to getprpwnam(3) the password information
* 3 : Failure to putprpwnam(3) the password information
*/

#include

char get_salt_char() {
int random_number;
random_number = abs(time(0) * random(time(0)) * getpid()) % 65;
if (random_number < 26) return('a' + random_number);
if (random_number < 52) return('A' + random_number - 26);
if (random_number < 62) return('0' + random_number - 52);
if (random_number == 62) return('.');
if (random_number == 63) return('/');
if (random_number == 64) return(get_salt_char());
}

main(argc, argv) int argc; char *argv[]; {

char username[10];
char password[10];
char salt[2];
struct pr_passwd *prpwd_entry;

strcpy(username, argv[1]);
strcpy(password, argv[2]);

salt[0] = get_salt_char();
salt[1] = get_salt_char();

if (argc != 3) {
printf("Incorrect argument count: %d\n", argc-1);
printf ("Usage: %s username password \n", argv[0]); exit(1);
}

if ((prpwd_entry = getprpwnam(argv[1])) == NULL) {
printf("failed to get password information for '%s'\n", username);
printf ("Usage: %s username password \n", argv[0]); exit(2);
}

strcpy(prpwd_entry->ufld.fd_encrypt, crypt(password, salt));
if (putprpwnam(argv[1], prpwd_entry) == NULL) {
printf("failed to put password information for '%s'\n", username);
exit(3);
}

endprpwent();
return(0);
}

I am getting a "bad syntax for #include directive error. Please help. thanks MPW
Show me your certification and I'll show you mine!
11 REPLIES 11
Patrick Wallek
Honored Contributor

Re: compile problem

I'm no C expert, but in the #include section, you have nothing there listed to include.

Remember that in C the # is NOT a comment. Go back and check where you got the C program from and see if there is anything else for the include statement there.

Perhaps you could post the link you got the program from?
A. Clay Stephenson
Acclaimed Contributor

Re: compile problem

Patrick has nailed it.

You need something like

#include
#include "./myfile.h"

Multiple include files are allowed; those within < > indicate look in the standard locations (e.g. /usr/include) while those with "filename" indicate a pathname.

There may be more errors but your first task is to identify any needed header files.
If it ain't broke, I can fix that.
Matt Williamson
Occasional Advisor

Re: compile problem

Thanks. I think you are both right. I'm new to C and a little lost here. I am posting the link to the C code. I actually got it off of the ITRC site and thought it would be simple. I guess I need to go learn C and try it again. Anymore feedback you have would be helpful...otherwise thanks for your help!

http://www2.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=200000062769744
Show me your certification and I'll show you mine!
Sridhar Bhaskarla
Honored Contributor

Re: compile problem

Hi,

Try the following includes

#include
#include
#include
#include
#include
#include
#include
#include
#include

One or more may not be required but there is no harm. prot.h and crypt.h are definitely required.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Patrick Wallek
Honored Contributor

Re: compile problem

That links C code is definitely flawed as they have the #include statments there, but nothing listed to include.

I would follow Sridhar's advice and use the include statements he specifies.

I would also go down to the comments section in that document and explain the difficulties and the incorrect #include statements in the document.

In fact, I'm going to do that right now. :)
Sridhar Bhaskarla
Honored Contributor

Re: compile problem

Patrick,

Did you say you were going to compile the program?

What else could be called dedication?

I bow to thee.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Patrick Wallek
Honored Contributor

Re: compile problem

No Sridhar, I did not mean that I was going to compile the program. I really don't feel like logging into a work machine. And I don't have a home HP-UX box. :(

I meant that I was going to fill out the comments section, which I did, in the document link that was given and complain about the lack of properly formatted #include lines.
Rick Beldin
HPE Pro

Re: compile problem

I suspect that this is a problem with the ITRC submission process. Some folks who regularly submit documents speak of the trouble that they have with embedded greater than and less than symbols because the ITRC tries to interpret it as HTML. It thinkis that (let's see if this actually gets posted) is some sort of HTML directive.

The code that the submitter references has just the #includes with no header file referenced.

Necessary questions: Why? What? How? When?
Rick Beldin
HPE Pro

Re: compile problem

I suspect that this is a problem with the ITRC submission process. Some folks who regularly submit documents speak of the trouble that they have with embedded greater than and less than symbols because the ITRC tries to interpret it as HTML. It thinks that (let's see if this actually gets posted) is some sort of HTML directive.

The code that the submitter references has just the #includes with no header file referenced.

Necessary questions: Why? What? How? When?
Paddy_1
Valued Contributor

Re: compile problem

I think you'll also need
#include for the passwd directives
you will need
# for random numbers
other than that the problem seems pretty much nailed
The sufficiency of my merit is to know that my merit is NOT sufficient
Matt Williamson
Occasional Advisor

Re: compile problem

Thanks fellas! I finally got this compiled and it works great. What I did was view the "source" for the page where the code was posted. I cut the code out of the source and all the proper "includes" where there. I had to remove a few tags here and there but it compiled just fine. Thanks again for your help on this one! Matt Williamso, SHPS
Show me your certification and I'll show you mine!