2001-04-10 22:10:38 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2001-04-10 22:10:38 +04:00
PAM Password checking
Copyright ( C ) Andrew Tridgell 1992 - 2001
Copyright ( C ) John H Terpsta 1999 - 2001
2001-04-13 08:27:50 +04:00
Copyright ( C ) Andrew Bartlett 2001
2001-04-23 08:15:35 +04:00
Copyright ( C ) Jeremy Allison 2001
2001-04-10 22:10:38 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
/*
* This module provides PAM based functions for validation of
* username / password pairs , account managment , session and access control .
* Note : SMB password checking is done in smbpass . c
*/
# include "includes.h"
2002-07-15 14:35:28 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_AUTH
2001-04-10 22:10:38 +04:00
# ifdef WITH_PAM
/*******************************************************************
* Handle PAM authentication
* - Access , Authentication , Session , Password
* Note : See PAM Documentation and refer to local system PAM implementation
* which determines what actions / limitations / allowances become affected .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <security/pam_appl.h>
/*
2001-05-01 01:05:58 +04:00
* Structure used to communicate between the conversation function
* and the server_login / change password functions .
2001-04-10 22:10:38 +04:00
*/
2001-05-01 01:05:58 +04:00
struct smb_pam_userdata {
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
const char * PAM_username ;
const char * PAM_password ;
const char * PAM_newpassword ;
2001-05-01 01:05:58 +04:00
} ;
typedef int ( * smb_pam_conv_fn ) ( int , const struct pam_message * * , struct pam_response * * , void * appdata_ptr ) ;
2001-04-10 22:10:38 +04:00
/*
* Macros to help make life easy
*/
# define COPY_STRING(s) (s) ? strdup(s) : NULL
2001-05-01 01:05:58 +04:00
/*******************************************************************
PAM error handler .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-04-23 08:15:35 +04:00
static BOOL smb_pam_error_handler ( pam_handle_t * pamh , int pam_error , char * msg , int dbglvl )
2001-04-10 22:10:38 +04:00
{
2001-04-22 11:20:24 +04:00
if ( pam_error ! = PAM_SUCCESS ) {
2001-05-01 01:05:58 +04:00
DEBUG ( dbglvl , ( " smb_pam_error_handler: PAM: %s : %s \n " ,
msg , pam_strerror ( pamh , pam_error ) ) ) ;
2001-06-26 00:44:04 +04:00
2001-04-10 22:10:38 +04:00
return False ;
}
return True ;
}
2001-05-01 01:05:58 +04:00
/*******************************************************************
This function is a sanity check , to make sure that we NEVER report
failure as sucess .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static BOOL smb_pam_nt_status_error_handler ( pam_handle_t * pamh , int pam_error ,
2001-09-04 11:13:01 +04:00
char * msg , int dbglvl ,
NTSTATUS * nt_status )
2001-05-01 01:05:58 +04:00
{
2002-02-06 02:45:29 +03:00
* nt_status = pam_to_nt_status ( pam_error ) ;
2001-05-01 01:05:58 +04:00
if ( smb_pam_error_handler ( pamh , pam_error , msg , dbglvl ) )
return True ;
2001-09-04 11:13:01 +04:00
if ( NT_STATUS_IS_OK ( * nt_status ) ) {
2001-05-01 01:05:58 +04:00
/* Complain LOUDLY */
DEBUG ( 0 , ( " smb_pam_nt_status_error_handler: PAM: BUG: PAM and NT_STATUS \
error MISMATCH , forcing to NT_STATUS_LOGON_FAILURE " ));
* nt_status = NT_STATUS_LOGON_FAILURE ;
}
return False ;
}
2001-04-10 22:10:38 +04:00
/*
* PAM conversation function
* Here we assume ( for now , at least ) that echo on means login name , and
* echo off means password .
*/
2001-04-23 08:15:35 +04:00
static int smb_pam_conv ( int num_msg ,
2001-04-10 22:10:38 +04:00
const struct pam_message * * msg ,
struct pam_response * * resp ,
void * appdata_ptr )
{
int replies = 0 ;
struct pam_response * reply = NULL ;
2001-05-01 01:05:58 +04:00
struct smb_pam_userdata * udp = ( struct smb_pam_userdata * ) appdata_ptr ;
* resp = NULL ;
2001-04-10 22:10:38 +04:00
2001-05-03 03:32:09 +04:00
if ( num_msg < = 0 )
return PAM_CONV_ERR ;
2001-05-01 22:25:20 +04:00
/*
* Apparantly HPUX has a buggy PAM that doesn ' t support the
* appdata_ptr . Fail if this is the case . JRA .
*/
if ( udp = = NULL ) {
DEBUG ( 0 , ( " smb_pam_conv: PAM on this system is broken - appdata_ptr == NULL ! \n " ) ) ;
return PAM_CONV_ERR ;
}
2001-04-10 22:10:38 +04:00
reply = malloc ( sizeof ( struct pam_response ) * num_msg ) ;
if ( ! reply )
return PAM_CONV_ERR ;
2001-06-26 00:44:04 +04:00
memset ( reply , ' \0 ' , sizeof ( struct pam_response ) * num_msg ) ;
2001-04-22 11:20:24 +04:00
for ( replies = 0 ; replies < num_msg ; replies + + ) {
switch ( msg [ replies ] - > msg_style ) {
2001-04-10 22:10:38 +04:00
case PAM_PROMPT_ECHO_ON :
reply [ replies ] . resp_retcode = PAM_SUCCESS ;
2001-05-01 01:05:58 +04:00
reply [ replies ] . resp = COPY_STRING ( udp - > PAM_username ) ;
2001-04-10 22:10:38 +04:00
/* PAM frees resp */
break ;
case PAM_PROMPT_ECHO_OFF :
reply [ replies ] . resp_retcode = PAM_SUCCESS ;
2001-05-01 01:05:58 +04:00
reply [ replies ] . resp = COPY_STRING ( udp - > PAM_password ) ;
2001-04-10 22:10:38 +04:00
/* PAM frees resp */
break ;
case PAM_TEXT_INFO :
/* fall through */
case PAM_ERROR_MSG :
/* ignore it... */
reply [ replies ] . resp_retcode = PAM_SUCCESS ;
reply [ replies ] . resp = NULL ;
break ;
default :
/* Must be an error of some sort... */
2001-09-17 09:04:17 +04:00
SAFE_FREE ( reply ) ;
2001-04-10 22:10:38 +04:00
return PAM_CONV_ERR ;
}
}
if ( reply )
* resp = reply ;
return PAM_SUCCESS ;
}
2001-05-01 01:05:58 +04:00
/*
* PAM password change conversation function
* Here we assume ( for now , at least ) that echo on means login name , and
* echo off means password .
*/
2001-06-26 00:44:04 +04:00
static void special_char_sub ( char * buf )
{
all_string_sub ( buf , " \\ n " , " " , 0 ) ;
all_string_sub ( buf , " \\ r " , " " , 0 ) ;
all_string_sub ( buf , " \\ s " , " " , 0 ) ;
all_string_sub ( buf , " \\ t " , " \t " , 0 ) ;
}
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
static void pwd_sub ( char * buf , const char * username , const char * oldpass , const char * newpass )
2001-06-26 00:44:04 +04:00
{
2002-07-15 14:35:28 +04:00
fstring_sub ( buf , " %u " , username ) ;
2001-06-26 00:44:04 +04:00
all_string_sub ( buf , " %o " , oldpass , sizeof ( fstring ) ) ;
all_string_sub ( buf , " %n " , newpass , sizeof ( fstring ) ) ;
}
struct chat_struct {
struct chat_struct * next , * prev ;
fstring prompt ;
fstring reply ;
} ;
/**************************************************************
Create a linked list containing chat data .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static struct chat_struct * make_pw_chat ( char * p )
{
fstring prompt ;
fstring reply ;
struct chat_struct * list = NULL ;
struct chat_struct * t ;
struct chat_struct * tmp ;
while ( 1 ) {
t = ( struct chat_struct * ) malloc ( sizeof ( * t ) ) ;
if ( ! t ) {
DEBUG ( 0 , ( " make_pw_chat: malloc failed! \n " ) ) ;
return NULL ;
}
ZERO_STRUCTP ( t ) ;
DLIST_ADD_END ( list , t , tmp ) ;
if ( ! next_token ( & p , prompt , NULL , sizeof ( fstring ) ) )
break ;
if ( strequal ( prompt , " . " ) )
fstrcpy ( prompt , " * " ) ;
special_char_sub ( prompt ) ;
fstrcpy ( t - > prompt , prompt ) ;
2001-07-07 02:54:49 +04:00
strlower ( t - > prompt ) ;
trim_string ( t - > prompt , " " , " " ) ;
2001-06-26 00:44:04 +04:00
if ( ! next_token ( & p , reply , NULL , sizeof ( fstring ) ) )
break ;
if ( strequal ( reply , " . " ) )
fstrcpy ( reply , " " ) ;
special_char_sub ( reply ) ;
fstrcpy ( t - > reply , reply ) ;
2001-07-07 02:54:49 +04:00
strlower ( t - > reply ) ;
trim_string ( t - > reply , " " , " " ) ;
2001-06-26 00:44:04 +04:00
}
return list ;
}
static void free_pw_chat ( struct chat_struct * list )
{
while ( list ) {
struct chat_struct * old_head = list ;
DLIST_REMOVE ( list , list ) ;
2001-09-17 09:04:17 +04:00
SAFE_FREE ( old_head ) ;
2001-06-26 00:44:04 +04:00
}
}
2001-05-01 01:05:58 +04:00
static int smb_pam_passchange_conv ( int num_msg ,
const struct pam_message * * msg ,
struct pam_response * * resp ,
void * appdata_ptr )
{
int replies = 0 ;
struct pam_response * reply = NULL ;
2001-06-26 00:44:04 +04:00
fstring current_prompt ;
fstring current_reply ;
2001-05-01 01:05:58 +04:00
struct smb_pam_userdata * udp = ( struct smb_pam_userdata * ) appdata_ptr ;
2001-06-26 00:44:04 +04:00
struct chat_struct * pw_chat = make_pw_chat ( lp_passwd_chat ( ) ) ;
struct chat_struct * t ;
BOOL found ;
2001-05-01 22:25:20 +04:00
* resp = NULL ;
2001-06-26 00:44:04 +04:00
DEBUG ( 10 , ( " smb_pam_passchange_conv: starting converstation for %d messages \n " , num_msg ) ) ;
2001-05-01 22:25:20 +04:00
2001-05-03 03:32:09 +04:00
if ( num_msg < = 0 )
return PAM_CONV_ERR ;
2001-06-26 00:44:04 +04:00
if ( pw_chat = = NULL )
return PAM_CONV_ERR ;
2001-05-01 22:25:20 +04:00
/*
* Apparantly HPUX has a buggy PAM that doesn ' t support the
* appdata_ptr . Fail if this is the case . JRA .
*/
if ( udp = = NULL ) {
DEBUG ( 0 , ( " smb_pam_passchange_conv: PAM on this system is broken - appdata_ptr == NULL ! \n " ) ) ;
2001-06-26 00:44:04 +04:00
free_pw_chat ( pw_chat ) ;
2001-05-01 22:25:20 +04:00
return PAM_CONV_ERR ;
}
2001-05-01 01:05:58 +04:00
reply = malloc ( sizeof ( struct pam_response ) * num_msg ) ;
2001-06-26 00:44:04 +04:00
if ( ! reply ) {
DEBUG ( 0 , ( " smb_pam_passchange_conv: malloc for reply failed! \n " ) ) ;
free_pw_chat ( pw_chat ) ;
2001-05-01 01:05:58 +04:00
return PAM_CONV_ERR ;
2001-06-26 00:44:04 +04:00
}
2001-05-01 01:05:58 +04:00
for ( replies = 0 ; replies < num_msg ; replies + + ) {
2001-06-26 00:44:04 +04:00
found = False ;
DEBUG ( 10 , ( " smb_pam_passchange_conv: Processing message %d \n " , replies ) ) ;
2001-05-01 01:05:58 +04:00
switch ( msg [ replies ] - > msg_style ) {
case PAM_PROMPT_ECHO_ON :
2001-06-26 00:44:04 +04:00
DEBUG ( 10 , ( " smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: PAM said: %s \n " , msg [ replies ] - > msg ) ) ;
fstrcpy ( current_prompt , msg [ replies ] - > msg ) ;
2001-07-07 02:54:49 +04:00
trim_string ( current_prompt , " " , " " ) ;
2001-06-26 00:44:04 +04:00
for ( t = pw_chat ; t ; t = t - > next ) {
2001-07-07 02:54:49 +04:00
DEBUG ( 10 , ( " smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s| \n " ,
t - > prompt , current_prompt ) ) ;
2001-10-03 01:58:09 +04:00
if ( unix_wild_match ( t - > prompt , current_prompt ) = = 0 ) {
2001-06-26 00:44:04 +04:00
fstrcpy ( current_reply , t - > reply ) ;
DEBUG ( 10 , ( " smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We sent: %s \n " , current_reply ) ) ;
2001-07-07 02:54:49 +04:00
pwd_sub ( current_reply , udp - > PAM_username , udp - > PAM_password , udp - > PAM_newpassword ) ;
# ifdef DEBUG_PASSWORD
DEBUG ( 100 , ( " smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We actualy sent: %s \n " , current_reply ) ) ;
# endif
2001-06-26 00:44:04 +04:00
reply [ replies ] . resp_retcode = PAM_SUCCESS ;
reply [ replies ] . resp = COPY_STRING ( current_reply ) ;
found = True ;
break ;
}
}
2001-05-01 01:05:58 +04:00
/* PAM frees resp */
2001-06-26 00:44:04 +04:00
if ( ! found ) {
DEBUG ( 3 , ( " smb_pam_passchange_conv: Could not find reply for PAM prompt: %s \n " , msg [ replies ] - > msg ) ) ;
free_pw_chat ( pw_chat ) ;
2001-09-17 09:04:17 +04:00
SAFE_FREE ( reply ) ;
2001-05-10 01:14:41 +04:00
return PAM_CONV_ERR ;
}
2001-06-26 00:44:04 +04:00
break ;
2001-05-10 01:14:41 +04:00
2001-06-26 00:44:04 +04:00
case PAM_PROMPT_ECHO_OFF :
DEBUG ( 10 , ( " smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: PAM said: %s \n " , msg [ replies ] - > msg ) ) ;
fstrcpy ( current_prompt , msg [ replies ] - > msg ) ;
2001-07-07 02:54:49 +04:00
trim_string ( current_prompt , " " , " " ) ;
2001-06-26 00:44:04 +04:00
for ( t = pw_chat ; t ; t = t - > next ) {
2001-07-07 02:54:49 +04:00
DEBUG ( 10 , ( " smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s| \n " ,
t - > prompt , current_prompt ) ) ;
2001-10-03 01:58:09 +04:00
if ( unix_wild_match ( t - > prompt , current_prompt ) = = 0 ) {
2001-06-26 00:44:04 +04:00
fstrcpy ( current_reply , t - > reply ) ;
DEBUG ( 10 , ( " smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We sent: %s \n " , current_reply ) ) ;
pwd_sub ( current_reply , udp - > PAM_username , udp - > PAM_password , udp - > PAM_newpassword ) ;
reply [ replies ] . resp_retcode = PAM_SUCCESS ;
reply [ replies ] . resp = COPY_STRING ( current_reply ) ;
# ifdef DEBUG_PASSWORD
DEBUG ( 100 , ( " smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We actualy sent: %s \n " , current_reply ) ) ;
# endif
found = True ;
break ;
}
}
/* PAM frees resp */
if ( ! found ) {
2001-05-01 01:05:58 +04:00
DEBUG ( 3 , ( " smb_pam_passchange_conv: Could not find reply for PAM prompt: %s \n " , msg [ replies ] - > msg ) ) ;
2001-06-26 00:44:04 +04:00
free_pw_chat ( pw_chat ) ;
2001-09-17 09:04:17 +04:00
SAFE_FREE ( reply ) ;
2001-05-01 22:19:15 +04:00
return PAM_CONV_ERR ;
2001-05-01 01:05:58 +04:00
}
break ;
case PAM_TEXT_INFO :
/* fall through */
case PAM_ERROR_MSG :
/* ignore it... */
reply [ replies ] . resp_retcode = PAM_SUCCESS ;
reply [ replies ] . resp = NULL ;
break ;
2001-06-26 00:44:04 +04:00
2001-05-01 01:05:58 +04:00
default :
/* Must be an error of some sort... */
2001-06-26 00:44:04 +04:00
free_pw_chat ( pw_chat ) ;
2001-09-17 09:04:17 +04:00
SAFE_FREE ( reply ) ;
2001-05-01 01:05:58 +04:00
return PAM_CONV_ERR ;
}
}
2001-06-26 00:44:04 +04:00
free_pw_chat ( pw_chat ) ;
2001-05-01 01:05:58 +04:00
if ( reply )
* resp = reply ;
return PAM_SUCCESS ;
}
/***************************************************************************
Free up a malloced pam_conv struct .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void smb_free_pam_conv ( struct pam_conv * pconv )
{
if ( pconv )
2001-09-17 09:04:17 +04:00
SAFE_FREE ( pconv - > appdata_ptr ) ;
2001-05-01 01:05:58 +04:00
2001-09-17 09:04:17 +04:00
SAFE_FREE ( pconv ) ;
2001-05-01 01:05:58 +04:00
}
/***************************************************************************
Allocate a pam_conv struct .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
static struct pam_conv * smb_setup_pam_conv ( smb_pam_conv_fn smb_pam_conv_fnptr , const char * user ,
const char * passwd , const char * newpass )
2001-05-01 01:05:58 +04:00
{
struct pam_conv * pconv = ( struct pam_conv * ) malloc ( sizeof ( struct pam_conv ) ) ;
struct smb_pam_userdata * udp = ( struct smb_pam_userdata * ) malloc ( sizeof ( struct smb_pam_userdata ) ) ;
if ( pconv = = NULL | | udp = = NULL ) {
2001-09-17 09:04:17 +04:00
SAFE_FREE ( pconv ) ;
SAFE_FREE ( udp ) ;
2001-05-01 01:05:58 +04:00
return NULL ;
}
udp - > PAM_username = user ;
udp - > PAM_password = passwd ;
udp - > PAM_newpassword = newpass ;
pconv - > conv = smb_pam_conv_fnptr ;
pconv - > appdata_ptr = ( void * ) udp ;
return pconv ;
}
2001-04-10 22:10:38 +04:00
2001-04-11 05:29:42 +04:00
/*
* PAM Closing out cleanup handler
*/
2001-05-01 01:05:58 +04:00
static BOOL smb_pam_end ( pam_handle_t * pamh , struct pam_conv * smb_pam_conv_ptr )
2001-04-10 22:10:38 +04:00
{
2001-04-22 11:20:24 +04:00
int pam_error ;
2001-05-01 01:05:58 +04:00
smb_free_pam_conv ( smb_pam_conv_ptr ) ;
2001-04-10 22:10:38 +04:00
2001-04-22 11:20:24 +04:00
if ( pamh ! = NULL ) {
2001-04-10 22:10:38 +04:00
pam_error = pam_end ( pamh , 0 ) ;
2001-04-23 08:15:35 +04:00
if ( smb_pam_error_handler ( pamh , pam_error , " End Cleanup Failed " , 2 ) = = True ) {
2001-05-01 01:05:58 +04:00
DEBUG ( 4 , ( " smb_pam_end: PAM: PAM_END OK. \n " ) ) ;
2001-04-22 11:20:24 +04:00
return True ;
2001-04-10 22:10:38 +04:00
}
2001-04-22 11:20:24 +04:00
}
2001-05-01 01:05:58 +04:00
DEBUG ( 2 , ( " smb_pam_end: PAM: not initialised " ) ) ;
2001-04-22 11:20:24 +04:00
return False ;
2001-04-10 22:10:38 +04:00
}
2001-04-11 05:29:42 +04:00
/*
* Start PAM authentication for specified account
*/
2001-05-01 01:05:58 +04:00
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
static BOOL smb_pam_start ( pam_handle_t * * pamh , const char * user , const char * rhost , struct pam_conv * pconv )
2001-04-10 22:10:38 +04:00
{
2001-04-22 11:20:24 +04:00
int pam_error ;
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
const char * our_rhost ;
2001-04-10 22:10:38 +04:00
2001-04-23 10:22:02 +04:00
* pamh = ( pam_handle_t * ) NULL ;
2001-05-01 01:05:58 +04:00
DEBUG ( 4 , ( " smb_pam_start: PAM: Init user: %s \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
2001-05-01 01:05:58 +04:00
pam_error = pam_start ( " samba " , user , pconv , pamh ) ;
2001-04-23 08:15:35 +04:00
if ( ! smb_pam_error_handler ( * pamh , pam_error , " Init Failed " , 0 ) ) {
2001-04-23 10:22:02 +04:00
* pamh = ( pam_handle_t * ) NULL ;
2001-04-22 11:20:24 +04:00
return False ;
}
2001-04-11 05:29:42 +04:00
2001-04-22 11:20:24 +04:00
if ( rhost = = NULL ) {
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
our_rhost = client_name ( ) ;
2001-04-22 11:20:24 +04:00
if ( strequal ( rhost , " UNKNOWN " ) )
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
our_rhost = client_addr ( ) ;
} else {
our_rhost = rhost ;
2001-04-22 11:20:24 +04:00
}
2001-04-11 05:29:42 +04:00
# ifdef PAM_RHOST
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
DEBUG ( 4 , ( " smb_pam_start: PAM: setting rhost to: %s \n " , our_rhost ) ) ;
pam_error = pam_set_item ( * pamh , PAM_RHOST , our_rhost ) ;
2001-04-23 08:15:35 +04:00
if ( ! smb_pam_error_handler ( * pamh , pam_error , " set rhost failed " , 0 ) ) {
2001-05-01 01:05:58 +04:00
smb_pam_end ( * pamh , pconv ) ;
2001-04-23 10:22:02 +04:00
* pamh = ( pam_handle_t * ) NULL ;
2001-04-22 11:20:24 +04:00
return False ;
}
2001-04-11 05:29:42 +04:00
# endif
# ifdef PAM_TTY
2001-05-01 01:05:58 +04:00
DEBUG ( 4 , ( " smb_pam_start: PAM: setting tty \n " ) ) ;
2001-04-22 11:20:24 +04:00
pam_error = pam_set_item ( * pamh , PAM_TTY , " samba " ) ;
2001-04-23 08:15:35 +04:00
if ( ! smb_pam_error_handler ( * pamh , pam_error , " set tty failed " , 0 ) ) {
2001-05-01 01:05:58 +04:00
smb_pam_end ( * pamh , pconv ) ;
2001-04-23 10:22:02 +04:00
* pamh = ( pam_handle_t * ) NULL ;
2001-04-22 11:20:24 +04:00
return False ;
}
2001-04-11 05:29:42 +04:00
# endif
2001-05-01 01:05:58 +04:00
DEBUG ( 4 , ( " smb_pam_start: PAM: Init passed for user: %s \n " , user ) ) ;
2001-04-22 11:20:24 +04:00
return True ;
2001-04-11 05:29:42 +04:00
}
/*
* PAM Authentication Handler
*/
2002-07-15 14:35:28 +04:00
static NTSTATUS smb_pam_auth ( pam_handle_t * pamh , const char * user )
2001-04-11 05:29:42 +04:00
{
int pam_error ;
2001-09-04 11:13:01 +04:00
NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE ;
2001-04-10 22:10:38 +04:00
/*
* To enable debugging set in / etc / pam . d / samba :
* auth required / lib / security / pam_pwdb . so nullok shadow audit
*/
2001-05-01 01:05:58 +04:00
DEBUG ( 4 , ( " smb_pam_auth: PAM: Authenticate User: %s \n " , user ) ) ;
pam_error = pam_authenticate ( pamh , PAM_SILENT | lp_null_passwords ( ) ? 0 : PAM_DISALLOW_NULL_AUTHTOK ) ;
2001-04-10 22:10:38 +04:00
switch ( pam_error ) {
case PAM_AUTH_ERR :
2001-05-01 01:05:58 +04:00
DEBUG ( 2 , ( " smb_pam_auth: PAM: Athentication Error for user %s \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
case PAM_CRED_INSUFFICIENT :
2001-05-01 01:05:58 +04:00
DEBUG ( 2 , ( " smb_pam_auth: PAM: Insufficient Credentials for user %s \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
case PAM_AUTHINFO_UNAVAIL :
2001-05-01 01:05:58 +04:00
DEBUG ( 2 , ( " smb_pam_auth: PAM: Authentication Information Unavailable for user %s \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
case PAM_USER_UNKNOWN :
2001-05-01 01:05:58 +04:00
DEBUG ( 2 , ( " smb_pam_auth: PAM: Username %s NOT known to Authentication system \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
case PAM_MAXTRIES :
2001-05-01 01:05:58 +04:00
DEBUG ( 2 , ( " smb_pam_auth: PAM: One or more authentication modules reports user limit for user %s exceeeded \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
case PAM_ABORT :
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_auth: PAM: One or more PAM modules failed to load for user %s \n " , user ) ) ;
break ;
case PAM_SUCCESS :
DEBUG ( 4 , ( " smb_pam_auth: PAM: User %s Authenticated OK \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
2001-04-13 08:27:50 +04:00
default :
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_auth: PAM: UNKNOWN ERROR while authenticating user %s \n " , user ) ) ;
break ;
2001-04-10 22:10:38 +04:00
}
2001-05-01 01:05:58 +04:00
smb_pam_nt_status_error_handler ( pamh , pam_error , " Authentication Failure " , 2 , & nt_status ) ;
return nt_status ;
2001-04-11 05:29:42 +04:00
}
2001-04-10 22:10:38 +04:00
2001-04-11 05:29:42 +04:00
/*
* PAM Account Handler
*/
2001-10-31 09:22:19 +03:00
static NTSTATUS smb_pam_account ( pam_handle_t * pamh , const char * user )
2001-04-11 05:29:42 +04:00
{
int pam_error ;
2001-09-04 11:13:01 +04:00
NTSTATUS nt_status = NT_STATUS_ACCOUNT_DISABLED ;
2001-04-11 05:29:42 +04:00
2001-05-01 01:05:58 +04:00
DEBUG ( 4 , ( " smb_pam_account: PAM: Account Management for User: %s \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
pam_error = pam_acct_mgmt ( pamh , PAM_SILENT ) ; /* Is user account enabled? */
switch ( pam_error ) {
case PAM_AUTHTOK_EXPIRED :
2001-05-01 01:05:58 +04:00
DEBUG ( 2 , ( " smb_pam_account: PAM: User %s is valid but password is expired \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
case PAM_ACCT_EXPIRED :
2001-05-01 01:05:58 +04:00
DEBUG ( 2 , ( " smb_pam_account: PAM: User %s no longer permitted to access system \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
case PAM_AUTH_ERR :
2001-05-01 01:05:58 +04:00
DEBUG ( 2 , ( " smb_pam_account: PAM: There was an authentication error for user %s \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
case PAM_PERM_DENIED :
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_account: PAM: User %s is NOT permitted to access system at this time \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
case PAM_USER_UNKNOWN :
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_account: PAM: User \" %s \" is NOT known to account management \n " , user ) ) ;
break ;
case PAM_SUCCESS :
DEBUG ( 4 , ( " smb_pam_account: PAM: Account OK for User: %s \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
break ;
2001-04-13 08:27:50 +04:00
default :
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_account: PAM: UNKNOWN PAM ERROR (%d) during Account Management for User: %s \n " , pam_error , user ) ) ;
break ;
2001-04-10 22:10:38 +04:00
}
2001-05-01 01:05:58 +04:00
smb_pam_nt_status_error_handler ( pamh , pam_error , " Account Check Failed " , 2 , & nt_status ) ;
return nt_status ;
}
/*
* PAM Credential Setting
*/
2002-07-15 14:35:28 +04:00
static NTSTATUS smb_pam_setcred ( pam_handle_t * pamh , const char * user )
2001-05-01 01:05:58 +04:00
{
int pam_error ;
2001-09-04 11:13:01 +04:00
NTSTATUS nt_status = NT_STATUS_NO_TOKEN ;
2001-04-18 08:34:42 +04:00
2001-04-10 22:10:38 +04:00
/*
* This will allow samba to aquire a kerberos token . And , when
* exporting an AFS cell , be able to / write / to this cell .
*/
2001-04-22 11:20:24 +04:00
DEBUG ( 4 , ( " PAM: Account Management SetCredentials for User: %s \n " , user ) ) ;
2001-04-10 22:10:38 +04:00
pam_error = pam_setcred ( pamh , ( PAM_ESTABLISH_CRED | PAM_SILENT ) ) ;
2001-04-20 03:52:45 +04:00
switch ( pam_error ) {
case PAM_CRED_UNAVAIL :
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_setcred: PAM: Credentials not found for user:%s \n " , user ) ) ;
2001-04-20 03:52:45 +04:00
break ;
case PAM_CRED_EXPIRED :
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_setcred: PAM: Credentials for user: \" %s \" EXPIRED! \n " , user ) ) ;
2001-04-20 03:52:45 +04:00
break ;
2001-04-20 04:19:49 +04:00
case PAM_USER_UNKNOWN :
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_setcred: PAM: User: \" %s \" is NOT known so can not set credentials! \n " , user ) ) ;
2001-04-20 03:52:45 +04:00
break ;
2001-04-20 04:19:49 +04:00
case PAM_CRED_ERR :
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_setcred: PAM: Unknown setcredentials error - unable to set credentials for %s \n " , user ) ) ;
break ;
case PAM_SUCCESS :
DEBUG ( 4 , ( " smb_pam_setcred: PAM: SetCredentials OK for User: %s \n " , user ) ) ;
2001-04-20 03:52:45 +04:00
break ;
default :
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_setcred: PAM: UNKNOWN PAM ERROR (%d) during SetCredentials for User: %s \n " , pam_error , user ) ) ;
break ;
2001-04-10 22:10:38 +04:00
}
2001-05-01 01:05:58 +04:00
smb_pam_nt_status_error_handler ( pamh , pam_error , " Set Credential Failure " , 2 , & nt_status ) ;
return nt_status ;
}
2001-04-10 22:10:38 +04:00
2001-04-11 05:29:42 +04:00
/*
* PAM Internal Session Handler
*/
2002-07-15 14:35:28 +04:00
static BOOL smb_internal_pam_session ( pam_handle_t * pamh , const char * user , const char * tty , BOOL flag )
2001-04-10 22:10:38 +04:00
{
2001-04-22 11:20:24 +04:00
int pam_error ;
2001-04-10 22:10:38 +04:00
# ifdef PAM_TTY
2001-05-01 01:05:58 +04:00
DEBUG ( 4 , ( " smb_internal_pam_session: PAM: tty set to: %s \n " , tty ) ) ;
2001-04-22 11:20:24 +04:00
pam_error = pam_set_item ( pamh , PAM_TTY , tty ) ;
2001-04-23 10:09:27 +04:00
if ( ! smb_pam_error_handler ( pamh , pam_error , " set tty failed " , 0 ) )
2001-04-22 11:20:24 +04:00
return False ;
2001-04-10 22:10:38 +04:00
# endif
2001-04-22 11:20:24 +04:00
if ( flag ) {
pam_error = pam_open_session ( pamh , PAM_SILENT ) ;
2001-04-23 10:09:27 +04:00
if ( ! smb_pam_error_handler ( pamh , pam_error , " session setup failed " , 0 ) )
2001-04-22 11:20:24 +04:00
return False ;
} else {
2001-05-01 01:05:58 +04:00
pam_setcred ( pamh , ( PAM_DELETE_CRED | PAM_SILENT ) ) ; /* We don't care if this fails */
pam_error = pam_close_session ( pamh , PAM_SILENT ) ; /* This will probably pick up the error anyway */
2001-04-23 10:09:27 +04:00
if ( ! smb_pam_error_handler ( pamh , pam_error , " session close failed " , 0 ) )
2001-04-22 11:20:24 +04:00
return False ;
}
return ( True ) ;
2001-04-10 22:10:38 +04:00
}
2001-05-01 01:05:58 +04:00
/*
* Internal PAM Password Changer .
*/
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
static BOOL smb_pam_chauthtok ( pam_handle_t * pamh , const char * user )
2001-05-01 01:05:58 +04:00
{
int pam_error ;
DEBUG ( 4 , ( " smb_pam_chauthtok: PAM: Password Change for User: %s \n " , user ) ) ;
pam_error = pam_chauthtok ( pamh , PAM_SILENT ) ; /* Change Password */
switch ( pam_error ) {
case PAM_AUTHTOK_ERR :
DEBUG ( 2 , ( " PAM: unable to obtain the new authentication token - is password to weak? \n " ) ) ;
break ;
2001-05-01 05:26:15 +04:00
/* This doesn't seem to be defined on Solaris. JRA */
# ifdef PAM_AUTHTOK_RECOVER_ERR
2001-05-01 01:05:58 +04:00
case PAM_AUTHTOK_RECOVER_ERR :
DEBUG ( 2 , ( " PAM: unable to obtain the old authentication token - was the old password wrong?. \n " ) ) ;
break ;
2001-05-01 05:26:15 +04:00
# endif
2001-05-01 01:05:58 +04:00
case PAM_AUTHTOK_LOCK_BUSY :
DEBUG ( 2 , ( " PAM: unable to change the authentication token since it is currently locked. \n " ) ) ;
break ;
case PAM_AUTHTOK_DISABLE_AGING :
DEBUG ( 2 , ( " PAM: Authentication token aging has been disabled. \n " ) ) ;
break ;
case PAM_PERM_DENIED :
DEBUG ( 0 , ( " PAM: Permission denied. \n " ) ) ;
break ;
case PAM_TRY_AGAIN :
DEBUG ( 0 , ( " PAM: Could not update all authentication token(s). No authentication tokens were updated. \n " ) ) ;
break ;
case PAM_USER_UNKNOWN :
DEBUG ( 0 , ( " PAM: User not known to PAM \n " ) ) ;
break ;
case PAM_SUCCESS :
DEBUG ( 4 , ( " PAM: Account OK for User: %s \n " , user ) ) ;
break ;
default :
DEBUG ( 0 , ( " PAM: UNKNOWN PAM ERROR (%d) for User: %s \n " , pam_error , user ) ) ;
}
if ( ! smb_pam_error_handler ( pamh , pam_error , " Password Change Failed " , 2 ) ) {
return False ;
}
/* If this point is reached, the password has changed. */
return True ;
}
2001-04-11 05:29:42 +04:00
/*
* PAM Externally accessible Session handler
*/
2001-04-24 00:43:20 +04:00
2001-05-01 01:05:58 +04:00
BOOL smb_pam_claim_session ( char * user , char * tty , char * rhost )
2001-04-10 22:10:38 +04:00
{
2001-04-11 05:29:42 +04:00
pam_handle_t * pamh = NULL ;
2001-05-01 01:05:58 +04:00
struct pam_conv * pconv = NULL ;
2001-04-10 22:10:38 +04:00
2001-04-24 00:43:20 +04:00
/* Ignore PAM if told to. */
if ( ! lp_obey_pam_restrictions ( ) )
return True ;
2001-05-01 01:05:58 +04:00
if ( ( pconv = smb_setup_pam_conv ( smb_pam_conv , user , NULL , NULL ) ) = = NULL )
2001-04-11 05:29:42 +04:00
return False ;
2001-04-10 22:10:38 +04:00
2001-05-01 01:05:58 +04:00
if ( ! smb_pam_start ( & pamh , user , rhost , pconv ) )
2001-04-22 11:20:24 +04:00
return False ;
2001-04-10 22:10:38 +04:00
2001-05-01 01:05:58 +04:00
if ( ! smb_internal_pam_session ( pamh , user , tty , True ) ) {
smb_pam_end ( pamh , pconv ) ;
2001-04-22 11:20:24 +04:00
return False ;
2001-04-10 22:10:38 +04:00
}
2001-05-01 01:05:58 +04:00
return smb_pam_end ( pamh , pconv ) ;
2001-04-10 22:10:38 +04:00
}
2001-04-13 08:27:50 +04:00
/*
2001-05-01 01:05:58 +04:00
* PAM Externally accessible Session handler
2001-04-13 08:27:50 +04:00
*/
2001-05-01 01:05:58 +04:00
BOOL smb_pam_close_session ( char * user , char * tty , char * rhost )
2001-04-13 08:27:50 +04:00
{
pam_handle_t * pamh = NULL ;
2001-05-01 01:05:58 +04:00
struct pam_conv * pconv = NULL ;
2001-04-13 08:27:50 +04:00
2001-04-24 00:43:20 +04:00
/* Ignore PAM if told to. */
if ( ! lp_obey_pam_restrictions ( ) )
return True ;
2001-05-01 01:05:58 +04:00
if ( ( pconv = smb_setup_pam_conv ( smb_pam_conv , user , NULL , NULL ) ) = = NULL )
return False ;
if ( ! smb_pam_start ( & pamh , user , rhost , pconv ) )
return False ;
if ( ! smb_internal_pam_session ( pamh , user , tty , False ) ) {
smb_pam_end ( pamh , pconv ) ;
return False ;
2001-04-13 08:27:50 +04:00
}
2001-05-01 01:05:58 +04:00
return smb_pam_end ( pamh , pconv ) ;
2001-04-13 08:27:50 +04:00
}
2001-04-11 05:29:42 +04:00
/*
2001-05-01 01:05:58 +04:00
* PAM Externally accessible Account handler
2001-04-11 05:29:42 +04:00
*/
2001-05-01 01:05:58 +04:00
2001-10-31 09:22:19 +03:00
NTSTATUS smb_pam_accountcheck ( const char * user )
2001-04-10 22:10:38 +04:00
{
2001-09-04 11:13:01 +04:00
NTSTATUS nt_status = NT_STATUS_ACCOUNT_DISABLED ;
2001-04-10 22:10:38 +04:00
pam_handle_t * pamh = NULL ;
2001-05-01 01:05:58 +04:00
struct pam_conv * pconv = NULL ;
2001-04-10 22:10:38 +04:00
2001-05-01 01:05:58 +04:00
/* Ignore PAM if told to. */
if ( ! lp_obey_pam_restrictions ( ) )
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-05-01 01:05:58 +04:00
if ( ( pconv = smb_setup_pam_conv ( smb_pam_conv , user , NULL , NULL ) ) = = NULL )
2001-09-04 11:13:01 +04:00
return NT_STATUS_NO_MEMORY ;
2001-05-01 01:05:58 +04:00
if ( ! smb_pam_start ( & pamh , user , NULL , pconv ) )
return NT_STATUS_ACCOUNT_DISABLED ;
2001-09-04 11:13:01 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status = smb_pam_account ( pamh , user ) ) )
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_accountcheck: PAM: Account Validation Failed - Rejecting User %s! \n " , user ) ) ;
smb_pam_end ( pamh , pconv ) ;
return nt_status ;
}
/*
* PAM Password Validation Suite
*/
2002-07-15 14:35:28 +04:00
NTSTATUS smb_pam_passcheck ( const char * user , const char * password )
2001-05-01 01:05:58 +04:00
{
pam_handle_t * pamh = NULL ;
2001-09-04 11:13:01 +04:00
NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE ;
2001-05-01 01:05:58 +04:00
struct pam_conv * pconv = NULL ;
2001-04-10 22:10:38 +04:00
2001-04-24 00:43:20 +04:00
/*
* Note we can ' t ignore PAM here as this is the only
* way of doing auths on plaintext passwords when
* compiled - - with - pam .
*/
2001-05-01 01:05:58 +04:00
if ( ( pconv = smb_setup_pam_conv ( smb_pam_conv , user , password , NULL ) ) = = NULL )
2001-05-01 21:19:42 +04:00
return NT_STATUS_LOGON_FAILURE ;
2001-05-01 01:05:58 +04:00
2001-05-01 21:19:42 +04:00
if ( ! smb_pam_start ( & pamh , user , NULL , pconv ) )
2001-05-01 01:05:58 +04:00
return NT_STATUS_LOGON_FAILURE ;
2001-09-04 11:13:01 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status = smb_pam_auth ( pamh , user ) ) ) {
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_passcheck: PAM: smb_pam_auth failed - Rejecting User %s ! \n " , user ) ) ;
smb_pam_end ( pamh , pconv ) ;
return nt_status ;
}
2001-09-04 11:13:01 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status = smb_pam_account ( pamh , user ) ) ) {
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_passcheck: PAM: smb_pam_account failed - Rejecting User %s ! \n " , user ) ) ;
smb_pam_end ( pamh , pconv ) ;
return nt_status ;
}
2001-09-04 11:13:01 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status = smb_pam_setcred ( pamh , user ) ) ) {
2001-05-01 01:05:58 +04:00
DEBUG ( 0 , ( " smb_pam_passcheck: PAM: smb_pam_setcred failed - Rejecting User %s ! \n " , user ) ) ;
smb_pam_end ( pamh , pconv ) ;
return nt_status ;
2001-04-10 22:10:38 +04:00
}
2001-05-01 01:05:58 +04:00
smb_pam_end ( pamh , pconv ) ;
return nt_status ;
}
/*
* PAM Password Change Suite
*/
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
BOOL smb_pam_passchange ( const char * user , const char * oldpassword , const char * newpassword )
2001-05-01 01:05:58 +04:00
{
/* Appropriate quantities of root should be obtained BEFORE calling this function */
struct pam_conv * pconv = NULL ;
pam_handle_t * pamh = NULL ;
if ( ( pconv = smb_setup_pam_conv ( smb_pam_passchange_conv , user , oldpassword , newpassword ) ) = = NULL )
return False ;
if ( ! smb_pam_start ( & pamh , user , NULL , pconv ) )
return False ;
if ( ! smb_pam_chauthtok ( pamh , user ) ) {
DEBUG ( 0 , ( " smb_pam_passchange: PAM: Password Change Failed for user %s! \n " , user ) ) ;
smb_pam_end ( pamh , pconv ) ;
return False ;
}
return smb_pam_end ( pamh , pconv ) ;
2001-04-10 22:10:38 +04:00
}
# else
2001-04-22 11:20:24 +04:00
/* If PAM not used, no PAM restrictions on accounts. */
2001-10-31 09:22:19 +03:00
NTSTATUS smb_pam_accountcheck ( const char * user )
2001-05-01 01:05:58 +04:00
{
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-05-01 01:05:58 +04:00
}
/* If PAM not used, also no PAM restrictions on sessions. */
2001-10-31 09:22:19 +03:00
BOOL smb_pam_claim_session ( char * user , char * tty , char * rhost )
2001-04-22 11:20:24 +04:00
{
return True ;
}
2001-04-10 22:10:38 +04:00
2001-05-01 01:05:58 +04:00
/* If PAM not used, also no PAM restrictions on sessions. */
2001-10-31 09:22:19 +03:00
BOOL smb_pam_close_session ( char * in_user , char * tty , char * rhost )
2001-05-01 01:05:58 +04:00
{
return True ;
}
2001-04-10 22:10:38 +04:00
# endif /* WITH_PAM */