ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose/*
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose Authors:
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose Sumit Bose <sbose@redhat.com>
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose Copyright (C) 2015 Red Hat
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SSSD tests: PAM responder tests
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose This program is free software; you can redistribute it and/or modify
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose it under the terms of the GNU General Public License as published by
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose the Free Software Foundation; either version 3 of the License, or
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose (at your option) any later version.
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose This program is distributed in the hope that it will be useful,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose GNU General Public License for more details.
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose You should have received a copy of the GNU General Public License
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose*/
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include <security/pam_modules.h>
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include <popt.h>
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include "tests/cmocka/common_mock.h"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include "tests/cmocka/common_mock_resp.h"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include "responder/common/responder_packet.h"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include "responder/common/negcache.h"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include "responder/pam/pamsrv.h"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include "responder/pam/pam_helpers.h"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include "sss_client/pam_message.h"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include "sss_client/sss_cli.h"
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose#include "confdb/confdb.h"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose#include "util/crypto/sss_crypto.h"
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose#ifdef HAVE_NSS
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#include "util/crypto/nss/nss_util.h"
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose#endif
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#ifdef HAVE_TEST_CA
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#include "tests/test_CA/SSSD_test_cert_x509_0001.h"
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#include "tests/test_CA/SSSD_test_cert_x509_0002.h"
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#else
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#define SSSD_TEST_CERT_0001 ""
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#define SSSD_TEST_CERT_0002 ""
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#endif
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose
50c9d542e8bf641412debaa82a4dcf67ddb72258Lukas Slebodnik#define TESTS_PATH "tp_" BASE_FILE_STEM
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#define TEST_CONF_DB "test_pam_conf.ldb"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#define TEST_DOM_NAME "pam_test"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#define TEST_SUBDOM_NAME "test.subdomain"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#define TEST_ID_PROVIDER "ldap"
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
0f99ab0ad35700f7eff4809a7f4859635311ba6dLukas Slebodnik#define NSS_DB_PATH TESTS_PATH
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose#define NSS_DB "sql:"NSS_DB_PATH
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose#define NSS_DB_PATH_2CERTS TESTS_PATH "_2certs"
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose#define NSS_DB_2CERTS "sql:"NSS_DB_PATH_2CERTS
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose#define TEST_TOKEN_NAME "SSSD Test Token"
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose#define TEST_MODULE_NAME "NSS-Internal"
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#define TEST_KEY_ID "C554C9F82C2A9D58B70921C143304153A8A42F17"
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#define TEST_PROMPT "SSSD test cert 0001 - SSSD\nCN=SSSD test cert 0001,OU=SSSD test,O=SSSD"
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#define TEST2_KEY_ID "5405842D56CF31F0BB025A695C5F3E907051C5B9"
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#define TEST2_PROMPT "SSSD test cert 0002 - SSSD\nCN=SSSD test cert 0002,OU=SSSD test,O=SSSD"
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
6574e41a8d1c2af293df2f57916628344eaa3560Lukas Slebodnikstatic char CACHED_AUTH_TIMEOUT_STR[] = "4";
6574e41a8d1c2af293df2f57916628344eaa3560Lukas Slebodnikstatic const int CACHED_AUTH_TIMEOUT = 4;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosestruct pam_test_ctx {
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose struct sss_test_ctx *tctx;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose struct sss_domain_info *subdom;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose struct resp_ctx *rctx;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose struct cli_ctx *cctx;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose struct sss_cmd_table *pam_cmds;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose struct pam_ctx *pctx;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ncache_hits;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int exp_pam_status;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl bool provider_contacted;
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek const char *pam_user_fqdn;
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek const char *wrong_user_fqdn;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose};
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose/* Must be global because it is needed in some wrappers */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosestruct pam_test_ctx *pam_test_ctx;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosestatic errno_t setup_nss_db(void)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose FILE *fp;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int status;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pid_t child_pid;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = mkdir(NSS_DB_PATH, 0775);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (ret != EOK) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "Failed to create " NSS_DB_PATH ".\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = mkdir(NSS_DB_PATH_2CERTS, 0775);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (ret != EOK) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose "Failed to create " NSS_DB_PATH_2CERTS ".\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose return ret;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose child_pid = fork();
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (child_pid == 0) { /* child */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = execlp("certutil", "certutil", "-N", "--empty-password", "-d",
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose NSS_DB, NULL);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (ret == -1) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "execl() failed.\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose exit(-1);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose } else if (child_pid > 0) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose wait(&status);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose } else {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = errno;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "fork() failed\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose child_pid = fork();
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (child_pid == 0) { /* child */
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = execlp("certutil", "certutil", "-N", "--empty-password", "-d",
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose NSS_DB_2CERTS, NULL);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (ret == -1) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "execl() failed.\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose exit(-1);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose } else if (child_pid > 0) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose wait(&status);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose } else {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = errno;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "fork() failed\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose return ret;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose fp = fopen(NSS_DB_PATH"/pkcs11.txt", "w");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (fp == NULL) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "fopen() failed.\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = fprintf(fp, "library=libsoftokn3.so\nname=soft\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (ret < 0) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "fprintf() failed.\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose ret = fprintf(fp, "parameters=configdir='sql:%s/src/tests/test_CA/p11_nssdb' dbSlotDescription='SSSD Test Slot' dbTokenDescription='SSSD Test Token' secmod='secmod.db' flags=readOnly \n\n", ABS_BUILD_DIR);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (ret < 0) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "fprintf() failed.\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = fclose(fp);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (ret != 0) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "fclose() failed.\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose fp = fopen(NSS_DB_PATH_2CERTS"/pkcs11.txt", "w");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (fp == NULL) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "fopen() failed.\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose return ret;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = fprintf(fp, "library=libsoftokn3.so\nname=soft\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (ret < 0) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "fprintf() failed.\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose return ret;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose ret = fprintf(fp, "parameters=configdir='sql:%s/src/tests/test_CA/p11_nssdb_2certs' dbSlotDescription='SSSD Test Slot' dbTokenDescription='SSSD Test Token' secmod='secmod.db' flags=readOnly \n\n", ABS_BUILD_DIR);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (ret < 0) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "fprintf() failed.\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose return ret;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = fclose(fp);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (ret != 0) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "fclose() failed.\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose return ret;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return EOK;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosestatic void cleanup_nss_db(void)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = unlink(NSS_DB_PATH"/cert9.db");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (ret != EOK) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Failed to remove cert9.db.\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = unlink(NSS_DB_PATH"/key4.db");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (ret != EOK) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Failed to remove key4.db.\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = unlink(NSS_DB_PATH"/pkcs11.txt");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (ret != EOK) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Failed to remove pkcs11.db.\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = rmdir(NSS_DB_PATH);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (ret != EOK) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Failed to remove " NSS_DB_PATH "\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = unlink(NSS_DB_PATH_2CERTS"/cert9.db");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (ret != EOK) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Failed to remove cert9.db.\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = unlink(NSS_DB_PATH_2CERTS"/key4.db");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (ret != EOK) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Failed to remove key4.db.\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = unlink(NSS_DB_PATH_2CERTS"/pkcs11.txt");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (ret != EOK) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Failed to remove pkcs11.db.\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = rmdir(NSS_DB_PATH_2CERTS);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (ret != EOK) {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Failed to remove " NSS_DB_PATH "\n");
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosestruct pam_ctx *mock_pctx(TALLOC_CTX *mem_ctx)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose struct pam_ctx *pctx;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose errno_t ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pctx = talloc_zero(mem_ctx, struct pam_ctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_non_null(pctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_hash_create(pctx, 10, &pctx->id_table);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek /* Two NULLs so that tests can just assign a const to the first slot
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek * should they need it. The code iterates until first NULL anyway
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pctx->app_services = talloc_zero_array(pctx, char *, 2);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek if (pctx->app_services == NULL) {
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek talloc_free(pctx);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek return NULL;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek }
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
177ab84f0e336b75289a3ac0b2df25bd5ab5198bSumit Bose ret = p11_refresh_certmap_ctx(pctx, NULL);
177ab84f0e336b75289a3ac0b2df25bd5ab5198bSumit Bose assert_int_equal(ret, 0);
177ab84f0e336b75289a3ac0b2df25bd5ab5198bSumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return pctx;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bosestatic int add_confdb_params(struct sss_test_conf_param params[],
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose struct confdb_ctx *cdb, const char *section)
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek{
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek const char *val[2];
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek int ret;
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek val[1] = NULL;
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose for (int i = 0; params[i].key; i++) {
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose val[0] = params[i].value;
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose ret = confdb_add_param(cdb, true, section, params[i].key, val);
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek assert_int_equal(ret, EOK);
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek }
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek return EOK;
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek}
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bosestatic int add_pam_params(struct sss_test_conf_param pam_params[],
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose struct confdb_ctx *cdb)
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose{
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose return add_confdb_params(pam_params, cdb, CONFDB_PAM_CONF_ENTRY);
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose}
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bosestatic int add_monitor_params(struct sss_test_conf_param monitor_params[],
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose struct confdb_ctx *cdb)
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose{
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose return add_confdb_params(monitor_params, cdb, CONFDB_MONITOR_CONF_ENTRY);
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose}
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židekvoid test_pam_setup(struct sss_test_conf_param dom_params[],
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek struct sss_test_conf_param pam_params[],
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose struct sss_test_conf_param monitor_params[],
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *prctx;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose errno_t ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx = talloc_zero(NULL, struct pam_test_ctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_non_null(pam_test_ctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->tctx = create_dom_test_ctx(pam_test_ctx, TESTS_PATH,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose TEST_CONF_DB, TEST_DOM_NAME,
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek TEST_ID_PROVIDER, dom_params);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_non_null(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds = get_pam_cmds();
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_non_null(pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* FIXME - perhaps this should be folded into sssd_domain_init or strictly
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose * used together
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_names_init(pam_test_ctx, pam_test_ctx->tctx->confdb,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose TEST_DOM_NAME, &pam_test_ctx->tctx->dom->names);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Initialize the PAM responder */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pctx = mock_pctx(pam_test_ctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_non_null(pam_test_ctx->pctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->rctx = mock_rctx(pam_test_ctx, pam_test_ctx->tctx->ev,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->tctx->dom, pam_test_ctx->pctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_non_null(pam_test_ctx->rctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->rctx->cdb = pam_test_ctx->tctx->confdb;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pctx->rctx = pam_test_ctx->rctx;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek assert_int_equal(ret, EOK);
ab3c0e05d18616295afbd46acad1ca243b33861cMichal Židek
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose ret = add_monitor_params(monitor_params, pam_test_ctx->rctx->cdb);
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose assert_int_equal(ret, EOK);
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Create client context */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->cctx = mock_cctx(pam_test_ctx, pam_test_ctx->rctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_non_null(pam_test_ctx->cctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->cctx->ev = pam_test_ctx->tctx->ev;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce prctx = mock_prctx(pam_test_ctx->cctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce assert_non_null(prctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce pam_test_ctx->cctx->protocol_ctx = prctx;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce prctx->cli_protocol_version = register_cli_protocol_version();
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichlstatic void pam_test_setup_common(void)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl errno_t ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn = \
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek sss_create_internal_fqname(pam_test_ctx,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "pamuser",
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->tctx->dom->name);
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek assert_non_null(pam_test_ctx->pam_user_fqdn);
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->wrong_user_fqdn = \
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek sss_create_internal_fqname(pam_test_ctx,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "wronguser",
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->tctx->dom->name);
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek assert_non_null(pam_test_ctx->wrong_user_fqdn);
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose /* integer values cannot be set by pam_params */
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose pam_test_ctx->pctx->id_timeout = 5;
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Prime the cache with a valid user */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sysdb_add_user(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek 123, 456, "pam user",
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose "/home/pamuser", "/bin/sh", NULL,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose NULL, 300, 0);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Add entry to the initgr cache to make sure no initgr request is sent to
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose * the backend */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = pam_initgr_cache_set(pam_test_ctx->pctx->rctx->ev,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pctx->id_table,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose discard_const("pamuser"),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pctx->id_timeout);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose /* Prime the cache with a user for wrong matches */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = sysdb_add_user(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->wrong_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek 321, 654, "wrong user",
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "/home/wronguser", "/bin/sh", NULL,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose NULL, 300, 0);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose /* Add entry to the initgr cache to make sure no initgr request is sent to
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose * the backend */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = pam_initgr_cache_set(pam_test_ctx->pctx->rctx->ev,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pctx->id_table,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose discard_const("wronguser"),
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pctx->id_timeout);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl}
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichlstatic int pam_test_setup(void **state)
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl{
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl struct sss_test_conf_param dom_params[] = {
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl { "enumerate", "false" },
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl { "cache_credentials", "true" },
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl { NULL, NULL }, /* Sentinel */
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl };
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl struct sss_test_conf_param pam_params[] = {
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl { "p11_child_timeout", "30" },
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl { NULL, NULL }, /* Sentinel */
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl };
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose struct sss_test_conf_param monitor_params[] = {
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose { "certificate_verification", "no_ocsp"},
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose { NULL, NULL }, /* Sentinel */
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose };
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose test_pam_setup(dom_params, pam_params, monitor_params, state);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
6411cd6074688762f793de8f1dddeffcb3a71d02Pavel Reichl pam_test_setup_common();
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return 0;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#ifdef HAVE_TEST_CA
ef045ad7616667e5d824d9ac326b461f9bb1d8cfLukas Slebodnik#ifdef HAVE_NSS
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bosestatic int pam_test_setup_no_verification(void **state)
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose{
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose struct sss_test_conf_param dom_params[] = {
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose { "enumerate", "false" },
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose { "cache_credentials", "true" },
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose { NULL, NULL }, /* Sentinel */
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose };
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose struct sss_test_conf_param pam_params[] = {
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose { "p11_child_timeout", "30" },
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose { NULL, NULL }, /* Sentinel */
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose };
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose struct sss_test_conf_param monitor_params[] = {
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose { "certificate_verification", "no_verification" },
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose { NULL, NULL }, /* Sentinel */
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose };
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose test_pam_setup(dom_params, pam_params, monitor_params, state);
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose pam_test_setup_common();
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose return 0;
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose}
ef045ad7616667e5d824d9ac326b461f9bb1d8cfLukas Slebodnik#endif /* HAVE_NSS */
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#endif /* HAVE_TEST_CA */
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichlstatic int pam_cached_test_setup(void **state)
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl{
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl struct sss_test_conf_param dom_params[] = {
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl { "enumerate", "false" },
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl { "cache_credentials", "true" },
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl { "cached_auth_timeout", CACHED_AUTH_TIMEOUT_STR },
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl { NULL, NULL }, /* Sentinel */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl };
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl struct sss_test_conf_param pam_params[] = {
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl { "p11_child_timeout", "30" },
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl { NULL, NULL }, /* Sentinel */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl };
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose struct sss_test_conf_param monitor_params[] = {
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose { "certificate_verification", "no_ocsp"},
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose { NULL, NULL }, /* Sentinel */
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose };
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose
544a20de7667f05c1a406c4dea0706b0ab507430Sumit Bose test_pam_setup(dom_params, pam_params, monitor_params, state);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_setup_common();
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl return 0;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl}
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosestatic int pam_test_teardown(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_delete_user(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn, 0);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_delete_user(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->wrong_user_fqdn, 0);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose talloc_free(pam_test_ctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return 0;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosetypedef int (*cmd_cb_fn_t)(uint32_t, uint8_t *, size_t);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Boseint __real_read_pipe_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose uint8_t **buf, ssize_t *len);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid __real_sss_packet_get_body(struct sss_packet *packet,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint8_t **body, size_t *blen);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid __wrap_sss_packet_get_body(struct sss_packet *packet,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint8_t **body, size_t *blen)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose enum sss_test_wrapper_call wtype = sss_mock_type(enum sss_test_wrapper_call);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose size_t len;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose if (wtype == WRAP_CALL_REAL) {
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return __real_sss_packet_get_body(packet, body, blen);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose }
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose *body = sss_mock_ptr_type(uint8_t *);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose len = sss_mock_type(size_t);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose if (len == 0) {
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose len = strlen((const char *) *body) + 1;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose }
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose *blen = len;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid __real_sss_packet_get_body(struct sss_packet *packet,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint8_t **body, size_t *blen);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid __wrap_sss_cmd_done(struct cli_ctx *cctx, void *freectx)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *prctx;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct sss_packet *packet;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint8_t *body;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose size_t blen;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmd_cb_fn_t check_cb;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce prctx = talloc_get_type(cctx->protocol_ctx, struct cli_protocol);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce packet = prctx->creq->out;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_non_null(packet);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose check_cb = sss_mock_ptr_type(cmd_cb_fn_t);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose __real_sss_packet_get_body(packet, &body, &blen);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->tctx->error = check_cb(sss_packet_get_status(packet),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose body, blen);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->tctx->done = true;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Boseenum sss_cli_command __wrap_sss_packet_get_cmd(struct sss_packet *packet)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return sss_mock_type(enum sss_cli_command);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Boseint __wrap_sss_cmd_send_empty(struct cli_ctx *cctx, TALLOC_CTX *freectx)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->tctx->done = true;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->tctx->error = ENOENT;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return EOK;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosestatic void set_cmd_cb(cmd_cb_fn_t fn)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_cmd_done, fn);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Boseint __wrap_pam_dp_send_req(struct pam_auth_req *preq, int timeout)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_ctx->provider_contacted = true;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Set expected status */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose preq->pd->pam_status = pam_test_ctx->exp_pam_status;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose preq->callback(preq);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return EOK;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozekstatic void mock_input_pam_ex(TALLOC_CTX *mem_ctx,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek const char *name,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek const char *pwd,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek const char *fa2,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek const char *svc,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek bool contact_dp)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose size_t buf_size;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint8_t *m_buf;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint8_t *buf;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose struct pam_items pi = { 0 };
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose size_t needed_size;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint8_t *authtok;
29d063505c07127f7747405b1a61d8f782673645Sumit Bose char *s_name;
29d063505c07127f7747405b1a61d8f782673645Sumit Bose char *dom;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (name != NULL) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_user = name;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_user_size = strlen(pi.pam_user) + 1;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose } else {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_user = "";
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_user_size = 0;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose if (pwd != NULL) {
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose if (fa2 != NULL) {
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_auth_pack_2fa_blob(pwd, 0, fa2, 0, NULL, 0, &needed_size);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EAGAIN);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose authtok = talloc_size(mem_ctx, needed_size);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_non_null(authtok);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_auth_pack_2fa_blob(pwd, 0, fa2, 0, authtok,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose needed_size, &needed_size);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_authtok = (char *) authtok;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_authtok_size = needed_size;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_authtok_type = SSS_AUTHTOK_TYPE_2FA;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose } else {
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_authtok = discard_const(pwd);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_authtok_size = strlen(pi.pam_authtok) + 1;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_authtok_type = SSS_AUTHTOK_TYPE_PASSWORD;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose }
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose }
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek if (svc == NULL) {
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek svc = "pam_test_service";
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek }
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pi.pam_service = svc;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_service_size = strlen(pi.pam_service) + 1;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_tty = "/dev/tty";
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_tty_size = strlen(pi.pam_tty) + 1;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_ruser = "remuser";
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_ruser_size = strlen(pi.pam_ruser) + 1;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_rhost = "remhost";
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.pam_rhost_size = strlen(pi.pam_rhost) + 1;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.requested_domains = "";
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pi.cli_pid = 12345;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = pack_message_v3(&pi, &buf_size, &m_buf);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, 0);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose buf = talloc_memdup(mem_ctx, m_buf, buf_size);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose free(m_buf);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_non_null(buf);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, buf);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, buf_size);
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio
29d063505c07127f7747405b1a61d8f782673645Sumit Bose if (strrchr(name, '@') == NULL) {
29d063505c07127f7747405b1a61d8f782673645Sumit Bose mock_parse_inp(name, NULL, EOK);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose } else {
29d063505c07127f7747405b1a61d8f782673645Sumit Bose ret = sss_parse_internal_fqname(mem_ctx, name, &s_name, &dom);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose mock_parse_inp(s_name, dom, EOK);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose }
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek if (contact_dp) {
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek mock_account_recv_simple();
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek }
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek}
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozekstatic void mock_input_pam(TALLOC_CTX *mem_ctx,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek const char *name,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek const char *pwd,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek const char *fa2)
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek{
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek return mock_input_pam_ex(mem_ctx, name, pwd, fa2, NULL, true);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosestatic void mock_input_pam_cert(TALLOC_CTX *mem_ctx, const char *name,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose const char *pin, const char *token_name,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose const char *module_name, const char *key_id,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose const char *service,
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio acct_cb_t acct_cb, const char *cert,
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio bool only_one_provider_call)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose size_t buf_size;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose uint8_t *m_buf;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose uint8_t *buf;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose struct pam_items pi = { 0 };
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio bool already_mocked = false;
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose size_t needed_size;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (name != NULL) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_user = name;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_user_size = strlen(pi.pam_user) + 1;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose } else {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_user = "";
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_user_size = 0;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (pin != NULL) {
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose ret = sss_auth_pack_sc_blob(pin, 0, token_name, 0, module_name, 0,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose key_id, 0, NULL, 0, &needed_size);
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose assert_int_equal(ret, EAGAIN);
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose pi.pam_authtok = malloc(needed_size);
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose assert_non_null(pi.pam_authtok);
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose ret = sss_auth_pack_sc_blob(pin, 0, token_name, 0, module_name, 0,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose key_id, 0,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose (uint8_t *)pi.pam_authtok, needed_size,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose &needed_size);
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose assert_int_equal(ret, EOK);
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_authtok_type = SSS_AUTHTOK_TYPE_SC_PIN;
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose pi.pam_authtok_size = needed_size;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose pi.pam_service = service == NULL ? "login" : service;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_service_size = strlen(pi.pam_service) + 1;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_tty = "/dev/tty";
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_tty_size = strlen(pi.pam_tty) + 1;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_ruser = "remuser";
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_ruser_size = strlen(pi.pam_ruser) + 1;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_rhost = "remhost";
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.pam_rhost_size = strlen(pi.pam_rhost) + 1;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.requested_domains = "";
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pi.cli_pid = 12345;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = pack_message_v3(&pi, &buf_size, &m_buf);
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose free(pi.pam_authtok);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, 0);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose buf = talloc_memdup(mem_ctx, m_buf, buf_size);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose free(m_buf);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_non_null(buf);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, buf);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, buf_size);
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio if (acct_cb != NULL) {
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio mock_account_recv(0, 0, NULL, acct_cb, discard_const(cert));
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio already_mocked = true;
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio }
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio if (name != NULL) {
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio mock_parse_inp(name, NULL, EOK);
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio if (!(only_one_provider_call && already_mocked)) {
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio mock_account_recv_simple();
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio }
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosestatic int test_pam_simple_check(uint32_t status, uint8_t *body, size_t blen)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose size_t rp = 0;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint32_t val;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(status, 0);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, pam_test_ctx->exp_pam_status);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, 1);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, SSS_PAM_DOMAIN_NAME);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, 9);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(*(body + rp + val - 1), 0);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_string_equal(body + rp, TEST_DOM_NAME);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return EOK;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose#define PKCS11_LOGIN_TOKEN_ENV_NAME "PKCS11_LOGIN_TOKEN_NAME"
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bosestatic int test_pam_cert_check_gdm_smartcard(uint32_t status, uint8_t *body,
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose size_t blen)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose size_t rp = 0;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose uint32_t val;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(status, 0);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(val, pam_test_ctx->exp_pam_status);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose assert_int_equal(val, 3);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(val, SSS_PAM_DOMAIN_NAME);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(val, 9);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(*(body + rp + val - 1), 0);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_string_equal(body + rp, TEST_DOM_NAME);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose rp += val;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose assert_int_equal(val, SSS_PAM_ENV_ITEM);
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose assert_int_equal(val, (strlen(PKCS11_LOGIN_TOKEN_ENV_NAME "=")
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose + sizeof(TEST_TOKEN_NAME)));
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose assert_string_equal(body + rp,
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose PKCS11_LOGIN_TOKEN_ENV_NAME "=" TEST_TOKEN_NAME);
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose rp += val;
d86224608ff60ec5cc7e7cbf9e53d8a04e083530Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(val, SSS_PAM_CERT_INFO);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_int_equal(val, (sizeof("pamuser@"TEST_DOM_NAME)
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose + sizeof(TEST_TOKEN_NAME)
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose + sizeof(TEST_MODULE_NAME)
06c2300353faf3983e38fecb1d6afe1f6cc8fe32Sumit Bose + sizeof(TEST_KEY_ID)
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose + sizeof(TEST_PROMPT)));
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
3649b959709f1ab187092f054d4aace0798c98faSumit Bose assert_int_equal(*(body + rp + sizeof("pamuser@"TEST_DOM_NAME) - 1), 0);
3649b959709f1ab187092f054d4aace0798c98faSumit Bose assert_string_equal(body + rp, "pamuser@"TEST_DOM_NAME);
3649b959709f1ab187092f054d4aace0798c98faSumit Bose rp += sizeof("pamuser@"TEST_DOM_NAME);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST_TOKEN_NAME) - 1), 0);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_string_equal(body + rp, TEST_TOKEN_NAME);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose rp += sizeof(TEST_TOKEN_NAME);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST_MODULE_NAME) - 1), 0);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_string_equal(body + rp, TEST_MODULE_NAME);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose rp += sizeof(TEST_MODULE_NAME);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST_KEY_ID) - 1), 0);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_string_equal(body + rp, TEST_KEY_ID);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose rp += sizeof(TEST_KEY_ID);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST_PROMPT) - 1), 0);
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose assert_string_equal(body + rp, TEST_PROMPT);
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose rp += sizeof(TEST_PROMPT);
06c2300353faf3983e38fecb1d6afe1f6cc8fe32Sumit Bose
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_int_equal(rp, blen);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return EOK;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bosestatic int test_pam_cert_check_ex(uint32_t status, uint8_t *body, size_t blen,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose enum response_type type, const char *name,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose const char *name2)
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose{
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose size_t rp = 0;
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose uint32_t val;
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose assert_int_equal(status, 0);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose assert_int_equal(val, pam_test_ctx->exp_pam_status);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose if (name == NULL || *name == '\0') {
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(val, 1);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose } else {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (name2 == NULL || *name2 == '\0') {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(val, 2);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose } else {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(val, 3);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(val, SSS_PAM_DOMAIN_NAME);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(val, 9);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(*(body + rp + val - 1), 0);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_string_equal(body + rp, TEST_DOM_NAME);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose rp += val;
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose }
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(val, type);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(val, (strlen(name) + 1
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose + sizeof(TEST_TOKEN_NAME)
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose + sizeof(TEST_MODULE_NAME)
06c2300353faf3983e38fecb1d6afe1f6cc8fe32Sumit Bose + sizeof(TEST_KEY_ID)
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose + sizeof(TEST_PROMPT)));
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(*(body + rp + strlen(name)), 0);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_string_equal(body + rp, name);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose rp += strlen(name) + 1;
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST_TOKEN_NAME) - 1), 0);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose assert_string_equal(body + rp, TEST_TOKEN_NAME);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose rp += sizeof(TEST_TOKEN_NAME);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST_MODULE_NAME) - 1), 0);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_string_equal(body + rp, TEST_MODULE_NAME);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose rp += sizeof(TEST_MODULE_NAME);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST_KEY_ID) - 1), 0);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_string_equal(body + rp, TEST_KEY_ID);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose rp += sizeof(TEST_KEY_ID);
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST_PROMPT) - 1), 0);
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose assert_string_equal(body + rp, TEST_PROMPT);
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose rp += sizeof(TEST_PROMPT);
06c2300353faf3983e38fecb1d6afe1f6cc8fe32Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose if (name2 != NULL && *name2 != '\0') {
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(val, type);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(val, (strlen(name) + 1
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose + sizeof(TEST_TOKEN_NAME)
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose + sizeof(TEST_MODULE_NAME)
06c2300353faf3983e38fecb1d6afe1f6cc8fe32Sumit Bose + sizeof(TEST2_KEY_ID)
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose + sizeof(TEST2_PROMPT)));
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(*(body + rp + strlen(name)), 0);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_string_equal(body + rp, name);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose rp += strlen(name) + 1;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST_TOKEN_NAME) - 1), 0);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_string_equal(body + rp, TEST_TOKEN_NAME);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose rp += sizeof(TEST_TOKEN_NAME);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST_MODULE_NAME) - 1), 0);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_string_equal(body + rp, TEST_MODULE_NAME);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose rp += sizeof(TEST_MODULE_NAME);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST2_KEY_ID) - 1), 0);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_string_equal(body + rp, TEST2_KEY_ID);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose rp += sizeof(TEST2_KEY_ID);
06c2300353faf3983e38fecb1d6afe1f6cc8fe32Sumit Bose
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose assert_int_equal(*(body + rp + sizeof(TEST2_PROMPT) - 1), 0);
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose assert_string_equal(body + rp, TEST2_PROMPT);
57cefea8305a57c1c0491afb739813b7f17d5a25Sumit Bose rp += sizeof(TEST2_PROMPT);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose }
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
ead25e32c52c8c2f5fd9abd179e9e81de58f9ca3Sumit Bose assert_int_equal(rp, blen);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose return EOK;
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bosestatic int test_pam_cert_check(uint32_t status, uint8_t *body, size_t blen)
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose{
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose return test_pam_cert_check_ex(status, body, blen,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose SSS_PAM_CERT_INFO, "pamuser@"TEST_DOM_NAME,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose NULL);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose}
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bosestatic int test_pam_cert_check_auth_success(uint32_t status, uint8_t *body,
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose size_t blen)
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose{
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose assert_int_equal(pam_test_ctx->exp_pam_status, PAM_BAD_ITEM);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose pam_test_ctx->exp_pam_status = PAM_SUCCESS;
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose return test_pam_cert_check_ex(status, body, blen,
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose SSS_PAM_CERT_INFO, "pamuser@"TEST_DOM_NAME,
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose NULL);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose}
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bosestatic int test_pam_cert_check_with_hint(uint32_t status, uint8_t *body,
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose size_t blen)
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose{
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose return test_pam_cert_check_ex(status, body, blen,
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose SSS_PAM_CERT_INFO_WITH_HINT,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose "pamuser@"TEST_DOM_NAME, NULL);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose}
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bosestatic int test_pam_cert_check_with_hint_no_user(uint32_t status, uint8_t *body,
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose size_t blen)
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose{
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose return test_pam_cert_check_ex(status, body, blen,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose SSS_PAM_CERT_INFO_WITH_HINT, "", NULL);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose}
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bosestatic int test_pam_cert_check_2certs(uint32_t status, uint8_t *body,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose size_t blen)
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose{
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose return test_pam_cert_check_ex(status, body, blen,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose SSS_PAM_CERT_INFO, "pamuser@"TEST_DOM_NAME,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose "pamuser@"TEST_DOM_NAME);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose}
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosestatic int test_pam_offline_chauthtok_check(uint32_t status,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint8_t *body, size_t blen)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose size_t rp = 0;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint32_t val;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHTOK_ERR;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(status, 0);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, pam_test_ctx->exp_pam_status);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, 2);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, SSS_PAM_DOMAIN_NAME);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, 9);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(*(body + rp + val - 1), 0);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_string_equal(body + rp, TEST_DOM_NAME);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose rp += val;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, SSS_PAM_USER_INFO);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, 4);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(val, SSS_PAM_USER_INFO_OFFLINE_CHPASS);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return EOK;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosestatic int test_pam_failed_offline_auth_check(uint32_t status, uint8_t *body,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose size_t blen)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_PERM_DENIED;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return test_pam_simple_check(status, body, blen);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosestatic int test_pam_successful_offline_auth_check(uint32_t status,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint8_t *body, size_t blen)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_SUCCESS;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return test_pam_simple_check(status, body, blen);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichlstatic int test_pam_successful_cached_auth_check(uint32_t status,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl uint8_t *body, size_t blen)
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl{
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_ctx->exp_pam_status = PAM_SUCCESS;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl return test_pam_simple_check(status, body, blen);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl}
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosestatic int test_pam_wrong_pw_offline_auth_check(uint32_t status,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose uint8_t *body, size_t blen)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTH_ERR;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return test_pam_simple_check(status, body, blen);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bosestatic int test_pam_simple_check_success(uint32_t status,
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose uint8_t *body, size_t blen)
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose{
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose pam_test_ctx->exp_pam_status = PAM_SUCCESS;
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose return test_pam_simple_check(status, body, blen);
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose}
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bosestatic int test_pam_creds_insufficient_check(uint32_t status,
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose uint8_t *body, size_t blen)
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose{
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose size_t rp = 0;
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose uint32_t val;
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose assert_int_equal(status, 0);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose assert_int_equal(val, PAM_CRED_INSUFFICIENT);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose assert_int_equal(val, 0);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose return EOK;
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose}
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosestatic int test_pam_user_unknown_check(uint32_t status,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose uint8_t *body, size_t blen)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose size_t rp = 0;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose uint32_t val;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(status, 0);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(val, PAM_USER_UNKNOWN);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(val, 0);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return EOK;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_authenticate(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_simple_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_setcreds(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_SETCRED);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_simple_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_SETCRED,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_acct_mgmt(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_ACCT_MGMT);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_simple_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_ACCT_MGMT,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_open_session(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_OPEN_SESSION);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
254f3898cc9fb9d76e12d72a2955906c49748e6dSumit Bose /* make sure pam_status is not touched by setting it to a value which is
254f3898cc9fb9d76e12d72a2955906c49748e6dSumit Bose * not used by SSSD. */
254f3898cc9fb9d76e12d72a2955906c49748e6dSumit Bose pam_test_ctx->exp_pam_status = _PAM_RETURN_VALUES;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_simple_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_OPEN_SESSION,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_close_session(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_CLOSE_SESSION);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_simple_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_CLOSE_SESSION,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_chauthtok(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_CHAUTHTOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_simple_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_CHAUTHTOK,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_chauthtok_prelim(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_CHAUTHTOK_PRELIM);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_simple_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_CHAUTHTOK_PRELIM,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_preauth(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_simple_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl/* Cached on-line authentication */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichlstatic void common_test_pam_cached_auth(const char *pwd)
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl{
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl int ret;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl mock_input_pam(pam_test_ctx, "pamuser", pwd, NULL);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_ctx->exp_pam_status = PAM_SUCCESS;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl set_cmd_cb(test_pam_successful_cached_auth_check);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_ctx->pam_cmds);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl /* Wait until the test finishes with EOK */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl ret = test_ev_loop(pam_test_ctx->tctx);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl}
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichlvoid test_pam_cached_auth_success(void **state)
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl{
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl int ret;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl common_test_pam_cached_auth("12345");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl /* Back end should be contacted */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_true(pam_test_ctx->provider_contacted);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_cache_password(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl /* Reset before next call */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_ctx->provider_contacted = false;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio pam_test_ctx->tctx->done = false;
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl common_test_pam_cached_auth("12345");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl /* Back end should not be contacted */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_false(pam_test_ctx->provider_contacted);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl}
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichlvoid test_pam_cached_auth_wrong_pw(void **state)
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl{
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl int ret;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_cache_password(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl ret = pam_set_last_online_auth_with_curr_token(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek time(NULL));
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl common_test_pam_cached_auth("11111");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl /* Back end should be contacted */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_true(pam_test_ctx->provider_contacted);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl}
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl/* test cached_auth_timeout option */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichlvoid test_pam_cached_auth_opt_timeout(void **state)
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl{
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl int ret;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl uint64_t last_online;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_cache_password(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl last_online = time(NULL) - CACHED_AUTH_TIMEOUT - 1;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl ret = pam_set_last_online_auth_with_curr_token(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl last_online);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl common_test_pam_cached_auth("12345");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl /* Back end should be contacted */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_true(pam_test_ctx->provider_contacted);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl}
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl/* too long since last on-line authentication */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichlvoid test_pam_cached_auth_timeout(void **state)
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl{
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl int ret;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_cache_password(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl ret = pam_set_last_online_auth_with_curr_token(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek 0);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl common_test_pam_cached_auth("12345");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl /* Back end should be contacted */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_true(pam_test_ctx->provider_contacted);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl}
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichlvoid test_pam_cached_auth_success_combined_pw_with_cached_2fa(void **state)
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl{
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl int ret;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl common_test_pam_cached_auth("12345678");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_true(pam_test_ctx->provider_contacted);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_cache_password_ex(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl "12345678", SSS_AUTHTOK_TYPE_2FA, 5);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl /* Reset before next call */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_ctx->provider_contacted = false;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio pam_test_ctx->tctx->done = false;
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl common_test_pam_cached_auth("12345678");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_false(pam_test_ctx->provider_contacted);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl}
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichlvoid test_pam_cached_auth_failed_combined_pw_with_cached_2fa(void **state)
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl{
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl int ret;
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_cache_password_ex(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl "12345678", SSS_AUTHTOK_TYPE_2FA, 5);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl ret = pam_set_last_online_auth_with_curr_token(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek time(NULL));
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_int_equal(ret, EOK);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl common_test_pam_cached_auth("1111abcde");
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl assert_true(pam_test_ctx->provider_contacted);
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl}
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl/* Off-line authentication */
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_no_hash(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "12345", NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_failed_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_success(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
29071a9e2df823a2cdc13cea996ece1c996e1172Michal Zidek ret = sysdb_cache_password(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345");
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "12345", NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_successful_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_wrong_pw(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_cache_password(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345");
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "11111", NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_wrong_pw_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_success_2fa(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
29071a9e2df823a2cdc13cea996ece1c996e1172Michal Zidek ret = sysdb_cache_password(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345");
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "12345", "abcde");
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_successful_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_failed_2fa(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
29071a9e2df823a2cdc13cea996ece1c996e1172Michal Zidek ret = sysdb_cache_password(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345");
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "11111", "abcde");
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_wrong_pw_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_success_2fa_with_cached_2fa(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
29071a9e2df823a2cdc13cea996ece1c996e1172Michal Zidek ret = sysdb_cache_password_ex(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345",
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SSS_AUTHTOK_TYPE_2FA, 5);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "12345", "abcde");
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_successful_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_failed_2fa_with_cached_2fa(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
29071a9e2df823a2cdc13cea996ece1c996e1172Michal Zidek ret = sysdb_cache_password_ex(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345",
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SSS_AUTHTOK_TYPE_2FA, 5);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "11111", "abcde");
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_wrong_pw_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_success_pw_with_cached_2fa(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
29071a9e2df823a2cdc13cea996ece1c996e1172Michal Zidek ret = sysdb_cache_password_ex(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345",
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SSS_AUTHTOK_TYPE_2FA, 5);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "12345", NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_successful_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_failed_pw_with_cached_2fa(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
29071a9e2df823a2cdc13cea996ece1c996e1172Michal Zidek ret = sysdb_cache_password_ex(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek "12345",
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SSS_AUTHTOK_TYPE_2FA, 5);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "11111", NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_wrong_pw_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_success_combined_pw_with_cached_2fa(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
29071a9e2df823a2cdc13cea996ece1c996e1172Michal Zidek ret = sysdb_cache_password_ex(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose "12345678", SSS_AUTHTOK_TYPE_2FA, 5);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "12345678abcde", NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_successful_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_failed_combined_pw_with_cached_2fa(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
29071a9e2df823a2cdc13cea996ece1c996e1172Michal Zidek ret = sysdb_cache_password_ex(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose "12345678", SSS_AUTHTOK_TYPE_2FA, 5);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "11111111abcde", NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_wrong_pw_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_auth_failed_wrong_2fa_size_with_cached_2fa(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
29071a9e2df823a2cdc13cea996ece1c996e1172Michal Zidek ret = sysdb_cache_password_ex(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose "12345678", SSS_AUTHTOK_TYPE_2FA, 5);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", "12345678abcd", NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_wrong_pw_offline_auth_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_chauthtok_prelim(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_CHAUTHTOK_PRELIM);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_offline_chauthtok_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_CHAUTHTOK_PRELIM,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bosevoid test_pam_offline_chauthtok(void **state)
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int ret;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose mock_input_pam(pam_test_ctx, "pamuser", NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_CHAUTHTOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->exp_pam_status = PAM_AUTHINFO_UNAVAIL;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose set_cmd_cb(test_pam_offline_chauthtok_check);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_CHAUTHTOK,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_ctx->pam_cmds);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Wait until the test finishes with EOK */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose assert_int_equal(ret, EOK);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bosevoid test_pam_preauth_no_logon_name(void **state)
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose{
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose int ret;
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose NULL, false);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose set_cmd_cb(test_pam_creds_insufficient_check);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose pam_test_ctx->pam_cmds);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose assert_int_equal(ret, EOK);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose /* Wait until the test finishes with EOK */
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose assert_int_equal(ret, EOK);
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose}
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bosevoid test_pam_auth_no_upn_logon_name(void **state)
29d063505c07127f7747405b1a61d8f782673645Sumit Bose{
29d063505c07127f7747405b1a61d8f782673645Sumit Bose int ret;
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose ret = sysdb_cache_password(pam_test_ctx->tctx->dom,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose pam_test_ctx->pam_user_fqdn,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose "12345");
29d063505c07127f7747405b1a61d8f782673645Sumit Bose assert_int_equal(ret, EOK);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose mock_input_pam_ex(pam_test_ctx, "upn@"TEST_DOM_NAME, "12345", NULL, NULL,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose true);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose mock_account_recv_simple();
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose pam_test_ctx->exp_pam_status = PAM_USER_UNKNOWN;
29d063505c07127f7747405b1a61d8f782673645Sumit Bose set_cmd_cb(test_pam_simple_check);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose pam_test_ctx->pam_cmds);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose assert_int_equal(ret, EOK);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose /* Wait until the test finishes with EOK */
29d063505c07127f7747405b1a61d8f782673645Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose assert_int_equal(ret, EOK);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose}
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bosevoid test_pam_auth_upn_logon_name(void **state)
29d063505c07127f7747405b1a61d8f782673645Sumit Bose{
29d063505c07127f7747405b1a61d8f782673645Sumit Bose int ret;
29d063505c07127f7747405b1a61d8f782673645Sumit Bose struct sysdb_attrs *attrs;
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose ret = sysdb_cache_password(pam_test_ctx->tctx->dom,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose pam_test_ctx->pam_user_fqdn,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose "12345");
29d063505c07127f7747405b1a61d8f782673645Sumit Bose assert_int_equal(ret, EOK);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose attrs = sysdb_new_attrs(pam_test_ctx);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose assert_non_null(attrs);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, "upn@"TEST_DOM_NAME);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose assert_int_equal(ret, EOK);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose ret = sysdb_set_user_attr(pam_test_ctx->tctx->dom,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose pam_test_ctx->pam_user_fqdn,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose attrs,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose LDB_FLAG_MOD_ADD);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose assert_int_equal(ret, EOK);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose mock_input_pam_ex(pam_test_ctx, "upn@"TEST_DOM_NAME, "12345", NULL, NULL,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose true);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose mock_account_recv_simple();
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose set_cmd_cb(test_pam_successful_offline_auth_check);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose pam_test_ctx->pam_cmds);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose assert_int_equal(ret, EOK);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose /* Wait until the test finishes with EOK */
29d063505c07127f7747405b1a61d8f782673645Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose assert_int_equal(ret, EOK);
29d063505c07127f7747405b1a61d8f782673645Sumit Bose}
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
29d063505c07127f7747405b1a61d8f782673645Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosestatic void set_cert_auth_param(struct pam_ctx *pctx, const char *dbpath)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pctx->cert_auth = true;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pctx->nss_db = discard_const(dbpath);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosevoid test_pam_preauth_cert_nocert(void **state)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, "/no/path");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, "pamuser", NULL, NULL, NULL, NULL, NULL,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose NULL, NULL, false);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cmd_cb(test_pam_simple_check);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pam_cmds);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose /* Wait until the test finishes with EOK */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosestatic int test_lookup_by_cert_cb(void *pvt)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose struct sysdb_attrs *attrs;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose unsigned char *der = NULL;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose size_t der_size;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (pvt != NULL) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose attrs = sysdb_new_attrs(pam_test_ctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_non_null(attrs);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose der = sss_base64_decode(pam_test_ctx, pvt, &der_size);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_non_null(der);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
81c564a0692aa4b719af2219f52894e6cd4bdf9fSumit Bose ret = sysdb_attrs_add_mem(attrs, SYSDB_USER_MAPPED_CERT, der, der_size);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose talloc_free(der);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_set_user_attr(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->pam_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek attrs,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose LDB_FLAG_MOD_ADD);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return EOK;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bosestatic int test_lookup_by_cert_cb_2nd_cert_same_user(void *pvt)
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose{
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose int ret;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose struct sysdb_attrs *attrs;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose unsigned char *der = NULL;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose size_t der_size;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose test_lookup_by_cert_cb(pvt);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose attrs = sysdb_new_attrs(pam_test_ctx);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_non_null(attrs);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose der = sss_base64_decode(pam_test_ctx, SSSD_TEST_CERT_0002, &der_size);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_non_null(der);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = sysdb_attrs_add_mem(attrs, SYSDB_USER_MAPPED_CERT, der, der_size);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose talloc_free(der);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(ret, EOK);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = sysdb_set_user_attr(pam_test_ctx->tctx->dom,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose pam_test_ctx->pam_user_fqdn,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose attrs,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose LDB_FLAG_MOD_ADD);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(ret, EOK);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose return EOK;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bosestatic int test_lookup_by_cert_double_cb(void *pvt)
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose{
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose int ret;
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose struct sysdb_attrs *attrs;
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose unsigned char *der = NULL;
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose size_t der_size;
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose if (pvt != NULL) {
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose ret = test_lookup_by_cert_cb(pvt);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose assert_int_equal(ret, EOK);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose attrs = sysdb_new_attrs(pam_test_ctx);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose assert_non_null(attrs);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose der = sss_base64_decode(pam_test_ctx, pvt, &der_size);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose assert_non_null(der);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
81c564a0692aa4b719af2219f52894e6cd4bdf9fSumit Bose ret = sysdb_attrs_add_mem(attrs, SYSDB_USER_MAPPED_CERT, der, der_size);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose talloc_free(der);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose assert_int_equal(ret, EOK);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose ret = sysdb_set_user_attr(pam_test_ctx->tctx->dom,
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose pam_test_ctx->wrong_user_fqdn,
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose attrs,
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose LDB_FLAG_MOD_ADD);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose assert_int_equal(ret, EOK);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose }
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose return EOK;
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose}
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosestatic int test_lookup_by_cert_wrong_user_cb(void *pvt)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose struct sysdb_attrs *attrs;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose unsigned char *der = NULL;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose size_t der_size;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (pvt != NULL) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose attrs = sysdb_new_attrs(pam_test_ctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_non_null(attrs);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose der = sss_base64_decode(pam_test_ctx, pvt, &der_size);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_non_null(der);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
81c564a0692aa4b719af2219f52894e6cd4bdf9fSumit Bose ret = sysdb_attrs_add_mem(attrs, SYSDB_USER_MAPPED_CERT, der, der_size);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose talloc_free(der);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek ret = sysdb_set_user_attr(pam_test_ctx->tctx->dom,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek pam_test_ctx->wrong_user_fqdn,
2b62d5a414b8b7dba4f714dc5033e28dc4b1f4feJakub Hrozek attrs,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose LDB_FLAG_MOD_ADD);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose return EOK;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosevoid test_pam_preauth_cert_nomatch(void **state)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, "pamuser", NULL, NULL, NULL, NULL, NULL,
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio test_lookup_by_cert_cb, NULL, false);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cmd_cb(test_pam_simple_check);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pam_cmds);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose /* Wait until the test finishes with EOK */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosevoid test_pam_preauth_cert_match(void **state)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, "pamuser", NULL, NULL, NULL, NULL, NULL,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose test_lookup_by_cert_cb, SSSD_TEST_CERT_0001, false);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cmd_cb(test_pam_cert_check);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pam_cmds);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose /* Wait until the test finishes with EOK */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose/* Test if PKCS11_LOGIN_TOKEN_NAME is added for the gdm-smartcard service */
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bosevoid test_pam_preauth_cert_match_gdm_smartcard(void **state)
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose{
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose int ret;
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, "pamuser", NULL, NULL, NULL, NULL,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose "gdm-smartcard", test_lookup_by_cert_cb,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose SSSD_TEST_CERT_0001, false);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose set_cmd_cb(test_pam_cert_check_gdm_smartcard);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose pam_test_ctx->pam_cmds);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose assert_int_equal(ret, EOK);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose /* Wait until the test finishes with EOK */
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose assert_int_equal(ret, EOK);
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose}
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosevoid test_pam_preauth_cert_match_wrong_user(void **state)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, "pamuser", NULL, NULL, NULL, NULL, NULL,
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio test_lookup_by_cert_wrong_user_cb,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose SSSD_TEST_CERT_0001, false);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cmd_cb(test_pam_simple_check);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pam_cmds);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose /* Wait until the test finishes with EOK */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosevoid test_pam_preauth_cert_no_logon_name(void **state)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio /* If no logon name is given the user is looked by certificate first.
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio * Since there is a matching user the upcoming lookup by name will find
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio * the user entry. But since we force the lookup by name to go to the
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio * backend to make sure the group-membership data is up to date the
89ff140d7ab92fce52d6730a7d27c8d73c7d9e4aSumit Bose * backend response has to be mocked twice.
89ff140d7ab92fce52d6730a7d27c8d73c7d9e4aSumit Bose * Additionally sss_parse_inp_recv() must be mocked because the cache
89ff140d7ab92fce52d6730a7d27c8d73c7d9e4aSumit Bose * request will be done with the username found by the certificate
89ff140d7ab92fce52d6730a7d27c8d73c7d9e4aSumit Bose * lookup. */
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, NULL, NULL, NULL, NULL, NULL, NULL,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose test_lookup_by_cert_cb, SSSD_TEST_CERT_0001, false);
89ff140d7ab92fce52d6730a7d27c8d73c7d9e4aSumit Bose mock_account_recv_simple();
89ff140d7ab92fce52d6730a7d27c8d73c7d9e4aSumit Bose mock_parse_inp("pamuser", NULL, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cmd_cb(test_pam_cert_check);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pam_cmds);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose /* Wait until the test finishes with EOK */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bosevoid test_pam_preauth_cert_no_logon_name_with_hint(void **state)
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose{
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose int ret;
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose pam_test_ctx->rctx->domains->user_name_hint = true;
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose /* If no logon name is given the user is looked by certificate first.
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose * Since user name hint is enabled we do not have to search the user
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose * during pre-auth and there is no need for an extra mocked response as in
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose * test_pam_preauth_cert_no_logon_name. */
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, NULL, NULL, NULL, NULL, NULL, NULL,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose test_lookup_by_cert_cb, SSSD_TEST_CERT_0001, false);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose set_cmd_cb(test_pam_cert_check_with_hint);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose pam_test_ctx->pam_cmds);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(ret, EOK);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose /* Wait until the test finishes with EOK */
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(ret, EOK);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose}
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bosevoid test_pam_preauth_cert_no_logon_name_double_cert(void **state)
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose{
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose int ret;
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, NULL, NULL, NULL, NULL, NULL, NULL,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose test_lookup_by_cert_double_cb, SSSD_TEST_CERT_0001,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose false);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose set_cmd_cb(test_pam_creds_insufficient_check);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose pam_test_ctx->pam_cmds);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose assert_int_equal(ret, EOK);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose /* Wait until the test finishes with EOK */
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose assert_int_equal(ret, EOK);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose}
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bosevoid test_pam_preauth_cert_no_logon_name_double_cert_with_hint(void **state)
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose{
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose int ret;
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose pam_test_ctx->rctx->domains->user_name_hint = true;
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, NULL, NULL, NULL, NULL, NULL, NULL,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose test_lookup_by_cert_double_cb, SSSD_TEST_CERT_0001,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose false);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose set_cmd_cb(test_pam_cert_check_with_hint_no_user);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose pam_test_ctx->pam_cmds);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(ret, EOK);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose /* Wait until the test finishes with EOK */
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose assert_int_equal(ret, EOK);
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose}
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosevoid test_pam_preauth_no_cert_no_logon_name(void **state)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, "/no/path");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose NULL, false);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cmd_cb(test_pam_user_unknown_check);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pam_cmds);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose /* Wait until the test finishes with EOK */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosevoid test_pam_preauth_cert_no_logon_name_no_match(void **state)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, NULL, NULL, NULL, NULL, NULL, NULL,
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio test_lookup_by_cert_cb, NULL, false);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cmd_cb(test_pam_user_unknown_check);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pam_cmds);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose /* Wait until the test finishes with EOK */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bosevoid test_pam_cert_auth(void **state)
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose{
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose int ret;
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio /* Here the last option must be set to true because the backend is only
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio * connected once. During authentication the backend is connected first to
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio * see if it can handle Smartcard authentication, but before that the user
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio * is looked up. Since the first mocked reply already adds the certificate
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio * to the user entry the lookup by certificate will already find the user
5aaaf081765b3f23e1518b5f299c289afb9d3f13Fabiano Fidêncio * in the cache and no second request to the backend is needed. */
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, "pamuser", "123456", "SSSD Test Token",
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose "NSS-Internal",
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose "C554C9F82C2A9D58B70921C143304153A8A42F17", NULL,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose test_lookup_by_cert_cb, SSSD_TEST_CERT_0001, true);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose /* Assume backend cannot handle Smartcard credentials */
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose pam_test_ctx->exp_pam_status = PAM_BAD_ITEM;
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose
82c5971fafe6063a90289ebba08035fc49ae8590Sumit Bose set_cmd_cb(test_pam_simple_check_success);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_ctx->pam_cmds);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose /* Wait until the test finishes with EOK */
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose assert_int_equal(ret, EOK);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose}
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bosevoid test_pam_cert_auth_no_logon_name(void **state)
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose{
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose int ret;
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose /* Here the last option must be set to true because the backend is only
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose * connected once. During authentication the backend is connected first to
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose * see if it can handle Smartcard authentication, but before that the user
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose * is looked up. Since the first mocked reply already adds the certificate
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose * to the user entry the lookup by certificate will already find the user
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose * in the cache and no second request to the backend is needed. */
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose mock_input_pam_cert(pam_test_ctx, NULL, "123456", "SSSD Test Token",
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose "NSS-Internal",
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose "C554C9F82C2A9D58B70921C143304153A8A42F17", NULL,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose test_lookup_by_cert_cb, SSSD_TEST_CERT_0001, true);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose mock_account_recv_simple();
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose mock_parse_inp("pamuser", NULL, EOK);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose /* Assume backend cannot handle Smartcard credentials */
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose pam_test_ctx->exp_pam_status = PAM_BAD_ITEM;
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose set_cmd_cb(test_pam_cert_check_auth_success);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose pam_test_ctx->pam_cmds);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose assert_int_equal(ret, EOK);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose /* Wait until the test finishes with EOK */
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose assert_int_equal(ret, EOK);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose}
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bosevoid test_pam_cert_auth_no_logon_name_no_key_id(void **state)
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose{
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose int ret;
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose /* Here the last option must be set to true because the backend is only
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose * connected once. During authentication the backend is connected first to
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose * see if it can handle Smartcard authentication, but before that the user
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose * is looked up. Since the first mocked reply already adds the certificate
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose * to the user entry the lookup by certificate will already find the user
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose * in the cache and no second request to the backend is needed. */
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose mock_input_pam_cert(pam_test_ctx, NULL, "123456", "SSSD Test Token",
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose "NSS-Internal", NULL, NULL,
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose NULL, NULL, false);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose /* Assume backend cannot handle Smartcard credentials */
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose pam_test_ctx->exp_pam_status = PAM_BAD_ITEM;
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose set_cmd_cb(test_pam_creds_insufficient_check);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose pam_test_ctx->pam_cmds);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose assert_int_equal(ret, EOK);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose /* Wait until the test finishes with EOK */
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose assert_int_equal(ret, EOK);
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose}
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bosevoid test_pam_cert_auth_double_cert(void **state)
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose{
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose int ret;
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, "pamuser", "123456", "SSSD Test Token",
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose "NSS-Internal",
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose "C554C9F82C2A9D58B70921C143304153A8A42F17", NULL,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose test_lookup_by_cert_double_cb, SSSD_TEST_CERT_0001,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose true);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose /* Assume backend cannot handle Smartcard credentials */
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose pam_test_ctx->exp_pam_status = PAM_BAD_ITEM;
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose set_cmd_cb(test_pam_simple_check_success);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose pam_test_ctx->pam_cmds);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose assert_int_equal(ret, EOK);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose /* Wait until the test finishes with EOK */
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose assert_int_equal(ret, EOK);
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose}
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bosevoid test_pam_cert_preauth_2certs_one_mapping(void **state)
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose{
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose int ret;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB_2CERTS);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, "pamuser", NULL, NULL, NULL, NULL, NULL,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose test_lookup_by_cert_cb, SSSD_TEST_CERT_0001, false);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose set_cmd_cb(test_pam_cert_check);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose pam_test_ctx->pam_cmds);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(ret, EOK);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose /* Wait until the test finishes with EOK */
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(ret, EOK);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose}
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bosevoid test_pam_cert_preauth_2certs_two_mappings(void **state)
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose{
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose int ret;
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose set_cert_auth_param(pam_test_ctx->pctx, NSS_DB_2CERTS);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0a8024af282b271ad2185f68703d9f4e766d2bdcSumit Bose mock_input_pam_cert(pam_test_ctx, "pamuser", NULL, NULL, NULL, NULL, NULL,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose test_lookup_by_cert_cb_2nd_cert_same_user,
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose SSSD_TEST_CERT_0001, false);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_PAM_PREAUTH);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose set_cmd_cb(test_pam_cert_check_2certs);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_PREAUTH,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose pam_test_ctx->pam_cmds);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(ret, EOK);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose /* Wait until the test finishes with EOK */
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose ret = test_ev_loop(pam_test_ctx->tctx);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose assert_int_equal(ret, EOK);
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose}
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bosevoid test_filter_response(void **state)
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose{
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose int ret;
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose struct pam_data *pd;
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose uint8_t offline_auth_data[(sizeof(uint32_t) + sizeof(int64_t))];
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose uint32_t info_type;
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose char *env;
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose struct sss_test_conf_param pam_params[] = {
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose { CONFDB_PAM_VERBOSITY, "1" },
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose { CONFDB_PAM_RESPONSE_FILTER, NULL },
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose { NULL, NULL }, /* Sentinel */
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose };
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose assert_int_equal(ret, EOK);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose pd = talloc_zero(pam_test_ctx, struct pam_data);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose assert_non_null(pd);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pd->service = discard_const("MyService");
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose env = talloc_asprintf(pd, "%s=%s", "MyEnv", "abcdef");
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_non_null(env);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = pam_add_response(pd, SSS_PAM_ENV_ITEM,
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose strlen(env) + 1, (uint8_t *) env);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose info_type = SSS_PAM_USER_INFO_OFFLINE_AUTH;
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose memset(offline_auth_data, 0, sizeof(offline_auth_data));
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose memcpy(offline_auth_data, &info_type, sizeof(uint32_t));
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose ret = pam_add_response(pd, SSS_PAM_USER_INFO,
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose sizeof(offline_auth_data), offline_auth_data);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose assert_int_equal(ret, EOK);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose /* pd->resp_list points to the SSS_PAM_USER_INFO and pd->resp_list->next
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose * to the SSS_PAM_ENV_ITEM message. */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose /* Test CONFDB_PAM_VERBOSITY option */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose assert_int_equal(ret, EOK);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_false(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose /* SSS_PAM_USER_INFO_OFFLINE_AUTH message will only be shown with
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose * pam_verbosity 2 or above if cache password never expires. */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[0].value = "2";
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_false(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_false(pd->resp_list->next->do_not_send_to_client);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose pam_params[0].value = "0";
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose assert_int_equal(ret, EOK);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose assert_int_equal(ret, EOK);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_false(pd->resp_list->next->do_not_send_to_client);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose /* Test CONFDB_PAM_RESPONSE_FILTER option */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "NoSuchOption";
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose assert_int_equal(ret, EOK);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_false(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV"; /* filter all environment variables */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose /* for all services */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV:"; /* filter all environment variables */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV::"; /* filter all environment variables */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV:abc:"; /* variable name does not match */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_false(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV:abc:MyService"; /* variable name does not match */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_false(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV::abc"; /* service name does not match */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_false(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose /* service name does not match */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV:MyEnv:abc";
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_false(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV:MyEnv"; /* match */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV:MyEnv:"; /* match */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV:MyEnv:MyService"; /* match */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose /* multiple rules with a match */
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose pam_params[1].value = "ENV:abc:def, "
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose "ENV:MyEnv:MyService, "
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose "ENV:stu:xyz";
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = add_pam_params(pam_params, pam_test_ctx->rctx->cdb);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose ret = filter_responses(pam_test_ctx->rctx->cdb, pd->resp_list, pd);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_int_equal(ret, EOK);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose assert_true(pd->resp_list->next->do_not_send_to_client);
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose
ce43f710c9638fbbeae077559cd7514370a10c0cSumit Bose talloc_free(pd);
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose}
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozekstatic int pam_test_setup_appsvc_posix_dom(void **state)
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek{
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek int ret;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek ret = pam_test_setup(state);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek if (ret != EOK) {
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek return ret;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek }
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek /* This config option is only read on startup, which is not executed
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek * in test, so we can't just pass in a param
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_ctx->pctx->app_services[0] = discard_const("app_svc");
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek return 0;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek}
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozekvoid test_appsvc_posix_dom(void **state)
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek{
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek int ret;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek /* The domain is POSIX, the request will skip over it */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek mock_input_pam_ex(pam_test_ctx, "pamuser", NULL, NULL, "app_svc", false);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_ctx->exp_pam_status = PAM_USER_UNKNOWN;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek set_cmd_cb(test_pam_user_unknown_check);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_ctx->pam_cmds);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek assert_int_equal(ret, EOK);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek ret = test_ev_loop(pam_test_ctx->tctx);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek assert_int_equal(ret, EOK);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek}
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozekvoid test_not_appsvc_posix_dom(void **state)
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek{
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek int ret;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek /* A different service than the app one can authenticate against a POSIX domain */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek mock_input_pam_ex(pam_test_ctx, "pamuser", NULL, NULL, "not_app_svc", true);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek set_cmd_cb(test_pam_simple_check);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_ctx->pam_cmds);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek assert_int_equal(ret, EOK);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek /* Wait until the test finishes with EOK */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek ret = test_ev_loop(pam_test_ctx->tctx);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek assert_int_equal(ret, EOK);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek}
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozekstatic int pam_test_setup_appsvc_app_dom(void **state)
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek{
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek struct sss_test_conf_param dom_params[] = {
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek { "domain_type", "application" },
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek { NULL, NULL }, /* Sentinel */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek };
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek struct sss_test_conf_param pam_params[] = {
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek { NULL, NULL }, /* Sentinel */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek };
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek struct sss_test_conf_param monitor_params[] = {
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek { NULL, NULL }, /* Sentinel */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek };
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek test_pam_setup(dom_params, pam_params, monitor_params, state);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_setup_common();
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek /* This config option is only read on startup, which is not executed
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek * in test, so we can't just pass in a param
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_ctx->pctx->app_services[0] = discard_const("app_svc");
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek return 0;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek}
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozekvoid test_appsvc_app_dom(void **state)
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek{
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek int ret;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek /* The domain is POSIX, the request will skip over it */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek mock_input_pam_ex(pam_test_ctx, "pamuser", NULL, NULL, "app_svc", true);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek set_cmd_cb(test_pam_simple_check);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_ctx->pam_cmds);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek assert_int_equal(ret, EOK);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek /* Wait until the test finishes with EOK */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek ret = test_ev_loop(pam_test_ctx->tctx);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek assert_int_equal(ret, EOK);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek}
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozekvoid test_not_appsvc_app_dom(void **state)
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek{
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek int ret;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek /* A different service than the app one can authenticate against a POSIX domain */
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek mock_input_pam_ex(pam_test_ctx, "pamuser", NULL, NULL, "not_app_svc", false);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_ctx->exp_pam_status = PAM_USER_UNKNOWN;
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_PAM_AUTHENTICATE);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek set_cmd_cb(test_pam_user_unknown_check);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek ret = sss_cmd_execute(pam_test_ctx->cctx, SSS_PAM_AUTHENTICATE,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_ctx->pam_cmds);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek assert_int_equal(ret, EOK);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek ret = test_ev_loop(pam_test_ctx->tctx);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek assert_int_equal(ret, EOK);
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek}
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Boseint main(int argc, const char *argv[])
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose{
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int rv;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int no_cleanup = 0;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose poptContext pc;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose int opt;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose struct poptOption long_options[] = {
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose POPT_AUTOHELP
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose SSSD_DEBUG_OPTS
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose { "no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose _("Do not delete the test database after a test run"), NULL },
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose POPT_TABLEEND
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose };
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose const struct CMUnitTest tests[] = {
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_authenticate,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_setcreds,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_acct_mgmt,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_open_session,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_close_session,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_chauthtok,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_chauthtok_prelim,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_preauth,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_offline_auth_no_hash,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_offline_auth_success,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_offline_auth_wrong_pw,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_offline_auth_success_2fa,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_offline_auth_failed_2fa,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose test_pam_offline_auth_success_2fa_with_cached_2fa,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose test_pam_offline_auth_failed_2fa_with_cached_2fa,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose test_pam_offline_auth_success_pw_with_cached_2fa,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose test_pam_offline_auth_failed_pw_with_cached_2fa,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose test_pam_offline_auth_success_combined_pw_with_cached_2fa,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose test_pam_offline_auth_failed_combined_pw_with_cached_2fa,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose test_pam_offline_auth_failed_wrong_2fa_size_with_cached_2fa,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_offline_chauthtok_prelim,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose cmocka_unit_test_setup_teardown(test_pam_offline_chauthtok,
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pam_test_setup, pam_test_teardown),
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose cmocka_unit_test_setup_teardown(test_pam_preauth_no_logon_name,
2e76b32e74abedb23665808bacc73cafd1097c37Sumit Bose pam_test_setup, pam_test_teardown),
29d063505c07127f7747405b1a61d8f782673645Sumit Bose cmocka_unit_test_setup_teardown(test_pam_auth_no_upn_logon_name,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose pam_test_setup, pam_test_teardown),
29d063505c07127f7747405b1a61d8f782673645Sumit Bose cmocka_unit_test_setup_teardown(test_pam_auth_upn_logon_name,
29d063505c07127f7747405b1a61d8f782673645Sumit Bose pam_test_setup, pam_test_teardown),
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl cmocka_unit_test_setup_teardown(test_pam_cached_auth_success,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_cached_test_setup,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_teardown),
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl cmocka_unit_test_setup_teardown(test_pam_cached_auth_wrong_pw,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_cached_test_setup,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_teardown),
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl cmocka_unit_test_setup_teardown(test_pam_cached_auth_opt_timeout,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_cached_test_setup,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_teardown),
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl cmocka_unit_test_setup_teardown(test_pam_cached_auth_timeout,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_cached_test_setup,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_teardown),
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl cmocka_unit_test_setup_teardown(test_pam_cached_auth_success_combined_pw_with_cached_2fa,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_cached_test_setup,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_teardown),
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl cmocka_unit_test_setup_teardown(test_pam_cached_auth_failed_combined_pw_with_cached_2fa,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_cached_test_setup,
4b12be504e20173e0629835818e4db6a9617a9a4Pavel Reichl pam_test_teardown),
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#ifdef HAVE_TEST_CA
f182ede719c4290f46f09af1191c5eec3da54503Lukas Slebodnik/* p11_child is not built without NSS */
f182ede719c4290f46f09af1191c5eec3da54503Lukas Slebodnik#ifdef HAVE_NSS
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose cmocka_unit_test_setup_teardown(test_pam_preauth_cert_nocert,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_setup, pam_test_teardown),
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose cmocka_unit_test_setup_teardown(test_pam_preauth_cert_nomatch,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_setup, pam_test_teardown),
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose cmocka_unit_test_setup_teardown(test_pam_preauth_cert_match,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_setup, pam_test_teardown),
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose cmocka_unit_test_setup_teardown(test_pam_preauth_cert_match_gdm_smartcard,
71cd9f98150577224559bdc12c53c01ce6f2c3d9Sumit Bose pam_test_setup, pam_test_teardown),
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose cmocka_unit_test_setup_teardown(test_pam_preauth_cert_match_wrong_user,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_setup, pam_test_teardown),
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose cmocka_unit_test_setup_teardown(test_pam_preauth_cert_no_logon_name,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_setup, pam_test_teardown),
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose cmocka_unit_test_setup_teardown(
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose test_pam_preauth_cert_no_logon_name_with_hint,
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose pam_test_setup, pam_test_teardown),
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose cmocka_unit_test_setup_teardown(
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose test_pam_preauth_cert_no_logon_name_double_cert,
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose pam_test_setup, pam_test_teardown),
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose cmocka_unit_test_setup_teardown(
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose test_pam_preauth_cert_no_logon_name_double_cert_with_hint,
32474fa2f0a6dc09386bab405fc3461cb3dd12acSumit Bose pam_test_setup, pam_test_teardown),
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose cmocka_unit_test_setup_teardown(test_pam_preauth_no_cert_no_logon_name,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_setup, pam_test_teardown),
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose cmocka_unit_test_setup_teardown(
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose test_pam_preauth_cert_no_logon_name_no_match,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_setup, pam_test_teardown),
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose cmocka_unit_test_setup_teardown(test_pam_cert_auth,
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose pam_test_setup, pam_test_teardown),
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose cmocka_unit_test_setup_teardown(test_pam_cert_auth,
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose pam_test_setup_no_verification,
aa35995ef056aa8ae052a47c62c6750b7adf065eSumit Bose pam_test_teardown),
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose cmocka_unit_test_setup_teardown(test_pam_cert_auth_double_cert,
16c9d63d96ce8dc7517ae16502e9ec72d6a58d6cSumit Bose pam_test_setup, pam_test_teardown),
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose cmocka_unit_test_setup_teardown(test_pam_cert_preauth_2certs_one_mapping,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose pam_test_setup, pam_test_teardown),
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose cmocka_unit_test_setup_teardown(test_pam_cert_preauth_2certs_two_mappings,
0bdd8800c16f39b8fe308d20694ad905c669dff3Sumit Bose pam_test_setup, pam_test_teardown),
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose cmocka_unit_test_setup_teardown(test_pam_cert_auth_no_logon_name,
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose pam_test_setup, pam_test_teardown),
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose cmocka_unit_test_setup_teardown(test_pam_cert_auth_no_logon_name_no_key_id,
fd6f4047b58686bd4057c9859c3c804a77b136d8Sumit Bose pam_test_setup, pam_test_teardown),
f182ede719c4290f46f09af1191c5eec3da54503Lukas Slebodnik#endif /* HAVE_NSS */
0dc7f90667df6420bc9e93ae2c8bacd6ea148f0fSumit Bose#endif /* HAVE_TEST_CA */
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose cmocka_unit_test_setup_teardown(test_filter_response,
c8fe1d922b254aa92e74f428135ada3c8bde87a1Sumit Bose pam_test_setup, pam_test_teardown),
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek cmocka_unit_test_setup_teardown(test_appsvc_posix_dom,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_setup_appsvc_posix_dom,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_teardown),
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek cmocka_unit_test_setup_teardown(test_not_appsvc_posix_dom,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_setup_appsvc_posix_dom,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_teardown),
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek cmocka_unit_test_setup_teardown(test_appsvc_app_dom,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_setup_appsvc_app_dom,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_teardown),
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek cmocka_unit_test_setup_teardown(test_not_appsvc_app_dom,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_setup_appsvc_posix_dom,
3e789aa0bd6b7bb6e62f91458b76753498030fb5Jakub Hrozek pam_test_teardown),
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose };
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose debug_level = SSSDBG_INVALID;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose while ((opt = poptGetNextOpt(pc)) != -1) {
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose switch (opt) {
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose default:
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose fprintf(stderr, "\nInvalid option %s: %s\n\n",
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose poptBadOption(pc, 0), poptStrerror(opt));
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose poptPrintUsage(pc, stderr, 0);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return 1;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose }
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose }
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose poptFreeContext(pc);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose DEBUG_CLI_INIT(debug_level);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose /* Even though normally the tests should clean up after themselves
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * they might not after a failed run. Remove the old DB to be sure */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose tests_set_cwd();
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose test_dom_suite_setup(TESTS_PATH);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose cleanup_nss_db();
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose rv = setup_nss_db();
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose if (rv != EOK) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "setup_nss_db failed.\n");
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose exit(-1);
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose }
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose rv = cmocka_run_group_tests(tests, NULL, NULL);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose if (rv == 0 && !no_cleanup) {
a8d887323f83984679a7d9b827a70146656bb7b2Sumit Bose cleanup_nss_db();
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose }
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#ifdef HAVE_NSS
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Cleanup NSS and NSPR to make Valgrind happy. */
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose nspr_nss_cleanup();
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose#endif
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose return rv;
ea422c7061072c125eb53b40d7f3ca444d886913Sumit Bose}