From 86f674bd92f8482fc627027153162bb2bf7bd865 Mon Sep 17 00:00:00 2001 From: Justin Stephenson Date: Thu, 27 Apr 2023 14:48:53 -0400 Subject: [PATCH] Read existing sssd conf domains and services Avoid overwriting services and domain sections of system with an existing sssd.conf (IPA client for example). Copy the services section used in sssd.conf, and append 'proxy' to existing domain section. --- src/config.jsx | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/config.jsx b/src/config.jsx index bacfb56..3a135fa 100644 --- a/src/config.jsx +++ b/src/config.jsx @@ -469,19 +469,54 @@ class SssdConfig extends React.Component { superuser: true, }); + const conf_syntax_object = { + parse: ini.parse, + }; + + this.sssdconf = cockpit.file("/etc/sssd/sssd.conf", { + syntax: conf_syntax_object, + superuser: true, + }); + const promise = this.file.read(); + const sssdconfpromise = this.sssdconf.read(); promise.fail(function(error) { console.log(error); }); + + /* It is not an error when the file does not exist, then() callback will + * be called with a null value for content and tag is "-" */ + sssdconfpromise + .then((content, tag) => { + if (content !== null) { + this.existingServices = content.sssd.services; + this.existingDomains = content.sssd.domains; + } + }) + .catch(error => { + console.log("Error: " + error); + }); } handleSubmit(e) { const obj = {}; /* SSSD section */ obj.sssd = {}; - obj.sssd.services = "nss"; - obj.sssd.domains = "nssfiles"; + /* Avoid overwriting services and domain sections of existing sssd.conf + * Copy the services section used in sssd.conf, and append 'proxy' to + * existing domain section */ + if (this.existingServices) { + obj.sssd.services = this.existingServices; + } else { + obj.sssd.services = "nss, pam"; + } + + if (this.existingDomains) { + obj.sssd.domains = this.existingDomains + ", nssfiles"; + } else { + obj.sssd.domains = "nssfiles"; + } /* Proxy provider */ obj.domainnssfiles = {}; /* Unparser converts this into domain/nssfiles */ obj.domainnssfiles.id_provider = "proxy";