aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher Copyright (C) 2012 Red Hat
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher This program is free software; you can redistribute it and/or modify
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher it under the terms of the GNU General Public License as published by
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher the Free Software Foundation; either version 3 of the License, or
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher (at your option) any later version.
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher This program is distributed in the hope that it will be useful,
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher GNU General Public License for more details.
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher You should have received a copy of the GNU General Public License
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
4fcc50e133f90cd4c5931a3ac48c84cb628b16fcMichal Zidekproxy_save_service(struct sss_domain_info *domain,
38429c99bf5af14c2d6bae6ddcf70974fdd103ccMichal Zidek cased_name = sss_get_cased_name(tmp_ctx, svc->s_name,
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher protocols = talloc_array(tmp_ctx, const char *, 2);
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher protocols[0] = sss_get_cased_name(protocols, svc->s_proto,
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher /* Count the aliases */
38429c99bf5af14c2d6bae6ddcf70974fdd103ccMichal Zidek /* Add lowercased alias to allow case-insensitive lookup */
38429c99bf5af14c2d6bae6ddcf70974fdd103ccMichal Zidek lc_alias = sss_tc_utf8_str_tolower(tmp_ctx, svc->s_name);
38429c99bf5af14c2d6bae6ddcf70974fdd103ccMichal Zidek DEBUG(SSSDBG_OP_FAILURE, "Cannot convert name to lowercase.\n");
38429c99bf5af14c2d6bae6ddcf70974fdd103ccMichal Zidek "Failed to add lowercased name alias.\n");
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher result = talloc_zero(tmp_ctx, struct servent);
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher status = ctx->ops.getservbyname_r(name, protocol, result,
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher if (status != NSS_STATUS_SUCCESS && status != NSS_STATUS_NOTFOUND) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "getservbyname_r failed for service [%s].\n", name);
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher /* Make sure we remove it from the cache */
4fcc50e133f90cd4c5931a3ac48c84cb628b16fcMichal Zidek ret = sysdb_svc_delete(dom, name, 0, protocol);
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher /* Results found. Save them into the cache */
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher result = talloc_zero(tmp_ctx, struct servent);
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher port = htons(strtouint16(be_filter, NULL, 0));
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher status = ctx->ops.getservbyport_r(port, protocol, result,
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher if (status != NSS_STATUS_SUCCESS && status != NSS_STATUS_NOTFOUND) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "getservbyport_r failed for service [%s].\n", be_filter);
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher /* Make sure we remove it from the cache */
4fcc50e133f90cd4c5931a3ac48c84cb628b16fcMichal Zidek ret = sysdb_svc_delete(dom, NULL, port, protocol);
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher /* Results found. Save them into the cache */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Enumerating services\n");
980a535ac81b0f63ce18fc2311dab702ced7fdc6Jakub Hrozek protocols = talloc_zero_array(tmpctx, const char *, 2);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* always zero out the svc structure */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* get entry */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos status = ctx->ops.getservent_r(svc, buffer, buflen, &ret);
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz /* buffer too small? */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos newbuf = talloc_realloc_size(tmpctx, buffer, buflen);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* we are done here */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Enumeration completed.\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Service found (%s, %d/%s)\n",
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos protocols[0] = sss_get_cased_name(protocols, svc->s_proto,
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* Do not fail completely on errors.
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos * Just report the failure to save and go on */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to store service [%s]. Ignoring.\n",
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* Do not fail completely on errors.
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos * Just report the failure to save and go on */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to store service [%s]. Ignoring.\n",
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* "remote" backend unavailable. Enter offline mode */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "proxy -> getservent_r failed (%d)[%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not cancel transaction! [%s]\n",