150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/*
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek Authors:
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek Copyright (C) 2013 Red Hat
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek SSSD tests: NSS responder tests
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek This program is free software; you can redistribute it and/or modify
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek it under the terms of the GNU General Public License as published by
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek (at your option) any later version.
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek This program is distributed in the hope that it will be useful,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek GNU General Public License for more details.
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek You should have received a copy of the GNU General Public License
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek*/
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#include <talloc.h>
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#include <tevent.h>
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#include <errno.h>
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#include <popt.h>
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#include "tests/cmocka/common_mock.h"
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#include "tests/cmocka/common_mock_resp.h"
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#include "responder/common/negcache.h"
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina#include "responder/nss/nss_private.h"
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina#include "responder/nss/nss_protocol.h"
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose#include "sss_client/idmap/sss_nss_idmap.h"
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose#include "util/util_sss_idmap.h"
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose#include "util/crypto/sss_crypto.h"
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose#include "util/crypto/nss/nss_util.h"
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek#include "db/sysdb_private.h" /* new_subdomain() */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
50c9d542e8bf641412debaa82a4dcf67ddb72258Lukas Slebodnik#define TESTS_PATH "tp_" BASE_FILE_STEM
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#define TEST_CONF_DB "test_nss_conf.ldb"
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#define TEST_DOM_NAME "nss_test"
61b58801f1e37c054affc99f6fe900f7b3ef7972Lukas Slebodnik#define TEST_SUBDOM_NAME "test.subdomain"
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#define TEST_ID_PROVIDER "ldap"
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek#define TEST_DOM_SID "S-1-5-21-444379608-1639770488-2995963434"
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekstruct nss_test_ctx {
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct sss_test_ctx *tctx;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek struct sss_domain_info *subdom;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct resp_ctx *rctx;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct cli_ctx *cctx;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct sss_cmd_table *nss_cmds;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct nss_ctx *nctx;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
9cc2223e0bc0478c1b47a47fd71bba7e7129492dJakub Hrozek int ncache_hits;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek};
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
7543052f562f157f7b17fdc46a6777d80c0cb3bdSumit Boseconst char *global_extra_attrs[] = {"phone", "mobile", NULL};
e4549c5364461644723361d688badde7fe137a25Sumit Bose
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekstruct nss_test_ctx *nss_test_ctx;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* Mock NSS structure */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekstruct nss_ctx *
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekmock_nctx(TALLOC_CTX *mem_ctx)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct nss_ctx *nctx;
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose enum idmap_error_code err;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nctx = talloc_zero(mem_ctx, struct nss_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (!nctx) {
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return NULL;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek }
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek nctx->pwfield = discard_const("*");
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose err = sss_idmap_init(sss_idmap_talloc, nctx, sss_idmap_talloc_free,
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose &nctx->idmap_ctx);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose if (err != IDMAP_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "sss_idmap_init failed.\n");
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose talloc_free(nctx);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose return NULL;
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose }
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return nctx;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* Mock reading requests from a client. Use values passed from mock
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek * instead
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekvoid __real_sss_packet_get_body(struct sss_packet *packet,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek uint8_t **body, size_t *blen);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekvoid __wrap_sss_packet_get_body(struct sss_packet *packet,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek uint8_t **body, size_t *blen)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek enum sss_test_wrapper_call wtype = sss_mock_type(enum sss_test_wrapper_call);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha size_t len;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (wtype == WRAP_CALL_REAL) {
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return __real_sss_packet_get_body(packet, body, blen);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek }
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek *body = sss_mock_ptr_type(uint8_t *);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha len = sss_mock_type(size_t);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha if (len == 0) {
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha len = strlen((const char *) *body)+1;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha }
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha *blen = len;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* Mock returning result to client. Terminate the unit test instead. */
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosetypedef int (*cmd_cb_fn_t)(uint32_t, uint8_t *, size_t );
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekstatic void set_cmd_cb(cmd_cb_fn_t fn)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek will_return(__wrap_sss_cmd_done, fn);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekvoid __wrap_sss_cmd_done(struct cli_ctx *cctx, void *freectx)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *pctx;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct sss_packet *packet;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek uint8_t *body;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek size_t blen;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek cmd_cb_fn_t check_cb;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek check_cb = sss_mock_ptr_type(cmd_cb_fn_t);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina if (check_cb == NULL) {
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina nss_test_ctx->tctx->error = ENOENT;
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina } else {
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina pctx = talloc_get_type(cctx->protocol_ctx, struct cli_protocol);
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina packet = pctx->creq->out;
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina __real_sss_packet_get_body(packet, &body, &blen);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina nss_test_ctx->tctx->error = check_cb(sss_packet_get_status(packet),
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina body, blen);
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina }
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->tctx->done = true;
343b053bc61792023003d077ae81c05ff1676a89Sumit Bose talloc_free(freectx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekenum sss_cli_command __wrap_sss_packet_get_cmd(struct sss_packet *packet)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return sss_mock_type(enum sss_cli_command);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekint __wrap_sss_cmd_send_empty(struct cli_ctx *cctx, TALLOC_CTX *freectx)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->tctx->done = true;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->tctx->error = ENOENT;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return EOK;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* Intercept negative cache lookups */
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnikint __real_sss_ncache_check_user(struct sss_nc_ctx *ctx,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct sss_domain_info *dom, const char *name);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnikint __wrap_sss_ncache_check_user(struct sss_nc_ctx *ctx,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct sss_domain_info *dom, const char *name)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek int ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnik ret = __real_sss_ncache_check_user(ctx, dom, name);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (ret == EEXIST) {
9cc2223e0bc0478c1b47a47fd71bba7e7129492dJakub Hrozek nss_test_ctx->ncache_hits++;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek }
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
54039570d26e29444c398aa4ad6ba638f1713566Sumit Boseint __real_sss_ncache_check_upn(struct sss_nc_ctx *ctx,
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose struct sss_domain_info *dom, const char *name);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose
54039570d26e29444c398aa4ad6ba638f1713566Sumit Boseint __wrap_sss_ncache_check_upn(struct sss_nc_ctx *ctx,
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose struct sss_domain_info *dom, const char *name)
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose{
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose int ret;
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose ret = __real_sss_ncache_check_upn(ctx, dom, name);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose if (ret == EEXIST) {
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose nss_test_ctx->ncache_hits++;
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose }
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose return ret;
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose}
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnikint __real_sss_ncache_check_uid(struct sss_nc_ctx *ctx,
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose struct sss_domain_info *dom, uid_t uid);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnikint __wrap_sss_ncache_check_uid(struct sss_nc_ctx *ctx,
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose struct sss_domain_info *dom, uid_t uid)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha int ret;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnik ret = __real_sss_ncache_check_uid(ctx, dom, uid);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha if (ret == EEXIST) {
9cc2223e0bc0478c1b47a47fd71bba7e7129492dJakub Hrozek nss_test_ctx->ncache_hits++;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha }
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha return ret;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnikint __real_sss_ncache_check_sid(struct sss_nc_ctx *ctx, const char *sid);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnikint __wrap_sss_ncache_check_sid(struct sss_nc_ctx *ctx, const char *sid)
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek{
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek int ret;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnik ret = __real_sss_ncache_check_sid(ctx, sid);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek if (ret == EEXIST) {
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx->ncache_hits++;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek }
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek return ret;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek}
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnikint __real_sss_ncache_check_cert(struct sss_nc_ctx *ctx, const char *cert);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnikint __wrap_sss_ncache_check_cert(struct sss_nc_ctx *ctx, const char *cert)
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose{
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose int ret;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
35567de112cd5d82acb582cbdb44c8652bbdfda1Lukas Slebodnik ret = __real_sss_ncache_check_cert(ctx, cert);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose if (ret == EEXIST) {
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose nss_test_ctx->ncache_hits++;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose }
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose return ret;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose}
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* Mock input from the client library */
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březinastatic void mock_input_user_or_group(const char *input)
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina{
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina const char *copy;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina const char *shortname;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina const char *domname;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina char *separator;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina copy = talloc_strdup(nss_test_ctx, input);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina assert_non_null(copy);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina separator = strrchr(copy, '@');
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina if (separator == NULL) {
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina shortname = input;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina domname = NULL;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina } else {
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina *separator = '\0';
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina shortname = copy;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina domname = separator + 1;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina }
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return(__wrap_sss_packet_get_body, input);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return(__wrap_sss_packet_get_body, 0);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_parse_inp(shortname, domname, EOK);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina}
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bosestatic void mock_input_user_or_group_ex(bool do_parse_inp, const char *input,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose uint32_t flags)
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose{
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose const char *copy;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose const char *shortname;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose const char *domname;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose char *separator;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose uint8_t *data;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose size_t len;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose len = strlen(input);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose len++;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose data = talloc_size(nss_test_ctx, len + sizeof(uint32_t));
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_non_null(data);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose memcpy(data, input, len);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SAFEALIGN_COPY_UINT32(data + len, &flags, NULL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, data);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, len + sizeof(uint32_t));
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose if (do_parse_inp) {
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose copy = talloc_strdup(nss_test_ctx, input);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_non_null(copy);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose separator = strrchr(copy, '@');
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose if (separator == NULL) {
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose shortname = input;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose domname = NULL;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose } else {
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose *separator = '\0';
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose shortname = copy;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose domname = separator + 1;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose }
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_parse_inp(shortname, domname, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose }
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose}
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březinastatic void mock_input_upn(const char *upn)
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina{
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return(__wrap_sss_packet_get_body, upn);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return(__wrap_sss_packet_get_body, 0);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina}
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březinastatic void mock_input_sid(const char *sid)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return(__wrap_sss_packet_get_body, sid);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return(__wrap_sss_packet_get_body, 0);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina}
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březinastatic void mock_input_cert(const char *cert)
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina{
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return(__wrap_sss_packet_get_body, cert);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_body, 0);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jhastatic void mock_input_id(TALLOC_CTX *mem_ctx, uint32_t id)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha uint8_t *body;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha body = talloc_zero_array(mem_ctx, uint8_t, 4);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha if (body == NULL) return;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha SAFEALIGN_SETMEM_UINT32(body, id, NULL);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_body, body);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_body, sizeof(uint32_t));
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bosestatic void mock_input_id_ex(TALLOC_CTX *mem_ctx, uint32_t id, uint32_t flags)
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose{
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose uint8_t *body;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose body = talloc_zero_array(mem_ctx, uint8_t, 8);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose if (body == NULL) return;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SAFEALIGN_SETMEM_UINT32(body, id, NULL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SAFEALIGN_SETMEM_UINT32(body + sizeof(uint32_t), flags, NULL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, body);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, 2 * sizeof(uint32_t));
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose}
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekstatic void mock_fill_user(void)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* One packet for the entry and one for num entries */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozekstatic void mock_fill_bysid(void)
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek{
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* One packet for the entry and one for num entries */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek}
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekstatic int parse_user_packet(uint8_t *body, size_t blen, struct passwd *pwd)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek size_t rp = 2 * sizeof(uint32_t);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek SAFEALIGN_COPY_UINT32(&pwd->pw_uid, body+rp, &rp);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek SAFEALIGN_COPY_UINT32(&pwd->pw_gid, body+rp, &rp);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Sequence of null terminated strings (name, passwd, gecos, dir, shell) */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek pwd->pw_name = (char *) body+rp;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek rp += strlen(pwd->pw_name) + 1;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (rp >= blen) return EINVAL;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek pwd->pw_passwd = (char *) body+rp;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek rp += strlen(pwd->pw_passwd) + 1;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek if (rp >= blen) return EINVAL;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek pwd->pw_gecos = (char *) body+rp;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek rp += strlen(pwd->pw_gecos) + 1;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (rp >= blen) return EINVAL;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek pwd->pw_dir = (char *) body+rp;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek rp += strlen(pwd->pw_dir) + 1;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (rp >= blen) return EINVAL;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek pwd->pw_shell = (char *) body+rp;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek rp += strlen(pwd->pw_shell) + 1;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek if (rp != blen) return EINVAL;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek return EOK;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek}
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozekstatic int parse_group_packet(uint8_t *body, size_t blen, struct group *gr, uint32_t *nmem)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek{
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek size_t rp = 2 * sizeof(uint32_t); /* Len and reserved */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek unsigned i;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek SAFEALIGN_COPY_UINT32(&gr->gr_gid, body+rp, &rp);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek SAFEALIGN_COPY_UINT32(nmem, body+rp, &rp);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek gr->gr_name = (char *) body+rp;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek rp += strlen(gr->gr_name) + 1;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek if (rp >= blen) return EINVAL;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek gr->gr_passwd = (char *) body+rp;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek rp += strlen(gr->gr_passwd) + 1;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek if (*nmem > 0) {
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek gr->gr_mem = talloc_zero_array(nss_test_ctx, char *, *nmem);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek if (gr->gr_mem == NULL) return ENOMEM;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek for (i = 0; i < *nmem; i++) {
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek if (rp >= blen) return EINVAL;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek gr->gr_mem[i] = talloc_strdup(gr->gr_mem, (char *) body+rp);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek rp += strlen(gr->gr_mem[i]) + 1;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek }
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek }
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Make sure we exactly matched the end of the packet */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek if (rp != blen) return EINVAL;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return EOK;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekstatic void check_initgr_packet(uint8_t *body, size_t blen,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek gid_t *gids, size_t num_gids)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek size_t rp;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek unsigned i;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek gid_t cur_gid;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek uint32_t num_ret;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek rp = 0;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek SAFEALIGN_COPY_UINT32(&num_ret, body, NULL);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(num_ret, num_gids);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek rp = 2 * sizeof(uint32_t); /* Len and reserved */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek for (i = 0; i < num_gids; i++) {
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek SAFEALIGN_COPY_UINT32(&cur_gid, body + rp, &rp);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(cur_gid, gids[i]);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek }
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstatic errno_t store_user(struct nss_test_ctx *ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct sss_domain_info *dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct passwd *user,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct sysdb_attrs *attrs,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek time_t cache_update)
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek{
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek errno_t ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek char *fqname;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek fqname = sss_create_internal_fqname(ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek user->pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek dom->name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek if (fqname == NULL) {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ENOMEM;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek }
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek /* Prime the cache with a valid user */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = sysdb_store_user(dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek fqname,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek user->pw_passwd,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek user->pw_uid,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek user->pw_gid,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek user->pw_gecos,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek user->pw_dir,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek user->pw_shell,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek NULL, attrs,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek NULL, 300, cache_update);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(fqname);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek}
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidênciostatic errno_t delete_user(struct nss_test_ctx *ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio struct sss_domain_info *dom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio struct passwd *user)
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio{
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio errno_t ret;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio char *fqname;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio fqname = sss_create_internal_fqname(ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio user->pw_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio dom->name);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio if (fqname == NULL) {
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio return ENOMEM;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio }
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = sysdb_delete_user(dom, fqname, user->pw_uid);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio talloc_free(fqname);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio return ret;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio}
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstatic errno_t set_user_attr(struct nss_test_ctx *ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct sss_domain_info *dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct passwd *user,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct sysdb_attrs *attrs)
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek{
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek errno_t ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek char *fqname;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek fqname = sss_create_internal_fqname(ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek user->pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek dom->name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek if (fqname == NULL) {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ENOMEM;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek }
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = sysdb_set_user_attr(nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek fqname,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek attrs, SYSDB_MOD_REP);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(fqname);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek}
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstatic int get_user(TALLOC_CTX *mem_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct sss_domain_info *domain,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek const char *shortname,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct ldb_result **_res)
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek{
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek errno_t ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek char *fqname;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek fqname = sss_create_internal_fqname(mem_ctx, shortname,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek domain->name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek if (fqname == NULL) {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ENOMEM;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek }
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = sysdb_getpwnam(mem_ctx, domain, fqname, _res);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(fqname);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek}
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstatic void assert_users_equal(struct passwd *a, struct passwd *b)
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek{
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_int_equal(a->pw_uid, b->pw_uid);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_int_equal(a->pw_gid, b->pw_gid);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_string_equal(a->pw_name, b->pw_name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_string_equal(a->pw_shell, b->pw_shell);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_string_equal(a->pw_passwd, b->pw_passwd);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek}
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstatic errno_t store_group(struct nss_test_ctx *ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct sss_domain_info *dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct group *group,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek time_t cache_update)
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek{
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek errno_t ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek char *fqname;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek fqname = sss_create_internal_fqname(ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek group->gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek dom->name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek if (fqname == NULL) {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ENOMEM;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek }
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = sysdb_add_group(dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek fqname,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek group->gr_gid,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek NULL, 300, 0);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(fqname);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek}
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidênciostatic errno_t delete_group(struct nss_test_ctx *ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio struct sss_domain_info *dom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio struct group *group)
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio{
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio errno_t ret;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio char *fqname;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio fqname = sss_create_internal_fqname(ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio group->gr_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio dom->name);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio if (fqname == NULL) {
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio return ENOMEM;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio }
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = sysdb_delete_group(dom, fqname, group->gr_gid);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio talloc_free(fqname);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio return ret;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio}
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
caae0e53e6091806634943699f4398b6a20273b4Michal Židekstatic int cmp_func(const void *a, const void *b)
caae0e53e6091806634943699f4398b6a20273b4Michal Židek{
caae0e53e6091806634943699f4398b6a20273b4Michal Židek char *str1 = *(char **)discard_const(a);
caae0e53e6091806634943699f4398b6a20273b4Michal Židek char *str2 = *(char **)discard_const(b);
caae0e53e6091806634943699f4398b6a20273b4Michal Židek
caae0e53e6091806634943699f4398b6a20273b4Michal Židek return strcmp(str1, str2);
caae0e53e6091806634943699f4398b6a20273b4Michal Židek}
caae0e53e6091806634943699f4398b6a20273b4Michal Židek
caae0e53e6091806634943699f4398b6a20273b4Michal Židekstatic void order_string_array(char **_list, int size)
caae0e53e6091806634943699f4398b6a20273b4Michal Židek{
caae0e53e6091806634943699f4398b6a20273b4Michal Židek if (size < 2 || _list == NULL || *_list == NULL) {
caae0e53e6091806634943699f4398b6a20273b4Michal Židek /* Nothing to do */
caae0e53e6091806634943699f4398b6a20273b4Michal Židek return;
caae0e53e6091806634943699f4398b6a20273b4Michal Židek }
caae0e53e6091806634943699f4398b6a20273b4Michal Židek
caae0e53e6091806634943699f4398b6a20273b4Michal Židek qsort(_list, size, sizeof(char *), cmp_func);
caae0e53e6091806634943699f4398b6a20273b4Michal Židek return;
caae0e53e6091806634943699f4398b6a20273b4Michal Židek}
caae0e53e6091806634943699f4398b6a20273b4Michal Židek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstatic void assert_groups_equal(struct group *expected,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct group *gr, const int nmem)
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek{
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek int i;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_int_equal(gr->gr_gid, expected->gr_gid);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_string_equal(gr->gr_name, expected->gr_name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_string_equal(gr->gr_passwd, expected->gr_passwd);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
caae0e53e6091806634943699f4398b6a20273b4Michal Židek order_string_array(gr->gr_mem, nmem);
caae0e53e6091806634943699f4398b6a20273b4Michal Židek order_string_array(expected->gr_mem, nmem);
caae0e53e6091806634943699f4398b6a20273b4Michal Židek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek for (i = 0; i < nmem; i++) {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_string_equal(gr->gr_mem[i], expected->gr_mem[i]);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek }
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek}
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstatic errno_t store_group_member(struct nss_test_ctx *ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek const char *shortname_group,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct sss_domain_info *group_dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek const char *shortname_member,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek struct sss_domain_info *member_dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek enum sysdb_member_type type)
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek{
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek errno_t ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek char *group_fqname = NULL;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek char *member_fqname = NULL;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek group_fqname = sss_create_internal_fqname(ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek shortname_group,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek group_dom->name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek if (group_fqname == NULL) {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ENOMEM;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek }
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek member_fqname = sss_create_internal_fqname(ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek shortname_member,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek member_dom->name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek if (member_fqname == NULL) {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(group_fqname);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ENOMEM;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek }
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = sysdb_add_group_member(group_dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek group_fqname,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek member_fqname,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER, false);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(group_fqname);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(member_fqname);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek}
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidênciostatic errno_t remove_group_member(struct nss_test_ctx *ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio const char *shortname_group,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio struct sss_domain_info *group_dom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio const char *shortname_member,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio struct sss_domain_info *member_dom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio enum sysdb_member_type type)
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio{
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio errno_t ret;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio char *group_fqname = NULL;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio char *member_fqname = NULL;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio group_fqname = sss_create_internal_fqname(ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio shortname_group,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio group_dom->name);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio if (group_fqname == NULL) {
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio return ENOMEM;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio }
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio member_fqname = sss_create_internal_fqname(ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio shortname_member,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio member_dom->name);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio if (member_fqname == NULL) {
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio talloc_free(group_fqname);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio return ENOMEM;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio }
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = sysdb_remove_group_member(group_dom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio group_fqname,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio member_fqname,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio type,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio false);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio talloc_free(group_fqname);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio talloc_free(member_fqname);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio return ret;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio}
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* ====================== The tests =============================== */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd getpwnam_usr = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testuser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 123,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 456,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* Check getting cached and valid user from cache. Account callback will
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek * not be called and test_nss_getpwnam_check will make sure the user is
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek * the same as the test entered before starting
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek */
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getpwnam_check(uint32_t status, uint8_t *body, size_t blen)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct passwd pwd;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek errno_t ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = parse_user_packet(body, blen, &pwd);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_users_equal(&pwd, &getpwnam_usr);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return EOK;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekvoid test_nss_getpwnam(void **state)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek errno_t ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &getpwnam_usr, NULL, 0);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek mock_input_user_or_group("testuser");
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek mock_fill_user();
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Query for that user, call a callback when command finishes */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek set_cmd_cb(test_nss_getpwnam_check);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->nss_cmds);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Wait until the test finishes with EOK */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz/* Test that searching for a nonexistent user yields ENOENT.
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek * Account callback will be called
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekvoid test_nss_getpwnam_neg(void **state)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek errno_t ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek mock_input_user_or_group("testuser_neg");
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek mock_account_recv_simple();
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
9cc2223e0bc0478c1b47a47fd71bba7e7129492dJakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 0);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->nss_cmds);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Wait until the test finishes with ENOENT */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, ENOENT);
9cc2223e0bc0478c1b47a47fd71bba7e7129492dJakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 0);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Test that subsequent search for a nonexistent user yields
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek * ENOENT and Account callback is not called, on the other hand
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek * the ncache functions will be called
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->tctx->done = false;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek mock_input_user_or_group("testuser_neg");
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->nss_cmds);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Wait until the test finishes with ENOENT */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, ENOENT);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Negative cache was hit this time */
9cc2223e0bc0478c1b47a47fd71bba7e7129492dJakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 1);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd getpwnam_search_usr = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testuser_search"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 567,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 890,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuser_search"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test search user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekstatic int test_nss_getpwnam_search_acct_cb(void *pvt)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct nss_test_ctx *ctx = talloc_get_type(pvt, struct nss_test_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return store_user(ctx, ctx->tctx->dom, &getpwnam_search_usr, NULL, 0);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getpwnam_search_check(uint32_t status,
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose uint8_t *body, size_t blen)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct passwd pwd;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek errno_t ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = parse_user_packet(body, blen, &pwd);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_users_equal(&pwd, &getpwnam_search_usr);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return EOK;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekvoid test_nss_getpwnam_search(void **state)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek errno_t ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct ldb_result *res;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek mock_input_user_or_group("testuser_search");
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek mock_account_recv(0, 0, NULL, test_nss_getpwnam_search_acct_cb, nss_test_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek mock_fill_user();
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek set_cmd_cb(test_nss_getpwnam_search_check);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = get_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek "testuser_search", &res);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(res->count, 0);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->nss_cmds);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Wait until the test finishes with EOK */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* test_nss_getpwnam_search_check will check the user attributes */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = get_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek "testuser_search", &res);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(res->count, 1);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* Test that searching for a user that is expired in the cache goes to the DP
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek * which updates the record and the NSS responder returns the updated record
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek *
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek * The user's shell attribute is updated.
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd getpwnam_update = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testuser_update"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 10,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 11,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekstatic int test_nss_getpwnam_update_acct_cb(void *pvt)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct nss_test_ctx *ctx = talloc_get_type(pvt, struct nss_test_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek getpwnam_update.pw_shell = discard_const("/bin/ksh");
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return store_user(ctx, ctx->tctx->dom, &getpwnam_update, NULL, 0);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getpwnam_update_check(uint32_t status,
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose uint8_t *body, size_t blen)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct passwd pwd;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek errno_t ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = parse_user_packet(body, blen, &pwd);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_users_equal(&pwd, &getpwnam_update);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return EOK;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekvoid test_nss_getpwnam_update(void **state)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek errno_t ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct ldb_result *res;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek const char *shell;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &getpwnam_update, NULL, 1);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Mock client input */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek mock_input_user_or_group("testuser_update");
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Mock client command */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Call this function when user is updated by the mock DP request */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek mock_account_recv(0, 0, NULL, test_nss_getpwnam_update_acct_cb, nss_test_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Call this function to check what the responder returned to the client */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek set_cmd_cb(test_nss_getpwnam_update_check);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Mock output buffer */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek mock_fill_user();
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Fire the command */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->nss_cmds);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Wait until the test finishes with EOK */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Check the user was updated in the cache */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = get_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek "testuser_update" , &res);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(res->count, 1);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek shell = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SHELL, NULL);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_string_equal(shell, "/bin/ksh");
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek/* Check that a FQDN is returned if the domain is FQDN-only and a
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek * FQDN is requested
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd getpwnam_fqdn = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testuser_fqdn"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 124,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 457,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getpwnam_check_fqdn(uint32_t status,
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose uint8_t *body, size_t blen)
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek{
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek struct passwd pwd;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek errno_t ret;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek nss_test_ctx->cctx->rctx->domains[0].fqnames = false;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek ret = parse_user_packet(body, blen, &pwd);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_int_equal(ret, EOK);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek getpwnam_fqdn.pw_name = discard_const("testuser_fqdn@"TEST_DOM_NAME);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_users_equal(&pwd, &getpwnam_fqdn);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek return EOK;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek}
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozekvoid test_nss_getpwnam_fqdn(void **state)
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek{
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek errno_t ret;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &getpwnam_fqdn, NULL, 0);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_int_equal(ret, EOK);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek mock_input_user_or_group("testuser_fqdn@"TEST_DOM_NAME);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek mock_fill_user();
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek /* Query for that user, call a callback when command finishes */
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek set_cmd_cb(test_nss_getpwnam_check_fqdn);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek nss_test_ctx->cctx->rctx->domains[0].fqnames = true;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek nss_test_ctx->nss_cmds);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_int_equal(ret, EOK);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek /* Wait until the test finishes with EOK */
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_int_equal(ret, EOK);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek}
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek/* Check that a user with a space in his username is returned fine.
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd getpwnam_space = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("space user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 225,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 558,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozekstatic int test_nss_getpwnam_check_space(uint32_t status,
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek uint8_t *body, size_t blen)
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek{
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek struct passwd pwd;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek errno_t ret;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(status, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = parse_user_packet(body, blen, &pwd);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_users_equal(&pwd, &getpwnam_space);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek return EOK;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek}
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozekvoid test_nss_getpwnam_space(void **state)
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek{
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek errno_t ret;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Prime the cache with a valid user */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &getpwnam_space, NULL, 0);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek mock_input_user_or_group("space user");
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek mock_fill_user();
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Query for that user, call a callback when command finishes */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek set_cmd_cb(test_nss_getpwnam_check_space);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->nss_cmds);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Wait until the test finishes with EOK */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek}
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozekstatic int test_nss_getpwnam_check_space_sub(uint32_t status,
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek uint8_t *body, size_t blen)
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek{
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek struct passwd pwd;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek errno_t ret;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(status, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = parse_user_packet(body, blen, &pwd);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(pwd.pw_uid, 225);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(pwd.pw_gid, 558);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_string_equal(pwd.pw_name, "space_user");
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_string_equal(pwd.pw_shell, "/bin/sh");
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek return EOK;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek}
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozekvoid test_nss_getpwnam_space_sub(void **state)
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek{
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek errno_t ret;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Set whitespace substitution */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->rctx->override_space = '_';
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek mock_input_user_or_group("space user");
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek mock_fill_user();
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Query for that user, call a callback when command finishes */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek set_cmd_cb(test_nss_getpwnam_check_space_sub);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->nss_cmds);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Wait until the test finishes with EOK */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->rctx->override_space = '\0';
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek}
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozekvoid test_nss_getpwnam_space_sub_query(void **state)
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek{
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek errno_t ret;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Set whitespace substitution */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->rctx->override_space = '_';
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek mock_input_user_or_group("space_user");
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek mock_fill_user();
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Query for that user, call a callback when command finishes */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek set_cmd_cb(test_nss_getpwnam_check_space_sub);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->nss_cmds);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Wait until the test finishes with EOK */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->rctx->override_space = '\0';
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek}
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek/*
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek * Check that FQDN processing is able to handle arbitrarily sized
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * delimiter
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd getpwnam_fancy_fqdn = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testuser_fqdn_fancy"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 125,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 458,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
c86904baad32fbf9e66bf1cdc667aa5e683b48baStef Walterstatic int test_nss_getpwnam_check_fancy_fqdn(uint32_t status,
c86904baad32fbf9e66bf1cdc667aa5e683b48baStef Walter uint8_t *body, size_t blen)
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek{
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek struct passwd pwd;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek errno_t ret;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek nss_test_ctx->cctx->rctx->domains[0].fqnames = false;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek ret = parse_user_packet(body, blen, &pwd);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_int_equal(ret, EOK);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_int_equal(pwd.pw_uid, 125);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_int_equal(pwd.pw_gid, 458);
c86904baad32fbf9e66bf1cdc667aa5e683b48baStef Walter assert_string_equal(pwd.pw_name, "testuser_fqdn_fancy@@@@@"TEST_DOM_NAME);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_string_equal(pwd.pw_shell, "/bin/sh");
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek return EOK;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek}
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
c86904baad32fbf9e66bf1cdc667aa5e683b48baStef Waltervoid test_nss_getpwnam_fqdn_fancy(void **state)
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek{
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek errno_t ret;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek /* Prime the cache with a valid user */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &getpwnam_fancy_fqdn, NULL, 0);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_int_equal(ret, EOK);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
c86904baad32fbf9e66bf1cdc667aa5e683b48baStef Walter mock_input_user_or_group("testuser_fqdn_fancy@"TEST_DOM_NAME);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek mock_fill_user();
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek /* Query for that user, call a callback when command finishes */
c86904baad32fbf9e66bf1cdc667aa5e683b48baStef Walter set_cmd_cb(test_nss_getpwnam_check_fancy_fqdn);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek nss_test_ctx->cctx->rctx->domains[0].fqnames = true;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek nss_test_ctx->nss_cmds);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_int_equal(ret, EOK);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek /* Wait until the test finishes with EOK */
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek assert_int_equal(ret, EOK);
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek}
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha/* Check getting cached and valid id from cache. Account callback will
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha * not be called and test_nss_getpwuid_check will make sure the id is
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha * the same as the test entered before starting
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd getpwuid_usr = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testuser1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 101,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 401,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuser1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test user1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jhastatic int test_nss_getpwuid_check(uint32_t status, uint8_t *body, size_t blen)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha struct passwd pwd;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha errno_t ret;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(status, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = parse_user_packet(body, blen, &pwd);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_users_equal(&pwd, &getpwuid_usr);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha return EOK;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jhavoid test_nss_getpwuid(void **state)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha errno_t ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek uint32_t id = 101;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Prime the cache with a valid user */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &getpwuid_usr, NULL, 0);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha mock_input_id(nss_test_ctx, id);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha mock_fill_user();
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Query for that id, call a callback when command finishes */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha set_cmd_cb(test_nss_getpwuid_check);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID,
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha nss_test_ctx->nss_cmds);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Wait until the test finishes with EOK */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = test_ev_loop(nss_test_ctx->tctx);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha/* Test that searching for a nonexistent id yields ENOENT.
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha * Account callback will be called
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jhavoid test_nss_getpwuid_neg(void **state)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha errno_t ret;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek uid_t uid_neg = 102;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek mock_input_id(nss_test_ctx, uid_neg);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha mock_account_recv_simple();
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
9cc2223e0bc0478c1b47a47fd71bba7e7129492dJakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 0);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID,
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha nss_test_ctx->nss_cmds);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Wait until the test finishes with ENOENT */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = test_ev_loop(nss_test_ctx->tctx);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, ENOENT);
9cc2223e0bc0478c1b47a47fd71bba7e7129492dJakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 0);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Test that subsequent search for a nonexistent id yields
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha * ENOENT and Account callback is not called, on the other hand
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha * the ncache functions will be called
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha nss_test_ctx->tctx->done = false;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek mock_input_id(nss_test_ctx, uid_neg);
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID,
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha nss_test_ctx->nss_cmds);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Wait until the test finishes with ENOENT */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = test_ev_loop(nss_test_ctx->tctx);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, ENOENT);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Negative cache was hit this time */
9cc2223e0bc0478c1b47a47fd71bba7e7129492dJakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 1);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek/* Test that lookup by UID for a user that does
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek * not exist in the cache fetches the user from DP
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd getpwuid_srch = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("exampleuser_search"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 107,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 987,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/examplesearch"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("example search"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jhastatic int test_nss_getpwuid_search_acct_cb(void *pvt)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha struct nss_test_ctx *ctx = talloc_get_type(pvt, struct nss_test_ctx);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return store_user(ctx, ctx->tctx->dom, &getpwuid_srch, NULL, 0);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jhastatic int test_nss_getpwuid_search_check(uint32_t status,
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha uint8_t *body, size_t blen)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha struct passwd pwd;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha errno_t ret;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(status, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = parse_user_packet(body, blen, &pwd);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_users_equal(&pwd, &getpwuid_srch);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha return EOK;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jhavoid test_nss_getpwuid_search(void **state)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha errno_t ret;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha struct ldb_result *res;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek mock_input_id(nss_test_ctx, getpwuid_srch.pw_uid);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha mock_account_recv(0, 0, NULL, test_nss_getpwuid_search_acct_cb, nss_test_ctx);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha mock_fill_user();
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha set_cmd_cb(test_nss_getpwuid_search_check);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = sysdb_getpwuid(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek getpwuid_srch.pw_uid, &res);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(res->count, 0);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID,
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha nss_test_ctx->nss_cmds);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Wait until the test finishes with EOK */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = test_ev_loop(nss_test_ctx->tctx);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* test_nss_getpwuid_search_check will check the id attributes */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = sysdb_getpwuid(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek getpwuid_srch.pw_uid, &res);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(res->count, 1);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha/* Test that searching for an id that is expired in the cache goes to the DP
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha * which updates the record and the NSS responder returns the updated record
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha *
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha * The user's shell attribute is updated.
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd getpwuid_update = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("exampleuser_update"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 109,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 11000,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/exampleuser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("example user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jhastatic int test_nss_getpwuid_update_acct_cb(void *pvt)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha struct nss_test_ctx *ctx = talloc_get_type(pvt, struct nss_test_ctx);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek getpwuid_update.pw_shell = discard_const("/bin/ksh");
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek return store_user(ctx, ctx->tctx->dom, &getpwuid_update, NULL, 0);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jhastatic int test_nss_getpwuid_update_check(uint32_t status,
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha uint8_t *body, size_t blen)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha struct passwd pwd;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha errno_t ret;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(status, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = parse_user_packet(body, blen, &pwd);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_users_equal(&pwd, &getpwuid_update);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha return EOK;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jhavoid test_nss_getpwuid_update(void **state)
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha{
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha errno_t ret;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha struct ldb_result *res;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha const char *shell;
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Prime the cache with a valid but expired user */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &getpwuid_update, NULL, 1);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Mock client input */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek mock_input_id(nss_test_ctx, getpwuid_update.pw_uid);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Mock client command */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Call this function when id is updated by the mock DP request */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha mock_account_recv(0, 0, NULL, test_nss_getpwuid_update_acct_cb, nss_test_ctx);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Call this function to check what the responder returned to the client */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha set_cmd_cb(test_nss_getpwuid_update_check);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Mock output buffer */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha mock_fill_user();
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Fire the command */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID,
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha nss_test_ctx->nss_cmds);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Wait until the test finishes with EOK */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = test_ev_loop(nss_test_ctx->tctx);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha /* Check the user was updated in the cache */
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha ret = sysdb_getpwuid(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek getpwuid_update.pw_uid, &res);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(ret, EOK);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_int_equal(res->count, 1);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha shell = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SHELL, NULL);
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha assert_string_equal(shell, "/bin/ksh");
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha}
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* Testsuite setup and teardown */
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozekvoid test_nss_setup(struct sss_test_conf_param params[],
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek void **state)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek errno_t ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx = talloc_zero(NULL, struct nss_test_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_non_null(nss_test_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
a95c006f748fa9df0dd81509b51974133d2786afLukas Slebodnik nss_test_ctx->tctx = create_dom_test_ctx(nss_test_ctx, TESTS_PATH,
a95c006f748fa9df0dd81509b51974133d2786afLukas Slebodnik TEST_CONF_DB, TEST_DOM_NAME,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek TEST_ID_PROVIDER, params);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_non_null(nss_test_ctx->tctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx->tctx->dom->domain_id = discard_const(TEST_DOM_SID);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->nss_cmds = get_nss_cmds();
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_non_null(nss_test_ctx->nss_cmds);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* FIXME - perhaps this should be folded into sssd_domain_init or strictly
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek * used together
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = sss_names_init(nss_test_ctx, nss_test_ctx->tctx->confdb,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek TEST_DOM_NAME, &nss_test_ctx->tctx->dom->names);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_int_equal(ret, EOK);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Initialize the NSS responder */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->nctx = mock_nctx(nss_test_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_non_null(nss_test_ctx->nctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->rctx = mock_rctx(nss_test_ctx, nss_test_ctx->tctx->ev,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->tctx->dom, nss_test_ctx->nctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_non_null(nss_test_ctx->rctx);
e4549c5364461644723361d688badde7fe137a25Sumit Bose nss_test_ctx->rctx->cdb = nss_test_ctx->tctx->confdb;
f3a5ac1a50c1fccd0801023658e42d2093e1a33aJakub Hrozek nss_test_ctx->nctx->rctx = nss_test_ctx->rctx;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
a22b0af1993a489c9c0e66fdc1083f43b410d12cPavel Březina ret = sss_ad_default_names_ctx(nss_test_ctx->nctx,
a22b0af1993a489c9c0e66fdc1083f43b410d12cPavel Březina &nss_test_ctx->nctx->rctx->global_names);
a22b0af1993a489c9c0e66fdc1083f43b410d12cPavel Březina assert_int_equal(ret, EOK);
a22b0af1993a489c9c0e66fdc1083f43b410d12cPavel Březina assert_non_null(nss_test_ctx->nctx->rctx->global_names);
a22b0af1993a489c9c0e66fdc1083f43b410d12cPavel Březina
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* Create client context */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek nss_test_ctx->cctx = mock_cctx(nss_test_ctx, nss_test_ctx->rctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek assert_non_null(nss_test_ctx->cctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce /* Add nss specific state_ctx */
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce nss_connection_setup(nss_test_ctx->cctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce assert_non_null(nss_test_ctx->cctx->state_ctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* do after previous setup as the former nulls protocol_ctx */
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce nss_test_ctx->cctx->protocol_ctx = mock_prctx(nss_test_ctx->cctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce assert_non_null(nss_test_ctx->cctx->protocol_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group getgrnam_no_members = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 1123,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testgroup"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getgrnam_no_members_check(uint32_t status,
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose uint8_t *body, size_t blen)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek{
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek int ret;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek uint32_t nmem;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek struct group gr;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = parse_group_packet(body, blen, &gr, &nmem);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(nmem, 0);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_groups_equal(&getgrnam_no_members, &gr, nmem);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek return EOK;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek}
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek/* Test that requesting a valid, cached group with no members returns a valid
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek * group structure
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozekvoid test_nss_getgrnam_no_members(void **state)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek{
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek errno_t ret;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Prime the cache with a valid group */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &getgrnam_no_members, 0);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek mock_input_user_or_group(getgrnam_no_members.gr_name);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Query for that group, call a callback when command finishes */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek set_cmd_cb(test_nss_getgrnam_no_members_check);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek nss_test_ctx->nss_cmds);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Wait until the test finishes with EOK */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek}
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd testmember1 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testmember1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 2001,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 456,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testmember1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test member1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd testmember2 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testmember2"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 2002,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 456,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testmember2"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test member2"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group testgroup_members = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 1124,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testgroup_members"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getgrnam_members_check(uint32_t status,
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose uint8_t *body, size_t blen)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek{
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek int ret;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek uint32_t nmem;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek struct group gr;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek const char *exp_members[] = { testmember1.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testmember2.pw_name };
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek struct group expected = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = testgroup_members.gr_gid,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = testgroup_members.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = testgroup_members.gr_passwd,
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek .gr_mem = discard_const(exp_members)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek };
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = parse_group_packet(body, blen, &gr, &nmem);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(nmem, 2);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_groups_equal(&expected, &gr, nmem);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek return EOK;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek}
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek/* Test that requesting a valid, cached group with some members returns a valid
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek * group structure with those members present
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozekvoid test_nss_getgrnam_members(void **state)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek{
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek errno_t ret;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testgroup_members, 0);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testmember1, NULL, 0);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testmember2, NULL, 0);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testgroup_members.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testmember1.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testgroup_members.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testmember2.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek mock_input_user_or_group("testgroup_members");
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Query for that group, call a callback when command finishes */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek set_cmd_cb(test_nss_getgrnam_members_check);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek nss_test_ctx->nss_cmds);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Wait until the test finishes with EOK */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek}
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getgrnam_members_check_fqdn(uint32_t status,
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose uint8_t *body, size_t blen)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek{
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek int ret;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek uint32_t nmem;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek struct group gr;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek const char *exp_members[2];
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek struct group expected = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = testgroup_members.gr_gid,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = testgroup_members.gr_passwd,
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek .gr_mem = discard_const(exp_members)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek };
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek TALLOC_CTX *tmp_ctx;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek tmp_ctx = talloc_new(nss_test_ctx);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_non_null(tmp_ctx);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek exp_members[0] = sss_tc_fqname(tmp_ctx, nss_test_ctx->tctx->dom->names,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom, testmember1.pw_name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_non_null(exp_members[0]);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek exp_members[1] = sss_tc_fqname(tmp_ctx, nss_test_ctx->tctx->dom->names,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom, testmember2.pw_name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_non_null(exp_members[1]);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek expected.gr_name = sss_tc_fqname(tmp_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom->names,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testgroup_members.gr_name);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_non_null(expected.gr_name);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = parse_group_packet(body, blen, &gr, &nmem);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(nmem, 2);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_groups_equal(&expected, &gr, nmem);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(tmp_ctx);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek return EOK;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek}
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek/* Test that requesting a valid, cached group with some members returns a valid
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek * group structure with those members present as fully qualified names
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozekvoid test_nss_getgrnam_members_fqdn(void **state)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek{
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek errno_t ret;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek nss_test_ctx->tctx->dom->fqnames = true;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek mock_input_user_or_group("testgroup_members@"TEST_DOM_NAME);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Query for that group, call a callback when command finishes */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek set_cmd_cb(test_nss_getgrnam_members_check_fqdn);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek nss_test_ctx->nss_cmds);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Wait until the test finishes with EOK */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Restore FQDN settings */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek nss_test_ctx->tctx->dom->fqnames = false;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek}
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek/* Test that requesting a valid, cached group with subdomain members returns
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek * a valid * group structure with those members present as fully
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek * qualified names
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd submember1 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("submember1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 4001,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 456,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/submember1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("sub member1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd submember2 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("submember2"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 4002,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 456,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/submember2"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("sub member2"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group testsubdomgroup = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 2002,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testsubdomgroup"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getgrnam_members_check_subdom(uint32_t status,
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose uint8_t *body, size_t blen)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek{
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek int ret;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek uint32_t nmem;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek struct group gr;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek const char *exp_members[2];
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek struct group expected = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = testsubdomgroup.gr_gid,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = testsubdomgroup.gr_passwd,
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek .gr_mem = discard_const(exp_members)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek };
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek TALLOC_CTX *tmp_ctx;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek tmp_ctx = talloc_new(nss_test_ctx);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_non_null(tmp_ctx);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio exp_members[0] = sss_tc_fqname(tmp_ctx,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom->names,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio submember1.pw_name);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio assert_non_null(exp_members[0]);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio exp_members[1] = sss_tc_fqname(tmp_ctx,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom->names,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio submember2.pw_name);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio assert_non_null(exp_members[1]);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio expected.gr_name = sss_tc_fqname(tmp_ctx,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom->names,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio testsubdomgroup.gr_name);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio assert_non_null(expected.gr_name);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = parse_group_packet(body, blen, &gr, &nmem);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(nmem, 2);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_groups_equal(&expected, &gr, nmem);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(tmp_ctx);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek return EOK;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek}
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozekvoid test_nss_getgrnam_members_subdom(void **state)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek{
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek errno_t ret;
e43929e2cebc3140b550fb6305ba42b8465efc59Michal Zidek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek mock_input_user_or_group("testsubdomgroup@"TEST_SUBDOM_NAME);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Query for that group, call a callback when command finishes */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek set_cmd_cb(test_nss_getgrnam_members_check_subdom);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek nss_test_ctx->nss_cmds);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek /* Wait until the test finishes with EOK */
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek}
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidênciovoid test_nss_getgrnam_members_subdom_nonfqnames(void **state)
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio{
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio errno_t ret;
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio mock_input_user_or_group("testsubdomgroup");
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio mock_account_recv_simple();
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio /* Query for that group, call a callback when command finishes */
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio set_cmd_cb(test_nss_getgrnam_members_check_subdom);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->nss_cmds);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio /* Wait until the test finishes with EOK */
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = test_ev_loop(nss_test_ctx->tctx);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio}
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getgrnam_check_mix_dom(uint32_t status,
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose uint8_t *body, size_t blen)
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek{
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek int ret;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek uint32_t nmem;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek struct group gr;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek const char *exp_members[3];
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek struct group expected = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = testgroup_members.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = testgroup_members.gr_gid,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = testgroup_members.gr_passwd,
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek .gr_mem = discard_const(exp_members)
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek };
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek TALLOC_CTX *tmp_ctx;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek tmp_ctx = talloc_new(nss_test_ctx);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_non_null(tmp_ctx);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio exp_members[0] = sss_tc_fqname(tmp_ctx,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom->names,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio submember1.pw_name);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio assert_non_null(exp_members[0]);
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose exp_members[1] = testmember1.pw_name;
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose exp_members[2] = testmember2.pw_name;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek ret = parse_group_packet(body, blen, &gr, &nmem);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(nmem, 3);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_groups_equal(&expected, &gr, nmem);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(tmp_ctx);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek return EOK;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek}
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozekvoid test_nss_getgrnam_mix_dom(void **state)
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek{
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek errno_t ret;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testgroup_members.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek submember1.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->subdom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek mock_input_user_or_group("testgroup_members");
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek /* Query for that group, call a callback when command finishes */
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek set_cmd_cb(test_nss_getgrnam_check_mix_dom);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek nss_test_ctx->nss_cmds);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek /* Wait until the test finishes with EOK */
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek}
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidênciovoid test_nss_getgrnam_mix_dom_nonfqnames(void **state)
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio{
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio errno_t ret;
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = store_group_member(nss_test_ctx,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio testgroup_members.gr_name,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->tctx->dom,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio submember1.pw_name,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->subdom,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio SYSDB_MEMBER_USER);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio mock_input_user_or_group("testgroup_members");
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio /* Query for that group, call a callback when command finishes */
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio set_cmd_cb(test_nss_getgrnam_check_mix_dom);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->nss_cmds);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio /* Wait until the test finishes with EOK */
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = test_ev_loop(nss_test_ctx->tctx);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio}
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getgrnam_check_mix_dom_fqdn(uint32_t status,
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose uint8_t *body, size_t blen)
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek{
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek int ret;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek uint32_t nmem;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek struct group gr;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek const char *exp_members[3];
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek struct group expected = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = testgroup_members.gr_gid,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = testgroup_members.gr_passwd,
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek .gr_mem = discard_const(exp_members)
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek };
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek TALLOC_CTX *tmp_ctx;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek tmp_ctx = talloc_new(nss_test_ctx);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_non_null(tmp_ctx);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio exp_members[0] = sss_tc_fqname(tmp_ctx,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom->names,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio submember1.pw_name);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio assert_non_null(exp_members[0]);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio if (nss_test_ctx->tctx->dom->fqnames) {
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio exp_members[1] = sss_tc_fqname(tmp_ctx, nss_test_ctx->tctx->dom->names,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->tctx->dom, testmember1.pw_name);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_non_null(exp_members[1]);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio exp_members[2] = sss_tc_fqname(tmp_ctx, nss_test_ctx->tctx->dom->names,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->tctx->dom, testmember2.pw_name);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_non_null(exp_members[2]);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio expected.gr_name = sss_tc_fqname(tmp_ctx,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->tctx->dom->names,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->tctx->dom,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio testgroup_members.gr_name);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_non_null(expected.gr_name);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio } else {
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio exp_members[1] = testmember1.pw_name;
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio exp_members[2] = testmember2.pw_name;
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio expected.gr_name = testgroup_members.gr_name;
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio }
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek ret = parse_group_packet(body, blen, &gr, &nmem);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(nmem, 3);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_groups_equal(&expected, &gr, nmem);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(tmp_ctx);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek return EOK;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek}
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozekvoid test_nss_getgrnam_mix_dom_fqdn(void **state)
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek{
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek errno_t ret;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = store_group_member(nss_test_ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio testgroup_members.gr_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_test_ctx->tctx->dom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio submember1.pw_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio SYSDB_MEMBER_USER);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek nss_test_ctx->tctx->dom->fqnames = true;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek mock_input_user_or_group("testgroup_members@"TEST_DOM_NAME);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek /* Query for that group, call a callback when command finishes */
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek set_cmd_cb(test_nss_getgrnam_check_mix_dom_fqdn);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek nss_test_ctx->nss_cmds);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek /* Wait until the test finishes with EOK */
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek /* Restore FQDN settings */
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek nss_test_ctx->tctx->dom->fqnames = false;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek}
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidênciovoid test_nss_getgrnam_mix_dom_fqdn_nonfqnames(void **state)
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio{
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio errno_t ret;
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = store_group_member(nss_test_ctx,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio testgroup_members.gr_name,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->tctx->dom,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio submember1.pw_name,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->subdom,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio SYSDB_MEMBER_USER);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio mock_input_user_or_group("testgroup_members");
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio /* Query for that group, call a callback when command finishes */
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio set_cmd_cb(test_nss_getgrnam_check_mix_dom_fqdn);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->nss_cmds);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio /* Wait until the test finishes with EOK */
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = test_ev_loop(nss_test_ctx->tctx);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio /* Restore FQDN settings */
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->tctx->dom->fqnames = false;
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio}
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bosestatic int test_nss_getgrnam_check_mix_subdom(uint32_t status,
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose uint8_t *body, size_t blen)
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek{
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek int ret;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek uint32_t nmem;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek struct group gr;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek const char *exp_members[3];
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek struct group expected = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = testsubdomgroup.gr_gid,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = testsubdomgroup.gr_passwd,
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek .gr_mem = discard_const(exp_members)
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek };
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek TALLOC_CTX *tmp_ctx;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek tmp_ctx = talloc_new(nss_test_ctx);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_non_null(tmp_ctx);
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio exp_members[0] = sss_tc_fqname(tmp_ctx,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom->names,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio submember1.pw_name);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio assert_non_null(exp_members[0]);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio exp_members[1] = sss_tc_fqname(tmp_ctx,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom->names,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio submember2.pw_name);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio assert_non_null(exp_members[1]);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek /* Important: this member is from a non-qualified domain, so his name will
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek * not be qualified either
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek exp_members[2] = testmember1.pw_name;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio expected.gr_name = sss_tc_fqname(tmp_ctx,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom->names,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio nss_test_ctx->subdom,
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio testsubdomgroup.gr_name);
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio assert_non_null(expected.gr_name);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose assert_int_equal(status, EOK);
32b976eb666044d106dd85e27f8d0bb1d7b6cd6cSumit Bose
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek ret = parse_group_packet(body, blen, &gr, &nmem);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(nmem, 3);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_groups_equal(&expected, &gr, nmem);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek talloc_free(tmp_ctx);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek return EOK;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek}
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozekvoid test_nss_getgrnam_mix_subdom(void **state)
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek{
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek errno_t ret;
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testsubdomgroup.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->subdom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testmember1.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek mock_input_user_or_group("testsubdomgroup@"TEST_SUBDOM_NAME);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek /* Query for that group, call a callback when command finishes */
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek set_cmd_cb(test_nss_getgrnam_check_mix_subdom);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek nss_test_ctx->nss_cmds);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek /* Wait until the test finishes with EOK */
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek assert_int_equal(ret, EOK);
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek}
000e61bb652400215a9a851d3630cdc7307af398Jakub Hrozek
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidênciovoid test_nss_getgrnam_mix_subdom_nonfqnames(void **state)
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio{
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio errno_t ret;
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = store_group_member(nss_test_ctx,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio testsubdomgroup.gr_name,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->subdom,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio testmember1.pw_name,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->tctx->dom,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio SYSDB_MEMBER_USER);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio mock_input_user_or_group("testsubdomgroup");
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio mock_account_recv_simple();
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio /* Query for that group, call a callback when command finishes */
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio set_cmd_cb(test_nss_getgrnam_check_mix_subdom);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_test_ctx->nss_cmds);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio /* Wait until the test finishes with EOK */
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio ret = test_ev_loop(nss_test_ctx->tctx);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio assert_int_equal(ret, EOK);
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio}
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group space_group = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 2123,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("space group"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozekstatic int test_nss_getgrnam_space_check(uint32_t status,
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek uint8_t *body, size_t blen)
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek{
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek int ret;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek uint32_t nmem;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek struct group gr;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(status, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = parse_group_packet(body, blen, &gr, &nmem);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(nmem, 0);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_groups_equal(&space_group, &gr, nmem);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek return EOK;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek}
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek/* Test that requesting a valid, cached group with space in its name returns a valid
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek * group structure
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozekvoid test_nss_getgrnam_space(void **state)
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek{
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek errno_t ret;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Prime the cache with a valid group */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &space_group, 0);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek mock_input_user_or_group("space group");
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Query for that group, call a callback when command finishes */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek set_cmd_cb(test_nss_getgrnam_space_check);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->nss_cmds);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Wait until the test finishes with EOK */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek}
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozekstatic int test_nss_getgrnam_space_sub_check(uint32_t status,
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek uint8_t *body, size_t blen)
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek{
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek int ret;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek uint32_t nmem;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek struct group gr;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(status, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = parse_group_packet(body, blen, &gr, &nmem);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(nmem, 0);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek space_group.gr_name = discard_const("space_group");
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_groups_equal(&space_group, &gr, nmem);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek return EOK;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek}
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek/* Test that requesting a valid, cached group with space in its name returns a valid
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek * group structure
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozekvoid test_nss_getgrnam_space_sub(void **state)
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek{
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek errno_t ret;
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Set whitespace substitution */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->rctx->override_space = '_';
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek mock_input_user_or_group("space group");
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Query for that group, call a callback when command finishes */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek set_cmd_cb(test_nss_getgrnam_space_sub_check);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM,
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->nss_cmds);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek /* Wait until the test finishes with EOK */
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek nss_test_ctx->rctx->override_space = '\0';
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek assert_int_equal(ret, EOK);
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek}
ef49e1d709c3cbb3eccbc22710964e1ffe2612c9Jakub Hrozek
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bosestatic int test_nss_well_known_sid_check(uint32_t status,
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose uint8_t *body, size_t blen)
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose{
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose const char *name;
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose enum sss_id_type type;
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose size_t rp = 2 * sizeof(uint32_t);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose char *expected_result = sss_mock_ptr_type(char *);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose if (expected_result == NULL) {
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(status, EINVAL);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(blen, 0);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose } else {
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(status, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose SAFEALIGN_COPY_UINT32(&type, body+rp, &rp);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose name = (char *) body+rp;
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(type, SSS_ID_TYPE_GID);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_string_equal(name, expected_result);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose }
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose return EOK;
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose}
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bosevoid test_nss_well_known_getnamebysid(void **state)
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose{
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose errno_t ret;
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_body, "S-1-5-32-550");
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_body, 0);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETNAMEBYSID);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(test_nss_well_known_sid_check, "Print Operators@BUILTIN");
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose set_cmd_cb(test_nss_well_known_sid_check);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETNAMEBYSID,
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose nss_test_ctx->nss_cmds);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(ret, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose /* Wait until the test finishes with EOK */
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(ret, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose}
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bosevoid test_nss_well_known_getnamebysid_special(void **state)
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose{
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose errno_t ret;
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_body, "S-1-2-0");
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_body, 0);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETNAMEBYSID);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(test_nss_well_known_sid_check, "LOCAL@LOCAL AUTHORITY");
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose set_cmd_cb(test_nss_well_known_sid_check);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETNAMEBYSID,
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose nss_test_ctx->nss_cmds);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(ret, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose /* Wait until the test finishes with EOK */
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(ret, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose}
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bosevoid test_nss_well_known_getnamebysid_non_existing(void **state)
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose{
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose errno_t ret;
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_body, "S-1-5-32-123");
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_body, 0);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETNAMEBYSID);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(test_nss_well_known_sid_check, NULL);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose set_cmd_cb(test_nss_well_known_sid_check);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETNAMEBYSID,
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose nss_test_ctx->nss_cmds);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(ret, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose /* Wait until the test finishes with EOK */
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(ret, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose}
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bosevoid test_nss_well_known_getidbysid_failure(void **state)
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose{
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose errno_t ret;
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(__wrap_sss_packet_get_body, "S-1-5-32-550");
a044c9a1012d11a2a75e9976ebf186d2d781d291Pallavi Jha will_return(__wrap_sss_packet_get_body, 0);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_cmd, SSS_NSS_GETIDBYSID);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose will_return(test_nss_well_known_sid_check, NULL);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose set_cmd_cb(test_nss_well_known_sid_check);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETIDBYSID,
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose nss_test_ctx->nss_cmds);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(ret, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose /* Wait until the test finishes with EOK */
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose assert_int_equal(ret, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose}
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bosevoid test_nss_well_known_getsidbyname(void **state)
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose{
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose errno_t ret;
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose const char *names[] = { "Cryptographic Operators@BUILTIN",
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose "BUILTIN\\Cryptographic Operators", NULL};
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose size_t c;
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose for (c = 0; names[c] != NULL; c++) {
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina nss_test_ctx->tctx->done = false;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, names[c]);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, 0);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETSIDBYNAME);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(test_nss_well_known_sid_check, "S-1-5-32-569");
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose set_cmd_cb(test_nss_well_known_sid_check);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETSIDBYNAME,
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose nss_test_ctx->nss_cmds);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose assert_int_equal(ret, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose /* Wait until the test finishes with EOK */
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose assert_int_equal(ret, EOK);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose }
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose}
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bosevoid test_nss_well_known_getsidbyname_nonexisting(void **state)
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose{
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose errno_t ret;
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose const char *names[] = { "Abc@BUILTIN", "BUILTIN\\Abc", NULL };
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose size_t c;
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose for (c = 0; names[c] != NULL; c++) {
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina nss_test_ctx->tctx->done = false;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, names[c]);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, 0);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETSIDBYNAME);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(test_nss_well_known_sid_check, NULL);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose set_cmd_cb(test_nss_well_known_sid_check);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETSIDBYNAME,
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose nss_test_ctx->nss_cmds);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose assert_int_equal(ret, EOK);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose /* Wait until the test finishes with EOK */
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose assert_int_equal(ret, EOK);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose }
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose}
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bosevoid test_nss_well_known_getsidbyname_special(void **state)
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose{
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose errno_t ret;
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose const char *names[] = { "CREATOR OWNER@CREATOR AUTHORITY",
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose "CREATOR AUTHORITY\\CREATOR OWNER", NULL };
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose size_t c;
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose for (c = 0; names[c] != NULL; c++) {
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina nss_test_ctx->tctx->done = false;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, names[c]);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, 0);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETSIDBYNAME);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose will_return(test_nss_well_known_sid_check, "S-1-3-0");
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose set_cmd_cb(test_nss_well_known_sid_check);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETSIDBYNAME,
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose nss_test_ctx->nss_cmds);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose assert_int_equal(ret, EOK);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose /* Wait until the test finishes with EOK */
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose assert_int_equal(ret, EOK);
4f1897ad419790834573643e88ac03e6c5c1c4beSumit Bose }
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose}
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bosestatic int test_nss_getorigbyname_check(uint32_t status, uint8_t *body,
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose size_t blen)
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose{
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose const char *s;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose enum sss_id_type id_type;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose size_t rp = 2 * sizeof(uint32_t);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_int_equal(status, EOK);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose SAFEALIGN_COPY_UINT32(&id_type, body+rp, &rp);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_int_equal(id_type, SSS_ID_TYPE_UID);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose /* Sequence of null terminated strings */
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose s = (char *) body+rp;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_string_equal(s, SYSDB_SID_STR);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose rp += strlen(s) + 1;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_true(rp < blen);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose s = (char *) body+rp;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_string_equal(s, "S-1-2-3-4");
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose rp += strlen(s) + 1;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_true(rp < blen);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose s = (char *) body+rp;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_string_equal(s, ORIGINALAD_PREFIX SYSDB_NAME);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose rp += strlen(s) + 1;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_true(rp < blen);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose s = (char *) body+rp;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_string_equal(s, "orig_name");
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose rp += strlen(s) + 1;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_true(rp < blen);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose s = (char *) body+rp;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_string_equal(s, ORIGINALAD_PREFIX SYSDB_UIDNUM);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose rp += strlen(s) + 1;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_true(rp < blen);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose s = (char *) body+rp;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_string_equal(s, "1234");
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose rp += strlen(s) + 1;
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek assert_true(rp < blen);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek s = (char *) body+rp;
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek assert_string_equal(s, SYSDB_UPN);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek rp += strlen(s) + 1;
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek assert_true(rp < blen);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek s = (char *) body+rp;
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek assert_string_equal(s, "testuserorig@upndomain.test");
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek rp += strlen(s) + 1;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_int_equal(rp, blen);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose return EOK;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose}
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd orig_name = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testuserorig"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 1234,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 5678,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuserorig"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bosevoid test_nss_getorigbyname(void **state)
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose{
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose errno_t ret;
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose struct sysdb_attrs *attrs;
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek const char *test_upn = "testuserorig@upndomain.test";
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose attrs = sysdb_new_attrs(nss_test_ctx);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_non_null(attrs);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, "S-1-2-3-4");
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_int_equal(ret, EOK);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose ret = sysdb_attrs_add_string(attrs, ORIGINALAD_PREFIX SYSDB_NAME,
9decb708802b6483de58ec27feb310baa7892ed9Sumit Bose "orig_name");
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_int_equal(ret, EOK);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose ret = sysdb_attrs_add_uint32(attrs, ORIGINALAD_PREFIX SYSDB_UIDNUM, 1234);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_int_equal(ret, EOK);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, test_upn);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek assert_int_equal(ret, EOK);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose /* Prime the cache with a valid user */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &orig_name, attrs, 0);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_int_equal(ret, EOK);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose mock_input_user_or_group("testuserorig");
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETORIGBYNAME);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose /* Query for that user, call a callback when command finishes */
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose set_cmd_cb(test_nss_getorigbyname_check);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETORIGBYNAME,
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose nss_test_ctx->nss_cmds);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_int_equal(ret, EOK);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose /* Wait until the test finishes with EOK */
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose assert_int_equal(ret, EOK);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek /* Also test looking up the same stuff with UPN */
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek nss_test_ctx->tctx->done = false;
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_upn(test_upn);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETORIGBYNAME);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek /* Query for that user, call a callback when command finishes */
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek set_cmd_cb(test_nss_getorigbyname_check);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETORIGBYNAME,
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek nss_test_ctx->nss_cmds);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek assert_int_equal(ret, EOK);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek /* Wait until the test finishes with EOK */
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek assert_int_equal(ret, EOK);
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose}
229c292143dcd4120acb022682b5b7d0aca622ddSumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bosestatic int test_nss_getorigbyname_extra_check(uint32_t status, uint8_t *body,
e4549c5364461644723361d688badde7fe137a25Sumit Bose size_t blen)
e4549c5364461644723361d688badde7fe137a25Sumit Bose{
e4549c5364461644723361d688badde7fe137a25Sumit Bose const char *s;
e4549c5364461644723361d688badde7fe137a25Sumit Bose enum sss_id_type id_type;
e4549c5364461644723361d688badde7fe137a25Sumit Bose size_t rp = 2 * sizeof(uint32_t);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(status, EOK);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose SAFEALIGN_COPY_UINT32(&id_type, body+rp, &rp);
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(id_type, SSS_ID_TYPE_UID);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose /* Sequence of null terminated strings */
e4549c5364461644723361d688badde7fe137a25Sumit Bose s = (char *) body+rp;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_string_equal(s, SYSDB_SID_STR);
e4549c5364461644723361d688badde7fe137a25Sumit Bose rp += strlen(s) + 1;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_true(rp < blen);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose s = (char *) body+rp;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_string_equal(s, "S-1-2-3-4");
e4549c5364461644723361d688badde7fe137a25Sumit Bose rp += strlen(s) + 1;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_true(rp < blen);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose s = (char *) body+rp;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_string_equal(s, ORIGINALAD_PREFIX SYSDB_NAME);
e4549c5364461644723361d688badde7fe137a25Sumit Bose rp += strlen(s) + 1;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_true(rp < blen);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose s = (char *) body+rp;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_string_equal(s, "orig_name");
e4549c5364461644723361d688badde7fe137a25Sumit Bose rp += strlen(s) + 1;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_true(rp < blen);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose s = (char *) body+rp;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_string_equal(s, ORIGINALAD_PREFIX SYSDB_UIDNUM);
e4549c5364461644723361d688badde7fe137a25Sumit Bose rp += strlen(s) + 1;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_true(rp < blen);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose s = (char *) body+rp;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_string_equal(s, "1234");
e4549c5364461644723361d688badde7fe137a25Sumit Bose rp += strlen(s) + 1;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_true(rp < blen);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose s = (char *) body+rp;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_string_equal(s, "phone");
e4549c5364461644723361d688badde7fe137a25Sumit Bose rp += strlen(s) + 1;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_true(rp < blen);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose s = (char *) body+rp;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_string_equal(s, "+12-34 56 78");
e4549c5364461644723361d688badde7fe137a25Sumit Bose rp += strlen(s) + 1;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_true(rp < blen);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose s = (char *) body+rp;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_string_equal(s, "mobile");
e4549c5364461644723361d688badde7fe137a25Sumit Bose rp += strlen(s) + 1;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_true(rp < blen);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose s = (char *) body+rp;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_string_equal(s, "+98-76 54 32");
e4549c5364461644723361d688badde7fe137a25Sumit Bose rp += strlen(s) + 1;
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(rp, blen);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose return EOK;
e4549c5364461644723361d688badde7fe137a25Sumit Bose}
e4549c5364461644723361d688badde7fe137a25Sumit Bose
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd orig_extra = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testuserorigextra"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 2345,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 6789,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuserorigextra"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
e4549c5364461644723361d688badde7fe137a25Sumit Bosevoid test_nss_getorigbyname_extra_attrs(void **state)
e4549c5364461644723361d688badde7fe137a25Sumit Bose{
e4549c5364461644723361d688badde7fe137a25Sumit Bose errno_t ret;
e4549c5364461644723361d688badde7fe137a25Sumit Bose struct sysdb_attrs *attrs;
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose attrs = sysdb_new_attrs(nss_test_ctx);
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_non_null(attrs);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, "S-1-2-3-4");
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(ret, EOK);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose ret = sysdb_attrs_add_string(attrs, ORIGINALAD_PREFIX SYSDB_NAME,
9decb708802b6483de58ec27feb310baa7892ed9Sumit Bose "orig_name");
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(ret, EOK);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose ret = sysdb_attrs_add_uint32(attrs, ORIGINALAD_PREFIX SYSDB_UIDNUM, 1234);
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(ret, EOK);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose ret = sysdb_attrs_add_string(attrs, "phone", "+12-34 56 78");
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(ret, EOK);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose ret = sysdb_attrs_add_string(attrs, "mobile", "+98-76 54 32");
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(ret, EOK);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose ret = sysdb_attrs_add_string(attrs, "not_extra", "abc");
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(ret, EOK);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &orig_extra, attrs, 0);
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(ret, EOK);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose mock_input_user_or_group("testuserorigextra");
e4549c5364461644723361d688badde7fe137a25Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETORIGBYNAME);
e4549c5364461644723361d688badde7fe137a25Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose /* Query for that user, call a callback when command finishes */
e4549c5364461644723361d688badde7fe137a25Sumit Bose set_cmd_cb(test_nss_getorigbyname_extra_check);
e4549c5364461644723361d688badde7fe137a25Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETORIGBYNAME,
e4549c5364461644723361d688badde7fe137a25Sumit Bose nss_test_ctx->nss_cmds);
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(ret, EOK);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose /* Wait until the test finishes with EOK */
e4549c5364461644723361d688badde7fe137a25Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
e4549c5364461644723361d688badde7fe137a25Sumit Bose assert_int_equal(ret, EOK);
e4549c5364461644723361d688badde7fe137a25Sumit Bose}
e4549c5364461644723361d688badde7fe137a25Sumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bosestatic int test_nss_getorigbyname_multi_check(uint32_t status, uint8_t *body,
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose size_t blen)
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose{
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose const char *s;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose enum sss_id_type id_type;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose size_t rp = 2 * sizeof(uint32_t);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(status, EOK);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose SAFEALIGN_COPY_UINT32(&id_type, body+rp, &rp);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(id_type, SSS_ID_TYPE_UID);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose /* Sequence of null terminated strings */
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, SYSDB_SID_STR);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, "S-1-2-3-4");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, ORIGINALAD_PREFIX SYSDB_NAME);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, "orig_name");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, ORIGINALAD_PREFIX SYSDB_UIDNUM);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, "1234");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, SYSDB_ORIG_MEMBEROF);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, "cn=abc");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, SYSDB_ORIG_MEMBEROF);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, "cn=def");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, SYSDB_ORIG_MEMBEROF);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_true(rp < blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose s = (char *) body+rp;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_string_equal(s, "cn=123");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose rp += strlen(s) + 1;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(rp, blen);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose return EOK;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose}
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd orig_multi = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testuserorigmulti"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 3456,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 7890,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuserorigmulti"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bosevoid test_nss_getorigbyname_multi_value_attrs(void **state)
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose{
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose errno_t ret;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose struct sysdb_attrs *attrs;
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose attrs = sysdb_new_attrs(nss_test_ctx);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_non_null(attrs);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, "S-1-2-3-4");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(ret, EOK);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose ret = sysdb_attrs_add_string(attrs, ORIGINALAD_PREFIX SYSDB_NAME,
9decb708802b6483de58ec27feb310baa7892ed9Sumit Bose "orig_name");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(ret, EOK);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose ret = sysdb_attrs_add_uint32(attrs, ORIGINALAD_PREFIX SYSDB_UIDNUM, 1234);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(ret, EOK);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_ORIG_MEMBEROF, "cn=abc");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(ret, EOK);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_ORIG_MEMBEROF, "cn=def");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(ret, EOK);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_ORIG_MEMBEROF, "cn=123");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(ret, EOK);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &orig_multi, attrs, 0);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(ret, EOK);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose mock_input_user_or_group("testuserorigmulti");
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETORIGBYNAME);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose /* Query for that user, call a callback when command finishes */
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose set_cmd_cb(test_nss_getorigbyname_multi_check);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETORIGBYNAME,
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose nss_test_ctx->nss_cmds);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(ret, EOK);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose /* Wait until the test finishes with EOK */
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose assert_int_equal(ret, EOK);
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose}
5f4d896ec8e06476f4282b562b1044de14c48ecfSumit Bose
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd upn_user = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("upnuser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 34567,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 45678,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testuserorig"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozekstatic int test_nss_getpwnam_upn_check(uint32_t status,
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek uint8_t *body,
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek size_t blen)
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek{
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek struct passwd pwd;
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek errno_t ret;
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(status, EOK);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek ret = parse_user_packet(body, blen, &pwd);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(ret, EOK);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_users_equal(&pwd, &upn_user);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek return EOK;
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek}
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozekvoid test_nss_getpwnam_upn(void **state)
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek{
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek errno_t ret;
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek struct sysdb_attrs *attrs;
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek attrs = sysdb_new_attrs(nss_test_ctx);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_non_null(attrs);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, "upnuser@upndomain.test");
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(ret, EOK);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek /* Prime the cache with a valid user */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &upn_user, attrs, 0);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(ret, EOK);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_upn("upnuser@upndomain.test");
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek mock_fill_user();
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek /* Query for that user, call a callback when command finishes */
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek set_cmd_cb(test_nss_getpwnam_upn_check);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek nss_test_ctx->nss_cmds);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(ret, EOK);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek /* Wait until the test finishes with EOK */
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(ret, EOK);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek}
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bosevoid test_nss_getpwnam_upn_same_domain(void **state)
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose{
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose errno_t ret;
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose struct sysdb_attrs *attrs;
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose attrs = sysdb_new_attrs(nss_test_ctx);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose assert_non_null(attrs);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, "upnuser_upn@" TEST_DOM_NAME);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose assert_int_equal(ret, EOK);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose /* Prime the cache with a valid user */
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose &upn_user, attrs, 0);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose assert_int_equal(ret, EOK);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose mock_input_user_or_group("upnuser_upn@" TEST_DOM_NAME);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose mock_account_recv_simple();
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose mock_fill_user();
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose /* Query for that user, call a callback when command finishes */
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose set_cmd_cb(test_nss_getpwnam_upn_check);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose nss_test_ctx->nss_cmds);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose assert_int_equal(ret, EOK);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose /* Wait until the test finishes with EOK */
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose assert_int_equal(ret, EOK);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose}
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz/* Test that searching for a nonexistent user yields ENOENT.
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek * Account callback will be called
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek */
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozekvoid test_nss_getpwnam_upn_neg(void **state)
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek{
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek errno_t ret;
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_upn("nosuchupnuser@upndomain.test");
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek mock_account_recv_simple();
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 0);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek nss_test_ctx->nss_cmds);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(ret, EOK);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek /* Wait until the test finishes with ENOENT */
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(ret, ENOENT);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina assert_int_equal(nss_test_ctx->ncache_hits, 0);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek /* Test that subsequent search for a nonexistent user yields
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek * ENOENT and Account callback is not called, on the other hand
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek * the ncache functions will be called
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek */
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek nss_test_ctx->tctx->done = false;
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek nss_test_ctx->ncache_hits = 0;
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_upn("nosuchupnuser@upndomain.test");
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM,
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek nss_test_ctx->nss_cmds);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(ret, EOK);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek /* Wait until the test finishes with ENOENT */
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(ret, ENOENT);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek /* Negative cache was hit this time */
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 1);
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek}
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekstatic int test_nss_initgr_check(uint32_t status, uint8_t *body, size_t blen)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek gid_t expected_gids[] = { 3211, 3212 };
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(status, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek check_initgr_packet(body, blen, expected_gids, N_ELEMENTS(expected_gids));
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek return EOK;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd testinitgr_usr = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testinitgr"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 321,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 654,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testinitgr"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test initgroups"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group testinitgr_gr1 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 3211,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testinitgr_gr1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group testinitgr_gr2 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 3212,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testinitgr_gr2"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekvoid test_nss_initgroups(void **state)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek errno_t ret;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek struct sysdb_attrs *attrs;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek attrs = sysdb_new_attrs(nss_test_ctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_non_null(attrs);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
390de028b3130ae564059101c662fe74e0e85a45Lukas Slebodnik ret = sysdb_attrs_add_time_t(attrs, SYSDB_INITGR_EXPIRE,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek time(NULL) + 300);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, "upninitgr@upndomain.test");
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_usr, attrs, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_gr1, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_gr2, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_gr1.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_usr.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_gr2.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_usr.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek mock_input_user_or_group("testinitgr");
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Query for that user, call a callback when command finishes */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek set_cmd_cb(test_nss_initgr_check);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_ctx->nss_cmds);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Wait until the test finishes with EOK */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz/* Test that searching for a nonexistent user yields ENOENT.
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek * Account callback will be called
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekvoid test_initgr_neg_by_name(const char *name, bool is_upn)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek errno_t ret;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina if (is_upn) {
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_upn(name);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina } else {
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_user_or_group(name);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina }
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek mock_account_recv_simple();
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_ctx->nss_cmds);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Wait until the test finishes with ENOENT */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, ENOENT);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina assert_int_equal(nss_test_ctx->ncache_hits, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Test that subsequent search for a nonexistent user yields
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek * ENOENT and Account callback is not called, on the other hand
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek * the ncache functions will be called
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_ctx->tctx->done = false;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_ctx->ncache_hits = 0;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina if (is_upn) {
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_upn(name);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina } else {
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_user_or_group(name);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina }
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_ctx->nss_cmds);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Wait until the test finishes with ENOENT */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, ENOENT);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Negative cache was hit this time */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 1);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekvoid test_nss_initgr_neg(void **state)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek test_initgr_neg_by_name("testinitgr_neg", false);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd testinitgr_srch_usr = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testinitgr_srch"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 421,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 654,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testinitgr_srch"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test initgroups"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group testinitgr_srch_gr1 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 4211,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testinitgr_srch_gr1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group testinitgr_srch_gr2 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 4212,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testinitgr_srch_gr2"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekstatic int test_nss_initgr_search_acct_cb(void *pvt)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek errno_t ret;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek struct sysdb_attrs *attrs;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek attrs = sysdb_new_attrs(nss_test_ctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_non_null(attrs);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
390de028b3130ae564059101c662fe74e0e85a45Lukas Slebodnik ret = sysdb_attrs_add_time_t(attrs, SYSDB_INITGR_EXPIRE,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek time(NULL) + 300);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_srch_usr, attrs, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_srch_gr1, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_srch_gr2, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_srch_gr1.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_srch_usr.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_srch_gr2.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_srch_usr.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek return EOK;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekstatic int test_nss_initgr_search_check(uint32_t status,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek uint8_t *body, size_t blen)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek gid_t expected_gids[] = { 4211, 4212 };
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(status, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek check_initgr_packet(body, blen, expected_gids, N_ELEMENTS(expected_gids));
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek return EOK;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekvoid test_nss_initgr_search(void **state)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek errno_t ret;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek struct ldb_result *res;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek mock_input_user_or_group("testinitgr_srch");
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek mock_account_recv(0, 0, NULL, test_nss_initgr_search_acct_cb, nss_test_ctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek set_cmd_cb(test_nss_initgr_search_check);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = get_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek "testinitgr_srch", &res);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(res->count, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_ctx->nss_cmds);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Wait until the test finishes with EOK */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* test_nss_getpwnam_search_check will check the user attributes */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = get_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek "testinitgr_srch", &res);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(res->count, 1);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd testinitgr_update_usr = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testinitgr_update"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 521,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 654,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testinitgr_update"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test initgroups"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group testinitgr_update_gr1 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 5211,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testinitgr_update_gr1"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group testinitgr_update_gr2 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 5212,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testinitgr_update_gr2"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekstatic int test_nss_initgr_update_acct_cb(void *pvt)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek errno_t ret;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek struct sysdb_attrs *attrs;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek attrs = sysdb_new_attrs(nss_test_ctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_non_null(attrs);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
390de028b3130ae564059101c662fe74e0e85a45Lukas Slebodnik ret = sysdb_attrs_add_time_t(attrs, SYSDB_INITGR_EXPIRE,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek time(NULL) + 300);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = set_user_attr(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_update_usr,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek attrs);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_update_gr2, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_update_gr2.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_update_usr.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek return EOK;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekstatic int test_nss_initgr_update_check(uint32_t status, uint8_t *body, size_t blen)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek gid_t expected_gids[] = { 5211, 5212 };
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(status, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek check_initgr_packet(body, blen, expected_gids, N_ELEMENTS(expected_gids));
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek return EOK;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekvoid test_nss_initgr_update(void **state)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek errno_t ret;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek struct sysdb_attrs *attrs;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek attrs = sysdb_new_attrs(nss_test_ctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_non_null(attrs);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
390de028b3130ae564059101c662fe74e0e85a45Lukas Slebodnik ret = sysdb_attrs_add_time_t(attrs, SYSDB_INITGR_EXPIRE,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek time(NULL) - 1);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_update_usr, attrs, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_update_gr1, 0);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_update_gr1.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_update_usr.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek mock_input_user_or_group("testinitgr_update");
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek mock_account_recv(0, 0, NULL, test_nss_initgr_update_acct_cb, nss_test_ctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek set_cmd_cb(test_nss_initgr_update_check);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Query for that user, call a callback when command finishes */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_ctx->nss_cmds);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Wait until the test finishes with EOK */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd testinitgr_2attr_usr = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testinitgr_2attr"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 521,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 654,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testinitgr_2attr"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test initgroups"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group testinitgr_2attr_gr1 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 5221,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testinitgr_2attr_gr11"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct group testinitgr_2attr_gr2 = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_gid = 5222,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_name = discard_const("testinitgr_2attr_gr12"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .gr_mem = NULL,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnikstatic int test_nss_initgr_update_acct_2expire_attributes_cb(void *pvt)
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik{
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik errno_t ret;
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik struct sysdb_attrs *attrs;
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik attrs = sysdb_new_attrs(nss_test_ctx);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_non_null(attrs);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik ret = sysdb_attrs_add_time_t(attrs, SYSDB_INITGR_EXPIRE,
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik time(NULL) + 300);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = set_user_attr(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_2attr_usr, attrs);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_2attr_gr2, 0);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_2attr_gr2.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_2attr_usr.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik return EOK;
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik}
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnikstatic int test_nss_initgr_update_2expire_attributes_check(uint32_t status,
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik uint8_t *body,
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik size_t blen)
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik{
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik gid_t expected_gids[] = { 5221, 5222 };
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(status, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik check_initgr_packet(body, blen, expected_gids, N_ELEMENTS(expected_gids));
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik return EOK;
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik}
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik/*
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik * SYSDB_INITGR_EXPIRE has default value 0 => initgroups was not finished.
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik * SYSDB_CACHE_EXPIRE has value from future => getpwnam finished successfully
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik *
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik * Test result: DP should be contacted for update.
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik */
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnikvoid test_nss_initgr_update_two_expire_attributes(void **state)
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik{
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik errno_t ret;
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik struct sysdb_attrs *attrs;
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik attrs = sysdb_new_attrs(nss_test_ctx);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_non_null(attrs);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik ret = sysdb_attrs_add_time_t(attrs, SYSDB_INITGR_EXPIRE,
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik 0);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE,
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik time(NULL) + 100);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_2attr_usr, attrs, 0);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testinitgr_2attr_gr1, 0);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_group_member(nss_test_ctx,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_2attr_gr1.gr_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testinitgr_2attr_usr.pw_name,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek SYSDB_MEMBER_USER);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik mock_input_user_or_group("testinitgr_2attr");
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik mock_account_recv(0, 0, NULL,
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik test_nss_initgr_update_acct_2expire_attributes_cb,
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik nss_test_ctx);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik set_cmd_cb(test_nss_initgr_update_2expire_attributes_check);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik /* Query for that user, call a callback when command finishes */
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR,
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik nss_test_ctx->nss_cmds);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik /* Wait until the test finishes with EOK */
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik ret = test_ev_loop(nss_test_ctx->tctx);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik assert_int_equal(ret, EOK);
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik}
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekvoid test_nss_initgroups_upn(void **state)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek errno_t ret;
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_upn("upninitgr@upndomain.test");
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR);
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Query for that user, call a callback when command finishes */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek set_cmd_cb(test_nss_initgr_check);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_ctx->nss_cmds);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek /* Wait until the test finishes with EOK */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek assert_int_equal(ret, EOK);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz/* Test that searching for a nonexistent user yields ENOENT.
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek * Account callback will be called
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek */
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozekvoid test_nss_initgr_neg_upn(void **state)
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek{
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek test_initgr_neg_by_name("upninitgr_neg@upndomain.test", true);
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek}
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int nss_test_setup(void **state)
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek{
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek struct sss_test_conf_param params[] = {
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek { "enumerate", "false" },
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek { NULL, NULL }, /* Sentinel */
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek };
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek test_nss_setup(params, state);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek}
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int nss_fqdn_test_setup(void **state)
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek{
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek struct sss_test_conf_param params[] = {
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek { "enumerate", "false" },
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek { "full_name_format", "%1$s@%2$s" },
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek { NULL, NULL }, /* Sentinel */
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek };
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek test_nss_setup(params, state);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek}
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int nss_test_setup_extra_attr(void **state)
e4549c5364461644723361d688badde7fe137a25Sumit Bose{
e4549c5364461644723361d688badde7fe137a25Sumit Bose struct sss_test_conf_param params[] = {
e4549c5364461644723361d688badde7fe137a25Sumit Bose { "enumerate", "false" },
e4549c5364461644723361d688badde7fe137a25Sumit Bose { NULL, NULL }, /* Sentinel */
e4549c5364461644723361d688badde7fe137a25Sumit Bose };
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose test_nss_setup(params, state);
e4549c5364461644723361d688badde7fe137a25Sumit Bose
e4549c5364461644723361d688badde7fe137a25Sumit Bose nss_test_ctx->nctx->extra_attributes = global_extra_attrs;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
e4549c5364461644723361d688badde7fe137a25Sumit Bose}
e4549c5364461644723361d688badde7fe137a25Sumit Bose
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidênciostatic int nss_subdom_test_setup_common(void **state, bool nonfqnames)
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek{
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek const char *const testdom[4] = { TEST_SUBDOM_NAME, "TEST.SUB", "test", "S-3" };
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio struct sss_domain_info *dom;
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek struct sss_domain_info *subdomain;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek errno_t ret;
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek nss_test_setup(state);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek subdomain = new_subdomain(nss_test_ctx, nss_test_ctx->tctx->dom,
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek testdom[0], testdom[1], testdom[2], testdom[3],
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek false, false, NULL, NULL, 0,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek nss_test_ctx->tctx->confdb);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_non_null(subdomain);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek ret = sysdb_subdomain_store(nss_test_ctx->tctx->sysdb,
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek testdom[0], testdom[1], testdom[2], testdom[3],
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose false, false, NULL, 0, NULL);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek ret = sysdb_update_subdomains(nss_test_ctx->tctx->dom,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek nss_test_ctx->tctx->confdb);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek assert_int_equal(ret, EOK);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio if (nonfqnames) {
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio for (dom = nss_test_ctx->rctx->domains;
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio dom != NULL;
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio dom = get_next_domain(dom, SSS_GND_ALL_DOMAINS)) {
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio if (strcmp(dom->name, subdomain->name) == 0) {
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio dom->fqnames = false;
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio break;
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio }
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio }
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio }
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio ret = sss_resp_populate_cr_domains(nss_test_ctx->rctx);
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio assert_int_equal(ret, EOK);
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio assert_non_null(nss_test_ctx->rctx->cr_domains);
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio
46c99a59c8d6501aa3ad701c567fba577924b48bPavel Březina nss_test_ctx->subdom = nss_test_ctx->tctx->dom->subdomains;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = store_group(nss_test_ctx, nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio &testsubdomgroup, 0);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = store_user(nss_test_ctx, nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio &submember1, NULL, 0);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = store_user(nss_test_ctx, nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio &submember2, NULL, 0);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = store_group_member(nss_test_ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio testsubdomgroup.gr_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio submember1.pw_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio SYSDB_MEMBER_USER);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = store_group_member(nss_test_ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio testsubdomgroup.gr_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio submember2.pw_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio SYSDB_MEMBER_USER);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio}
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidênciostatic int nss_subdom_test_setup(void **state)
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio{
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio return nss_subdom_test_setup_common(state, false);
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio}
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidênciostatic int nss_subdom_test_setup_nonfqnames(void **state)
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio{
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio return nss_subdom_test_setup_common(state, true);
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek}
34926c3809b19f9e70f18931e44bf993321647a8Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int nss_fqdn_fancy_test_setup(void **state)
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek{
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek struct sss_test_conf_param params[] = {
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek { "enumerate", "false" },
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek { "full_name_format", "%1$s@@@@@%2$s" },
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek { NULL, NULL }, /* Sentinel */
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek };
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek test_nss_setup(params, state);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek}
777374243e15c53e7b0a7345e190c1018920be18Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int nss_test_teardown(void **state)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek talloc_free(nss_test_ctx);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidênciostatic int nss_subdom_test_teardown(void **state)
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio{
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio errno_t ret;
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = remove_group_member(nss_test_ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio testsubdomgroup.gr_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio submember2.pw_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio SYSDB_MEMBER_USER);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = remove_group_member(nss_test_ctx,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio testsubdomgroup.gr_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio submember1.pw_name,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_test_ctx->subdom,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio SYSDB_MEMBER_USER);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = delete_user(nss_test_ctx, nss_test_ctx->subdom, &submember2);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = delete_user(nss_test_ctx, nss_test_ctx->subdom, &submember1);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio ret = delete_group(nss_test_ctx, nss_test_ctx->subdom, &testsubdomgroup);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio assert_int_equal(ret, EOK);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio return nss_test_teardown(state);
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio}
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd testbysid = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testsiduser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 12345,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 6890,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testsiduser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test bysid lookup"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozekstatic int test_nss_getnamebysid_check(uint32_t status, uint8_t *body, size_t blen)
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek{
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek size_t rp = 2 * sizeof(uint32_t); /* num_results and reserved */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek uint32_t id_type;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek const char *name;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(status, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek SAFEALIGN_COPY_UINT32(&id_type, body+rp, &rp);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(id_type, SSS_ID_TYPE_UID);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek name = (const char *) body + rp;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_string_equal(name, testbysid.pw_name);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek return EOK;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek}
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozekstatic void test_nss_getnamebysid(void **state)
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek{
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek errno_t ret;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek struct sysdb_attrs *attrs;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek char *user_sid;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek attrs = sysdb_new_attrs(nss_test_ctx);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_non_null(attrs);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek user_sid = talloc_asprintf(attrs, "%s-500",
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx->tctx->dom->domain_id);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_non_null(user_sid);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, user_sid);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testbysid, attrs, 0);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_sid(user_sid);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETNAMEBYSID);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek mock_fill_bysid();
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Query for that user, call a callback when command finishes */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Should go straight to back end, without contacting DP */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek set_cmd_cb(test_nss_getnamebysid_check);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETNAMEBYSID,
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx->nss_cmds);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Wait until the test finishes with EOK */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek}
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz/* Test that searching for a nonexistent user yields ENOENT.
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek * Account callback will be called
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozekvoid test_nss_getnamebysid_neg(void **state)
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek{
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek errno_t ret;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek char *user_sid;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek user_sid = talloc_asprintf(nss_test_ctx, "%s-499",
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx->tctx->dom->domain_id);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_non_null(user_sid);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_sid(user_sid);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek mock_account_recv_simple();
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 0);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETNAMEBYSID,
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx->nss_cmds);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Wait until the test finishes with ENOENT */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, ENOENT);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 0);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Test that subsequent search for a nonexistent user yields
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek * ENOENT and Account callback is not called, on the other hand
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek * the ncache functions will be called
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx->tctx->done = false;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_sid(user_sid);
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETNAMEBYSID,
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx->nss_cmds);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Wait until the test finishes with ENOENT */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, ENOENT);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Negative cache was hit this time */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(nss_test_ctx->ncache_hits, 1);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek}
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd testbysid_update = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testsidbyname_update"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 123456,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 789,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testsidbyname_update"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test bysid lookup"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozekstatic int test_nss_getnamebysid_update_check(uint32_t status,
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek uint8_t *body,
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek size_t blen)
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek{
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek size_t rp = 2 * sizeof(uint32_t); /* num_results and reserved */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek uint32_t id_type;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek const char *name;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(status, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek SAFEALIGN_COPY_UINT32(&id_type, body+rp, &rp);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(id_type, SSS_ID_TYPE_UID);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek name = (const char *) body + rp;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_string_equal(name, "testsidbyname_update");
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek return EOK;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek}
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozekstatic int test_nss_getnamebysid_update_acct_cb(void *pvt)
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek{
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek errno_t ret;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek struct nss_test_ctx *ctx = talloc_get_type(pvt, struct nss_test_ctx);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testbysid_update.pw_shell = discard_const("/bin/ksh");
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testbysid_update, NULL, 0);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek return EOK;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek}
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozekvoid test_nss_getnamebysid_update(void **state)
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek{
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek errno_t ret;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek struct ldb_result *res;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek struct sysdb_attrs *attrs;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek const char *shell;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek char *user_sid;
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek attrs = sysdb_new_attrs(nss_test_ctx);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_non_null(attrs);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek user_sid = talloc_asprintf(attrs, "%s-123456",
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx->tctx->dom->domain_id);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_non_null(user_sid);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, user_sid);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Prime the cache with a valid but expired user */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testbysid_update, attrs, 1);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Mock client input */
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_sid(user_sid);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Mock client command */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETNAMEBYSID);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Call this function when user is updated by the mock DP request */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek mock_account_recv(0, 0, NULL, test_nss_getnamebysid_update_acct_cb,
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Call this function to check what the responder returned to the client */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek set_cmd_cb(test_nss_getnamebysid_update_check);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Mock output buffer */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek mock_fill_bysid();
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Fire the command */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETNAMEBYSID,
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_ctx->nss_cmds);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Wait until the test finishes with EOK */
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek /* Check the user was updated in the cache */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = get_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek testbysid_update.pw_name, &res);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(ret, EOK);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_int_equal(res->count, 1);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek shell = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SHELL, NULL);
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek assert_string_equal(shell, "/bin/ksh");
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek}
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozekstruct passwd testbycert = {
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_name = discard_const("testcertuser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_uid = 23456,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gid = 6890,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_dir = discard_const("/home/testcertuser"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_gecos = discard_const("test cert user"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek .pw_passwd = discard_const("*"),
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek};
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek
440797cba931aa491bf418035f55935943e22b4bSumit Bosestruct passwd testbycert2 = {
440797cba931aa491bf418035f55935943e22b4bSumit Bose .pw_name = discard_const("testcertuser2"),
440797cba931aa491bf418035f55935943e22b4bSumit Bose .pw_uid = 23457,
440797cba931aa491bf418035f55935943e22b4bSumit Bose .pw_gid = 6890,
440797cba931aa491bf418035f55935943e22b4bSumit Bose .pw_dir = discard_const("/home/testcertuser2"),
440797cba931aa491bf418035f55935943e22b4bSumit Bose .pw_gecos = discard_const("test cert user2"),
440797cba931aa491bf418035f55935943e22b4bSumit Bose .pw_shell = discard_const("/bin/sh"),
440797cba931aa491bf418035f55935943e22b4bSumit Bose .pw_passwd = discard_const("*"),
440797cba931aa491bf418035f55935943e22b4bSumit Bose};
440797cba931aa491bf418035f55935943e22b4bSumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose#define TEST_TOKEN_CERT \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"MIIECTCCAvGgAwIBAgIBCDANBgkqhkiG9w0BAQsFADA0MRIwEAYDVQQKDAlJUEEu" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"REVWRUwxHjAcBgNVBAMMFUNlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNTA2MjMx" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"NjMyMDdaFw0xNzA2MjMxNjMyMDdaMDIxEjAQBgNVBAoMCUlQQS5ERVZFTDEcMBoG" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"A1UEAwwTaXBhLWRldmVsLmlwYS5kZXZlbDCCASIwDQYJKoZIhvcNAQEBBQADggEP" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"ADCCAQoCggEBALXUq56VlY+Z0aWLLpFAjFfbElPBXGQsbZb85J3cGyPjaMHC9wS+" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"wjB6Ve4HmQyPLx8hbINdDmbawMHYQvTScLYfsqLtj0Lqw20sUUmedk+Es5Oh9VHo" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"nd8MavYx25Du2u+T0iSgNIDikXguiwCmtAj8VC49ebbgITcjJGzMmiiuJkV3o93Y" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"vvYF0VjLGDQbQWOy7IxzYJeNVJnZWKo67CHdok6qOrm9rxQt81rzwV/mGLbCMUbr" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"+N4M8URtd7EmzaYZQmNm//s2owFrCYMxpLiURPj+URZVuB72504/Ix7X0HCbA/AV" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"26J27fPY5nc8DMwfhUDCbTqPH/JEjd3mvY8CAwEAAaOCASYwggEiMB8GA1UdIwQY" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"MBaAFJOq+KAQmPEnNp8Wok23eGTdE7aDMDsGCCsGAQUFBwEBBC8wLTArBggrBgEF" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"BQcwAYYfaHR0cDovL2lwYS1jYS5pcGEuZGV2ZWwvY2Evb2NzcDAOBgNVHQ8BAf8E" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"BAMCBPAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMHQGA1UdHwRtMGsw" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"aaAxoC+GLWh0dHA6Ly9pcGEtY2EuaXBhLmRldmVsL2lwYS9jcmwvTWFzdGVyQ1JM" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"LmJpbqI0pDIwMDEOMAwGA1UECgwFaXBhY2ExHjAcBgNVBAMMFUNlcnRpZmljYXRl" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"IEF1dGhvcml0eTAdBgNVHQ4EFgQUFaDNd5a53QGpaw5m63hnwXicMQ8wDQYJKoZI" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"hvcNAQELBQADggEBADH7Nj00qqGhGJeXJQAsepqSskz/wooqXh8vgVyb8SS4N0/c" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"0aQtVmY81xamlXE12ZFpwDX43d+EufBkwCUKFX/+8JFDd2doAyeJxv1xM22kKRpc" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"AqITPgMsa9ToGMWxjbVpc/X/5YfZixWPF0/eZUTotBj9oaR039UrhGfyN7OguF/G" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"rzmxtB5y4ZrMpcD/Oe90mkd9HY7sA/fB8OWOUgeRfQoh97HNS0UiDWsPtfxmjQG5" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"zotpoBIZmdH+ipYsu58HohHVlM9Wi5H4QmiiXl+Soldkq7eXYlafcmT7wv8+cKwz" \
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose"Nz0Tm3+eYpFqRo3skr6QzXi525Jkg3r6r+kkhxU="
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bosestatic int test_nss_getnamebycert_check(uint32_t status, uint8_t *body, size_t blen)
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose{
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose size_t rp = 2 * sizeof(uint32_t); /* num_results and reserved */
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose uint32_t id_type;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose const char *name;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(status, EOK);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose SAFEALIGN_COPY_UINT32(&id_type, body + rp, &rp);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(id_type, SSS_ID_TYPE_UID);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose name = (const char *)body + rp;
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek assert_string_equal(name, testbycert.pw_name);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose return EOK;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose}
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bosestatic int test_nss_getlistbycert_check_exp(uint32_t status, uint8_t *body,
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose size_t blen, size_t exp)
440797cba931aa491bf418035f55935943e22b4bSumit Bose{
440797cba931aa491bf418035f55935943e22b4bSumit Bose size_t rp = 0;
440797cba931aa491bf418035f55935943e22b4bSumit Bose uint32_t id_type;
440797cba931aa491bf418035f55935943e22b4bSumit Bose uint32_t num;
440797cba931aa491bf418035f55935943e22b4bSumit Bose uint32_t reserved;
440797cba931aa491bf418035f55935943e22b4bSumit Bose const char *name;
440797cba931aa491bf418035f55935943e22b4bSumit Bose int found = 0;
440797cba931aa491bf418035f55935943e22b4bSumit Bose const char *fq_name1 = "testcertuser@"TEST_DOM_NAME ;
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose const char *fq_name2 = "testcertuser2@"TEST_SUBDOM_NAME;
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(status, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* num_results and reserved */
440797cba931aa491bf418035f55935943e22b4bSumit Bose SAFEALIGN_COPY_UINT32(&num, body + rp, &rp);
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose assert_int_equal(num, exp);
440797cba931aa491bf418035f55935943e22b4bSumit Bose SAFEALIGN_COPY_UINT32(&reserved, body + rp, &rp);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(reserved, 0);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose SAFEALIGN_COPY_UINT32(&id_type, body + rp, &rp);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(id_type, SSS_ID_TYPE_UID);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose name = (const char *)body + rp;
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (num == 1) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_string_equal(name, fq_name1);
440797cba931aa491bf418035f55935943e22b4bSumit Bose return EOK;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose rp += strlen(name) + 1;
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (strcmp(name, fq_name1) == 0) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose found = 1;
440797cba931aa491bf418035f55935943e22b4bSumit Bose } else if (strcmp(name, fq_name2) == 0) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose found = 2;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_in_range(found, 1, 2);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose SAFEALIGN_COPY_UINT32(&id_type, body + rp, &rp);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(id_type, SSS_ID_TYPE_UID);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose name = (const char *)body + rp;
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (found == 1) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_string_equal(name, fq_name2);
440797cba931aa491bf418035f55935943e22b4bSumit Bose } else {
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_string_equal(name, fq_name1);
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose return EOK;
440797cba931aa491bf418035f55935943e22b4bSumit Bose}
440797cba931aa491bf418035f55935943e22b4bSumit Bose
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bosestatic int test_nss_getlistbycert_check_one(uint32_t status, uint8_t *body,
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose size_t blen)
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose{
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose return test_nss_getlistbycert_check_exp(status, body, blen, 1);
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose}
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bosestatic int test_nss_getlistbycert_check_two(uint32_t status, uint8_t *body,
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose size_t blen)
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose{
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose return test_nss_getlistbycert_check_exp(status, body, blen, 2);
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose}
440797cba931aa491bf418035f55935943e22b4bSumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bosestatic void test_nss_getnamebycert(void **state)
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose{
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose errno_t ret;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose struct sysdb_attrs *attrs;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose unsigned char *der = NULL;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose size_t der_size;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose attrs = sysdb_new_attrs(nss_test_ctx);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_non_null(attrs);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose der = sss_base64_decode(nss_test_ctx, TEST_TOKEN_CERT, &der_size);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_non_null(der);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
81c564a0692aa4b719af2219f52894e6cd4bdf9fSumit Bose ret = sysdb_attrs_add_mem(attrs, SYSDB_USER_MAPPED_CERT, der, der_size);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose talloc_free(der);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(ret, EOK);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose /* Prime the cache with a valid user */
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
2dcf7b9b65df21f2aee6cdf051a7fbdef6dfe034Jakub Hrozek &testbycert, attrs, 0);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(ret, EOK);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose talloc_free(attrs);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_cert(TEST_TOKEN_CERT);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETNAMEBYCERT);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose mock_fill_bysid();
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose /* Query for that user, call a callback when command finishes */
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose /* Should go straight to back end, without contacting DP */
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose set_cmd_cb(test_nss_getnamebycert_check);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETNAMEBYCERT,
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose nss_test_ctx->nss_cmds);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(ret, EOK);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose /* Wait until the test finishes with EOK */
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(ret, EOK);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose}
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bosevoid test_nss_getnamebycert_neg(void **state)
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose{
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose errno_t ret;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_cert(TEST_TOKEN_CERT);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose mock_account_recv_simple();
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(nss_test_ctx->ncache_hits, 0);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETNAMEBYCERT,
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose nss_test_ctx->nss_cmds);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(ret, EOK);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose /* Wait until the test finishes with ENOENT */
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(ret, ENOENT);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(nss_test_ctx->ncache_hits, 0);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose /* Test that subsequent search for a nonexistent user yields
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose * ENOENT and Account callback is not called, on the other hand
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose * the ncache functions will be called
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose */
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose nss_test_ctx->tctx->done = false;
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_cert(TEST_TOKEN_CERT);
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETNAMEBYCERT,
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose nss_test_ctx->nss_cmds);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(ret, EOK);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose /* Wait until the test finishes with ENOENT */
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(ret, ENOENT);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose /* Negative cache was hit this time */
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose assert_int_equal(nss_test_ctx->ncache_hits, 1);
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose}
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bosestatic void test_nss_getlistbycert(void **state)
440797cba931aa491bf418035f55935943e22b4bSumit Bose{
440797cba931aa491bf418035f55935943e22b4bSumit Bose errno_t ret;
440797cba931aa491bf418035f55935943e22b4bSumit Bose struct sysdb_attrs *attrs;
440797cba931aa491bf418035f55935943e22b4bSumit Bose unsigned char *der = NULL;
440797cba931aa491bf418035f55935943e22b4bSumit Bose size_t der_size;
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose attrs = sysdb_new_attrs(nss_test_ctx);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_non_null(attrs);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose der = sss_base64_decode(nss_test_ctx, TEST_TOKEN_CERT, &der_size);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_non_null(der);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose ret = sysdb_attrs_add_mem(attrs, SYSDB_USER_MAPPED_CERT, der, der_size);
440797cba931aa491bf418035f55935943e22b4bSumit Bose talloc_free(der);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(ret, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* Prime the cache with a valid user */
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
440797cba931aa491bf418035f55935943e22b4bSumit Bose &testbycert, attrs, 0);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(ret, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose talloc_free(attrs);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose mock_input_cert(TEST_TOKEN_CERT);
440797cba931aa491bf418035f55935943e22b4bSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETLISTBYCERT);
440797cba931aa491bf418035f55935943e22b4bSumit Bose mock_fill_bysid();
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* Query for that user, call a callback when command finishes */
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* Should go straight to back end, without contacting DP. */
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* If there is only a single user mapped the result will look like the */
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* result of getnamebycert. */
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose set_cmd_cb(test_nss_getlistbycert_check_one);
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETLISTBYCERT,
440797cba931aa491bf418035f55935943e22b4bSumit Bose nss_test_ctx->nss_cmds);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(ret, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* Wait until the test finishes with EOK */
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(ret, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose}
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bosestatic void test_nss_getlistbycert_multi(void **state)
440797cba931aa491bf418035f55935943e22b4bSumit Bose{
440797cba931aa491bf418035f55935943e22b4bSumit Bose errno_t ret;
440797cba931aa491bf418035f55935943e22b4bSumit Bose struct sysdb_attrs *attrs;
440797cba931aa491bf418035f55935943e22b4bSumit Bose unsigned char *der = NULL;
440797cba931aa491bf418035f55935943e22b4bSumit Bose size_t der_size;
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose der = sss_base64_decode(nss_test_ctx, TEST_TOKEN_CERT, &der_size);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_non_null(der);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose attrs = sysdb_new_attrs(nss_test_ctx);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_non_null(attrs);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose ret = sysdb_attrs_add_mem(attrs, SYSDB_USER_MAPPED_CERT, der, der_size);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(ret, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* Prime the cache with two valid user */
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
440797cba931aa491bf418035f55935943e22b4bSumit Bose &testbycert, attrs, 0);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(ret, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose talloc_free(attrs);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* Looks like attrs is modified during store_user() makes sure we start
440797cba931aa491bf418035f55935943e22b4bSumit Bose * with fresh data. */
440797cba931aa491bf418035f55935943e22b4bSumit Bose attrs = sysdb_new_attrs(nss_test_ctx);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_non_null(attrs);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose ret = sysdb_attrs_add_mem(attrs, SYSDB_USER_MAPPED_CERT, der, der_size);
440797cba931aa491bf418035f55935943e22b4bSumit Bose talloc_free(der);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(ret, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose ret = store_user(nss_test_ctx, nss_test_ctx->subdom,
440797cba931aa491bf418035f55935943e22b4bSumit Bose &testbycert2, attrs, 0);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(ret, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose talloc_free(attrs);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose mock_input_cert(TEST_TOKEN_CERT);
440797cba931aa491bf418035f55935943e22b4bSumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETLISTBYCERT);
440797cba931aa491bf418035f55935943e22b4bSumit Bose mock_fill_bysid();
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* Query for that user, call a callback when command finishes */
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* Should go straight to back end, without contacting DP */
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose set_cmd_cb(test_nss_getlistbycert_check_two);
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETLISTBYCERT,
440797cba931aa491bf418035f55935943e22b4bSumit Bose nss_test_ctx->nss_cmds);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(ret, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose /* Wait until the test finishes with EOK */
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
440797cba931aa491bf418035f55935943e22b4bSumit Bose assert_int_equal(ret, EOK);
440797cba931aa491bf418035f55935943e22b4bSumit Bose}
440797cba931aa491bf418035f55935943e22b4bSumit Bose
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozekstruct passwd sid_user = {
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek .pw_name = discard_const("testusersid"),
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek .pw_uid = 1234,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek .pw_gid = 5678,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek .pw_dir = discard_const("/home/testusersid"),
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek .pw_gecos = discard_const("test user"),
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek .pw_shell = discard_const("/bin/sh"),
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek .pw_passwd = discard_const("*"),
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek};
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozekstatic int test_nss_getsidbyname_check(uint32_t status,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek uint8_t *body,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek size_t blen)
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek{
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek const char *name;
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek enum sss_id_type type;
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek size_t rp = 2 * sizeof(uint32_t);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek char *expected_result = sss_mock_ptr_type(char *);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek if (expected_result == NULL) {
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(status, EINVAL);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(blen, 0);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek } else {
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(status, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek SAFEALIGN_COPY_UINT32(&type, body+rp, &rp);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek name = (char *) body+rp;
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(type, SSS_ID_TYPE_UID);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_string_equal(name, expected_result);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek }
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek return EOK;
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek}
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozekvoid test_nss_getsidbyname(void **state)
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek{
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek errno_t ret;
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek struct sysdb_attrs *attrs;
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek const char *testuser_sid = "S-1-2-3-4";
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek attrs = sysdb_new_attrs(nss_test_ctx);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_non_null(attrs);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, testuser_sid);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek &sid_user, attrs, 0);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek mock_input_user_or_group("testusersid");
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETSIDBYNAME);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek will_return(test_nss_getsidbyname_check, testuser_sid);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek /* Query for that user, call a callback when command finishes */
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek set_cmd_cb(test_nss_getsidbyname_check);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETSIDBYNAME,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek nss_test_ctx->nss_cmds);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek /* Wait until the test finishes with EOK */
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek}
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozekvoid test_nss_getsidbyupn(void **state)
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek{
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek errno_t ret;
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek struct sysdb_attrs *attrs;
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek const char *testuser_sid = "S-1-2-3-4";
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek const char *testuser_upn = "testusersid@upndomain.test";
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek attrs = sysdb_new_attrs(nss_test_ctx);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_non_null(attrs);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, testuser_sid);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, testuser_upn);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek &sid_user, attrs, 0);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina mock_input_upn(testuser_upn);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETSIDBYNAME);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek will_return(test_nss_getsidbyname_check, testuser_sid);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek /* Query for that user, call a callback when command finishes */
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek set_cmd_cb(test_nss_getsidbyname_check);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETSIDBYNAME,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek nss_test_ctx->nss_cmds);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek /* Wait until the test finishes with EOK */
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek}
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozekvoid test_nss_getsidbyname_neg(void **state)
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek{
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek errno_t ret;
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek mock_input_user_or_group("testnosuchsid");
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek mock_account_recv_simple();
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek /* Query for that user, call a callback when command finishes */
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina set_cmd_cb(NULL);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETSIDBYNAME,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek nss_test_ctx->nss_cmds);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, EOK);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek /* Wait until the test finishes with ENOENT (because there is no such SID */
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek ret = test_ev_loop(nss_test_ctx->tctx);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek assert_int_equal(ret, ENOENT);
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek}
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bosestatic int test_nss_EINVAL_check(uint32_t status, uint8_t *body, size_t blen)
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose{
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(status, EINVAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(blen, 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose return EOK;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose}
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose#define RESET_TCTX do { \
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->tctx->done = false; \
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->tctx->error = EIO; \
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose} while (0)
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bosevoid test_nss_getpwnam_ex(void **state)
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose{
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose errno_t ret;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose &getpwnam_usr, NULL, 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(true, "testuser", 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_fill_user();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Query for that user, call a callback when command finishes */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getpwnam_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use old input format, expect EINVAL */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, "testuser");
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_EINVAL_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use unsupported flag combination, expect EINVAL */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(false, "testuser",
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_NO_CACHE
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose |SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_EINVAL_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use flag SSS_NSS_EX_FLAG_NO_CACHE,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose * will cause a backend lookup -> mock_account_recv_simple() */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(true, "testuser", SSS_NSS_EX_FLAG_NO_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_fill_user();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_account_recv_simple();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getpwnam_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use flag SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(true, "testuser",
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_fill_user();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getpwnam_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose}
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bosevoid test_nss_getpwuid_ex(void **state)
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose{
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose errno_t ret;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose uint32_t id = 101;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Prime the cache with a valid user */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose &getpwuid_usr, NULL, 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_id_ex(nss_test_ctx, id, 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_fill_user();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Query for that id, call a callback when command finishes */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getpwuid_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use old input format, expect failure */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_id(nss_test_ctx, id);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_EINVAL_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use unsupported flag combination, expect EINVAL */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_id_ex(nss_test_ctx, id, SSS_NSS_EX_FLAG_NO_CACHE
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose |SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_EINVAL_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use flag SSS_NSS_EX_FLAG_NO_CACHE,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose * will cause a backend lookup -> mock_account_recv_simple() */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_id_ex(nss_test_ctx, id, SSS_NSS_EX_FLAG_NO_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_fill_user();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_account_recv_simple();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getpwuid_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use flag SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_id_ex(nss_test_ctx, id, SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_fill_user();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getpwuid_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose}
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bosevoid test_nss_getgrnam_ex_no_members(void **state)
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose{
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose errno_t ret;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Test group is still in the cache */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(true, getgrnam_no_members.gr_name, 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Query for that group, call a callback when command finishes */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getgrnam_no_members_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use old input format, expect failure */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, "testgroup");
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_EINVAL_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use unsupported flag combination, expect EINVAL */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(false, getgrnam_no_members.gr_name,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_NO_CACHE
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose |SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_EINVAL_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use flag SSS_NSS_EX_FLAG_NO_CACHE,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose * will cause a backend lookup -> mock_account_recv_simple() */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(true, getgrnam_no_members.gr_name,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_NO_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_account_recv_simple();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getgrnam_no_members_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use flag SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(true, getgrnam_no_members.gr_name,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getgrnam_no_members_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose}
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bosevoid test_nss_getgrgid_ex_no_members(void **state)
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose{
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose errno_t ret;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Test group is still in the cache */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_id_ex(nss_test_ctx, getgrnam_no_members.gr_gid, 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRGID_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_account_recv_simple();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Query for that group, call a callback when command finishes */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getgrnam_no_members_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRGID_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use old input format, expect failure */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_id(nss_test_ctx, getgrnam_no_members.gr_gid);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRGID_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_EINVAL_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRGID_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use unsupported flag combination, expect EINVAL */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_id_ex(nss_test_ctx, getgrnam_no_members.gr_gid,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_NO_CACHE
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose |SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRGID_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_EINVAL_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRGID_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use flag SSS_NSS_EX_FLAG_NO_CACHE,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose * will cause a backend lookup -> mock_account_recv_simple() */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_id_ex(nss_test_ctx, getgrnam_no_members.gr_gid,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_NO_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRGID_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_account_recv_simple();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_account_recv_simple();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getgrnam_no_members_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRGID_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use flag SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_id_ex(nss_test_ctx, getgrnam_no_members.gr_gid,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRGID_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_getgrnam_no_members_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRGID_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose}
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bosevoid test_nss_initgroups_ex(void **state)
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose{
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose errno_t ret;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose struct sysdb_attrs *attrs;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose attrs = sysdb_new_attrs(nss_test_ctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_non_null(attrs);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sysdb_attrs_add_time_t(attrs, SYSDB_INITGR_EXPIRE,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose time(NULL) + 300);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, "upninitgr@upndomain.test");
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose &testinitgr_usr, attrs, 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(true, "testinitgr", 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_fill_user();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Query for that user, call a callback when command finishes */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_initgr_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use old input format, expect failure */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, "testinitgr");
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_body, 0);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_EINVAL_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use unsupported flag combination, expect EINVAL */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(false, "testinitgr",
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_NO_CACHE
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose |SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_EINVAL_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use flag SSS_NSS_EX_FLAG_NO_CACHE,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose * will cause a backend lookup -> mock_account_recv_simple() */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(true, "testinitgr",
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_NO_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_fill_user();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_account_recv_simple();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_initgr_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose RESET_TCTX;
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Use flag SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_input_user_or_group_ex(true, "testinitgr",
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR_EX);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose mock_fill_user();
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose set_cmd_cb(test_nss_initgr_check);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR_EX,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_ctx->nss_cmds);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose /* Wait until the test finishes with EOK */
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose ret = test_ev_loop(nss_test_ctx->tctx);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose assert_int_equal(ret, EOK);
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose}
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekint main(int argc, const char *argv[])
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek int rv;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek int no_cleanup = 0;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek poptContext pc;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek int opt;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct poptOption long_options[] = {
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek POPT_AUTOHELP
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek SSSD_DEBUG_OPTS
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek _("Do not delete the test database after a test run"), NULL },
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek POPT_TABLEEND
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek };
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwuid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam_neg,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwuid_neg,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam_search,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwuid_search,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam_update,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwuid_update,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam_fqdn,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_fqdn_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam_fqdn_fancy,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_fqdn_fancy_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam_space,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam_space_sub,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam_space_sub_query,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getgrnam_no_members,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getgrnam_members,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getgrnam_members_fqdn,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_fqdn_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getgrnam_members_subdom,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_subdom_test_setup,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_subdom_test_teardown),
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio cmocka_unit_test_setup_teardown(test_nss_getgrnam_members_subdom_nonfqnames,
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio nss_subdom_test_setup_nonfqnames,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_subdom_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_dom,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_subdom_test_setup,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_subdom_test_teardown),
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_dom_nonfqnames,
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio nss_subdom_test_setup_nonfqnames,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_subdom_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_dom_fqdn,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_subdom_test_setup,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_subdom_test_teardown),
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_dom_fqdn_nonfqnames,
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio nss_subdom_test_setup_nonfqnames,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_subdom_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_subdom,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_subdom_test_setup,
a3442e4a268ad2172c89d58e6daa759eb4b39e7cFabiano Fidêncio nss_subdom_test_teardown),
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_subdom_nonfqnames,
ed518f61f1a5d4cf5d87eec492c158725a73d6a1Fabiano Fidêncio nss_subdom_test_setup_nonfqnames,
5856a621ac5909ca96520ac5a809eb83fd46d8bcFabiano Fidêncio nss_subdom_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getgrnam_space,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getgrnam_space_sub,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_well_known_getnamebysid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_well_known_getnamebysid_special,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_well_known_getnamebysid_non_existing,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_well_known_getidbysid_failure,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_well_known_getsidbyname,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_well_known_getsidbyname_nonexisting,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_well_known_getsidbyname_special,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup, nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getorigbyname,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getorigbyname_extra_attrs,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup_extra_attr,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getorigbyname_multi_value_attrs,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_setup_extra_attr,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek nss_test_teardown),
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getorigbyname,
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek nss_test_setup,
03713a6444fdecd01465b9d5fbfead9601adce6eJakub Hrozek nss_test_teardown),
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam_upn,
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek nss_test_setup, nss_test_teardown),
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose cmocka_unit_test_setup_teardown(test_nss_getpwnam_upn_same_domain,
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose nss_test_setup, nss_test_teardown),
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getpwnam_upn_neg,
84a4c4fcc93b3dcc70604817a05f7943606ff596Jakub Hrozek nss_test_setup, nss_test_teardown),
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_initgroups,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_setup, nss_test_teardown),
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_initgr_neg,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_setup, nss_test_teardown),
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_initgr_search,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_setup, nss_test_teardown),
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_initgr_update,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_setup, nss_test_teardown),
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik cmocka_unit_test_setup_teardown(test_nss_initgr_update_two_expire_attributes,
fd60528321fd52720222ec35b895ade54cccb48dLukas Slebodnik nss_test_setup, nss_test_teardown),
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_initgroups_upn,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_setup, nss_test_teardown),
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_initgr_neg_upn,
aa648535f445e7a95bf6dedc7c43bb5f94ab7354Jakub Hrozek nss_test_setup, nss_test_teardown),
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getnamebysid,
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_setup, nss_test_teardown),
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getnamebysid_neg,
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_setup, nss_test_teardown),
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getnamebysid_update,
bbd6f73bbad478a450ecfa2933a63de6dc269778Jakub Hrozek nss_test_setup, nss_test_teardown),
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose cmocka_unit_test_setup_teardown(test_nss_getnamebycert_neg,
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose nss_test_setup, nss_test_teardown),
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose cmocka_unit_test_setup_teardown(test_nss_getnamebycert,
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose nss_test_setup, nss_test_teardown),
440797cba931aa491bf418035f55935943e22b4bSumit Bose cmocka_unit_test_setup_teardown(test_nss_getlistbycert,
440797cba931aa491bf418035f55935943e22b4bSumit Bose nss_test_setup, nss_test_teardown),
440797cba931aa491bf418035f55935943e22b4bSumit Bose cmocka_unit_test_setup_teardown(test_nss_getlistbycert_multi,
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose nss_subdom_test_setup,
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose nss_subdom_test_teardown),
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getsidbyname,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek nss_test_setup, nss_test_teardown),
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getsidbyupn,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek nss_test_setup, nss_test_teardown),
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek cmocka_unit_test_setup_teardown(test_nss_getsidbyname_neg,
eb9bc1c590b8c3b3b58574c70d9fe5357ef3e901Jakub Hrozek nss_test_setup, nss_test_teardown),
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose cmocka_unit_test_setup_teardown(test_nss_getpwnam_ex,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_setup, nss_test_teardown),
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose cmocka_unit_test_setup_teardown(test_nss_getpwuid_ex,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_setup, nss_test_teardown),
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose cmocka_unit_test_setup_teardown(test_nss_getgrnam_ex_no_members,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_setup, nss_test_teardown),
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose cmocka_unit_test_setup_teardown(test_nss_getgrgid_ex_no_members,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_setup, nss_test_teardown),
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose cmocka_unit_test_setup_teardown(test_nss_initgroups_ex,
85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86Sumit Bose nss_test_setup, nss_test_teardown),
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek };
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek debug_level = SSSDBG_INVALID;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek switch(opt) {
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek default:
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek poptPrintUsage(pc, stderr, 0);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return 1;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek }
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek }
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek poptFreeContext(pc);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(debug_level);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* 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 */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek tests_set_cwd();
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek test_dom_suite_setup(TESTS_PATH);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (rv == 0 && !no_cleanup) {
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek }
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose#ifdef HAVE_NSS
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Cleanup NSS and NSPR to make Valgrind happy. */
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose nspr_nss_cleanup();
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose#endif
1a45124f3f300f9afdcb08eab0938e5e7d0534d9Sumit Bose
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return rv;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}