usertools.c revision 09a36be00ddcf1d7bd5b8a368143d5b2e2f4fb68
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 2009
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch This program is free software; you can redistribute it and/or modify
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch it under the terms of the GNU General Public License as published by
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch the Free Software Foundation; either version 3 of the License, or
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch (at your option) any later version.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch This program is distributed in the hope that it will be useful,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch but WITHOUT ANY WARRANTY; without even the implied warranty of
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch GNU General Public License for more details.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch You should have received a copy of the GNU General Public License
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch along with this program. If not, see <http://www.gnu.org/licenses/>.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#define NAME_DOMAIN_PATTERN_OPTIONS (PCRE_EXTENDED)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#define NAME_DOMAIN_PATTERN_OPTIONS (PCRE_DUPNAMES | PCRE_EXTENDED)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch/* Function returns given realm name as new uppercase string */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschchar *get_uppercase_realm(TALLOC_CTX *memctx, const char *name)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch while(*c != '\0') {
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int sss_names_ctx_destructor(struct sss_names_ctx *snctx)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#define IPA_AD_DEFAULT_RE "(((?P<domain>[^\\\\]+)\\\\(?P<name>.+$))|" \
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch "((?P<name>[^@]+)@(?P<domain>.+$))|" \
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch "(^(?P<name>[^@\\\\]+)$))"
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic errno_t get_id_provider_default_re(TALLOC_CTX *mem_ctx,
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen "The libpcre version on this system is too old. Only "
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen "the user@DOMAIN name fully qualified name format will "
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen "be supported\n");
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *re;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch } provider_default_re[] = {{"ipa", IPA_AD_DEFAULT_RE},
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ret = confdb_get_string(cdb, mem_ctx, conf_path, CONFDB_DOMAIN_ID_PROVIDER,
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen DEBUG(SSSDBG_OP_FAILURE, "Failed to read ID provider " \
70505f4839520ac67895992621c97d2480c22e7fTimo Sirainen "from conf db.\n");
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch for (c = 0; provider_default_re[c].name != NULL; c++) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (strcmp(id_provider, provider_default_re[c].name) == 0) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch *re_pattern = talloc_strdup(mem_ctx, provider_default_re[c].re);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic errno_t sss_fqnames_init(struct sss_names_ctx *nctx, const char *fq_fmt)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch DEBUG(SSSDBG_CONF_SETTINGS, "Using fq format [%s].\n", nctx->fq_fmt);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* Fail if the name specifier is missing, or if the format is
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch fq = sss_tc_fqname2 (nctx, nctx, "unused.example.com", "unused", "the-test-user");
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch "The fq format is invalid [%s]", nctx->fq_fmt);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch } else if (strstr (fq, "the-test-user") == NULL) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch "Username pattern not found in [%s]\n", nctx->fq_fmt);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschint sss_names_init_from_args(TALLOC_CTX *mem_ctx, const char *re_pattern,
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch const char *fq_fmt, struct sss_names_ctx **out)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx = talloc_zero(mem_ctx, struct sss_names_ctx);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch talloc_set_destructor(ctx, sss_names_ctx_destructor);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx->re_pattern = talloc_strdup(ctx, re_pattern);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch DEBUG(SSSDBG_CONF_SETTINGS, "Using re [%s].\n", ctx->re_pattern);
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen DEBUG(SSSDBG_OP_FAILURE, "Could not check the FQ names format"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch "Invalid Regular Expression pattern at position %d."
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch " (Error: %d [%s])\n", errpos, errval, errstr);
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainenint sss_names_init(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb,
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen const char *domain, struct sss_names_ctx **out)
ba1c847d0af4afe4787ed470d0c818e948e184e2Timo Sirainen conf_path = talloc_asprintf(tmpctx, CONFDB_DOMAIN_PATH_TMPL, domain);
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen ret = confdb_get_string(cdb, tmpctx, conf_path,
goto done;
if (!re_pattern) {
if (!re_pattern) {
goto done;
#ifdef HAVE_LIBPCRE_LESSER_THAN_7
if (!fq_fmt) {
if (!fq_fmt) {
goto done;
done:
return ret;
const char *result;
int origlen;
return EINVAL;
} else if (ret < 0) {
return EINVAL;
if (ret == 0) {
return EINVAL;
&result);
if (*result) {
return EOK;
char *domain;
char *name;
int ret;
return ret;
const char *dmatch)
return dom;
const char *default_domain,
bool name_mismatch = false;
int ret;
return ENOMEM;
name_mismatch = true;
goto done;
goto done;
goto done;
rdomain);
goto done;
} else if (candidate_domain) {
goto done;
goto done;
done:
return ret;
const char *orig_name,
bool case_sensitive)
const char **out;
return EOK;
if (num == 0) {
return EOK;
return ENOMEM;
for (i = 0; i < num; i++) {
return ENOMEM;
return EOK;
if (s == NULL) {
const char *piece,
const char *name)
char *output;
return output;
const char *orig_name,
char *user_name;
int ret;
return NULL;
return user_name;