summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2010-09-29 22:15:39 +0200
committerStephen Gallagher <sgallagh@redhat.com>2010-10-15 09:03:07 -0400
commitc1d525a90f06a9414d0788857b271b80625a5858 (patch)
tree82144584d74a7939e801a3fefdf9432c1afd10ad /src/db
parent3dd54ad87fd6a2bc8f646cd93be0329647e96f0e (diff)
downloadsssd-c1d525a90f06a9414d0788857b271b80625a5858.tar.gz
sssd-c1d525a90f06a9414d0788857b271b80625a5858.tar.xz
sssd-c1d525a90f06a9414d0788857b271b80625a5858.zip
sysdb interface for adding fake users
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb.h4
-rw-r--r--src/db/sysdb_ops.c61
2 files changed, 65 insertions, 0 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 7db1a6ea4..a1baa20d9 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -465,6 +465,10 @@ int sysdb_add_user(TALLOC_CTX *mem_ctx,
struct sysdb_attrs *attrs,
int cache_timeout);
+int sysdb_add_fake_user(struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name);
+
/* Add group (only basic attrs and w/o checks) */
int sysdb_add_basic_group(TALLOC_CTX *mem_ctx,
struct sysdb_ctx *ctx,
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index f8e1fbd52..7ae22f7d1 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -916,6 +916,67 @@ done:
return ret;
}
+int sysdb_add_fake_user(struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name)
+{
+ TALLOC_CTX *tmpctx;
+ struct ldb_message *msg;
+ time_t now;
+ int ret;
+
+ tmpctx = talloc_new(NULL);
+ if (!tmpctx) {
+ return ENOMEM;
+ }
+
+ msg = ldb_msg_new(tmpctx);
+ if (!msg) {
+ ERROR_OUT(ret, ENOMEM, done);
+ }
+
+ /* user dn */
+ msg->dn = sysdb_user_dn(ctx, msg, domain->name, name);
+ if (!msg->dn) {
+ ERROR_OUT(ret, ENOMEM, done);
+ }
+
+ ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_OBJECTCLASS, SYSDB_USER_CLASS);
+ if (ret) goto done;
+
+ ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_NAME, name);
+ if (ret) goto done;
+
+ now = time(NULL);
+
+ ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_CREATE_TIME,
+ (unsigned long) now);
+ if (ret) goto done;
+
+ /* set last login so that the fake entry does not get cleaned up
+ * immediately */
+ ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_LAST_LOGIN,
+ (unsigned long) now);
+ if (ret) return ret;
+
+ ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_LAST_UPDATE,
+ (unsigned long) now);
+ if (ret) goto done;
+
+ ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_CACHE_EXPIRE,
+ (unsigned long) now-1);
+ if (ret) goto done;
+
+ ret = ldb_add(ctx->ldb, msg);
+ ret = sysdb_error_to_errno(ret);
+
+done:
+ if (ret != EOK) {
+ DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
+ }
+ talloc_zfree(tmpctx);
+ return ret;
+}
/* =Add-Basic-Group-NO-CHECKS============================================= */