PAM makes users no longer crazy

Source: Internet
Author: User
Article Title: PAM makes users no longer crazy. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The Pluggable Authentication Module (PAM) is a user verification mechanism on most Linux systems. PAM is also an abstraction layer that allows applications to verify users without understanding the details of the underlying system. PAM is modular and modules can be added and deleted as needed.
  
Simply put, PAM allows applications to verify users or processes using different underlying methods that are transparent to applications. The application only needs to know the pam api, and can use any module added to the PAM without any modifications to the application. For example, both password verification and smart card verification can be performed in the same way as PAM.
  
PAM is installed in multiple Linux distributions by default, including RedHat, Mandrake, and my favorite Gentoo. If it is not installed in your system, you can also obtain PAM in the form of source code or binary code. You can get it from the download website of your Linux release, or download it from the PAM homepage.
  
Easy Verification
  
The first thing to do is to call pam_start to initialize the PAM system. To clear resources allocated by the PAM system, call pam_end. To perform simple verification, you need to call pam_authenticate. To verify that the user has access permissions, you need to call pam_accnt_mgmt. Remember, these are the most basic systems that require far more. A complete example of basic verification is as follows:
  
# Include
# Include
# Include
  
Structpam_convconvstn = {
Misc_conv,/* built in conversation function */
NULL
};
  
Int Authenticate (const char * uname ){
Pam_handle_t * hPAM = NULL;/* Handle for use with all PAM functions */
Intrslt = 0;
/* The first parameter is the service name used in pam. conf */
Rslt = pam_start ("pamdemo", uname, & convstn, & hPAM );
  
If (rslt! = PAM_SUCCESS ){
Return-1;
}
/* Authenticate the user */
Rslt = pam_authenticate (hPAM, 0 );
  
If (rslt! = PAM_SUCCESS ){
Return-1;
}
/* Does the user have access */
Rslt = pam_acct_mgmt (hPAM, 0 );
  
If (rslt! = PAM_SUCCESS ){
Return-1;
}
  
If (pam_end (hPAM, rslt )! = PAM_SUCCESS ){
Printf ("PAM cleanup failed .");
}
  
Return 0;
}
  
To run the above Code correctly, you need to add the following command to the/etc/pam. conf file:
  
Pamdemo auth required/usr/lib/security/pam_unix_auth.so
Pamdemo account required/usr/lib/security/pam_unix_acct.so
  
An important concept is the dialog function, which prompts users to correctly input and obtain the input content. All PAM applications must have conversational functions. In pam_misc.h, there is a dialog function called misc_conv, which can be used by applications without the need to implement it by themselves. This function can be used well in most console applications, but when you need to verify the X-Windows application, you will need to implement your own function. This function must have the following signatures.
  
Int (* conv) (intnum_msg, const structpam_message ** msgm,
Structpam_response ** response, void * appdata_ptr)
  
This function is assigned to pam_conv: conv member. Then conv member is used as the callback of the PAM system ).
  
PAM provides a very complete but relatively simple API for verification in Linux. The traditional method for adding verification functionality to an application requires writing your verification code into a specific verification method. If the verification method changes, you must re-compile the verification code for your application. With PAM, you can change the underlying verification method without affecting your system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.