Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/auth/pampass.c

    r414 r745  
    66   Copyright (C) Andrew Bartlett 2001
    77   Copyright (C) Jeremy Allison 2001
    8    
     8
    99   This program is free software; you can redistribute it and/or modify
    1010   it under the terms of the GNU General Public License as published by
    1111   the Free Software Foundation; either version 3 of the License, or
    1212   (at your option) any later version.
    13    
     13
    1414   This program is distributed in the hope that it will be useful,
    1515   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1616   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1717   GNU General Public License for more details.
    18    
     18
    1919   You should have received a copy of the GNU General Public License
    2020   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2828
    2929#include "includes.h"
     30#include "auth.h"
     31#include "../libcli/auth/pam_errors.h"
    3032
    3133#undef DBGC_CLASS
     
    6062typedef int (*smb_pam_conv_fn)(int, const struct pam_message **, struct pam_response **, void *appdata_ptr);
    6163
    62 /*
    63  *  Macros to help make life easy
    64  */
    65 #define COPY_STRING(s) (s) ? SMB_STRDUP(s) : NULL
    66 #define COPY_FSTRING(s) (s[0]) ? SMB_STRDUP(s) : NULL
     64static char *smb_pam_copy_string(const char *s)
     65{
     66        if (s == NULL) {
     67                return NULL;
     68        }
     69        return SMB_STRDUP(s);
     70}
     71
     72static char *smb_pam_copy_fstring(const char *s)
     73{
     74        if (s[0] == '\0') {
     75                return NULL;
     76        }
     77        return SMB_STRDUP(s);
     78}
    6779
    6880/*******************************************************************
     
    7688                DEBUG(dbglvl, ("smb_pam_error_handler: PAM: %s : %s\n",
    7789                                msg, pam_strerror(pamh, pam_error)));
    78                
    7990                return False;
    8091        }
     
    145156                        case PAM_PROMPT_ECHO_ON:
    146157                                reply[replies].resp_retcode = PAM_SUCCESS;
    147                                 reply[replies].resp = COPY_STRING(udp->PAM_username);
     158                                reply[replies].resp = smb_pam_copy_string(
     159                                        udp->PAM_username);
    148160                                /* PAM frees resp */
    149161                                break;
     
    151163                        case PAM_PROMPT_ECHO_OFF:
    152164                                reply[replies].resp_retcode = PAM_SUCCESS;
    153                                 reply[replies].resp = COPY_STRING(udp->PAM_password);
     165                                reply[replies].resp = smb_pam_copy_string(
     166                                        udp->PAM_password);
    154167                                /* PAM frees resp */
    155168                                break;
     
    281294        bool found;
    282295        *resp = NULL;
    283        
     296
    284297        DEBUG(10,("smb_pam_passchange_conv: starting converstation for %d messages\n", num_msg));
    285298
     
    326339                                        pwd_sub(current_reply, udp->PAM_username, udp->PAM_password, udp->PAM_newpassword);
    327340#ifdef DEBUG_PASSWORD
    328                                         DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We actualy sent: %s\n", current_reply));
     341                                        DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We actually sent: %s\n", current_reply));
    329342#endif
    330343                                        reply[replies].resp_retcode = PAM_SUCCESS;
    331                                         reply[replies].resp = COPY_FSTRING(current_reply);
     344                                        reply[replies].resp = smb_pam_copy_fstring(
     345                                                current_reply);
    332346                                        found = True;
    333347                                        break;
     
    357371                                        pwd_sub(current_reply, udp->PAM_username, udp->PAM_password, udp->PAM_newpassword);
    358372                                        reply[replies].resp_retcode = PAM_SUCCESS;
    359                                         reply[replies].resp = COPY_FSTRING(current_reply);
     373                                        reply[replies].resp = smb_pam_copy_fstring(
     374                                                current_reply);
    360375#ifdef DEBUG_PASSWORD
    361                                         DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We actualy sent: %s\n", current_reply));
     376                                        DEBUG(100,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We actually sent: %s\n", current_reply));
    362377#endif
    363378                                        found = True;
     
    366381                        }
    367382                        /* PAM frees resp */
    368                        
     383
    369384                        if (!found) {
    370385                                DEBUG(3,("smb_pam_passchange_conv: Could not find reply for PAM prompt: %s\n",msg[replies]->msg));
     
    383398                        reply[replies].resp = NULL;
    384399                        break;
    385                        
     400
    386401                default:
    387402                        /* Must be an error of some sort... */
     
    391406                }
    392407        }
    393                
     408
    394409        free_pw_chat(pw_chat);
    395410        if (reply)
     
    444459
    445460        smb_free_pam_conv(smb_pam_conv_ptr);
    446        
     461
    447462        if( pamh != NULL ) {
    448463                pam_error = pam_end(pamh, 0);
     
    463478{
    464479        int pam_error;
    465 #ifdef PAM_RHOST
    466         const char *our_rhost;
    467         char addr[INET6_ADDRSTRLEN];
    468 #endif
    469480
    470481        *pamh = (pam_handle_t *)NULL;
     
    478489        }
    479490
    480 #ifdef PAM_RHOST
    481         if (rhost == NULL) {
    482                 our_rhost = client_name(get_client_fd());
    483                 if (strequal(our_rhost,"UNKNOWN"))
    484                         our_rhost = client_addr(get_client_fd(),addr,sizeof(addr));
    485         } else {
    486                 our_rhost = rhost;
    487         }
    488 
    489         DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", our_rhost));
    490         pam_error = pam_set_item(*pamh, PAM_RHOST, our_rhost);
     491#if HAVE_PAM_RHOST
     492        DEBUG(4,("smb_pam_start: PAM: setting rhost to: %s\n", rhost));
     493        pam_error = pam_set_item(*pamh, PAM_RHOST, rhost);
    491494        if(!smb_pam_error_handler(*pamh, pam_error, "set rhost failed", 0)) {
    492495                smb_pam_end(*pamh, pconv);
     
    495498        }
    496499#endif
    497 #ifdef PAM_TTY
     500#if HAVE_PAM_TTY
    498501        DEBUG(4,("smb_pam_start: PAM: setting tty\n"));
    499502        pam_error = pam_set_item(*pamh, PAM_TTY, "samba");
     
    520523         *      auth required /lib/security/pam_pwdb.so nullok shadow audit
    521524         */
    522        
     525
    523526        DEBUG(4,("smb_pam_auth: PAM: Authenticate User: %s\n", user));
    524527        pam_error = pam_authenticate(pamh, PAM_SILENT | lp_null_passwords() ? 0 : PAM_DISALLOW_NULL_AUTHTOK);
     
    640643        int pam_error;
    641644
    642 #ifdef PAM_TTY
     645#if HAVE_PAM_TTY
    643646        DEBUG(4,("smb_internal_pam_session: PAM: tty set to: %s\n", tty));
    644647        pam_error = pam_set_item(pamh, PAM_TTY, tty);
     
    774777 */
    775778
    776 NTSTATUS smb_pam_accountcheck(const char * user)
     779NTSTATUS smb_pam_accountcheck(const char *user, const char *rhost)
    777780{
    778781        NTSTATUS nt_status = NT_STATUS_ACCOUNT_DISABLED;
     
    788791                return NT_STATUS_NO_MEMORY;
    789792
    790         if (!smb_pam_start(&pamh, user, NULL, pconv))
     793        if (!smb_pam_start(&pamh, user, rhost, pconv))
    791794                return NT_STATUS_ACCOUNT_DISABLED;
    792795
     
    802805 */
    803806
    804 NTSTATUS smb_pam_passcheck(const char * user, const char * password)
     807NTSTATUS smb_pam_passcheck(const char * user, const char * rhost,
     808                           const char * password)
    805809{
    806810        pam_handle_t *pamh = NULL;
     
    817821                return NT_STATUS_LOGON_FAILURE;
    818822
    819         if (!smb_pam_start(&pamh, user, NULL, pconv))
     823        if (!smb_pam_start(&pamh, user, rhost, pconv))
    820824                return NT_STATUS_LOGON_FAILURE;
    821825
     
    846850 */
    847851
    848 bool smb_pam_passchange(const char * user, const char * oldpassword, const char * newpassword)
     852bool smb_pam_passchange(const char *user, const char *rhost,
     853                        const char *oldpassword, const char *newpassword)
    849854{
    850855        /* Appropriate quantities of root should be obtained BEFORE calling this function */
     
    855860                return False;
    856861
    857         if(!smb_pam_start(&pamh, user, NULL, pconv))
     862        if(!smb_pam_start(&pamh, user, rhost, pconv))
    858863                return False;
    859864
     
    870875
    871876/* If PAM not used, no PAM restrictions on accounts. */
    872 NTSTATUS smb_pam_accountcheck(const char * user)
     877NTSTATUS smb_pam_accountcheck(const char *user, const char *rhost)
    873878{
    874879        return NT_STATUS_OK;
Note: See TracChangeset for help on using the changeset viewer.