summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/db/sysdb_search.c6
-rw-r--r--src/providers/ipa/ipa_s2n_exop.c8
-rw-r--r--src/responder/nss/nsssrv_cmd.c49
-rw-r--r--src/responder/pac/pacsrv_cmd.c4
-rw-r--r--src/responder/pac/pacsrv_utils.c3
-rw-r--r--src/tools/sss_cache.c3
-rw-r--r--src/util/usertools.c25
-rw-r--r--src/util/util.h16
8 files changed, 70 insertions, 44 deletions
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c
index 843c746d..344ff6fa 100644
--- a/src/db/sysdb_search.c
+++ b/src/db/sysdb_search.c
@@ -57,8 +57,7 @@ int sysdb_getpwnam(TALLOC_CTX *mem_ctx,
* search as well by default */
if (IS_SUBDOMAIN(domain) && domain->fqnames) {
ret = ENOMEM;
- src_name = talloc_asprintf(tmp_ctx, domain->names->fq_fmt,
- name, domain->name);
+ src_name = sss_tc_fqname(tmp_ctx, domain->names, domain, name);
} else {
ret = EINVAL;
src_name = name;
@@ -245,8 +244,7 @@ int sysdb_getgrnam(TALLOC_CTX *mem_ctx,
* search as well by default */
if (IS_SUBDOMAIN(domain) && domain->fqnames) {
ret = ENOMEM;
- src_name = talloc_asprintf(tmp_ctx, domain->names->fq_fmt,
- name, domain->name);
+ src_name = sss_tc_fqname(tmp_ctx, domain->names, domain, name);
} else {
ret = EINVAL;
src_name = name;
diff --git a/src/providers/ipa/ipa_s2n_exop.c b/src/providers/ipa/ipa_s2n_exop.c
index 02a7bc22..f589a06f 100644
--- a/src/providers/ipa/ipa_s2n_exop.c
+++ b/src/providers/ipa/ipa_s2n_exop.c
@@ -757,8 +757,8 @@ static void ipa_s2n_get_user_done(struct tevent_req *subreq)
}
/* we always use the fully qualified name for subdomain users */
- name = talloc_asprintf(state, state->dom->names->fq_fmt,
- attrs->a.user.pw_name, state->dom->name);
+ name = sss_tc_fqname(state, state->dom->names, state->dom,
+ attrs->a.user.pw_name);
if (!name) {
DEBUG(SSSDBG_OP_FAILURE, ("failed to format user name.\n"));
ret = ENOMEM;
@@ -822,8 +822,8 @@ static void ipa_s2n_get_user_done(struct tevent_req *subreq)
break;
case RESP_GROUP:
/* we always use the fully qualified name for subdomain users */
- name = talloc_asprintf(state, state->dom->names->fq_fmt,
- attrs->a.group.gr_name, state->dom->name);
+ name = sss_tc_fqname(state, state->dom->names, state->dom,
+ attrs->a.group.gr_name);
if (!name) {
DEBUG(SSSDBG_OP_FAILURE, ("failed to format user name,\n"));
ret = ENOMEM;
diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
index 57b5786f..268cfc83 100644
--- a/src/responder/nss/nsssrv_cmd.c
+++ b/src/responder/nss/nsssrv_cmd.c
@@ -303,13 +303,10 @@ static int fill_pwent(struct sss_packet *packet,
int i, ret, num, t;
bool add_domain = (!IS_SUBDOMAIN(dom) && dom->fqnames);
const char *domain = dom->name;
- const char *namefmt;
bool packet_initialized = false;
int ncret;
TALLOC_CTX *tmp_ctx = NULL;
- namefmt = dom->names->fq_fmt;
-
if (add_domain) dom_len = strlen(domain);
to_sized_string(&pwfield, nctx->pwfield);
@@ -394,9 +391,8 @@ static int fill_pwent(struct sss_packet *packet,
SAFEALIGN_SET_UINT32(&body[rp], gid, &rp);
if (add_domain) {
- ret = snprintf((char *)&body[rp],
- name.len + delim + dom_len,
- namefmt, name.str, domain);
+ ret = sss_fqname((char *) &body[rp], name.len + delim + dom_len,
+ dom->names, dom, name.str);
if (ret >= (name.len + delim + dom_len)) {
/* need more space, got creative with the print format ? */
t = ret - (name.len + delim + dom_len) + 1;
@@ -409,9 +405,8 @@ static int fill_pwent(struct sss_packet *packet,
sss_packet_get_body(packet, &body, &blen);
/* retry */
- ret = snprintf((char *)&body[rp],
- name.len + delim + dom_len,
- namefmt, name.str, domain);
+ ret = sss_fqname((char *) &body[rp], name.len + delim + dom_len,
+ dom->names, dom, name.str);
}
if (ret != name.len + delim + dom_len - 1) {
@@ -665,7 +660,7 @@ static int delete_entry_from_memcache(struct sss_domain_info *dom, char *name,
}
if (dom->fqnames) {
- fqdn = talloc_asprintf(tmp_ctx, dom->names->fq_fmt, name, dom->name);
+ fqdn = sss_tc_fqname(tmp_ctx, dom->names, dom, name);
if (fqdn == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory.\n"));
ret = ENOMEM;
@@ -2153,7 +2148,6 @@ static int fill_members(struct sss_packet *packet,
size_t rsize = *_rsize;
char *tmpstr;
struct sized_string name;
- const char *namefmt = dom->names->fq_fmt;
TALLOC_CTX *tmp_ctx = NULL;
size_t delim;
@@ -2214,9 +2208,9 @@ static int fill_members(struct sss_packet *packet,
sss_packet_get_body(packet, &body, &blen);
if (add_domain) {
- ret = snprintf((char *)&body[rzero + rsize],
- name.len + delim + dom_len,
- namefmt, name.str, domain);
+ ret = sss_fqname((char *)&body[rzero + rsize],
+ name.len + delim + dom_len,
+ dom->names, dom, name.str);
if (ret >= (name.len + delim + dom_len)) {
/* need more space,
* got creative with the print format ? */
@@ -2229,9 +2223,9 @@ static int fill_members(struct sss_packet *packet,
delim += t;
/* retry */
- ret = snprintf((char *)&body[rzero + rsize],
- name.len + delim + dom_len,
- namefmt, name.str, domain);
+ ret = sss_fqname((char *)&body[rzero + rsize],
+ name.len + delim + dom_len,
+ dom->names, dom, name.str);
}
if (ret != name.len + delim + dom_len - 1) {
@@ -2294,11 +2288,8 @@ static int fill_grent(struct sss_packet *packet,
size_t rzero, rsize;
bool add_domain = (!IS_SUBDOMAIN(dom) && dom->fqnames);
const char *domain = dom->name;
- const char *namefmt;
TALLOC_CTX *tmp_ctx = NULL;
- namefmt = dom->names->fq_fmt;
-
if (add_domain) {
delim = 1;
dom_len = strlen(domain);
@@ -2384,9 +2375,9 @@ static int fill_grent(struct sss_packet *packet,
/* 8-X: sequence of strings (name, passwd, mem..) */
if (add_domain) {
- ret = snprintf((char *)&body[rzero+STRS_ROFFSET],
- name.len + delim + dom_len,
- namefmt, name.str, domain);
+ ret = sss_fqname((char *)&body[rzero+STRS_ROFFSET],
+ name.len + delim + dom_len,
+ dom->names, dom, name.str);
if (ret >= (name.len + delim + dom_len)) {
/* need more space, got creative with the print format ? */
int t = ret - (name.len + delim + dom_len) + 1;
@@ -2400,9 +2391,9 @@ static int fill_grent(struct sss_packet *packet,
delim += t;
/* retry */
- ret = snprintf((char *)&body[rzero+STRS_ROFFSET],
- name.len + delim + dom_len,
- namefmt, name.str, domain);
+ ret = sss_fqname((char *)&body[rzero+STRS_ROFFSET],
+ name.len + delim + dom_len,
+ dom->names, dom, name.str);
}
if (ret != name.len + delim + dom_len - 1) {
@@ -3675,8 +3666,7 @@ static errno_t nss_cmd_getsidby_search(struct nss_dom_ctx *dctx)
/* For subdomains a fully qualified name is needed for
* sysdb_search_user_by_name and sysdb_search_group_by_name. */
if (IS_SUBDOMAIN(dom)) {
- sysdb_name = talloc_asprintf(cmdctx, dom->names->fq_fmt,
- name, dom->name);
+ sysdb_name = sss_tc_fqname(cmdctx, dom->names, dom, name);
if (sysdb_name == NULL) {
DEBUG(SSSDBG_OP_FAILURE, ("talloc_asprintf failed.\n"));
return ENOMEM;
@@ -4045,8 +4035,7 @@ static errno_t fill_name(struct sss_packet *packet,
}
if (add_domain) {
- fq_name = talloc_asprintf(tmp_ctx, dom->names->fq_fmt, cased_name,
- dom->name);
+ fq_name = sss_tc_fqname(tmp_ctx, dom->names, dom, cased_name);
if (fq_name == NULL) {
DEBUG(SSSDBG_OP_FAILURE, ("talloc_asprintf failed.\n"));
ret = ENOMEM;
diff --git a/src/responder/pac/pacsrv_cmd.c b/src/responder/pac/pacsrv_cmd.c
index 2b6cd965..8f5617c7 100644
--- a/src/responder/pac/pacsrv_cmd.c
+++ b/src/responder/pac/pacsrv_cmd.c
@@ -204,8 +204,8 @@ static errno_t pac_add_user_next(struct pac_req_ctx *pr_ctx)
/* this is a subdomain so we need to search for the fully qualified
* name in the database */
- pr_ctx->fq_name = talloc_asprintf(pr_ctx, pr_ctx->dom->names->fq_fmt,
- pr_ctx->user_name, pr_ctx->dom->name);
+ pr_ctx->fq_name= sss_tc_fqname(pr_ctx, pr_ctx->dom->names,
+ pr_ctx->dom, pr_ctx->user_name);
if (!pr_ctx->fq_name) {
ret = ENOMEM;
DEBUG(SSSDBG_OP_FAILURE, ("talloc_sprintf failed.\n"));
diff --git a/src/responder/pac/pacsrv_utils.c b/src/responder/pac/pacsrv_utils.c
index cb480d3e..bcea640b 100644
--- a/src/responder/pac/pacsrv_utils.c
+++ b/src/responder/pac/pacsrv_utils.c
@@ -765,8 +765,7 @@ errno_t get_pwd_from_pac(TALLOC_CTX *mem_ctx,
ret = ENOMEM;
goto done;
}
- pwd->pw_name = talloc_asprintf(pwd, dom->names->fq_fmt,
- lname, dom->name);
+ pwd->pw_name = sss_tc_fqname(pwd, dom->names, dom, lname);
if (!pwd->pw_name) {
DEBUG(SSSDBG_OP_FAILURE, ("talloc_sprintf failed.\n"));
ret = ENOMEM;
diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c
index 9942e6a7..f888608a 100644
--- a/src/tools/sss_cache.c
+++ b/src/tools/sss_cache.c
@@ -221,8 +221,7 @@ static errno_t update_filter(struct cache_tool_ctx *tctx,
if (parsed_domain) {
if (IS_SUBDOMAIN(dinfo)) {
/* Use fqdn for subdomains */
- use_name = talloc_asprintf(tmp_ctx, tctx->nctx->fq_fmt, use_name,
- dinfo->name);
+ use_name = sss_tc_fqname(tmp_ctx, tctx->nctx, dinfo, name);
if (use_name == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
ret = ENOMEM;
diff --git a/src/util/usertools.c b/src/util/usertools.c
index 91110f26..20ca407f 100644
--- a/src/util/usertools.c
+++ b/src/util/usertools.c
@@ -507,3 +507,28 @@ sss_get_cased_name_list(TALLOC_CTX *mem_ctx, const char * const *orig,
*_cased = out;
return EOK;
}
+
+static inline const char *
+safe_fq_str(struct sss_names_ctx *nctx, uint8_t part, const char *str)
+{
+
+ return nctx->fq_flags & part ? str : "";
+}
+
+char *
+sss_tc_fqname(TALLOC_CTX *mem_ctx, struct sss_names_ctx *nctx,
+ struct sss_domain_info *domain, const char *name)
+{
+ if (domain == NULL || nctx == NULL) return NULL;
+
+ return talloc_asprintf(mem_ctx, nctx->fq_fmt, name, domain->name);
+}
+
+int
+sss_fqname(char *str, size_t size, struct sss_names_ctx *nctx,
+ struct sss_domain_info *domain, const char *name)
+{
+ if (domain == NULL || nctx == NULL) return -EINVAL;
+
+ return snprintf(str, size, nctx->fq_fmt, name, domain->name);
+}
diff --git a/src/util/util.h b/src/util/util.h
index bdb04a8f..2f65fa20 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -43,6 +43,7 @@
#include <ldb.h>
#include <dhash.h>
+#include "confdb/confdb.h"
#include "util/atomic_io.h"
#include "util/util_errors.h"
#include "util/util_safealign.h"
@@ -365,6 +366,21 @@ errno_t
sss_get_cased_name_list(TALLOC_CTX *mem_ctx, const char * const *orig,
bool case_sensitive, const char ***_cased);
+/* Return fully-qualified name according to the fq_fmt. The name is allocated using
+ * talloc on top of mem_ctx
+ */
+char *
+sss_tc_fqname(TALLOC_CTX *mem_ctx, struct sss_names_ctx *nctx,
+ struct sss_domain_info *domain, const char *name);
+
+/* Return fully-qualified name formatted according to the fq_fmt. The buffer in "str" is
+ * "size" bytes long. Returns the number of bytes written on success or a negative
+ * value of failure.
+ */
+int
+sss_fqname(char *str, size_t size, struct sss_names_ctx *nctx,
+ struct sss_domain_info *domain, const char *name);
+
/* from backup-file.c */
int backup_file(const char *src, int dbglvl);