Skip to content

Commit cb11e00

Browse files
aplopezalexey-tikhonov
authored andcommitted
NSS: Fix sysdb_enumpwent_filter()
The "name" attribute was not being added to the TS cache, even though that it is part of the DN (ldb doesn't enforce it). Adding this attribute requires that the DB version is incremented for the TS cache to be regenerated with the missing attribute. This made the if-block in sysdb_enumpwent_filter() rather useless. In addition, once this if-block is executed, the fuction leaves without further processing. Reviewed-by: Alexey Tikhonov <atikhono@redhat.com> Reviewed-by: Sumit Bose <sbose@redhat.com> (cherry picked from commit 11a15c2)
1 parent e0e5f3d commit cb11e00

5 files changed

Lines changed: 66 additions & 12 deletions

File tree

src/db/sysdb_init.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
const char *sysdb_ts_cache_attrs[] = {
3838
SYSDB_OBJECTCLASS,
3939
SYSDB_OBJECTCATEGORY,
40+
SYSDB_NAME,
4041
SYSDB_LAST_UPDATE,
4142
SYSDB_CACHE_EXPIRE,
4243
SYSDB_ORIG_MODSTAMP,
@@ -566,6 +567,12 @@ static errno_t sysdb_domain_cache_upgrade(TALLOC_CTX *mem_ctx,
566567
}
567568
}
568569

570+
if (strcmp(version, SYSDB_VERSION_0_25) == 0) {
571+
ret = sysdb_upgrade_25(sysdb, &version);
572+
if (ret != EOK) {
573+
goto done;
574+
}
575+
}
569576
ret = EOK;
570577
done:
571578
sysdb->ldb = save_ldb;

src/db/sysdb_ops.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ static errno_t sysdb_create_ts_entry(struct sysdb_ctx *sysdb,
10051005
struct sysdb_attrs *attrs)
10061006
{
10071007
struct ldb_message *msg;
1008+
const struct ldb_val *rdn_value;
10081009
errno_t ret;
10091010
int lret;
10101011
TALLOC_CTX *tmp_ctx;
@@ -1013,16 +1014,26 @@ static errno_t sysdb_create_ts_entry(struct sysdb_ctx *sysdb,
10131014
return EOK;
10141015
}
10151016

1017+
if (entry_dn == NULL) {
1018+
return EINVAL;
1019+
}
1020+
10161021
tmp_ctx = talloc_new(NULL);
10171022
if (tmp_ctx == NULL) {
10181023
return ENOMEM;
10191024
}
10201025

1021-
if (entry_dn == NULL) {
1026+
rdn_value = ldb_dn_get_rdn_val(entry_dn);
1027+
if (rdn_value == NULL) {
10221028
ret = EINVAL;
10231029
goto done;
10241030
}
10251031

1032+
ret = sysdb_attrs_add_val_safe(attrs, SYSDB_NAME, rdn_value);
1033+
if (ret != EOK) {
1034+
goto done;
1035+
}
1036+
10261037
msg = sysdb_attrs2msg(tmp_ctx, entry_dn, attrs, 0);
10271038
if (msg == NULL) {
10281039
ret = ENOMEM;
@@ -1048,7 +1059,8 @@ static errno_t sysdb_create_ts_entry(struct sysdb_ctx *sysdb,
10481059
}
10491060

10501061
static struct sysdb_attrs *ts_obj_attrs(TALLOC_CTX *mem_ctx,
1051-
enum sysdb_obj_type obj_type)
1062+
enum sysdb_obj_type obj_type,
1063+
const char *obj_name)
10521064
{
10531065
struct sysdb_attrs *attrs;
10541066
const char *oc;
@@ -1076,6 +1088,12 @@ static struct sysdb_attrs *ts_obj_attrs(TALLOC_CTX *mem_ctx,
10761088
return NULL;
10771089
}
10781090

1091+
ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, obj_name);
1092+
if (ret != EOK) {
1093+
talloc_free(attrs);
1094+
return NULL;
1095+
}
1096+
10791097
return attrs;
10801098
}
10811099

@@ -1273,7 +1291,7 @@ static errno_t sysdb_create_ts_obj(struct sss_domain_info *domain,
12731291
goto done;
12741292
}
12751293

1276-
ts_attrs = ts_obj_attrs(tmp_ctx, obj_type);
1294+
ts_attrs = ts_obj_attrs(tmp_ctx, obj_type, obj_name);
12771295
if (ts_attrs == NULL) {
12781296
ret = ENOMEM;
12791297
goto done;

src/db/sysdb_private.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#ifndef __INT_SYS_DB_H__
2424
#define __INT_SYS_DB_H__
2525

26+
#define SYSDB_VERSION_0_26 "0.26"
2627
#define SYSDB_VERSION_0_25 "0.25"
2728
#define SYSDB_VERSION_0_24 "0.24"
2829
#define SYSDB_VERSION_0_23 "0.23"
@@ -49,7 +50,7 @@
4950
#define SYSDB_VERSION_0_2 "0.2"
5051
#define SYSDB_VERSION_0_1 "0.1"
5152

52-
#define SYSDB_VERSION SYSDB_VERSION_0_25
53+
#define SYSDB_VERSION SYSDB_VERSION_0_26
5354

5455
#define SYSDB_BASE_LDIF \
5556
"dn: @ATTRIBUTES\n" \
@@ -195,6 +196,7 @@ int sysdb_upgrade_21(struct sysdb_ctx *sysdb, const char **ver);
195196
int sysdb_upgrade_22(struct sysdb_ctx *sysdb, const char **ver);
196197
int sysdb_upgrade_23(struct sysdb_ctx *sysdb, const char **ver);
197198
int sysdb_upgrade_24(struct sysdb_ctx *sysdb, const char **ver);
199+
int sysdb_upgrade_25(struct sysdb_ctx *sysdb, const char **ver);
198200

199201
int sysdb_ts_upgrade_01(struct sysdb_ctx *sysdb, const char **ver);
200202

src/db/sysdb_search.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,20 @@ int sysdb_enumpwent_filter(TALLOC_CTX *mem_ctx,
913913
if (ret != EOK && ret != ENOENT) {
914914
goto done;
915915
}
916+
} else {
917+
/* If there are no results, EOK and res->count == 0 are expected */
918+
ts_cache_res = talloc_zero(tmp_ctx, struct ldb_result);
919+
if (ts_cache_res == NULL) {
920+
DEBUG(SSSDBG_OP_FAILURE, "talloc_zero() failed.\n");
921+
ret = ENOMEM;
922+
goto done;
923+
}
916924
}
925+
926+
ret = EOK;
927+
DEBUG(SSSDBG_TRACE_LIBS, "Returning timestamp cache based results [%d].\n", ts_cache_res->count);
928+
*_res = talloc_steal(mem_ctx, ts_cache_res);
929+
goto done;
917930
}
918931

919932
filter = enum_filter(tmp_ctx, SYSDB_PWENT_FILTER,
@@ -939,14 +952,6 @@ int sysdb_enumpwent_filter(TALLOC_CTX *mem_ctx,
939952
ret = EOK;
940953
}
941954

942-
if (ts_cache_res != NULL) {
943-
res = sss_merge_ldb_results(res, ts_cache_res);
944-
if (res == NULL) {
945-
ret = ENOMEM;
946-
goto done;
947-
}
948-
}
949-
950955
*_res = talloc_steal(mem_ctx, res);
951956

952957
done:

src/db/sysdb_upgrade.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,28 @@ int sysdb_upgrade_24(struct sysdb_ctx *sysdb, const char **ver)
28012801
return ret;
28022802
}
28032803

2804+
int sysdb_upgrade_25(struct sysdb_ctx *sysdb, const char **ver)
2805+
{
2806+
struct upgrade_ctx *ctx;
2807+
errno_t ret;
2808+
2809+
ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_26, &ctx);
2810+
if (ret != EOK) {
2811+
return ret;
2812+
}
2813+
2814+
/* We do nothing because the only goal of this version change is to remove the TS cache. */
2815+
2816+
ret = update_version(ctx);
2817+
if (ret != EOK) {
2818+
goto done;
2819+
}
2820+
2821+
done:
2822+
ret = finish_upgrade(ret, &ctx, ver);
2823+
return ret;
2824+
}
2825+
28042826
/*
28052827
* Example template for future upgrades.
28062828
* Copy and change version numbers as appropriate.

0 commit comments

Comments
 (0)