/ [pam-modules] / trunk / pam_sql / pam_sql.c
To checkout: svn checkout http://svn.gnu.org.ua/sources/pam-modules/trunk/pam_sql/pam_sql.c
Puszcza

Diff of /trunk/pam_sql/pam_sql.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 62 by gray, Mon Aug 27 22:38:35 2007 UTC revision 63 by gray, Thu Mar 13 13:53:32 2008 UTC
# Line 1  Line 1 
1  /* This file is part of pam-modules.  /* This file is part of pam-modules.
2     Copyright (C) 2005, 2006, 2007 Sergey Poznyakoff     Copyright (C) 2005, 2006, 2007, 2008 Sergey Poznyakoff
3    
4     This program is free software; you can redistribute it and/or modify it     This program is free software; you can redistribute it and/or modify it
5     under the terms of the GNU General Public License as published by the     under the terms of the GNU General Public License as published by the
# Line 14  Line 14 
14     You should have received a copy of the GNU General Public License along     You should have received a copy of the GNU General Public License along
15     with this program.  If not, see <http://www.gnu.org/licenses/>. */     with this program.  If not, see <http://www.gnu.org/licenses/>. */
16    
17  #if defined(HAVE_CONFIG_H)  #include <graypam.h>
 # include <config.h>  
 #endif  
 #ifdef HAVE__PAM_ACONF_H  
 # include <security/_pam_aconf.h>  
 #endif  
 #include <security/pam_modules.h>  
 #include <stdio.h>  
 #include <stdlib.h>  
 #include <stdarg.h>  
 #include <string.h>  
 #include <unistd.h>  
 #include <ctype.h>  
 #include <syslog.h>  
 #include <errno.h>  
18  #if defined(HAVE_CRYPT_H)  #if defined(HAVE_CRYPT_H)
19  # include <crypt.h>  # include <crypt.h>
20    #else
21    extern char *crypt(const char *, const char *);
22  #endif  #endif
23    
24  /* indicate the following groups are defined */  /* indicate the following groups are defined */
25  #define PAM_SM_AUTH  #define PAM_SM_AUTH
26    
 #include <common.c>  
   
27  #define CHKVAR(v) \  #define CHKVAR(v) \
28          if (!(v)) {                                                        \          if (!(v)) {                                                        \
29                  _pam_log(LOG_ERR, "%s: %s not defined", config_file, #v);  \                  _pam_log(LOG_ERR, "%s: %s not defined", config_file, #v);  \
# Line 47  Line 33 
33    
34  static int verify_user_pass(const char *username, const char *password);  static int verify_user_pass(const char *username, const char *password);
35    
36  #define CNTL_DEBUG        0x0001  #define CNTL_AUTHTOK      0x0010
 #define CNTL_AUDIT        0x0002  
 #define CNTL_AUTHTOK      0x0004  
   
 #define CNTL_SET_DEBUG_LEV(cntl,n) (cntl |= ((n)<<16))  
 #define CNTL_DEBUG_LEV() (cntl_flags>>16)  
   
 #define DEBUG(m,c) if (CNTL_DEBUG_LEV()>=(m)) _pam_debug c  
 #define AUDIT(c) if (cntl_flags&CNTL_AUDIT) _pam_debug c  
37    
38  static int cntl_flags;  static int cntl_flags;
39  char *config_file = SYSCONFDIR "/pam_sql.conf";  char *config_file = SYSCONFDIR "/pam_sql.conf";
# Line 65  Line 43 
43  {  {
44          int ctrl=0;          int ctrl=0;
45    
46            gray_log_init(0, MODULE_NAME, LOG_AUTHPRIV);
47    
48          /* step through arguments */          /* step through arguments */
49          for (ctrl=0; argc-- > 0; ++argv) {          for (ctrl=0; argc-- > 0; ++argv) {
50    
# Line 93  Line 73 
73  }  }
74    
75    
 /* FIXME: Duplicated in pam_fshadow */  
 static int  
 converse(pam_handle_t *pamh,  
          int nargs,  
          struct pam_message **message,  
          struct pam_response **response)  
 {  
         int retval;  
         struct pam_conv *conv;  
   
         DEBUG(100,("enter converse"));  
   
         retval = pam_get_item(pamh, PAM_CONV, (const void **) &conv);  
         DEBUG(10,("pam_get_item(PAM_CONV): %d", retval));  
         if (retval == PAM_SUCCESS) {  
   
                 retval = conv->conv(nargs,  
                                     (const struct pam_message **) message,  
                                     response,  
                                     conv->appdata_ptr);  
                   
                 DEBUG(10, ("app conversation returned %d", retval));  
   
                 if (retval != PAM_SUCCESS) {  
                         _pam_log(LOG_ERR,  
                                  "conversation failure [%s]",  
                                  pam_strerror(pamh, retval));  
                 }  
         } else if (retval != PAM_CONV_AGAIN) {  
                 _pam_log(LOG_ERR,  
                          "couldn't obtain coversation function: %s",  
                          pam_strerror(pamh, retval));  
         }  
   
         DEBUG(100,("exit converse: %d", retval));  
   
         return retval;          /* propagate error status */  
 }  
   
76  static int  static int
77  _pam_get_password(pam_handle_t *pamh, char **password, const char *prompt)  _pam_get_password(pam_handle_t *pamh, char **password, const char *prompt)
78  {  {
# Line 177  Line 118 
118          /* run conversation */          /* run conversation */
119          resp = NULL;          resp = NULL;
120          token = NULL;          token = NULL;
121          retval = converse(pamh, i, pmsg, &resp);          retval = gray_converse(pamh, i, pmsg, &resp);
122    
123          if (resp != NULL) {          if (resp != NULL) {
124                  if (retval == PAM_SUCCESS) {    /* a good conversation */                  if (retval == PAM_SUCCESS) {    /* a good conversation */
# Line 201  Line 142 
142                   */                   */
143                  retval = pam_set_data(pamh, "password",                  retval = pam_set_data(pamh, "password",
144                                        (void *)token,                                        (void *)token,
145                                        _cleanup_string);                                        gray_cleanup_string);
146                  if (retval != PAM_SUCCESS) {                  if (retval != PAM_SUCCESS) {
147                          _pam_log(LOG_CRIT,                          _pam_log(LOG_CRIT,
148                                   "can't keep password: %s",                                   "can't keep password: %s",
149                                   pam_strerror(pamh, retval));                                   pam_strerror(pamh, retval));
150                          _pam_delete(token);                          gray_pam_delete(token);
151                  } else {                  } else {
152                          *password = token;                          *password = token;
153                          token = NULL;   /* break link to password */                          token = NULL;   /* break link to password */

Legend:
Removed from v.62  
changed lines
  Added in v.63

Send suggestions and bug reports to Sergey Poznyakoff
ViewVC Help
Powered by ViewVC 1.1.20