diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2009-07-27 09:49:45 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-08-05 10:19:20 -0400 |
commit | 1f6d7dfad2956cb2f6c33104eda4fdbefe380a42 (patch) | |
tree | 3763e4fd1cfe233bbdcd342b26545577f141273e /server/tools/tools_util.c | |
parent | a5fe74914ab920bfaed87c046c525ee7148623f2 (diff) | |
download | sssd-1f6d7dfad2956cb2f6c33104eda4fdbefe380a42.tar.gz sssd-1f6d7dfad2956cb2f6c33104eda4fdbefe380a42.tar.bz2 sssd-1f6d7dfad2956cb2f6c33104eda4fdbefe380a42.zip |
Parse fully qualified names in tools
Allow adding users into different domains not only by specifying
ID directly but also by specifying fully qualified name. Exit when
both specifications are used in conflict.
Diffstat (limited to 'server/tools/tools_util.c')
-rw-r--r-- | server/tools/tools_util.c | 125 |
1 files changed, 88 insertions, 37 deletions
diff --git a/server/tools/tools_util.c b/server/tools/tools_util.c index b580300b..1e0e91de 100644 --- a/server/tools/tools_util.c +++ b/server/tools/tools_util.c @@ -69,52 +69,61 @@ static int is_domain_local_legacy(struct tools_ctx *ctx, struct sss_domain_info return -1; } -enum id_domain find_domain_for_id(struct tools_ctx *ctx, - uint32_t id, - struct sss_domain_info **dom_ret) +enum id_domain get_domain_type(struct tools_ctx *ctx, + struct sss_domain_info *dom) +{ + if (dom == NULL) { + return ID_OUTSIDE; + } + + if (strcasecmp(dom->provider, "local") == 0) { + return ID_IN_LOCAL; + } else if (is_domain_local_legacy(ctx, dom) == 0) { + return ID_IN_LEGACY_LOCAL; + } + + return ID_IN_OTHER; +} + +static struct sss_domain_info *get_local_domain(struct tools_ctx *ctx) { struct sss_domain_info *dom = NULL; - if (id) { - /* ID specified, find which domain it's in */ - for (dom = ctx->domains; dom; dom = dom->next) { - if (id < dom->id_min || id > dom->id_max) { - continue; - } else { - if (strcasecmp(dom->provider, "local") == 0) { - *dom_ret = dom; - return ID_IN_LOCAL; - } else if (is_domain_local_legacy(ctx, dom) == 0) { - *dom_ret = dom; - return ID_IN_LEGACY_LOCAL; - } else { - *dom_ret = dom; - return ID_IN_OTHER; - } - } - } - if (dom == NULL) { - *dom_ret = NULL; - return ID_OUTSIDE; + /* No ID specified, find LOCAL */ + for (dom = ctx->domains; dom; dom = dom->next) { + if (strcasecmp(dom->provider, "local") == 0) { + break; } - } else { - /* No ID specified, find LOCAL */ + } + + return dom; +} + +int get_domain_by_id(struct tools_ctx *ctx, + uint32_t id, + struct sss_domain_info **_dom) +{ + struct sss_domain_info *dom = NULL; + int ret = EOK; + + if (id) { for (dom = ctx->domains; dom; dom = dom->next) { - if (strcasecmp(dom->provider, "local") == 0) { - *dom_ret = dom; - return ID_IN_LOCAL; + if (id >= dom->id_min && id <= dom->id_max) { + break; } } + } + + if (dom == NULL && id == 0) { + dom = get_local_domain(ctx); if (dom == NULL) { - DEBUG(1, ("Could not get LOCAL domain info\n")); - *dom_ret = dom; - return ID_ERROR; + DEBUG(1, ("Cannot find local domain info\n")); + ret = ENOENT; } } - /* We should never end up here */ - *dom_ret = NULL; - return ID_ERROR; + *_dom = dom; + return ret; } int setup_db(struct tools_ctx **tools_ctx) @@ -229,6 +238,40 @@ int parse_groups(TALLOC_CTX *mem_ctx, const char *optstr, char ***_out) return EOK; } +int parse_name_domain(struct ops_ctx *octx, + const char *fullname) +{ + int ret; + char *domain = NULL; + struct sss_domain_info *dom; + + ret = sss_parse_name(octx, octx->ctx->snctx, fullname, &domain, &octx->name); + if (ret != EOK) { + DEBUG(0, ("Cannot parse full name\n")); + return ret; + } + DEBUG(5, ("Parsed username: %s\n", octx->name)); + + if (domain) { + DEBUG(5, ("Parsed domain: %s\n", domain)); + + /* Got string domain name, find corresponding sss_domain_info */ + for (dom = octx->ctx->domains; dom; dom = dom->next) { + if (strcasecmp(dom->name, domain) == 0) { + DEBUG(6, ("Found sss_domain_info for given domain name\n")); + octx->domain = dom; + break; + } + } + if (octx->domain == NULL) { + DEBUG(0, ("Invalid domain %s specified in FQDN\n", domain)); + return EINVAL; + } + } + + return EOK; +} + int set_locale(void) { char *c; @@ -253,18 +296,26 @@ int set_locale(void) return EOK; } -int init_sss_tools(struct tools_ctx **ctx) +int init_sss_tools(struct tools_ctx **_ctx) { int ret; + struct tools_ctx *ctx; /* Connect to the database */ - ret = setup_db(ctx); + ret = setup_db(&ctx); if (ret != EOK) { DEBUG(1, ("Could not set up database\n")); ret = EXIT_FAILURE; goto fini; } + ret = sss_names_init(ctx, ctx->confdb, &ctx->snctx); + if (ret != EOK) { + DEBUG(1, ("Could not set up parsing\n")); + goto fini; + } + + *_ctx = ctx; ret = EOK; fini: return ret; |