From 980851d1848562405d9047b499f7faf489d9031a Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Wed, 4 Nov 2009 12:36:25 +0100 Subject: Add sysdb_attrs_replace_name to sysdb API. --- server/db/sysdb.c | 32 ++++++++++++++++++++++++++++++++ server/db/sysdb.h | 3 +++ 2 files changed, 35 insertions(+) (limited to 'server/db') diff --git a/server/db/sysdb.c b/server/db/sysdb.c index a2ac3b22..ae32ef4b 100644 --- a/server/db/sysdb.c +++ b/server/db/sysdb.c @@ -1429,3 +1429,35 @@ int compare_ldb_dn_comp_num(const void *m1, const void *m2) return ldb_dn_get_comp_num(msg2->dn) - ldb_dn_get_comp_num(msg1->dn); } +int sysdb_attrs_replace_name(struct sysdb_attrs *attrs, const char *oldname, + const char *newname) +{ + struct ldb_message_element *e = NULL; + int i; + const char *dummy; + + if (attrs == NULL || oldname == NULL || newname == NULL) return EINVAL; + + for (i = 0; i < attrs->num; i++) { + if (strcasecmp(oldname, attrs->a[i].name) == 0) { + e = &(attrs->a[i]); + } + if (strcasecmp(newname, attrs->a[i].name) == 0) { + DEBUG(3, ("New attribute name [%s] already exists.\n", newname)); + return EEXIST; + } + } + + if (e != NULL) { + dummy = talloc_strdup(attrs, newname); + if (dummy == NULL) { + DEBUG(1, ("talloc_strdup failed.\n")); + return ENOMEM; + } + + talloc_free(discard_const(e->name)); + e->name = dummy; + } + + return EOK; +} diff --git a/server/db/sysdb.h b/server/db/sysdb.h index 642cc30a..0b474221 100644 --- a/server/db/sysdb.h +++ b/server/db/sysdb.h @@ -174,6 +174,9 @@ int sysdb_attrs_get_el(struct sysdb_attrs *attrs, const char *name, int sysdb_attrs_steal_string(struct sysdb_attrs *attrs, const char *name, char *str); +int sysdb_attrs_replace_name(struct sysdb_attrs *attrs, const char *oldname, + const char *newname); + /* convert an ldb error into an errno error */ int sysdb_error_to_errno(int ldberr); -- cgit