4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina Pavel Březina <pbrezina@redhat.com>
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina Copyright (C) 2016 Red Hat
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina This program is free software; you can redistribute it and/or modify
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina it under the terms of the GNU General Public License as published by
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina the Free Software Foundation; either version 3 of the License, or
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina (at your option) any later version.
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina This program is distributed in the hope that it will be useful,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina GNU General Public License for more details.
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina You should have received a copy of the GNU General Public License
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Check object class. */
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose if (!ldb_msg_check_string_attribute(msg, SYSDB_OBJECTCATEGORY,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE, "Wrong object (%s) found on stack!\n",
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Get fields. */
a012a71f21bf1a4687e58085f19c18cc5b2bbaddNikolai Kondrashov name = sss_get_name_from_msg(domain, msg);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina gid = sss_view_ldb_msg_find_attr_as_uint64(domain, msg, SYSDB_GIDNUM, 0);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Incomplete group object for %s[%u]! Skipping\n",
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Convert to sized strings. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sized_output_name(mem_ctx, nss_ctx->rctx, name, domain, _name);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "sized_output_name failed, skipping [%d]: %s\n",
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březinanss_get_group_members(struct sss_domain_info *domain,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Unconditionally prefer OVERRIDE_PREFIX SYSDB_MEMBERUID, it
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina * might contain override names from the default view. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina el = ldb_msg_find_element(msg, OVERRIDE_PREFIX SYSDB_MEMBERUID);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina el = ldb_msg_find_element(msg, SYSDB_MEMBERUID);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březinanss_get_group_ghosts(struct sss_domain_info *domain,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina if (DOM_HAS_VIEWS(domain) && !is_local_view(domain->view_name)
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Domain has a view [%s] but group [%s] still has "
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "ghost members.\n", domain->view_name, group_name);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březinanss_protocol_fill_members(struct sss_packet *packet,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina members[0] = nss_get_group_members(domain, msg);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina members[1] = nss_get_group_ghosts(domain, msg, group_name);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina for (i = 0; i < sizeof(members) / sizeof(members[0]); i++) {
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina member_name = (const char *)el->values[j].data;
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_ncache_check_user(rctx->ncache, domain, member_name);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Group [%s] member [%s] filtered out! "
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "(negative cache)\n", group_name, member_name);
7c074ba2f923985ab0d4f9d6a5e01ff3f2f0a7a8Jakub Hrozek ret = sized_domain_name(tmp_ctx, rctx, member_name, &name);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unable to get sized name [%d]: %s\n",
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_STRING(&body[*_rp], name->str, name->len, _rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březinanss_protocol_fill_grent(struct nss_ctx *nss_ctx,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* First two fields (length and reserved), filled up later. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_packet_grow(packet, 2 * sizeof(uint32_t));
c778c36c5170c2b9f1cf7a6e3b0811124534df03Jakub Hrozek /* Password field content. */
c778c36c5170c2b9f1cf7a6e3b0811124534df03Jakub Hrozek to_sized_string(&pwfield, nss_get_pwfield(nss_ctx, result->domain));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = nss_get_grent(tmp_ctx, nss_ctx, result->domain, msg,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Adjust packet size: gid, num_members + string fields. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_packet_grow(packet, 2 * sizeof(uint32_t)
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Fill packet. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Remember pointer to number of members field. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_STRING(&body[rp], name->str, name->len, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_STRING(&body[rp], pwfield.str, pwfield.len, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Fill members. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = nss_protocol_fill_members(packet, nss_ctx, result->domain, msg,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp_num_members], num_members, NULL);
55f7d8034d783c01789d76a2b9ffc901045e8af8Sumit Bose /* Do not store entry in memory cache during enumeration or when
55f7d8034d783c01789d76a2b9ffc901045e8af8Sumit Bose * requested. */
55f7d8034d783c01789d76a2b9ffc901045e8af8Sumit Bose && (cmd_ctx->flags & SSS_NSS_EX_FLAG_INVALIDATE_CACHE) == 0) {
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_mmap_cache_gr_store(&nss_ctx->grp_mc_ctx, name, &pwfield,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Failed to store group %s (%s) in mem-cache [%d]: %s!\n",
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina name->str, result->domain->name, ret, sss_strerror(ret));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_COPY_UINT32(body, &num_results, NULL);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SETMEM_UINT32(body + sizeof(uint32_t), 0, NULL); /* reserved */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březinanss_protocol_fill_initgr(struct nss_ctx *nss_ctx,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* num_results, reserved + gids */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_packet_grow(packet, (2 + result->count) * sizeof(uint32_t));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina gid = sss_view_ldb_msg_find_attr_as_uint64(domain, user, SYSDB_GIDNUM, 0);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina orig_gid = sss_view_ldb_msg_find_attr_as_uint64(domain, user,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* If the GID of the original primary group is available but equal to the
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina * current primary GID it must not be added. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* First message is user, skip it. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina gid = sss_view_ldb_msg_find_attr_as_uint64(domain, msg, SYSDB_GIDNUM,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina posix = ldb_msg_find_attr_as_string(msg, SYSDB_POSIX, NULL);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina if (posix != NULL && strcmp(posix, "FALSE") == 0) {
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Incomplete group object [%s] for initgroups! "
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Aborting.\n", ldb_dn_get_linearized(msg->dn));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Do not add the GID of the original primary group if the user is
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina * already an explicit member of the group. */
677a31351c80453d9ce006481364399a96312052René Genz /* Initialize allocated memory to be safe and make Valgrind happy. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Insert original primary group into the result. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_COPY_UINT32(&body[rp], &orig_gid, &rp);
55f7d8034d783c01789d76a2b9ffc901045e8af8Sumit Bose && (cmd_ctx->flags & SSS_NSS_EX_FLAG_INVALIDATE_CACHE) == 0) {
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina to_sized_string(&unique_name, result->lookup_name);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_mmap_cache_initgr_store(&nss_ctx->initgr_mc_ctx, &rawname,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Failed to store initgroups %s (%s) in mem-cache [%d]: %s!\n",
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina rawname.str, domain->name, ret, sss_strerror(ret));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_COPY_UINT32(body, &num_results, NULL);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SETMEM_UINT32(body + sizeof(uint32_t), 0, NULL); /* reserved */