| 1 | /* Unix NT password database implementation, version 0.7.5.
|
|---|
| 2 | *
|
|---|
| 3 | * This program is free software; you can redistribute it and/or modify it under
|
|---|
| 4 | * the terms of the GNU General Public License as published by the Free
|
|---|
| 5 | * Software Foundation; either version 2 of the License, or (at your option)
|
|---|
| 6 | * any later version.
|
|---|
| 7 | *
|
|---|
| 8 | * This program is distributed in the hope that it will be useful, but WITHOUT
|
|---|
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|---|
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|---|
| 11 | * more details.
|
|---|
| 12 | *
|
|---|
| 13 | * You should have received a copy of the GNU General Public License along with
|
|---|
| 14 | * this program; if not, write to the Free Software Foundation, Inc., 675
|
|---|
| 15 | * Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 16 | */
|
|---|
| 17 |
|
|---|
| 18 | /* indicate the following groups are defined */
|
|---|
| 19 | #define PAM_SM_ACCT
|
|---|
| 20 |
|
|---|
| 21 | #include "includes.h"
|
|---|
| 22 |
|
|---|
| 23 | #ifndef LINUX
|
|---|
| 24 |
|
|---|
| 25 | /* This is only used in the Sun implementation. */
|
|---|
| 26 | #include <security/pam_appl.h>
|
|---|
| 27 |
|
|---|
| 28 | #endif /* LINUX */
|
|---|
| 29 |
|
|---|
| 30 | #include <security/pam_modules.h>
|
|---|
| 31 |
|
|---|
| 32 | #include "general.h"
|
|---|
| 33 |
|
|---|
| 34 | #include "support.h"
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | /*
|
|---|
| 38 | * pam_sm_acct_mgmt() verifies whether or not the account is disabled.
|
|---|
| 39 | *
|
|---|
| 40 | */
|
|---|
| 41 |
|
|---|
| 42 | int pam_sm_acct_mgmt( pam_handle_t *pamh, int flags,
|
|---|
| 43 | int argc, const char **argv )
|
|---|
| 44 | {
|
|---|
| 45 | unsigned int ctrl;
|
|---|
| 46 | int retval;
|
|---|
| 47 |
|
|---|
| 48 | const char *name;
|
|---|
| 49 | struct samu *sampass = NULL;
|
|---|
| 50 | void (*oldsig_handler)(int);
|
|---|
| 51 | extern BOOL in_client;
|
|---|
| 52 |
|
|---|
| 53 | /* Samba initialization. */
|
|---|
| 54 | load_case_tables();
|
|---|
| 55 | setup_logging( "pam_smbpass", False );
|
|---|
| 56 | in_client = True;
|
|---|
| 57 |
|
|---|
| 58 | ctrl = set_ctrl( flags, argc, argv );
|
|---|
| 59 |
|
|---|
| 60 | /* get the username */
|
|---|
| 61 |
|
|---|
| 62 | retval = pam_get_user( pamh, &name, "Username: " );
|
|---|
| 63 | if (retval != PAM_SUCCESS) {
|
|---|
| 64 | if (on( SMB_DEBUG, ctrl )) {
|
|---|
| 65 | _log_err( LOG_DEBUG, "acct: could not identify user" );
|
|---|
| 66 | }
|
|---|
| 67 | return retval;
|
|---|
| 68 | }
|
|---|
| 69 | if (on( SMB_DEBUG, ctrl )) {
|
|---|
| 70 | _log_err( LOG_DEBUG, "acct: username [%s] obtained", name );
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | if (geteuid() != 0) {
|
|---|
| 74 | _log_err( LOG_DEBUG, "Cannot access samba password database, not running as root.");
|
|---|
| 75 | return PAM_AUTHINFO_UNAVAIL;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | /* Getting into places that might use LDAP -- protect the app
|
|---|
| 79 | from a SIGPIPE it's not expecting */
|
|---|
| 80 | oldsig_handler = CatchSignal(SIGPIPE, SIGNAL_CAST SIG_IGN);
|
|---|
| 81 | if (!initialize_password_db(True)) {
|
|---|
| 82 | _log_err( LOG_ALERT, "Cannot access samba password database" );
|
|---|
| 83 | CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
|
|---|
| 84 | return PAM_AUTHINFO_UNAVAIL;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | /* Get the user's record. */
|
|---|
| 88 |
|
|---|
| 89 | if (!(sampass = samu_new( NULL ))) {
|
|---|
| 90 | CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
|
|---|
| 91 | /* malloc fail. */
|
|---|
| 92 | return nt_status_to_pam(NT_STATUS_NO_MEMORY);
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | if (!pdb_getsampwnam(sampass, name )) {
|
|---|
| 96 | _log_err( LOG_DEBUG, "acct: could not identify user" );
|
|---|
| 97 | CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
|
|---|
| 98 | return PAM_USER_UNKNOWN;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | /* check for lookup failure */
|
|---|
| 102 | if (!strlen(pdb_get_username(sampass)) ) {
|
|---|
| 103 | CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
|
|---|
| 104 | return PAM_USER_UNKNOWN;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | if (pdb_get_acct_ctrl(sampass) & ACB_DISABLED) {
|
|---|
| 108 | if (on( SMB_DEBUG, ctrl )) {
|
|---|
| 109 | _log_err( LOG_DEBUG
|
|---|
| 110 | , "acct: account %s is administratively disabled", name );
|
|---|
| 111 | }
|
|---|
| 112 | make_remark( pamh, ctrl, PAM_ERROR_MSG
|
|---|
| 113 | , "Your account has been disabled; "
|
|---|
| 114 | "please see your system administrator." );
|
|---|
| 115 |
|
|---|
| 116 | CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
|
|---|
| 117 | return PAM_ACCT_EXPIRED;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | /* TODO: support for expired passwords. */
|
|---|
| 121 |
|
|---|
| 122 | CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
|
|---|
| 123 | return PAM_SUCCESS;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | /* static module data */
|
|---|
| 127 | #ifdef PAM_STATIC
|
|---|
| 128 | struct pam_module _pam_smbpass_acct_modstruct = {
|
|---|
| 129 | "pam_smbpass",
|
|---|
| 130 | NULL,
|
|---|
| 131 | NULL,
|
|---|
| 132 | pam_sm_acct_mgmt,
|
|---|
| 133 | NULL,
|
|---|
| 134 | NULL,
|
|---|
| 135 | NULL
|
|---|
| 136 | };
|
|---|
| 137 | #endif
|
|---|
| 138 |
|
|---|