summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2011-09-19 12:53:37 +0200
committerStephen Gallagher <sgallagh@redhat.com>2011-10-13 13:32:31 -0400
commit684d1b48b5582a1bf7812b8c3c663592dc6dfed9 (patch)
tree63122c680b079a9c31a046ebb38a3489f0b1c95a /src/db
parent90a83f3c7b49e689d47553a5aa0eb15751846963 (diff)
downloadsssd-684d1b48b5582a1bf7812b8c3c663592dc6dfed9.tar.gz
sssd-684d1b48b5582a1bf7812b8c3c663592dc6dfed9.tar.xz
sssd-684d1b48b5582a1bf7812b8c3c663592dc6dfed9.zip
SysDB commands that save lastUpdate allows this value to be passed in
https://fedorahosted.org/sssd/ticket/836
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb.h21
-rw-r--r--src/db/sysdb_ops.c66
2 files changed, 55 insertions, 32 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 2985a1a0c..88767d3cf 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -473,11 +473,13 @@ int sysdb_add_user(struct sysdb_ctx *sysdb,
const char *homedir,
const char *shell,
struct sysdb_attrs *attrs,
- int cache_timeout);
+ int cache_timeout,
+ time_t now);
int sysdb_add_fake_user(struct sysdb_ctx *sysdb,
const char *name,
- const char *original_dn);
+ const char *original_dn,
+ time_t now);
/* Add group (only basic attrs and w/o checks) */
int sysdb_add_basic_group(struct sysdb_ctx *sysdb,
@@ -487,12 +489,14 @@ int sysdb_add_basic_group(struct sysdb_ctx *sysdb,
int sysdb_add_group(struct sysdb_ctx *sysdb,
const char *name, gid_t gid,
struct sysdb_attrs *attrs,
- int cache_timeout);
+ int cache_timeout,
+ time_t now);
int sysdb_add_incomplete_group(struct sysdb_ctx *sysdb,
const char *name,
gid_t gid,
- const char *original_dn, bool posix);
+ const char *original_dn, bool posix,
+ time_t now);
/* Add netgroup (only basic attrs and w/o checks) */
int sysdb_add_basic_netgroup(struct sysdb_ctx *sysdb,
@@ -502,7 +506,8 @@ int sysdb_add_netgroup(struct sysdb_ctx *sysdb,
const char *name,
const char *description,
struct sysdb_attrs *attrs,
- int cache_timeout);
+ int cache_timeout,
+ time_t now);
/* mod_op must be either LDB_FLAG_MOD_ADD or LDB_FLAG_MOD_DELETE */
int sysdb_mod_group_member(struct sysdb_ctx *sysdb,
@@ -519,13 +524,15 @@ int sysdb_store_user(struct sysdb_ctx *sysdb,
const char *shell,
struct sysdb_attrs *attrs,
char **remove_attrs,
- uint64_t cache_timeout);
+ uint64_t cache_timeout,
+ time_t now);
int sysdb_store_group(struct sysdb_ctx *sysdb,
const char *name,
gid_t gid,
struct sysdb_attrs *attrs,
- uint64_t cache_timeout);
+ uint64_t cache_timeout,
+ time_t now);
enum sysdb_member_type {
SYSDB_MEMBER_USER,
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index f4418e4ef..457370f2b 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -811,13 +811,13 @@ int sysdb_add_user(struct sysdb_ctx *sysdb,
const char *homedir,
const char *shell,
struct sysdb_attrs *attrs,
- int cache_timeout)
+ int cache_timeout,
+ time_t now)
{
TALLOC_CTX *tmp_ctx;
struct ldb_message *msg;
struct sysdb_attrs *id_attrs;
uint32_t id;
- time_t now;
int ret;
struct sss_domain_info *domain = sysdb->domain;
@@ -913,7 +913,9 @@ int sysdb_add_user(struct sysdb_ctx *sysdb,
}
}
- now = time(NULL);
+ if (!now) {
+ now = time(NULL);
+ }
ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
if (ret) goto done;
@@ -939,11 +941,11 @@ done:
int sysdb_add_fake_user(struct sysdb_ctx *sysdb,
const char *name,
- const char *original_dn)
+ const char *original_dn,
+ time_t now)
{
TALLOC_CTX *tmp_ctx;
struct ldb_message *msg;
- time_t now;
int ret;
tmp_ctx = talloc_new(NULL);
@@ -968,7 +970,9 @@ int sysdb_add_fake_user(struct sysdb_ctx *sysdb,
ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_NAME, name);
if (ret) goto done;
- now = time(NULL);
+ if (!now) {
+ now = time(NULL);
+ }
ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_CREATE_TIME,
(unsigned long) now);
@@ -1061,12 +1065,12 @@ done:
int sysdb_add_group(struct sysdb_ctx *sysdb,
const char *name, gid_t gid,
struct sysdb_attrs *attrs,
- int cache_timeout)
+ int cache_timeout,
+ time_t now)
{
TALLOC_CTX *tmp_ctx;
struct ldb_message *msg;
uint32_t id;
- time_t now;
int ret;
bool posix;
@@ -1144,7 +1148,9 @@ int sysdb_add_group(struct sysdb_ctx *sysdb,
if (ret) goto done;
}
- now = time(NULL);
+ if (!now) {
+ now = time(NULL);
+ }
ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
if (ret) goto done;
@@ -1172,10 +1178,10 @@ int sysdb_add_incomplete_group(struct sysdb_ctx *sysdb,
const char *name,
gid_t gid,
const char *original_dn,
- bool posix)
+ bool posix,
+ time_t now)
{
TALLOC_CTX *tmp_ctx;
- time_t now;
int ret;
struct sysdb_attrs *attrs;
@@ -1194,7 +1200,9 @@ int sysdb_add_incomplete_group(struct sysdb_ctx *sysdb,
goto done;
}
- now = time(NULL);
+ if (!now) {
+ now = time(NULL);
+ }
ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
if (ret) goto done;
@@ -1320,10 +1328,10 @@ int sysdb_add_netgroup(struct sysdb_ctx *sysdb,
const char *name,
const char *description,
struct sysdb_attrs *attrs,
- int cache_timeout)
+ int cache_timeout,
+ time_t now)
{
TALLOC_CTX *tmp_ctx;
- time_t now;
int ret;
tmp_ctx = talloc_new(NULL);
@@ -1350,7 +1358,9 @@ int sysdb_add_netgroup(struct sysdb_ctx *sysdb,
}
}
- now = time(NULL);
+ if (!now) {
+ now = time(NULL);
+ }
ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
if (ret) goto done;
@@ -1390,11 +1400,11 @@ int sysdb_store_user(struct sysdb_ctx *sysdb,
const char *shell,
struct sysdb_attrs *attrs,
char **remove_attrs,
- uint64_t cache_timeout)
+ uint64_t cache_timeout,
+ time_t now)
{
TALLOC_CTX *tmp_ctx;
struct ldb_message *msg;
- time_t now;
int ret;
errno_t sret = EOK;
bool in_transaction = false;
@@ -1428,10 +1438,15 @@ int sysdb_store_user(struct sysdb_ctx *sysdb,
goto done;
}
+ /* get transaction timestamp */
+ if (!now) {
+ now = time(NULL);
+ }
+
if (ret == ENOENT) {
/* users doesn't exist, turn into adding a user */
ret = sysdb_add_user(sysdb, name, uid, gid,
- gecos, homedir, shell, attrs, cache_timeout);
+ gecos, homedir, shell, attrs, cache_timeout, now);
goto done;
}
@@ -1466,8 +1481,6 @@ int sysdb_store_user(struct sysdb_ctx *sysdb,
if (ret) goto done;
}
- now = time(NULL);
-
ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
if (ret) goto done;
@@ -1519,14 +1532,14 @@ int sysdb_store_group(struct sysdb_ctx *sysdb,
const char *name,
gid_t gid,
struct sysdb_attrs *attrs,
- uint64_t cache_timeout)
+ uint64_t cache_timeout,
+ time_t now)
{
TALLOC_CTX *tmp_ctx;
static const char *src_attrs[] = { SYSDB_NAME, SYSDB_GIDNUM,
SYSDB_ORIG_MODSTAMP, NULL };
struct ldb_message *msg;
bool new_group = false;
- time_t now;
int ret;
tmp_ctx = talloc_new(NULL);
@@ -1551,12 +1564,17 @@ int sysdb_store_group(struct sysdb_ctx *sysdb,
}
}
+ /* get transaction timestamp */
+ if (!now) {
+ now = time(NULL);
+ }
+
/* FIXME: use the remote modification timestamp to know if the
* group needs any update */
if (new_group) {
/* group doesn't exist, turn into adding a group */
- ret = sysdb_add_group(sysdb, name, gid, attrs, cache_timeout);
+ ret = sysdb_add_group(sysdb, name, gid, attrs, cache_timeout, now);
goto done;
}
@@ -1566,8 +1584,6 @@ int sysdb_store_group(struct sysdb_ctx *sysdb,
if (ret) goto done;
}
- now = time(NULL);
-
ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
if (ret) goto done;