|
Packit Service |
b29381 |
/*
|
|
Packit Service |
b29381 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
b29381 |
* modification, are permitted provided that the following conditions
|
|
Packit Service |
b29381 |
* are met:
|
|
Packit Service |
b29381 |
* 1. Redistributions of source code must retain the above copyright
|
|
Packit Service |
b29381 |
* notice, and the entire permission notice in its entirety,
|
|
Packit Service |
b29381 |
* including the disclaimer of warranties.
|
|
Packit Service |
b29381 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
Packit Service |
b29381 |
* notice, this list of conditions and the following disclaimer in the
|
|
Packit Service |
b29381 |
* documentation and/or other materials provided with the distribution.
|
|
Packit Service |
b29381 |
* 3. The name of the author may not be used to endorse or promote
|
|
Packit Service |
b29381 |
* products derived from this software without specific prior
|
|
Packit Service |
b29381 |
* written permission.
|
|
Packit Service |
b29381 |
*
|
|
Packit Service |
b29381 |
* ALTERNATIVELY, this product may be distributed under the terms of
|
|
Packit Service |
b29381 |
* the GNU Public License, in which case the provisions of the GPL are
|
|
Packit Service |
b29381 |
* required INSTEAD OF the above restrictions. (This clause is
|
|
Packit Service |
b29381 |
* necessary due to a potential bad interaction between the GPL and
|
|
Packit Service |
b29381 |
* the restrictions contained in a BSD-style copyright.)
|
|
Packit Service |
b29381 |
*
|
|
Packit Service |
b29381 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
Packit Service |
b29381 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
Packit Service |
b29381 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
Packit Service |
b29381 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
Packit Service |
b29381 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
Packit Service |
b29381 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
Packit Service |
b29381 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
Packit Service |
b29381 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
Packit Service |
b29381 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit Service |
b29381 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
Packit Service |
b29381 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit Service |
b29381 |
*/
|
|
Packit Service |
b29381 |
#include "config.h"
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
#include <pwd.h>
|
|
Packit Service |
b29381 |
#include <netdb.h>
|
|
Packit Service |
b29381 |
#include <string.h>
|
|
Packit Service |
b29381 |
#include <syslog.h>
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
#define PAM_SM_AUTH /* only defines this management group */
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
#include <security/pam_modules.h>
|
|
Packit Service |
b29381 |
#include <security/pam_modutil.h>
|
|
Packit Service |
b29381 |
#include <security/pam_ext.h>
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
int pam_sm_authenticate (pam_handle_t *pamh, int flags, int argc,
|
|
Packit Service |
b29381 |
const char **argv)
|
|
Packit Service |
b29381 |
{
|
|
Packit Service |
b29381 |
const char *luser = NULL;
|
|
Packit Service |
b29381 |
const char *ruser = NULL, *rhost = NULL;
|
|
Packit Service |
b29381 |
const char *opt_superuser = NULL;
|
|
Packit Service |
b29381 |
const void *c_void;
|
|
Packit Service |
b29381 |
int opt_debug = 0;
|
|
Packit Service |
b29381 |
int opt_silent;
|
|
Packit Service |
b29381 |
int as_root;
|
|
Packit Service |
b29381 |
int retval;
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
opt_silent = flags & PAM_SILENT;
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
while (argc-- > 0) {
|
|
Packit Service |
b29381 |
if (strcmp(*argv, "debug") == 0)
|
|
Packit Service |
b29381 |
opt_debug = 1;
|
|
Packit Service |
b29381 |
else if (strcmp (*argv, "silent") == 0 || strcmp(*argv, "suppress") == 0)
|
|
Packit Service |
b29381 |
opt_silent = 1;
|
|
Packit Service |
b29381 |
else if (strncmp(*argv, "superuser=", sizeof("superuser=")-1) == 0)
|
|
Packit Service |
b29381 |
opt_superuser = *argv+sizeof("superuser=")-1;
|
|
Packit Service |
b29381 |
else
|
|
Packit Service |
b29381 |
pam_syslog(pamh, LOG_WARNING, "unrecognized option '%s'", *argv);
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
++argv;
|
|
Packit Service |
b29381 |
}
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
retval = pam_get_item (pamh, PAM_RHOST, &c_void);
|
|
Packit Service |
b29381 |
if (retval != PAM_SUCCESS) {
|
|
Packit Service |
b29381 |
pam_syslog(pamh, LOG_ERR, "could not get the remote host name");
|
|
Packit Service |
b29381 |
return retval;
|
|
Packit Service |
b29381 |
}
|
|
Packit Service |
b29381 |
rhost = c_void;
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
retval = pam_get_item(pamh, PAM_RUSER, &c_void);
|
|
Packit Service |
b29381 |
ruser = c_void;
|
|
Packit Service |
b29381 |
if (retval != PAM_SUCCESS) {
|
|
Packit Service |
b29381 |
pam_syslog(pamh, LOG_ERR, "could not get the remote username");
|
|
Packit Service |
b29381 |
return retval;
|
|
Packit Service |
b29381 |
}
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
retval = pam_get_user(pamh, &luser, NULL);
|
|
Packit Service |
b29381 |
if (retval != PAM_SUCCESS) {
|
|
Packit Service |
b29381 |
pam_syslog(pamh, LOG_ERR, "could not determine name of local user");
|
|
Packit Service |
b29381 |
return retval;
|
|
Packit Service |
b29381 |
}
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
if (rhost == NULL || ruser == NULL || luser == NULL)
|
|
Packit Service |
b29381 |
return PAM_AUTH_ERR;
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
if (opt_superuser && strcmp(opt_superuser, luser) == 0)
|
|
Packit Service |
b29381 |
as_root = 1;
|
|
Packit Service |
b29381 |
else {
|
|
Packit Service |
b29381 |
struct passwd *lpwd;
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
lpwd = pam_modutil_getpwnam(pamh, luser);
|
|
Packit Service |
b29381 |
if (lpwd == NULL) {
|
|
Packit Service |
b29381 |
if (opt_debug)
|
|
Packit Service |
b29381 |
/* don't print by default, could be the user's password */
|
|
Packit Service |
b29381 |
pam_syslog(pamh, LOG_DEBUG,
|
|
Packit Service |
b29381 |
"user '%s' unknown to this system", luser);
|
|
Packit Service |
b29381 |
return PAM_USER_UNKNOWN;
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
}
|
|
Packit Service |
b29381 |
as_root = (lpwd->pw_uid == 0);
|
|
Packit Service |
b29381 |
}
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
#ifdef HAVE_RUSEROK_AF
|
|
Packit Service |
b29381 |
retval = ruserok_af (rhost, as_root, ruser, luser, PF_UNSPEC);
|
|
Packit Service |
b29381 |
#else
|
|
Packit Service |
b29381 |
retval = ruserok (rhost, as_root, ruser, luser);
|
|
Packit Service |
b29381 |
#endif
|
|
Packit Service |
b29381 |
if (retval != 0) {
|
|
Packit Service |
b29381 |
if (!opt_silent || opt_debug)
|
|
Packit Service |
b29381 |
pam_syslog(pamh, LOG_WARNING, "denied access to %s@%s as %s",
|
|
Packit Service |
b29381 |
ruser, rhost, luser);
|
|
Packit Service |
b29381 |
return PAM_AUTH_ERR;
|
|
Packit Service |
b29381 |
} else {
|
|
Packit Service |
b29381 |
if (!opt_silent || opt_debug)
|
|
Packit Service |
b29381 |
pam_syslog(pamh, LOG_NOTICE, "allowed access to %s@%s as %s",
|
|
Packit Service |
b29381 |
ruser, rhost, luser);
|
|
Packit Service |
b29381 |
return PAM_SUCCESS;
|
|
Packit Service |
b29381 |
}
|
|
Packit Service |
b29381 |
}
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
|
|
Packit Service |
b29381 |
int
|
|
Packit Service |
b29381 |
pam_sm_setcred (pam_handle_t *pamh UNUSED, int flags UNUSED,
|
|
Packit Service |
b29381 |
int argc UNUSED, const char **argv UNUSED)
|
|
Packit Service |
b29381 |
{
|
|
Packit Service |
b29381 |
return PAM_SUCCESS;
|
|
Packit Service |
b29381 |
}
|