sysdb_services.c revision 4c1bf6607060cea867fccf667063c028dfd51e96
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny/*
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny SSSD
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny Authors:
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny Stephen Gallagher <sgallagh@redhat.com>
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny Copyright (C) 2012 Red Hat
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny This program is free software; you can redistribute it and/or modify
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny it under the terms of the GNU General Public License as published by
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny the Free Software Foundation; either version 3 of the License, or
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny (at your option) any later version.
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny This program is distributed in the hope that it will be useful,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny GNU General Public License for more details.
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny You should have received a copy of the GNU General Public License
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny*/
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny#include "util/util.h"
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny#include "db/sysdb.h"
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek#include "db/sysdb_private.h"
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek#include "db/sysdb_services.h"
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozekerrno_t
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozeksysdb_svc_add(TALLOC_CTX *mem_ctx,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct sysdb_ctx *sysdb,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char *primary_name,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek int port,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char **aliases,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char **protocols,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct ldb_dn **dn);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozekstatic errno_t
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozeksysdb_svc_update(struct sysdb_ctx *sysdb,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct ldb_dn *dn,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek int port,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char **aliases,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char **protocols);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozekerrno_t
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozeksysdb_svc_remove_alias(struct sysdb_ctx *sysdb,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct ldb_dn *dn,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char *alias);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozekerrno_t
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozeksysdb_getservbyname(TALLOC_CTX *mem_ctx,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct sysdb_ctx *sysdb,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char *name,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char *proto,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct ldb_result **_res)
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek{
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek errno_t ret;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek int lret;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek TALLOC_CTX *tmp_ctx;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek static const char *attrs[] = SYSDB_SVC_ATTRS;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct ldb_dn *base_dn;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct ldb_result *res;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek char *sanitized_name;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek char *sanitized_proto;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek *_res = NULL;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek tmp_ctx = talloc_new(NULL);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (!tmp_ctx) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek return ENOMEM;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek base_dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek SYSDB_TMPL_SVC_BASE,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek sysdb->domain->name);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (!base_dn) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek ret = ENOMEM;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto done;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek ret = sss_filter_sanitize(tmp_ctx, name, &sanitized_name);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (ret != EOK) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto done;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (proto) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek ret = sss_filter_sanitize(tmp_ctx, proto, &sanitized_proto);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (ret != EOK) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto done;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek lret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek LDB_SCOPE_SUBTREE, attrs,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek SYSDB_SVC_BYNAME_FILTER,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek proto?sanitized_proto:"*",
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek sanitized_name, sanitized_name);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (lret != LDB_SUCCESS) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek ret = sysdb_error_to_errno(lret);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto done;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (res->count == 0) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek ret = ENOENT;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto done;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek *_res = talloc_steal(mem_ctx, res);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek ret = EOK;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozekdone:
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek talloc_free(tmp_ctx);
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek return ret;
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek}
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozekerrno_t
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozeksysdb_getservbyport(TALLOC_CTX *mem_ctx,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct sysdb_ctx *sysdb,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek int port,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char *proto,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct ldb_result **_res)
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek{
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek errno_t ret;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek int lret;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek TALLOC_CTX *tmp_ctx;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek static const char *attrs[] = SYSDB_SVC_ATTRS;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct ldb_dn *base_dn;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct ldb_result *res;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek char *sanitized_proto = NULL;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (port <= 0) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek return EINVAL;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek tmp_ctx = talloc_new(NULL);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (!tmp_ctx) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek return ENOMEM;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek base_dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek SYSDB_TMPL_SVC_BASE,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek sysdb->domain->name);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (!base_dn) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek ret = ENOMEM;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto done;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (proto) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek ret = sss_filter_sanitize(tmp_ctx, proto, &sanitized_proto);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (ret != EOK) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto done;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek lret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek LDB_SCOPE_SUBTREE, attrs,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek SYSDB_SVC_BYPORT_FILTER,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek sanitized_proto?sanitized_proto:"*",
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek (unsigned int) port);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (lret) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek ret = sysdb_error_to_errno(lret);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek goto done;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (res->count == 0) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek ret = ENOENT;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek goto done;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek *_res = talloc_steal(mem_ctx, res);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek ret = EOK;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekdone:
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek talloc_free(tmp_ctx);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek return ret;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek}
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekerrno_t
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozeksysdb_store_service(struct sysdb_ctx *sysdb,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek const char *primary_name,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek int port,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek const char **aliases,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek const char **protocols,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek uint64_t cache_timeout,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek time_t now)
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek{
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek errno_t ret;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek errno_t sret;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek TALLOC_CTX *tmp_ctx;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek bool in_transaction = false;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ldb_result *res = NULL;
f191a6f9f3313df88eaf3debf52eebfe5d3dee59Michal Židek const char *name;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek unsigned int i;
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek struct ldb_dn *update_dn = NULL;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct sysdb_attrs *attrs;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek tmp_ctx = talloc_new(NULL);
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek if (!tmp_ctx) return ENOMEM;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek ret = sysdb_transaction_start(sysdb);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (ret != EOK) goto done;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek in_transaction = true;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek /* Check that the port is unique
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * If the port appears for any service other than
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek * the one matching the primary_name, we need to
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * remove them so that getservbyport() can work
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * properly. Last entry saved to the cache should
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * always "win".
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek */
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek ret = sysdb_getservbyport(tmp_ctx, sysdb, port, NULL, &res);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (ret != EOK && ret != ENOENT) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek goto done;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek } else if (ret != ENOENT) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (res->count != 1) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek /* Somehow the cache has multiple entries with
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * the same port. This is corrupted. We'll delete
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * them all to sort it out.
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek */
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek for (i = 0; i < res->count; i++) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek ("Corrupt cache entry [%s] detected. Deleting\n",
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ldb_dn_canonical_string(tmp_ctx,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny res->msgs[i]->dn)));
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = sysdb_delete_entry(sysdb, res->msgs[i]->dn, true);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (ret != EOK) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny DEBUG(SSSDBG_MINOR_FAILURE,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ("Could not delete corrupt cache entry [%s]\n",
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce ldb_dn_canonical_string(tmp_ctx,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny res->msgs[i]->dn)));
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose }
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose } else {
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek /* Check whether this is the same name as we're currently
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny * saving to the cache.
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce */
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny name = ldb_msg_find_attr_as_string(res->msgs[0],
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose SYSDB_NAME,
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose NULL);
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose if (!name || strcmp(name, primary_name) != 0) {
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (!name) {
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek ("A service with no name?\n"));
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek /* Corrupted */
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny /* Either this is a corrupt entry or it's another service
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny * claiming ownership of this port. In order to account
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny * for port reassignments, we need to delete the old entry.
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny */
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny DEBUG(SSSDBG_TRACE_FUNC,
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce ("Corrupt or replaced cache entry [%s] detected. "
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny "Deleting\n",
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ldb_dn_canonical_string(tmp_ctx,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny res->msgs[0]->dn)));
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce ret = sysdb_delete_entry(sysdb, res->msgs[0]->dn, true);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (ret != EOK) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny DEBUG(SSSDBG_MINOR_FAILURE,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ("Could not delete cache entry [%s]\n",
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ldb_dn_canonical_string(tmp_ctx,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny res->msgs[0]->dn)));
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce talloc_zfree(res);
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* Ok, ports should now be unique. Now look
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce * the service up by name to determine if we
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce * need to update existing entries or modify
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce * aliases.
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny */
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = sysdb_getservbyname(tmp_ctx, sysdb, primary_name, NULL, &res);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (ret != EOK && ret != ENOENT) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce } else if (ret != ENOENT) { /* Found entries */
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce for (i = 0; i < res->count; i++) {
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce /* Check whether this is the same name as we're currently
7fe69bb6ec70bce439c6b975a9a0044c98ff502bSimo Sorce * saving to the cache.
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov name = ldb_msg_find_attr_as_string(res->msgs[i],
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny SYSDB_NAME,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny NULL);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (!name) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce /* Corrupted */
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce DEBUG(SSSDBG_CRIT_FAILURE,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ("A service with no name?\n"));
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce DEBUG(SSSDBG_TRACE_FUNC,
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce ("Corrupt cache entry [%s] detected. Deleting\n",
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce ldb_dn_canonical_string(tmp_ctx,
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce res->msgs[i]->dn)));
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = sysdb_delete_entry(sysdb, res->msgs[i]->dn, true);
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose if (ret != EOK) {
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE,
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose ("Could not delete corrupt cache entry [%s]\n",
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek ldb_dn_canonical_string(tmp_ctx,
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek res->msgs[i]->dn)));
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek goto done;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose } else if (strcmp(name, primary_name) == 0) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose /* This is the same service name, so we need
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek * to update this entry with the values
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek * provided.
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek */
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek if(update_dn) {
2bbc9d6f8d5f2c1b07fd6968314b7f530b7f3a4dMichal Židek DEBUG(SSSDBG_CRIT_FAILURE,
2bbc9d6f8d5f2c1b07fd6968314b7f530b7f3a4dMichal Židek ("Two existing services with the same name: [%s]? "
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce "Deleting both.\n",
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek primary_name));
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* Delete the entry from the previous pass */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = sysdb_delete_entry(sysdb, update_dn, true);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ("Could not delete cache entry [%s]\n",
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ldb_dn_canonical_string(tmp_ctx,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce update_dn)));
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* Delete the new entry as well */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = sysdb_delete_entry(sysdb, res->msgs[i]->dn, true);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (ret != EOK) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ("Could not delete cache entry [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_canonical_string(tmp_ctx,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce res->msgs[i]->dn)));
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce update_dn = NULL;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce } else {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce update_dn = talloc_steal(tmp_ctx, res->msgs[i]->dn);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov /* Another service is claiming this name as an alias.
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov * In order to account for aliases being promoted to
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce * primary names, we need to make sure to remove the
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce * old alias entry.
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = sysdb_svc_remove_alias(sysdb,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce res->msgs[i]->dn,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce primary_name);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (ret != EOK) goto done;
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose }
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose }
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose talloc_zfree(res);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (update_dn) {
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose /* Update the existing entry */
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose ret = sysdb_svc_update(sysdb, update_dn, port, aliases, protocols);
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose } else {
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek /* Add a new entry */
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek ret = sysdb_svc_add(tmp_ctx, sysdb, primary_name, port,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek aliases, protocols, &update_dn);
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (ret != EOK) goto done;
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek /* Set the cache timeout */
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek attrs = sysdb_new_attrs(tmp_ctx);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (!attrs) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = ENOMEM;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose goto done;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (ret) goto done;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE,
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ((cache_timeout) ?
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose (now + cache_timeout) : 0));
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (ret) goto done;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = sysdb_set_entry_attr(sysdb, update_dn, attrs, SYSDB_MOD_REP);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (ret != EOK) goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = sysdb_transaction_commit(sysdb);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (ret == EOK) in_transaction = false;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bosedone:
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (in_transaction) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose sret = sysdb_transaction_cancel(sysdb);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (sret != EOK) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, ("Could not cancel transaction\n"));
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose talloc_free(tmp_ctx);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose return ret;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose}
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bosestruct ldb_dn *
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bosesysdb_svc_dn(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose const char *domain, const char *name)
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose{
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose errno_t ret;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose char *clean_name;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose struct ldb_dn *dn;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = sysdb_dn_sanitize(NULL, name, &clean_name);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (ret != EOK) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose return NULL;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose dn = ldb_dn_new_fmt(mem_ctx, sysdb->ldb, SYSDB_TMPL_SVC,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek clean_name, domain);
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek talloc_free(clean_name);
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek return dn;
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek}
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozekerrno_t
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorcesysdb_svc_add(TALLOC_CTX *mem_ctx,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce struct sysdb_ctx *sysdb,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce const char *primary_name,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce int port,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce const char **aliases,
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek const char **protocols,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek struct ldb_dn **dn)
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek{
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce errno_t ret;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce int lret;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce TALLOC_CTX *tmp_ctx;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce struct ldb_message *msg;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce unsigned long i;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny tmp_ctx = talloc_new(NULL);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (!tmp_ctx) return ENOMEM;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek msg = ldb_msg_new(tmp_ctx);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (!msg) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = ENOMEM;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny /* svc dn */
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny msg->dn = sysdb_svc_dn(sysdb, msg, sysdb->domain->name, primary_name);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (!msg->dn) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* Objectclass */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = add_string(msg, LDB_FLAG_MOD_ADD,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny SYSDB_OBJECTCLASS, SYSDB_SVC_CLASS);
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce if (ret != EOK) goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* Set the primary name */
17195241500e46272018d7897d6e87249870caf2Pavel Reichl ret = add_string(msg, LDB_FLAG_MOD_ADD,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny SYSDB_NAME, primary_name);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (ret != EOK) goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* Set the port number */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = add_ulong(msg, LDB_FLAG_MOD_ADD,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny SYSDB_SVC_PORT, port);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK) goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce /* If this service has any aliases, include them */
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (aliases && aliases[0]) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* Set the name aliases */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny lret = ldb_msg_add_empty(msg, SYSDB_NAME_ALIAS,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny LDB_FLAG_MOD_ADD, NULL);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (lret != LDB_SUCCESS) {
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce ret = sysdb_error_to_errno(lret);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny for (i=0; aliases[i]; i++) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny lret = ldb_msg_add_string(msg, SYSDB_NAME_ALIAS, aliases[i]);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (lret != LDB_SUCCESS) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_error_to_errno(lret);
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce goto done;
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce }
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce }
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce }
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce /* Set the protocols */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov lret = ldb_msg_add_empty(msg, SYSDB_SVC_PROTO,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov LDB_FLAG_MOD_ADD, NULL);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (lret != LDB_SUCCESS) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_error_to_errno(lret);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce for (i=0; protocols[i]; i++) {
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce lret = ldb_msg_add_string(msg, SYSDB_SVC_PROTO, protocols[i]);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (lret != LDB_SUCCESS) {
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce ret = sysdb_error_to_errno(lret);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce goto done;
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce }
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce }
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce /* creation time */
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_CREATE_TIME,
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce (unsigned long)time(NULL));
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce if (ret) goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny lret = ldb_add(sysdb->ldb, msg);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce ret = sysdb_error_to_errno(lret);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (ret == EOK && dn) {
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce *dn = talloc_steal(mem_ctx, msg->dn);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce }
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenydone:
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_TRACE_INTERNAL,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ("Error: %d (%s)\n", ret, strerror(ret)));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny talloc_free(tmp_ctx);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return ret;
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce}
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorcestatic errno_t
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorcesysdb_svc_update(struct sysdb_ctx *sysdb,
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce struct ldb_dn *dn,
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce int port,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char **aliases,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char **protocols)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny{
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny errno_t ret;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ldb_message *msg;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl int lret;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl unsigned int i;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl
17195241500e46272018d7897d6e87249870caf2Pavel Reichl if (!dn || !protocols || !protocols[0]) {
17195241500e46272018d7897d6e87249870caf2Pavel Reichl return EINVAL;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl }
17195241500e46272018d7897d6e87249870caf2Pavel Reichl
17195241500e46272018d7897d6e87249870caf2Pavel Reichl msg = ldb_msg_new(NULL);
17195241500e46272018d7897d6e87249870caf2Pavel Reichl if (!msg) {
17195241500e46272018d7897d6e87249870caf2Pavel Reichl ret = ENOMEM;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl goto done;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl }
17195241500e46272018d7897d6e87249870caf2Pavel Reichl
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose msg->dn = dn;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose /* Update the port */
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = add_ulong(msg, SYSDB_MOD_REP,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose SYSDB_SVC_PORT, port);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (ret != EOK) goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (aliases && aliases[0]) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose /* Update the aliases */
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose lret = ldb_msg_add_empty(msg, SYSDB_NAME_ALIAS, SYSDB_MOD_REP, NULL);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (lret != LDB_SUCCESS) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = ENOMEM;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose for (i = 0; aliases[i]; i++) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose lret = ldb_msg_add_fmt(msg, SYSDB_NAME_ALIAS, "%s", aliases[i]);
9ac2a33f4cdc4941fa63118dcffe8058854f33c4Michal Židek if (lret != LDB_SUCCESS) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = EINVAL;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose /* Update the protocols */
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose lret = ldb_msg_add_empty(msg, SYSDB_SVC_PROTO, SYSDB_MOD_REP, NULL);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (lret != LDB_SUCCESS) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = ENOMEM;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose for (i = 0; protocols[i]; i++) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose lret = ldb_msg_add_fmt(msg, SYSDB_SVC_PROTO, "%s", protocols[i]);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (lret != LDB_SUCCESS) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = EINVAL;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose lret = ldb_modify(sysdb->ldb, msg);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = sysdb_error_to_errno(lret);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bosedone:
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (ret) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_TRACE_INTERNAL,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ("Error: %d (%s)\n", ret, strerror(ret)));
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose talloc_free(msg);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose return ret;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose}
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Boseerrno_t
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bosesysdb_svc_remove_alias(struct sysdb_ctx *sysdb,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose struct ldb_dn *dn,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose const char *alias)
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose{
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose errno_t ret;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose struct ldb_message *msg;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose int lret;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose msg = ldb_msg_new(NULL);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (!msg) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = ENOMEM;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose msg->dn = dn;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = add_string(msg, SYSDB_MOD_DEL,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose SYSDB_NAME_ALIAS, alias);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (ret != EOK) goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose lret = ldb_modify(sysdb->ldb, msg);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = sysdb_error_to_errno(lret);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bosedone:
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (ret) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_TRACE_INTERNAL,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ("Error: %d (%s)\n", ret, strerror(ret)));
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose talloc_zfree(msg);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose return ret;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose}
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Boseerrno_t
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenysysdb_svc_delete(struct sysdb_ctx *sysdb,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char *name,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny int port,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char *proto)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny{
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce errno_t ret, sret;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek TALLOC_CTX *tmp_ctx;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek struct ldb_result *res;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek unsigned int i;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl bool in_transaction;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny tmp_ctx = talloc_new(NULL);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (!tmp_ctx) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_transaction_start(sysdb);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK) goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny in_transaction = true;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (name) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_getservbyname(tmp_ctx, sysdb, name, proto, &res);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK && ret != ENOENT) goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret == ENOENT) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* Doesn't exist in the DB. Nothing to do */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EOK;
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce goto done;
0754ff886f909f0404038eb9c99dd61be1acf5b9Simo Sorce }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny } else {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_getservbyport(tmp_ctx, sysdb, port, proto, &res);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK && ret != ENOENT) goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret == ENOENT) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* Doesn't exist in the DB. Nothing to do */
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce ret = EOK;
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce goto done;
7fe69bb6ec70bce439c6b975a9a0044c98ff502bSimo Sorce }
7fe69bb6ec70bce439c6b975a9a0044c98ff502bSimo Sorce }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* There should only be one matching entry,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny * but if there are multiple, we should delete
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny * them all to de-corrupt the DB.
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny */
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce for (i = 0; i < res->count; i++) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_delete_entry(sysdb, res->msgs[i]->dn, false);
c03b28a38b14fdb59f74864ae4dc56affe256508Simo Sorce if (ret != EOK) goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_transaction_commit(sysdb);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny in_transaction = false;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenydone:
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce if (in_transaction) {
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce sret = sysdb_transaction_cancel(sysdb);
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce if (sret != EOK) {
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce DEBUG(SSSDBG_CRIT_FAILURE,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ("Could not cancel transaction\n"));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK && ret != ENOENT) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_TRACE_INTERNAL,
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce ("Error: %d (%s)\n", ret, strerror(ret)));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
c03b28a38b14fdb59f74864ae4dc56affe256508Simo Sorce talloc_zfree(tmp_ctx);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return ret;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny}
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny