c - Different access levels with PAM -
Currently I have a graphical application that has two levels of access, operator and administrator. Login and authentication are all homemade and I want to switch applications using PAM instead. I'm not sure what is the right way to do this.
Correct me if I am wrong, but it looks like PAM boils down to "yes" or "no" to check - yes you can use this service, or you do not There is no provision based on the various levels of admission in which the user is logging on. I should be able to tell who is the operator and who is the administrator, though, and it is possible that I probably want to be able to do this through PAM. / P>
So my idea is that I have two services with two different configurations , /etc/pam.d/pamdemo
and < Code> Administrator /etc/pam.d/pamdemo-admin My application will then try to authenticate before pamdemo-admin
, and if it is unsuccessful then pamdemo
. If both fail, then admission is denied. Am I on the right track or am I completely off the rail?
Here are some sample C code that I have written as proof of concept. When I login I do not want to ask the user twice for his identification. I've got it, so it remembers the username on two pam_start ()
calls, but I do not have to do the same caching from the application level to pam_get_item (PAM_AUTHTOK)
Could have access to the password and was trying to do that I realized that there could be a completely different way to do this. Regardless of this application, the authentication method for any purpose, username / password or Kerberos ticket or fingerprint, whatever you want.
pam_handle_t * try_login (const char * service, int * pass) {static four * user name = faucet; Struct pam_conv pam_conversation = {conversion, NULL}; Pam_handle_t * Palm; * Retval = pam_start (service, user name, and pam_conversation, and pamh); If (* retval == PAM_SUCCESS) * retval = pam_authenticate (pamh, 0); If (* revolve == PAM_SUCCESS) * retal = pam_acct_mgmt (pm, 0); If (* retval == PAM_SUCCESS) * retval = pam_open_session (pam, 0); If (username == NULL) {if (pam_get_item (pamh, PAM_USER, (const zero) and user name) == PAM_SUCCESS) {username = strdup (username); }} If (* retval! = PAM_SUCCESS) {fprintf (stderr, "% s:% s \ n", service, pam_strerror (pamh, * retval)); Pam_end (Pum, * Retal); Palm = null; } Return Pum; } Int main (zero) {pam_handle_t * pamh = NULL; Intraverted; Const char * service, * Username; If (! Pamh) pamh = try_login ("pamedo-admin", and retal); If (! Pamh) pamh = try_login ("Pamdomo", and retal); If (! Pamh) {fprintf (stderr, "Access denied. \ N"); Return 1; } Pam_get_item (pamh, PAM_SERVICE, (denote zero **) and service); Pam_get_item (Palm, PAM_USER, (Cost Worth **) and Username); Printf ("% s is logged as% s. \ N", service, user name); Pam_close_session (POM, 0); Pam_end (Pum, Retal); Return 0; }
This password repeats "password:" prompt written in this demo program. I do not want to ask this twice!
I believe this may be the right way to do this:
- Set up the "PadMom" service for account, authentication and session functions.
-
The "pamdemo-admin" service only accounts (and possibly session) functions no authentication.
- When entering, first make them "PamDOMO" (to make sure they are who they are) - if it fails, then remove them. Once certified, put them on the "pendemo-admin" checks to see if they are allowed to be administrators - if they are, this test is successful, if they If not, then it is not so. Since this check does not have certification modules, they are not prompted for a password again.
Comments
Post a Comment