--- samba-2.2.1a/source/pam_smbpass/pam_smb_passwd.c Fri Jul 6 11:01:15 2001 +++ samba-2.2.1a-jn/source/pam_smbpass/pam_smb_passwd.c Fri Feb 1 15:36:17 2002 @@ -33,6 +33,10 @@ #include "support.h" +/* Helper function for adding a user to the db. */ +static int _smb_add_user(pam_handle_t *pamh, unsigned int ctrl, + const char *name, struct smb_passwd *smb_pwent); + int smb_update_db( pam_handle_t *pamh, int ctrl, const char *user , const char *pass_new ) { @@ -128,6 +132,18 @@ /* obtain user record */ smb_pwent = getsmbpwnam(user); + /* migrate... */ + if (smb_pwent == NULL) { + if(on( SMB_MIGRATE, ctrl )) { + _log_err( LOG_INFO, "Attempting to create new smbuser" ); + _smb_add_user(pamh, ctrl, user, smb_pwent); + + smb_pwent = getsmbpwnam(user); + } + } + + + if (smb_pwent == NULL) { _log_err( LOG_ALERT, "Failed to find entry for user %s.", user ); return PAM_USER_UNKNOWN; @@ -299,6 +315,43 @@ return retval; } +/* Helper function for adding a user to the db. */ +static int _smb_add_user(pam_handle_t *pamh, unsigned int ctrl, + const char *name, struct smb_passwd *smb_pwent) +{ + pstring err_str; + pstring msg_str; + const char *pass = NULL; + int retval; + + err_str[0] = '\0'; + msg_str[0] = '\0'; + + /* Add the user to the db if they aren't already there. */ + if (smb_pwent == NULL) { + retval = local_password_change( name, LOCAL_ADD_USER | LOCAL_SET_NO_PASSWORD, + pass, err_str, + sizeof(err_str), + msg_str, sizeof(msg_str) ); + if (!retval && *err_str) + { + err_str[PSTRING_LEN-1] = '\0'; + make_remark( pamh, ctrl, PAM_ERROR_MSG, err_str ); + } + else if (*msg_str) + { + msg_str[PSTRING_LEN-1] = '\0'; + make_remark( pamh, ctrl, PAM_TEXT_INFO, msg_str ); + } + pass = NULL; + + return PAM_IGNORE; + } + + return PAM_IGNORE; +} + + /* static module data */ #ifdef PAM_STATIC struct pam_module _pam_smbpass_passwd_modstruct = {