Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Unix - getpwuid & getprpwuid

Posted on 1999-01-18
3
Medium Priority
?
395 Views
Last Modified: 2010-08-05
I need a c-program that will detect if the Unix System is trusted host or not and use the appropriate function
getpwuid - none trusted host
getprpwuid - trusted host

How do I do this?

If you know the answer and have sample code, please send it to me.  

I'm creating a cgi script that will authenticate users on a Web Site using the System password DB. This includes encrypting the password using crypt & the SALT and then comparing it to the encrypted System User password.  If they match, your logged in.
*** If you have already done this, please let me know and I'll reward you 500 points. ***

Thanks.
0
Comment
Question by:lerous
3 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1258173
getpwuid's purpose is to retrieve information about known users on a UNIX system, it has nocthig to do with trusted hosts.
Could you please explain your first section?
Where did you find getprpwuid?
0
 
LVL 3

Accepted Solution

by:
mliberi earned 400 total points
ID: 1258174
The following code is not a full CGI, but contains all you need to validate a user password

int userok(char *username; char *password)
/* validate username password */
/* if OK return 0  */
{
    char *p;
    struct passwd *passwd;
#ifdef AIX
  struct userpw *userpw; /* AIX stores password in /etc/security/passwd */
#endif

 if (!(passwd=getpwnam(username))) /* use getpwuid if you have user uid */
   return 1;                                      /* user not present in /etc/passwd */

#ifdef AIX
  if (!(userpw=getuserpw(passwd->pw_name)))
    return 2;
  p=userpw->upw_passwd;
#else
  p=passwd->pw_passwd;
#endif
  if (strcmp(crypt(password,p),p))
    return 3;   /* password mismatch */
  return 0;     /* user validated */
}
0
 

Author Comment

by:lerous
ID: 1258175
If you have an Unix Server, simply type "man getprpwuid" and if you read the documentation, it specifies all functions that are designed for trusted host systems where normally you would use getpwuid.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question