20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny/*
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny Authors:
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny Sumit Bose <sbose@redhat.com>
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny Copyright (C) 2012 Red Hat
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny This program is free software; you can redistribute it and/or modify
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny it under the terms of the GNU General Public License as published by
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny the Free Software Foundation; either version 3 of the License, or
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny (at your option) any later version.
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny This program is distributed in the hope that it will be useful,
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny GNU General Public License for more details.
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny You should have received a copy of the GNU General Public License
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny*/
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny
96e1794db6915a655d97ecab7ab71ad53d1f527bLukas Slebodnik#include <ctype.h>
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek#include <utime.h>
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny#include "confdb/confdb.h"
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny#include "db/sysdb.h"
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny#include "util/util.h"
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březinastruct sss_domain_info *get_domains_head(struct sss_domain_info *domain)
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina{
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina struct sss_domain_info *dom = NULL;
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina /* get to the top level domain */
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina for (dom = domain; dom->parent != NULL; dom = dom->parent);
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina return dom;
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina}
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorcestruct sss_domain_info *get_next_domain(struct sss_domain_info *domain,
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek uint32_t gnd_flags)
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce{
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce struct sss_domain_info *dom;
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek bool descend = gnd_flags & SSS_GND_DESCEND;
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek bool include_disabled = gnd_flags & SSS_GND_INCLUDE_DISABLED;
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce dom = domain;
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce while (dom) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (descend && dom->subdomains) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce dom = dom->subdomains;
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce } else if (dom->next) {
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce dom = dom->next;
07b92f78d1751d8a2a538a440e1fdb24c59021e0Pavel Březina } else if (descend && IS_SUBDOMAIN(dom) && dom->parent->next) {
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce dom = dom->parent->next;
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce } else {
850ca620611f65115ee95e1d919be8443f95c14cLukas Slebodnik dom = NULL;
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce }
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek if (dom) {
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek if (sss_domain_get_state(dom) == DOM_DISABLED
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek && !include_disabled) {
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek continue;
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek } else {
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek /* Next domain found. */
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek break;
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek }
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek }
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce }
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce return dom;
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce}
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozekbool subdomain_enumerates(struct sss_domain_info *parent,
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek const char *sd_name)
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek{
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek if (parent->sd_enumerate == NULL
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek || parent->sd_enumerate[0] == NULL) {
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Subdomain_enumerate not set\n");
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek return false;
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek }
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek if (strcasecmp(parent->sd_enumerate[0], "all") == 0) {
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek return true;
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek } else if (strcasecmp(parent->sd_enumerate[0], "none") == 0) {
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek return false;
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek } else {
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek for (int i=0; parent->sd_enumerate[i]; i++) {
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek if (strcasecmp(parent->sd_enumerate[i], sd_name) == 0) {
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek return true;
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek }
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek }
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek }
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek return false;
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek}
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichlstruct sss_domain_info *find_domain_by_name(struct sss_domain_info *domain,
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl const char *name,
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl bool match_any)
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce{
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce struct sss_domain_info *dom = domain;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose if (name == NULL) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose return NULL;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek while (dom && sss_domain_get_state(dom) == DOM_DISABLED) {
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, SSS_GND_DESCEND);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce while (dom) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (strcasecmp(dom->name, name) == 0 ||
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ((match_any == true) && (dom->flat_name != NULL) &&
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce (strcasecmp(dom->flat_name, name) == 0))) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce return dom;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, SSS_GND_DESCEND);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce return NULL;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce}
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichlstruct sss_domain_info *find_domain_by_sid(struct sss_domain_info *domain,
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina const char *sid)
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina{
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina struct sss_domain_info *dom = domain;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose size_t sid_len;
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina size_t dom_sid_len;
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose if (sid == NULL) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose return NULL;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose sid_len = strlen(sid);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek while (dom && sss_domain_get_state(dom) == DOM_DISABLED) {
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, SSS_GND_DESCEND);
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina }
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina while (dom) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose if (dom->domain_id != NULL) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom_sid_len = strlen(dom->domain_id);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose if (strncasecmp(dom->domain_id, sid, dom_sid_len) == 0) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose if (dom_sid_len == sid_len) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose /* sid is domain sid */
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose return dom;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose /* sid is object sid, check if domain sid is align with
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose * sid first subauthority component */
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose if (sid[dom_sid_len] == '-') {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose return dom;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina }
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina }
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, SSS_GND_DESCEND);
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina }
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina return NULL;
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina}
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichlstruct sss_domain_info*
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichlsss_get_domain_by_sid_ldap_fallback(struct sss_domain_info *domain,
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl const char* sid)
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl{
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl /* LDAP provider doesn't know about sub-domains and hence can only
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl * have one configured domain
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl */
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl if (strcmp(domain->provider, "ldap") == 0) {
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl return domain;
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl } else {
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl return find_domain_by_sid(get_domains_head(domain), sid);
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl }
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl}
b12e2500237f33c44807d7e5b377ec06007c7252Pavel Reichl
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březinastruct sss_domain_info *
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bosefind_domain_by_object_name_ex(struct sss_domain_info *domain,
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose const char *object_name, bool strict)
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina{
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina TALLOC_CTX *tmp_ctx;
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina struct sss_domain_info *dom = NULL;
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina char *domainname = NULL;
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina errno_t ret;
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina tmp_ctx = talloc_new(NULL);
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina if (tmp_ctx == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina return NULL;
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina }
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina
1f5f330f02a95abf76b46f42ce853d2a5a1f2a61Jakub Hrozek ret = sss_parse_internal_fqname(tmp_ctx, object_name,
1f5f330f02a95abf76b46f42ce853d2a5a1f2a61Jakub Hrozek NULL, &domainname);
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse name '%s' [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov object_name, ret, sss_strerror(ret));
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina goto done;
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina }
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina if (domainname == NULL) {
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose if (strict) {
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose dom = NULL;
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose } else {
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose dom = domain;
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose }
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina } else {
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(domain, domainname, true);
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina }
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březinadone:
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina talloc_free(tmp_ctx);
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina return dom;
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina}
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bosestruct sss_domain_info *
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bosefind_domain_by_object_name(struct sss_domain_info *domain,
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose const char *object_name)
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose{
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose return find_domain_by_object_name_ex(domain, object_name, false);
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose}
b6d3da6cfe78c6d0ddb854088bc23e293b336401Sumit Bose
234958be042980242fff6da936af674da877c5efSimo Sorceerrno_t sssd_domain_init(TALLOC_CTX *mem_ctx,
234958be042980242fff6da936af674da877c5efSimo Sorce struct confdb_ctx *cdb,
234958be042980242fff6da936af674da877c5efSimo Sorce const char *domain_name,
234958be042980242fff6da936af674da877c5efSimo Sorce const char *db_path,
234958be042980242fff6da936af674da877c5efSimo Sorce struct sss_domain_info **_domain)
234958be042980242fff6da936af674da877c5efSimo Sorce{
234958be042980242fff6da936af674da877c5efSimo Sorce int ret;
234958be042980242fff6da936af674da877c5efSimo Sorce struct sss_domain_info *dom;
234958be042980242fff6da936af674da877c5efSimo Sorce struct sysdb_ctx *sysdb;
234958be042980242fff6da936af674da877c5efSimo Sorce
234958be042980242fff6da936af674da877c5efSimo Sorce ret = confdb_get_domain(cdb, domain_name, &dom);
234958be042980242fff6da936af674da877c5efSimo Sorce if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Error retrieving domain configuration.\n");
234958be042980242fff6da936af674da877c5efSimo Sorce return ret;
234958be042980242fff6da936af674da877c5efSimo Sorce }
234958be042980242fff6da936af674da877c5efSimo Sorce
234958be042980242fff6da936af674da877c5efSimo Sorce if (dom->sysdb != NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Sysdb context already initialized.\n");
234958be042980242fff6da936af674da877c5efSimo Sorce return EEXIST;
234958be042980242fff6da936af674da877c5efSimo Sorce }
234958be042980242fff6da936af674da877c5efSimo Sorce
234958be042980242fff6da936af674da877c5efSimo Sorce ret = sysdb_domain_init(mem_ctx, dom, db_path, &sysdb);
234958be042980242fff6da936af674da877c5efSimo Sorce if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Error opening cache database.\n");
234958be042980242fff6da936af674da877c5efSimo Sorce return ret;
234958be042980242fff6da936af674da877c5efSimo Sorce }
234958be042980242fff6da936af674da877c5efSimo Sorce
234958be042980242fff6da936af674da877c5efSimo Sorce dom->sysdb = talloc_steal(dom, sysdb);
234958be042980242fff6da936af674da877c5efSimo Sorce
234958be042980242fff6da936af674da877c5efSimo Sorce *_domain = dom;
234958be042980242fff6da936af674da877c5efSimo Sorce
234958be042980242fff6da936af674da877c5efSimo Sorce return EOK;
234958be042980242fff6da936af674da877c5efSimo Sorce}
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozekstatic errno_t
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozeksss_krb5_touch_config(void)
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek{
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek const char *config = NULL;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek errno_t ret;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek config = getenv("KRB5_CONFIG");
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (config == NULL) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek config = KRB5_CONF_PATH;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = utime(config, NULL);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (ret == -1) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = errno;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to change mtime of \"%s\" "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%d]: %s\n", config, ret, strerror(ret));
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek return ret;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek return EOK;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek}
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Boseerrno_t sss_get_domain_mappings_content(TALLOC_CTX *mem_ctx,
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose struct sss_domain_info *domain,
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose char **content)
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek{
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose int ret;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose char *o = NULL;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek struct sss_domain_info *dom;
bbd43fbcd8f70eedeac4e4ce01c36256cde82ab1Sumit Bose struct sss_domain_info *parent_dom;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose char *uc_parent = NULL;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose char *uc_forest = NULL;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose char *parent_capaths = NULL;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose bool capaths_started = false;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (domain == NULL || content == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Missing parameter.\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose return EINVAL;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose o = talloc_strdup(mem_ctx, "[domain_realm]\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (o == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = ENOMEM;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose goto done;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose /* This loops skips the starting parent and start rigth with the first
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose * subdomain. Although in all the interesting cases (AD and IPA) the
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose * default is that realm and DNS domain are the same strings (expect case)
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose * and no domain_realm mapping is needed we might consider to add this
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose * domain here as well to cover corner cases? */
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose for (dom = get_next_domain(domain, SSS_GND_DESCEND);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose dom && IS_SUBDOMAIN(dom); /* if we get back to a parent, stop */
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose dom = get_next_domain(dom, 0)) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose o = talloc_asprintf_append(o, ".%s = %s\n%s = %s\n",
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose dom->name, dom->realm, dom->name, dom->realm);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (o == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf_append failed.\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = ENOMEM;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose goto done;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose parent_dom = domain;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose uc_parent = get_uppercase_realm(mem_ctx, parent_dom->name);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (uc_parent == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "get_uppercase_realm failed.\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = ENOMEM;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose goto done;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose for (dom = get_next_domain(domain, SSS_GND_DESCEND);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose dom && IS_SUBDOMAIN(dom); /* if we get back to a parent, stop */
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose dom = get_next_domain(dom, 0)) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (dom->forest == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose continue;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose talloc_free(uc_forest);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose uc_forest = get_uppercase_realm(mem_ctx, dom->forest);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (uc_forest == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "get_uppercase_realm failed.\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = ENOMEM;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose goto done;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (!capaths_started) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose o = talloc_asprintf_append(o, "[capaths]\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (o == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf_append failed.\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = ENOMEM;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose goto done;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose capaths_started = true;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose o = talloc_asprintf_append(o, "%s = {\n %s = %s\n}\n",
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose dom->realm, uc_parent, uc_forest);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (o == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf_append failed.\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = ENOMEM;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose goto done;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (parent_capaths == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose parent_capaths = talloc_asprintf(mem_ctx, " %s = %s\n", dom->realm,
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose uc_forest);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose } else {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose parent_capaths = talloc_asprintf_append(parent_capaths,
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose " %s = %s\n", dom->realm,
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose uc_forest);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (parent_capaths == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose DEBUG(SSSDBG_OP_FAILURE,
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose "talloc_asprintf/talloc_asprintf_append failed.\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = ENOMEM;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose goto done;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (parent_capaths != NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose o = talloc_asprintf_append(o, "%s = {\n%s}\n", uc_parent,
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose parent_capaths);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (o == NULL) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf_append failed.\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = ENOMEM;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose goto done;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = EOK;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bosedone:
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose talloc_free(parent_capaths);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose talloc_free(uc_parent);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose talloc_free(uc_forest);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (ret == EOK) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose *content = o;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose } else {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose talloc_free(o);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose return ret;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose}
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Boseerrno_t
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bosesss_write_domain_mappings(struct sss_domain_info *domain)
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose{
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek errno_t ret;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek errno_t err;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek TALLOC_CTX *tmp_ctx;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek const char *mapping_file;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek char *sanitized_domain;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek char *tmp_file = NULL;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek int fd = -1;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek mode_t old_mode;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek FILE *fstream = NULL;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek int i;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose char *content = NULL;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (domain == NULL || domain->name == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "No domain name provided\n");
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek return EINVAL;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek tmp_ctx = talloc_new(NULL);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (!tmp_ctx) return ENOMEM;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = sss_get_domain_mappings_content(tmp_ctx, domain, &content);
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose if (ret != EOK) {
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_get_domain_mappings_content failed.\n");
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose goto done;
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose }
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek sanitized_domain = talloc_strdup(tmp_ctx, domain->name);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (sanitized_domain == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n");
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek return ENOMEM;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek /* only alpha-numeric chars, dashes and underscores are allowed in
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek * krb5 include directory */
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek for (i = 0; sanitized_domain[i] != '\0'; i++) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (!isalnum(sanitized_domain[i])
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek && sanitized_domain[i] != '-' && sanitized_domain[i] != '_') {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek sanitized_domain[i] = '_';
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek mapping_file = talloc_asprintf(tmp_ctx, "%s/domain_realm_%s",
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek KRB5_MAPPING_DIR, sanitized_domain);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (!mapping_file) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = ENOMEM;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek goto done;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "Mapping file for domain [%s] is [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov domain->name, mapping_file);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek tmp_file = talloc_asprintf(tmp_ctx, "%sXXXXXX", mapping_file);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (tmp_file == NULL) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = ENOMEM;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek goto done;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
a0ad4f2a4a342214acd4ab4b77cc5ccce22b35adPetr Cech old_mode = umask(SSS_DFL_UMASK);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek fd = mkstemp(tmp_file);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek umask(old_mode);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (fd < 0) {
b07a3b729892d2bc2ffa73d93de95e19003cc6c8Pavel Reichl DEBUG(SSSDBG_OP_FAILURE,
b07a3b729892d2bc2ffa73d93de95e19003cc6c8Pavel Reichl "creating the temp file [%s] for domain-realm mappings "
b07a3b729892d2bc2ffa73d93de95e19003cc6c8Pavel Reichl "failed.\n", tmp_file);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = EIO;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek talloc_zfree(tmp_ctx);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek goto done;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek fstream = fdopen(fd, "a");
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (!fstream) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = errno;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "fdopen failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = close(fd);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (ret != 0) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = errno;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "fclose failed [%d][%s].\n", ret, strerror(ret));
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek /* Nothing to do here, just report the failure */
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = EIO;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek goto done;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
2efebde7ddd5f1729a70ef4ec9de607cc393214cSumit Bose ret = fprintf(fstream, "%s", content);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (ret < 0) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "fprintf failed\n");
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = EIO;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek goto done;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = fclose(fstream);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek fstream = NULL;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (ret != 0) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = errno;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "fclose failed [%d][%s].\n", ret, strerror(ret));
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek goto done;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = rename(tmp_file, mapping_file);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (ret == -1) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = errno;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "rename failed [%d][%s].\n", ret, strerror(ret));
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek goto done;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek talloc_zfree(tmp_file);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = chmod(mapping_file, 0644);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (ret == -1) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = errno;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "fchmod failed [%d][%s].\n", ret, strerror(ret));
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek goto done;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = EOK;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozekdone:
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek err = sss_krb5_touch_config();
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (err != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to change last modification time "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "of krb5.conf. Created mappings may not be loaded.\n");
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek /* Ignore */
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (fstream) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek err = fclose(fstream);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (err != 0) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek err = errno;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "fclose failed [%d][%s].\n", err, strerror(err));
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek /* Nothing to do here, just report the failure */
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (tmp_file) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek err = unlink(tmp_file);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek if (err < 0) {
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek err = errno;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Could not remove file [%s]: [%d]: %s\n",
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik tmp_file, err, strerror(err));
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek }
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek talloc_free(tmp_ctx);
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek return ret;
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek}
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl/* Save domain names, do not descend. */
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichlerrno_t get_dom_names(TALLOC_CTX *mem_ctx,
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl struct sss_domain_info *start_dom,
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl char ***_dom_names,
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl int *_dom_names_count)
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl{
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl struct sss_domain_info *dom;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl TALLOC_CTX *tmp_ctx;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl char **dom_names;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl size_t count, i;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl errno_t ret;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl tmp_ctx = talloc_new(NULL);
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl if (tmp_ctx == NULL) {
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl ret = ENOMEM;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl goto done;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl }
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl /* get count of domains*/
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl count = 0;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl dom = start_dom;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl while (dom) {
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl count++;
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, 0);
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl }
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl dom_names = talloc_array(tmp_ctx, char*, count);
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl if (dom_names == NULL) {
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl ret = ENOMEM;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl goto done;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl }
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl /* copy names */
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl i = 0;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl dom = start_dom;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl while (dom) {
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl dom_names[i] = talloc_strdup(dom_names, dom->name);
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl if (dom_names[i] == NULL) {
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl ret = ENOMEM;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl goto done;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl }
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, 0);
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl i++;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl }
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl if (_dom_names != NULL ) {
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl *_dom_names = talloc_steal(mem_ctx, dom_names);
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl }
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl if (_dom_names_count != NULL ) {
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl *_dom_names_count = count;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl }
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl ret = EOK;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichldone:
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl talloc_free(tmp_ctx);
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl return ret;
830ded27453015080a54d6ba85fd4999ee7e9af1Pavel Reichl}
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bosestatic errno_t sss_write_krb5_snippet_common(const char *file_name,
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose const char *content)
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose{
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose int ret;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose errno_t err;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose TALLOC_CTX *tmp_ctx = NULL;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose char *tmp_file = NULL;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose int fd = -1;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose mode_t old_mode;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ssize_t written;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose size_t size;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose tmp_ctx = talloc_new(NULL);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (tmp_ctx == NULL) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose return ENOMEM;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose tmp_file = talloc_asprintf(tmp_ctx, "%sXXXXXX", file_name);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (tmp_file == NULL) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = ENOMEM;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose goto done;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
a0ad4f2a4a342214acd4ab4b77cc5ccce22b35adPetr Cech old_mode = umask(SSS_DFL_UMASK);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose fd = mkstemp(tmp_file);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose umask(old_mode);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (fd < 0) {
b07a3b729892d2bc2ffa73d93de95e19003cc6c8Pavel Reichl DEBUG(SSSDBG_OP_FAILURE, "creating the temp file [%s] for "
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose "krb5 config snippet failed.\n", tmp_file);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = EIO;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose talloc_zfree(tmp_ctx);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose goto done;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose size = strlen(content);
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose written = sss_atomic_write_s(fd, discard_const(content), size);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose close(fd);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (written == -1) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = errno;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose "write failed [%d][%s]\n", ret, sss_strerror(ret));
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose goto done;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (written != size) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose "Wrote %zd bytes expected %zu\n", written, size);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = EIO;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose goto done;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = rename(tmp_file, file_name);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (ret == -1) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = errno;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose "rename failed [%d][%s].\n", ret, sss_strerror(ret));
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose goto done;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose tmp_file = NULL;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = chmod(file_name, 0644);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (ret == -1) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = errno;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose "chmod failed [%d][%s].\n", ret, sss_strerror(ret));
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose goto done;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bosedone:
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (tmp_file != NULL) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose err = unlink(tmp_file);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (err == -1) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose err = errno;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_MINOR_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Could not remove file [%s]: [%d]: %s\n",
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik tmp_file, err, sss_strerror(err));
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose talloc_free(tmp_ctx);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose return ret;
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose}
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose#define LOCALAUTH_PLUGIN_CONFIG \
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose"[plugins]\n" \
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose" localauth = {\n" \
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose" module = sssd:"APP_MODULES_PATH"/sssd_krb5_localauth_plugin.so\n" \
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose" }\n"
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bosestatic errno_t sss_write_krb5_localauth_snippet(const char *path)
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose{
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose#ifdef HAVE_KRB5_LOCALAUTH_PLUGIN
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose int ret;
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose TALLOC_CTX *tmp_ctx = NULL;
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose const char *file_name;
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose tmp_ctx = talloc_new(NULL);
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose if (tmp_ctx == NULL) {
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose return ENOMEM;
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose }
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose file_name = talloc_asprintf(tmp_ctx, "%s/localauth_plugin", path);
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose if (file_name == NULL) {
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose ret = ENOMEM;
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose goto done;
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose }
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose DEBUG(SSSDBG_FUNC_DATA, "File for localauth plugin configuration is [%s]\n",
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose file_name);
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose ret = sss_write_krb5_snippet_common(file_name, LOCALAUTH_PLUGIN_CONFIG);
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose if (ret != EOK) {
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_write_krb5_snippet_common failed.\n");
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose goto done;
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose }
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bosedone:
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose talloc_free(tmp_ctx);
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose return ret;
d278822ab3ab18f2c5b012cd055f01f06e687e49Sumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose#else
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_TRACE_ALL, "Kerberos localauth plugin not available.\n");
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose return EOK;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose#endif
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose}
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čechstatic errno_t sss_write_krb5_libdefaults_snippet(const char *path,
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech bool canonicalize,
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech bool udp_limit)
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose{
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose int ret;
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose TALLOC_CTX *tmp_ctx = NULL;
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose const char *file_name;
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech char *file_contents;
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose tmp_ctx = talloc_new(NULL);
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose if (tmp_ctx == NULL) {
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose return ENOMEM;
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose }
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose file_name = talloc_asprintf(tmp_ctx, "%s/krb5_libdefaults", path);
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose if (file_name == NULL) {
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose ret = ENOMEM;
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose goto done;
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose }
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose DEBUG(SSSDBG_FUNC_DATA, "File for KRB5 kibdefaults configuration is [%s]\n",
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose file_name);
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech file_contents = talloc_strdup(tmp_ctx, "[libdefaults]\n");
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech if (file_contents == NULL) {
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech DEBUG(SSSDBG_OP_FAILURE,
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech "talloc_asprintf failed while creating the content\n");
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = ENOMEM;
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech goto done;
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech }
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech if (canonicalize == true) {
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech file_contents = talloc_asprintf_append(file_contents,
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech " canonicalize = true\n");
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech if (file_contents == NULL) {
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech DEBUG(SSSDBG_OP_FAILURE,
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech "talloc_asprintf failed while appending to the content\n");
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = ENOMEM;
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech goto done;
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech }
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech }
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech if (udp_limit == true) {
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech file_contents = talloc_asprintf_append(file_contents,
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech " udp_preference_limit = 0\n");
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech if (file_contents == NULL) {
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech DEBUG(SSSDBG_OP_FAILURE,
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech "talloc_asprintf failed while appending to the content\n");
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = ENOMEM;
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech goto done;
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech }
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech }
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_snippet_common(file_name, file_contents);
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose if (ret != EOK) {
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_write_krb5_snippet_common failed.\n");
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose goto done;
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose }
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bosedone:
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose talloc_free(tmp_ctx);
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose return ret;
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose}
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čecherrno_t sss_write_krb5_conf_snippet(const char *path, bool canonicalize,
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech bool udp_limit)
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose{
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose errno_t ret;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose errno_t err;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (path != NULL && (*path == '\0' || strcasecmp(path, "none") == 0)) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_TRACE_FUNC, "Empty path, nothing to do.\n");
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose return EOK;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (path == NULL || *path != '/') {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Invalid or missing path [%s]-\n",
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose path == NULL ? "missing" : path);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose return EINVAL;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = sss_write_krb5_localauth_snippet(path);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (ret != EOK) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_write_krb5_localauth_snippet failed.\n");
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose goto done;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_libdefaults_snippet(path, canonicalize, udp_limit);
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech if (ret != EOK) {
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech DEBUG(SSSDBG_OP_FAILURE, "sss_write_krb5_libdefaults_snippet failed.\n");
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech goto done;
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose }
e6b6b9fa79c67d7d2698bc7e33d2e2f6bb53d483Sumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = EOK;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bosedone:
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose err = sss_krb5_touch_config();
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (err != EOK) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Unable to change last modification time "
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose "of krb5.conf. Created mappings may not be loaded.\n");
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose /* Ignore */
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose return ret;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose}
dd5ebcde05442422f39084acb49b28cf47002d1eSumit Bose
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozekstatic const char *domain_state_str(struct sss_domain_info *dom)
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek{
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek switch (dom->state) {
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek case DOM_ACTIVE:
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek return "Active";
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek case DOM_DISABLED:
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek return "Disabled";
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek case DOM_INACTIVE:
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek return "Inactive";
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek case DOM_INCONSISTENT:
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek return "Inconsistent";
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek }
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek return "Unknown";
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek}
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozekenum sss_domain_state sss_domain_get_state(struct sss_domain_info *dom)
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek{
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek "Domain %s is %s\n", dom->name, domain_state_str(dom));
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek return dom->state;
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek}
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozekvoid sss_domain_set_state(struct sss_domain_info *dom,
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek enum sss_domain_state state)
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek{
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek dom->state = state;
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
c109f063b4469818fd335b8b509f0458e7b33b0aJakub Hrozek "Domain %s is %s\n", dom->name, domain_state_str(dom));
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek}
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose
712e5b2e4465812c00a8667c75813322373bc657Sumit Bosebool sss_domain_is_forest_root(struct sss_domain_info *dom)
712e5b2e4465812c00a8667c75813322373bc657Sumit Bose{
712e5b2e4465812c00a8667c75813322373bc657Sumit Bose return (dom->forest_root == dom);
712e5b2e4465812c00a8667c75813322373bc657Sumit Bose}
712e5b2e4465812c00a8667c75813322373bc657Sumit Bose
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bosebool is_email_from_domain(const char *email, struct sss_domain_info *dom)
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose{
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose const char *p;
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose if (email == NULL || dom == NULL) {
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose return false;
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose }
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose p = strchr(email, '@');
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose if (p == NULL) {
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose DEBUG(SSSDBG_TRACE_ALL,
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose "Input [%s] does not look like an email address.\n", email);
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose return false;
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose }
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose if (strcasecmp(p+1, dom->name) == 0) {
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Email [%s] is from domain [%s].\n", email,
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose dom->name);
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose return true;
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose }
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Email [%s] is not from domain [%s].\n", email,
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose dom->name);
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose return false;
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose}
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek
e0e038218580166648ac24f23180f0f4c2769d99Michal Židekchar *subdomain_create_conf_path(TALLOC_CTX *mem_ctx,
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek struct sss_domain_info *subdomain)
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek{
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek if (!IS_SUBDOMAIN(subdomain)) {
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek DEBUG(SSSDBG_OP_FAILURE,
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek "The domain \"%s\" is not a subdomain.\n",
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek subdomain->name);
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek return NULL;
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek }
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek return talloc_asprintf(mem_ctx, CONFDB_DOMAIN_PATH_TMPL "/%s",
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek subdomain->parent->name,
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek subdomain->name);
e0e038218580166648ac24f23180f0f4c2769d99Michal Židek}
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozekconst char *sss_domain_type_str(struct sss_domain_info *dom)
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek{
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek if (dom == NULL) {
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek return "BUG: Invalid domain";
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek }
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek switch (dom->type) {
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek case DOM_TYPE_POSIX:
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek return "POSIX";
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek case DOM_TYPE_APPLICATION:
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek return "Application";
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek }
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek return "Unknown";
6324eaf1fb321c41ca9883966118df6d45259b7eJakub Hrozek}
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidêncio
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidênciovoid sss_domain_info_set_output_fqnames(struct sss_domain_info *domain,
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidêncio bool output_fqnames)
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidêncio{
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidêncio domain->output_fqnames = output_fqnames;
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidêncio}
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidêncio
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidênciobool sss_domain_info_get_output_fqnames(struct sss_domain_info *domain)
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidêncio{
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidêncio return domain->output_fqnames;
fa2fc8a2908619031292eaf375eb1a510b8b2ebaFabiano Fidêncio}