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.
This commit is contained in:
Justin Stephenson 2023-04-27 14:48:53 -04:00
parent 07b5b13b12
commit 86f674bd92

View file

@ -469,19 +469,54 @@ class SssdConfig extends React.Component {
superuser: true, 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 promise = this.file.read();
const sssdconfpromise = this.sssdconf.read();
promise.fail(function(error) { promise.fail(function(error) {
console.log(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) { handleSubmit(e) {
const obj = {}; const obj = {};
/* SSSD section */ /* SSSD section */
obj.sssd = {}; obj.sssd = {};
obj.sssd.services = "nss"; /* Avoid overwriting services and domain sections of existing sssd.conf
obj.sssd.domains = "nssfiles"; * 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 */ /* Proxy provider */
obj.domainnssfiles = {}; /* Unparser converts this into domain/nssfiles */ obj.domainnssfiles = {}; /* Unparser converts this into domain/nssfiles */
obj.domainnssfiles.id_provider = "proxy"; obj.domainnssfiles.id_provider = "proxy";