Solved

Unix - getpwuid & getprpwuid

Posted on 1999-01-18
3
366 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 200 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now